Skip to content

Commit 9f0b5c0

Browse files
committed
wip: settings dialog fixes
added closed signal to the settings dialog which allows the caller to delete the window. added section & category to settings pages, under windows & linux the section is displayed in the list and the category is a tab. changed mirror operation to clone
1 parent 77490d5 commit 9f0b5c0

File tree

4 files changed

+77
-15
lines changed

4 files changed

+77
-15
lines changed

GeneralSettingsPage.ui

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>466</width>
10-
<height>104</height>
10+
<height>113</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -55,7 +55,7 @@
5555
<item row="0" column="0">
5656
<widget class="QLabel" name="label">
5757
<property name="text">
58-
<string>Mirror Detail:</string>
58+
<string>Info:</string>
5959
</property>
6060
</widget>
6161
</item>

MainWindow.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ void Nedrysoft::MainWindow::on_actionPreferences_triggered()
124124
m_settingsDialog = new SettingsDialog(this);
125125

126126
m_settingsDialog->show();
127+
128+
connect(m_settingsDialog, &SettingsDialog::closed, [=](){
129+
m_settingsDialog->deleteLater();
130+
131+
m_settingsDialog = nullptr;
132+
});
127133
}
128134

129135
void Nedrysoft::MainWindow::closeEvent(QCloseEvent *closeEvent)

SettingsDialog.cpp

+57-11
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,53 @@ Nedrysoft::SettingsDialog::SettingsDialog(QWidget *parent) :
131131

132132
m_controlsLayout->addSpacerItem(new QSpacerItem(0,0,QSizePolicy::Expanding, QSizePolicy::Minimum));
133133

134-
m_okButton = new QPushButton("OK");
135-
m_cancelButton = new QPushButton("Cancel");
136-
m_applyButton = new QPushButton("Apply");
134+
m_okButton = new QPushButton(tr("OK"));
135+
m_cancelButton = new QPushButton(tr("Cancel"));
136+
m_applyButton = new QPushButton(tr("Apply)"));
137+
138+
connect(m_okButton, &QPushButton::clicked, [=](bool /*checked*/) {
139+
bool settingsValid = true;
140+
141+
for(auto page : m_pages) {
142+
if (!page->m_pageSettings->canAcceptSettings()) {
143+
settingsValid = false;
144+
break;
145+
}
146+
}
147+
148+
if (!settingsValid) {
149+
//TODO go to page with error
150+
} else {
151+
for(auto page : m_pages) {
152+
page->m_pageSettings->acceptSettings();
153+
}
154+
155+
close();
156+
}
157+
});
158+
159+
connect(m_applyButton, &QPushButton::clicked, [=](bool /*checked*/) {
160+
bool settingsValid = true;
161+
162+
for(auto page : m_pages) {
163+
if (!page->m_pageSettings->canAcceptSettings()) {
164+
settingsValid = false;
165+
break;
166+
}
167+
}
168+
169+
if (!settingsValid) {
170+
//TODO go to page with error
171+
} else {
172+
for(auto page : m_pages) {
173+
page->m_pageSettings->acceptSettings();
174+
}
175+
}
176+
});
177+
178+
connect(m_cancelButton, &QPushButton::clicked, [=](bool /*checked*/) {
179+
close();
180+
});
137181

138182
m_controlsLayout->addWidget(m_okButton);
139183
m_controlsLayout->addWidget(m_cancelButton);
@@ -143,8 +187,8 @@ Nedrysoft::SettingsDialog::SettingsDialog(QWidget *parent) :
143187

144188
setLayout(m_layout);
145189
#endif
146-
addPage(tr("General"), tr("General settings"), SettingsPage::Icon::General, new GeneralSettingsPage, true);
147-
addPage(tr("Database"), tr("The database settings"), SettingsPage::Icon::Database, new DatabaseSettingsPage);
190+
addPage(tr("General"), tr("Application Clone"), tr("General settings"), SettingsPage::Icon::General, new GeneralSettingsPage, true);
191+
addPage(tr("Database"), tr("Connection"), tr("Database connection settings"), SettingsPage::Icon::Database, new DatabaseSettingsPage);
148192

149193
#if defined(Q_OS_MACOS)
150194
m_toolBar->attachToWindow(nativeWindowHandle());
@@ -202,7 +246,9 @@ bool Nedrysoft::SettingsDialog::close()
202246
page->m_pageSettings->acceptSettings();
203247
}
204248
#endif
205-
return true;
249+
emit closed();
250+
251+
return QWidget::close();
206252
}
207253
void Nedrysoft::SettingsDialog::resizeEvent(QResizeEvent *event)
208254
{
@@ -223,14 +269,14 @@ QWindow *Nedrysoft::SettingsDialog::nativeWindowHandle()
223269
return window()->windowHandle();
224270
}
225271

226-
Nedrysoft::SettingsPage *Nedrysoft::SettingsDialog::addPage(QString name, QString description, SettingsPage::Icon icon, QWidget *widget, bool defaultPage)
272+
Nedrysoft::SettingsPage *Nedrysoft::SettingsDialog::addPage(QString section, QString category, QString description, SettingsPage::Icon icon, QWidget *widget, bool defaultPage)
227273
{
228274
#if defined(Q_OS_MACOS)
229275
auto widgetContainer = new TransparentWidget(widget, 0, this);
230276

231277
auto settingsPage = new SettingsPage;
232278

233-
settingsPage->m_name = name;
279+
settingsPage->m_name = section;
234280
settingsPage->m_widget = widgetContainer;
235281
settingsPage->m_pageSettings = dynamic_cast<ISettingsPage *>(widget);
236282
settingsPage->m_icon = icon;
@@ -321,19 +367,19 @@ Nedrysoft::SettingsPage *Nedrysoft::SettingsDialog::addPage(QString name, QStrin
321367
auto tabWidget = new QTabWidget();
322368

323369
newTreeItem->setIcon(0, getIcon(icon));
324-
newTreeItem->setText(0, name);
370+
newTreeItem->setText(0, section);
325371
newTreeItem->setData(0, Qt::UserRole, QVariant::fromValue(tabWidget));
326372
newTreeItem->setData(0, Qt::ToolTipRole, description);
327373

328374
m_treeWidget->addTopLevelItem(newTreeItem);
329375

330-
tabWidget->addTab(widget, "Interface");
376+
tabWidget->addTab(widget, category);
331377

332378
m_stackedWidget->addWidget(tabWidget);
333379

334380
auto settingsPage = new SettingsPage;
335381

336-
settingsPage->m_name = name;
382+
settingsPage->m_name = section;
337383
settingsPage->m_widget = widget;
338384
settingsPage->m_pageSettings = dynamic_cast<ISettingsPage *>(widget);
339385
settingsPage->m_icon = icon;

SettingsDialog.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ namespace Nedrysoft {
107107
* @returns true if closed; otherwise false.
108108
*/
109109
bool close();
110+
111+
signals:
112+
/**
113+
* @brief Closed signal
114+
*
115+
* @details Emmited when the dialog is closed
116+
*/
117+
void closed();
118+
110119
private:
111120
/**
112121
* @brief Returns the QWindow handle from native widget
@@ -138,15 +147,16 @@ namespace Nedrysoft {
138147
*
139148
* @details Adds the given page to the settings dialog
140149
*
141-
* @params[in] name is the displayed name of the page
150+
* @params[in] section is the displayed name of the section
151+
* @params[in] category is the category within the section
142152
* @params[in] description is the description of the purpose of the page
143153
* @params[in] icon is the icon of the page
144154
* @params[in] widget is the widget containing the page content
145155
* @params[in] defaultPage true if page is the default shown page; otherwise false
146156
*
147157
* @returns the settings page structure
148158
*/
149-
Nedrysoft::SettingsPage *addPage(QString name, QString description, SettingsPage::Icon icon, QWidget *widget, bool defaultPage=false);
159+
SettingsPage *addPage(QString section, QString category, QString description, SettingsPage::Icon icon, QWidget *widget, bool defaultPage=false);
150160

151161
private:
152162
#if defined(Q_OS_MACOS)

0 commit comments

Comments
 (0)