Tulip  5.7.4
Large graphs analysis and drawing
GlSimpleEntityItemModel.h
1 /*
2  *
3  * This file is part of Tulip (https://tulip.labri.fr)
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 #ifndef GLSIMPLEENTITYITEMMODEL_H
22 #define GLSIMPLEENTITYITEMMODEL_H
23 
24 #include <QAbstractItemModel>
25 
26 #include <tulip/tulipconf.h>
27 
28 namespace tlp {
29 
30 class GlSimpleEntity;
31 
32 class TLP_QT_SCOPE GlSimpleEntityItemEditor {
33 public:
34  GlSimpleEntityItemEditor(GlSimpleEntity *ent) : entity(ent) {}
35  virtual ~GlSimpleEntityItemEditor() {}
36 
37  /**
38  * @brief Return properties names for this entity
39  * These properties names are used to dynamically configure the embedded entity
40  * for example this function can be used by Mouse information interactor
41  * If you create a class that inherits of GlSimpleEntityItemEditor : you can reimplement this
42  * function to return your properties names
43  * for example : return QStringList() << "fillColor" << "outlineColor";
44  * @return QList of properties names
45  */
46  virtual QStringList propertiesNames() const;
47 
48  /**
49  * @brief Return properties (in QVariant format) for this entity
50  * These properties QVariant are used to dynamically configure the entity
51  * for example this function can be used by Mouse information interactor
52  * If you create a class that inherits of GlSimpleEntity : you can reimplement this function to
53  * return your properties
54  * for example : return QVariantList() << QVariant::fromValue<Color>(getFillColor()) <<
55  * QVariant::fromValue<Color>(getOutlineColor());
56  * @return QList of properties (in QVariant format)
57  */
58  virtual QVariantList propertiesQVariant() const;
59 
60  /**
61  * @brief Set value for a property previously returned by propertiesNames() and properties()
62  * functions
63  * This function is called to set the value of a property
64  * this parameter is returned in list by propertiesNames() and properties functions
65  * If you create a class that inherits of GlSimpleEntityItemEditor : you can reimplement this
66  * function to set your properties
67  * For example :
68  * if(name=="fillColor")
69  * setFillColor(value.value<Color>());
70  * else if(name=="outlineColor")
71  * setOutlineColor(value.value<Color>());
72  */
73  virtual void setProperty(const QString &name, const QVariant &value);
74 
75 protected:
76  GlSimpleEntity *entity;
77 };
78 
79 class TLP_QT_SCOPE GlSimpleEntityItemModel : public QAbstractItemModel {
80  Q_OBJECT
81  Q_ENUMS(SimpleEntityRole)
82 
83 public:
84  enum class SimpleEntityRole { SimpleEntityRole = Qt::UserRole + 1 };
85 
86  GlSimpleEntityItemModel(GlSimpleEntityItemEditor *itemEditor, QObject *parent = nullptr);
87  ~GlSimpleEntityItemModel() override;
88 
89  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
90  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
91  QModelIndex parent(const QModelIndex &child) const override;
92 
93  QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
94  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
95  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
96 
97  QString headerText() const {
98  return QString("toto");
99  }
100 
101  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
102 
103  Qt::ItemFlags flags(const QModelIndex &index) const override {
104  return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
105  }
106 
107 protected:
108  GlSimpleEntityItemEditor *editor;
109 };
110 } // namespace tlp
111 
112 #endif // GLSIMPLEENTITYITEMMODEL_H
113 ///@endcond