Qt Utilities  5.6.0
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 <QLabel>
4 #include <QCheckBox>
5 #include <QRadioButton>
6 #include <QPushButton>
7 #include <QGroupBox>
8 
9 namespace Dialogs {
10 
21 OptionPage::OptionPage(QWidget *parentWindow) :
22  m_parentWindow(parentWindow),
23  m_shown(false),
24  m_keywordsInitialized(false)
25 {}
26 
31 {}
32 
43 {
44  if(!m_widget) {
45  m_widget.reset(setupWidget()); // ensure widget has been created
46  }
47  if(!m_shown) {
48  m_shown = true;
49  reset(); // show current configuration if not shown yet
50  }
51  return m_widget.get();
52 }
53 
58 bool OptionPage::matches(const QString &searchKeyWord)
59 {
60  if(searchKeyWord.isEmpty()) {
61  return true;
62  }
63  if(!m_keywordsInitialized) {
64  if(!m_widget) {
65  m_widget.reset(setupWidget()); // ensure widget has been created
66  }
67  m_keywords << m_widget->windowTitle();
68  // find common subwidgets
69  for(const QLabel *label : m_widget->findChildren<QLabel *>())
70  m_keywords << label->text();
71  for(const QCheckBox *checkbox : m_widget->findChildren<QCheckBox *>())
72  m_keywords << checkbox->text();
73  for(const QRadioButton *checkbox : m_widget->findChildren<QRadioButton *>())
74  m_keywords << checkbox->text();
75  for(const QPushButton *pushButton : m_widget->findChildren<QPushButton *>())
76  m_keywords << pushButton->text();
77  for(const QGroupBox *groupBox : m_widget->findChildren<QGroupBox *>())
78  m_keywords << groupBox->title();
79  m_keywordsInitialized = true;
80  }
81  for(const QString &keyword : m_keywords)
82  if(keyword.contains(searchKeyWord, Qt::CaseInsensitive))
83  return true;
84  return false;
85 }
86 
102 }
QWidget * widget()
Returns the widget for the option page.
Definition: optionpage.cpp:42
bool matches(const QString &searchKeyWord)
Returns whether the pages matches the specified searchKeyWord.
Definition: optionpage.cpp:58
virtual QWidget * setupWidget()=0
Creates the widget for the page.
Provides common dialogs such as AboutDialog, EnterPasswordDialog and SettingsDialog.
Definition: dialogutils.h:12
virtual void reset()=0
Discards altered settings and resets relevant widgets.
OptionPage(QWidget *parentWindow=nullptr)
Constructs a option page.
Definition: optionpage.cpp:21
virtual ~OptionPage()
Destroys the option page.
Definition: optionpage.cpp:30