Tulip  4.6.0
Better Visualization Through Research
library/tulip-gui/include/tulip/GlSimpleEntityItemModel.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 
00022 #ifndef GLSIMPLEENTITYITEMMODEL_H
00023 #define GLSIMPLEENTITYITEMMODEL_H
00024 
00025 #include <QAbstractItemModel>
00026 
00027 #include <tulip/tulipconf.h>
00028 
00029 namespace tlp {
00030 
00031 class GlSimpleEntity;
00032 
00033 class TLP_QT_SCOPE GlSimpleEntityItemEditor {
00034 public:
00035 
00036   GlSimpleEntityItemEditor(GlSimpleEntity* ent):entity(ent) {}
00037   virtual ~GlSimpleEntityItemEditor() {}
00038 
00039   /**
00040    * @brief Return properties names for this entity
00041    * These properties names are used to dynamically configure the embedded entity
00042    * for example these function can be used by Mouse information interactor
00043    * If you create a class that inherits of GlSimpleEntityItemEditor : you can reimplement this function to return your properties names
00044    * for example : return QStringList() << "fillColor" << "outlineColor";
00045    * @return QList of properties names
00046    */
00047   virtual QStringList propertiesNames() const;
00048 
00049   /**
00050    * @brief Return properties (in  QVariant format) for this entity
00051    * These properties QVariant are used to dynamically configure the entity
00052    * for example these function can be used by Mouse information interactor
00053    * If you create a class that inherits of GlSimpleEntity : you can reimplement this function to return your properties
00054    * for example : return QVariantList() << QVariant::fromValue<Color>(getFillColor()) << QVariant::fromValue<Color>(getOutlineColor());
00055    * @return QList of properties (in QVariant format)
00056    */
00057   virtual QVariantList propertiesQVariant() const;
00058 
00059   /**
00060    * @brief Set value for a property previously returned by propertiesNames() and properties() functions
00061    * This function is call when we want to set value of a property
00062    * this parameter is returned in list by propertiesNames() and properties funtions
00063    * If you create a class that inherits of GlSimpleEntityItemEditor : you can reimplement this function to set your properties
00064    * For example :
00065    * if(name=="fillColor")
00066    *   setFillColor(value.value<Color>());
00067    * else if(name=="outlineColor")
00068    *   setOutlineColor(value.value<Color>());
00069    */
00070   virtual void setProperty(const QString &name, const QVariant &value);
00071 
00072 protected :
00073 
00074   GlSimpleEntity *entity;
00075 };
00076 
00077 
00078 class TLP_QT_SCOPE GlSimpleEntityItemModel : public QAbstractItemModel {
00079   Q_OBJECT
00080   Q_ENUMS(SimpleEntityRole)
00081 
00082 public:
00083   enum SimpleEntityRole {
00084     SimpleEntityRole = Qt::UserRole+1
00085   };
00086 
00087   GlSimpleEntityItemModel(GlSimpleEntityItemEditor *itemEditor, QObject *parent=NULL);
00088   virtual ~GlSimpleEntityItemModel();
00089 
00090   int rowCount(const QModelIndex &parent = QModelIndex()) const;
00091   int columnCount(const QModelIndex &parent = QModelIndex()) const;
00092   QModelIndex parent(const QModelIndex &child) const;
00093 
00094   QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00095   QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
00096   QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00097 
00098   QString headerText() const {
00099     return QString("toto");
00100   }
00101 
00102   bool setData(const QModelIndex &index, const QVariant &value, int role);
00103 
00104   Qt::ItemFlags flags(const QModelIndex &index) const {
00105     return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
00106   }
00107 
00108 protected :
00109 
00110   GlSimpleEntityItemEditor *editor;
00111 };
00112 
00113 }
00114 
00115 #endif // GLSIMPLEENTITYITEMMODEL_H
00116 ///@endcond
 All Classes Files Functions Variables Enumerations Enumerator Properties