Compare commits
2 Commits
12e5596b34
...
683f5d224c
| Author | SHA1 | Date | |
|---|---|---|---|
| 683f5d224c | |||
| bcba8f8452 |
@ -6,12 +6,12 @@
|
|||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
AbstractDialog::AbstractDialog(QWidget* parent)
|
AbstractDialog::AbstractDialog(QDialogButtonBox::StandardButtons buttons, QWidget* parent)
|
||||||
: QDialog(parent) {
|
: QDialog(parent) {
|
||||||
setWindowTitle(tr("Dialog does what?..."));
|
setWindowTitle(tr("Dialog does what?..."));
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
|
||||||
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
m_buttonBox = new QDialogButtonBox(buttons, this);
|
||||||
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &AbstractDialog::accept);
|
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &AbstractDialog::accept);
|
||||||
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &AbstractDialog::reject);
|
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &AbstractDialog::reject);
|
||||||
|
|
||||||
|
|||||||
@ -2,15 +2,15 @@
|
|||||||
#define ABSTRACTDIALOG_H
|
#define ABSTRACTDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
|
||||||
class QGridLayout;
|
class QGridLayout;
|
||||||
class QDialogButtonBox;
|
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
|
||||||
class AbstractDialog : public QDialog {
|
class AbstractDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AbstractDialog(QWidget* parent = nullptr);
|
AbstractDialog(QDialogButtonBox::StandardButtons buttons, QWidget* parent = nullptr);
|
||||||
virtual void createContent() = 0;
|
virtual void createContent() = 0;
|
||||||
|
|
||||||
/// QDialog interface
|
/// QDialog interface
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
#include "edititemdialog.h"
|
#include "edititemdialog.h"
|
||||||
|
|
||||||
|
#include <QDialogButtonBox>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#include "../views/itemdetailmapper.h"
|
#include "../views/itemdetailmapper.h"
|
||||||
|
|
||||||
EditItemDialog::EditItemDialog(QTableView* tableView, QWidget* parent)
|
EditItemDialog::EditItemDialog(QTableView* tableView, QWidget* parent)
|
||||||
: AbstractDialog(parent)
|
: AbstractDialog(QDialogButtonBox::Close, parent)
|
||||||
, m_tableView(tableView) {}
|
, m_tableView(tableView) {}
|
||||||
|
|
||||||
void EditItemDialog::createContent() {
|
void EditItemDialog::createContent() {
|
||||||
|
|||||||
@ -6,11 +6,11 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
|
#include "formats/jsonparser.h"
|
||||||
#include <model/tablemodel.h>
|
#include "model/metadata.h"
|
||||||
|
|
||||||
NewItemDialog::NewItemDialog(QWidget* parent)
|
NewItemDialog::NewItemDialog(QWidget* parent)
|
||||||
: AbstractDialog(parent) {}
|
: AbstractDialog(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, parent) {}
|
||||||
|
|
||||||
void NewItemDialog::createContent() {
|
void NewItemDialog::createContent() {
|
||||||
if (m_contentContainer) {
|
if (m_contentContainer) {
|
||||||
@ -21,7 +21,9 @@ void NewItemDialog::createContent() {
|
|||||||
|
|
||||||
m_contentContainer = new QWidget(this);
|
m_contentContainer = new QWidget(this);
|
||||||
|
|
||||||
// REFACTOR deduce label names and types from meta data & use a factory
|
// 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_nameLabel = new QLabel("&Name");
|
||||||
m_nameEdit = new QLineEdit();
|
m_nameEdit = new QLineEdit();
|
||||||
m_nameLabel->setBuddy(m_nameEdit);
|
m_nameLabel->setBuddy(m_nameEdit);
|
||||||
@ -62,18 +64,17 @@ void NewItemDialog::createContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NewItemDialog::accept() {
|
void NewItemDialog::accept() {
|
||||||
QJsonObject itemObject;
|
QHash<int, QVariant> itemValues;
|
||||||
itemObject.insert("Name", m_nameEdit->text());
|
// TODO (after refactoring data structure for input widgets) use iteration through the relevant
|
||||||
itemObject.insert("Description", m_descriptionEdit->text());
|
// roles and their input widgets
|
||||||
itemObject.insert("Info", m_infoEdit->text());
|
itemValues.insert(NameRole, m_nameEdit->text());
|
||||||
itemObject.insert("Amount", m_amountBox->value());
|
itemValues.insert(DescriptionRole, m_descriptionEdit->text());
|
||||||
itemObject.insert("Factor", m_factorBox->value());
|
itemValues.insert(InfoRole, m_infoEdit->text());
|
||||||
|
itemValues.insert(AmountRole, m_amountBox->value());
|
||||||
|
itemValues.insert(FactorRole, m_factorBox->value());
|
||||||
|
|
||||||
QJsonDocument jsonDoc;
|
const QByteArray jsonDoc = JsonParser::itemValuesListToJson({itemValues}, ITEM_KEY_STRING);
|
||||||
QJsonArray itemArray;
|
emit addItems(jsonDoc);
|
||||||
itemArray.append(itemObject);
|
|
||||||
jsonDoc.setArray(itemArray);
|
|
||||||
emit addItems(jsonDoc.toJson(QJsonDocument::Compact));
|
|
||||||
|
|
||||||
// resetContent();
|
// resetContent();
|
||||||
AbstractDialog::accept();
|
AbstractDialog::accept();
|
||||||
|
|||||||
@ -329,10 +329,6 @@ void MainWindow::createUndoActions() {
|
|||||||
// connect(m_showUndoViewAction, &QAction::toggled, this, &MainWindow::onShowUndoViewToggled);
|
// connect(m_showUndoViewAction, &QAction::toggled, this, &MainWindow::onShowUndoViewToggled);
|
||||||
connect(m_showModelUndoViewAct.get(), &QAction::triggered, this,
|
connect(m_showModelUndoViewAct.get(), &QAction::triggered, this,
|
||||||
&MainWindow::onShowUndoViewToggled);
|
&MainWindow::onShowUndoViewToggled);
|
||||||
|
|
||||||
// TODO ? add a keyboard short cut?
|
|
||||||
// m_showUndoViewAction->setShortcuts(QKeySequence::Copy);
|
|
||||||
|
|
||||||
ui->menu_View->addAction(m_showModelUndoViewAct.get());
|
ui->menu_View->addAction(m_showModelUndoViewAct.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,14 @@ ItemDetailMapper::ItemDetailMapper(QWidget* parent)
|
|||||||
: QWidget{parent} {
|
: QWidget{parent} {
|
||||||
/// model mapping
|
/// model mapping
|
||||||
m_mapper = std::make_unique<QDataWidgetMapper>(this);
|
m_mapper = std::make_unique<QDataWidgetMapper>(this);
|
||||||
m_mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
/// BUG: If multiple columns are changed not all changes are applied.
|
||||||
|
/// Multiple changes are set individually by calling setData().
|
||||||
|
/// Probably due to a conflicting dataChanged signal for too many roles&columns the data of
|
||||||
|
/// the remaining columns is reset before setData is called.
|
||||||
|
/// And a manual submit would also create multiple undo steps anyway.
|
||||||
|
/// Workaround: ManualSubmit -> AutoSubmit
|
||||||
|
// m_mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
||||||
|
m_mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
|
||||||
|
|
||||||
/// model mapping buttons
|
/// model mapping buttons
|
||||||
m_nextButton = new QPushButton(tr("Ne&xt"));
|
m_nextButton = new QPushButton(tr("Ne&xt"));
|
||||||
|
|||||||
Reference in New Issue
Block a user