Tulip  4.6.0
Better Visualization Through Research
library/tulip-gui/include/tulip/GraphModel.h
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 GRAPHMODEL_H
00022 #define GRAPHMODEL_H
00023 
00024 #include <QVector>
00025 #include <QSortFilterProxyModel>
00026 
00027 
00028 #include <tulip/Observable.h>
00029 #include <tulip/TulipModel.h>
00030 
00031 namespace tlp {
00032 class Graph;
00033 class PropertyInterface;
00034 class BooleanProperty;
00035 
00036 class TLP_QT_SCOPE GraphModel : public tlp::TulipModel, public Observable {
00037   tlp::Graph* _graph;
00038 
00039 public:
00040   static QVariant nodeValue(unsigned int, tlp::PropertyInterface*);
00041   static QVariant nodeDefaultValue(tlp::PropertyInterface*);
00042   static bool setNodeValue(unsigned int,tlp::PropertyInterface*, QVariant);
00043   static bool setAllNodeValue(tlp::PropertyInterface*, QVariant);
00044   static QVariant edgeValue(unsigned int, tlp::PropertyInterface*);
00045   static QVariant edgeDefaultValue(tlp::PropertyInterface*);
00046   static bool setEdgeValue(unsigned int,tlp::PropertyInterface*, QVariant);
00047   static bool setAllEdgeValue(tlp::PropertyInterface*, QVariant);
00048 
00049   explicit GraphModel(QObject *parent = NULL);
00050 
00051   virtual void setGraph(tlp::Graph*);
00052   tlp::Graph* graph() const;
00053 
00054   // Methods re-implemented from QAbstractItemModel
00055   int rowCount(const QModelIndex &parent = QModelIndex()) const;
00056   int columnCount(const QModelIndex &parent = QModelIndex()) const;
00057   QModelIndex parent(const QModelIndex &child) const;
00058   Qt::ItemFlags flags(const QModelIndex &index) const;
00059 
00060   QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00061   QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
00062   QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00063   bool setData(const QModelIndex &index, const QVariant &value, int role);
00064 
00065   void treatEvent(const tlp::Event&);
00066   void treatEvents(const std::vector<tlp::Event> &);
00067 
00068   unsigned int elementAt(int) const;
00069   virtual bool lessThan(unsigned int,unsigned int,tlp::PropertyInterface*) const = 0;
00070   virtual QString stringValue(unsigned int,tlp::PropertyInterface*) const = 0;
00071   virtual QVariant value(unsigned int,tlp::PropertyInterface*) const = 0;
00072   virtual bool isNode() const = 0;
00073 
00074 protected:
00075   QVector<unsigned int> _elements;
00076   QVector<QPair<unsigned int,bool> > _elementsToModify;
00077   QVector<PropertyInterface*> _properties;
00078 
00079   virtual bool setValue(unsigned int,tlp::PropertyInterface*,QVariant) const = 0;
00080 };
00081 
00082 class TLP_QT_SCOPE GraphSortFilterProxyModel: public QSortFilterProxyModel, public Observable {
00083   QVector<PropertyInterface*> _properties;
00084   BooleanProperty* _filterProperty;
00085 
00086 public:
00087   GraphSortFilterProxyModel(QObject* parent = NULL);
00088 
00089   void setFilterProperty(tlp::BooleanProperty*);
00090   void setSelectedOnly(bool);
00091   void setProperties(QVector<PropertyInterface*>);
00092 
00093   bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
00094   bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
00095 
00096   void treatEvent(const tlp::Event&);
00097 
00098   tlp::BooleanProperty* filterProperty() const;
00099 };
00100 
00101 class TLP_QT_SCOPE NodesGraphModel: public GraphModel {
00102 public:
00103   NodesGraphModel(QObject* parent = NULL);
00104   void setGraph(Graph *);
00105 
00106   void treatEvent(const tlp::Event &);
00107   virtual bool lessThan(unsigned int,unsigned int,tlp::PropertyInterface*) const;
00108   virtual QString stringValue(unsigned int,tlp::PropertyInterface*) const;
00109   virtual QVariant value(unsigned int,tlp::PropertyInterface*) const;
00110   bool isNode() const {
00111     return true;
00112   }
00113 
00114 protected:
00115   virtual bool setValue(unsigned int,tlp::PropertyInterface*,QVariant) const;
00116 };
00117 
00118 class TLP_QT_SCOPE EdgesGraphModel: public GraphModel {
00119 public:
00120   EdgesGraphModel(QObject* parent = NULL);
00121   void setGraph(Graph *);
00122   void treatEvent(const tlp::Event &);
00123   virtual bool lessThan(unsigned int,unsigned int,tlp::PropertyInterface*) const;
00124   virtual QString stringValue(unsigned int,tlp::PropertyInterface*) const;
00125   virtual QVariant value(unsigned int,tlp::PropertyInterface*) const;
00126 
00127   bool isNode() const {
00128     return false;
00129   }
00130 protected:
00131   virtual bool setValue(unsigned int,tlp::PropertyInterface*,QVariant) const;
00132 };
00133 
00134 }
00135 
00136 #endif // GRAPHMODEL_H
00137 ///@endcond
 All Classes Files Functions Variables Enumerations Enumerator Properties