Initial commit based on GenericQtClient v0.3.0
This commit is contained in:
51
UIs/GenericWidgets/dialogs/abstractdialog.cpp
Normal file
51
UIs/GenericWidgets/dialogs/abstractdialog.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "abstractdialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGuiApplication>
|
||||
#include <QLabel>
|
||||
#include <QScreen>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
AbstractDialog::AbstractDialog(QDialogButtonBox::StandardButtons buttons, QWidget* parent)
|
||||
: QDialog(parent) {
|
||||
setWindowTitle(tr("Dialog does what?..."));
|
||||
setModal(true);
|
||||
|
||||
m_buttonBox = new QDialogButtonBox(buttons, this);
|
||||
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &AbstractDialog::accept);
|
||||
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &AbstractDialog::reject);
|
||||
|
||||
m_contentContainer = new QLabel("content", this);
|
||||
|
||||
m_outerLayout = new QVBoxLayout;
|
||||
m_outerLayout->addWidget(m_contentContainer);
|
||||
m_outerLayout->addWidget(m_buttonBox);
|
||||
|
||||
setLayout(m_outerLayout);
|
||||
}
|
||||
|
||||
void AbstractDialog::show() {
|
||||
centerInParent();
|
||||
QWidget::show();
|
||||
}
|
||||
|
||||
void AbstractDialog::accept() { QDialog::accept(); }
|
||||
|
||||
void AbstractDialog::reject() { QDialog::reject(); }
|
||||
|
||||
void AbstractDialog::centerInParent() {
|
||||
// BUG the centering in the parent doesn't work the first time (and the later ones seem off too)
|
||||
QWidget* parent = parentWidget();
|
||||
|
||||
if (parent) {
|
||||
auto parentRect = parent->geometry();
|
||||
move(parentRect.center() - rect().center());
|
||||
} else {
|
||||
QRect screenGeometry = QGuiApplication::screens().at(0)->geometry();
|
||||
int x = (screenGeometry.width() - width()) / 2;
|
||||
int y = (screenGeometry.height() - height()) / 2;
|
||||
move(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractDialog::closeEvent(QCloseEvent* event) { QWidget::closeEvent(event); }
|
||||
33
UIs/GenericWidgets/dialogs/abstractdialog.h
Normal file
33
UIs/GenericWidgets/dialogs/abstractdialog.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef ABSTRACTDIALOG_H
|
||||
#define ABSTRACTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
class QGridLayout;
|
||||
class QVBoxLayout;
|
||||
|
||||
class AbstractDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AbstractDialog(QDialogButtonBox::StandardButtons buttons, QWidget* parent = nullptr);
|
||||
virtual void createContent() = 0;
|
||||
|
||||
/// QDialog interface
|
||||
public slots:
|
||||
void show();
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
protected:
|
||||
void centerInParent();
|
||||
|
||||
protected:
|
||||
QWidget* m_contentContainer;
|
||||
QVBoxLayout* m_outerLayout;
|
||||
QDialogButtonBox* m_buttonBox = nullptr;
|
||||
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
};
|
||||
|
||||
#endif // ABSTRACTDIALOG_H
|
||||
57
UIs/GenericWidgets/dialogs/edititemdialog.cpp
Normal file
57
UIs/GenericWidgets/dialogs/edititemdialog.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "edititemdialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../views/itemdetailmapper.h"
|
||||
|
||||
EditItemDialog::EditItemDialog(QTableView* tableView, QWidget* parent)
|
||||
: AbstractDialog(QDialogButtonBox::Ok, parent)
|
||||
, m_tableView(tableView)
|
||||
, m_qrCodeDisplay(new QLabel("QR Code")) {}
|
||||
|
||||
void EditItemDialog::createContent() {
|
||||
if (m_contentContainer) {
|
||||
delete m_contentContainer;
|
||||
}
|
||||
|
||||
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);
|
||||
innerLayout->addWidget(m_detailMapper);
|
||||
|
||||
updateQRCode();
|
||||
connect(m_detailMapper, &ItemDetailMapper::contentChanged, this, &EditItemDialog::updateQRCode);
|
||||
innerLayout->addWidget(m_qrCodeDisplay);
|
||||
|
||||
m_outerLayout->insertWidget(0, m_contentContainer);
|
||||
}
|
||||
|
||||
void EditItemDialog::accept() {
|
||||
m_detailMapper->submit();
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
53
UIs/GenericWidgets/dialogs/edititemdialog.h
Normal file
53
UIs/GenericWidgets/dialogs/edititemdialog.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef EDITITEMDIALOG_H
|
||||
#define EDITITEMDIALOG_H
|
||||
|
||||
#include "QrCodeGenerator.h"
|
||||
#include "abstractdialog.h"
|
||||
|
||||
class QDoubleSpinBox;
|
||||
class QLineEdit;
|
||||
class QSpinBox;
|
||||
class QLabel;
|
||||
class QTableView;
|
||||
|
||||
class ItemDetailMapper;
|
||||
|
||||
class EditItemDialog : public AbstractDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
EditItemDialog(QTableView* tableView, QWidget* parent = nullptr);
|
||||
|
||||
/// AbstractDialog interface
|
||||
void createContent() override;
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
void reject() override;
|
||||
|
||||
private slots:
|
||||
void updateQRCode(const QString text = "");
|
||||
|
||||
private:
|
||||
QTableView* m_tableView = nullptr;
|
||||
ItemDetailMapper* m_detailMapper;
|
||||
|
||||
QLabel* m_nameLabel = nullptr;
|
||||
QLineEdit* m_nameEdit = nullptr;
|
||||
|
||||
QLabel* m_descriptionLabel = nullptr;
|
||||
QLineEdit* m_descriptionEdit = nullptr;
|
||||
|
||||
QLabel* m_infoLabel = nullptr;
|
||||
QLineEdit* m_infoEdit = nullptr;
|
||||
|
||||
QLabel* m_amountLabel = nullptr;
|
||||
QSpinBox* m_amountBox = nullptr;
|
||||
|
||||
QLabel* m_factorLabel = nullptr;
|
||||
QDoubleSpinBox* m_factorBox = nullptr;
|
||||
|
||||
QLabel* m_qrCodeDisplay = nullptr;
|
||||
QrCodeGenerator m_generator;
|
||||
};
|
||||
|
||||
#endif // EDITITEMDIALOG_H
|
||||
81
UIs/GenericWidgets/dialogs/newitemdialog.cpp
Normal file
81
UIs/GenericWidgets/dialogs/newitemdialog.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "newitemdialog.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
#include "formats/jsonparser.h"
|
||||
#include "model/metadata.h"
|
||||
|
||||
NewItemDialog::NewItemDialog(QWidget* parent)
|
||||
: AbstractDialog(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, parent) {}
|
||||
|
||||
void NewItemDialog::createContent() {
|
||||
if (m_contentContainer) {
|
||||
delete m_contentContainer;
|
||||
}
|
||||
|
||||
setWindowTitle(tr("New item..."));
|
||||
|
||||
m_contentContainer = new QWidget(this);
|
||||
|
||||
// REFACTOR use a data structure for input widgets which can be iterated through
|
||||
// using a factory which iterates through the roles from metadata.h
|
||||
// and create the input widgets based on the data type of this role
|
||||
m_nameLabel = new QLabel("&Name");
|
||||
m_nameEdit = new QLineEdit();
|
||||
m_nameLabel->setBuddy(m_nameEdit);
|
||||
|
||||
m_descriptionLabel = new QLabel("&Description");
|
||||
m_descriptionEdit = new QLineEdit();
|
||||
m_descriptionLabel->setBuddy(m_descriptionEdit);
|
||||
|
||||
m_infoLabel = new QLabel("&Info");
|
||||
m_infoEdit = new QLineEdit();
|
||||
m_infoLabel->setBuddy(m_infoEdit);
|
||||
|
||||
m_amountLabel = new QLabel("&Amount");
|
||||
m_amountBox = new QSpinBox();
|
||||
m_amountBox->setMaximum(1000);
|
||||
m_amountLabel->setBuddy(m_amountBox);
|
||||
|
||||
m_factorLabel = new QLabel("&Factor");
|
||||
m_factorBox = new QDoubleSpinBox();
|
||||
m_factorBox->setMaximum(1000);
|
||||
m_factorLabel->setBuddy(m_factorBox);
|
||||
|
||||
QGridLayout* layout = new QGridLayout();
|
||||
layout->addWidget(m_nameLabel, 0, 0, 1, 1);
|
||||
layout->addWidget(m_nameEdit, 0, 1, 1, 1);
|
||||
layout->addWidget(m_descriptionLabel, 1, 0, 1, 1);
|
||||
layout->addWidget(m_descriptionEdit, 1, 1, 1, 1);
|
||||
layout->addWidget(m_infoLabel, 2, 0, 1, 1);
|
||||
layout->addWidget(m_infoEdit, 2, 1, 1, 1);
|
||||
layout->addWidget(m_amountLabel, 3, 0, 1, 1);
|
||||
layout->addWidget(m_amountBox, 3, 1, 1, 1);
|
||||
layout->addWidget(m_factorLabel, 4, 0, 1, 1);
|
||||
layout->addWidget(m_factorBox, 4, 1, 1, 1);
|
||||
|
||||
m_contentContainer->setLayout(layout);
|
||||
|
||||
m_outerLayout->insertWidget(0, m_contentContainer);
|
||||
}
|
||||
|
||||
void NewItemDialog::accept() {
|
||||
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());
|
||||
itemValues.insert(DescriptionRole, m_descriptionEdit->text());
|
||||
itemValues.insert(InfoRole, m_infoEdit->text());
|
||||
itemValues.insert(AmountRole, m_amountBox->value());
|
||||
itemValues.insert(FactorRole, m_factorBox->value());
|
||||
|
||||
const QByteArray jsonDoc = JsonParser::itemValuesListToJson({itemValues}, ITEMS_KEY_STRING);
|
||||
emit addItems(jsonDoc);
|
||||
|
||||
// resetContent();
|
||||
AbstractDialog::accept();
|
||||
}
|
||||
43
UIs/GenericWidgets/dialogs/newitemdialog.h
Normal file
43
UIs/GenericWidgets/dialogs/newitemdialog.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef NEWITEMDIALOG_H
|
||||
#define NEWITEMDIALOG_H
|
||||
|
||||
#include "abstractdialog.h"
|
||||
|
||||
class QDoubleSpinBox;
|
||||
class QLineEdit;
|
||||
class QSpinBox;
|
||||
class QLabel;
|
||||
|
||||
class NewItemDialog : public AbstractDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NewItemDialog(QWidget* parent = nullptr);
|
||||
|
||||
void createContent() override;
|
||||
|
||||
signals:
|
||||
void addItems(const QByteArray& jsonDoc);
|
||||
|
||||
public slots:
|
||||
void accept() override;
|
||||
// void reject() override;
|
||||
|
||||
private:
|
||||
QLabel* m_nameLabel = nullptr;
|
||||
QLineEdit* m_nameEdit = nullptr;
|
||||
|
||||
QLabel* m_descriptionLabel = nullptr;
|
||||
QLineEdit* m_descriptionEdit = nullptr;
|
||||
|
||||
QLabel* m_infoLabel = nullptr;
|
||||
QLineEdit* m_infoEdit = nullptr;
|
||||
|
||||
QLabel* m_amountLabel = nullptr;
|
||||
QSpinBox* m_amountBox = nullptr;
|
||||
|
||||
QLabel* m_factorLabel = nullptr;
|
||||
QDoubleSpinBox* m_factorBox = nullptr;
|
||||
};
|
||||
|
||||
#endif // NEWITEMDIALOG_H
|
||||
63
UIs/GenericWidgets/dialogs/settingsdialog.cpp
Normal file
63
UIs/GenericWidgets/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
UIs/GenericWidgets/dialogs/settingsdialog.h
Normal file
23
UIs/GenericWidgets/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
|
||||
Reference in New Issue
Block a user