DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
objecttreemodel.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // DISPLACE: DYNAMIC INDIVIDUAL VESSEL-BASED SPATIAL PLANNING
3 // AND EFFORT DISPLACEMENT
4 // Copyright (c) 2012-2019 Francois Bastardie <fba@aqua.dtu.dk>
5 
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // --------------------------------------------------------------------------
20 
21 #ifndef OBJECTTREEMODEL_H
22 #define OBJECTTREEMODEL_H
23 
24 #include <QAbstractItemModel>
25 #include <QList>
26 
27 class DisplaceModel;
29 class StatsController;
30 
31 namespace objecttree {
32 class ObjectTreeEntity;
33 class FFarmTypesEntity;
34 class BFunctionalGroupsEntity;
35 class WFarmTypesEntity;
36 class ShipTypesEntity;
37 }
38 
39 class ObjectTreeModel : public QAbstractItemModel
40 {
41  Q_OBJECT
42 
43 public:
44  enum Category {
45  Layers = 0,
54  };
55 
56  explicit ObjectTreeModel(MapObjectsController *map, StatsController *stats, QObject *parent = 0);
57 
58  int columnCount(const QModelIndex &parent) const;
59  int rowCount(const QModelIndex &parent) const;
60  QModelIndex parent(const QModelIndex &child) const;
61  QModelIndex index(int row, int column, const QModelIndex &parent) const;
62  QVariant data(const QModelIndex &index, int role) const;
63  Qt::ItemFlags flags ( const QModelIndex & index ) const;
64  bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
65 
66  void setCurrentModel (int idx, DisplaceModel *model);
67  int getModelIdx() const { return mModelIdx; }
68  DisplaceModel *getModel() const { return mModel; }
69  MapObjectsController *getMapControl() const { return mMapControl; }
70  StatsController *getStatsController() const { return mStatsController; }
71 
72  // For use from ObjectTreeEntities
73  QModelIndex createCategoryEntity(int row, int column, Category cat) const;
74  QModelIndex createCategoryEntityFromChild (Category cat) const;
75  QModelIndex createEntity (int row, int column, objecttree::ObjectTreeEntity *entity) const;
76 
77  bool isObject(QModelIndex index) const;
78  Category getCategory (QModelIndex index) const;
79  objecttree::ObjectTreeEntity *entity (const QModelIndex &index) const;
80 
81  void refresh();
82 signals:
83 
84 public slots:
85 
86 private:
87  MapObjectsController *mMapControl;
88  StatsController *mStatsController;
89  DisplaceModel *mModel;
90  int mModelIdx;
91 
94  objecttree::WFarmTypesEntity *windfarmtypes;
95  objecttree::ShipTypesEntity *shiptypes;
96 
97 protected:
98  // helper functions
99 
100  bool isRootLevel (const QModelIndex &level) const {
101  return !level.isValid();
102  }
103 
104  bool isCategoryLevel (const QModelIndex &level) const { // level.internalId() > 0 && level.internalId() < LastCategory
105  return level.isValid() &&
106  (level.row() < entityTemplates.size() &&
107  level.internalPointer() == entityTemplates[level.row()]);
108  }
109 
110  static QList<objecttree::ObjectTreeEntity *> entityTemplates;
111  static QString entityNames[];
112 };
113 
114 #endif // OBJECTTREEMODEL_H
Definition: objecttreemodel.h:51
Definition: objecttreemodel.h:52
Definition: benthosentity.cpp:27
Definition: objecttreemodel.h:50
int rowCount(const QModelIndex &parent) const
Definition: objecttreemodel.cpp:127
Definition: objecttreemodel.h:51
QVariant data(const QModelIndex &index, int role) const
Definition: objecttreemodel.cpp:159
Definition: objecttreemodel.h:49
Definition: ffarmtypesentity.h:10
Definition: objecttreemodel.h:48
Definition: wfarmtypesentity.h:10
void refresh()
Definition: objecttreemodel.cpp:245
QModelIndex parent(const QModelIndex &child) const
Definition: objecttreemodel.cpp:140
Definition: objecttreemodel.h:50
Definition: objecttreemodel.h:53
Definition: objecttreemodel.h:46
Definition: objecttreemodel.h:47
Definition: objecttreemodel.h:51
QModelIndex createEntity(int row, int column, objecttree::ObjectTreeEntity *entity) const
Definition: objecttreemodel.cpp:225
bool isRootLevel(const QModelIndex &level) const
Definition: objecttreemodel.h:100
void setCurrentModel(int idx, DisplaceModel *model)
Definition: objecttreemodel.cpp:196
int columnCount(const QModelIndex &parent) const
Definition: objecttreemodel.cpp:120
QModelIndex createCategoryEntityFromChild(Category cat) const
Definition: objecttreemodel.cpp:220
Definition: objecttreeentity.h:32
Definition: objecttreemodel.h:50
Definition: objecttreemodel.h:45
Definition: objecttreemodel.h:52
Definition: statscontroller.h:45
bool isCategoryLevel(const QModelIndex &level) const
Definition: objecttreemodel.h:104
ObjectTreeModel(MapObjectsController *map, StatsController *stats, QObject *parent=0)
Definition: objecttreemodel.cpp:73
QModelIndex index(int row, int column, const QModelIndex &parent) const
Definition: objecttreemodel.cpp:148
Definition: objecttreemodel.h:51
Definition: objecttreemodel.h:39
static QList< objecttree::ObjectTreeEntity * > entityTemplates
Definition: objecttreemodel.h:110
Definition: displacemodel.h:71
objecttree::ObjectTreeEntity * entity(const QModelIndex &index) const
Definition: objecttreemodel.cpp:240
int getModelIdx() const
Definition: objecttreemodel.h:67
std::pair< box, unsigned > value
Definition: diffusion.cpp:30
Definition: objecttreemodel.h:51
Definition: objecttreemodel.h:50
Definition: shiptypesentity.h:10
Category
Definition: objecttreemodel.h:44
Definition: mapobjectscontroller.h:91
Definition: statsutils.h:4
bool isObject(QModelIndex index) const
Definition: objecttreemodel.cpp:230
Definition: objecttreemodel.h:50
Definition: objecttreemodel.h:52
StatsController * getStatsController() const
Definition: objecttreemodel.h:70
Definition: bfunctionalgroupsentity.h:10
QModelIndex createCategoryEntity(int row, int column, Category cat) const
Definition: objecttreemodel.cpp:215
MapObjectsController * getMapControl() const
Definition: objecttreemodel.h:69
DisplaceModel * getModel() const
Definition: objecttreemodel.h:68
Category getCategory(QModelIndex index) const
Definition: objecttreemodel.cpp:235
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: objecttreemodel.cpp:185
Definition: objecttreemodel.h:52
Definition: objecttreemodel.h:52
Qt::ItemFlags flags(const QModelIndex &index) const
Definition: objecttreemodel.cpp:176
Definition: objecttreemodel.h:52
static QString entityNames[]
Definition: objecttreemodel.h:111