diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-17 18:59:50 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-17 18:59:50 -0300 |
commit | ae68ae38bbbc981aab4b8eaf1e84a15b8ab05bf4 (patch) | |
tree | 1b8cd2c26c573aa444f701ee0848a22d4ad1d8e0 /qt-ui/models.h | |
parent | 14ccbbf6e87b69267426ae69c402c1bae70ec5d5 (diff) | |
download | subsurface-ae68ae38bbbc981aab4b8eaf1e84a15b8ab05bf4.tar.gz |
Changed a lot of code to reduce boilerplate on models in the future.
So, I changed a lot of code to reduce boilerplate on models in the
future. Currently we do not have a lot of models, but this can increase
quite rapdly. There's a second TreeModel in the works, the Yearly
Statistics, this patch will save around 250 LOC for this new model,
and more and more models will give us a greater saving.
Iwll do that for the table models in the future too - I did the tree
models now because they are the most complex case and I didn't wanted
to create a second tree model without this.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/models.h')
-rw-r--r-- | qt-ui/models.h | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/qt-ui/models.h b/qt-ui/models.h index b61c79cd6..67e7e3b98 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -123,51 +123,54 @@ private: * */ -struct TreeItemDT { +struct TreeItem { Q_DECLARE_TR_FUNCTIONS (TreeItemDT); public: - enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT, - SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS }; - - enum ExtraRoles{STAR_ROLE = Qt::UserRole + 1, DIVE_ROLE, SORT_ROLE}; - - virtual ~TreeItemDT(); - int columnCount() const { - return COLUMNS; - }; + virtual ~TreeItem(); virtual QVariant data (int column, int role) const; int row() const; - QList<TreeItemDT *> children; - TreeItemDT *parent; + QList<TreeItem*> children; + TreeItem *parent; }; struct TripItem; -class DiveTripModel : public QAbstractItemModel +class TreeModel : public QAbstractItemModel { Q_OBJECT public: - enum Layout{TREE, LIST, CURRENT}; + TreeModel(QObject *parent = 0); + virtual ~TreeModel(); - DiveTripModel(QObject *parent = 0); - ~DiveTripModel(); - - /*reimp*/ Qt::ItemFlags flags(const QModelIndex &index) const; - /*reimp*/ QVariant data(const QModelIndex &index, int role) const; - /*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + virtual QVariant data(const QModelIndex &index, int role) const; /*reimp*/ int rowCount(const QModelIndex &parent = QModelIndex()) const; /*reimp*/ int columnCount(const QModelIndex &parent = QModelIndex()) const; /*reimp*/ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; /*reimp*/ QModelIndex parent(const QModelIndex &child) const; +protected: + int columns; + TreeItem *rootItem; +}; + +class DiveTripModel : public TreeModel { +public: + enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT, + SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS }; + + enum ExtraRoles{STAR_ROLE = Qt::UserRole + 1, DIVE_ROLE, SORT_ROLE}; + enum Layout{TREE, LIST, CURRENT}; + + Qt::ItemFlags flags(const QModelIndex &index) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + DiveTripModel(QObject* parent = 0); Layout layout() const; void setLayout(Layout layout); + private: void setupModelData(); - - TreeItemDT *rootItem; QMap<dive_trip_t*, TripItem*> trips; Layout currentLayout; }; @@ -185,12 +188,12 @@ public: virtual Qt::ItemFlags flags(const QModelIndex& index) const; virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); void update(); - + public slots: void remove(const QModelIndex& index); private: int numRows; - + }; #endif |