[tracking] Connect UI to configuration

- policy buttons open the policy URL
- hide tracking levels that are not configurable
main
Adriaan de Groot 5 years ago
parent 756e3084dc
commit 8c1685d2cf

@ -29,7 +29,6 @@
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include <QButtonGroup>
#include <QDesktopServices>
#include <QLabel>
@ -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<bool>::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() );
}

@ -21,6 +21,7 @@
#include "TrackingType.h"
#include <QCheckBox>
#include <QUrl>
#include <QWidget>
@ -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;
};

Loading…
Cancel
Save