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