ctkSettingsPanel.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.commontk.org/LICENSE
  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 entrie into the settings uniquely defined by the 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 slots:
  51. /// By default, it calls applySettings()
  52. virtual void acceptSettings();
  53. /// Forget the old property values so next time resetSettings is called it
  54. /// will set the properties with the same values when applySettings() is
  55. /// called.
  56. void applySettings();
  57. /// Restore all the properties with their values when applySettings() was
  58. /// called last (or their original values if applySettings was never called).
  59. void resetSettings();
  60. /// Restore all the properties with their original values; the current values
  61. /// of the properties when they were registered using registerProperty().
  62. void restoreDefaultSettings();
  63. signals:
  64. /// Fired anytime a property is modified.
  65. void settingChanged(const QString& key, const QVariant& value);
  66. protected slots:
  67. void updateSetting(const QString& key);
  68. protected:
  69. QScopedPointer<ctkSettingsPanelPrivate> d_ptr;
  70. virtual void updateProperties();
  71. private:
  72. Q_DECLARE_PRIVATE(ctkSettingsPanel);
  73. Q_DISABLE_COPY(ctkSettingsPanel);
  74. };
  75. #endif