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
34 #include "./qanNodeItem.h"
35 #include "./qanEdgeItem.h"
36 #include "./qanGraphModel.h"
40 #include <QAbstractItemModel>
41 #include <QAbstractItemView>
42 #include <QGraphicsScene>
43 #include <QGraphicsView>
44 #include <QGraphicsItem>
46 #include <QStandardItemModel>
49 //-----------------------------------------------------------------------------
50 namespace qan
{ // ::qan
55 //! Display a graph provided as a QT Interview based model.
59 class GraphScene
: public GraphListener
, public QGraphicsScene
61 /*! \name GraphScene Object Management *///----------------------------
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( );
71 //---------------------------------------------------------------------
75 /*! \name Scene Management *///----------------------------------------
79 //! Clear the scene from all its graphics elements (styles are not destroyed).
82 //! Get bounding box for a group of nodes.
83 static VectorF
getBoundingBox( const Node::List
& nodes
);
86 void updatePositions( Node
* except
= 0 );
88 //---------------------------------------------------------------------
92 /*! \name Style Management *///----------------------------------------
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
);
106 //! Graph view style manager.
107 Style::Manager _styleManager
;
109 //---------------------------------------------------------------------
113 /*! \name Scene Topology Management *///-------------------------------
117 void init( Node::List
& rootNodes
);
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
);
135 void insertNode( qan::Node
& node
);
137 void insertEdge( qan::Edge
& edge
);
139 //---------------------------------------------------------------------
143 /*! \name Node and Graphic Item Mapping Management *///----------------
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
);
158 void nodeDoubleClicked( qan::Node
* node
);
162 typedef QMap
< const Edge
*, EdgeItem
* > EdgeGraphicItemMap
;
164 typedef QMap
< const Node
*, AbstractNodeItem
* > NodeGraphicItemMap
;
166 EdgeGraphicItemMap _edgeGraphicItemMap
;
168 NodeGraphicItemMap _nodeGraphicItemMap
;
170 //---------------------------------------------------------------------
174 /*! \name Graphic Item Node Factory Management *///--------------------
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
);
186 AbstractNodeItem::AbstractFactory::List _factories
;
188 //---------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
194 #endif // canGraphScene_h