Tulip  5.0.0
Large graphs analysis and drawing
GlSimpleEntityItemModel.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 
22 #ifndef GLSIMPLEENTITYITEMMODEL_H
23 #define GLSIMPLEENTITYITEMMODEL_H
24 
25 #include <QAbstractItemModel>
26 
27 #include <tulip/tulipconf.h>
28 
29 namespace tlp {
30 
31 class GlSimpleEntity;
32 
33 class TLP_QT_SCOPE GlSimpleEntityItemEditor {
34 public:
35 
36  GlSimpleEntityItemEditor(GlSimpleEntity* ent):entity(ent) {}
37  virtual ~GlSimpleEntityItemEditor() {}
38 
39  /**
40  * @brief Return properties names for this entity
41  * These properties names are used to dynamically configure the embedded entity
42  * for example these function can be used by Mouse information interactor
43  * If you create a class that inherits of GlSimpleEntityItemEditor : you can reimplement this function to return your properties names
44  * for example : return QStringList() << "fillColor" << "outlineColor";
45  * @return QList of properties names
46  */
47  virtual QStringList propertiesNames() const;
48 
49  /**
50  * @brief Return properties (in QVariant format) for this entity
51  * These properties QVariant are used to dynamically configure the entity
52  * for example these function can be used by Mouse information interactor
53  * If you create a class that inherits of GlSimpleEntity : you can reimplement this function to return your properties
54  * for example : return QVariantList() << QVariant::fromValue<Color>(getFillColor()) << QVariant::fromValue<Color>(getOutlineColor());
55  * @return QList of properties (in QVariant format)
56  */
57  virtual QVariantList propertiesQVariant() const;
58 
59  /**
60  * @brief Set value for a property previously returned by propertiesNames() and properties() functions
61  * This function is call when we want to set value of a property
62  * this parameter is returned in list by propertiesNames() and properties funtions
63  * If you create a class that inherits of GlSimpleEntityItemEditor : you can reimplement this function to set your properties
64  * For example :
65  * if(name=="fillColor")
66  * setFillColor(value.value<Color>());
67  * else if(name=="outlineColor")
68  * setOutlineColor(value.value<Color>());
69  */
70  virtual void setProperty(const QString &name, const QVariant &value);
71 
72 protected :
73 
74  GlSimpleEntity *entity;
75 };
76 
77 
78 class TLP_QT_SCOPE GlSimpleEntityItemModel : public QAbstractItemModel {
79  Q_OBJECT
80  Q_ENUMS(SimpleEntityRole)
81 
82 public:
83  enum SimpleEntityRole {
84  SimpleEntityRole = Qt::UserRole+1
85  };
86 
87  GlSimpleEntityItemModel(GlSimpleEntityItemEditor *itemEditor, QObject *parent=NULL);
88  virtual ~GlSimpleEntityItemModel();
89 
90  int rowCount(const QModelIndex &parent = QModelIndex()) const;
91  int columnCount(const QModelIndex &parent = QModelIndex()) const;
92  QModelIndex parent(const QModelIndex &child) const;
93 
94  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
95  QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
96  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
97 
98  QString headerText() const {
99  return QString("toto");
100  }
101 
102  bool setData(const QModelIndex &index, const QVariant &value, int role);
103 
104  Qt::ItemFlags flags(const QModelIndex &index) const {
105  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
106  }
107 
108 protected :
109 
110  GlSimpleEntityItemEditor *editor;
111 };
112 
113 }
114 
115 #endif // GLSIMPLEENTITYITEMMODEL_H
116 ///@endcond