Tulip  5.1.0
Large graphs analysis and drawing
TulipItemEditorCreators.h
1 /*
2  *
3  * This file is part of Tulip (http://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 TULIPITEMEDITORCREATORS_H
22 #define TULIPITEMEDITORCREATORS_H
23 
24 #include <tulip/tulipconf.h>
25 #include <tulip/PropertyTypes.h>
26 #include <tulip/TlpQtTools.h>
27 #include <tulip/TulipViewSettings.h>
28 
29 #include <QVariant>
30 #include <QSize>
31 
32 class QWidget;
33 class QPainter;
34 class QStyleOptionViewItem;
35 class QModelIndex;
36 
37 namespace tlp {
38 
39 class PropertyInterface;
40 
41 class TLP_QT_SCOPE TulipItemEditorCreator {
42 public:
43  virtual ~TulipItemEditorCreator() {}
44  virtual QWidget* createWidget(QWidget*) const=0;
45  virtual bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&, const QModelIndex &) const;
46  virtual QString displayText(const QVariant &) const {
47  return "";
48  }
49 
50  virtual QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
51 
52  virtual void setEditorData(QWidget*,const QVariant&,bool isMandatory,tlp::Graph* g=NULL)=0;
53  virtual QVariant editorData(QWidget*,tlp::Graph* g=NULL)=0;
54  virtual void setPropertyToEdit(tlp::PropertyInterface*) {}
55 };
56 
57 template<typename T>
58 class TLP_QT_SCOPE StringDisplayEditorCreator: public TulipItemEditorCreator {
59 public:
60  inline QString displayText(const QVariant& v) const {
61  return tlpStringToQString(T::toString(v.value<typename T::RealType>()));
62  }
63 };
64 
65 class TLP_QT_SCOPE ColorEditorCreator: public tlp::TulipItemEditorCreator {
66 public:
67  QWidget* createWidget(QWidget*) const;
68  bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&,const QModelIndex &) const;
69  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
70  virtual QVariant editorData(QWidget*,tlp::Graph*);
71 };
72 
73 template<typename T>
74 class NumberEditorCreator: public StringDisplayEditorCreator<T> {
75 public:
76  QWidget* createWidget(QWidget*) const;
77  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
78  virtual QVariant editorData(QWidget*,tlp::Graph*);
79 };
80 
81 template<typename T>
82 class LineEditEditorCreator: public StringDisplayEditorCreator<T> {
83 public:
84  QWidget* createWidget(QWidget*) const;
85  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
86  virtual QVariant editorData(QWidget*,tlp::Graph*);
87 };
88 
89 template<typename T>
90 class MultiLinesEditEditorCreator: public StringDisplayEditorCreator<T> {
91 public:
92  QWidget* createWidget(QWidget*) const;
93  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
94  virtual QVariant editorData(QWidget*,tlp::Graph*);
95  virtual QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
96  bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&,const QModelIndex &) const;
97 };
98 
99 class TLP_QT_SCOPE BooleanEditorCreator: public TulipItemEditorCreator {
100 public:
101  virtual QWidget* createWidget(QWidget*) const;
102  virtual void setEditorData(QWidget*,const QVariant&,bool,tlp::Graph*);
103  virtual QVariant editorData(QWidget*,tlp::Graph*);
104  virtual QString displayText(const QVariant &) const;
105 };
106 
107 class TLP_QT_SCOPE CoordEditorCreator: public StringDisplayEditorCreator<tlp::PointType> {
108  bool editSize;
109 public:
110  CoordEditorCreator():editSize(false) {}
111  QWidget* createWidget(QWidget*) const;
112  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
113  virtual QVariant editorData(QWidget*,tlp::Graph*);
114  virtual void setPropertyToEdit(tlp::PropertyInterface* prop);
115 };
116 
117 template<typename PROP>
118 class PropertyEditorCreator: public tlp::TulipItemEditorCreator {
119 public:
120  QWidget* createWidget(QWidget*) const;
121  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
122  virtual QVariant editorData(QWidget*,tlp::Graph*);
123  virtual QString displayText(const QVariant &) const;
124 };
125 
126 class TLP_QT_SCOPE PropertyInterfaceEditorCreator: public tlp::TulipItemEditorCreator {
127 public:
128  QWidget* createWidget(QWidget*) const;
129  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
130  virtual QVariant editorData(QWidget*,tlp::Graph*);
131  virtual QString displayText(const QVariant &) const;
132 };
133 
134 class TLP_QT_SCOPE NumericPropertyEditorCreator: public tlp::TulipItemEditorCreator {
135 public:
136  QWidget* createWidget(QWidget*) const;
137  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
138  virtual QVariant editorData(QWidget*,tlp::Graph*);
139  virtual QString displayText(const QVariant &) const;
140 };
141 
142 class TLP_QT_SCOPE ColorScaleEditorCreator: public tlp::TulipItemEditorCreator {
143 public:
144  QWidget* createWidget(QWidget*) const;
145  bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&, const QModelIndex &) const;
146  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
147  virtual QVariant editorData(QWidget*,tlp::Graph*);
148 };
149 
150 class TLP_QT_SCOPE StringCollectionEditorCreator: public tlp::TulipItemEditorCreator {
151 public:
152  QWidget* createWidget(QWidget*) const;
153  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
154  virtual QVariant editorData(QWidget*,tlp::Graph*);
155  virtual QString displayText(const QVariant &) const;
156 };
157 
158 class TLP_QT_SCOPE TulipFileDescriptorEditorCreator: public tlp::TulipItemEditorCreator {
159 public:
160  QWidget* createWidget(QWidget*) const;
161  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
162  virtual QVariant editorData(QWidget*,tlp::Graph*);
163  virtual bool paint(QPainter *, const QStyleOptionViewItem &, const QVariant &, const QModelIndex &) const;
164  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
165 };
166 
167 class TLP_QT_SCOPE TextureFileEditorCreator: 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 bool paint(QPainter *, const QStyleOptionViewItem &, const QVariant &, const QModelIndex &index) const;
173  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
174 };
175 
176 class TLP_QT_SCOPE TulipFontIconCreator: public tlp::TulipItemEditorCreator {
177 public:
178  QWidget* createWidget(QWidget*) const;
179  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
180  virtual QVariant editorData(QWidget*,tlp::Graph*);
181  virtual bool paint(QPainter *, const QStyleOptionViewItem &, const QVariant &, const QModelIndex &) const;
182  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
183  virtual QString displayText(const QVariant &) const;
184 };
185 
186 class TLP_QT_SCOPE NodeShapeEditorCreator: public tlp::TulipItemEditorCreator {
187 public:
188  QWidget* createWidget(QWidget*) const;
189  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
190  virtual QVariant editorData(QWidget*,tlp::Graph*);
191  virtual QString displayText(const QVariant &) const;
192  virtual bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&, const QModelIndex &index) const;
193  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
194 };
195 
196 class TLP_QT_SCOPE EdgeExtremityShapeEditorCreator: public tlp::TulipItemEditorCreator {
197 public:
198  QWidget* createWidget(QWidget*) const;
199  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
200  virtual QVariant editorData(QWidget*,tlp::Graph*);
201  virtual QString displayText(const QVariant &) const;
202  virtual bool paint(QPainter*, const QStyleOptionViewItem&, const QVariant&, const QModelIndex &index) const;
203  QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const;
204 };
205 
206 class TLP_QT_SCOPE EdgeShapeEditorCreator: public tlp::TulipItemEditorCreator {
207 public:
208  QWidget* createWidget(QWidget*) const;
209  virtual void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
210  virtual QVariant editorData(QWidget*,tlp::Graph*);
211  virtual QString displayText(const QVariant &) const;
212 };
213 
214 template<typename ElementType>
215 class VectorEditorCreator : public tlp::TulipItemEditorCreator {
216 public:
217  QWidget* createWidget(QWidget* parent) const;
218  virtual void setEditorData(QWidget* editor, const QVariant& data,bool,tlp::Graph*);
219  virtual QVariant editorData(QWidget* editor,tlp::Graph*);
220  virtual QString displayText(const QVariant &data) const;
221 };
222 
223 class QVectorBoolEditorCreator : public tlp::TulipItemEditorCreator {
224 public:
225  QWidget* createWidget(QWidget* parent) const;
226  virtual void setEditorData(QWidget* editor, const QVariant& data,bool,tlp::Graph*);
227  virtual QVariant editorData(QWidget* editor,tlp::Graph*);
228  virtual QString displayText(const QVariant &data) const;
229 };
230 
231 struct TLP_QT_SCOPE TulipFontEditorCreator: public tlp::TulipItemEditorCreator {
232  QWidget* createWidget(QWidget*) const;
233  void setEditorData(QWidget*, const QVariant&,bool,tlp::Graph*);
234  QVariant editorData(QWidget*,tlp::Graph*);
235  QString displayText(const QVariant &) const;
236 };
237 
238 class TLP_QT_SCOPE TulipLabelPositionEditorCreator: public tlp::TulipItemEditorCreator {
239 
240 public:
241  QWidget* createWidget(QWidget*) const;
242  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
243  QVariant editorData(QWidget*,tlp::Graph*);
244  QString displayText(const QVariant &) const;
245 
246 };
247 
248 class TLP_QT_SCOPE GraphEditorCreator: public tlp::TulipItemEditorCreator {
249 public:
250  QWidget* createWidget(QWidget* parent) const;
251  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
252  QVariant editorData(QWidget*,tlp::Graph*);
253  QString displayText(const QVariant &) const;
254 };
255 
256 class TLP_QT_SCOPE EdgeSetEditorCreator: public tlp::TulipItemEditorCreator {
257 public:
258  QWidget* createWidget(QWidget* parent) const;
259  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
260  QVariant editorData(QWidget*,tlp::Graph*);
261  QString displayText(const QVariant &) const;
262 };
263 
264 class TLP_QT_SCOPE QStringEditorCreator: public tlp::TulipItemEditorCreator {
265 public:
266  QWidget* createWidget(QWidget* parent) const;
267  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
268  QVariant editorData(QWidget*,tlp::Graph*);
269  QString displayText(const QVariant &) const;
270  void setPropertyToEdit(tlp::PropertyInterface* prop);
271 
272 protected:
273  std::string propName;
274 };
275 
276 class TLP_QT_SCOPE StdStringEditorCreator: public QStringEditorCreator {
277 public:
278  void setEditorData(QWidget*w, const QVariant&var, bool, tlp::Graph*);
279  QVariant editorData(QWidget*,tlp::Graph*);
280  QString displayText(const QVariant &) const;
281 };
282 
283 class TLP_QT_SCOPE QStringListEditorCreator: public tlp::TulipItemEditorCreator {
284 public:
285  QWidget* createWidget(QWidget* parent) const;
286  void setEditorData(QWidget*w, const QVariant& var, bool, tlp::Graph*);
287  QVariant editorData(QWidget*,tlp::Graph*);
288  QString displayText(const QVariant &) const;
289 };
290 
291 TLP_QT_SCOPE void addIconToPool(const QString &iconName, const QIcon &icon);
292 
293 }
294 
295 
296 #if defined(__clang__)
297 template class tlp::StringDisplayEditorCreator<tlp::PointType>;
298 template class tlp::StringDisplayEditorCreator<tlp::SizeType>;
299 #endif
300 
301 inline QString& truncateText(QString &text, const QString &trailingChars = " ...", int maxChars=45) {
302  if (text.size() > maxChars) {
303  text.truncate(maxChars - trailingChars.length());
304  text.append(trailingChars);
305  }
306 
307  return text;
308 }
309 
310 #include "cxx/TulipItemEditorCreators.cxx"
311 
312 #endif // TULIPITEMEDITORCREATORS_H
313 ///@endcond
PropertyInterface describes the interface of a graph property.
QString tlpStringToQString(const std::string &toConvert)
Convert a Tulip UTF-8 encoded std::string to a QString.
Definition: TlpQtTools.h:54