Compare commits
11 Commits
c83ba2da9d
...
5e3950f6ba
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e3950f6ba | |||
| 34a34891b4 | |||
| 4c4d734b1b | |||
| 0eef55fc32 | |||
| d109eb31f8 | |||
| a9f24ac8f2 | |||
| 67d9a3914d | |||
| 518bebcbb7 | |||
| 8f61c6bc2f | |||
| a966b26185 | |||
| a8bf5b4032 |
@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(TARGET_APP "GenericQtClient-Widgets")
|
||||
project(${TARGET_APP} VERSION 0.2.0 LANGUAGES CXX)
|
||||
project(${TARGET_APP} VERSION 0.3.0 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
@ -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:
|
||||
@ -63,6 +64,8 @@ target_link_libraries(${TARGET_APP} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
target_include_directories(${TARGET_APP} PRIVATE ${CORE_LIB_DIR}/)
|
||||
target_link_libraries(${TARGET_APP} PRIVATE GenericCore)
|
||||
target_include_directories(${TARGET_APP} PRIVATE ${QR_LIB_DIR}/src)
|
||||
target_link_libraries(${TARGET_APP} PRIVATE qrcode)
|
||||
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
#include "edititemdialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../views/itemdetailmapper.h"
|
||||
|
||||
EditItemDialog::EditItemDialog(QTableView* tableView, QWidget* parent)
|
||||
: AbstractDialog(QDialogButtonBox::Close, parent)
|
||||
, m_tableView(tableView) {}
|
||||
: AbstractDialog(QDialogButtonBox::Ok, parent)
|
||||
, m_tableView(tableView)
|
||||
, m_qrCodeDisplay(new QLabel("QR Code")) {}
|
||||
|
||||
void EditItemDialog::createContent() {
|
||||
if (m_contentContainer) {
|
||||
@ -16,9 +18,17 @@ void EditItemDialog::createContent() {
|
||||
|
||||
setWindowTitle(tr("Edit item..."));
|
||||
|
||||
m_contentContainer = new QWidget(this);
|
||||
QHBoxLayout* innerLayout = new QHBoxLayout();
|
||||
m_contentContainer->setLayout(innerLayout);
|
||||
|
||||
m_detailMapper = new ItemDetailMapper(this);
|
||||
m_detailMapper->setModelMappings(m_tableView);
|
||||
m_contentContainer = m_detailMapper;
|
||||
innerLayout->addWidget(m_detailMapper);
|
||||
|
||||
updateQRCode();
|
||||
connect(m_detailMapper, &ItemDetailMapper::contentChanged, this, &EditItemDialog::updateQRCode);
|
||||
innerLayout->addWidget(m_qrCodeDisplay);
|
||||
|
||||
m_outerLayout->insertWidget(0, m_contentContainer);
|
||||
}
|
||||
@ -32,3 +42,16 @@ void EditItemDialog::reject() {
|
||||
m_detailMapper->revert();
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void EditItemDialog::updateQRCode(const QString text) {
|
||||
QImage unscaledImage;
|
||||
if (text.isEmpty()) {
|
||||
unscaledImage = QImage("://no-picture-taking.png");
|
||||
} else {
|
||||
unscaledImage = m_generator.generateQr(text);
|
||||
}
|
||||
QImage image = unscaledImage.scaled(250, 250);
|
||||
|
||||
m_qrCodeDisplay->setPixmap(QPixmap::fromImage(image));
|
||||
m_qrCodeDisplay->setToolTip(text);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#ifndef EDITITEMDIALOG_H
|
||||
#define EDITITEMDIALOG_H
|
||||
|
||||
#include "QrCodeGenerator.h"
|
||||
#include "abstractdialog.h"
|
||||
|
||||
class QDoubleSpinBox;
|
||||
@ -23,6 +24,9 @@ class EditItemDialog : public AbstractDialog {
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
private slots:
|
||||
void updateQRCode(const QString text = "");
|
||||
|
||||
private:
|
||||
QTableView* m_tableView = nullptr;
|
||||
ItemDetailMapper* m_detailMapper;
|
||||
@ -41,6 +45,9 @@ class EditItemDialog : public AbstractDialog {
|
||||
|
||||
QLabel* m_factorLabel = nullptr;
|
||||
QDoubleSpinBox* m_factorBox = nullptr;
|
||||
|
||||
QLabel* m_qrCodeDisplay = nullptr;
|
||||
QrCodeGenerator m_generator;
|
||||
};
|
||||
|
||||
#endif // EDITITEMDIALOG_H
|
||||
|
||||
@ -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();
|
||||
|
||||
63
dialogs/settingsdialog.cpp
Normal file
63
dialogs/settingsdialog.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#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();
|
||||
m_emailEdit->setEnabled(false);
|
||||
serverLayout->addWidget(emailLabel, 1, 0);
|
||||
serverLayout->addWidget(m_emailEdit, 1, 1);
|
||||
QLabel* passwordLabel = new QLabel("Password:");
|
||||
m_passwordEdit = new QLineEdit();
|
||||
m_passwordEdit->setEnabled(false);
|
||||
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"/>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
#include <QTableView>
|
||||
#include "model/metadata.h"
|
||||
|
||||
ItemDetailMapper::ItemDetailMapper(QWidget* parent)
|
||||
: QWidget{parent} {
|
||||
@ -101,12 +102,13 @@ bool ItemDetailMapper::submit() { return m_mapper->submit(); }
|
||||
void ItemDetailMapper::revert() { m_mapper->revert(); }
|
||||
|
||||
void ItemDetailMapper::onCurrentIndexChanged(const QModelIndex& current,
|
||||
const QModelIndex& previous) {
|
||||
const QModelIndex& /*previous*/) {
|
||||
if (!isEnabled()) {
|
||||
setEnabled(true);
|
||||
}
|
||||
m_mapper->setCurrentModelIndex(current);
|
||||
updateButtons(current.row());
|
||||
emitContentChanged(current);
|
||||
}
|
||||
|
||||
void ItemDetailMapper::rowsInserted(const QModelIndex& parent, int start, int end) {
|
||||
@ -147,3 +149,12 @@ void ItemDetailMapper::updateButtons(int row) {
|
||||
m_previousButton->setEnabled(row > 0);
|
||||
m_nextButton->setEnabled(row < m_model->rowCount() - 1);
|
||||
}
|
||||
|
||||
void ItemDetailMapper::emitContentChanged(const QModelIndex& currentIndex) {
|
||||
// BUG QR-Code isn't updated after changes through the ItemDetailMapper #18
|
||||
QString toStringText = "";
|
||||
if (currentIndex.isValid()) {
|
||||
toStringText = currentIndex.data(ToStringRole).toString();
|
||||
}
|
||||
emit contentChanged(toStringText);
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ class ItemDetailMapper : public QWidget {
|
||||
void revert();
|
||||
|
||||
signals:
|
||||
void contentChanged(const QString text);
|
||||
|
||||
private slots:
|
||||
void onCurrentIndexChanged(const QModelIndex& current, const QModelIndex& previous);
|
||||
@ -32,6 +33,7 @@ class ItemDetailMapper : public QWidget {
|
||||
void toPrevious();
|
||||
void toNext();
|
||||
void updateButtons(int row);
|
||||
void emitContentChanged(const QModelIndex& currentIndex);
|
||||
|
||||
private:
|
||||
/// *** members ***
|
||||
|
||||
Reference in New Issue
Block a user