From a9667aac092c2c68f51c9620d5c0b80d01fa1bda Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 28 Aug 2014 14:05:58 +0300 Subject: [PATCH] New property list of objects (points, arcs, curves). --HG-- branch : feature --- src/app/tools/drawTools/vtoolendline.cpp | 103 ++++++++++-- src/app/tools/drawTools/vtoolendline.h | 8 + src/app/tools/drawTools/vtoollinepoint.cpp | 10 ++ src/app/tools/drawTools/vtoollinepoint.h | 6 + src/app/tools/drawTools/vtoolpoint.cpp | 6 + src/app/tools/drawTools/vtoolpoint.h | 2 + src/app/tools/drawTools/vtoolsinglepoint.cpp | 6 - src/app/tools/drawTools/vtoolsinglepoint.h | 1 - src/app/tools/vabstracttool.cpp | 26 +++ src/app/tools/vabstracttool.h | 4 + .../widgets/vtooloptionspropertybrowser.cpp | 96 +++++++---- src/app/widgets/vtooloptionspropertybrowser.h | 3 + .../plugins/vobjectproperty.cpp | 156 ++++++++++++++++++ .../plugins/vobjectproperty.h | 88 ++++++++++ src/libs/vpropertyexplorer/vproperties.h | 46 ++++++ .../vpropertyexplorer/vpropertyexplorer.pro | 7 +- 16 files changed, 514 insertions(+), 54 deletions(-) create mode 100644 src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vobjectproperty.h create mode 100644 src/libs/vpropertyexplorer/vproperties.h diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index a5cc6650b..cbdf3b2f5 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -32,6 +32,7 @@ #include "../../dialogs/tools/dialogendline.h" #include "../../dialogs/tools/dialogeditwrongformula.h" #include "../../geometry/vpointf.h" +#include "../../undocommands/savetooloptions.h" const QString VToolEndLine::ToolType = QStringLiteral("endLine"); @@ -170,6 +171,51 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, return nullptr; } +void VToolEndLine::SaveOption(const VPointF &point) +{ + QDomElement oldDomElement = doc->elementById(QString().setNum(id)); + if (oldDomElement.isElement()) + { + QDomElement newDomElement = oldDomElement.cloneNode().toElement(); + + SaveOptions(newDomElement, point); + + SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id); + connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree); + qApp->getUndoStack()->push(saveOptions); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; + } +} + +void VToolEndLine::setName(const QString &name) +{ + VPointF newPoint = VPointF(*VAbstractTool::data.GeometricObject(id).data()); + newPoint.setName(name); + SaveOption(newPoint); +} + +void VToolEndLine::setBasePointId(const quint32 &value) +{ + if (value != NULL_ID) + { + basePointId = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); + } +} + +void VToolEndLine::setFormulaLength(const QString &value) +{ + formulaLength = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -216,16 +262,7 @@ void VToolEndLine::AddToFile() const QSharedPointer point = VAbstractTool::data.GeometricObject(id); QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrAngle, formulaAngle); - doc->SetAttribute(domElement, AttrBasePoint, basePointId); + SaveOptions(domElement, *point.data()); AddToCalculation(domElement); } @@ -240,13 +277,7 @@ void VToolEndLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrAngle, formulaAngle); - doc->SetAttribute(domElement, AttrBasePoint, basePointId); + SaveOptions(domElement, *point.data()); } } @@ -265,3 +296,41 @@ void VToolEndLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrAngle, dialogTool->getAngle()); doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolEndLine::SaveOptions(QDomElement &tag, const VPointF &point) +{ + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point.name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point.mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point.my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrAngle, formulaAngle); + doc->SetAttribute(tag, AttrBasePoint, basePointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolEndLine::getFormulaAngle() const +{ + return formulaAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolEndLine::setFormulaAngle(const QString &value) +{ + formulaAngle = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + +void VToolEndLine::setTypeLine(const QString &value) +{ + typeLine = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 414ba671d..2be6d1558 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -51,6 +51,12 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::EndLine)}; + void setName(const QString &name); + QString getFormulaAngle() const; + void setFormulaAngle(const QString &value); + void setTypeLine(const QString &value); + void setFormulaLength(const QString &value); + void setBasePointId(const quint32 &value); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); @@ -61,6 +67,8 @@ protected: virtual void SaveDialog(QDomElement &domElement); private: QString formulaAngle; + void SaveOptions(QDomElement &tag, const VPointF &point); + void SaveOption(const VPointF &point); }; #endif // VTOOLENDLINE_H diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 6340b1c45..9cd09944a 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -107,3 +107,13 @@ void VToolLinePoint::SetFactor(qreal factor) VDrawTool::SetFactor(factor); RefreshGeometry(); } + +quint32 VToolLinePoint::getBasePointId() const +{ + return basePointId; +} + +QString VToolLinePoint::getFormulaLength() const +{ + return formulaLength; +} diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 6ba31b80a..1ad64bbf3 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -42,6 +42,12 @@ public: const quint32 &basePointId, const qreal &angle, QGraphicsItem * parent = nullptr); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::LinePoint)}; + QString getFormulaLength() const; + //void setFormulaLength(const QString &value)=0; + + quint32 getBasePointId() const; + //void setBasePointId(const quint32 &value)=0; + public slots: virtual void ChangedActivDraw(const QString &newName); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 3f4c8cb1c..13dd87e5c 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -72,6 +72,12 @@ void VToolPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option QGraphicsEllipseItem::paint(painter, &myOption, widget); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPoint::name() const +{ + return VAbstractTool::data.GeometricObject(id)->name(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NameChangePosition handle change posion point label. diff --git a/src/app/tools/drawTools/vtoolpoint.h b/src/app/tools/drawTools/vtoolpoint.h index 926b59cbf..d06188241 100644 --- a/src/app/tools/drawTools/vtoolpoint.h +++ b/src/app/tools/drawTools/vtoolpoint.h @@ -46,6 +46,8 @@ public: virtual ~VToolPoint(){} static const QString TagName; virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + QString name() const; + //void setName(const QString &name)=0; public slots: void NameChangePosition(const QPointF &pos); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 35b066c8f..36af6b6af 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -83,12 +83,6 @@ void VToolSinglePoint::setDialog() dialogTool->setData(p->name(), p->toQPointF()); } -//--------------------------------------------------------------------------------------------------------------------- -QString VToolSinglePoint::name() const -{ - return VAbstractTool::data.GeometricObject(id)->name(); -} - //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::setName(const QString &name) { diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index cc87d3725..48c7494a0 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -43,7 +43,6 @@ public: const QString &namePP, const QString &mPath, QGraphicsItem * parent = nullptr ); virtual void setDialog(); static const QString ToolType; - QString name() const; void setName(const QString &name); virtual int type()const; enum { Type = UserType + static_cast(Tool::SinglePoint)}; diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 5e157743d..452b6d859 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -31,6 +31,7 @@ #include #include "../undocommands/deltool.h" #include "../widgets/vapplication.h" +#include "../geometry/vpointf.h" const QString VAbstractTool::AttrType = QStringLiteral("type"); const QString VAbstractTool::AttrMx = QStringLiteral("mx"); @@ -288,6 +289,31 @@ Qt::PenStyle VAbstractTool::LineStyle(const QString &typeLine) break; } } +QString VAbstractTool::getTypeLine() const +{ + return typeLine; +} + +QMap VAbstractTool::PointsList() const +{ + const QHash > *objs = data.DataGObjects(); + QMap list; + QHash >::const_iterator i; + for (i = objs->constBegin(); i != objs->constEnd(); ++i) + { + if (i.key() != id) + { + QSharedPointer obj = i.value(); + if (obj->getType() == GOType::Point && obj->getMode() == Draw::Calculation) + { + const QSharedPointer point = data.GeometricObject(i.key()); + list[point->name()] = i.key(); + } + } + } + return list; +} + //--------------------------------------------------------------------------------------------------------------------- int VAbstractTool::ConfirmDeletion() diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index e8297f8a8..74ab724b7 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -100,6 +100,10 @@ public: static void AddRecord(const quint32 id, const Tool &toolType, VPattern *doc); static Qt::PenStyle LineStyle(const QString &typeLine); const VContainer *getData() const; + + QString getTypeLine() const; + //void setTypeLine(const QString &value)=0; + QMap PointsList() const; public slots: /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 558cb9024..8893b4b6e 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -32,10 +32,7 @@ #include "widgets/vmaingraphicsview.h" #include "visualization/vgraphicssimpletextitem.h" #include "visualization/vcontrolpointspline.h" -#include "../libs/vpropertyexplorer/plugins/vnumberproperty.h" -#include "../libs/vpropertyexplorer/plugins/vstringproperty.h" -#include "../libs/vpropertyexplorer/plugins/vpointfproperty.h" -#include "../libs/vpropertyexplorer/plugins/venumproperty.h" +#include "../libs/vpropertyexplorer/vproperties.h" #include #include @@ -108,7 +105,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) return; } - QVariant variant = prop->data(VProperty::DPC_Data); + QVariant variant = prop->data(VProperty::DPC_Data, Qt::DisplayRole); QString id = propertyToId[prop]; switch (currentItem->type()) @@ -117,23 +114,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) { if (id == QLatin1String("name")) { - if (VToolSinglePoint *i = qgraphicsitem_cast(currentItem)) - { - if (variant.toString() == i->name()) - { - return; - } - - if (variant.toString().isEmpty()) - { - idToProperty[QLatin1String("name")]->setValue(i->name()); - } - else - { - //TODO check if label name is unique - i->setName(variant.toString()); - } - } + SetPointName(variant.toString()); } else if (id == QLatin1String("position")) { @@ -145,18 +126,51 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) // } break; } -// case VGraphicsSimpleTextItem::Type: -// ShowItemOptions(currentItem->parentItem()); -// break; -// case VControlPointSpline::Type: -// ShowItemOptions(currentItem->parentItem()); -// break; + case VToolEndLine::Type: + { + if (id == QLatin1String("name")) + { + SetPointName(variant.toString()); + } + else if (id == QLatin1String("basePoint")) + { + VToolEndLine *i = qgraphicsitem_cast(currentItem); + i->setBasePointId(variant.toUInt()); + } + break; + } default: break; } qApp->getSceneView()->update(); } +template +void VToolOptionsPropertyBrowser::SetPointName(const QString &name) +{ + if (Tool *i = qgraphicsitem_cast(currentItem)) + { + if (name == i->name()) + { + return; + } + + if (name.isEmpty()) + { + idToProperty[QLatin1String("name")]->setValue(i->name()); + } + else + { + //TODO check if label name is unique + i->setName(name); + } + } + else + { + qWarning()<<"Can't cast item"; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptions() { @@ -174,6 +188,14 @@ void VToolOptionsPropertyBrowser::UpdateOptions() idToProperty[QLatin1String("position")]->setValue(i->pos()); break; } + case VToolEndLine::Type: + { + VToolEndLine *i = qgraphicsitem_cast(currentItem); + idToProperty[QLatin1String("name")]->setValue(i->name()); + idToProperty[QLatin1String("basePoint")]->setValue(i->getBasePointId()); + + break; + } case VGraphicsSimpleTextItem::Type: ShowItemOptions(currentItem->parentItem()); break; @@ -212,6 +234,24 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) itemPosition->setValue(i->pos()); AddProperty(itemPosition, QLatin1String("position")); + break; + } + case VToolEndLine::Type: + { + VToolEndLine *i = qgraphicsitem_cast(item); + QDockWidget *parent = qobject_cast(this->parent()); + parent->setWindowTitle(tr("Tool options (End of line)")); + + VProperty* itemName = new VProperty(tr("Point name")); + itemName->setValue(i->name()); + AddProperty(itemName, QLatin1String("name")); + + VObjectProperty *pointsProperty = new VObjectProperty(tr("Base point")); + QMap pointsList = i->PointsList(); + pointsProperty->setObjectsList(pointsList); + pointsProperty->setValue(i->getBasePointId()); + AddProperty(pointsProperty, QLatin1String("basePoint")); + // VEnumProperty *enumProperty = new VEnumProperty(tr("list")); // QStringList list = QStringList()<<"a1"<<"a2"<<"a3"; // enumProperty->setLiterals(list); diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h index e915e989d..347495bc8 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.h +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -63,6 +63,9 @@ private: void AddProperty(VProperty *property, const QString &id); void ShowItemOptions(QGraphicsItem *item); + + template + void SetPointName(const QString &name); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp b/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp new file mode 100644 index 000000000..321c09231 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp @@ -0,0 +1,156 @@ +/************************************************************************ + ** + ** @file vobjectproperty.cpp + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** All rights reserved. This program and the accompanying materials + ** are made available under the terms of the GNU Lesser General Public License + ** (LGPL) version 2.1 which accompanies this distribution, and is available at + ** http://www.gnu.org/licenses/lgpl-2.1.html + ** + ** This library is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. + ** + *************************************************************************/ + +#include "vobjectproperty.h" +#include "vproperty_p.h" + +#include +#include +#include + +using namespace VPE; + +VObjectProperty::VObjectProperty(const QString& name) + : QObject(), VProperty(name, QVariant::Int) +{ + VProperty::d_ptr->VariantValue = 0; + VProperty::d_ptr->VariantValue.convert(QVariant::UInt); +} + +//! Get the data how it should be displayed +QVariant VObjectProperty::data (int column, int role) const +{ + if(objects.empty()) + return QVariant(); + + QComboBox* tmpEditor = qobject_cast(VProperty::d_ptr->editor); + + if(column == DPC_Data && Qt::DisplayRole == role) + { + return VProperty::d_ptr->VariantValue; + } + else if(column == DPC_Data && Qt::EditRole == role) + return tmpEditor->currentIndex(); + else + return VProperty::data(column, role); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VObjectProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, + const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + QComboBox* tmpEditor = new QComboBox(parent); + tmpEditor->clear(); + FillList(tmpEditor, objects); + tmpEditor->setCurrentIndex(tmpEditor->findData(VProperty::d_ptr->VariantValue.toUInt())); + connect(tmpEditor, static_cast(&QComboBox::currentIndexChanged), this, + &VObjectProperty::currentIndexChanged); + + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; +} + +bool VObjectProperty::setEditorData(QWidget *editor) +{ + if(!editor) + return false; + + QComboBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + { + quint32 objId = VProperty::d_ptr->VariantValue.toUInt(); + qint32 tmpIndex = tmpEditor->findData(objId); + + if (tmpIndex == -1) + { + tmpIndex = 0; + } + tmpEditor->blockSignals(true); + tmpEditor->setCurrentIndex(tmpIndex); + tmpEditor->blockSignals(false); + return true; + } + + return false; +} + +//! Gets the data from the widget +QVariant VObjectProperty::getEditorData(QWidget* editor) const +{ + QComboBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->itemData(tmpEditor->currentIndex()); + + return QVariant(0); +} + +//! Sets the objects list +void VObjectProperty::setObjectsList(const QMap &objects) +{ + this->objects = objects; +} + +//! Get the settings. This function has to be implemented in a subclass in order to have an effect +QMap VObjectProperty::getObjects() const +{ + return objects; +} + +//! Sets the value of the property +void VObjectProperty::setValue(const QVariant& value) +{ + VProperty::d_ptr->VariantValue = value; + VProperty::d_ptr->VariantValue.convert(QVariant::UInt); + + if (VProperty::d_ptr->editor != nullptr) + { + setEditorData(VProperty::d_ptr->editor); + } +} + +QString VObjectProperty::type() const +{ + return "objectList"; +} + +VProperty* VObjectProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VObjectProperty(getName())); +} + +void VObjectProperty::currentIndexChanged(int index) +{ + Q_UNUSED(index) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} + +void VObjectProperty::FillList(QComboBox *box, const QMap &list) const +{ + box->clear(); + + QMap::const_iterator i; + for (i = list.constBegin(); i != list.constEnd(); ++i) + { + box->addItem(i.key(), i.value()); + } +} diff --git a/src/libs/vpropertyexplorer/plugins/vobjectproperty.h b/src/libs/vpropertyexplorer/plugins/vobjectproperty.h new file mode 100644 index 000000000..a3e7b49d4 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vobjectproperty.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file vobjectproperty.h + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** All rights reserved. This program and the accompanying materials + ** are made available under the terms of the GNU Lesser General Public License + ** (LGPL) version 2.1 which accompanies this distribution, and is available at + ** http://www.gnu.org/licenses/lgpl-2.1.html + ** + ** This library is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. + ** + *************************************************************************/ + +#ifndef VOBJECTPROPERTY_H +#define VOBJECTPROPERTY_H + +#include "vproperty.h" + +#include + +class QComboBox; + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VObjectProperty : public QObject, public VProperty +{ + Q_OBJECT +public: + //! Constructor + VObjectProperty(const QString& name); + + //! Destructor + ~VObjectProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the objects list + void setObjectsList(const QMap &objects); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QMap getObjects() const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + +public slots: + void currentIndexChanged(int index); + +protected: + //! The list of possible objects + QMap objects; + + void FillList(QComboBox *box, const QMap &list)const; + // No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other members by reimplementing the VPropertyPrivate class without touching this header file. +}; + +} + +#endif // VOBJECTPROPERTY_H diff --git a/src/libs/vpropertyexplorer/vproperties.h b/src/libs/vpropertyexplorer/vproperties.h new file mode 100644 index 000000000..b33eff79c --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperties.h @@ -0,0 +1,46 @@ +/************************************************************************ + ** + ** @file vproperties.h + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPROPERTIES_H +#define VPROPERTIES_H + +#include "vproperty.h" +#include "plugins/vboolproperty.h" +#include "plugins/vcolorproperty.h" +#include "plugins/Vector3d/vvector3dproperty.h" +#include "plugins/vemptyproperty.h" +#include "plugins/venumproperty.h" +#include "plugins/vfileproperty.h" +#include "plugins/vnumberproperty.h" +#include "plugins/vobjectproperty.h" +#include "plugins/vpointfproperty.h" +#include "plugins/vshortcutproperty.h" +#include "plugins/vstringproperty.h" +#include "plugins/vwidgetproperty.h" + +#endif // VPROPERTIES_H diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro index 8e41c380a..1fc339927 100644 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.pro +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -48,7 +48,8 @@ SOURCES += \ plugins/Vector3d/vvector3dproperty.cpp \ vstandardpropertyfactory.cpp \ plugins/vstringproperty.cpp \ - plugins/vpointfproperty.cpp + plugins/vpointfproperty.cpp \ + plugins/vobjectproperty.cpp HEADERS +=\ vpropertyexplorer_global.h \ @@ -85,7 +86,9 @@ HEADERS +=\ vpropertyfactorymanager.h \ vserializedproperty.h \ plugins/vstringproperty.h \ - plugins/vpointfproperty.h + plugins/vpointfproperty.h \ + plugins/vobjectproperty.h \ + vproperties.h unix { target.path = /usr/lib