(empty message)
[qanava.git] / src / can / canGraphView.h
blobf4ce1f2ca5b44aa398dee856d9375982d3f8f444
1 /*
2 Qanava - Graph drawing library for QT
3 Copyright (C) 2005 Benoit AUTHEMAN
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 //-----------------------------------------------------------------------------
21 // This file is a part of the Qanava software.
23 // \file canGraphView.h
24 // \author Benoit Autheman (benoit@faktiss.net)
25 // \date 2003 August 13
26 //-----------------------------------------------------------------------------
29 #ifndef canGraphView_h
30 #define canGraphView_h
33 // Qanava headers
34 #include "../la/laGraph.h"
35 #include "../la/laNode.h"
36 #include "canItemGeom.h"
37 #include "canCanvasView.h"
40 // QT headers
41 #include <qpoint.h>
44 //-----------------------------------------------------------------------------
45 namespace qan { // ::qan
46 namespace can { // ::qan::can
48 //! Models a view to handle nodes of a graph as it is defined in the qan::can framework.
49 /*!
50 Coherency between the model graph and this view must be enforced manually, when the
51 model is modified. This view is updated by calling the update() method when the model graph
52 connectivity has been modified, or by calling more cheaper methods such as updatePositions() or
53 updateStyles() when only nodes parameter modifications need to be reflected in the view
54 (node position or style).
56 \nosubgrouping
58 class GraphView
60 public:
62 //! GraphView constructor.
63 GraphView( ) { }
65 //! GraphView virtual destructor.
66 virtual ~GraphView( ) { }
68 /*! \name Graph View Management *///-----------------------------------
69 //@{
70 public:
72 //! Update the graph view with appropriate Item objects for all changed or created node in the model graph.
73 virtual void update( ) = 0;
75 //! Update nodes view to reflect the model nodes position.
76 virtual void updatePositions( ) = 0;
78 //! Update nodes view to refect the current state of styles in the model graph.
79 virtual void updateStyles( ) = 0;
81 //! Hide all nodes.
82 virtual void hide( ) = 0;
84 //! Show all nodes.
85 virtual void show( ) = 0;
87 //! Get the graph node associed to a given graphic item.
88 virtual la::Node* getItemNode( const QCanvasItem* item ) = 0;
89 //@}
90 //---------------------------------------------------------------------
94 /*! \name Style Management *///----------------------------------------
95 //@{
96 public:
98 //! Get the graph view style manager.
99 AdvStyle::Manager& getStyleManager( ) { return _styleManager; }
101 protected:
103 //! Graph view style manager.
104 AdvStyle::Manager _styleManager;
105 //@}
106 //---------------------------------------------------------------------
111 //! Concrete view for a qan::la::Graph based graph.
113 \nosubgrouping
115 class GraphViewImpl : public GraphView
117 public:
119 //! GraphViewImpl with model graph and canvas initialisation.
120 GraphViewImpl( Canvas& canvas, la::Graph& graph ) :
121 _canvas( canvas ), _graph( graph ) { canvas.setGraphView( this ); }
123 /*! \name Graph View Management *///-----------------------------------
124 //@{
125 public:
127 //! Update the graph view with appropriate Item objects for all changed or created node in the model graph.
128 virtual void update( );
130 //! Update nodes view to reflect the model nodes position.
131 virtual void updatePositions( );
133 //! Update nodes view to refect the current state of styles in the model graph.
134 virtual void updateStyles( );
136 //! Hide all nodes.
137 virtual void hide( );
139 //! Show all nodes.
140 virtual void show( );
142 //! Get the graph node associed to a given graphic item.
143 la::Node* getItemNode( const QCanvasItem* item );
145 //! Get a graph node associed graphic item.
146 QCanvasItem* getNodeItem( const la::Node* node );
148 private:
150 //! Get a group of nodes bounding box
151 static la::Vectorf getBoundingBox( const la::Node::Nodes& nodes );
153 //! STL typedef for a map of 'la' graph nodes to 'ql' graphical canvas items.
154 typedef std::map< la::Node*, can::RectangularItem* > NodeItemMap;
156 //! STL typedef for a map of 'ql' graphical canvas items to 'la' graph nodes.
157 typedef std::map< const QCanvasItem*, la::Node* > ItemNodeMap;
159 //! Map node from the link analysis (la) framework to graphical qlayout items.
160 NodeItemMap _nodeItemMap;
162 ItemNodeMap _itemNodeMap;
164 //! Reference to the canvas were the node are beeing positionned.
165 Canvas& _canvas;
167 //! Reference to the source graph whose nodes are beeig positionned.
168 la::Graph& _graph;
169 //@}
170 //---------------------------------------------------------------------
172 } // ::qan::can
173 } // ::qan
174 //-----------------------------------------------------------------------------
177 #endif // canGraphView_h