PropertyItem.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef PROPERTYEDITORITEM_H
00025 #define PROPERTYEDITORITEM_H
00026 
00027 #include <QObject>
00028 #include <QPointer>
00029 #include <QItemEditorFactory>
00030 #include <vector>
00031 
00032 #include <Base/Type.h>
00033 #include <Base/Vector3D.h>
00034 #include <Base/Placement.h>
00035 #include <Base/UnitsApi.h>
00036 #include <App/PropertyStandard.h>
00037 #include <Gui/Widgets.h>
00038 
00039 Q_DECLARE_METATYPE(Base::Vector3f)
00040 Q_DECLARE_METATYPE(Base::Vector3d)
00041 Q_DECLARE_METATYPE(Base::Placement)
00042 
00043 namespace Gui {
00044 namespace Dialog { class TaskPlacement; }
00045 namespace PropertyEditor {
00046 
00047 class GuiExport PropertyItem : virtual public QObject, public Base::BaseClass
00048 {
00049     Q_OBJECT
00050 
00051     TYPESYSTEM_HEADER();
00052 
00053 public:
00054     ~PropertyItem();
00055 
00057     void setPropertyData( const std::vector<App::Property*>& );
00058     const std::vector<App::Property*>& getPropertyData() const;
00059 
00061     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00062     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00063     virtual QVariant editorData(QWidget *editor) const;
00064     virtual bool isSeparator() const { return false; }
00065 
00066     void setParent(PropertyItem* parent);
00067     PropertyItem *parent() const;
00068     void appendChild(PropertyItem *child);
00069 
00070     void setReadOnly(bool);
00071     bool isReadOnly() const;
00072 
00073     PropertyItem *child(int row);
00074     int childCount() const;
00075     int columnCount() const;
00076     QString propertyName() const;
00077     void setPropertyName(const QString&);
00078     void setPropertyValue(const QString&);
00079     QVariant data(int column, int role) const;
00080     bool setData (const QVariant& value);
00081     Qt::ItemFlags flags(int column) const;
00082     int row() const;
00083     void reset();
00084 
00085 protected:
00086     PropertyItem();
00087 
00088     virtual QVariant decoration(const App::Property*) const;
00089     virtual QVariant toolTip(const App::Property*) const;
00090     virtual QVariant toString(const QVariant&) const;
00091     virtual QVariant value(const App::Property*) const;
00092     virtual void setValue(const QVariant&);
00093     QString pythonIdentifier(const App::Property*) const;
00094 
00095 private:
00096     QString propName;
00097     QVariant propData;
00098     std::vector<App::Property*> propertyItems;
00099     PropertyItem *parentItem;
00100     QList<PropertyItem*> childItems;
00101     bool readonly;
00102 };
00103 
00108 class GuiExport PropertyStringItem: public PropertyItem
00109 {
00110     TYPESYSTEM_HEADER();
00111 
00112     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00113     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00114     virtual QVariant editorData(QWidget *editor) const;
00115 
00116 protected:
00117     virtual QVariant value(const App::Property*) const;
00118     virtual void setValue(const QVariant&);
00119 
00120 protected:
00121     PropertyStringItem();
00122 };
00123 
00128 class GuiExport PropertyFontItem: public PropertyItem
00129 {
00130     TYPESYSTEM_HEADER();
00131 
00132     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00133     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00134     virtual QVariant editorData(QWidget *editor) const;
00135 
00136 protected:
00137     virtual QVariant value(const App::Property*) const;
00138     virtual void setValue(const QVariant&);
00139 
00140 protected:
00141     PropertyFontItem();
00142 };
00143 
00148 class GuiExport PropertySeparatorItem : public PropertyItem
00149 {
00150     TYPESYSTEM_HEADER();
00151 
00152     bool isSeparator() const { return true; }
00153     QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00154 };
00155 
00160 class GuiExport PropertyIntegerItem: public PropertyItem
00161 {
00162     TYPESYSTEM_HEADER();
00163 
00164     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00165     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00166     virtual QVariant editorData(QWidget *editor) const;
00167 
00168 protected:
00169     virtual QVariant value(const App::Property*) const;
00170     virtual void setValue(const QVariant&);
00171 
00172 protected:
00173     PropertyIntegerItem();
00174 };
00175 
00180 class GuiExport PropertyIntegerConstraintItem: public PropertyItem
00181 {
00182     TYPESYSTEM_HEADER();
00183 
00184     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00185     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00186     virtual QVariant editorData(QWidget *editor) const;
00187 
00188 protected:
00189     virtual QVariant value(const App::Property*) const;
00190     virtual void setValue(const QVariant&);
00191 
00192 protected:
00193     PropertyIntegerConstraintItem();
00194 };
00195 
00200 class GuiExport PropertyFloatItem: public PropertyItem
00201 {
00202     TYPESYSTEM_HEADER();
00203 
00204     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00205     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00206     virtual QVariant editorData(QWidget *editor) const;
00207 
00208 protected:
00209     virtual QVariant toString(const QVariant&) const;
00210     virtual QVariant value(const App::Property*) const;
00211     virtual void setValue(const QVariant&);
00212 
00213 protected:
00214     PropertyFloatItem();
00215 };
00216 
00221 class GuiExport PropertyUnitItem: public PropertyItem
00222 {
00223     TYPESYSTEM_HEADER();
00224 
00225     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00226     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00227     virtual QVariant editorData(QWidget *editor) const;
00228 
00229 protected:
00230     //virtual QVariant toString(const QVariant&) const;
00231     virtual QVariant value(const App::Property*) const;
00232     virtual void setValue(const QVariant&);
00233     Base::QuantityType  UnitType;
00234 
00235     PropertyUnitItem();
00236 };
00237 
00242 class GuiExport PropertyFloatConstraintItem: public PropertyItem
00243 {
00244     TYPESYSTEM_HEADER();
00245 
00246     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00247     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00248     virtual QVariant editorData(QWidget *editor) const;
00249 
00250 protected:
00251     virtual QVariant toString(const QVariant&) const;
00252     virtual QVariant value(const App::Property*) const;
00253     virtual void setValue(const QVariant&);
00254 
00255 protected:
00256     PropertyFloatConstraintItem();
00257 };
00258 
00263 class GuiExport PropertyAngleItem : public PropertyFloatItem
00264 {
00265     TYPESYSTEM_HEADER();
00266 
00267 protected:
00268     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00269     virtual QVariant toString(const QVariant&) const;
00270 
00271 protected:
00272     PropertyAngleItem();
00273 };
00274 
00279 class GuiExport PropertyBoolItem: public PropertyItem
00280 {
00281     TYPESYSTEM_HEADER();
00282 
00283     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00284     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00285     virtual QVariant editorData(QWidget *editor) const;
00286 
00287 protected:
00288     virtual QVariant value(const App::Property*) const;
00289     virtual void setValue(const QVariant&);
00290 
00291 protected:
00292     PropertyBoolItem();
00293 };
00294 
00299 class PropertyFloatItem;
00300 class GuiExport PropertyVectorItem: public PropertyItem
00301 {
00302     Q_OBJECT
00303     Q_PROPERTY(double x READ x WRITE setX DESIGNABLE true USER true)
00304     Q_PROPERTY(double y READ y WRITE setY DESIGNABLE true USER true)
00305     Q_PROPERTY(double z READ z WRITE setZ DESIGNABLE true USER true)
00306     TYPESYSTEM_HEADER();
00307 
00308     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00309     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00310     virtual QVariant editorData(QWidget *editor) const;
00311 
00312     double x() const;
00313     void setX(double x);
00314     double y() const;
00315     void setY(double y);
00316     double z() const;
00317     void setZ(double z);
00318 
00319 protected:
00320     virtual QVariant toString(const QVariant&) const;
00321     virtual QVariant value(const App::Property*) const;
00322     virtual void setValue(const QVariant&);
00323 
00324 protected:
00325     PropertyVectorItem();
00326 
00327 private:
00328     PropertyFloatItem* m_x;
00329     PropertyFloatItem* m_y;
00330     PropertyFloatItem* m_z;
00331 };
00332 
00333 class GuiExport PropertyDoubleVectorItem: public PropertyItem
00334 {
00335     Q_OBJECT
00336     Q_PROPERTY(double x READ x WRITE setX DESIGNABLE true USER true)
00337     Q_PROPERTY(double y READ y WRITE setY DESIGNABLE true USER true)
00338     Q_PROPERTY(double z READ z WRITE setZ DESIGNABLE true USER true)
00339     TYPESYSTEM_HEADER();
00340 
00341     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00342     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00343     virtual QVariant editorData(QWidget *editor) const;
00344 
00345     double x() const;
00346     void setX(double x);
00347     double y() const;
00348     void setY(double y);
00349     double z() const;
00350     void setZ(double z);
00351 
00352 protected:
00353     virtual QVariant toString(const QVariant&) const;
00354     virtual QVariant value(const App::Property*) const;
00355     virtual void setValue(const QVariant&);
00356 
00357 protected:
00358     PropertyDoubleVectorItem();
00359 
00360 private:
00361     PropertyFloatItem* m_x;
00362     PropertyFloatItem* m_y;
00363     PropertyFloatItem* m_z;
00364 };
00365 
00366 class PlacementEditor : public Gui::LabelButton
00367 {
00368     Q_OBJECT
00369 
00370 public:
00371     PlacementEditor(const QString& name, QWidget * parent = 0);
00372     ~PlacementEditor();
00373 
00374 private Q_SLOTS:
00375     void updateValue(const QVariant& v, bool, bool);
00376 
00377 private:
00378     void browse();
00379     void showValue(const QVariant& d);
00380 
00381 private:
00382     QPointer<Gui::Dialog::TaskPlacement> _task;
00383     QString propertyname;
00384 };
00385 
00390 class GuiExport PropertyPlacementItem: public PropertyItem
00391 {
00392     Q_OBJECT
00393     Q_PROPERTY(double Angle READ getAngle WRITE setAngle DESIGNABLE true USER true)
00394     Q_PROPERTY(Base::Vector3d Axis READ getAxis WRITE setAxis DESIGNABLE true USER true)
00395     Q_PROPERTY(Base::Vector3d Position READ getPosition WRITE setPosition DESIGNABLE true USER true)
00396     TYPESYSTEM_HEADER();
00397 
00398     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00399     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00400     virtual QVariant editorData(QWidget *editor) const;
00401 
00402     double getAngle() const;
00403     void setAngle(double);
00404     Base::Vector3d getAxis() const;
00405     void setAxis(const Base::Vector3d&);
00406     Base::Vector3d getPosition() const;
00407     void setPosition(const Base::Vector3d&);
00408 
00409 protected:
00410     PropertyPlacementItem();
00411     ~PropertyPlacementItem();
00412     virtual QVariant toolTip(const App::Property*) const;
00413     virtual QVariant toString(const QVariant&) const;
00414     virtual QVariant value(const App::Property*) const;
00415     virtual void setValue(const QVariant&);
00416 
00417 private:
00418     bool init_axis;
00419     bool changed_value;
00420     Base::Vector3d rot_axis;
00421     PropertyAngleItem * m_a;
00422     PropertyDoubleVectorItem* m_d;
00423     PropertyDoubleVectorItem* m_p;
00424 };
00425 
00430 class GuiExport PropertyEnumItem: public PropertyItem
00431 {
00432     TYPESYSTEM_HEADER();
00433 
00434     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00435     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00436     virtual QVariant editorData(QWidget *editor) const;
00437 
00438 protected:
00439     virtual QVariant value(const App::Property*) const;
00440     virtual void setValue(const QVariant&);
00441 
00442 protected:
00443     PropertyEnumItem();
00444 };
00445 
00450 class GuiExport PropertyStringListItem: public PropertyItem
00451 {
00452     TYPESYSTEM_HEADER();
00453 
00454     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00455     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00456     virtual QVariant editorData(QWidget *editor) const;
00457 
00458 protected:
00459     QVariant toString(const QVariant&) const;
00460     virtual QVariant value(const App::Property*) const;
00461     virtual void setValue(const QVariant&);
00462 
00463 protected:
00464     PropertyStringListItem();
00465 };
00466 
00471 class GuiExport PropertyColorItem: public PropertyItem
00472 {
00473     TYPESYSTEM_HEADER();
00474 
00475     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00476     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00477     virtual QVariant editorData(QWidget *editor) const;
00478 
00479 protected:
00480     virtual QVariant decoration(const App::Property*) const;
00481     virtual QVariant toString(const QVariant&) const;
00482     virtual QVariant value(const App::Property*) const;
00483     virtual void setValue(const QVariant&);
00484 
00485 protected:
00486     PropertyColorItem();
00487 };
00488 
00493 class GuiExport PropertyFileItem: public PropertyItem
00494 {
00495     TYPESYSTEM_HEADER();
00496 
00497     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00498     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00499     virtual QVariant editorData(QWidget *editor) const;
00500 
00501 protected:
00502     virtual QVariant value(const App::Property*) const;
00503     virtual void setValue(const QVariant&);
00504 
00505 protected:
00506     PropertyFileItem();
00507     virtual QVariant toolTip(const App::Property*) const;
00508 };
00509 
00514 class GuiExport PropertyPathItem: public PropertyItem
00515 {
00516     TYPESYSTEM_HEADER();
00517 
00518     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00519     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00520     virtual QVariant editorData(QWidget *editor) const;
00521 
00522 protected:
00523     virtual QVariant value(const App::Property*) const;
00524     virtual void setValue(const QVariant&);
00525 
00526 protected:
00527     PropertyPathItem();
00528     virtual QVariant toolTip(const App::Property*) const;
00529 };
00530 
00535 class GuiExport PropertyTransientFileItem: public PropertyItem
00536 {
00537     TYPESYSTEM_HEADER();
00538 
00539     virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
00540     virtual void setEditorData(QWidget *editor, const QVariant& data) const;
00541     virtual QVariant editorData(QWidget *editor) const;
00542 
00543 protected:
00544     virtual QVariant value(const App::Property*) const;
00545     virtual void setValue(const QVariant&);
00546 
00547 protected:
00548     PropertyTransientFileItem();
00549     virtual QVariant toolTip(const App::Property*) const;
00550 };
00551 
00552 class PropertyItemEditorFactory : public QItemEditorFactory
00553 {
00554 public:
00555     PropertyItemEditorFactory();
00556     virtual ~PropertyItemEditorFactory();
00557 
00558     virtual QWidget * createEditor ( QVariant::Type type, QWidget * parent ) const;
00559     virtual QByteArray valuePropertyName ( QVariant::Type type ) const;
00560 };
00561 
00562 } // namespace PropertyEditor
00563 } // namespace Gui
00564 
00565 #endif // PROPERTYEDITORITEM_H

Generated on Wed Nov 23 19:00:31 2011 for FreeCAD by  doxygen 1.6.1