ctkSettingsPanel.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /// \ingroup Widgets
  23. class CTK_WIDGETS_EXPORT ctkSettingsPanel : public QWidget
  24. {
  25. Q_OBJECT
  26. public:
  27. /// Superclass typedef
  28. typedef QWidget Superclass;
  29. /// Constructor
  30. explicit ctkSettingsPanel(QWidget* parent = 0);
  31. /// Destructor
  32. virtual ~ctkSettingsPanel();
  33. QSettings* settings()const;
  34. void setSettings(QSettings* settings);
  35. /// Add an entry into the settings uniquely defined by the \a key name and the
  36. /// current value of the property.
  37. /// The property is then synchronized with the settings by observing the signal
  38. /// notification. Anytime the property is modified (the signal \a signal is
  39. /// fired), its value associated to \a key is updated in the settings.
  40. /// \a signal is typically the value under NOTIFY in Q_PROPERTY.
  41. /// The current value of the property is later used when
  42. /// restoreDefaultSettings() is called.
  43. /// \sa Q_PROPERTY()
  44. void registerProperty(const QString& key,
  45. QObject* object,
  46. const QString& property,
  47. const char* signal);
  48. /// Set the setting to the property defined by the key.
  49. /// The old value can be restored using resetSettings()
  50. void setSetting(const QString& key, const QVariant& newVal);
  51. public Q_SLOTS:
  52. /// Forget the old property values so next time resetSettings is called it
  53. /// will set the properties with the same values when applySettings() is
  54. /// called.
  55. virtual void applySettings();
  56. /// Restore all the properties with their values when applySettings() was
  57. /// called last (or their original values if applySettings was never called).
  58. virtual void resetSettings();
  59. /// Restore all the properties with their original values; the current values
  60. /// of the properties when they were registered using registerProperty().
  61. virtual void restoreDefaultSettings();
  62. Q_SIGNALS:
  63. /// Fired anytime a property is modified.
  64. void settingChanged(const QString& key, const QVariant& value);
  65. protected:
  66. /// Return the default value of a property identified by its settings \a key
  67. /// \sa registerProperty();
  68. QVariant defaultPropertyValue(const QString& key) const;
  69. /// Return the previous value of a property identified by its settings \a key
  70. /// \sa registerProperty();
  71. QVariant previousPropertyValue(const QString& key) const;
  72. /// Return the value of a property identified by its settings \a key
  73. /// \sa registerProperty();
  74. QVariant propertyValue(const QString& key) const;
  75. protected Q_SLOTS:
  76. void updateSetting(const QString& key);
  77. protected:
  78. QScopedPointer<ctkSettingsPanelPrivate> d_ptr;
  79. virtual void updateProperties();
  80. private:
  81. Q_DECLARE_PRIVATE(ctkSettingsPanel);
  82. Q_DISABLE_COPY(ctkSettingsPanel);
  83. };
  84. #endif