Qt Utilities 6.14.3
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
optionpage.cpp
Go to the documentation of this file.
1#include "./optionpage.h"
2
3#include <QCheckBox>
4#include <QEvent>
5#include <QGroupBox>
6#include <QLabel>
7#include <QPushButton>
8#include <QRadioButton>
9
10#include <utility>
11
12namespace QtUtilities {
13
25OptionPage::OptionPage(QWidget *parentWindow)
26 : m_parentWindow(parentWindow)
27 , m_shown(false)
28 , m_keywordsInitialized(false)
29{
30}
31
38
49{
50 if (!m_widget) {
51 m_widget.reset(setupWidget()); // ensure widget has been created
52 }
53 if (!m_shown) {
54 m_shown = true;
55 reset(); // show current configuration if not shown yet
56 }
57 return m_widget.get();
58}
59
64bool OptionPage::matches(const QString &searchKeyWord)
65{
66 if (searchKeyWord.isEmpty()) {
67 return true;
68 }
69 if (!m_keywordsInitialized) {
70 if (!m_widget) {
71 m_widget.reset(setupWidget()); // ensure widget has been created
72 }
73 m_keywords << m_widget->windowTitle();
74 // find common subwidgets
75 for (const QLabel *label : m_widget->findChildren<QLabel *>())
76 m_keywords << label->text();
77 for (const QCheckBox *checkbox : m_widget->findChildren<QCheckBox *>())
78 m_keywords << checkbox->text();
79 for (const QRadioButton *checkbox : m_widget->findChildren<QRadioButton *>())
80 m_keywords << checkbox->text();
81 for (const QPushButton *pushButton : m_widget->findChildren<QPushButton *>())
82 m_keywords << pushButton->text();
83 for (const QGroupBox *groupBox : m_widget->findChildren<QGroupBox *>())
84 m_keywords << groupBox->title();
85 m_keywordsInitialized = true;
86 }
87 for (const QString &keyword : std::as_const(m_keywords))
88 if (keyword.contains(searchKeyWord, Qt::CaseInsensitive))
89 return true;
90 return false;
91}
92
96bool OptionPageWidget::event(QEvent *event)
97{
98 switch (event->type()) {
99 case QEvent::PaletteChange:
100 emit paletteChanged();
101 break;
102 case QEvent::LanguageChange:
104 break;
105 default:;
106 }
107 return QWidget::event(event);
108}
109
135} // namespace QtUtilities
bool event(QEvent *) override
Emits the paletteChanged() signal.
OptionPage(QWidget *parentWindow=nullptr)
Constructs a option page.
virtual void reset()=0
Discards altered settings and resets relevant widgets.
bool matches(const QString &searchKeyWord)
Returns whether the pages matches the specified searchKeyWord.
virtual QWidget * setupWidget()=0
Creates the widget for the page.
virtual ~OptionPage()
Destroys the option page.
QWidget * widget()
Returns the widget for the option page.