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 canGraphModel.h
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2007 December 27
26 //-----------------------------------------------------------------------------
29 #ifndef canGraphModel_h
30 #define canGraphModel_h
34 #include "./qanNodeItem.h"
35 #include "./qanEdgeItem.h"
39 #include <QStandardItemModel>
42 //-----------------------------------------------------------------------------
43 namespace qan
{ // ::qan
45 //! Standard interface for template listeners used in qan::GraphT.
48 /*! \name Graph Topology Listener *///---------------------------------
52 void init( Node::List
& rootNodes
) { }
54 void edgeInserted( qan::Edge
& edge
) { }
56 void edgeRemoved( qan::Edge
& edge
) { }
58 void nodeInserted( qan::Node
& node
) { }
60 void nodeRemoved( qan::Node
& node
) { }
62 void nodeChanged( qan::Node
& node
) { }
64 //---------------------------------------------------------------------
68 //! Expose a graph data structure to a QT Interview model.
72 class GraphModel
: public QStandardItemModel
, public GraphListener
78 /*! \name Scene Interface Management *///------------------------------
82 qan::Node
* getModelIndexNode( QModelIndex index
);
84 void init( Node::List
& rootNodes
);
86 void edgeInserted( qan::Edge
& edge
);
88 void edgeRemoved( qan::Edge
& edge
);
90 void nodeInserted( qan::Node
& node
);
92 void nodeRemoved( qan::Node
& node
);
94 void nodeChanged( qan::Node
& node
);
98 void visit( qan::Node
& node
);
100 void createNode( qan::Node
& node
);
102 void removeNode( qan::Node
& node
);
104 QStandardItem
* addItem( qan::Node
& node
, QStandardItem
* parent
= 0 );
106 void removeItem( qan::Node
& node
);
108 //! Remove an item and all its child from the model.
109 void removeItemHierarchy( QStandardItem
* item
);
111 //! Add and item (and all its childs) to a given parent.
112 void addItemHierarchy( qan::Node
& node
, QStandardItem
* parent
= 0, qan::Node::Set
* marked
= 0 );
114 typedef QMultiMap
< qan::Node
*, QStandardItem
* > NodeItemMap
;
116 NodeItemMap _nodeItemMap
;
118 //---------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
124 #endif // canGraphModel_h