Added a SettingsDialog with a "Server" tab to configure the server settings.
This commit is contained in:
@ -32,6 +32,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
|||||||
dialogs/abstractdialog.h dialogs/abstractdialog.cpp
|
dialogs/abstractdialog.h dialogs/abstractdialog.cpp
|
||||||
dialogs/newitemdialog.h dialogs/newitemdialog.cpp
|
dialogs/newitemdialog.h dialogs/newitemdialog.cpp
|
||||||
dialogs/edititemdialog.h dialogs/edititemdialog.cpp
|
dialogs/edititemdialog.h dialogs/edititemdialog.cpp
|
||||||
|
dialogs/settingsdialog.h dialogs/settingsdialog.cpp
|
||||||
views/itemdetailmapper.h views/itemdetailmapper.cpp
|
views/itemdetailmapper.h views/itemdetailmapper.cpp
|
||||||
)
|
)
|
||||||
# Define target properties for Android with Qt 6 as:
|
# Define target properties for Android with Qt 6 as:
|
||||||
|
|||||||
61
dialogs/settingsdialog.cpp
Normal file
61
dialogs/settingsdialog.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "settingsdialog.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QTabWidget>
|
||||||
|
|
||||||
|
SettingsDialog::SettingsDialog(QWidget* parent)
|
||||||
|
: AbstractDialog(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, parent) {}
|
||||||
|
|
||||||
|
void SettingsDialog::createContent() {
|
||||||
|
if (m_contentContainer) {
|
||||||
|
delete m_contentContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString dialogTitle = tr("Settings - ");
|
||||||
|
const QString applicationName = QCoreApplication::applicationName();
|
||||||
|
|
||||||
|
setWindowTitle(dialogTitle + applicationName);
|
||||||
|
setModal(true);
|
||||||
|
setGeometry(0, 0, 350, 250);
|
||||||
|
QGridLayout* serverLayout = new QGridLayout();
|
||||||
|
QLabel* urlLabel = new QLabel("Server URL:");
|
||||||
|
m_urlEdit = new QLineEdit();
|
||||||
|
serverLayout->addWidget(urlLabel, 0, 0);
|
||||||
|
serverLayout->addWidget(m_urlEdit, 0, 1);
|
||||||
|
QLabel* emailLabel = new QLabel("Email:");
|
||||||
|
m_emailEdit = new QLineEdit();
|
||||||
|
serverLayout->addWidget(emailLabel, 1, 0);
|
||||||
|
serverLayout->addWidget(m_emailEdit, 1, 1);
|
||||||
|
QLabel* passwordLabel = new QLabel("Password:");
|
||||||
|
m_passwordEdit = new QLineEdit();
|
||||||
|
m_passwordEdit->setEchoMode(QLineEdit::Password);
|
||||||
|
serverLayout->addWidget(passwordLabel, 2, 0);
|
||||||
|
serverLayout->addWidget(m_passwordEdit, 2, 1);
|
||||||
|
|
||||||
|
QWidget* serverTab = new QWidget();
|
||||||
|
serverTab->setLayout(serverLayout);
|
||||||
|
|
||||||
|
QTabWidget* widget = new QTabWidget();
|
||||||
|
widget->addTab(serverTab, "Server");
|
||||||
|
|
||||||
|
m_contentContainer = widget;
|
||||||
|
m_outerLayout->insertWidget(0, m_contentContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsDialog::fillContent(const QVariantMap& settings) {
|
||||||
|
m_urlEdit->setText(settings.value("url").toString());
|
||||||
|
m_emailEdit->setText(settings.value("email").toString());
|
||||||
|
m_passwordEdit->setText(settings.value("password").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariantMap SettingsDialog::getSettings() const {
|
||||||
|
QVariantMap result;
|
||||||
|
result.insert("url", m_urlEdit->text());
|
||||||
|
result.insert("email", m_emailEdit->text());
|
||||||
|
result.insert("password", m_passwordEdit->text());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
23
dialogs/settingsdialog.h
Normal file
23
dialogs/settingsdialog.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef SETTINGSDIALOG_H
|
||||||
|
#define SETTINGSDIALOG_H
|
||||||
|
|
||||||
|
#include "abstractdialog.h"
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
|
class SettingsDialog : public AbstractDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
SettingsDialog(QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
void createContent() override;
|
||||||
|
void fillContent(const QVariantMap& settings);
|
||||||
|
QVariantMap getSettings() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLineEdit* m_urlEdit = nullptr;
|
||||||
|
QLineEdit* m_emailEdit = nullptr;
|
||||||
|
QLineEdit* m_passwordEdit = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SETTINGSDIALOG_H
|
||||||
@ -12,6 +12,7 @@
|
|||||||
#include "../../ApplicationConfig.h"
|
#include "../../ApplicationConfig.h"
|
||||||
#include "dialogs/edititemdialog.h"
|
#include "dialogs/edititemdialog.h"
|
||||||
#include "dialogs/newitemdialog.h"
|
#include "dialogs/newitemdialog.h"
|
||||||
|
#include "dialogs/settingsdialog.h"
|
||||||
#include "genericcore.h"
|
#include "genericcore.h"
|
||||||
#include "model/generalsortfiltermodel.h"
|
#include "model/generalsortfiltermodel.h"
|
||||||
#include "model/tablemodel.h"
|
#include "model/tablemodel.h"
|
||||||
@ -315,12 +316,37 @@ void MainWindow::deleteItem() {
|
|||||||
emit m_core->deleteItemFromServer(currentId);
|
emit m_core->deleteItemFromServer(currentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::execSettingsDialog() {
|
||||||
|
showStatusMessage(tr("Invoked 'Tools|Settings'"));
|
||||||
|
QVariantMap oldSettings = m_core->getSettings("Server");
|
||||||
|
// SettingsDialog* settingsDialog = new SettingsDialog(settingMap, this);
|
||||||
|
SettingsDialog* settingsDialog = new SettingsDialog(this);
|
||||||
|
settingsDialog->createContent();
|
||||||
|
settingsDialog->fillContent(oldSettings);
|
||||||
|
|
||||||
|
int returnCode = settingsDialog->exec();
|
||||||
|
if (returnCode == QDialog::Accepted) {
|
||||||
|
qDebug() << "Settings dialog accepted, writing settings...";
|
||||||
|
const QVariantMap settings = settingsDialog->getSettings();
|
||||||
|
|
||||||
|
m_core->applySettings(settings, "Server");
|
||||||
|
// TODO use signal-slot connection Core::syncServerSetupChanged(bool enabled) ->
|
||||||
|
// MainWindow::onSyncServerSetupChanged(bool enabled)
|
||||||
|
|
||||||
|
// enableDisableServerActions();
|
||||||
|
} else {
|
||||||
|
qDebug() << "Settings dialog rejected";
|
||||||
|
}
|
||||||
|
delete settingsDialog;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::createActions() {
|
void MainWindow::createActions() {
|
||||||
// TODO add generic menu actions (file/new, edit/cut, ...)
|
// TODO add generic menu actions (file/new, edit/cut, ...)
|
||||||
createFileActions();
|
createFileActions();
|
||||||
createUndoActions();
|
createUndoActions();
|
||||||
createEditActions();
|
createEditActions();
|
||||||
createServerActions();
|
createServerActions();
|
||||||
|
createToolsActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createFileActions() {
|
void MainWindow::createFileActions() {
|
||||||
@ -489,6 +515,12 @@ void MainWindow::createServerActions() {
|
|||||||
ui->menu_Server->addAction(m_deleteItemsAct.get());
|
ui->menu_Server->addAction(m_deleteItemsAct.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::createToolsActions() {
|
||||||
|
QMenu* menu = ui->menu_Tools;
|
||||||
|
QAction* settingsAct = menu->addAction(tr("&Settings"), this, &MainWindow::execSettingsDialog);
|
||||||
|
settingsAct->setStatusTip(tr("Opens a dialog to configure applications settings."));
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::createHelpMenu() {
|
void MainWindow::createHelpMenu() {
|
||||||
QMenu* helpMenu = ui->menu_Help;
|
QMenu* helpMenu = ui->menu_Help;
|
||||||
helpMenu->addSeparator();
|
helpMenu->addSeparator();
|
||||||
|
|||||||
@ -68,6 +68,9 @@ class MainWindow : public QMainWindow {
|
|||||||
void postItems();
|
void postItems();
|
||||||
void deleteItem();
|
void deleteItem();
|
||||||
|
|
||||||
|
/// 'Tools' slots
|
||||||
|
void execSettingsDialog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow* ui;
|
Ui::MainWindow* ui;
|
||||||
|
|
||||||
@ -112,6 +115,7 @@ class MainWindow : public QMainWindow {
|
|||||||
void createUndoActions();
|
void createUndoActions();
|
||||||
void createEditActions();
|
void createEditActions();
|
||||||
void createServerActions();
|
void createServerActions();
|
||||||
|
void createToolsActions();
|
||||||
void createHelpMenu();
|
void createHelpMenu();
|
||||||
void createGuiDialogs();
|
void createGuiDialogs();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -69,10 +69,16 @@
|
|||||||
<string>&Server</string>
|
<string>&Server</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="menu_Tools">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Tools</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
<addaction name="menu_File"/>
|
<addaction name="menu_File"/>
|
||||||
<addaction name="menu_Edit"/>
|
<addaction name="menu_Edit"/>
|
||||||
<addaction name="menu_View"/>
|
<addaction name="menu_View"/>
|
||||||
<addaction name="menu_Server"/>
|
<addaction name="menu_Server"/>
|
||||||
|
<addaction name="menu_Tools"/>
|
||||||
<addaction name="menu_Help"/>
|
<addaction name="menu_Help"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user