#ifndef TABLEMODEL_H #define TABLEMODEL_H #include #include "metadata.h" class bidding; class QUndoStack; class ModelItem; using namespace std; typedef QMap ModelItemValues; class TableModel : public QAbstractTableModel { Q_OBJECT friend class InsertRowsCommand; friend class RemoveRowsCommand; friend class EditItemCommand; public: static QByteArray generateExampleItems(); explicit TableModel(QUndoStack* undoStack, QObject* parent = nullptr); /// QAbstractItemModel interface Qt::ItemFlags flags(const QModelIndex& index) const override; QHash roleNames() const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; int columnCount(const QModelIndex& parent = QModelIndex()) const override; QVariant data(const QModelIndex& index, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; bool setData(const QModelIndex& index, const QVariant& value, int role) override; bool setItemData(const QModelIndex& index, const QMap& roles) override; ModelItemValues getItemValues(const QModelIndex& index) const; QJsonDocument getAllItemsAsJsonDoc() const; QList getItemsAsStringLists() const; QByteArray jsonDataForServer(const QModelIndex& currentIndex) const; QString updateItemsFromJson(const QByteArray& jsonData); bool updateItem(const ModelItemValues& itemValues); void setOnlineCredentials(const QString& mail, const QString& uuid, const QString& token); QJsonDocument getMailInviteJsonDoc(const QString& mail, const QString& serverUrl) const; void updateBiddings(const QList biddings); public slots: // bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex()) // override; bool removeRows(int firstRow, int nRows, const QModelIndex& parentIndex = QModelIndex()) override; void appendItems(const QByteArray& jsonDoc); void insertItems(int startPosition, const QByteArray& jsonDoc, const QModelIndex& parentIndex = QModelIndex()); void insertItems(int startPosition, const QList& itemValuesList, const QModelIndex& parentIndex = QModelIndex()); /// property functions qreal nTotalExpectedShares() const; int nExpectedBiddings() const; int nPlacedBiddings1() const; int nPlacedBiddings2() const; int nPlacedBiddings3() const; int biddingSum1() const; int biddingSum2() const; int biddingSum3() const; qreal biddingAverage1() const; qreal biddingAverage2() const; qreal biddingAverage3() const; signals: void rowCountChanged(); void nExpectedBiddingsChanged(); void nTotalExpectedSharesChanged(); void nPlacedBiddingsChanged(const int roundNumber); void biddingSumChanged(const int roundNumber); void biddingAverageChanged(const int roundNumber); private slots: void onRowCountChanged(const QModelIndex& parent, int first, int last); private: /// *** members *** // TODO shared_ptr -> unique_ptr QList> m_items; QUndoStack* m_undoStack; /// *** functions *** /// undo/redo functions void execInsertItems(const int firstRow, const QList valueList); void execRemoveItems(const int firstRow, const int nRows); void execEditItemData(const int row, const QMap& changedValues); /// misc functions QMap onlyChangedValues(const QModelIndex& index, const QMap& roleValueMap) const; bool isEmptyValueEqualToZero(const int role) const; QModelIndex searchItemIndex(const ModelItemValues givenItemValues) const; bool isItemEqualToItemValues(const QModelIndex& itemIndex, const ModelItemValues givenItemValues) const; int nPlacedBiddings(const UserRoles biddingRole) const; int biddingSum(const UserRoles biddingRole) const; qreal averageBiddingAmount(const UserRoles biddingRole) const; qreal totalSharesWithBiddings(const UserRoles biddingRole) const; QModelIndex getIndexByRoleValue(const QString& valueString, const int role) const; QMap getItemValues(const bidding bid); }; #endif // TABLEMODEL_H