![]() |
Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 ///@cond DOXYGEN_HIDDEN 00020 00021 #ifndef GRAPHHIERARCHIESMODEL_H 00022 #define GRAPHHIERARCHIESMODEL_H 00023 00024 #include <tulip/tulipconf.h> 00025 #include <tulip/TulipModel.h> 00026 #include <tulip/Observable.h> 00027 00028 #include <QList> 00029 00030 namespace tlp { 00031 class Graph; 00032 class GraphNeedsSavingObserver; 00033 class TulipProject; 00034 class PluginProgress; 00035 00036 class TLP_QT_SCOPE GraphHierarchiesModel : public tlp::TulipModel, public tlp::Observable { 00037 Q_OBJECT 00038 00039 QList<tlp::Graph *> _graphs; 00040 QString generateName(tlp::Graph *) const; 00041 00042 tlp::Graph *_currentGraph; 00043 QMap<const tlp::Graph*,QModelIndex> _indexCache; 00044 QMap<const tlp::Graph*, GraphNeedsSavingObserver*> _saveNeeded; 00045 void initIndexCache(tlp::Graph *root); 00046 00047 public: 00048 bool needsSaving(); 00049 00050 explicit GraphHierarchiesModel(QObject *parent=0); 00051 GraphHierarchiesModel(const GraphHierarchiesModel &); 00052 virtual ~GraphHierarchiesModel(); 00053 00054 // Allows the model to behave like a list and to be iterable 00055 typedef QList<tlp::Graph *>::iterator iterator; 00056 typedef QList<tlp::Graph *>::const_iterator const_iterator; 00057 tlp::Graph *operator[](int i) const { 00058 return _graphs[i]; 00059 } 00060 tlp::Graph *operator[](int i) { 00061 return _graphs[i]; 00062 } 00063 int size() const { 00064 return _graphs.size(); 00065 } 00066 00067 iterator begin() { 00068 return _graphs.begin(); 00069 } 00070 iterator end() { 00071 return _graphs.end(); 00072 } 00073 const_iterator begin() const { 00074 return _graphs.begin(); 00075 } 00076 const_iterator end() const { 00077 return _graphs.end(); 00078 } 00079 00080 QList<tlp::Graph *> graphs() const { 00081 return _graphs; 00082 } 00083 bool empty() const { 00084 return _graphs.isEmpty(); 00085 } 00086 00087 // Methods re-implemented from QAbstractItemModel 00088 QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const; 00089 QModelIndex parent(const QModelIndex &child) const; 00090 int rowCount(const QModelIndex &parent = QModelIndex()) const; 00091 int columnCount(const QModelIndex &parent = QModelIndex()) const; 00092 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 00093 bool setData(const QModelIndex &index, const QVariant &value, int role); 00094 Qt::ItemFlags flags(const QModelIndex &index) const; 00095 QVariant headerData(int section, Qt::Orientation orientation, int role) const; 00096 QMimeData* mimeData(const QModelIndexList &indexes) const; 00097 00098 QModelIndex indexOf(const Graph *); 00099 QModelIndex forceGraphIndex(Graph *); 00100 00101 // Methods inherited from the observable system 00102 void treatEvent(const tlp::Event &); 00103 00104 // active graph handling 00105 void setCurrentGraph(tlp::Graph *); 00106 tlp::Graph *currentGraph() const; 00107 00108 signals: 00109 void currentGraphChanged(tlp::Graph *); 00110 00111 public slots: 00112 void addGraph(tlp::Graph *); 00113 void removeGraph(tlp::Graph *); 00114 00115 QMap<QString,tlp::Graph*> readProject(tlp::TulipProject *,tlp::PluginProgress *); 00116 QMap<tlp::Graph*,QString> writeProject(tlp::TulipProject *, tlp::PluginProgress *); 00117 00118 }; 00119 00120 } 00121 00122 #endif // GRAPHHIERARCHIESMODEL_H 00123 ///@endcond