~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/propertyeditor/PropertyItem.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2004 Werner Mayer <werner.wm.mayer@gmx.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#ifndef PROPERTYEDITORITEM_H
 
25
#define PROPERTYEDITORITEM_H
 
26
 
 
27
#ifndef __Qt4All__
 
28
# include <Gui/Qt4All.h>
 
29
#endif
 
30
 
 
31
#include <vector>
 
32
 
 
33
#include <Base/Type.h>
 
34
#include <Base/Vector3D.h>
 
35
#include <Base/Placement.h>
 
36
#include <App/PropertyStandard.h>
 
37
 
 
38
Q_DECLARE_METATYPE(Base::Vector3f)
 
39
Q_DECLARE_METATYPE(Base::Placement)
 
40
 
 
41
namespace Gui {
 
42
namespace PropertyEditor {
 
43
 
 
44
class GuiExport PropertyItem : virtual public QObject, public Base::BaseClass
 
45
{
 
46
    Q_OBJECT
 
47
 
 
48
    TYPESYSTEM_HEADER();
 
49
 
 
50
public:
 
51
    ~PropertyItem();
 
52
 
 
53
    /** Sets the current property objects. */
 
54
    void setPropertyData( const std::vector<App::Property*>& );
 
55
    const std::vector<App::Property*>& getPropertyData() const;
 
56
 
 
57
    /** Creates the appropriate editor for this item and sets the editor to the value of overrideValue(). */
 
58
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
59
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
60
    virtual QVariant editorData(QWidget *editor) const;
 
61
    virtual bool isSeparator() const { return false; }
 
62
 
 
63
    void setParent(PropertyItem* parent);
 
64
    PropertyItem *parent() const;
 
65
    void appendChild(PropertyItem *child);
 
66
 
 
67
    void setReadOnly(bool);
 
68
    bool isReadOnly() const;
 
69
 
 
70
    PropertyItem *child(int row);
 
71
    int childCount() const;
 
72
    int columnCount() const;
 
73
    QString propertyName() const;
 
74
    void setPropertyName(const QString&);
 
75
    void setPropertyValue(const QString&);
 
76
    QVariant data(int column, int role) const;
 
77
    bool setData (const QVariant& value);
 
78
    Qt::ItemFlags flags(int column) const;
 
79
    int row() const;
 
80
    void reset();
 
81
 
 
82
protected:
 
83
    PropertyItem();
 
84
 
 
85
    virtual QVariant decoration(const App::Property*) const;
 
86
    virtual QVariant toolTip(const App::Property*) const;
 
87
    virtual QVariant toString(const QVariant&) const;
 
88
    virtual QVariant value(const App::Property*) const;
 
89
    virtual void setValue(const QVariant&);
 
90
    QString pythonIdentifier(const App::Property*) const;
 
91
 
 
92
private:
 
93
    QString propName;
 
94
    QVariant propData;
 
95
    std::vector<App::Property*> propertyItems;
 
96
    PropertyItem *parentItem;
 
97
    QList<PropertyItem*> childItems;
 
98
    bool readonly;
 
99
};
 
100
 
 
101
/**
 
102
 * Change a string property.
 
103
 * \author Werner Mayer
 
104
 */
 
105
class GuiExport PropertyStringItem: public PropertyItem
 
106
{
 
107
    TYPESYSTEM_HEADER();
 
108
 
 
109
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
110
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
111
    virtual QVariant editorData(QWidget *editor) const;
 
112
 
 
113
protected:
 
114
    virtual QVariant value(const App::Property*) const;
 
115
    virtual void setValue(const QVariant&);
 
116
 
 
117
protected:
 
118
    PropertyStringItem();
 
119
};
 
120
 
 
121
/**
 
122
 * Dummy property to separate groups of properties.
 
123
 * \author Werner Mayer
 
124
 */
 
125
class GuiExport PropertySeparatorItem : public PropertyItem
 
126
{
 
127
    TYPESYSTEM_HEADER();
 
128
 
 
129
    bool isSeparator() const { return true; }
 
130
    QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
131
};
 
132
 
 
133
/**
 
134
 * Change a number.
 
135
 * \author Werner Mayer
 
136
 */
 
137
class GuiExport PropertyIntegerItem: public PropertyItem
 
138
{
 
139
    TYPESYSTEM_HEADER();
 
140
 
 
141
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
142
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
143
    virtual QVariant editorData(QWidget *editor) const;
 
144
 
 
145
protected:
 
146
    virtual QVariant value(const App::Property*) const;
 
147
    virtual void setValue(const QVariant&);
 
148
 
 
149
protected:
 
150
    PropertyIntegerItem();
 
151
};
 
152
 
 
153
/**
 
154
 * Change a number with constraints.
 
155
 * \author Werner Mayer
 
156
 */
 
157
class GuiExport PropertyIntegerConstraintItem: public PropertyItem
 
158
{
 
159
    TYPESYSTEM_HEADER();
 
160
 
 
161
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
162
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
163
    virtual QVariant editorData(QWidget *editor) const;
 
164
 
 
165
protected:
 
166
    virtual QVariant value(const App::Property*) const;
 
167
    virtual void setValue(const QVariant&);
 
168
 
 
169
protected:
 
170
    PropertyIntegerConstraintItem();
 
171
};
 
172
 
 
173
/**
 
174
 * Change a floating point number.
 
175
 * \author Werner Mayer
 
176
 */
 
177
class GuiExport PropertyFloatItem: public PropertyItem
 
178
{
 
179
    TYPESYSTEM_HEADER();
 
180
 
 
181
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
182
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
183
    virtual QVariant editorData(QWidget *editor) const;
 
184
 
 
185
protected:
 
186
    virtual QVariant toString(const QVariant&) const;
 
187
    virtual QVariant value(const App::Property*) const;
 
188
    virtual void setValue(const QVariant&);
 
189
 
 
190
protected:
 
191
    PropertyFloatItem();
 
192
};
 
193
 
 
194
/**
 
195
 * Change a floating point number with constraints.
 
196
 * \author Werner Mayer
 
197
 */
 
198
class GuiExport PropertyFloatConstraintItem: public PropertyItem
 
199
{
 
200
    TYPESYSTEM_HEADER();
 
201
 
 
202
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
203
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
204
    virtual QVariant editorData(QWidget *editor) const;
 
205
 
 
206
protected:
 
207
    virtual QVariant toString(const QVariant&) const;
 
208
    virtual QVariant value(const App::Property*) const;
 
209
    virtual void setValue(const QVariant&);
 
210
 
 
211
protected:
 
212
    PropertyFloatConstraintItem();
 
213
};
 
214
 
 
215
/**
 
216
 * Edit properties of boolean type. 
 
217
 * \author Werner Mayer
 
218
 */
 
219
class GuiExport PropertyBoolItem: public PropertyItem
 
220
{
 
221
    TYPESYSTEM_HEADER();
 
222
 
 
223
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
224
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
225
    virtual QVariant editorData(QWidget *editor) const;
 
226
 
 
227
protected:
 
228
    virtual QVariant value(const App::Property*) const;
 
229
    virtual void setValue(const QVariant&);
 
230
 
 
231
protected:
 
232
    PropertyBoolItem();
 
233
};
 
234
 
 
235
/**
 
236
 * Edit properties of vector type. 
 
237
 * \author Werner Mayer
 
238
 */
 
239
class PropertyFloatItem;
 
240
class GuiExport PropertyVectorItem: public PropertyItem
 
241
{
 
242
    Q_OBJECT
 
243
    Q_PROPERTY(double x READ x WRITE setX DESIGNABLE true USER true)
 
244
    Q_PROPERTY(double y READ y WRITE setY DESIGNABLE true USER true)
 
245
    Q_PROPERTY(double z READ z WRITE setZ DESIGNABLE true USER true)
 
246
    TYPESYSTEM_HEADER();
 
247
 
 
248
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
249
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
250
    virtual QVariant editorData(QWidget *editor) const;
 
251
 
 
252
    double x() const;
 
253
    void setX(double x);
 
254
    double y() const;
 
255
    void setY(double y);
 
256
    double z() const;
 
257
    void setZ(double z);
 
258
 
 
259
protected:
 
260
    virtual QVariant toString(const QVariant&) const;
 
261
    virtual QVariant value(const App::Property*) const;
 
262
    virtual void setValue(const QVariant&);
 
263
 
 
264
protected:
 
265
    PropertyVectorItem();
 
266
 
 
267
private:
 
268
    PropertyFloatItem* m_x;
 
269
    PropertyFloatItem* m_y;
 
270
    PropertyFloatItem* m_z;
 
271
};
 
272
 
 
273
/**
 
274
 * Edit properties of placement type. 
 
275
 * \author Werner Mayer
 
276
 */
 
277
class GuiExport PropertyPlacementItem: public PropertyItem
 
278
{
 
279
    Q_OBJECT
 
280
    Q_PROPERTY(QString Axis READ getAxis)
 
281
    Q_PROPERTY(QString Angle READ getAngle)
 
282
    Q_PROPERTY(QString Position READ getPosition)
 
283
    TYPESYSTEM_HEADER();
 
284
 
 
285
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
286
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
287
    virtual QVariant editorData(QWidget *editor) const;
 
288
 
 
289
    QString getAxis() const;
 
290
    QString getAngle() const;
 
291
    QString getPosition() const;
 
292
 
 
293
protected:
 
294
    PropertyPlacementItem();
 
295
    virtual QVariant toolTip(const App::Property*) const;
 
296
    virtual QVariant toString(const QVariant&) const;
 
297
    virtual QVariant value(const App::Property*) const;
 
298
    virtual void setValue(const QVariant&);
 
299
 
 
300
private:
 
301
    PropertyStringItem* m_d;
 
302
    PropertyStringItem* m_a;
 
303
    PropertyStringItem* m_p;
 
304
};
 
305
 
 
306
/**
 
307
 * Edit properties of enum type. 
 
308
 * \author Werner Mayer
 
309
 */
 
310
class GuiExport PropertyEnumItem: public PropertyItem
 
311
{
 
312
    TYPESYSTEM_HEADER();
 
313
 
 
314
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
315
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
316
    virtual QVariant editorData(QWidget *editor) const;
 
317
 
 
318
protected:
 
319
    virtual QVariant value(const App::Property*) const;
 
320
    virtual void setValue(const QVariant&);
 
321
 
 
322
protected:
 
323
    PropertyEnumItem();
 
324
};
 
325
 
 
326
/**
 
327
 * Edit properties of enum type. 
 
328
 * \author Werner Mayer
 
329
 */
 
330
class GuiExport PropertyStringListItem: public PropertyItem
 
331
{
 
332
    TYPESYSTEM_HEADER();
 
333
 
 
334
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
335
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
336
    virtual QVariant editorData(QWidget *editor) const;
 
337
 
 
338
protected:
 
339
    QVariant toString(const QVariant&) const;
 
340
    virtual QVariant value(const App::Property*) const;
 
341
    virtual void setValue(const QVariant&);
 
342
 
 
343
protected:
 
344
    PropertyStringListItem();
 
345
};
 
346
 
 
347
/**
 
348
 * Change a color property.
 
349
 * \author Werner Mayer
 
350
 */
 
351
class GuiExport PropertyColorItem: public PropertyItem
 
352
{
 
353
    TYPESYSTEM_HEADER();
 
354
 
 
355
    virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
 
356
    virtual void setEditorData(QWidget *editor, const QVariant& data) const;
 
357
    virtual QVariant editorData(QWidget *editor) const;
 
358
 
 
359
protected:
 
360
    virtual QVariant decoration(const App::Property*) const;
 
361
    virtual QVariant toString(const QVariant&) const;
 
362
    virtual QVariant value(const App::Property*) const;
 
363
    virtual void setValue(const QVariant&);
 
364
 
 
365
protected:
 
366
    PropertyColorItem();
 
367
};
 
368
 
 
369
/**
 
370
 * Change a file.
 
371
 * \author Werner Mayer
 
372
 */
 
373
class GuiExport PropertyFileItem: public PropertyItem
 
374
{
 
375
    TYPESYSTEM_HEADER();
 
376
 
 
377
protected:
 
378
    virtual QVariant value(const App::Property*) const;
 
379
    virtual void setValue(const QVariant&);
 
380
 
 
381
protected:
 
382
    PropertyFileItem();
 
383
    virtual QVariant toolTip(const App::Property*) const;
 
384
};
 
385
 
 
386
/**
 
387
 * Change a path.
 
388
 * \author Werner Mayer
 
389
 */
 
390
class GuiExport PropertyPathItem: public PropertyItem
 
391
{
 
392
    TYPESYSTEM_HEADER();
 
393
 
 
394
protected:
 
395
    virtual QVariant value(const App::Property*) const;
 
396
    virtual void setValue(const QVariant&);
 
397
 
 
398
protected:
 
399
    PropertyPathItem();
 
400
};
 
401
 
 
402
class PropertyItemEditorFactory : public QItemEditorFactory
 
403
{
 
404
public:
 
405
    PropertyItemEditorFactory();
 
406
    virtual ~PropertyItemEditorFactory();
 
407
 
 
408
    virtual QWidget * createEditor ( QVariant::Type type, QWidget * parent ) const;
 
409
    virtual QByteArray valuePropertyName ( QVariant::Type type ) const;
 
410
};
 
411
 
 
412
} // namespace PropertyEditor
 
413
} // namespace Gui
 
414
 
 
415
#endif // PROPERTYEDITORITEM_H