Browse Source

Allow reload in case of external changes

Add ctkSettingsDialog::reloadSettings() method to allow reloading
settings in case of external changes. Rename / make public the
ctkSettingsPanel::updateProperties() method (to reloadSettings() also)
in order to implement this.

This provides a way to make the settings dialog / panels aware of
changes made to the relevant QSettings outside of the dialog, which is
both an obvious bug in its own right, but more importantly prevents the
dialog from overwriting such external changes (see commontk/CTK#450).
Matthew Woehlke 11 years ago
parent
commit
c1759c1621

+ 11 - 0
Libs/Widgets/ctkSettingsDialog.cpp

@@ -337,6 +337,17 @@ void ctkSettingsDialog::applySettings()
 }
 }
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
+void ctkSettingsDialog::reloadSettings()
+{
+  Q_D(ctkSettingsDialog);
+  foreach(ctkSettingsPanel* panel, d->Panels.values())
+    {
+    panel->reloadSettings();
+    }
+  d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
+}
+
+// --------------------------------------------------------------------------
 void ctkSettingsDialog::resetSettings()
 void ctkSettingsDialog::resetSettings()
 {
 {
   Q_D(ctkSettingsDialog);
   Q_D(ctkSettingsDialog);

+ 8 - 0
Libs/Widgets/ctkSettingsDialog.h

@@ -80,6 +80,14 @@ public Q_SLOTS:
   void resetSettings();
   void resetSettings();
   void restoreDefaultSettings();
   void restoreDefaultSettings();
 
 
+  /// Reload settings for all registered panels.
+  ///
+  /// This reloads the settings for all panels, effectively throwing out any
+  /// values in the UI or the panels' caches and reverting to the values in the
+  /// associated QSettings. You should call this if you have made changes to
+  /// the QSettings that were not made through ctkSettingsPanel.
+  void reloadSettings();
+
   virtual void accept();
   virtual void accept();
   virtual void reject();
   virtual void reject();
 
 

+ 2 - 2
Libs/Widgets/ctkSettingsPanel.cpp

@@ -191,11 +191,11 @@ void ctkSettingsPanel::setSettings(QSettings* settings)
     return;
     return;
     }
     }
   d->Settings = settings;
   d->Settings = settings;
-  this->updateProperties();
+  this->reloadSettings();
 }
 }
 
 
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
-void ctkSettingsPanel::updateProperties()
+void ctkSettingsPanel::reloadSettings()
 {
 {
   Q_D(ctkSettingsPanel);
   Q_D(ctkSettingsPanel);
   foreach(const QString& key, d->Properties.keys())
   foreach(const QString& key, d->Properties.keys())

+ 6 - 1
Libs/Widgets/ctkSettingsPanel.h

@@ -111,6 +111,12 @@ public Q_SLOTS:
   /// of the properties when they were registered using registerProperty().
   /// of the properties when they were registered using registerProperty().
   virtual void restoreDefaultSettings();
   virtual void restoreDefaultSettings();
 
 
+  /// Reload all properties from disk.
+  ///
+  /// This reloads all properties from their respective QSettings instance(s).
+  /// The previous values are discarded (as in resetSettings()).
+  virtual void reloadSettings();
+
 Q_SIGNALS:
 Q_SIGNALS:
   /// Fired anytime a property is modified.
   /// Fired anytime a property is modified.
   void settingChanged(const QString& key, const QVariant& value);
   void settingChanged(const QString& key, const QVariant& value);
@@ -134,7 +140,6 @@ protected Q_SLOTS:
 protected:
 protected:
   QScopedPointer<ctkSettingsPanelPrivate> d_ptr;
   QScopedPointer<ctkSettingsPanelPrivate> d_ptr;
 
 
-  virtual void updateProperties();
 private:
 private:
   Q_DECLARE_PRIVATE(ctkSettingsPanel);
   Q_DECLARE_PRIVATE(ctkSettingsPanel);
   Q_DISABLE_COPY(ctkSettingsPanel);
   Q_DISABLE_COPY(ctkSettingsPanel);