0.3.1
[qanava.git] / src / qanGraphScene.h
blob41793cbce74efbbaa1990248f25478caba7885e2
1 /*
2 Qanava - Graph drawing library for QT
3 Copyright (C) 2006 Benoit AUTHEMAN
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; 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 canGraphScene.h
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2005 November 22
26 //-----------------------------------------------------------------------------
29 #ifndef canGraphScene_h
30 #define canGraphScene_h
33 // Qanava headers
34 #include "./qanNodeItem.h"
35 #include "./qanEdgeItem.h"
36 #include "./qanGraphModel.h"
39 // QT headers
40 #include <QAbstractItemModel>
41 #include <QAbstractItemView>
42 #include <QGraphicsScene>
43 #include <QGraphicsView>
44 #include <QGraphicsItem>
45 #include <QMap>
46 #include <QStandardItemModel>
49 //-----------------------------------------------------------------------------
50 namespace qan { // ::qan
52 class Grid;
55 //! Display a graph provided as a QT Interview based model.
56 /*!
57 \nosubgrouping
59 class GraphScene : public GraphListener, public QGraphicsScene
61 /*! \name GraphScene Object Management *///----------------------------
62 //@{
63 public:
65 //! GraphScene constructor with optionnal settings for graph widget initialization.
66 GraphScene( QWidget* parent = 0, QColor backColor = QColor( 170, 171, 205 ), QSize size = QSize( 300, 150 ) );
68 //! GraphScene virtual destructor.
69 virtual ~GraphScene( );
70 //@}
71 //---------------------------------------------------------------------
75 /*! \name Scene Management *///----------------------------------------
76 //@{
77 public:
79 //! Clear the scene from all its graphics elements (styles are not destroyed).
80 void clear( );
82 //! Get bounding box for a group of nodes.
83 static VectorF getBoundingBox( const Node::List& nodes );
85 //! .
86 void updatePositions( Node* except = 0 );
87 //@}
88 //---------------------------------------------------------------------
92 /*! \name Style Management *///----------------------------------------
93 //@{
94 public:
96 //! Get the graph view style manager.
97 Style::Manager& getStyleManager( ) { return _styleManager; }
99 //! Set a node or edge (or other graphic object) style.
100 void applyStyle( void* item, Style* style );
102 void updateStyle( void* item, Style* style );
104 protected:
106 //! Graph view style manager.
107 Style::Manager _styleManager;
108 //@}
109 //---------------------------------------------------------------------
113 /*! \name Scene Topology Management *///-------------------------------
114 //@{
115 public:
117 void init( Node::List& rootNodes );
119 public:
121 void edgeInserted( qan::Edge& edge );
123 void edgeRemoved( qan::Edge& edge );
125 void nodeInserted( qan::Node& node );
127 void nodeRemoved( qan::Node& node );
129 void nodeChanged( qan::Node& node );
131 void visit( qan::Node& node );
133 private:
135 void insertNode( qan::Node& node );
137 void insertEdge( qan::Edge& edge );
138 //@}
139 //---------------------------------------------------------------------
143 /*! \name Node and Graphic Item Mapping Management *///----------------
144 //@{
145 public:
147 //! Get a graph node associed to a given graphic item.
148 Node* getGraphicItemNode( const QGraphicsItem* item );
150 //! Get a graphic item associed to a given graph node.
151 QGraphicsItem* getNodeGraphicItem( const Node* node );
153 //! Get the node that is currently under the mouse pointer.
154 Node* getCurrentNode( QPoint& p );
156 signals:
158 void nodeDoubleClicked( qan::Node* node );
160 protected:
162 typedef QMap< const Edge*, EdgeItem* > EdgeGraphicItemMap;
164 typedef QMap< const Node*, AbstractNodeItem* > NodeGraphicItemMap;
166 EdgeGraphicItemMap _edgeGraphicItemMap;
168 NodeGraphicItemMap _nodeGraphicItemMap;
169 //@}
170 //---------------------------------------------------------------------
174 /*! \name Graphic Item Node Factory Management *///--------------------
175 //@{
176 public:
178 //! Register a graphic node factory for a certain type of nodes (from graph topology to graph graphic visualization).
179 void registerGraphicNodeFactory( AbstractNodeItem::AbstractFactory* factory );
181 //! Create a graphic node from a topological node using the currently registered graphic node factories.
182 AbstractNodeItem* createNodeItem( Node& node, QGraphicsItem* parent, QPoint origin, const QString& label );
184 private:
186 AbstractNodeItem::AbstractFactory::List _factories;
187 //@}
188 //---------------------------------------------------------------------
190 } // ::qan
191 //-----------------------------------------------------------------------------
194 #endif // canGraphScene_h