Compare commits
6 Commits
8f61c6bc2f
...
4c4d734b1b
| Author | SHA1 | Date | |
|---|---|---|---|
| 4c4d734b1b | |||
| 0eef55fc32 | |||
| d109eb31f8 | |||
| a9f24ac8f2 | |||
| 67d9a3914d | |||
| 518bebcbb7 |
@ -32,6 +32,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
dialogs/abstractdialog.h dialogs/abstractdialog.cpp
|
||||
dialogs/newitemdialog.h dialogs/newitemdialog.cpp
|
||||
dialogs/edititemdialog.h dialogs/edititemdialog.cpp
|
||||
dialogs/settingsdialog.h dialogs/settingsdialog.cpp
|
||||
views/itemdetailmapper.h views/itemdetailmapper.cpp
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
|
||||
@ -64,7 +64,7 @@ void NewItemDialog::createContent() {
|
||||
}
|
||||
|
||||
void NewItemDialog::accept() {
|
||||
QHash<int, QVariant> itemValues;
|
||||
ModelItemValues itemValues;
|
||||
// TODO (after refactoring data structure for input widgets) use iteration through the relevant
|
||||
// roles and their input widgets
|
||||
itemValues.insert(NameRole, m_nameEdit->text());
|
||||
@ -73,7 +73,7 @@ void NewItemDialog::accept() {
|
||||
itemValues.insert(AmountRole, m_amountBox->value());
|
||||
itemValues.insert(FactorRole, m_factorBox->value());
|
||||
|
||||
const QByteArray jsonDoc = JsonParser::itemValuesListToJson({itemValues}, ITEM_KEY_STRING);
|
||||
const QByteArray jsonDoc = JsonParser::itemValuesListToJson({itemValues}, ITEMS_KEY_STRING);
|
||||
emit addItems(jsonDoc);
|
||||
|
||||
// resetContent();
|
||||
|
||||
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
|
||||
@ -10,9 +10,9 @@
|
||||
#include <QUndoView>
|
||||
|
||||
#include "../../ApplicationConfig.h"
|
||||
#include "data/settingshandler.h"
|
||||
#include "dialogs/edititemdialog.h"
|
||||
#include "dialogs/newitemdialog.h"
|
||||
#include "dialogs/settingsdialog.h"
|
||||
#include "genericcore.h"
|
||||
#include "model/generalsortfiltermodel.h"
|
||||
#include "model/tablemodel.h"
|
||||
@ -42,7 +42,7 @@ MainWindow::MainWindow(QWidget* parent)
|
||||
setWindowIcon(QIcon(iconString));
|
||||
#endif
|
||||
|
||||
const QVariantMap settings = SettingsHandler::getSettings("GUI");
|
||||
const QVariantMap settings = m_core->getSettings("GUI");
|
||||
restoreGeometry(settings.value("geometry").toByteArray());
|
||||
restoreState(settings.value("windowState").toByteArray());
|
||||
|
||||
@ -106,8 +106,7 @@ void MainWindow::closeEvent(QCloseEvent* event) {
|
||||
|
||||
if (event->isAccepted()) {
|
||||
qInfo() << "Saving GUI settings...";
|
||||
SettingsHandler::saveSettings({{"geometry", saveGeometry()}, {"windowState", saveState()}},
|
||||
"GUI");
|
||||
m_core->applySettings({{"geometry", saveGeometry()}, {"windowState", saveState()}}, "GUI");
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,11 +296,57 @@ void MainWindow::findItems() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::fetchItems() {
|
||||
showStatusMessage(tr("Invoked 'Server|Fetch items'"));
|
||||
emit m_core->fetchItemsFromServer();
|
||||
}
|
||||
|
||||
void MainWindow::postItems() {
|
||||
showStatusMessage(tr("Invoked 'Server|Post items'"));
|
||||
const QModelIndex currentIndex = ui->tableView->currentIndex();
|
||||
const QByteArray jsonData = m_proxyModel->jsonDataForServer(currentIndex);
|
||||
emit m_core->postItemToServer(jsonData);
|
||||
}
|
||||
|
||||
void MainWindow::deleteItem() {
|
||||
showStatusMessage(tr("Invoked 'Server|Delete items'"));
|
||||
const QModelIndex currentIndex = ui->tableView->currentIndex();
|
||||
// const QByteArray jsonData = m_proxyModel->jsonDataForServer(currentIndex);
|
||||
const QString currentId = m_proxyModel->getUuid(currentIndex);
|
||||
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() {
|
||||
// TODO add generic menu actions (file/new, edit/cut, ...)
|
||||
createFileActions();
|
||||
createUndoActions();
|
||||
createEditActions();
|
||||
createServerActions();
|
||||
createToolsActions();
|
||||
}
|
||||
|
||||
void MainWindow::createFileActions() {
|
||||
@ -433,7 +478,7 @@ void MainWindow::createEditActions() {
|
||||
ui->menu_Edit->addAction(m_openEditItemDialogAct.get());
|
||||
|
||||
m_deleteItemAct = make_unique<QAction>(tr("&Delete item(s)"), this);
|
||||
m_deleteItemAct->setShortcuts(QKeySequence::Delete);
|
||||
m_deleteItemAct->setShortcut(QKeySequence::Delete);
|
||||
m_deleteItemAct->setStatusTip(tr("Delete currently selected item(s)"));
|
||||
// connect(m_deleteItemAct.get(), &QAction::triggered, this, &MainWindow::deleteSelectedtItems);
|
||||
connect(m_deleteItemAct.get(), &QAction::triggered, this, &MainWindow::deleteCurrentItem);
|
||||
@ -448,6 +493,34 @@ void MainWindow::createEditActions() {
|
||||
ui->menu_Edit->addAction(m_findItemAct.get());
|
||||
}
|
||||
|
||||
void MainWindow::createServerActions() {
|
||||
m_fetchItemsAct = make_unique<QAction>(tr("&Fetch item(s)"), this);
|
||||
m_fetchItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Down));
|
||||
m_fetchItemsAct->setStatusTip(tr("Fetches all item on configured server"));
|
||||
connect(m_fetchItemsAct.get(), &QAction::triggered, this, &MainWindow::fetchItems);
|
||||
ui->menu_Server->addAction(m_fetchItemsAct.get());
|
||||
|
||||
m_postItemsAct = make_unique<QAction>(tr("&Post item(s)"), this);
|
||||
m_postItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Up));
|
||||
// m_postItemsAct->setStatusTip(tr("Posts the selected items on configured server"));
|
||||
m_postItemsAct->setStatusTip(tr("Posts the current item on configured server"));
|
||||
connect(m_postItemsAct.get(), &QAction::triggered, this, &MainWindow::postItems);
|
||||
ui->menu_Server->addAction(m_postItemsAct.get());
|
||||
|
||||
m_deleteItemsAct = make_unique<QAction>(tr("&Delete item"), this);
|
||||
m_deleteItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Backspace));
|
||||
// m_deleteItemsAct->setStatusTip(tr("Deletes the selected items on configured server"));
|
||||
m_deleteItemsAct->setStatusTip(tr("Deletes the current item on configured server"));
|
||||
connect(m_deleteItemsAct.get(), &QAction::triggered, this, &MainWindow::deleteItem);
|
||||
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() {
|
||||
QMenu* helpMenu = ui->menu_Help;
|
||||
helpMenu->addSeparator();
|
||||
|
||||
15
mainwindow.h
15
mainwindow.h
@ -63,6 +63,14 @@ class MainWindow : public QMainWindow {
|
||||
/// 'Edit' slots
|
||||
void findItems();
|
||||
|
||||
/// 'Server' slots
|
||||
void fetchItems();
|
||||
void postItems();
|
||||
void deleteItem();
|
||||
|
||||
/// 'Tools' slots
|
||||
void execSettingsDialog();
|
||||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
|
||||
@ -89,6 +97,11 @@ class MainWindow : public QMainWindow {
|
||||
unique_ptr<QAction> m_openEditItemDialogAct;
|
||||
unique_ptr<QAction> m_deleteItemAct;
|
||||
unique_ptr<QAction> m_findItemAct;
|
||||
/// Server actions
|
||||
unique_ptr<QAction> m_fetchItemsAct;
|
||||
unique_ptr<QAction> m_postItemsAct;
|
||||
unique_ptr<QAction> m_deleteItemsAct;
|
||||
|
||||
/// View actions
|
||||
unique_ptr<QAction> m_showModelUndoViewAct;
|
||||
|
||||
@ -101,6 +114,8 @@ class MainWindow : public QMainWindow {
|
||||
void createFileActions();
|
||||
void createUndoActions();
|
||||
void createEditActions();
|
||||
void createServerActions();
|
||||
void createToolsActions();
|
||||
void createHelpMenu();
|
||||
void createGuiDialogs();
|
||||
};
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>25</height>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menu_File">
|
||||
@ -64,9 +64,21 @@
|
||||
</property>
|
||||
<addaction name="actionCheck_for_update"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Server">
|
||||
<property name="title">
|
||||
<string>&Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Tools">
|
||||
<property name="title">
|
||||
<string>&Tools</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menu_File"/>
|
||||
<addaction name="menu_Edit"/>
|
||||
<addaction name="menu_View"/>
|
||||
<addaction name="menu_Server"/>
|
||||
<addaction name="menu_Tools"/>
|
||||
<addaction name="menu_Help"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
|
||||
Reference in New Issue
Block a user