Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
TulipItemEditorCreators.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 1 and Inria Bordeaux - Sud Ouest
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 TULIPITEMEDITORCREATORS_H
22 #define TULIPITEMEDITORCREATORS_H
23 
24 #include <tulip/tulipconf.h>
25 #include <tulip/PropertyTypes.h>
26 
27 #include <QVariant>
28 #include <QSize>
29 
30 class QWidget;
31 class QPainter;
32 class QStyleOptionViewItem;
33 class QModelIndex;
34 
35 namespace tlp {
36 
37 class PropertyInterface;
38 
39 class TLP_QT_SCOPE TulipItemEditorCreator {
40 public:
41  virtual ~TulipItemEditorCreator() {}
42  virtual QWidget* createWidget(QWidget*) const=0;
43  virtual bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&) const;
44  virtual QString displayText(const QVariant &) const {
45  return "";
46  }
47 
48  virtual QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
49 
50  virtual void setEditorData(QWidget*,const QVariant&,bool isMandatory,tlp::Graph* g=NULL)=0;
51  virtual QVariant editorData(QWidget*,tlp::Graph* g=NULL)=0;
52  virtual void setPropertyToEdit(tlp::PropertyInterface*) {}
53 };
54 
55 template<typename T>
56 class TLP_QT_SCOPE StringDisplayEditorCreator: public TulipItemEditorCreator {
57 public:
58  inline QString displayText(const QVariant& v) const {
59  return QString::fromUtf8(T::toString(v.value<typename T::RealType>()).c_str());
60  }
61 };
62 
63 class TLP_QT_SCOPE ColorEditorCreator: public tlp::TulipItemEditorCreator {
64 public:
65  QWidget* createWidget(QWidget*) const;
66  bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&) const;
67  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
68  virtual QVariant editorData(QWidget*,tlp::Graph*);
69 };
70 
71 template<typename T>
72 class LineEditEditorCreator: public StringDisplayEditorCreator<T> {
73 public:
74  QWidget* createWidget(QWidget*) const;
75  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
76  virtual QVariant editorData(QWidget*,tlp::Graph*);
77 };
78 
79 template<typename T>
80 class MultiLinesEditEditorCreator: public StringDisplayEditorCreator<T> {
81 public:
82  QWidget* createWidget(QWidget*) const;
83  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
84  virtual QVariant editorData(QWidget*,tlp::Graph*);
85  virtual QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
86  bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&) const;
87 };
88 
89 class TLP_QT_SCOPE BooleanEditorCreator: public TulipItemEditorCreator {
90 public:
91  virtual QWidget* createWidget(QWidget*) const;
92  virtual void setEditorData(QWidget*,const QVariant&,bool,tlp::Graph*);
93  virtual QVariant editorData(QWidget*,tlp::Graph*);
94  virtual QString displayText(const QVariant &) const;
95 };
96 
97 class TLP_QT_SCOPE CoordEditorCreator: public StringDisplayEditorCreator<tlp::PointType> {
98  bool editSize;
99 public:
100  CoordEditorCreator():editSize(false) {}
101  QWidget* createWidget(QWidget*) const;
102  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
103  virtual QVariant editorData(QWidget*,tlp::Graph*);
104  virtual void setPropertyToEdit(tlp::PropertyInterface* prop);
105 };
106 
107 template<typename PROP>
108 class PropertyEditorCreator: public tlp::TulipItemEditorCreator {
109 public:
110  QWidget* createWidget(QWidget*) const;
111  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
112  virtual QVariant editorData(QWidget*,tlp::Graph*);
113  virtual QString displayText(const QVariant &) const;
114 };
115 
116 class TLP_QT_SCOPE PropertyInterfaceEditorCreator: public tlp::TulipItemEditorCreator {
117 public:
118  QWidget* createWidget(QWidget*) const;
119  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
120  virtual QVariant editorData(QWidget*,tlp::Graph*);
121  virtual QString displayText(const QVariant &) const;
122 };
123 
124 class TLP_QT_SCOPE NumericPropertyEditorCreator: public tlp::TulipItemEditorCreator {
125 public:
126  QWidget* createWidget(QWidget*) const;
127  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
128  virtual QVariant editorData(QWidget*,tlp::Graph*);
129  virtual QString displayText(const QVariant &) const;
130 };
131 
132 class TLP_QT_SCOPE ColorScaleEditorCreator: public tlp::TulipItemEditorCreator {
133 public:
134  QWidget* createWidget(QWidget*) const;
135  bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&) const;
136  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
137  virtual QVariant editorData(QWidget*,tlp::Graph*);
138 };
139 
140 class TLP_QT_SCOPE StringCollectionEditorCreator: public tlp::TulipItemEditorCreator {
141 public:
142  QWidget* createWidget(QWidget*) const;
143  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
144  virtual QVariant editorData(QWidget*,tlp::Graph*);
145  virtual QString displayText(const QVariant &) const;
146 };
147 
148 class TLP_QT_SCOPE TulipFileDescriptorEditorCreator: public tlp::TulipItemEditorCreator {
149 public:
150  QWidget* createWidget(QWidget*) const;
151  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
152  virtual QVariant editorData(QWidget*,tlp::Graph*);
153  virtual bool paint(QPainter *, const QStyleOptionViewItem &, const QVariant &) const;
154  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
155 };
156 
157 class TLP_QT_SCOPE NodeShapeEditorCreator: public tlp::TulipItemEditorCreator {
158 public:
159  QWidget* createWidget(QWidget*) const;
160  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
161  virtual QVariant editorData(QWidget*,tlp::Graph*);
162  virtual QString displayText(const QVariant &) const;
163  virtual bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&) const;
164  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
165 };
166 
167 class TLP_QT_SCOPE EdgeExtremityShapeEditorCreator: public tlp::TulipItemEditorCreator {
168 public:
169  QWidget* createWidget(QWidget*) const;
170  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
171  virtual QVariant editorData(QWidget*,tlp::Graph*);
172  virtual QString displayText(const QVariant &) const;
173  virtual bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&) const;
174  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
175 };
176 
177 class TLP_QT_SCOPE EdgeShapeEditorCreator: public tlp::TulipItemEditorCreator {
178 public:
179  QWidget* createWidget(QWidget*) const;
180  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
181  virtual QVariant editorData(QWidget*,tlp::Graph*);
182  virtual QString displayText(const QVariant &) const;
183 };
184 
185 template<typename ElementType>
186 class VectorEditorCreator : public tlp::TulipItemEditorCreator {
187 public:
188  QWidget* createWidget(QWidget* parent) const;
189  virtual void setEditorData(QWidget* editor, const QVariant& data,bool,tlp::Graph*);
190  virtual QVariant editorData(QWidget* editor,tlp::Graph*);
191  virtual QString displayText(const QVariant &data) const;
192 };
193 
194 
195 class TLP_QT_SCOPE TulipFontEditorCreator: public tlp::TulipItemEditorCreator {
196 public:
197  QWidget* createWidget(QWidget*) const;
198  void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
199  QVariant editorData(QWidget*,tlp::Graph*);
200  QString displayText(const QVariant &) const;
201 };
202 
203 class TLP_QT_SCOPE TulipLabelPositionEditorCreator: public tlp::TulipItemEditorCreator {
204  static QVector<QString> POSITION_LABEL;
205 public:
206  QWidget* createWidget(QWidget*) const;
207  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
208  QVariant editorData(QWidget*,tlp::Graph*);
209  QString displayText(const QVariant &) const;
210 };
211 
212 class TLP_QT_SCOPE GraphEditorCreator: public tlp::TulipItemEditorCreator {
213 public:
214  QWidget* createWidget(QWidget* parent) const;
215  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
216  QVariant editorData(QWidget*,tlp::Graph*);
217  QString displayText(const QVariant &) const;
218 };
219 
220 class TLP_QT_SCOPE EdgeSetEditorCreator: public tlp::TulipItemEditorCreator {
221 public:
222  QWidget* createWidget(QWidget* parent) const;
223  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
224  QVariant editorData(QWidget*,tlp::Graph*);
225  QString displayText(const QVariant &) const;
226 };
227 
228 class TLP_QT_SCOPE QStringEditorCreator: public tlp::TulipItemEditorCreator {
229 public:
230  QWidget* createWidget(QWidget* parent) const;
231  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
232  QVariant editorData(QWidget*,tlp::Graph*);
233  QString displayText(const QVariant &) const;
234 };
235 
236 class TLP_QT_SCOPE QStringListEditorCreator: public tlp::TulipItemEditorCreator {
237 public:
238  QWidget* createWidget(QWidget* parent) const;
239  void setEditorData(QWidget*w, const QVariant& var, bool, tlp::Graph*);
240  QVariant editorData(QWidget*,tlp::Graph*);
241  QString displayText(const QVariant &) const;
242 };
243 
244 }
245 
246 
247 #if defined(__clang__)
248 template class tlp::StringDisplayEditorCreator<tlp::PointType>;
249 template class tlp::StringDisplayEditorCreator<tlp::SizeType>;
250 #endif
251 
252 
253 #include "cxx/TulipItemEditorCreators.cxx"
254 
255 #endif // TULIPITEMEDITORCREATORS_H
256 ///@endcond