Qt Utilities 6.5.1
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
optionpage.cpp
Go to the documentation of this file.
1#include "./optionpage.h"
2
3#include <QCheckBox>
4#include <QGroupBox>
5#include <QLabel>
6#include <QPushButton>
7#include <QRadioButton>
8
9namespace QtUtilities {
10
22OptionPage::OptionPage(QWidget *parentWindow)
23 : m_parentWindow(parentWindow)
24 , m_shown(false)
25 , m_keywordsInitialized(false)
26{
27}
28
33{
34}
35
46{
47 if (!m_widget) {
48 m_widget.reset(setupWidget()); // ensure widget has been created
49 }
50 if (!m_shown) {
51 m_shown = true;
52 reset(); // show current configuration if not shown yet
53 }
54 return m_widget.get();
55}
56
61bool OptionPage::matches(const QString &searchKeyWord)
62{
63 if (searchKeyWord.isEmpty()) {
64 return true;
65 }
66 if (!m_keywordsInitialized) {
67 if (!m_widget) {
68 m_widget.reset(setupWidget()); // ensure widget has been created
69 }
70 m_keywords << m_widget->windowTitle();
71 // find common subwidgets
72 for (const QLabel *label : m_widget->findChildren<QLabel *>())
73 m_keywords << label->text();
74 for (const QCheckBox *checkbox : m_widget->findChildren<QCheckBox *>())
75 m_keywords << checkbox->text();
76 for (const QRadioButton *checkbox : m_widget->findChildren<QRadioButton *>())
77 m_keywords << checkbox->text();
78 for (const QPushButton *pushButton : m_widget->findChildren<QPushButton *>())
79 m_keywords << pushButton->text();
80 for (const QGroupBox *groupBox : m_widget->findChildren<QGroupBox *>())
81 m_keywords << groupBox->title();
82 m_keywordsInitialized = true;
83 }
84 for (const QString &keyword : m_keywords)
85 if (keyword.contains(searchKeyWord, Qt::CaseInsensitive))
86 return true;
87 return false;
88}
89
115} // namespace QtUtilities
OptionPage(QWidget *parentWindow=nullptr)
Constructs a option page.
Definition: optionpage.cpp:22
virtual void reset()=0
Discards altered settings and resets relevant widgets.
virtual QWidget * setupWidget()=0
Creates the widget for the page.
bool matches(const QString &searchKeyWord)
Returns whether the pages matches the specified searchKeyWord.
Definition: optionpage.cpp:61
virtual ~OptionPage()
Destroys the option page.
Definition: optionpage.cpp:32
QWidget * widget()
Returns the widget for the option page.
Definition: optionpage.cpp:45