diff --git a/src/modules/tracking/TrackingPage.cpp b/src/modules/tracking/TrackingPage.cpp index cb7e5a10a..d206a20a3 100644 --- a/src/modules/tracking/TrackingPage.cpp +++ b/src/modules/tracking/TrackingPage.cpp @@ -29,7 +29,6 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" -#include #include #include @@ -42,13 +41,26 @@ TrackingPage::TrackingPage( Config* config, QWidget* parent ) ui->noneCheckBox->setChecked( true ); connect( ui->noneCheckBox, &QCheckBox::stateChanged, this, &TrackingPage::buttonNoneChecked ); - connect( ui->installCheckBox, &QCheckBox::stateChanged, this, &TrackingPage::buttonChecked ); - connect( ui->machineCheckBox, &QCheckBox::stateChanged, this, &TrackingPage::buttonChecked ); - connect( ui->userCheckBox, &QCheckBox::stateChanged, this, &TrackingPage::buttonChecked ); - connect( ui->installCheckBox, &QCheckBox::stateChanged, [ this ]( int s ) { cDebug() << "Checkbox install changed" << s; } ); - connect( config->installTracking(), &TrackingStyleConfig::trackingChanged, [ config ]() { cDebug() << - "Install tracking configuration changed to " << config->installTracking()->isEnabled(); } ) ; + // Each "panel" of configuration has the same kind of setup, + // where the xButton and xCheckBox is connected to the xTracking + // configuration object; that takes macro-trickery, unfortunately. +#define trackingSetup(x) { \ + connect( ui->x ## CheckBox, &QCheckBox::stateChanged, \ + this, &TrackingPage::buttonChecked ); \ + connect( ui->x ## CheckBox, &QCheckBox::stateChanged, \ + config->x ## Tracking(), QOverload::of( &TrackingStyleConfig::setTracking ) ); \ + connect( config->x ## Tracking(), &TrackingStyleConfig::trackingChanged, \ + this, [ this, config ]() { this->trackerChanged( config->x ## Tracking(), this->ui->x ## Group, this->ui->x ## CheckBox);} ); \ + connect( ui->x ## PolicyButton, &QAbstractButton::clicked, \ + config, [ config ] { QString url( config->x ## Tracking()->policy() ); if ( !url.isEmpty() ) { QDesktopServices::openUrl( url ); } } ); \ +} + + trackingSetup( install ) + trackingSetup( machine ) + trackingSetup( user ) + +#undef trackingSetup connect( config, &Config::generalPolicyChanged, [ this ]( const QString& url ) { this->ui->generalPolicyLabel->setVisible( !url.isEmpty() ); @@ -119,3 +131,10 @@ void TrackingPage::buttonChecked(int state) } } } + +void +TrackingPage::trackerChanged(TrackingStyleConfig* config, QWidget* panel, QCheckBox* check) +{ + panel->setVisible( config->isConfigurable() ); + check->setChecked( config->isEnabled() ); +} diff --git a/src/modules/tracking/TrackingPage.h b/src/modules/tracking/TrackingPage.h index 1a995870d..48599ead4 100644 --- a/src/modules/tracking/TrackingPage.h +++ b/src/modules/tracking/TrackingPage.h @@ -21,6 +21,7 @@ #include "TrackingType.h" +#include #include #include @@ -30,6 +31,7 @@ class TrackingPage; } class Config; +class TrackingStyleConfig; class TrackingPage : public QWidget { @@ -62,6 +64,14 @@ public Q_SLOTS: void buttonChecked( int state ); private: + /** @brief Apply the tracking configuration to the UI + * + * If the config cannot be changed (disabled in config) then + * hide the UI parts on the @p panel; otherwise show it + * and set @p check state to whether the user has enabled it. + */ + void trackerChanged( TrackingStyleConfig* subconfig, QWidget* panel, QCheckBox* check); + Ui::TrackingPage* ui; };