Import doxygen generated api doc
[qanava.git] / src / qanGraphItemModel.h
blobcf911eea777700eaa4ac088a0794277a56403e41
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 canGraphItemModel.h
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2005 November 22
26 //-----------------------------------------------------------------------------
29 #ifndef canGraphItemModel_h
30 #define canGraphItemModel_h
33 // Qanava headers
34 #include "./qanNode.h"
35 #include "./qanStyle.h"
38 // QT headers
39 #include <QAbstractItemModel>
40 #include <QAbstractItemView>
41 #include <QTreeView>
42 #include <QPersistentModelIndex>
45 //-----------------------------------------------------------------------------
46 namespace qan { // ::qan
48 /* class GraphItemListener : public QObject, public Graph::Listener
50 Q_OBJECT
52 public:
54 GraphItemListener( Graph& graph, QObject* parent = 0 ) : QObject( parent ), Graph::Listener( graph ) { }
56 virtual void nodeInsertedBegin( Node& node ) { emit nodeInsertedBeginSig( node ); }
58 virtual void nodeInserted( Node& node ) { emit nodeInsertedSig( node ); }
60 virtual void nodeRemovedBegin( Node& node ) { emit nodeRemovedBeginSig( node ); }
62 virtual void nodeRemoved( Node& node ) { emit nodeRemovedSig( node ); }
64 virtual void nodeChanged( Node& node ) { emit nodeChangedSig( node ); }
66 signals:
68 void nodeInsertedBeginSig( qan::Node& node );
70 void nodeInsertedSig( qan::Node& node );
72 void nodeRemovedBeginSig( qan::Node& node );
74 void nodeRemovedSig( qan::Node& node );
76 void nodeChangedSig( qan::Node& node );
77 };*/
79 //! Provide access to a Graph trough a QT interview compatible interface.
80 /*! This model is useable with any classes based on QAbstractItemView, even if some
81 view might eventually not support (or have never been tested with) general graphs
82 with circular depedencies.
84 \nosubgrouping
86 class GraphItemModel : public QAbstractItemModel
88 Q_OBJECT
90 public:
92 //! Value to be added to the Qt::UserRole constant to get corresponding GraphItemModel data role.
93 enum DataRole
95 POSITION_X = 1,
96 POSITION_Y = 2,
97 DIMENSION_X = 3,
98 DIMENSION_Y = 4
101 /*! \name Custom Graph Model Interface *///----------------------------
102 //@{
103 public:
105 GraphItemModel( Node::List& rootNodes );
107 void init( Node::List& rootNodes );
109 void visit( Node& node, int row = 0, int column = 0, int maxDepth = 1 );
111 void visit( Node& node, int row, int column, Node::Set& marked, int maxDepth = 1 );
113 QPersistentModelIndex* getNodePersistentIndex( Node* node ) const;
115 void setStyleManager( Style::Manager* styleManager ) { _styleManager = styleManager; }
117 typedef std::map< Node*, QPersistentModelIndex* > NodePersistentIndexMap;
119 protected:
121 NodePersistentIndexMap _nodePersistentIndexMap;
123 Node::List& _rootNodes;
125 Style::Manager* _styleManager;
126 //@}
127 //---------------------------------------------------------------------
131 /*! \name QT Model Interface Management *///---------------------------
132 //@{
133 public:
135 virtual QVariant data( const QModelIndex& index, int role ) const;
137 virtual bool hasChildren( const QModelIndex & parent = QModelIndex( ) ) const;
139 virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
141 virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex( ) ) const;
143 virtual QModelIndex parent( const QModelIndex& index ) const;
145 virtual int rowCount( const QModelIndex& parent = QModelIndex( ) ) const;
147 virtual int columnCount( const QModelIndex& parent = QModelIndex( ) ) const;
149 virtual bool setData ( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
151 virtual void reset( ) { QAbstractItemModel::reset( ); }
152 //@}
153 //---------------------------------------------------------------------
155 signals:
157 void rowsAboutToBeInserted( const QModelIndex& parent, int start, int end );
159 void rowsAboutToBeRemoved( const QModelIndex& parent, int start, int end );
161 void rowsInserted( const QModelIndex& parent, int start, int end );
163 void rowsRemoved( const QModelIndex& parent, int start, int end );
165 public:
167 void nodeInsertedBegin( qan::Node& node );
169 void nodeInserted( qan::Node& node );
171 void nodeRemovedBegin( qan::Node& node );
173 void nodeRemoved( qan::Node& node );
175 void nodeChanged( qan::Node& node );
177 } // ::qan
178 //-----------------------------------------------------------------------------
181 #endif // canGraphItemModel_h