Browse Source

Improve Python access to ctkSettingsPanel

Add a Q_INVOKABLE overload of ctkSettingsPanel::registerProperty in
order to make the method usable from PythonQt. The overload takes the
signal as a QByteArray, to match the behavior of qt.SIGNAL, so that
users do not need to explicitly cast that to a str in order to call the
method. Also expose settings/setSettings as a Q_PROPERTY, for similar
reasons.
Matthew Woehlke 11 years ago
parent
commit
12d566c1e9
2 changed files with 22 additions and 0 deletions
  1. 10 0
      Libs/Widgets/ctkSettingsPanel.cpp
  2. 12 0
      Libs/Widgets/ctkSettingsPanel.h

+ 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);