DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
dtgraphicsscene.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 DTGRAPHICSSCENE_H
22 #define DTGRAPHICSSCENE_H
23 
24 #include <QGraphicsScene>
25 
26 #include <memory>
27 #include <set>
28 
29 namespace dtree {
30 class DecisionTree;
31 class GraphNodeExtra;
32 class Node;
33 }
34 
35 class GraphNodeItem;
36 
37 class DtGraphicsScene : public QGraphicsScene
38 {
39  Q_OBJECT
40 public:
41  explicit DtGraphicsScene(std::shared_ptr<dtree::DecisionTree> tree, QObject *parent = 0);
42 
43  void clear();
44  bool requiresChildrenHighlight() const;
45 
46  void nodeChildEntered (GraphNodeItem *item, int childId);
47  void nodeChildExited();
48 
49  GraphNodeItem *root() const { return mRoot; }
50  void addItemAsRoot(GraphNodeItem *item);
51 
52  void removeNodes (QList<GraphNodeItem *>items);
53 
54 protected:
55  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
56  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
57  virtual void keyPressEvent(QKeyEvent * keyEvent) override;
58 
59 signals:
60  void nodeAdded(GraphNodeItem *);
61  void mouseModeEnded();
62 
63 public slots:
64  void startAddNode(std::shared_ptr<dtree::Node>);
65  void endMode();
66 
67 private:
68  enum Mode {
69  None, AddNode, AddNodeConnect
70  };
71 
72  Mode mMode = None;
73 
74  std::shared_ptr<dtree::DecisionTree> mTree;
75  GraphNodeItem *mRoot;
76 
78  std::shared_ptr<dtree::Node> mAddingNode;
79  GraphNodeItem *mAddingItem;
80 
81  GraphNodeItem *mHoveringNode;
82  int mHoveringNodeChild;
83 };
84 
85 #endif // DTGRAPHICSSCENE_H
bool requiresChildrenHighlight() const
Definition: dtgraphicsscene.cpp:57
Definition: Node.h:39
Definition: dtgraphicsscene.h:37
void clear()
Definition: dtgraphicsscene.cpp:41
void nodeChildEntered(GraphNodeItem *item, int childId)
Definition: dtgraphicsscene.cpp:62
void startAddNode(std::shared_ptr< dtree::Node >)
Definition: dtgraphicsscene.cpp:200
void nodeAdded(GraphNodeItem *)
Definition: moc_dtgraphicsscene.cpp:150
void removeNodes(QList< GraphNodeItem * >items)
Definition: dtgraphicsscene.cpp:80
void addItemAsRoot(GraphNodeItem *item)
Definition: dtgraphicsscene.cpp:74
void endMode()
Definition: dtgraphicsscene.cpp:207
Definition: commonstateevaluators.h:8
void nodeChildExited()
Definition: dtgraphicsscene.cpp:68
GraphNodeItem * root() const
Definition: dtgraphicsscene.h:49
virtual void keyPressEvent(QKeyEvent *keyEvent) override
Definition: dtgraphicsscene.cpp:184
DtGraphicsScene(std::shared_ptr< dtree::DecisionTree > tree, QObject *parent=0)
Definition: dtgraphicsscene.cpp:30
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Definition: dtgraphicsscene.cpp:130
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Definition: dtgraphicsscene.cpp:143
void mouseModeEnded()
Definition: moc_dtgraphicsscene.cpp:157
Definition: graphnodeitem.h:36