ctkSettingsPanel.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkSettingsPanel_h
  15. #define __ctkSettingsPanel_h
  16. // Qt includes
  17. #include <QWidget>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class QSettings;
  21. class ctkSettingsPanelPrivate;
  22. class CTK_WIDGETS_EXPORT ctkSettingsPanel : public QWidget
  23. {
  24. Q_OBJECT
  25. public:
  26. /// Superclass typedef
  27. typedef QWidget Superclass;
  28. /// Constructor
  29. explicit ctkSettingsPanel(QWidget* parent = 0);
  30. /// Destructor
  31. virtual ~ctkSettingsPanel();
  32. QSettings* settings()const;
  33. void setSettings(QSettings* settings);
  34. /// Add an entry into the settings uniquely defined by the \a key name and the
  35. /// current value of the property.
  36. /// The property is then synchronized with the settings by observing the signal
  37. /// notification. Anytime the property is modified (the signal \a signal is
  38. /// fired), its value associated to \a key is updated in the settings.
  39. /// \a signal is typically the value under NOTIFY in Q_PROPERTY.
  40. /// The current value of the property is later used when
  41. /// restoreDefaultSettings() is called.
  42. /// \sa Q_PROPERTY()
  43. void registerProperty(const QString& key,
  44. QObject* object,
  45. const QString& property,
  46. const char* signal);
  47. /// Set the setting to the property defined by the key.
  48. /// The old value can be restored using resetSettings()
  49. void setSetting(const QString& key, const QVariant& newVal);
  50. public Q_SLOTS:
  51. /// Forget the old property values so next time resetSettings is called it
  52. /// will set the properties with the same values when applySettings() is
  53. /// called.
  54. virtual void applySettings();
  55. /// Restore all the properties with their values when applySettings() was
  56. /// called last (or their original values if applySettings was never called).
  57. virtual void resetSettings();
  58. /// Restore all the properties with their original values; the current values
  59. /// of the properties when they were registered using registerProperty().
  60. virtual void restoreDefaultSettings();
  61. Q_SIGNALS:
  62. /// Fired anytime a property is modified.
  63. void settingChanged(const QString& key, const QVariant& value);
  64. protected:
  65. /// Return the default value of a property identified by its settings \a key
  66. /// \sa registerProperty();
  67. QVariant defaultPropertyValue(const QString& key) const;
  68. /// Return the previous value of a property identified by its settings \a key
  69. /// \sa registerProperty();
  70. QVariant previousPropertyValue(const QString& key) const;
  71. /// Return the value of a property identified by its settings \a key
  72. /// \sa registerProperty();
  73. QVariant propertyValue(const QString& key) const;
  74. protected Q_SLOTS:
  75. void updateSetting(const QString& key);
  76. protected:
  77. QScopedPointer<ctkSettingsPanelPrivate> d_ptr;
  78. virtual void updateProperties();
  79. private:
  80. Q_DECLARE_PRIVATE(ctkSettingsPanel);
  81. Q_DISABLE_COPY(ctkSettingsPanel);
  82. };
  83. #endif