ソースを参照

ctkSettingsPanel can register properties from same sender

Before, the QSignalMapper was returning the same property
(the last one registered) from a sender that had multiple registered
properties.
By using a unique QSignalMapper per property, we fix that problem.
This is particularly useful when registering custom properties from
the setting panel itself instead of typical basic widgets (QLineEdit,
QCheckBox...)
Julien Finet 13 年 前
コミット
1a6957cc2b
共有1 個のファイルを変更した8 個の追加10 個の削除を含む
  1. 8 10
      Libs/Widgets/ctkSettingsPanel.cpp

+ 8 - 10
Libs/Widgets/ctkSettingsPanel.cpp

@@ -117,7 +117,6 @@ public:
 
   QSettings*                  Settings;
   QMap<QString, PropertyType> Properties;
-  QSignalMapper*              SignalMapper;
   bool                        SaveToSettingsWhenRegister;
 };
 
@@ -128,18 +127,12 @@ ctkSettingsPanelPrivate::ctkSettingsPanelPrivate(ctkSettingsPanel& object)
   qRegisterMetaType<ctkSettingsPanel::SettingOption>("ctkSettingsPanel::SettingOption");
   qRegisterMetaType<ctkSettingsPanel::SettingOptions>("ctkSettingsPanel::SettingOptions");
   this->Settings = 0;
-  this->SignalMapper = 0;
   this->SaveToSettingsWhenRegister = true;
 }
 
 // --------------------------------------------------------------------------
 void ctkSettingsPanelPrivate::init()
 {
-  Q_Q(ctkSettingsPanel);
-  
-  this->SignalMapper = new QSignalMapper(q);
-  QObject::connect(this->SignalMapper, SIGNAL(mapped(QString)),
-                   q, SLOT(updateSetting(QString)));
 }
 
 // --------------------------------------------------------------------------
@@ -259,9 +252,14 @@ void ctkSettingsPanel::registerProperty(const QString& key,
     }
   d->Properties[key] = prop;
 
-  d->SignalMapper->setMapping(object, key);
-  this->connect(object, signal, d->SignalMapper, SLOT(map()));
-  
+  // Create a signal mapper per property to be able to support
+  // multiple signals from the same sender.
+  QSignalMapper* signalMapper = new QSignalMapper(this);
+  QObject::connect(signalMapper, SIGNAL(mapped(QString)),
+                   this, SLOT(updateSetting(QString)));
+  signalMapper->setMapping(object, key);
+  this->connect(object, signal, signalMapper, SLOT(map()));
+
   if (d->SaveToSettingsWhenRegister)
     {
     this->updateSetting(key);