SettingsSection.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef SETTINGSSECTION_H
  2. #define SETTINGSSECTION_H
  3. #include <QObject>
  4. #include <QMap>
  5. #include <QVariant>
  6. #include <QDebug>
  7. #include "SettingsValue.h"
  8. #include "SettingsComponent.h"
  9. class SettingsSection : public QObject
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit SettingsSection(const QString& sectionID, quint8 platforms = PLATFORM_ANY,
  14. int _orderIndex = -1, QObject* parent = nullptr);
  15. void updatePossibleValues(const QString& key, const QVariantList& possibleValues);
  16. QVariantList possibleValues(const QString& key);
  17. void setValues(const QVariant& values);
  18. bool setValue(const QString& key, const QVariant& value);
  19. void resetValue(const QString& key);
  20. void resetValues();
  21. void registerSetting(SettingsValue* value);
  22. bool isHidden() const;
  23. QVariant value(const QString& key);
  24. QVariant defaultValue(const QString& key);
  25. QString sectionName() const { return m_sectionID; }
  26. const QVariantMap allValues() const;
  27. const QVariantMap descriptions() const;
  28. bool isValueHidden(const QString& key) const { return m_values[key]->isHidden(); }
  29. int orderIndex() const { return m_orderIndex; }
  30. void setHidden(bool hidden=true)
  31. {
  32. m_hidden = hidden;
  33. }
  34. void setValueHidden(const QString& value, bool hidden)
  35. {
  36. if (m_values.contains(value))
  37. m_values.value(value)->setHidden(hidden);
  38. }
  39. void setStorage(bool storage) { m_storage = storage; }
  40. bool isStorage() const
  41. {
  42. return m_storage;
  43. }
  44. Q_SIGNAL void valuesUpdated(const QVariantMap& values);
  45. protected:
  46. // if the value is _not_ removed, _and_ changes, it's added to updatedValues
  47. void resetValueNoNotify(const QString& key, QVariantMap& updatedValues);
  48. QHash<QString, SettingsValue*> m_values;
  49. QString m_sectionID;
  50. int m_orderIndex;
  51. quint8 m_platform;
  52. bool m_hidden;
  53. bool m_storage;
  54. };
  55. #endif // SETTINGSSECTION_H