浏览代码

Merge pull request #453 from mwoehlke-kitware/ctksettingspanel-python

Make ctkSettings{Dialog,Panel} usable via PythonQt
Jean-Christophe Fillion-Robin 11 年之前
父节点
当前提交
bb128be6d3
共有 3 个文件被更改,包括 55 次插入8 次删除
  1. 33 8
      Libs/Widgets/ctkSettingsDialog.h
  2. 10 0
      Libs/Widgets/ctkSettingsPanel.cpp
  3. 12 0
      Libs/Widgets/ctkSettingsPanel.h

+ 33 - 8
Libs/Widgets/ctkSettingsDialog.h

@@ -42,6 +42,17 @@ class CTK_WIDGETS_EXPORT ctkSettingsDialog : public QDialog
   /// the dialog at the same time.
   Q_PROPERTY(bool resetButton READ resetButton WRITE setResetButton);
 
+  Q_PROPERTY(QSettings* settings READ settings WRITE setSettings);
+
+  Q_PROPERTY(ctkSettingsPanel* currentPanel READ currentPanel WRITE setCurrentPanel);
+
+  /// Specifies if a restart required to fully apply changes.
+  ///
+  /// This property is \c true if at least one OptionRestartRequired setting is
+  /// changed. It doesn't imply that the user accepted to restart the
+  /// application.
+  Q_PROPERTY(bool restartRequired READ isRestartRequired);
+
 public:
   /// Superclass typedef
   typedef QDialog Superclass;
@@ -58,18 +69,32 @@ public:
   ctkSettingsPanel* panel(const QString& panel)const;
   ctkSettingsPanel* currentPanel()const;
 
-  /// Uses the ctkSettingsPanel::windowTitle property to show in the list
-  void addPanel(ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
-  /// Utility function
-  void addPanel(const QString& label, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
-  void addPanel(const QString& label, const QIcon& icon, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
+  /// Add settings panel to the dialog.
+  ///
+  /// This adds the specified settings panel to the dialog. The panel's
+  /// QWidget::windowTitle property is used as the panel name as shown in the
+  /// panels list.
+  Q_INVOKABLE void addPanel(ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
+
+  /// \copybrief addPanel
+  ///
+  /// This convenience overload allows the caller to specify the panel name
+  /// that will be used in the panels list.
+  Q_INVOKABLE void addPanel(const QString& label, ctkSettingsPanel* panel,
+                            ctkSettingsPanel* parentPanel = 0);
+
+  /// \copybrief addPanel
+  ///
+  /// This convenience overload allows the caller to specify the panel name
+  /// that will be used in the panels list, as well as an icon for the panel.
+  Q_INVOKABLE void addPanel(const QString& label, const QIcon& icon,
+                            ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
 
   bool resetButton()const;
   void setResetButton(bool show);
 
-  /// True if at least one OptionRestartRequired setting is changed.
-  /// It doesn't mean the user accepted to restart the application
-  /// \sa restartRequired
+  /// \copybrief restartRequired
+  /// \sa restartRequired, restartRequested
   bool isRestartRequired()const;
 
 public Q_SLOTS:

+ 10 - 0
Libs/Widgets/ctkSettingsPanel.cpp

@@ -301,6 +301,16 @@ void ctkSettingsPanel::registerProperty(const QString& key,
 }
 
 // --------------------------------------------------------------------------
+void ctkSettingsPanel::registerProperty(
+  const QString& key, QObject* object, const QString& property,
+  const QByteArray& signal, const QString& label,
+  ctkSettingsPanel::SettingOptions options, QSettings* settings)
+{
+  this->registerProperty(key, object, property, signal.constData(),
+                         label, options, settings);
+}
+
+// --------------------------------------------------------------------------
 QVariant ctkSettingsPanel::defaultPropertyValue(const QString& key) const
 {
   Q_D(const ctkSettingsPanel);

+ 12 - 0
Libs/Widgets/ctkSettingsPanel.h

@@ -37,6 +37,9 @@ class CTK_WIDGETS_EXPORT ctkSettingsPanel : public QWidget
   Q_OBJECT
   Q_ENUMS(SettingOption)
   Q_FLAGS(SettingOptions)
+
+  Q_PROPERTY(QSettings* settings READ settings WRITE setSettings);
+
 public:
   /// Superclass typedef
   typedef QWidget Superclass;
@@ -83,6 +86,15 @@ public:
                         SettingOptions options = OptionNone,
                         QSettings * settings = 0);
 
+  /// \copybrief registerProperty
+  /// \overload
+  Q_INVOKABLE void registerProperty(const QString& settingKey, QObject* object,
+                                    const QString& objectProperty,
+                                    const QByteArray& propertySignal,
+                                    const QString& settingLabel = QString(),
+                                    SettingOptions options = OptionNone,
+                                    QSettings * settings = 0);
+
   /// Set the setting to the property defined by the key.
   /// The old value can be restored using resetSettings()
   void setSetting(const QString& key, const QVariant& newVal);