DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
graphnodeitem.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 GRAPHNODEITEM_H
22 #define GRAPHNODEITEM_H
23 
24 #include <QGraphicsItemGroup>
25 #include <memory>
26 #include <boost/weak_ptr.hpp>
27 #include <dtree/variables.h>
28 
29 namespace dtree {
30  class Node;
31 }
32 
33 class DtGraphicsScene;
35 
36 class GraphNodeItem : public QGraphicsItemGroup
37 {
38 public:
39  explicit GraphNodeItem(std::shared_ptr<dtree::Node> node, DtGraphicsScene *scene, QGraphicsItem *parent = 0);
40  virtual ~GraphNodeItem();
41 
42  std::shared_ptr<dtree::Node> getNode() const { return mNode.lock(); }
43 
44  // These mimics the Node's counterparts.
45  int getChildrenCount() const;
46  GraphNodeItem *getChild(int idx);
47  int getChildrenId() const { return mChildrenId; }
48  GraphNodeItem *getParent() const { return mParent; }
49 
50  void setVariable(dtree::Variable var);
51 
52  void connectAsParent(GraphNodeItem *item, int idx);
53  void connectAsChild(GraphNodeItem *item, int idx);
54  void unlinkParent();
55  void unlinkChild(int idx);
56 
57  void moveArrow(QPointF pt);
58 
59  bool requiresChildrenHighlight(int childid) const;
60  void childHoverEntered(int id);
61  void childHoverExited();
62 
63  void update();
64 
65 protected:
66  void setChild(int idx, GraphNodeItem *child);
67  void setParent(GraphNodeItem *child);
68 
69  void createArrow();
70  QPointF getChildrenArrowLocation(int idx) const;
71  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
72 
73 private:
74  DtGraphicsScene *mScene;
75  GraphNodeItem *mParent;
76  QVector<GraphNodeItem *> mChildrenItems;
77 
78  std::weak_ptr<dtree::Node> mNode;
79 
80  QGraphicsRectItem *mRect;
81  QGraphicsTextItem *mText;
82  int mChildrenId;
83  QVector<GraphNodeChildBoxItem *> mChildrenBoxes;
84  QVector<QGraphicsTextItem *> mChildrenBoxText;
85  QGraphicsLineItem *mArrow;
86 
87  int mHoveredChild;
88 
89  static double sDefWidth, sDefHeight;
90 };
91 
92 class GraphNodeChildBoxItem : public QGraphicsRectItem
93 {
94 public:
95  explicit GraphNodeChildBoxItem(QRectF r, GraphNodeItem *parent, int id);
96 
97 protected:
98  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
99  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
100 
102  int mId;
103 
105 };
106 
107 #endif // GRAPHNODEITEM_H
void unlinkChild(int idx)
Definition: graphnodeitem.cpp:185
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Definition: graphnodeitem.cpp:265
int getChildrenCount() const
Definition: graphnodeitem.cpp:76
GraphNodeItem * getParent() const
Definition: graphnodeitem.h:48
GraphNodeItem * mParent
Definition: graphnodeitem.h:101
Definition: Node.h:39
Definition: dtgraphicsscene.h:37
void connectAsChild(GraphNodeItem *item, int idx)
Definition: graphnodeitem.cpp:173
void connectAsParent(GraphNodeItem *item, int idx)
Definition: graphnodeitem.cpp:166
void setVariable(dtree::Variable var)
Definition: graphnodeitem.cpp:86
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: graphnodeitem.cpp:302
virtual ~GraphNodeItem()
Definition: graphnodeitem.cpp:54
Variable
Definition: variables.h:10
void setChild(int idx, GraphNodeItem *child)
Definition: graphnodeitem.cpp:156
void childHoverExited()
Definition: graphnodeitem.cpp:213
void moveArrow(QPointF pt)
Definition: graphnodeitem.cpp:190
static QBrush mNormalBrush
Definition: graphnodeitem.h:104
std::shared_ptr< dtree::Node > getNode() const
Definition: graphnodeitem.h:42
void childHoverEntered(int id)
Definition: graphnodeitem.cpp:208
Definition: graphnodeitem.h:92
Definition: commonstateevaluators.h:8
int mId
Definition: graphnodeitem.h:102
GraphNodeItem * getChild(int idx)
Definition: graphnodeitem.cpp:81
std::pair< box, unsigned > value
Definition: diffusion.cpp:30
GraphNodeItem(std::shared_ptr< dtree::Node > node, DtGraphicsScene *scene, QGraphicsItem *parent=0)
Definition: graphnodeitem.cpp:31
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Definition: graphnodeitem.cpp:293
void setParent(GraphNodeItem *child)
Definition: graphnodeitem.cpp:161
bool requiresChildrenHighlight(int childid) const
Definition: graphnodeitem.cpp:203
void createArrow()
Definition: graphnodeitem.cpp:253
void update()
Definition: graphnodeitem.cpp:218
void unlinkParent()
Definition: graphnodeitem.cpp:180
int getChildrenId() const
Definition: graphnodeitem.h:47
GraphNodeChildBoxItem(QRectF r, GraphNodeItem *parent, int id)
Definition: graphnodeitem.cpp:285
QPointF getChildrenArrowLocation(int idx) const
Definition: graphnodeitem.cpp:260
static QBrush mHighlightBrush
Definition: graphnodeitem.h:104
Definition: graphnodeitem.h:36