Import doxygen generated api doc
[qanava.git] / src / qanGraphItemView.h
blobda5f8d33a22f4d3a0bc3bbf3af2df8448d9de1e3
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 canGraphItemView.h
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2005 November 22
26 //-----------------------------------------------------------------------------
29 #ifndef canGraphItemView_h
30 #define canGraphItemView_h
33 // Qanava headers
34 #include "./qanNode.h"
35 #include "./qanGraph.h"
36 #include "./qanLayout.h"
37 #include "./qanItemGeom.h"
38 #include "./qanGraphicsView.h"
41 // QT headers
42 #include <QAbstractItemModel>
43 #include <QAbstractItemView>
44 #include <QGraphicsScene>
45 #include <QGraphicsView>
46 #include <QGraphicsItem>
47 #include <QMap>
50 //-----------------------------------------------------------------------------
51 namespace qan { // ::qan
53 class Grid;
56 //! Display a graph provided as a QT Interview based model.
57 /*!
58 \nosubgrouping
60 class GraphItemView : public QAbstractItemView
62 Q_OBJECT
64 /*! \name View Construction *///---------------------------------------
65 //@{
66 public:
68 //! GraphItemView constructor with optionnal settings for graph widget initialization.
69 GraphItemView( QWidget* parent, Graph* graph = 0,
70 QColor backColor = QColor( 170, 171, 205 ), QSize size = QSize( 300, 150 ),
71 bool autoExpand = true );
73 //! GraphItemView virtual destructor.
74 virtual ~GraphItemView( );
76 //! Clear this item view of all elements and set its model to 0.
77 void clear( );
79 QGraphicsScene* getGraphicsScene( ) { return _graphicsScene; }
81 GraphicsView* getGraphicsView( ) { return _graphicsView; }
83 void setGrid( GridItem* grid ) { _graphicsView->setGrid( grid ); }
85 virtual QSize sizeHint( ) const { return QSize( 300, 250 ); }
87 private:
89 QGraphicsScene* _graphicsScene;
91 GraphicsView* _graphicsView;
93 Graph* _graph;
94 //@}
95 //---------------------------------------------------------------------
99 /*! \name QT View Interface Management *///----------------------------
100 //@{
101 public:
103 virtual void setModel ( QAbstractItemModel* model );
105 virtual QModelIndex indexAt( const QPoint& p ) const;
107 virtual void scrollTo( const QModelIndex& index, ScrollHint hint = EnsureVisible ) { }
109 virtual QRect visualRect( const QModelIndex& index ) const { return QRect( 0, 0, 0, 0 ); }
111 virtual int horizontalOffset( ) const { return 0; }
113 virtual bool isIndexHidden ( const QModelIndex & index ) const { return false; }
115 virtual QModelIndex moveCursor ( CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) { return QModelIndex( ); }
117 virtual void setSelection ( const QRect& rect, QItemSelectionModel::SelectionFlags flags ) { }
119 virtual int verticalOffset( ) const { return 0; }
121 virtual QRegion visualRegionForSelection ( const QItemSelection& selection ) const { return QRegion( 0, 0, 0, 0 ); }
123 protected:
125 //! Visit a model index and its child index, and map encoutered indexes.
126 void visitModelIndex( QAbstractItemModel& model, QModelIndex& modelIndex, QModelIndex& parentIndex, int depth = -1 );
128 //! Map a given model index to a graph node and a canvas geometric items.
129 void mapIndex( QModelIndex& index, QModelIndex& parent );
131 //! Update an index associed graphic item (and eventually node) with the current index data.
132 void updateModelIndexGraphicItem( QModelIndex& index );
134 //! Update a node from data comming from its associed model index (assuming the model data are more accurate than the node ones).
135 void updateModelIndexNode( QModelIndex& index, Node* node = 0 );
137 public slots:
139 void expand( const Node* node );
141 protected slots:
143 void graphicItemDoubleClicked( QGraphicsItem* item );
145 virtual void reset( );
147 virtual void rowsAboutToBeInserted( const QModelIndex& parent, int start, int end );
149 virtual void rowsInserted( const QModelIndex& parent, int start, int end );
151 virtual void rowsAboutToBeRemoved( const QModelIndex & parent, int start, int end );
153 virtual void rowsRemoved( const QModelIndex &parent, int first, int last );
155 virtual void dataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight );
156 //@}
157 //---------------------------------------------------------------------
161 /*! \name Model Index and Graphic Item Management *///-----------------
162 //@{
163 public:
165 //! Get a graph node associed to a given graphic item.
166 Node* getGraphicItemNode( const QGraphicsItem* item );
168 //! Get a graphic item associed to a given graph node.
169 QGraphicsItem* getNodeGraphicItem( const Node* node );
171 //! Get a graph node associed to a given model item index.
172 Node* getModelIndexNode( QModelIndex& index );
174 //! Get the node that is currently under the mouse pointer.
175 Node* getCurrentNode( QPoint& p );
177 signals:
179 void nodeDoubleClicked( qan::Node* node );
181 protected:
183 typedef QMap< void*, Node* > ModelIndexNodeMap;
185 typedef QMap< void*, AbstractNodeItem* > ModelIndexGraphicItemMap;
187 typedef QMap< const Edge*, EdgeItem* > EdgeGraphicItemMap;
189 typedef QMap< const Node*, AbstractNodeItem* > NodeGraphicItemMap;
191 typedef QMap< const QGraphicsItem*, void* > GraphicItemModelIndexMap;
193 typedef QMap< const Node*, QModelIndex > NodeModelIndexMap;
195 ModelIndexNodeMap _modelIndexNodeMap;
197 ModelIndexGraphicItemMap _modelIndexGraphicItemMap;
199 EdgeGraphicItemMap _edgeGraphicItemMap;
201 NodeGraphicItemMap _nodeGraphicItemMap;
203 GraphicItemModelIndexMap _graphicItemModelIndexMap;
205 NodeModelIndexMap _nodeModelIndexMap;
207 bool _autoExpand;
208 //@}
209 //---------------------------------------------------------------------
213 /*! \name Style Management *///----------------------------------------
214 //@{
215 public:
217 //! Get the graph view style manager.
218 Style::Manager& getStyleManager( ) { return _styleManager; }
220 //! Set a node style.
221 void applyStyle( Node* node, Style* style );
223 protected:
225 //! Graph view style manager.
226 Style::Manager _styleManager;
227 //@}
228 //---------------------------------------------------------------------
232 /*! \name Layout Management *///---------------------------------------
233 //@{
234 public:
236 //! .
237 void setGraphLayout( Layout* layout, QProgressDialog* progress = 0 );
239 //! .
240 Layout* getGraphLayout( Layout& layout ) { return _layout; }
242 //! .
243 const Layout* getGraphLayout( Layout& layout ) const { return _layout; }
245 //! .
246 void layoutGraph( QProgressDialog* progress = 0, Layout* layout = 0, int step = -1, Node* except = 0 );
248 //! Get bounding box for a group of nodes.
249 static VectorF getBoundingBox( const Node::List& nodes );
251 protected:
253 //! .
254 Layout* _layout;
255 //@}
256 //---------------------------------------------------------------------
260 /*! \name ScrollArea Management *///-----------------------------------
261 //@{
262 protected:
264 void resizeEvent( QResizeEvent* event );
266 bool eventFilter( QObject* o, QEvent* e );
267 //@}
268 //---------------------------------------------------------------------
272 /*! \name Graphic Node Factory Management *///-------------------------
273 //@{
274 public:
276 //! Register a graphic node factory for a certain type of nodes (from graph topology to graph graphic visualization).
277 void registerGraphicNodeFactory( AbstractNodeItem::AbstractFactory* factory );
279 //! Create a graphic node from a topological node using the currently registered graphic node factories.
280 AbstractNodeItem* createGraphicNode( Node& node, Style::Manager& styleManager, Style& style,
281 QGraphicsItem* parent, QGraphicsScene* scene,
282 QPoint origin, const QString& label );
284 private:
286 AbstractNodeItem::AbstractFactory::List _factories;
287 //@}
288 //---------------------------------------------------------------------
290 } // ::qan
291 //-----------------------------------------------------------------------------
294 #endif // canGraphItemView_h