VoiceAssistant  main
Resource-efficient, customizable voice assistant
Loading...
Searching...
No Matches
settingswidget.h
Go to the documentation of this file.
1#pragma once
2
3#if !defined(QT_WIDGETS_LIB)
4#error Qt Widgets required!
5#endif
6
7#include <QCheckBox>
8#include <QGroupBox>
9#include <QLabel>
10#include <QPushButton>
11#include <QWidget>
12
13class QSettings;
14
15class SettingsWidget : public QWidget
16{
17 Q_OBJECT
18public:
23 explicit SettingsWidget(QWidget *parent = nullptr)
24 : QWidget(parent){};
25
31 ~SettingsWidget() = default;
32
39 virtual void apply() = 0;
40
47 virtual void finish() = 0;
48
55 [[nodiscard]] QString displayName() const { return m_displayName; }
56
63 [[nodiscard]] QString displayCategory() const { return m_displayCategory; }
64
71 [[nodiscard]] const QIcon &categoryIcon() const { return m_categoryIcon; }
72
80 [[nodiscard]] inline const QStringList &keyWords()
81 {
82 if (m_keywordsInitialized)
83 return m_keywords;
84
85 // find common sub-widgets
86 for (const QLabel *label : findChildren<QLabel *>())
87 m_keywords << label->text();
88 for (const QCheckBox *checkbox : findChildren<QCheckBox *>())
89 m_keywords << checkbox->text();
90 for (const QPushButton *pushButton : findChildren<QPushButton *>())
91 m_keywords << pushButton->text();
92 for (const QGroupBox *groupBox : findChildren<QGroupBox *>())
93 m_keywords << groupBox->title();
94
95 m_keywordsInitialized = true;
96
97 return m_keywords;
98 };
99
107 virtual void setSettings(QSettings *settings) final { m_settings = settings; };
108
109protected:
117 void setDisplayName(const QString &displayName) { m_displayName = displayName; }
118
126 void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; }
127
135 void setCategoryIcon(const QIcon &categoryIcon) { m_categoryIcon = categoryIcon; }
136
144 QSettings *settings() { return m_settings; };
145
146private:
147 bool m_keywordsInitialized = false;
148 QStringList m_keywords;
149
150 QString m_displayName;
151 QString m_displayCategory;
152 QIcon m_categoryIcon;
153
154 QSettings *m_settings = nullptr;
155};
virtual void apply()=0
apply applies the changes made in the settings widget.
QString displayCategory() const
displayCategory returns the display category of the settings widget.
virtual void finish()=0
finish writes the settings to storage.
void setDisplayName(const QString &displayName)
setDisplayName sets the display name of the settings widget.
QSettings * settings()
settings returns the QSettings object used by the settings widget.
~SettingsWidget()=default
SettingsWidget destructor.
virtual void setSettings(QSettings *settings) final
setSettings sets the QSettings object to be used by the settings widget.
const QIcon & categoryIcon() const
categoryIcon returns the icon of the settings widget category.
QString displayName() const
displayName returns the display name of the settings widget.
const QStringList & keyWords()
keyWords returns the keywords associated with the settings widget.
SettingsWidget(QWidget *parent=nullptr)
SettingsWidget constructor.
void setCategoryIcon(const QIcon &categoryIcon)
setCategoryIcon sets the icon of the settings widget category.
void setDisplayCategory(const QString &displayCategory)
setDisplayCategory sets the display category of the settings widget.