150 lines
5.7 KiB
C++
150 lines
5.7 KiB
C++
#include "newitemdialog.h"
|
|
|
|
#include <QGridLayout>
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QSpinBox>
|
|
#include <QStringListModel>
|
|
#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_numberLabel = new QLabel(GET_HEADER_FOR_COLUMN(0));
|
|
m_numberBox = new QSpinBox();
|
|
m_numberBox->setMaximum(1000);
|
|
|
|
m_lastNameLabel = new QLabel(GET_HEADER_FOR_COLUMN(1));
|
|
m_lastNameEdit = new QLineEdit();
|
|
m_lastNameLabel->setBuddy(m_lastNameEdit);
|
|
|
|
m_firstNameLabel = new QLabel(GET_HEADER_FOR_COLUMN(2));
|
|
m_firstNameEdit = new QLineEdit();
|
|
m_firstNameLabel->setBuddy(m_firstNameEdit);
|
|
|
|
m_shareTypeLabel = new QLabel(GET_HEADER_FOR_COLUMN(3));
|
|
m_shareTypeBox = new QComboBox();
|
|
m_shareTypeLabel->setBuddy(m_shareTypeBox);
|
|
m_shareTypeModel = new QStringListModel(SHARE_TYPES, this);
|
|
m_shareTypeBox->setModel(m_shareTypeModel);
|
|
|
|
m_amountLabel = new QLabel(GET_HEADER_FOR_COLUMN(4));
|
|
m_amountSpinBox = new QDoubleSpinBox();
|
|
m_amountLabel->setBuddy(m_amountSpinBox);
|
|
m_amountSpinBox->setValue(1.0);
|
|
|
|
m_biddingTypeLabel = new QLabel(GET_HEADER_FOR_COLUMN(5));
|
|
m_biddingTypeBox = new QComboBox();
|
|
m_biddingTypeLabel->setBuddy(m_biddingTypeBox);
|
|
m_biddingTypeModel = new QStringListModel(BIDDING_TYPES, this);
|
|
m_biddingTypeBox->setModel(m_biddingTypeModel);
|
|
|
|
m_bidding1Label = new QLabel(GET_HEADER_FOR_COLUMN(6));
|
|
m_bidding1SpinBox = new QSpinBox();
|
|
m_bidding1SpinBox->setMaximum(500);
|
|
m_bidding2Label = new QLabel(GET_HEADER_FOR_COLUMN(7));
|
|
m_bidding2SpinBox = new QSpinBox();
|
|
m_bidding2SpinBox->setMaximum(500);
|
|
m_bidding3Label = new QLabel(GET_HEADER_FOR_COLUMN(8));
|
|
m_bidding3SpinBox = new QSpinBox();
|
|
m_bidding3SpinBox->setMaximum(500);
|
|
|
|
m_depotWish1Label = new QLabel(GET_HEADER_FOR_COLUMN(9));
|
|
m_depotWish1Edit = new QLineEdit();
|
|
m_depotWish1Label->setBuddy(m_depotWish1Edit);
|
|
m_depotWish2Label = new QLabel(GET_HEADER_FOR_COLUMN(10));
|
|
m_depotWish2Edit = new QLineEdit();
|
|
m_depotWish2Label->setBuddy(m_depotWish2Edit);
|
|
|
|
m_mailLabel = new QLabel(GET_HEADER_FOR_COLUMN(11));
|
|
m_mailEdit = new QLineEdit();
|
|
m_mailEdit->setMinimumWidth(200);
|
|
m_mailLabel->setBuddy(m_mailEdit);
|
|
|
|
/// layouting
|
|
QGridLayout* layout = new QGridLayout();
|
|
layout->addWidget(m_numberLabel, 0, 0, 1, 1);
|
|
layout->addWidget(m_numberBox, 0, 1, 1, 1);
|
|
layout->addWidget(m_lastNameLabel, 1, 0, 1, 1);
|
|
layout->addWidget(m_lastNameEdit, 1, 1, 1, 1);
|
|
layout->addWidget(m_firstNameLabel, 2, 0, 1, 1);
|
|
layout->addWidget(m_firstNameEdit, 2, 1, 1, 1);
|
|
layout->addWidget(m_shareTypeLabel, 3, 0, 1, 1);
|
|
layout->addWidget(m_shareTypeBox, 3, 1, 1, 1);
|
|
layout->addWidget(m_amountLabel, 4, 0, 1, 1);
|
|
layout->addWidget(m_amountSpinBox, 4, 1, 1, 1);
|
|
layout->addWidget(m_biddingTypeLabel, 5, 0, 1, 1);
|
|
layout->addWidget(m_biddingTypeBox, 5, 1, 1, 1);
|
|
layout->addWidget(m_bidding1Label, 6, 0, 1, 1);
|
|
layout->addWidget(m_bidding1SpinBox, 6, 1, 1, 1);
|
|
layout->addWidget(m_bidding2Label, 7, 0, 1, 1);
|
|
layout->addWidget(m_bidding2SpinBox, 7, 1, 1, 1);
|
|
layout->addWidget(m_bidding3Label, 8, 0, 1, 1);
|
|
layout->addWidget(m_bidding3SpinBox, 8, 1, 1, 1);
|
|
layout->addWidget(m_depotWish1Label, 9, 0, 1, 1);
|
|
layout->addWidget(m_depotWish1Edit, 9, 1, 1, 1);
|
|
layout->addWidget(m_depotWish2Label, 10, 0, 1, 1);
|
|
layout->addWidget(m_depotWish2Edit, 10, 1, 1, 1);
|
|
layout->addWidget(m_mailLabel, 11, 0, 1, 1);
|
|
layout->addWidget(m_mailEdit, 11, 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(LastNameRole, m_nameEdit->text());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(0), m_numberBox->value());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(1), m_lastNameEdit->text());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(2), m_firstNameEdit->text());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(3), m_shareTypeBox->currentText());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(4), m_amountSpinBox->value());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(5), m_biddingTypeBox->currentText());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(6), m_bidding1SpinBox->value());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(7), m_bidding2SpinBox->value());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(8), m_bidding3SpinBox->value());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(9), m_depotWish1Edit->text());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(10), m_depotWish2Edit->text());
|
|
itemValues.insert(GET_ROLE_FOR_COLUMN(11), m_mailEdit->text());
|
|
|
|
const QByteArray jsonDoc = JsonParser::itemValuesListToJson({itemValues}, ITEMS_KEY_STRING);
|
|
emit addItems(jsonDoc);
|
|
|
|
resetContent();
|
|
AbstractDialog::accept();
|
|
}
|
|
|
|
void NewItemDialog::resetContent() {
|
|
m_numberBox->setValue(0);
|
|
m_lastNameEdit->setText("");
|
|
m_firstNameEdit->setText("");
|
|
m_shareTypeBox->setCurrentIndex(0);
|
|
m_amountSpinBox->setValue(1);
|
|
m_biddingTypeBox->setCurrentIndex(0);
|
|
m_bidding1SpinBox->setValue(0);
|
|
m_bidding2SpinBox->setValue(0);
|
|
m_bidding3SpinBox->setValue(0);
|
|
m_depotWish1Edit->setText("");
|
|
m_depotWish2Edit->setText("");
|
|
m_mailEdit->setText("");
|
|
}
|