diff --git a/UIs/BeetRoundWidgets/dialogs/newitemdialog.cpp b/UIs/BeetRoundWidgets/dialogs/newitemdialog.cpp index a3760c2..fd6da12 100644 --- a/UIs/BeetRoundWidgets/dialogs/newitemdialog.cpp +++ b/UIs/BeetRoundWidgets/dialogs/newitemdialog.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "formats/jsonparser.h" #include "model/metadata.h" @@ -24,39 +25,82 @@ void NewItemDialog::createContent() { // 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_numberLabel = new QLabel(GET_HEADER_FOR_COLUMN(0)); + m_numberBox = new QSpinBox(); + m_numberBox->setMaximum(1000); - m_descriptionLabel = new QLabel("&Description"); - m_descriptionEdit = new QLineEdit(); - m_descriptionLabel->setBuddy(m_descriptionEdit); + m_lastNameLabel = new QLabel(GET_HEADER_FOR_COLUMN(1)); + m_lastNameEdit = new QLineEdit(); + m_lastNameLabel->setBuddy(m_lastNameEdit); - m_infoLabel = new QLabel("&Info"); - m_infoEdit = new QLineEdit(); - m_infoLabel->setBuddy(m_infoEdit); + m_firstNameLabel = new QLabel(GET_HEADER_FOR_COLUMN(2)); + m_firstNameEdit = new QLineEdit(); + m_firstNameLabel->setBuddy(m_firstNameEdit); - m_amountLabel = new QLabel("&Amount"); - m_amountBox = new QSpinBox(); - m_amountBox->setMaximum(1000); - m_amountLabel->setBuddy(m_amountBox); + 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_factorLabel = new QLabel("&Factor"); - m_factorBox = new QDoubleSpinBox(); - m_factorBox->setMaximum(1000); - m_factorLabel->setBuddy(m_factorBox); + m_amountLabel = new QLabel(GET_HEADER_FOR_COLUMN(4)); + m_amountSpinBox = new QDoubleSpinBox(); + m_amountLabel->setBuddy(m_amountSpinBox); + 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_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); + 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); @@ -67,11 +111,19 @@ 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()); + // 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); diff --git a/UIs/BeetRoundWidgets/dialogs/newitemdialog.h b/UIs/BeetRoundWidgets/dialogs/newitemdialog.h index 23b1987..ee22fbf 100644 --- a/UIs/BeetRoundWidgets/dialogs/newitemdialog.h +++ b/UIs/BeetRoundWidgets/dialogs/newitemdialog.h @@ -3,6 +3,9 @@ #include "abstractdialog.h" +#include + +class QStringListModel; class QDoubleSpinBox; class QLineEdit; class QSpinBox; @@ -24,20 +27,40 @@ class NewItemDialog : public AbstractDialog { // void reject() override; private: - QLabel* m_nameLabel = nullptr; - QLineEdit* m_nameEdit = nullptr; + QLabel* m_numberLabel; + QSpinBox* m_numberBox; - QLabel* m_descriptionLabel = nullptr; - QLineEdit* m_descriptionEdit = nullptr; + QLabel* m_lastNameLabel; + QLineEdit* m_lastNameEdit; - QLabel* m_infoLabel = nullptr; - QLineEdit* m_infoEdit = nullptr; + QLabel* m_firstNameLabel; + QLineEdit* m_firstNameEdit; - QLabel* m_amountLabel = nullptr; - QSpinBox* m_amountBox = nullptr; + QLabel* m_shareTypeLabel; + QComboBox* m_shareTypeBox; + QStringListModel* m_shareTypeModel = nullptr; - QLabel* m_factorLabel = nullptr; - QDoubleSpinBox* m_factorBox = nullptr; + QLabel* m_amountLabel; + QDoubleSpinBox* m_amountSpinBox; + + QLabel* m_biddingTypeLabel; + QComboBox* m_biddingTypeBox; + QStringListModel* m_biddingTypeModel = nullptr; + + QLabel* m_bidding1Label; + QSpinBox* m_bidding1SpinBox; + QLabel* m_bidding2Label; + QSpinBox* m_bidding2SpinBox; + QLabel* m_bidding3Label; + QSpinBox* m_bidding3SpinBox; + + QLabel* m_depotWish1Label; + QLineEdit* m_depotWish1Edit; + QLabel* m_depotWish2Label; + QLineEdit* m_depotWish2Edit; + + QLabel* m_mailLabel; + QLineEdit* m_mailEdit; }; #endif // NEWITEMDIALOG_H diff --git a/UIs/BeetRoundWidgets/views/itemdetailmapper.cpp b/UIs/BeetRoundWidgets/views/itemdetailmapper.cpp index 08f521c..28a2f59 100644 --- a/UIs/BeetRoundWidgets/views/itemdetailmapper.cpp +++ b/UIs/BeetRoundWidgets/views/itemdetailmapper.cpp @@ -1,6 +1,7 @@ #include "itemdetailmapper.h" #include +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include "model/metadata.h" @@ -34,42 +36,84 @@ ItemDetailMapper::ItemDetailMapper(QWidget* parent) /// the individual widgets // REFACTOR deduce label names and types from meta data & use a factory - m_nameLabel = new QLabel("&Name"); - m_nameEdit = new QLineEdit(); - m_nameLabel->setBuddy(m_nameEdit); + m_numberLabel = new QLabel(GET_HEADER_FOR_COLUMN(0)); + m_numberBox = new QSpinBox(); + m_numberBox->setMaximum(1000); - m_descriptionLabel = new QLabel("&Description"); - m_descriptionEdit = new QLineEdit(); - m_descriptionLabel->setBuddy(m_descriptionEdit); + m_lastNameLabel = new QLabel(GET_HEADER_FOR_COLUMN(1)); + m_lastNameEdit = new QLineEdit(); + m_lastNameLabel->setBuddy(m_lastNameEdit); - m_infoLabel = new QLabel("&Info"); - m_infoEdit = new QLineEdit(); - m_infoLabel->setBuddy(m_infoEdit); + m_firstNameLabel = new QLabel(GET_HEADER_FOR_COLUMN(2)); + m_firstNameEdit = new QLineEdit(); + m_firstNameLabel->setBuddy(m_firstNameEdit); - m_amountLabel = new QLabel("&Amount"); - m_amountBox = new QSpinBox(); - m_amountBox->setMaximum(1000); - m_amountLabel->setBuddy(m_amountBox); + 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_factorLabel = new QLabel("&Factor"); - m_factorBox = new QDoubleSpinBox(); - m_factorBox->setMaximum(1000); - m_factorLabel->setBuddy(m_factorBox); + m_amountLabel = new QLabel(GET_HEADER_FOR_COLUMN(4)); + m_amountSpinBox = new QDoubleSpinBox(); + m_amountLabel->setBuddy(m_amountSpinBox); + + 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); 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); + 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); - layout->addWidget(m_previousButton, 5, 0, 1, 1); - layout->addWidget(m_nextButton, 5, 1, 1, 1); + layout->addWidget(m_previousButton, 12, 0, 1, 1); + layout->addWidget(m_nextButton, 12, 1, 1, 1); setLayout(layout); } @@ -81,11 +125,18 @@ void ItemDetailMapper::setModelMappings(QTableView* tableView) { m_selectionModel = tableView->selectionModel(); m_mapper->setModel(m_model); - m_mapper->addMapping(m_nameEdit, 0); - m_mapper->addMapping(m_descriptionEdit, 1); - m_mapper->addMapping(m_infoEdit, 2); - m_mapper->addMapping(m_amountBox, 3); - m_mapper->addMapping(m_factorBox, 4); + m_mapper->addMapping(m_numberBox, 0); + m_mapper->addMapping(m_lastNameEdit, 1); + m_mapper->addMapping(m_firstNameEdit, 2); + m_mapper->addMapping(m_shareTypeBox, 3, "currentText"); + m_mapper->addMapping(m_amountSpinBox, 4); + m_mapper->addMapping(m_biddingTypeBox, 5, "currentText"); + m_mapper->addMapping(m_bidding1SpinBox, 6); + m_mapper->addMapping(m_bidding2SpinBox, 7); + m_mapper->addMapping(m_bidding3SpinBox, 8); + m_mapper->addMapping(m_depotWish1Edit, 9); + m_mapper->addMapping(m_depotWish2Edit, 10); + m_mapper->addMapping(m_mailEdit, 11); m_mapper->setCurrentIndex(m_selectionModel->currentIndex().row()); @@ -119,11 +170,11 @@ void ItemDetailMapper::rowsRemoved(const QModelIndex& parent, int start, int end if (m_model->rowCount() == 0) { setEnabled(false); - m_nameEdit->clear(); - m_descriptionEdit->clear(); - m_infoEdit->clear(); - m_amountBox->clear(); - m_factorBox->clear(); + // m_nameEdit->clear(); + // m_descriptionEdit->clear(); + // m_infoEdit->clear(); + // m_amountBox->clear(); + // m_factorBox->clear(); } updateButtons(m_mapper->currentIndex()); diff --git a/UIs/BeetRoundWidgets/views/itemdetailmapper.h b/UIs/BeetRoundWidgets/views/itemdetailmapper.h index a12d55e..0c9f487 100644 --- a/UIs/BeetRoundWidgets/views/itemdetailmapper.h +++ b/UIs/BeetRoundWidgets/views/itemdetailmapper.h @@ -6,11 +6,13 @@ class QLabel; class QLineEdit; +class QComboBox; class QDoubleSpinBox; class QSpinBox; class QPushButton; class QAbstractItemModel; class QItemSelectionModel; +class QStringListModel; class QTableView; class ItemDetailMapper : public QWidget { @@ -45,21 +47,42 @@ class ItemDetailMapper : public QWidget { std::unique_ptr m_mapper; /// GUI elements - QLabel* m_nameLabel = nullptr; - QLineEdit* m_nameEdit = nullptr; + QLabel* m_numberLabel; + QSpinBox* m_numberBox; - QLabel* m_descriptionLabel = nullptr; - QLineEdit* m_descriptionEdit = nullptr; + QLabel* m_lastNameLabel; + QLineEdit* m_lastNameEdit; - QLabel* m_infoLabel = nullptr; - QLineEdit* m_infoEdit = nullptr; + QLabel* m_firstNameLabel; + QLineEdit* m_firstNameEdit; - QLabel* m_amountLabel = nullptr; - QSpinBox* m_amountBox = nullptr; + QLabel* m_shareTypeLabel; + QComboBox* m_shareTypeBox; + QStringListModel* m_shareTypeModel = nullptr; - QLabel* m_factorLabel = nullptr; - QDoubleSpinBox* m_factorBox = nullptr; + QLabel* m_amountLabel; + QDoubleSpinBox* m_amountSpinBox; + QLabel* m_biddingTypeLabel; + QComboBox* m_biddingTypeBox; + QStringListModel* m_biddingTypeModel = nullptr; + + QLabel* m_bidding1Label; + QSpinBox* m_bidding1SpinBox; + QLabel* m_bidding2Label; + QSpinBox* m_bidding2SpinBox; + QLabel* m_bidding3Label; + QSpinBox* m_bidding3SpinBox; + + QLabel* m_depotWish1Label; + QLineEdit* m_depotWish1Edit; + QLabel* m_depotWish2Label; + QLineEdit* m_depotWish2Edit; + + QLabel* m_mailLabel; + QLineEdit* m_mailEdit; + + /// Model mapper stuff QPushButton* m_nextButton; QPushButton* m_previousButton; }; diff --git a/libs/BeetRoundCore/formats/jsonparser.cpp b/libs/BeetRoundCore/formats/jsonparser.cpp index 8ef90de..3067cc6 100644 --- a/libs/BeetRoundCore/formats/jsonparser.cpp +++ b/libs/BeetRoundCore/formats/jsonparser.cpp @@ -86,14 +86,6 @@ QJsonArray JsonParser::extractItemArray(const QJsonDocument& doc, const QString& ModelItemValues JsonParser::jsonObjectToItemValues(const QJsonObject& itemJsonObject) { ModelItemValues values; - const UserRoles idRole = IdRole; - const QString idRoleName = ROLE_NAMES.value(idRole); - // QVariant idValue = data(idRole); - if (itemJsonObject.contains(idRoleName)) { - std::pair keyValuePair = getKeyValuePair(itemJsonObject, idRole); - values.insert(keyValuePair.first, keyValuePair.second); - } - QListIterator i(USER_FACING_ROLES); while (i.hasNext()) { const UserRoles role = i.next(); diff --git a/libs/BeetRoundCore/model/commands/edititemcommand.cpp b/libs/BeetRoundCore/model/commands/edititemcommand.cpp index f9280f8..449272b 100644 --- a/libs/BeetRoundCore/model/commands/edititemcommand.cpp +++ b/libs/BeetRoundCore/model/commands/edititemcommand.cpp @@ -26,11 +26,6 @@ EditItemCommand::EditItemCommand(TableModel* model, .arg(roleName) .arg(index.data(DEFAULT_ROLE).toString()) .arg(value.toString()); - } else if (role == IdRole) { - commandText = QString("Setting '%1' of item '%2' to '%3'") - .arg(roleName) - .arg(index.data(DEFAULT_ROLE).toString()) - .arg(value.toString()); } else { qWarning() << "Role didn't match! Using a generic command text..."; commandText = QString("Edit item '%1'").arg(index.data(DEFAULT_ROLE).toString()); diff --git a/libs/BeetRoundCore/model/generalsortfiltermodel.cpp b/libs/BeetRoundCore/model/generalsortfiltermodel.cpp index 1dd5cf3..dd7ce69 100644 --- a/libs/BeetRoundCore/model/generalsortfiltermodel.cpp +++ b/libs/BeetRoundCore/model/generalsortfiltermodel.cpp @@ -24,7 +24,7 @@ QItemSelection GeneralSortFilterModel::findItems(const QString& text) const { } QString GeneralSortFilterModel::getUuid(const QModelIndex& itemIndex) const { - return data(itemIndex, IdRole).toString(); + return data(itemIndex, OnlineIdRole).toString(); } QByteArray GeneralSortFilterModel::jsonDataForServer(const QModelIndex& proxyIndex) { diff --git a/libs/BeetRoundCore/model/metadata.h b/libs/BeetRoundCore/model/metadata.h index eadb1d0..5d3d69a 100644 --- a/libs/BeetRoundCore/model/metadata.h +++ b/libs/BeetRoundCore/model/metadata.h @@ -10,29 +10,68 @@ /// model data enum UserRoles { - NameRole = Qt::UserRole + 1, - DescriptionRole, - InfoRole, - AmountRole, - FactorRole, - /// Non user facing - IdRole, - /// read only roles + LastNameRole = Qt::UserRole + 1, + FirstNameRole, + MembershipNumberRole, + Bidding1Role, + Bidding2Role, + Bidding3Role, + DepotWish1Role, + DepotWish2Role, + ShareAmountRole, + MailRole, + ShareTypeRole, + BiddingTypeRole, + OnlineIdRole, + AccessCodeRole, + // read-only (calculated) + FullNameRole, + FactoredBiddingRole, ToStringRole, - ToJsonRole + JsonObjectRole }; -static UserRoles DEFAULT_ROLE = NameRole; +static UserRoles DEFAULT_ROLE = FullNameRole; // TODO ?rename USER_FACING_ROLES -> MAIN_ROLES ? -static QList USER_FACING_ROLES = {NameRole, DescriptionRole, InfoRole, AmountRole, - FactorRole}; -static QHash ROLE_NAMES = { - {NameRole, "name"}, {DescriptionRole, "description"}, {InfoRole, "info"}, - {AmountRole, "amount"}, {FactorRole, "factor"}, {ToStringRole, "ToString"}, - {IdRole, "id"}}; -static QList STRING_ROLES = {NameRole, DescriptionRole, InfoRole, IdRole}; -static QList INT_ROLES = {AmountRole}; -static QList DOUBLE_ROLES = {FactorRole}; +static QList USER_FACING_ROLES = { + LastNameRole, FirstNameRole, MembershipNumberRole, Bidding1Role, Bidding2Role, + Bidding3Role, DepotWish1Role, DepotWish2Role, ShareAmountRole, MailRole, + ShareTypeRole, BiddingTypeRole, OnlineIdRole, AccessCodeRole}; +static QHash ROLE_NAMES = {{MembershipNumberRole, "Mitglieds-nr."}, + {LastNameRole, "Name"}, + {FirstNameRole, "Vorname"}, + {Bidding1Role, "Gebot 1"}, + {Bidding2Role, "Gebot 2"}, + {Bidding3Role, "Gebot 3"}, + {DepotWish1Role, "Wunsch 1"}, + {DepotWish2Role, "Wunsch 2"}, + {ShareAmountRole, "Anzahl"}, + {MailRole, "Mail"}, + {ShareTypeRole, "Art"}, + {BiddingTypeRole, "Bietart"}, + {OnlineIdRole, "Online ID"}, + {AccessCodeRole, "Access Code"}, + {FactoredBiddingRole, "factoredBidding"}}; + +static const QList SHARE_TYPES = {"bezahlt", "teils/teils", "erarbeitet", ""}; +static const QList BIDDING_TYPES = {"paper", "digital", "online", "offline", ""}; + +static QList STRING_ROLES = {LastNameRole, FirstNameRole, DepotWish1Role, + DepotWish2Role, MailRole, ShareTypeRole, + BiddingTypeRole, OnlineIdRole, AccessCodeRole}; +static QList INT_ROLES = { + MembershipNumberRole, + Bidding1Role, + Bidding2Role, + Bidding3Role, +}; +static QList DOUBLE_ROLES = { + ShareAmountRole, +}; + +static const QList TYPE_ROLES = {ShareTypeRole, BiddingTypeRole}; +static const QList SHARE_TYPE_ROLES = {ShareTypeRole}; +static const QList BIDDING_TYPE_ROLES = {BiddingTypeRole}; /// JSON keys static const QString ITEMS_KEY_STRING = "items"; @@ -42,26 +81,53 @@ static const QString ITEM_KEY_STRING = "item"; static const QString ITEMS_FILE_NAME = ITEMS_KEY_STRING + ".json"; /// functions -static int GET_ROLE_FOR_COLUMN(const int column) { +static UserRoles GET_ROLE_FOR_COLUMN(const int column) { switch (column) { case 0: - return NameRole; + return MembershipNumberRole; break; case 1: - return DescriptionRole; + return LastNameRole; break; case 2: - return InfoRole; + return FirstNameRole; break; case 3: - return AmountRole; + return ShareTypeRole; break; case 4: - return FactorRole; + return ShareAmountRole; + break; + case 5: + return BiddingTypeRole; + break; + case 6: + return Bidding1Role; + break; + case 7: + return Bidding2Role; + break; + case 8: + return Bidding3Role; + break; + case 9: + return DepotWish1Role; + break; + case 10: + return DepotWish2Role; + break; + case 11: + return MailRole; + break; + case 12: + return OnlineIdRole; + break; + case 13: + return AccessCodeRole; break; default: - qWarning() << QString("No role found for column %1! Returning 'NameRole'...").arg(column); - return NameRole; + qWarning() << QString("No role found for column %1! Returning 'FullNameRole'...").arg(column); + return FullNameRole; break; } } @@ -74,4 +140,10 @@ static QList GET_HEADER_NAMES() { return result; } +static QString GET_HEADER_FOR_COLUMN(const int column) { + const UserRoles role = GET_ROLE_FOR_COLUMN(column); + const QString headerName = ROLE_NAMES.value(role); + return headerName; +} + #endif // METADATA_H diff --git a/libs/BeetRoundCore/model/modelitem.cpp b/libs/BeetRoundCore/model/modelitem.cpp index 88ac31b..f725673 100644 --- a/libs/BeetRoundCore/model/modelitem.cpp +++ b/libs/BeetRoundCore/model/modelitem.cpp @@ -52,15 +52,7 @@ QString ModelItem::toString() const { const UserRoles role = i.next(); const QString roleName = ROLE_NAMES.value(role); const QVariant value = data(role); - // result.append(value.toString()); - result.append(QString("%1: %2\n").arg(roleName, data(role).toString())); - } - - const UserRoles idRole = IdRole; - QVariant idValue = data(idRole); - if (!idValue.isNull()) { - const QString idRoleName = ROLE_NAMES.value(idRole); - result.append(QString("%1: %2\n").arg(idRoleName, idValue.toString())); + result.append(QString("%1: %2\n").arg(roleName, value.toString())); } return result; } @@ -68,12 +60,6 @@ QString ModelItem::toString() const { QJsonObject ModelItem::toJsonObject() const { QJsonObject itemObject; // TODO add UUID and dates (entry, modification, end) - const UserRoles idRole = IdRole; - QVariant idValue = data(idRole); - if (!idValue.isNull()) { - const QString idRoleName = ROLE_NAMES.value(idRole); - itemObject.insert(idRoleName, idValue.toString()); - } QListIterator i(USER_FACING_ROLES); while (i.hasNext()) { diff --git a/libs/BeetRoundCore/model/tablemodel.cpp b/libs/BeetRoundCore/model/tablemodel.cpp index 76e87a7..3a33f9e 100644 --- a/libs/BeetRoundCore/model/tablemodel.cpp +++ b/libs/BeetRoundCore/model/tablemodel.cpp @@ -21,11 +21,20 @@ QByteArray TableModel::generateExampleItems() { QJsonObject itemObject; // itemObject.insert("uuid", m_uuid.toString()); // itemObject.insert("entryDateUTC", m_entryDateUTC.toString(Qt::ISODate)); - itemObject.insert(ROLE_NAMES.value(NameRole), QString("Item %1").arg(row)); - itemObject.insert(ROLE_NAMES.value(DescriptionRole), QString("This is item %1").arg(row)); - itemObject.insert(ROLE_NAMES.value(InfoRole), QString("Info of item %1").arg(row)); - itemObject.insert(ROLE_NAMES.value(AmountRole), row); - itemObject.insert(ROLE_NAMES.value(FactorRole), row * 1.1); + itemObject.insert(ROLE_NAMES.value(MembershipNumberRole), row); + itemObject.insert(ROLE_NAMES.value(LastNameRole), QString("Nachname%1").arg(row)); + itemObject.insert(ROLE_NAMES.value(FirstNameRole), QString("Vorname%1").arg(row)); + itemObject.insert(ROLE_NAMES.value(Bidding1Role), 100 + row); + itemObject.insert(ROLE_NAMES.value(DepotWish1Role), QString("Depot X%1").arg(row)); + itemObject.insert(ROLE_NAMES.value(DepotWish2Role), QString("Depot Y%1").arg(row)); + itemObject.insert(ROLE_NAMES.value(MailRole), + QString("%1@%2.com") + .arg(itemObject.value(ROLE_NAMES.value(FirstNameRole)).toString(), + itemObject.value(ROLE_NAMES.value(LastNameRole)).toString())); + itemObject.insert(ROLE_NAMES.value(ShareAmountRole), 1); + itemObject.insert(ROLE_NAMES.value(ShareTypeRole), SHARE_TYPES.at(row % 3)); + itemObject.insert(ROLE_NAMES.value(BiddingTypeRole), BIDDING_TYPES.at(row % 4)); + // itemObject.insert(ROLE_NAMES.value(FactorRole), row * 1.1); array.append(itemObject); } @@ -78,16 +87,25 @@ QVariant TableModel::data(const QModelIndex& index, int role) const { case Qt::DisplayRole: case Qt::EditRole: return m_items.at(row)->data(roleForColumn); - case NameRole: - case DescriptionRole: - case InfoRole: - case AmountRole: - case FactorRole: - case IdRole: + case MembershipNumberRole: + case LastNameRole: + case FirstNameRole: + case FullNameRole: + case Bidding1Role: + case Bidding2Role: + case Bidding3Role: + case DepotWish1Role: + case DepotWish2Role: + case ShareAmountRole: + case MailRole: + case ShareTypeRole: + case BiddingTypeRole: + case OnlineIdRole: + case AccessCodeRole: return m_items.at(row)->data(role); case ToStringRole: return m_items.at(row)->toString(); - case ToJsonRole: + case JsonObjectRole: return m_items.at(row)->toJsonObject(); } @@ -174,7 +192,7 @@ QList TableModel::getItemsAsStringLists() const { // TODO use item selection as parameter to wrap multiple items into JSON data structure QByteArray TableModel::jsonDataForServer(const QModelIndex& currentIndex) const { - const QJsonObject itemObject = data(currentIndex, ToJsonRole).toJsonObject(); + const QJsonObject itemObject = data(currentIndex, JsonObjectRole).toJsonObject(); QJsonObject rootObject; rootObject.insert(ITEM_KEY_STRING, itemObject); const QJsonDocument jsonDoc(rootObject); @@ -350,8 +368,9 @@ QModelIndex TableModel::searchItemIndex(const ModelItemValues givenItemValues) c bool TableModel::isItemEqualToItemValues(const QModelIndex& itemIndex, const ModelItemValues givenItemValues) const { /// do both have a UUID? - QVariant idOfItem = data(itemIndex, IdRole); - QVariant given = givenItemValues.value(IdRole); + const UserRoles idRole = OnlineIdRole; + QVariant idOfItem = data(itemIndex, idRole); + QVariant given = givenItemValues.value(idRole); if (idOfItem.isValid() && given.isValid()) { /// are the UUIDs the same? if (idOfItem.toString() == given.toString()) {