21 #ifndef TULIPITEMEDITORCREATORS_H
22 #define TULIPITEMEDITORCREATORS_H
24 #include <tulip/tulipconf.h>
25 #include <tulip/PropertyTypes.h>
26 #include <tulip/TlpQtTools.h>
27 #include <tulip/TulipViewSettings.h>
34 class QStyleOptionViewItem;
39 class PropertyInterface;
41 class TLP_QT_SCOPE TulipItemEditorCreator {
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 {
51 virtual QSize sizeHint(
const QStyleOptionViewItem &,
const QModelIndex &)
const;
53 virtual void setEditorData(QWidget *,
const QVariant &,
bool isMandatory,
55 virtual QVariant editorData(QWidget *,
tlp::Graph *g =
nullptr) = 0;
60 class TLP_QT_SCOPE StringDisplayEditorCreator :
public TulipItemEditorCreator {
62 inline QString displayText(
const QVariant &v)
const override {
67 class TLP_QT_SCOPE ColorEditorCreator :
public tlp::TulipItemEditorCreator {
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;
77 class NumberEditorCreator :
public StringDisplayEditorCreator<T> {
79 QWidget *createWidget(QWidget *)
const override;
80 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
81 QVariant editorData(QWidget *,
tlp::Graph *)
override;
85 class LineEditEditorCreator :
public StringDisplayEditorCreator<T> {
87 QWidget *createWidget(QWidget *)
const;
88 virtual void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *);
89 virtual QVariant editorData(QWidget *,
tlp::Graph *);
93 class MultiLinesEditEditorCreator :
public StringDisplayEditorCreator<T> {
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;
103 class TLP_QT_SCOPE BooleanEditorCreator :
public TulipItemEditorCreator {
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;
111 class TLP_QT_SCOPE CoordEditorCreator :
public StringDisplayEditorCreator<tlp::PointType> {
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;
122 template <
typename PROP>
123 class PropertyEditorCreator :
public tlp::TulipItemEditorCreator {
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;
131 class TLP_QT_SCOPE PropertyInterfaceEditorCreator :
public tlp::TulipItemEditorCreator {
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;
139 class TLP_QT_SCOPE NumericPropertyEditorCreator :
public tlp::TulipItemEditorCreator {
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;
147 class TLP_QT_SCOPE ColorScaleEditorCreator :
public tlp::TulipItemEditorCreator {
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;
156 class TLP_QT_SCOPE StringCollectionEditorCreator :
public tlp::TulipItemEditorCreator {
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;
164 class TLP_QT_SCOPE PropertiesCollectionEditorCreator :
public tlp::TulipItemEditorCreator {
166 QWidget *createWidget(QWidget *)
const override;
167 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
168 QVariant editorData(QWidget *,
tlp::Graph *)
override;
169 QString displayText(
const QVariant &)
const override;
172 class TLP_QT_SCOPE TulipFileDescriptorEditorCreator :
public tlp::TulipItemEditorCreator {
174 QWidget *createWidget(QWidget *)
const override;
175 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
176 QVariant editorData(QWidget *,
tlp::Graph *)
override;
177 bool paint(QPainter *,
const QStyleOptionViewItem &,
const QVariant &,
178 const QModelIndex &)
const override;
179 QSize sizeHint(
const QStyleOptionViewItem &,
const QModelIndex &)
const override;
182 class TLP_QT_SCOPE TextureFileEditorCreator :
public tlp::TulipItemEditorCreator {
184 QWidget *createWidget(QWidget *)
const override;
185 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
186 QVariant editorData(QWidget *,
tlp::Graph *)
override;
187 bool paint(QPainter *,
const QStyleOptionViewItem &,
const QVariant &,
188 const QModelIndex &index)
const override;
189 QSize sizeHint(
const QStyleOptionViewItem &,
const QModelIndex &)
const override;
192 class TLP_QT_SCOPE TulipFontIconCreator :
public tlp::TulipItemEditorCreator {
194 QWidget *createWidget(QWidget *)
const override;
195 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
196 QVariant editorData(QWidget *,
tlp::Graph *)
override;
197 bool paint(QPainter *,
const QStyleOptionViewItem &,
const QVariant &,
198 const QModelIndex &)
const override;
199 QSize sizeHint(
const QStyleOptionViewItem &,
const QModelIndex &)
const override;
200 QString displayText(
const QVariant &)
const override;
203 class TLP_QT_SCOPE NodeShapeEditorCreator :
public tlp::TulipItemEditorCreator {
205 QWidget *createWidget(QWidget *)
const override;
206 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
207 QVariant editorData(QWidget *,
tlp::Graph *)
override;
208 QString displayText(
const QVariant &)
const override;
209 bool paint(QPainter *,
const QStyleOptionViewItem &,
const QVariant &,
210 const QModelIndex &index)
const override;
211 QSize sizeHint(
const QStyleOptionViewItem &,
const QModelIndex &)
const override;
214 class TLP_QT_SCOPE EdgeExtremityShapeEditorCreator :
public tlp::TulipItemEditorCreator {
216 QWidget *createWidget(QWidget *)
const override;
217 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
218 QVariant editorData(QWidget *,
tlp::Graph *)
override;
219 QString displayText(
const QVariant &)
const override;
220 bool paint(QPainter *,
const QStyleOptionViewItem &,
const QVariant &,
221 const QModelIndex &index)
const override;
222 QSize sizeHint(
const QStyleOptionViewItem &,
const QModelIndex &)
const override;
225 class TLP_QT_SCOPE EdgeShapeEditorCreator :
public tlp::TulipItemEditorCreator {
227 QWidget *createWidget(QWidget *)
const override;
228 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
229 QVariant editorData(QWidget *,
tlp::Graph *)
override;
230 QString displayText(
const QVariant &)
const override;
233 template <
typename ElementType>
234 class VectorEditorCreator :
public tlp::TulipItemEditorCreator {
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;
242 class QVectorBoolEditorCreator :
public tlp::TulipItemEditorCreator {
244 QWidget *createWidget(QWidget *parent)
const override;
245 void setEditorData(QWidget *editor,
const QVariant &data,
bool,
tlp::Graph *)
override;
246 QVariant editorData(QWidget *editor,
tlp::Graph *)
override;
247 QString displayText(
const QVariant &data)
const override;
250 struct TLP_QT_SCOPE TulipFontEditorCreator :
public tlp::TulipItemEditorCreator {
251 QWidget *createWidget(QWidget *)
const override;
252 void setEditorData(QWidget *,
const QVariant &,
bool,
tlp::Graph *)
override;
253 QVariant editorData(QWidget *,
tlp::Graph *)
override;
254 QString displayText(
const QVariant &)
const override;
257 class TLP_QT_SCOPE TulipLabelPositionEditorCreator :
public tlp::TulipItemEditorCreator {
260 QWidget *createWidget(QWidget *)
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;
266 class TLP_QT_SCOPE GraphEditorCreator :
public tlp::TulipItemEditorCreator {
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;
274 class TLP_QT_SCOPE EdgeSetEditorCreator :
public tlp::TulipItemEditorCreator {
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;
282 class TLP_QT_SCOPE QStringEditorCreator :
public tlp::TulipItemEditorCreator {
284 QWidget *createWidget(QWidget *parent)
const override;
285 void setEditorData(QWidget *w,
const QVariant &var,
bool,
tlp::Graph *)
override;
286 QVariant editorData(QWidget *,
tlp::Graph *)
override;
287 QString displayText(
const QVariant &)
const override;
291 std::string propName;
294 class TLP_QT_SCOPE StdStringEditorCreator :
public QStringEditorCreator {
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;
301 class TLP_QT_SCOPE QStringListEditorCreator :
public tlp::TulipItemEditorCreator {
303 QWidget *createWidget(QWidget *parent)
const override;
304 void setEditorData(QWidget *w,
const QVariant &var,
bool,
tlp::Graph *)
override;
305 QVariant editorData(QWidget *,
tlp::Graph *)
override;
306 QString displayText(
const QVariant &)
const override;
309 TLP_QT_SCOPE
void addIconToPool(
const QString &iconName,
const QIcon &icon);
312 #if defined(__clang__)
313 template class tlp::StringDisplayEditorCreator<tlp::PointType>;
314 template class tlp::StringDisplayEditorCreator<tlp::SizeType>;
317 inline QString &truncateText(QString &text,
const QString &trailingChars =
" ...",
319 if (text.size() > maxChars) {
320 text.truncate(maxChars - trailingChars.length());
321 text.append(trailingChars);
327 #include "cxx/TulipItemEditorCreators.cxx"
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.