From 3ccd40871819324e6699ba66f0c5a795d538517f Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 26 Aug 2014 18:06:14 +0300 Subject: [PATCH 01/52] New library VPropertyExplorer. --HG-- branch : feature --- src/app/app.pro | 27 +- src/libs/libs.pro | 3 +- .../plugins/Vector3d/vvector3dproperty.cpp | 113 ++++++ .../plugins/Vector3d/vvector3dproperty.h | 78 ++++ .../plugins/vboolproperty.cpp | 67 ++++ .../vpropertyexplorer/plugins/vboolproperty.h | 49 +++ .../plugins/vcolorproperty.cpp | 68 ++++ .../plugins/vcolorproperty.h | 44 +++ .../plugins/vcolorpropertyeditor.cpp | 115 ++++++ .../plugins/vcolorpropertyeditor.h | 67 ++++ .../plugins/vemptyproperty.cpp | 70 ++++ .../plugins/vemptyproperty.h | 48 +++ .../plugins/venumproperty.cpp | 109 ++++++ .../vpropertyexplorer/plugins/venumproperty.h | 68 ++++ .../plugins/vfileproperty.cpp | 136 +++++++ .../vpropertyexplorer/plugins/vfileproperty.h | 76 ++++ .../plugins/vfilepropertyeditor.cpp | 204 +++++++++++ .../plugins/vfilepropertyeditor.h | 89 +++++ .../plugins/vnumberproperty.cpp | 183 ++++++++++ .../plugins/vnumberproperty.h | 115 ++++++ .../plugins/vshortcutproperty.cpp | 84 +++++ .../plugins/vshortcutproperty.h | 49 +++ .../plugins/vshortcutpropertyeditor.cpp | 86 +++++ .../plugins/vshortcutpropertyeditor.h | 64 ++++ .../plugins/vwidgetproperty.cpp | 46 +++ .../plugins/vwidgetproperty.h | 42 +++ .../vabstractpropertyfactory.h | 26 ++ src/libs/vpropertyexplorer/vfileproperty_p.h | 30 ++ src/libs/vpropertyexplorer/vproperty.cpp | 345 ++++++++++++++++++ src/libs/vpropertyexplorer/vproperty.h | 176 +++++++++ src/libs/vpropertyexplorer/vproperty_p.h | 61 ++++ .../vpropertyexplorer/vpropertydelegate.cpp | 100 +++++ .../vpropertyexplorer/vpropertydelegate.h | 44 +++ .../vpropertyexplorer/vpropertyexplorer.cpp | 34 ++ .../vpropertyexplorer/vpropertyexplorer.h | 41 +++ .../vpropertyexplorer/vpropertyexplorer.pro | 80 ++++ .../vpropertyexplorer_global.h | 40 ++ .../vpropertyfactorymanager.cpp | 109 ++++++ .../vpropertyfactorymanager.h | 67 ++++ .../vpropertyfactorymanager_p.h | 21 ++ .../vpropertyexplorer/vpropertyformview.cpp | 180 +++++++++ .../vpropertyexplorer/vpropertyformview.h | 81 ++++ .../vpropertyexplorer/vpropertyformview_p.h | 40 ++ .../vpropertyexplorer/vpropertyformwidget.cpp | 223 +++++++++++ .../vpropertyexplorer/vpropertyformwidget.h | 73 ++++ .../vpropertyexplorer/vpropertyformwidget_p.h | 44 +++ src/libs/vpropertyexplorer/vpropertymodel.cpp | 290 +++++++++++++++ src/libs/vpropertyexplorer/vpropertymodel.h | 142 +++++++ src/libs/vpropertyexplorer/vpropertymodel_p.h | 40 ++ src/libs/vpropertyexplorer/vpropertyset.cpp | 211 +++++++++++ src/libs/vpropertyexplorer/vpropertyset.h | 111 ++++++ src/libs/vpropertyexplorer/vpropertyset_p.h | 29 ++ .../vpropertyexplorer/vpropertytreeview.cpp | 57 +++ .../vpropertyexplorer/vpropertytreeview.h | 45 +++ .../vpropertyexplorer/vpropertytreeview_p.h | 30 ++ .../vpropertyexplorer/vserializedproperty.cpp | 49 +++ .../vpropertyexplorer/vserializedproperty.h | 52 +++ .../vstandardpropertyFactory.cpp | 66 ++++ .../vstandardpropertyfactory.h | 33 ++ .../vpropertyexplorer/vwidgetproperty_p.h | 35 ++ 60 files changed, 5094 insertions(+), 11 deletions(-) create mode 100644 src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/vboolproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vboolproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vcolorproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.h create mode 100644 src/libs/vpropertyexplorer/plugins/vemptyproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vemptyproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/venumproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/venumproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/vfileproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vfileproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h create mode 100644 src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vnumberproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vshortcutproperty.h create mode 100644 src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.h create mode 100644 src/libs/vpropertyexplorer/plugins/vwidgetproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vwidgetproperty.h create mode 100644 src/libs/vpropertyexplorer/vabstractpropertyfactory.h create mode 100644 src/libs/vpropertyexplorer/vfileproperty_p.h create mode 100644 src/libs/vpropertyexplorer/vproperty.cpp create mode 100644 src/libs/vpropertyexplorer/vproperty.h create mode 100644 src/libs/vpropertyexplorer/vproperty_p.h create mode 100644 src/libs/vpropertyexplorer/vpropertydelegate.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertydelegate.h create mode 100644 src/libs/vpropertyexplorer/vpropertyexplorer.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertyexplorer.h create mode 100644 src/libs/vpropertyexplorer/vpropertyexplorer.pro create mode 100644 src/libs/vpropertyexplorer/vpropertyexplorer_global.h create mode 100644 src/libs/vpropertyexplorer/vpropertyfactorymanager.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertyfactorymanager.h create mode 100644 src/libs/vpropertyexplorer/vpropertyfactorymanager_p.h create mode 100644 src/libs/vpropertyexplorer/vpropertyformview.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertyformview.h create mode 100644 src/libs/vpropertyexplorer/vpropertyformview_p.h create mode 100644 src/libs/vpropertyexplorer/vpropertyformwidget.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertyformwidget.h create mode 100644 src/libs/vpropertyexplorer/vpropertyformwidget_p.h create mode 100644 src/libs/vpropertyexplorer/vpropertymodel.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertymodel.h create mode 100644 src/libs/vpropertyexplorer/vpropertymodel_p.h create mode 100644 src/libs/vpropertyexplorer/vpropertyset.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertyset.h create mode 100644 src/libs/vpropertyexplorer/vpropertyset_p.h create mode 100644 src/libs/vpropertyexplorer/vpropertytreeview.cpp create mode 100644 src/libs/vpropertyexplorer/vpropertytreeview.h create mode 100644 src/libs/vpropertyexplorer/vpropertytreeview_p.h create mode 100644 src/libs/vpropertyexplorer/vserializedproperty.cpp create mode 100644 src/libs/vpropertyexplorer/vserializedproperty.h create mode 100644 src/libs/vpropertyexplorer/vstandardpropertyFactory.cpp create mode 100644 src/libs/vpropertyexplorer/vstandardpropertyfactory.h create mode 100644 src/libs/vpropertyexplorer/vwidgetproperty_p.h diff --git a/src/app/app.pro b/src/app/app.pro index e9ad262be..1b389589b 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -620,29 +620,36 @@ INSTALLS += \ for(_translation_name, TRANSLATIONS) { _translation_name_qm = $$section(_translation_name,".", 0, 0).qm - system($$shell_path($$[QT_INSTALL_BINS]/lrelease) $$shell_path($$PWD/$$_translation_name) -qm $$shell_path($$PWD/$$_translation_name_qm)) + system($$shell_path($$[QT_INSTALL_BINS]/lrelease) $$shell_path($${PWD}/$$_translation_name) -qm $$shell_path($${PWD}/$$_translation_name_qm)) } } for(DIR, INSTALL_TRANSLATIONS) { #add these absolute paths to a variable which #ends up as 'mkcommands = path1 path2 path3 ...' - tr_path += $$PWD/$$DIR + tr_path += $${PWD}/$$DIR } -copyToDestdir($$tr_path, $$shell_path($$OUT_PWD/$$DESTDIR/translations)) +copyToDestdir($$tr_path, $$shell_path($${OUT_PWD}/$$DESTDIR/translations)) for(DIR, INSTALL_STANDARD_MEASHUREMENTS) { #add these absolute paths to a variable which #ends up as 'mkcommands = path1 path2 path3 ...' - st_path += $$PWD/$$DIR + st_path += $${PWD}/$$DIR } -copyToDestdir($$st_path, $$shell_path($$OUT_PWD/$$DESTDIR/tables/standard)) +copyToDestdir($$st_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tables/standard)) -win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libs/qmuparser/bin -lqmuparser2 -else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libs/qmuparser/bin -lqmuparser2 -else:unix: LIBS += -L$$OUT_PWD/../libs/qmuparser/bin -lqmuparser +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:unix: LIBS += -L$${OUT_PWD}/../libs/qmuparser/$${DESTDIR} -lqmuparser -INCLUDEPATH += $$PWD/../libs/qmuparser -DEPENDPATH += $$PWD/../libs/qmuparser +INCLUDEPATH += $${PWD}/../libs/qmuparser +DEPENDPATH += $${PWD}/../libs/qmuparser + +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:unix: LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer + +INCLUDEPATH += $${PWD}/../libs/vpropertyexplorer +DEPENDPATH += $${PWD}/../libs/vpropertyexplorer diff --git a/src/libs/libs.pro b/src/libs/libs.pro index 5d08776e9..bd493ca45 100644 --- a/src/libs/libs.pro +++ b/src/libs/libs.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS = qmuparser +SUBDIRS = qmuparser \ + vpropertyexplorer diff --git a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.cpp b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.cpp new file mode 100644 index 000000000..2873d4c2a --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.cpp @@ -0,0 +1,113 @@ +#include "vvector3dproperty.h" + +using namespace VPE; + +#include "vproperty_p.h" +#include "../vnumberproperty.h" +#include + +QVector3DProperty::QVector3DProperty(const QString& name) + : VProperty(name, QVariant::String) // todo: QVariant::Vector3D?? +{ + QVariant tmpFloat(0); tmpFloat.convert(QVariant::Double); + VDoubleProperty* tmpX = new VDoubleProperty("X"); addChild(tmpX); tmpX->setUpdateBehaviour(true, false); + VDoubleProperty* tmpY = new VDoubleProperty("Y"); addChild(tmpY); tmpY->setUpdateBehaviour(true, false); + VDoubleProperty* tmpZ = new VDoubleProperty("Z"); addChild(tmpZ); tmpZ->setUpdateBehaviour(true, false); + setVector(Vector3D()); +} + + +//! Get the data how it should be displayed +QVariant QVector3DProperty::data (int column, int role) const +{ + if(column == DPC_Data && Qt::DisplayRole == role) + { + Vector3D tmpVect = getVector(); + return QString("(%1, %2, %3)").arg(QString::number(tmpVect.X), + QString::number(tmpVect.Y), + QString::number(tmpVect.Z)); + } + else + return VProperty::data(column, role); +} + +//! Returns item flags +Qt::ItemFlags QVector3DProperty::flags(int column) const +{ + if(column == DPC_Name || column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + + +//! Returns the Vector3d +Vector3D QVector3DProperty::getVector() const +{ + Vector3D tmpVect; + + if(d_ptr->Children.count() < 3) + return tmpVect; + + tmpVect.X = d_ptr->Children.at(0)->getValue().toFloat(); + tmpVect.Y = d_ptr->Children.at(1)->getValue().toFloat(); + tmpVect.Z = d_ptr->Children.at(2)->getValue().toFloat(); + + return tmpVect; +} + +//! Sets the Vector3d +void QVector3DProperty::setVector(const Vector3D &vect) +{ + setVector(vect.X, vect.Y, vect.Z); +} + +void QVector3DProperty::setVector(float x, float y, float z) +{ + if(d_ptr->Children.count() < 3) + return; + + QVariant tmpX(x); tmpX.convert(QVariant::Double); + QVariant tmpY(y); tmpY.convert(QVariant::Double); + QVariant tmpZ(z); tmpZ.convert(QVariant::Double); + d_ptr->Children.at(0)->setValue(tmpX); + d_ptr->Children.at(1)->setValue(tmpY); + d_ptr->Children.at(2)->setValue(tmpZ); +} + +QString QVector3DProperty::type() const +{ + return "vector3d"; +} + +VProperty* QVector3DProperty::clone(bool include_children, VProperty* container) const +{ + if(!container) { + container = new QVector3DProperty(getName()); + + if(!include_children) { + QList tmpChildren = container->getChildren(); + foreach(VProperty* tmpChild, tmpChildren) { + container->removeChild(tmpChild); + delete tmpChild; + } + } + } + + return VProperty::clone(false, container); // Child +} + +void QVector3DProperty::setValue(const QVariant &value) +{ + QStringList tmpStrings = value.toString().split(","); + if(tmpStrings.count() == 3) { + setVector(tmpStrings[0].toDouble(), tmpStrings[1].toDouble(), tmpStrings[2].toDouble()); + } + +} + +QVariant QVector3DProperty::getValue() const +{ + Vector3D tmpVect = getVector(); + return QString("%1,%2,%3").arg(QString::number(tmpVect.X), QString::number(tmpVect.Y), QString::number(tmpVect.Z)); +} diff --git a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h new file mode 100644 index 000000000..12eb17aeb --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h @@ -0,0 +1,78 @@ +#ifndef VVECTOR3DPROPERTY_H +#define VVECTOR3DPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +namespace VPE{ + +struct VPROPERTYEXPLORERSHARED_EXPORT Vector3D +{ +public: + Vector3D() + { + X = Y = Z = 0; + } + + Vector3D(const Vector3D& other) + { + X = other.X; + Y = other.Y; + Z = other.Z; + } + + ~Vector3D() {} + + float X, Y, Z; +}; +/* +} + +Q_DECLARE_METATYPE(QPE::Vector3D) // todo + + +namespace QPE{*/ + +class VPROPERTYEXPLORERSHARED_EXPORT QVector3DProperty : public VProperty +{ +public: + QVector3DProperty(const QString& name); + + virtual ~QVector3DProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns item flags + Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns the Vector3d + virtual Vector3D getVector() const; + + //! Sets the Vector3d + virtual void setVector(const Vector3D& vect); + + //! Sets the Vector3d + virtual void setVector(float x, float y, float z); + + //! 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 = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + +}; + +} + +#endif // VVECTOR3DPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vboolproperty.cpp b/src/libs/vpropertyexplorer/plugins/vboolproperty.cpp new file mode 100644 index 000000000..8b894d503 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vboolproperty.cpp @@ -0,0 +1,67 @@ +#include "vboolproperty.h" + +#include +#include +#include +#include +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + +QVariant VBoolProperty::TrueText; +QVariant VBoolProperty::FalseText; + +VBoolProperty::VBoolProperty(const QString& name) : + VProperty(name, QVariant::Bool) +{ + d_ptr->VariantValue.setValue(false); + d_ptr->VariantValue.convert(QVariant::Bool); + + // I'm not sure, how Qt handles the translations... + if(TrueText.isNull()) TrueText = QObject::tr("True"); + if(TrueText.isNull()) FalseText = QObject::tr("False"); +} + + +//! Get the data how it should be displayed +QVariant VBoolProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return d_ptr->VariantValue.toBool() ? TrueText : FalseText; + if(column == DPC_Data && Qt::CheckStateRole == role) + return d_ptr->VariantValue.toBool() ? Qt::Checked : Qt::Unchecked; + else + return VProperty::data(column, role); +} + +bool VBoolProperty::setData(const QVariant &data, int role) +{ + if(Qt::CheckStateRole == role) + { + d_ptr->VariantValue = (Qt::Checked == static_cast(data.toInt())); return true; + } + + return false; +} + +//! Returns item flags +Qt::ItemFlags VBoolProperty::flags(int column) const +{ + if(column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; + else + return VProperty::flags(column); +} + +QString VBoolProperty::type() const +{ + return "bool"; +} + +VProperty *VBoolProperty::clone(bool include_children, VProperty *container) const +{ + return VProperty::clone(include_children, container ? container : new VBoolProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vboolproperty.h b/src/libs/vpropertyexplorer/plugins/vboolproperty.h new file mode 100644 index 000000000..62fb3d9b3 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vboolproperty.h @@ -0,0 +1,49 @@ +#ifndef VBOOLPROPERTY_H +#define VBOOLPROPERTY_H + +#include "vproperty.h" + +namespace VPE{ + +//! The VBoolProperty can take two states: True or False. +class VPROPERTYEXPLORERSHARED_EXPORT VBoolProperty : public VProperty +{ +public: + //! Default constructor + VBoolProperty(const QString& name); + + //! Destructor + ~VBoolProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! This is used by the model to set the data + //! \param data The data to set + //! \param role The role. Default is Qt::EditRole + //! \return Returns true, if the data was changed, false if not. + virtual bool setData (const QVariant& data, int role = Qt::EditRole); + + //! Returns item flags + virtual Qt::ItemFlags flags(int column = DPC_Name) const; + + //! 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 = NULL) const; + +protected: + //! The (translatable) text displayed when the property is set to true (default: "True") + static QVariant TrueText; + + //! The (translatable) text displayed when the property is set to false (default: "False") + static QVariant FalseText; +}; + +} + +#endif // VBOOLPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp b/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp new file mode 100644 index 000000000..7d3152eda --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp @@ -0,0 +1,68 @@ +#include "vcolorproperty.h" +#include "vcolorpropertyeditor.h" + +#include "vproperty_p.h" + +using namespace VPE; + +QColorProperty::QColorProperty(const QString &name) : + VProperty(name, QVariant::Color) +{ +} + + +//! Get the data how it should be displayed +QVariant QColorProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role)) + return VColorPropertyEditor::getColorString(d_ptr->VariantValue.value()); + else if(Qt::EditRole == role) + return QVariant(); + else if(column == DPC_Data && (Qt::DecorationRole == role)) + return VColorPropertyEditor::getColorPixmap(d_ptr->VariantValue.value()); + else + return VProperty::data(column, role); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* QColorProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + VColorPropertyEditor* tmpWidget = new VColorPropertyEditor(parent); + tmpWidget->setColor(d_ptr->VariantValue.value()); + return tmpWidget; +} + +//! Sets the property's data to the editor (returns false, if the standard delegate should do that) +bool QColorProperty::setEditorData(QWidget* editor) +{ + VColorPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + tmpWidget->setColor(d_ptr->VariantValue.value()); + else + return false; + + return true; +} + +//! Gets the data from the widget +QVariant QColorProperty::getEditorData(QWidget* editor) const +{ + VColorPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + return tmpWidget->getColor(); + + return QVariant(); +} + +QString QColorProperty::type() const +{ + return "color"; +} + +VProperty *QColorProperty::clone(bool include_children, VProperty *container) const +{ + return VProperty::clone(include_children, container ? container : new QColorProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vcolorproperty.h b/src/libs/vpropertyexplorer/plugins/vcolorproperty.h new file mode 100644 index 000000000..d61802f1f --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorproperty.h @@ -0,0 +1,44 @@ +#ifndef VCOLORPROPERTY_H +#define VCOLORPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT QColorProperty : public VProperty +{ + +public: + QColorProperty(const QString &name); + + //! 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; + + //! 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 = NULL) const; + +}; + +} + +#endif // VCOLORPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.cpp b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.cpp new file mode 100644 index 000000000..f254bd3fb --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.cpp @@ -0,0 +1,115 @@ +#include "vcolorpropertyeditor.h" + +#include +#include +#include +#include +#include + +#include "vproperty.h" + +using namespace VPE; + +VColorPropertyEditor::VColorPropertyEditor(QWidget *parent) : + QWidget(parent) +{ + setAutoFillBackground(true); + + // Create the tool button + ToolButton = new QToolButton(this); + ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); + ToolButton->setText(tr("...")); + ToolButton->setFixedWidth(20); + ToolButton->installEventFilter(this); + setFocusProxy(ToolButton); // Make the ToolButton the focus proxy + setFocusPolicy(ToolButton->focusPolicy()); + connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked())); + + // Create the text label + TextLabel = new QLabel(this); + TextLabel->setText(getColorString(Color)); + + // Create the label for the pixmap + ColorLabel = new QLabel(this); + ColorLabel->setPixmap(getColorPixmap(Color)); + + // Spacer (this is needed for proper display of the label and button) + Spacer = new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(3); + layout->setMargin(0); + layout->addWidget(ColorLabel); + layout->addWidget(TextLabel); + layout->addItem(Spacer); + layout->addWidget(ToolButton); + //TextLabel->hide(); + //ColorLabel->hide(); // for now, we just use the standard display and only add the button +} + +void VColorPropertyEditor::setColor(const QColor& color_) +{ + if (Color != color_) + { + Color = color_; + ColorLabel->setPixmap(getColorPixmap(Color)); + TextLabel->setText(getColorString(Color)); + } +} + +QPixmap VColorPropertyEditor::getColorPixmap(const QColor& color, unsigned int size) +{ + QImage tmpImgage(size, size, QImage::Format_ARGB32_Premultiplied); + tmpImgage.fill(static_cast(color.rgb())); + return QPixmap::fromImage(tmpImgage); + // todo: support alpha channel +} + +QString VColorPropertyEditor::getColorString(const QColor& color) +{ + return QApplication::translate("QtPropertyExplorer", "[%1, %2, %3] (%4)", "Colors as string") + .arg(QString::number(color.red())) + .arg(QString::number(color.green())) + .arg(QString::number(color.blue())) + .arg(QString::number(color.alpha())); + +} + +void VColorPropertyEditor::onToolButtonClicked() +{ + bool ok = false; + QRgb oldRgba = Color.rgba(); + QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, this); + if (ok && newRgba != oldRgba) { + setColor(QColor::fromRgba(newRgba)); + emit dataChangedByUser(Color, this); + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( this, event ); + } +} + +bool VColorPropertyEditor::eventFilter(QObject *obj, QEvent *ev) +{ + if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress)) + { + // Ignore the event, so that eventually the delegate gets the event. + ev->ignore(); + return true; + } + + return QWidget::eventFilter(obj, ev); +} + + +VColorPropertyEditor::~VColorPropertyEditor() +{ + // +} + + + +QColor VColorPropertyEditor::getColor() +{ + return Color; +} diff --git a/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.h b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.h new file mode 100644 index 000000000..63ba6928f --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.h @@ -0,0 +1,67 @@ +#ifndef VCOLORPROPERTYEDITOR_H +#define VCOLORPROPERTYEDITOR_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include +#include + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VColorPropertyEditor : public QWidget +{ + Q_OBJECT + +public: + //! Constructor taking a widget as parent + VColorPropertyEditor(QWidget *parent); + + //! Destructor + virtual ~VColorPropertyEditor(); + + + //! Returns the color currently set + QColor getColor(); + + //! A little helper function generating an image to represent a color + //! \param color The color to fill the image with + //! \size The size of the generated pixmap + //! \return Returns a QPixmap + static QPixmap getColorPixmap(const QColor& color, unsigned int size = 16); + + //! A helper function to convert a color into a string. + //! \param color The color to fill the image with + //! \return The color as string, usually in the format [RRR, GGG, BBB] (AAA) + static QString getColorString(const QColor& color); + + //! Needed for proper event handling + bool eventFilter(QObject *obj, QEvent *ev); + +signals: + //! This is emitted, when the user changes the color + void dataChangedByUser(const QColor &getColor, VColorPropertyEditor* editor); + + void dataChanged(); + +public slots: + //! Sets the color of the widget + void setColor(const QColor &color_); + +private slots: + void onToolButtonClicked(); + +private: + QColor Color; + QToolButton* ToolButton; + QLineEdit* Lineedit; + QLabel* TextLabel; + QLabel* ColorLabel; + QSpacerItem* Spacer; +}; + +} + +#endif // QFILEPROPERTYEDITOR_H diff --git a/src/libs/vpropertyexplorer/plugins/vemptyproperty.cpp b/src/libs/vpropertyexplorer/plugins/vemptyproperty.cpp new file mode 100644 index 000000000..50da8f390 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vemptyproperty.cpp @@ -0,0 +1,70 @@ +#include "vemptyproperty.h" + +using namespace VPE; + +VEmptyProperty::VEmptyProperty(const QString& name) + : VProperty(name, QVariant::Invalid) +{ +} + + +VEmptyProperty::VEmptyProperty(VPropertyPrivate *d) + : VProperty(d) +{ +} + + +VEmptyProperty::~VEmptyProperty() +{ + // +} + +//! Get the data how it should be displayed +QVariant VEmptyProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return QVariant(); + else if(role == Qt::BackgroundRole) + return QBrush(QColor(217,217,217)); + else if(role == Qt::FontRole) + { QFont tmpFont; tmpFont.setBold(true); return tmpFont; } + else + return VProperty::data(column, role); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VEmptyProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(parent); + Q_UNUSED(delegate); + + return NULL; +} + + +//! Gets the data from the widget +QVariant VEmptyProperty::getEditorData(QWidget* editor) const +{ + Q_UNUSED(editor); + + return QVariant(); +} + +//! Returns item flags +Qt::ItemFlags VEmptyProperty::flags(int column) const +{ + Q_UNUSED(column); + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QString VEmptyProperty::type() const +{ + return "empty"; +} + +VProperty* VEmptyProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VEmptyProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vemptyproperty.h b/src/libs/vpropertyexplorer/plugins/vemptyproperty.h new file mode 100644 index 000000000..33cf02315 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vemptyproperty.h @@ -0,0 +1,48 @@ +#ifndef VEMPTYPROPERTY_H +#define VEMPTYPROPERTY_H + +#include "vproperty.h" + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT VEmptyProperty : public VProperty +{ +public: + //! Standard constructor, takes a name and a parent property as argument + explicit VEmptyProperty(const QString& name); + + //! Destructor + virtual ~VEmptyProperty(); + + //! 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); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Returns item flags + virtual Qt::ItemFlags flags(int column = DPC_Name) const; + + //! 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 = NULL) const; + +protected: + //! Protected constructor + VEmptyProperty(VPropertyPrivate* d); +}; + +} + +#endif // VEMPTYPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp new file mode 100644 index 000000000..b8285235e --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp @@ -0,0 +1,109 @@ +#include "venumproperty.h" +#include "vproperty_p.h" + +#include + +using namespace VPE; + +VEnumProperty::VEnumProperty(const QString& name) + : VProperty(name, QVariant::Int) +{ + d_ptr->VariantValue = 0; + d_ptr->VariantValue.convert(QVariant::Int); +} + + +//! Get the data how it should be displayed +QVariant VEnumProperty::data (int column, int role) const +{ + if(EnumerationLiterals.empty()) + return QVariant(); + + int tmpIndex = d_ptr->VariantValue.toInt(); + + if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) + tmpIndex = 0; + + if(column == DPC_Data && Qt::DisplayRole == role) + return EnumerationLiterals.at(tmpIndex); + else if(column == DPC_Data && Qt::EditRole == role) + return tmpIndex; + else + return VProperty::data(column, role); +} + + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + QComboBox* tmpEditor = new QComboBox(parent); + tmpEditor->clear(); + tmpEditor->addItems(EnumerationLiterals); + tmpEditor->setCurrentIndex(d_ptr->VariantValue.toInt()); + + return tmpEditor; +} + +//! Gets the data from the widget +QVariant VEnumProperty::getEditorData(QWidget* editor) const +{ + QComboBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->currentIndex(); + + return QVariant(0); +} + +//! Sets the enumeration literals +void VEnumProperty::setLiterals(const QStringList& literals) +{ + EnumerationLiterals = literals; +} + +//! Get the settings. This function has to be implemented in a subclass in order to have an effect +QStringList VEnumProperty::getLiterals() const +{ + return EnumerationLiterals; +} + +//! Sets the value of the property +void VEnumProperty::setValue(const QVariant& value) +{ + int tmpIndex = value.toInt(); + + if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) + tmpIndex = 0; + + d_ptr->VariantValue.setValue(tmpIndex); +} + +QString VEnumProperty::type() const +{ + return "enum"; +} + +VProperty* VEnumProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VEnumProperty(getName())); +} + +void VEnumProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == "literals") + setLiterals(value.toString().split(";;")); +} + +QVariant VEnumProperty::getSetting(const QString& key) const +{ + if(key == "literals") + return getLiterals().join(";;"); + else + return VProperty::getSetting(key); +} + +QStringList VEnumProperty::getSettingKeys() const +{ + return QStringList("literals"); +} diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.h b/src/libs/vpropertyexplorer/plugins/venumproperty.h new file mode 100644 index 000000000..72748529d --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.h @@ -0,0 +1,68 @@ +#ifndef VENUMPROPERTY_H +#define VENUMPROPERTY_H + +#include "vproperty.h" + +#include + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public VProperty +{ +public: + //! Constructor + VEnumProperty(const QString& name); + + //! Destructor + ~VEnumProperty() {} + + //! 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); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the enumeration literals + virtual void setLiterals(const QStringList &literals); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QStringList getLiterals() 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; + + //! Sets the settings. Available settings: + //! + //! key: "literals" - value: "item1;;item2;;item3" + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + +protected: + //! The list of possible options to choose frome + QStringList EnumerationLiterals; + // 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 // VENUMPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vfileproperty.cpp b/src/libs/vpropertyexplorer/plugins/vfileproperty.cpp new file mode 100644 index 000000000..583d71d3f --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfileproperty.cpp @@ -0,0 +1,136 @@ +#include "vfileproperty.h" +#include +#include + +#include "vfilepropertyeditor.h" + +#include "vfileproperty_p.h" + +using namespace VPE; + +VFileProperty::VFileProperty(const QString& name) + : VProperty(new VFilePropertyPrivate(name, QVariant::String)) +{ + +} + +VFileProperty::~VFileProperty() +{ + // +} + + +void VFileProperty::setFileFilters(const QString& filefilters) +{ + static_cast(d_ptr)->FileFilters = filefilters; +} + + +QString VFileProperty::getFileFilters() const +{ + return static_cast(d_ptr)->FileFilters; +} + + +void VFileProperty::setFile(const QString& file) +{ + d_ptr->VariantValue.setValue(file); +} + + +QString VFileProperty::getFile() const +{ + return d_ptr->VariantValue.toString(); +} + + +QVariant VFileProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + { + QFileInfo tmpFile(d_ptr->VariantValue.toString()); + return tmpFile.fileName(); + } + else + return VProperty::data(column, role); +} + + +QWidget* VFileProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + + VFileEditWidget* tmpWidget = new VFileEditWidget(parent); + if(delegate) + VFileEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*))); + tmpWidget->setFilter(static_cast(d_ptr)->FileFilters); // todo: parse this string + tmpWidget->setFile(d_ptr->VariantValue.toString()); + tmpWidget->setDirectory(static_cast(d_ptr)->Directory); + return tmpWidget; +} + + +bool VFileProperty::setEditorData(QWidget* editor) +{ + VFileEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + tmpWidget->setFile(d_ptr->VariantValue.toString()); + else + return false; + + return true; +} + + +QVariant VFileProperty::getEditorData(QWidget* editor) const +{ + VFileEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + return tmpWidget->getFile(); + + return QVariant(); +} + +void VFileProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == "FileFilters") + setFileFilters(value.toString()); + else if(key == "Directory") + setDirectory(value.toBool()); +} + +QVariant VFileProperty::getSetting(const QString& key) const +{ + if(key == "FileFilters") + return getFileFilters(); + else if(key == "Directory") + return isDirectory(); + else + return VProperty::getSetting(key); +} + +QStringList VFileProperty::getSettingKeys() const +{ + return QStringList("FileFilters") << "Directory"; +} + +QString VFileProperty::type() const +{ + return "file"; +} + +VProperty* VFileProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VFileProperty(getName())); +} + +bool VFileProperty::isDirectory() const +{ + return static_cast(d_ptr)->Directory; +} + + +void VFileProperty::setDirectory(bool is_directory) +{ + static_cast(d_ptr)->Directory = is_directory; +} diff --git a/src/libs/vpropertyexplorer/plugins/vfileproperty.h b/src/libs/vpropertyexplorer/plugins/vfileproperty.h new file mode 100644 index 000000000..dd66ec24a --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfileproperty.h @@ -0,0 +1,76 @@ +#ifndef VFILEPROPERTY_H +#define VFILEPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +#include + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT VFileProperty : public VProperty +{ +public: + VFileProperty(const QString &name); + + //! The destructor + ~VFileProperty(); + + //! Sets the file filters. The file filters have to be like the ones passed a QFileOpenDialog. + virtual void setFileFilters(const QString& filefilters); + + //! Returns the current file filters as a string + virtual QString getFileFilters() const; + + //! Set file + virtual void setFile(const QString& file); + + //! Get file + virtual QString getFile() const; + + //! 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 settings. Available settings: + //! + //! key: "FileFilters" - value: File filters in the same format the QFileDialog expects it + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! 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; + + //! Returns whether this is a file (false) or a directory (true) + virtual bool isDirectory() const; + + //! Sets whether this is a file (false) or a directory (true) + virtual void setDirectory(bool is_directory); +}; + +} + +#endif // VFILEPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.cpp b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.cpp new file mode 100644 index 000000000..ddd681afc --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.cpp @@ -0,0 +1,204 @@ +#include "vfilepropertyeditor.h" + +#include "vfileproperty.h" + +#include +#include +#include +#include + +using namespace VPE; + +VFileEditWidget::VFileEditWidget(QWidget *parent, bool is_directory) + : QWidget(parent), Directory(is_directory) +{ + // Create the tool button,ToolButton = new QToolButton(this); + ToolButton = new QToolButton(this); + ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); + ToolButton->setText(tr("...")); + ToolButton->setFixedWidth(20); + ToolButton->installEventFilter(this); + setFocusProxy(ToolButton); // Make the ToolButton the focus proxy + setFocusPolicy(ToolButton->focusPolicy()); + connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked())); + + // Create the line edit widget + FileLineEdit = new QLineEdit(this); + FileLineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + FileLineEdit->setText(CurrentFilePath); + FileLineEdit->installEventFilter(this); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(0); + layout->setMargin(0); + layout->addWidget(FileLineEdit); + layout->addWidget(ToolButton); + + // Accept drops + setAcceptDrops(true); +} + + +VFileEditWidget::~VFileEditWidget() +{ + // nothing needs to be done here +} + + +void VFileEditWidget::setFile(const QString &value, bool emit_signal) +{ + if (CurrentFilePath != value) + { + CurrentFilePath = value; + FileLineEdit->setText(CurrentFilePath); + + if(emit_signal) + { + emit dataChangedByUser(CurrentFilePath, this); + emit commitData(this); + } + } +} + + +void VFileEditWidget::setFilter(const QString &dialog_filter, const QStringList& filter_list) +{ + FileDialogFilter = dialog_filter; + FilterList = filter_list; +} + +void VFileEditWidget::setDirectory(bool dir) +{ + Directory = dir; +} + +QString VFileEditWidget::getFile() +{ + return CurrentFilePath; +} + + +void VFileEditWidget::onToolButtonClicked() +{ + QString filepath = (Directory ? QFileDialog::getExistingDirectory(0, tr("Directory"), CurrentFilePath) : QFileDialog::getOpenFileName(0, tr("Open File"), CurrentFilePath, FileDialogFilter)); + if (!filepath.isNull()) + setFile(filepath, true); +} + + +bool VFileEditWidget::eventFilter(QObject *obj, QEvent *ev) +{ + if(ev->type() == QEvent::DragEnter || ev->type() == QEvent::Drop) + { + ev->ignore(); + if(ev->type() == QEvent::DragEnter) + dragEnterEvent(static_cast(ev)); + else if(ev->type() == QEvent::Drop) + dropEvent(static_cast(ev)); + + if(ev->isAccepted()) + return true; + else + return QWidget::eventFilter(obj, ev); + } + else if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress)) + { + // Ignore the event, so that eventually the delegate gets the event. + ev->ignore(); + return true; + } + else if(obj == FileLineEdit) + { + if(ev->type() == QEvent::FocusOut) + { + setFile(FileLineEdit->text(), true); + // We don't return true here because we still want the line edit to catch the event as well + } + } + + // forward the signal to the parent class + return QWidget::eventFilter(obj, ev); +} + +bool VFileEditWidget::isDirectory() +{ + return Directory; +} + + +void VFileEditWidget::dragEnterEvent(QDragEnterEvent* event) +{ + QString tmpFileName; + if(checkMimeData(event->mimeData(), tmpFileName)) + { + event->accept(); + event->acceptProposedAction(); + } +} + +void VFileEditWidget::dragMoveEvent(QDragMoveEvent* event) +{ + event->acceptProposedAction(); +} + +void VFileEditWidget::dragLeaveEvent(QDragLeaveEvent* event) +{ + event->accept(); +} + +void VFileEditWidget::dropEvent(QDropEvent* event) +{ + QString tmpFileName; + if(checkMimeData(event->mimeData(), tmpFileName)) + { + setFile(tmpFileName); + emit dataChangedByUser(getFile(), this); + emit commitData(this); + event->accept(); + event->acceptProposedAction(); + } +} + + +bool VFileEditWidget::checkMimeData(const QMimeData* data, QString& file) const +{ + if (data->hasUrls()) + { + QList tmpUrlList = data->urls(); + QFileInfo tmpFileInfo; + + foreach(QUrl tmpUrl, tmpUrlList) + if(QFile::exists(tmpUrl.toLocalFile())) + { tmpFileInfo = QFileInfo(tmpUrl.toLocalFile()); break; } + + if(checkFileFilter(tmpFileInfo.fileName())) + { + file = tmpFileInfo.absoluteFilePath(); + return true; + } + } + + return false; +} + +bool VFileEditWidget::checkFileFilter(const QString& file) const +{ + if(FilterList.isEmpty()) + return true; + + QFileInfo tmpFileInfo(file); + + if((Directory && !tmpFileInfo.isDir()) || (!Directory && !tmpFileInfo.isFile())) + return false; + + foreach(QString tmpFilter, FilterList) + { + QRegExp tmpRegExpFilter(tmpFilter, Qt::CaseInsensitive, QRegExp::Wildcard); + if(tmpRegExpFilter.exactMatch(file)) + return true; + } + + return false; +} + diff --git a/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h new file mode 100644 index 000000000..729dbead6 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h @@ -0,0 +1,89 @@ +#ifndef VFILEPROPERTYEDITOR_H +#define VFILEPROPERTYEDITOR_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include + +namespace VPE{ + + +class VPROPERTYEXPLORERSHARED_EXPORT VFileEditWidget : public QWidget +{ + Q_OBJECT + +public: + VFileEditWidget(QWidget* parent, bool is_directory = false); + virtual ~VFileEditWidget(); + + + //! This function returns the file currently set to this editor + QString getFile(); + + //! Needed for proper event handling + bool eventFilter(QObject* obj, QEvent* ev); + + //! Returns the directory/file setting + //! \return True, if a directory dialog is being shown, false if a file dialog + bool isDirectory(); + +signals: + //! This signal is emitted when the user changed the curret file. + //! Actions triggering this signal are either using the file dialog + //! to select a new file or changing the file path in the line edit. + void dataChangedByUser(const QString &getFile, VFileEditWidget* editor); + + //! This signal is emitted whenever dataChangedByUser() gets emmitted + //! and is connected to the delegate's commitData() signal + void commitData(QWidget* editor); + + +public slots: + //! Sets the current file, does not check if it is valid + //! \param file The new filepath the widget should show + //! \emit_signal If true, this will emit the dataChangedByUser()-signal (if file differs from the current file) + void setFile(const QString &getFile, bool emit_signal = false); + + //! Sets a filter for the file field + //! \param dialog_filter The filter used for the File Dialog + //! \param filter_list The list of file endings. The filters are being checked using regular expressions + void setFilter(const QString& dialog_filter = QString(), const QStringList& filter_list = QStringList()); + + //! Sets whether the property stores a directory or a file + void setDirectory(bool dir); + +private slots: + //! This slot gets activated, when the "..." button gets clicked + void onToolButtonClicked(); + +protected: + void dragEnterEvent(QDragEnterEvent* event); + void dragMoveEvent(QDragMoveEvent* event); + void dragLeaveEvent(QDragLeaveEvent* event); + void dropEvent(QDropEvent* event); + + + + //! This function checks the mime data, if it is compatible with the filters + virtual bool checkMimeData(const QMimeData* data, QString& getFile) const; + + //! This checks, if a file is compatible with the filters + virtual bool checkFileFilter(const QString& getFile) const; + + + QString CurrentFilePath; + QToolButton* ToolButton; + QLineEdit* FileLineEdit; + QString FileDialogFilter; + QStringList FilterList; + + //! Specifies whether it is being looked for a directory (true) or a file (false, default) + bool Directory; +}; + +} + +#endif // VFILEPROPERTYEDITOR_H diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp new file mode 100644 index 000000000..8cf45b399 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp @@ -0,0 +1,183 @@ +#include "vnumberproperty.h" + +#include +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + + +const int VIntegerProperty::StandardMin = -1000000; +const int VIntegerProperty::StandardMax = 1000000; + +VIntegerProperty::VIntegerProperty(const QString& name, const QMap& settings) + : VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) +{ + VProperty::setSettings(settings); + d_ptr->VariantValue.setValue(0); + d_ptr->VariantValue.convert(QVariant::Int); +} + +VIntegerProperty::VIntegerProperty(const QString &name) + : VProperty(name), Min(StandardMin), Max(StandardMax) +{ + d_ptr->VariantValue.setValue(0); + d_ptr->VariantValue.convert(QVariant::Int); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + QSpinBox* tmpEditor = new QSpinBox(parent); + tmpEditor->setMinimum(Min); + tmpEditor->setMaximum(Max); + tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + tmpEditor->setValue(d_ptr->VariantValue.toInt()); + + return tmpEditor; +} + +//! Gets the data from the widget +QVariant VIntegerProperty::getEditorData(QWidget* editor) const +{ + QSpinBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->value(); + + return QVariant(0); +} + +void VIntegerProperty::setSettings(int minimum, int maxiumum) +{ + Min = minimum; + Max = maxiumum; +} + +void VIntegerProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == "Min") + setSettings(value.toInt(), Max); + else if(key == "Max") + setSettings(Min, value.toInt()); +} + +QVariant VIntegerProperty::getSetting(const QString& key) const +{ + if(key == "Min") + return Min; + if(key == "Max") + return Max; + else + return VProperty::getSetting(key); +} + +QStringList VIntegerProperty::getSettingKeys() const +{ + return (QStringList("Min") << "Max"); +} + +QString VIntegerProperty::type() const +{ + return "integer"; +} + +VProperty* VIntegerProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VIntegerProperty(getName())); +} + + + + + +const double VDoubleProperty::StandardPrecision = 5; + +VDoubleProperty::VDoubleProperty(const QString& name, const QMap& settings) + : VIntegerProperty(name), Precision(StandardPrecision) +{ + VProperty::setSettings(settings); + d_ptr->VariantValue.setValue(0); + d_ptr->VariantValue.convert(QVariant::Double); + d_ptr->PropertyVariantType = QVariant::Double; +} + +VDoubleProperty::VDoubleProperty(const QString &name) + : VIntegerProperty(name), Precision(StandardPrecision) +{ + d_ptr->VariantValue.setValue(0); + d_ptr->VariantValue.convert(QVariant::Double); + d_ptr->PropertyVariantType = QVariant::Double; +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + QDoubleSpinBox* tmpEditor = new QDoubleSpinBox(parent); + tmpEditor->setMinimum(Min); + tmpEditor->setMaximum(Max); + tmpEditor->setDecimals(Precision); + tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + tmpEditor->setValue(d_ptr->VariantValue.toDouble()); + + return tmpEditor; +} + +//! Gets the data from the widget +QVariant VDoubleProperty::getEditorData(QWidget* editor) const +{ + QDoubleSpinBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->value(); + + return QVariant(0); +} + +void VDoubleProperty::setSettings(double minimum, double maxiumum, int precision) +{ + VIntegerProperty::setSettings(minimum, maxiumum); + Precision = precision; +} + +void VDoubleProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == "Min") + setSettings(value.toDouble(), Max, Precision); + else if(key == "Max") + setSettings(Min, value.toDouble(), Precision); + else if(key == "Precision") + setSettings(Min, Max, value.toDouble()); +} + +QVariant VDoubleProperty::getSetting(const QString& key) const +{ + if(key == "Min") + return Min; + if(key == "Max") + return Max; + if(key == "Precision") + return Precision; + else + return VProperty::getSetting(key); +} + +QStringList VDoubleProperty::getSettingKeys() const +{ + return (QStringList("Min") << "Max" << "Precision"); +} + +QString VDoubleProperty::type() const +{ + return "double"; +} + +VProperty* VDoubleProperty::clone(bool include_children, VProperty* container) const +{ + return VIntegerProperty::clone(include_children, container ? container : new VDoubleProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h new file mode 100644 index 000000000..fa4fbcf4b --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h @@ -0,0 +1,115 @@ +#ifndef VNUMBERPROPERTY_H +#define VNUMBERPROPERTY_H + +#include "vpropertyexplorer_global.h" +#include "vproperty.h" + +namespace VPE { + + +//! Class for holding an integer property +class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public VProperty +{ +public: + VIntegerProperty(const QString& name, const QMap& settings); + + VIntegerProperty(const QString& name); + + //! 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); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the settings of a basic integer property + //! \param minimum The minimum value + //! \param maxiumum The maximum value + virtual void setSettings(int minimum, int maxiumum); + + //! Sets the settings. Available settings: + //! + //! key: "Min" - value: Minimum number as integer + //! key: "Max" - value: Maximum number as integer + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! 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 = NULL) const; + +protected: + int Min, Max; + + static const int StandardMin;// = -1000000; + static const int StandardMax;// = 1000000; +}; + + +//! Class for holding a double property +class VPROPERTYEXPLORERSHARED_EXPORT VDoubleProperty : public VIntegerProperty +{ +public: + VDoubleProperty(const QString& name, const QMap& settings); + + VDoubleProperty(const QString& name); + + //! 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); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the settings of a double property + //! \param minimum The minimum value + //! \param maxiumum The maximum value + //! \param precision The number of decimal places + virtual void setSettings(double minimum, double maxiumum, int precision); + + //! Sets the settings. Available settings: + //! + //! key: "Min" - value: Minimum number as integer + //! key: "Max" - value: Maximum number as integer + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! 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 = NULL) const; + +protected: + //! Number of decimals after the decimal point + int Precision; + + const static double StandardPrecision;// = 5; +}; + + +} + +#endif // VNUMBERPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp new file mode 100644 index 000000000..79772108c --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp @@ -0,0 +1,84 @@ +#include "vshortcutproperty.h" +#include +#include + +#include "vshortcutpropertyeditor.h" + +#include "vproperty_p.h" + + +using namespace VPE; + +VShortcutProperty::VShortcutProperty(const QString& name) + : VProperty(name, QVariant::String) +{ + +} + +VShortcutProperty::~VShortcutProperty() +{ + // +} + +QVariant VShortcutProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + { + return d_ptr->VariantValue; + } + else + return VProperty::data(column, role); +} + + +QWidget* VShortcutProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, + const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + + VShortcutEditWidget* tmpWidget = new VShortcutEditWidget(parent); + if(delegate) + VShortcutEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*))); + + return tmpWidget; + return nullptr; +} + + +bool VShortcutProperty::setEditorData(QWidget* editor) +{ + VShortcutEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + tmpWidget->setShortcut(d_ptr->VariantValue.toString(), false); + else + return false; + + return true; +} + + +QVariant VShortcutProperty::getEditorData(QWidget* editor) const +{ + VShortcutEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + return tmpWidget->getShortcutAsString(); + + return QVariant(); +} + + +QString VShortcutProperty::type() const +{ + return "shortcut"; +} + +VProperty* VShortcutProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VShortcutProperty(getName())); +} + +void VShortcutProperty::setValue(const QVariant &value) +{ + VProperty::setValue(QKeySequence::fromString(value.toString()).toString()); +} + diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutproperty.h b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.h new file mode 100644 index 000000000..f8be59e6b --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.h @@ -0,0 +1,49 @@ +#ifndef VSHORTCUTROPERTY_H +#define VSHORTCUTROPERTY_H + +#include "vpropertyexplorer_global.h" +#include "vproperty.h" + +namespace VPE { + +//! This property can be used to handle key shortcuts +class VPROPERTYEXPLORERSHARED_EXPORT VShortcutProperty : public VProperty +{ +public: + VShortcutProperty(const QString &name); + + //! The destructor + ~VShortcutProperty(); + + //! 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; + + //! 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 = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); +}; + +} + +#endif // VFILEPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.cpp b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.cpp new file mode 100644 index 000000000..4defbebe9 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.cpp @@ -0,0 +1,86 @@ +#include "vshortcutpropertyeditor.h" + +#include +#include + +using namespace VPE; + +VShortcutEditWidget::VShortcutEditWidget(QWidget *parent) + : QWidget(parent) +{ + // Create the line edit widget + LineEdit = new QLineEdit(this); + LineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + LineEdit->clear(); + LineEdit->installEventFilter(this); + setFocusProxy(LineEdit); + connect(LineEdit, SIGNAL(textEdited(QString)), this, SLOT(onTextEdited(QString))); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(0); + layout->setMargin(0); + layout->addWidget(LineEdit); +} + + +VShortcutEditWidget::~VShortcutEditWidget() +{ + // nothing needs to be done here +} + +bool VShortcutEditWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == LineEdit) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + + int keys = keyEvent->key(); + + if(keys != Qt::Key_Shift && + keys != Qt::Key_Control && + keys != Qt::Key_Meta && + keys != Qt::Key_AltGr && + keys != Qt::Key_Alt) + { + keys += keyEvent->modifiers(); + setShortcut(QKeySequence(keys), true); + return true; + } + } + } + + return QWidget::eventFilter(obj, event); +} + +QString VShortcutEditWidget::getShortcutAsString() +{ + return CurrentKeySequence.toString(); +} + +QKeySequence VShortcutEditWidget::getShortcut() +{ + return CurrentKeySequence; +} + + + +void VShortcutEditWidget::setShortcut(const QString &shortcut, bool emit_signal) +{ + setShortcut(QKeySequence::fromString(shortcut), emit_signal); +} + +void VShortcutEditWidget::setShortcut(const QKeySequence &shortcut, bool emit_signal) +{ + if(shortcut != CurrentKeySequence) { + CurrentKeySequence = shortcut; + LineEdit->setText(CurrentKeySequence.toString()); + if(emit_signal) + emit dataChangedByUser(CurrentKeySequence, this); + } +} + +void VShortcutEditWidget::onTextEdited(const QString &text) +{ + setShortcut(text, true); +} diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.h b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.h new file mode 100644 index 000000000..8e907c161 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.h @@ -0,0 +1,64 @@ +#ifndef VSHORTCUTPROPERTYEDITOR_H +#define VSHORTCUTPROPERTYEDITOR_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include + +namespace VPE{ + + +class VPROPERTYEXPLORERSHARED_EXPORT VShortcutEditWidget : public QWidget +{ + Q_OBJECT + +public: + VShortcutEditWidget(QWidget* parent); + virtual ~VShortcutEditWidget(); + + //! Needed for proper event handling + bool eventFilter(QObject* obj, QEvent* evenvt); + + //! Returns the currently set shortcut + QString getShortcutAsString(); + + //! Returns the currently set shortcut + QKeySequence getShortcut(); + +signals: + //! This signal is emitted when the user changed the current shortcut + void dataChangedByUser(const QKeySequence& sequence, VShortcutEditWidget* editor); + + //! This signal is emitted whenever dataChangedByUser() gets emmitted + //! and is connected to the delegate's commitData() signal + void commitData(QWidget* editor); + +public slots: + //! Sets the shortcut + //! \param shortcut The new shortcut + //! \emit_signal If true, this will emit the dataChangedByUser()-signal + void setShortcut(const QString &shortcut, bool emit_signal); + + //! Sets the shortcut + //! \param shortcut The new shortcut + //! \emit_signal If true, this will emit the dataChangedByUser()-signal + void setShortcut(const QKeySequence &shortcut, bool emit_signal); + +private slots: + //! This slot is called when the user edits the line edit (e.g. by removing or pasting text using the mouse) + void onTextEdited(const QString& text); + +protected: + //! The current key sequence + QKeySequence CurrentKeySequence; + + //! The line to display and edit the key sequence + QLineEdit* LineEdit; +}; + +} + +#endif // VFILEPROPERTYEDITOR_H diff --git a/src/libs/vpropertyexplorer/plugins/vwidgetproperty.cpp b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.cpp new file mode 100644 index 000000000..2082ffdd5 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.cpp @@ -0,0 +1,46 @@ +#include "vwidgetproperty.h" + + +#include "vwidgetproperty_p.h" + +using namespace VPE; + + + + +VWidgetProperty::VWidgetProperty(const QString& name, QWidget* widget) + : VEmptyProperty(new VWidgetPropertyPrivate(name, QVariant::Invalid, widget)) +{ +} + +VWidgetProperty::~VWidgetProperty() +{ + // +} + +QWidget *VWidgetProperty::getWidget() const +{ + return static_cast(d_ptr)->Widget.data(); +} + +void VWidgetProperty::setWidget(QWidget* widget) +{ + VWidgetPropertyPrivate* tmpDPtr = static_cast(d_ptr); + QWidget* tmpOldWidget = tmpDPtr->Widget.data(); + if(tmpOldWidget) + tmpOldWidget->deleteLater(); + + tmpDPtr->Widget = widget; +} + + +QString VWidgetProperty::type() const +{ + return "widget"; +} + +VProperty* VWidgetProperty::clone(bool include_children, VProperty* container) const +{ + // todo: This is a tricky one to clone... don't know what would be the best way to do so... Maybe serialize the widget somehow? + return VProperty::clone(include_children, container ? container : new VWidgetProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vwidgetproperty.h b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.h new file mode 100644 index 000000000..a2de4f078 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.h @@ -0,0 +1,42 @@ +#ifndef VWIDGETROPERTY_H +#define VWIDGETROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vemptyproperty.h" + +#include + +namespace VPE { + +// todo: this way, this class doesn't really make sense. What we have to do is pass a widget factory instead of the actual widget! + +//! This property holds a QWidget and displays it, if the view supports that. If not, it will behave like an empty property +class VPROPERTYEXPLORERSHARED_EXPORT VWidgetProperty : public VEmptyProperty +{ +public: + //! Constructor + VWidgetProperty(const QString &name, QWidget* widget = nullptr); + + //! The destructor + ~VWidgetProperty(); + + //! Returns the widget held by this property + QWidget* getWidget() const; + + //! Sets the widget for this property. If there is already an old one, it will be deleted. + void setWidget(QWidget* widget); + + //! 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; +}; + +} + +#endif // VWIDGETROPERTY_H diff --git a/src/libs/vpropertyexplorer/vabstractpropertyfactory.h b/src/libs/vpropertyexplorer/vabstractpropertyfactory.h new file mode 100644 index 000000000..832fd8fdd --- /dev/null +++ b/src/libs/vpropertyexplorer/vabstractpropertyfactory.h @@ -0,0 +1,26 @@ +#ifndef VABSTRACTPROPERTYFACTORY_H +#define VABSTRACTPROPERTYFACTORY_H + +#include "vpropertyexplorer_global.h" +#include + +namespace VPE { + +class VProperty; + +class VPROPERTYEXPLORERSHARED_EXPORT VAbstractPropertyFactory +{ +public: + //! Empty virtual destructor + virtual ~VAbstractPropertyFactory() {} + + //! Creates a new property of a certain type and assigns a name and description (otionally) + //! \param type The type of the property as string + //! \param name The property's name + //! \return Returns the created property or NULL if it couldn't be be created + virtual VProperty* createProperty(const QString& type, const QString &name) = 0; +}; + +} + +#endif // VABSTRACTPROPERTYFACTORY_H diff --git a/src/libs/vpropertyexplorer/vfileproperty_p.h b/src/libs/vpropertyexplorer/vfileproperty_p.h new file mode 100644 index 000000000..6e2dc8ee0 --- /dev/null +++ b/src/libs/vpropertyexplorer/vfileproperty_p.h @@ -0,0 +1,30 @@ +#ifndef VFILEPROPERTY_P_H +#define VFILEPROPERTY_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include "vproperty_p.h" + +namespace VPE { + +class VFilePropertyPrivate : public VPropertyPrivate { +public: + //! File filters + QString FileFilters; + + //! Determines whether the file property is a file or a directory. Default: false + bool Directory; + + + //! Constructor passing name and type + VFilePropertyPrivate(const QString& name, QVariant::Type type, bool directory = false) + : VPropertyPrivate(name, type), FileFilters(), Directory(directory) {} + + //! Constructor + VFilePropertyPrivate() + : VPropertyPrivate(), FileFilters(), Directory(false) {} +}; + +} + +#endif // VFILEPROPERTY_P_H diff --git a/src/libs/vpropertyexplorer/vproperty.cpp b/src/libs/vpropertyexplorer/vproperty.cpp new file mode 100644 index 000000000..b845891db --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperty.cpp @@ -0,0 +1,345 @@ +#include "vproperty.h" +#include +#include +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + +//! Standard constructor, takes a name and a parent property as argument +VProperty::VProperty(const QString& name, QVariant::Type type) + : d_ptr(new VPropertyPrivate(name, type)) +{ + +} + +VProperty::VProperty(VPropertyPrivate *d) + : d_ptr(d) +{ +} + + +VProperty::~VProperty() +{ + setParent(nullptr); + + while(!d_ptr->Children.isEmpty()) + { + VProperty* tmpChild = d_ptr->Children.takeLast(); + delete tmpChild; + } + + delete d_ptr; +} + +QString VProperty::type() const +{ + return "string"; +} + +//! Get the data how it should be displayed +QVariant VProperty::data (int column, int role) const +{ + if(column == DPC_Name && Qt::DisplayRole == role) + return QVariant(d_ptr->Name); + else if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return d_ptr->VariantValue; + else if(Qt::ToolTipRole == role) + return QVariant(d_ptr->Description); + else + return QVariant(); +} + +bool VProperty::setData(const QVariant &data, int role) +{ + bool tmpResult = false; + if(Qt::EditRole == role) + { + tmpResult = (d_ptr->VariantValue != data); + setValue(data); + } + + return tmpResult; +} + +bool VProperty::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QAbstractItemDelegate *delegate) const +{ + Q_UNUSED(painter); + Q_UNUSED(option); + Q_UNUSED(index); + Q_UNUSED(delegate); + + return false; +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + QItemEditorFactory *factory = new QItemEditorFactory; + QItemEditorCreatorBase *lineCreator = new QStandardItemEditorCreator(); + factory->registerEditor(QVariant::String, lineCreator); + QItemEditorFactory::setDefaultFactory(factory); + + d_ptr->editor = factory->createEditor(d_ptr->PropertyVariantType, parent); + //return factory->createEditor(d_ptr->PropertyVariantType, parent); + return d_ptr->editor; +} + +bool VProperty::setEditorData(QWidget* editor) +{ + if(!editor) + return false; + + QByteArray n = editor->metaObject()->userProperty().name(); + + if (!n.isEmpty()) { + editor->blockSignals(true); + editor->setProperty(n, d_ptr->VariantValue); + editor->blockSignals(false); + return true; + } + + return false; +} + +//! Gets the data from the widget +QVariant VProperty::getEditorData(QWidget* editor) const +{ + if(!editor) + return QVariant(); + + QByteArray n = editor->metaObject()->userProperty().name(); + + if (!n.isEmpty()) + return editor->property(n); + else + return QVariant(); +} + +//! Returns item flags +Qt::ItemFlags VProperty::flags(int column) const +{ + if(column == DPC_Name) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else if(column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + + +void VProperty::setValue(const QVariant &value) +{ + d_ptr->VariantValue = value; + d_ptr->VariantValue.convert(d_ptr->PropertyVariantType); + if (d_ptr->editor != nullptr) + { + setEditorData(d_ptr->editor); + } +} + + +QVariant VProperty::getValue() const +{ + return d_ptr->VariantValue; +} + +QString VProperty::serialize() const +{ + return getValue().toString(); +} + +void VProperty::deserialize(const QString& value) +{ + setValue(QVariant(value)); +} + + +void VProperty::setName(const QString& name) +{ + d_ptr->Name = name; +} + + +QString VProperty::getName() const +{ + return d_ptr->Name; +} + + +void VProperty::setDescription(const QString& desc) +{ + d_ptr->Description = desc; +} + + +QString VProperty::getDescription() const +{ + return d_ptr->Description; +} + + + + +//! Returns a reference to the list of children +QList& VProperty::getChildren() +{ + return d_ptr->Children; +} + +//! Returns a reference to the list of children +const QList& VProperty::getChildren() const +{ + return d_ptr->Children; +} + +//! Returns the child at a certain row +VProperty* VProperty::getChild(int row) const +{ + if(row >= 0 && row < getRowCount()) + return d_ptr->Children.at(row); + else + return nullptr; +} + +//! Gets the number of children +int VProperty::getRowCount() const +{ + return d_ptr->Children.count(); +} + +//! Gets the parent of this property +VProperty* VProperty::getParent() const +{ + return d_ptr->Parent; +} + +//! Sets the parent of this property +void VProperty::setParent(VProperty* parent) +{ + if(d_ptr->Parent == parent) + return; + + VProperty* oldParent = d_ptr->Parent; + d_ptr->Parent = parent; + + if(oldParent) + oldParent->removeChild(this); + + if(d_ptr->Parent && d_ptr->Parent->getChildRow(this) == -1) + d_ptr->Parent->addChild(this); +} + +int VProperty::addChild(VProperty *child) +{ + if(child && child->getParent() != this) + child->setParent(this); + + if(!d_ptr->Children.contains(child) && child != nullptr) + { + d_ptr->Children.push_back(child); + return d_ptr->Children.count()-1; + } + else + { + return d_ptr->Children.indexOf(child); + } +} + +//! Removes a child from the children list +void VProperty::removeChild(VProperty* child) +{ + d_ptr->Children.removeAll(child); + + if(child && child->getParent() == this) + child->setParent(nullptr); +} + +//! Returns the row the child has +int VProperty::getChildRow(VProperty* child) const +{ + return d_ptr->Children.indexOf(child); +} + + +//! Returns whether the views have to update the parent of this property if it changes +bool VProperty::getUpdateParent() const +{ + return d_ptr->UpdateParent; +} + +//! Returns whether the views have to update the children of this property if it changes +bool VProperty::getUpdateChildren() const +{ + return d_ptr->UpdateChildren; +} + +//! Sets whether the views should update Parents or children after this property changes +void VProperty::setUpdateBehaviour(bool update_parent, bool update_children) +{ + d_ptr->UpdateParent = update_parent; + d_ptr->UpdateChildren = update_children; +} + + +void VProperty::setSettings(const QMap& settings) +{ + QMap::const_iterator tmpIterator = settings.constBegin(); + for (; tmpIterator != settings.constEnd(); ++tmpIterator) { + setSetting(tmpIterator.key(), tmpIterator.value()); + } +} + +QMap VProperty::getSettings() const +{ + QMap tmpResult; + + QStringList tmpKeyList = getSettingKeys(); + foreach(const QString& tmpKey, tmpKeyList) + tmpResult.insert(tmpKey, getSetting(tmpKey)); + + return tmpResult; +} + +void VProperty::setSetting(const QString& key, const QVariant& value) +{ + Q_UNUSED(key) + Q_UNUSED(value) + // Not needed in the Standard property +} + +QVariant VProperty::getSetting(const QString& key) const +{ + // Not needed in the Standard property + Q_UNUSED(key) + return QVariant(); +} + +QStringList VProperty::getSettingKeys() const +{ + return QStringList(); +} + +VProperty* VProperty::clone(bool include_children, VProperty* container) const +{ + if(!container) + container = new VProperty(getName(), d_ptr->PropertyVariantType); + + container->setName(getName()); + container->setDescription(getDescription()); + container->setValue(getValue()); + container->setSettings(getSettings()); + container->setUpdateBehaviour(getUpdateParent(), getUpdateChildren()); + + if(include_children) { + foreach(VProperty* tmpChild, d_ptr->Children) + container->addChild(tmpChild->clone(true)); + } + + return container; +} diff --git a/src/libs/vpropertyexplorer/vproperty.h b/src/libs/vpropertyexplorer/vproperty.h new file mode 100644 index 000000000..26e80f60b --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperty.h @@ -0,0 +1,176 @@ +#ifndef VPROPERTY_H +#define VPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include +#include +#include + +namespace VPE { + +static const int MyCustomEventType = 1099; + +class UserChangeEvent : public QEvent +{ +public: + UserChangeEvent() : QEvent((QEvent::Type)MyCustomEventType) {} +}; + +class VPropertyPrivate; + +class VPROPERTYEXPLORERSHARED_EXPORT VProperty +{ +public: + enum DPC_DisplayColumn { + DPC_Name = 0, + DPC_Data + }; + + //! Standard constructor, takes a name and a parent property as argument + explicit VProperty(const QString& name, QVariant::Type type = QVariant::String); + + //! Destructor + virtual ~VProperty(); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! This is used by the model to set the data + //! \param data The data to set + //! \param role The role. Default is Qt::EditRole + //! \return Returns true, if the data was changed, false if not. + virtual bool setData (const QVariant& data, int role = Qt::EditRole); + + //! This is called by the delegate when the property value is being drawn. + //! The standard implementation doesn't do anything. + //! If you reimplement this in a sub property, make sure to return true or the delegate will draw the item. + virtual bool paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QAbstractItemDelegate* delegate) 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; + + //! Returns item flags + virtual Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + + //! Serializes the value to a string + virtual QString serialize() const; + + //! Deserializes the value from a string + virtual void deserialize(const QString& value); + + // The following functions are experimental and not yet implemented. + /*//! Returns a pointer to the data stored and handled by this property. In most cases this function shouldn't be used. + //! \return Returns a void pointer to the data. Not all properties have to support this. By default, this implementation returns a NULL pointer. + virtual void* getDataPointer(); + + //! Sets the data. + //! \return Returns a void pointer to the data. Not all properties have to support this. By default, this implementation returns a NULL pointer. + virtual bool setDataPointer(void* pointer);*/ + + //! Sets the name of the property + virtual void setName(const QString& name); + + //! Gets the name of the property + virtual QString getName() const; + + //! Sets the name of the property + virtual void setDescription(const QString& desc); + + //! Gets the name of the property + virtual QString getDescription() const; + + //! Adds a child to this property + virtual int addChild(VProperty* child); + + //! Returns a reference to the list of children + virtual QList& getChildren(); + + //! Returns a reference to the list of children + virtual const QList& getChildren() const; + + //! Returns the child at a certain row + virtual VProperty* getChild(int row) const; + + //! Gets the number of children + virtual int getRowCount() const; + + //! Gets the parent of this property + virtual VProperty* getParent() const; + + //! Sets the parent of this property + virtual void setParent(VProperty* parent); + + //! Removes a child from the children list, doesn't delete the child! + virtual void removeChild(VProperty* child); + + //! Returns the row the child has + virtual int getChildRow(VProperty* child) const; + + //! Returns whether the views have to update the parent of this property if it changes + virtual bool getUpdateParent() const; + + //! Returns whether the views have to update the children of this property if it changes + virtual bool getUpdateChildren() const; + + //! Sets whether the views should update Parents or children after this property changes + virtual void setUpdateBehaviour(bool update_parent, bool update_children); + + //! Sets the settings by calling the overloaded setSetting(const QString& key, const QVariant& value) for each item in the map. + virtual void setSettings(const QMap& settings); + + //! Get the settings. + virtual QMap getSettings() const; + + //! Sets the settings. This function has to be implemented in a subclass in order to have an effect + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() 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; + + +protected: + //! Protected constructor + VProperty(VPropertyPrivate* d); + + //! The protected structure holding the member variables (to assure binary compatibility) + VPropertyPrivate* d_ptr; + +private: + // Provide access functions for the d_ptr + Q_DECLARE_PRIVATE(VProperty) +}; + +} + +#endif // VPROPERTY_H diff --git a/src/libs/vpropertyexplorer/vproperty_p.h b/src/libs/vpropertyexplorer/vproperty_p.h new file mode 100644 index 000000000..deaecdfed --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperty_p.h @@ -0,0 +1,61 @@ +#ifndef VPROPERTY_P_H +#define VPROPERTY_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include +#include "vproperty.h" + +namespace VPE { + +class VPropertyPrivate { +public: + //! The property's value. + //! This does not have to be used by subclasses, but it makes sense in cases where QVariant supports + //! the data type. Also, this can be used as cache, so that when the data() function gets called by + //! the model, the data does not have to be converted in a QVariant every time. + QVariant VariantValue; + + //! Property name + QString Name; + + //! Description + QString Description; + + //! Specifies whether the property is empty or not + bool IsEmpty; + + //! Stores the property type + QVariant::Type PropertyVariantType; + + //! Stores whether the views have to update the parent of this property if it changes + bool UpdateParent; + + //! Stores whether the views have to update the children of this property if it changes + bool UpdateChildren; + + //! The parent property + VProperty* Parent; + + QWidget* editor; + + //! List of child properties + QList Children; + + //! Constructor passing name and type + VPropertyPrivate(const QString& name, QVariant::Type type) + : VariantValue(type), Name(name), PropertyVariantType(type), UpdateParent(false), UpdateChildren(false), + Parent(nullptr), editor(nullptr) + {} + + //! Constructor + VPropertyPrivate() + : VariantValue(), Name(), PropertyVariantType(QVariant::Invalid), UpdateParent(false), UpdateChildren(false), + Parent(nullptr), editor(nullptr) + {} +}; + +} + +#endif // VPROPERTY_P_H diff --git a/src/libs/vpropertyexplorer/vpropertydelegate.cpp b/src/libs/vpropertyexplorer/vpropertydelegate.cpp new file mode 100644 index 000000000..091f61eb6 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertydelegate.cpp @@ -0,0 +1,100 @@ +#include "vpropertydelegate.h" +#include "vproperty.h" + +#include +#include +#include +#include + +using namespace VPE; + +VPropertyDelegate::VPropertyDelegate(QObject *parent) : + QStyledItemDelegate(parent), RowHeight(0), AddRowHeight(false) +{ +} + +VPropertyDelegate::~VPropertyDelegate() +{ + // +} + +QWidget* VPropertyDelegate::createEditor (QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QWidget* tmpWidget = nullptr; + if(index.isValid()) + { + VProperty* tmpProperty = reinterpret_cast(index.internalPointer()); + tmpWidget = tmpProperty->createEditor(parent, option, this); + } + + return tmpWidget ? tmpWidget : QStyledItemDelegate::createEditor(parent, option, index); +} + + +//! Sets the index data to the editor +void VPropertyDelegate::setEditorData (QWidget * editor, const QModelIndex & index) const +{ + bool done = false; + if(index.isValid() && editor) + { + VProperty* tmpProperty = reinterpret_cast(index.internalPointer()); + done = tmpProperty->setEditorData(editor); + } + + if(!done) + QStyledItemDelegate::setEditorData(editor, index); +} + +//! Updates the index data +void VPropertyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const +{ + QVariant tmpData; + if(index.isValid() && editor) + { + VProperty* tmpProperty = reinterpret_cast(index.internalPointer()); + tmpData = tmpProperty->getEditorData(editor); + } + + if(tmpData.isNull()) + QStyledItemDelegate::setModelData(editor, model, index); + else + model->setData(index, tmpData); +} + +QSize VPropertyDelegate::sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QSize tmpStandardSizeHint = QStyledItemDelegate::sizeHint(option, index); + tmpStandardSizeHint.setHeight(tmpStandardSizeHint.height() + 1); + + if(RowHeight > 0) + return QSize(tmpStandardSizeHint.width(), AddRowHeight ? tmpStandardSizeHint.height() + RowHeight : RowHeight); + else + return tmpStandardSizeHint; +} + +void VPropertyDelegate::setRowHeight(int height, bool add_to_standard) +{ + RowHeight = height; + AddRowHeight = add_to_standard; +} + +void VPropertyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const +{ + bool done = false; + if(index.isValid() && index.column() == 1) + done = reinterpret_cast(index.internalPointer())->paint(painter, option, index, this); + + if(!done) + QStyledItemDelegate::paint(painter, option, index); + + QColor tmpPenColor = static_cast(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option)); + + QPen tmpOldPen = painter->pen(); + painter->setPen(QPen(tmpPenColor)); + painter->drawLine(option.rect.right(), option.rect.y(), option.rect.right(), option.rect.bottom()); + painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom()); + painter->setPen(tmpOldPen); +} + + + diff --git a/src/libs/vpropertyexplorer/vpropertydelegate.h b/src/libs/vpropertyexplorer/vpropertydelegate.h new file mode 100644 index 000000000..ba6584db3 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertydelegate.h @@ -0,0 +1,44 @@ +#ifndef VPROPERTYDELEGATE_H +#define VPROPERTYDELEGATE_H + +#include "vpropertyexplorer_global.h" + +#include + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit VPropertyDelegate(QObject *parent = 0); + virtual ~VPropertyDelegate(); + + //! Creates the editor widget + virtual QWidget* createEditor (QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; + + //! Sets the index data to the editor + virtual void setEditorData (QWidget * editor, const QModelIndex & index) const; + + //! Updates the index data + virtual void setModelData (QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const; + + //! Returns the size hint + virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const; + + //! Sets the row height. Set this to 0 and the standard will be taken + void setRowHeight(int height = 0, bool add_to_standard = false); + + //! Renders the delegate using the given painter and style option for the item specified by index. + virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; + +protected: + int RowHeight; + bool AddRowHeight; + + +}; + +} + +#endif // VPROPERTYDELEGATE_H diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.cpp b/src/libs/vpropertyexplorer/vpropertyexplorer.cpp new file mode 100644 index 000000000..67bf08c0b --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.cpp @@ -0,0 +1,34 @@ +/************************************************************************ + ** + ** @file vpropertyexplorer.cpp + ** @author Roman Telezhynskyi + ** @date 26 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 . + ** + *************************************************************************/ + +#include "vpropertyexplorer.h" + + +Vpropertyexplorer::Vpropertyexplorer() +{ +} diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.h b/src/libs/vpropertyexplorer/vpropertyexplorer.h new file mode 100644 index 000000000..36c1d5917 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.h @@ -0,0 +1,41 @@ +/************************************************************************ + ** + ** @file vpropertyexplorer.h + ** @author Roman Telezhynskyi + ** @date 26 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 VPROPERTYEXPLORER_H +#define VPROPERTYEXPLORER_H + +#include "vpropertyexplorer_global.h" + +class VPROPERTYEXPLORERSHARED_EXPORT Vpropertyexplorer +{ + +public: + Vpropertyexplorer(); +}; + +#endif // VPROPERTYEXPLORER_H diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro new file mode 100644 index 000000000..a32c23255 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -0,0 +1,80 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-08-26T14:18:08 +# +#------------------------------------------------- + +QT += widgets + +QT -= gui + +TARGET = vpropertyexplorer +TEMPLATE = lib + +CONFIG += c++11 + +DEFINES += VPROPERTYEXPLORER_LIBRARY + +SOURCES += vpropertyexplorer.cpp \ + vproperty.cpp \ + vpropertydelegate.cpp \ + vpropertyfactorymanager.cpp \ + vpropertyformview.cpp \ + vpropertyformwidget.cpp \ + vpropertymodel.cpp \ + vpropertyset.cpp \ + vpropertytreeview.cpp \ + vserializedproperty.cpp \ + vstandardpropertyFactory.cpp \ + plugins/vwidgetproperty.cpp \ + plugins/vemptyproperty.cpp \ + plugins/vboolproperty.cpp \ + plugins/vshortcutproperty.cpp \ + plugins/vcolorproperty.cpp \ + plugins/vshortcutpropertyeditor.cpp \ + plugins/venumproperty.cpp \ + plugins/vfileproperty.cpp \ + plugins/vcolorpropertyeditor.cpp \ + plugins/vfilepropertyeditor.cpp \ + plugins/vnumberproperty.cpp \ + plugins/Vector3d/vvector3dproperty.cpp + +HEADERS += vpropertyexplorer.h\ + vpropertyexplorer_global.h \ + vpropertyfactorymanager_p.h \ + vpropertytreeview_p.h \ + vpropertyset_p.h \ + vabstractpropertyfactory.h \ + vfileproperty_p.h \ + vwidgetproperty_p.h \ + vpropertymodel_p.h \ + vstandardpropertyfactory.h \ + vpropertyformview_p.h \ + vpropertytreeview.h \ + vpropertyformwidget_p.h \ + vpropertydelegate.h \ + vproperty_p.h \ + vpropertyformwidget.h \ + vpropertyformview.h \ + vpropertyset.h \ + vpropertymodel.h \ + vproperty.h \ + plugins/vwidgetproperty.h \ + plugins/vcolorproperty.h \ + plugins/vboolproperty.h \ + plugins/vcolorpropertyeditor.h \ + plugins/vshortcutpropertyeditor.h \ + plugins/vemptyproperty.h \ + plugins/vshortcutproperty.h \ + plugins/venumproperty.h \ + plugins/vfilepropertyeditor.h \ + plugins/vfileproperty.h \ + plugins/vnumberproperty.h \ + plugins/Vector3d/vvector3dproperty.h \ + vpropertyfactorymanager.h \ + vserializedproperty.h + +unix { + target.path = /usr/lib + INSTALLS += target +} diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer_global.h b/src/libs/vpropertyexplorer/vpropertyexplorer_global.h new file mode 100644 index 000000000..68c08bffb --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyexplorer_global.h @@ -0,0 +1,40 @@ +/************************************************************************ + ** + ** @file vpropertyexplorer_global.h + ** @author Roman Telezhynskyi + ** @date 26 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 VPROPERTYEXPLORER_GLOBAL_H +#define VPROPERTYEXPLORER_GLOBAL_H + +#include + +#if defined(VPROPERTYEXPLORER_LIBRARY) +# define VPROPERTYEXPLORERSHARED_EXPORT Q_DECL_EXPORT +#else +# define VPROPERTYEXPLORERSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // VPROPERTYEXPLORER_GLOBAL_H diff --git a/src/libs/vpropertyexplorer/vpropertyfactorymanager.cpp b/src/libs/vpropertyexplorer/vpropertyfactorymanager.cpp new file mode 100644 index 000000000..51bcc73d8 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyfactorymanager.cpp @@ -0,0 +1,109 @@ +#include "vpropertyfactorymanager.h" +#include "vpropertyfactorymanager_p.h" + +#include "vstandardpropertyfactory.h" +#include "vproperty.h" + +using namespace VPE; + + +VPropertyFactoryManager* VPropertyFactoryManager::DefaultManager = NULL; + +VPropertyFactoryManager::VPropertyFactoryManager(QObject *parent) + : QObject(parent), d_ptr(new VPropertyFactoryManagerPrivate()) +{ + +} + +VPropertyFactoryManager::~VPropertyFactoryManager() +{ + // Delete all factories + QList tmpFactories = d_ptr->Factories.values(); + while(!tmpFactories.isEmpty()) { + VAbstractPropertyFactory* tmpFactory = tmpFactories.takeLast(); + tmpFactories.removeAll(tmpFactory); + delete tmpFactory; + } + + + delete d_ptr; + if(this == DefaultManager) + DefaultManager = NULL; +} + +void VPropertyFactoryManager::registerFactory(const QString& type, VAbstractPropertyFactory* factory) +{ + if(type.isEmpty()) + return; + + // Remove old factory + unregisterFactory(getFactory(type), type, true); + // Register new one + d_ptr->Factories[type] = factory; +} + +void VPropertyFactoryManager::unregisterFactory(VAbstractPropertyFactory* factory, const QString& type, bool delete_if_unused) +{ + if(!factory) + return; + + if(!type.isEmpty()) { + // Remove all occurances + QString tmpKey; + do { + tmpKey = d_ptr->Factories.key(factory, QString()); + if(!tmpKey.isEmpty()) d_ptr->Factories.remove(tmpKey); + } while(!tmpKey.isEmpty()); + } else { + // Only remove one type + if(d_ptr->Factories.value(type, NULL) == factory) + d_ptr->Factories.remove(type); + } + + if(delete_if_unused && !isRegistered(factory)) + delete factory; +} + +bool VPropertyFactoryManager::isRegistered(VAbstractPropertyFactory* factory) +{ + return (!d_ptr->Factories.key(factory, QString()).isEmpty()); +} + +VAbstractPropertyFactory* VPropertyFactoryManager::getFactory(const QString& type) +{ + return d_ptr->Factories.value(type, NULL); +} + + +VProperty* VPropertyFactoryManager::createProperty(const QString& type, const QString& name, const QString& description, const QString &default_value) +{ + VAbstractPropertyFactory* tmpFactory = getFactory(type); + VProperty* tmpResult = NULL; + if(tmpFactory) { + tmpResult = tmpFactory->createProperty(type, name); + + if(tmpResult) { + tmpResult->setDescription(description); + + if(!default_value.isEmpty()) + tmpResult->deserialize(default_value); + } + } + + return tmpResult; +} + +VPropertyFactoryManager *VPropertyFactoryManager::getDefaultManager() +{ + if(!DefaultManager) { + DefaultManager = new VPropertyFactoryManager(); + /*VStandardPropertyFactory* tmpStandardProp = */new VStandardPropertyFactory(DefaultManager); + } + + return DefaultManager; +} + +QStringList VPropertyFactoryManager::getSupportedTypes() +{ + return d_ptr->Factories.keys(); +} diff --git a/src/libs/vpropertyexplorer/vpropertyfactorymanager.h b/src/libs/vpropertyexplorer/vpropertyfactorymanager.h new file mode 100644 index 000000000..31450eb33 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyfactorymanager.h @@ -0,0 +1,67 @@ +#ifndef VPROPERTYFACTORYMANAGER_H +#define VPROPERTYFACTORYMANAGER_H + +#include "vpropertyexplorer_global.h" +#include + +namespace VPE { + +class VAbstractPropertyFactory; +class VPropertyFactoryManagerPrivate; +class VProperty; + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyFactoryManager : public QObject +{ + Q_OBJECT +public: + //! Constructor + VPropertyFactoryManager(QObject* parent = nullptr); + + //! Destructor + virtual ~VPropertyFactoryManager(); + + //! Register a factory to the factory manager + //! Note that the manager takes ownership of the factory, so don't delete it. + //! You can unregister a factory using unregisterFactory() + void registerFactory(const QString& type, VAbstractPropertyFactory* factory); + + //! Removes a factory from the manager. + //! \param factory The factory to unregister + //! \param type The type from which to remove the factory. If this is empty, all the types the factory is registered for are being removed + //! \param delete_if_unused Determines whether the factory should be deleted, if it not used anymore by this manager. Default: true. Otherwise, if the factory is unused by this manager, ownership is being passed on. + void unregisterFactory(VAbstractPropertyFactory* factory, const QString& type = QString(), + bool delete_if_unused = true); + + //! Returns whether a factory is registered (and thus owned) by this factory manager + bool isRegistered(VAbstractPropertyFactory* factory); + + //! Returns a pointer to a factory registered for a certain type + //! \param type The type to return the factory for + //! \return Returns NULL, if there is none registered for this type + VAbstractPropertyFactory* getFactory(const QString& type); + + //! Creates a new property of a certain type and assigns a name and description (otionally) + //! \param type The type of the property as string + //! \param name The name of the property + //! \param description The property's description. Optional. + //! \param default_value The properties initial value as string. Optional. + //! \return Returns the created property or NULL if it couldn't be be created + VProperty* createProperty(const QString& type, const QString& name, const QString& description = QString(), + const QString& default_value = QString()); + + //! Returns the default manager. + static VPropertyFactoryManager* getDefaultManager(); + + //! Returns a list of all supported property types + QStringList getSupportedTypes(); + +protected: + VPropertyFactoryManagerPrivate* d_ptr; + + //! The default manager + static VPropertyFactoryManager* DefaultManager; +}; + +} + +#endif // VPROPERTYFACTORYMANAGER_H diff --git a/src/libs/vpropertyexplorer/vpropertyfactorymanager_p.h b/src/libs/vpropertyexplorer/vpropertyfactorymanager_p.h new file mode 100644 index 000000000..ff47fa40d --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyfactorymanager_p.h @@ -0,0 +1,21 @@ +#ifndef VPROPERTYFACTORYMANAGER_P_H +#define VPROPERTYFACTORYMANAGER_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include + +namespace VPE { + +class VAbstractPropertyFactory; + +class VPropertyFactoryManagerPrivate { +public: + QMap Factories; + +}; + +} + +#endif // VPROPERTYFACTORYMANAGER_P_H diff --git a/src/libs/vpropertyexplorer/vpropertyformview.cpp b/src/libs/vpropertyexplorer/vpropertyformview.cpp new file mode 100644 index 000000000..a11061f70 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformview.cpp @@ -0,0 +1,180 @@ +#include "vpropertyformview.h" +#include "vpropertymodel.h" +#include "vpropertyset.h" +#include +#include +#include + +#include "vpropertyformview_p.h" + +using namespace VPE; + +VPropertyFormView::VPropertyFormView(QWidget* parent) + : VPropertyFormWidget(new VPropertyFormViewPrivate(), parent) +{ + // +} + +VPropertyFormView::VPropertyFormView(VPropertyModel* model, QWidget *parent) + : VPropertyFormWidget(new VPropertyFormViewPrivate(), parent) +{ + setModel(model); +} + +VPropertyFormView::VPropertyFormView(VPropertySet* property_set, QWidget *parent) + : VPropertyFormWidget(new VPropertyFormViewPrivate(), parent) +{ + setPropertySet(property_set); +} + +VPropertyFormView::~VPropertyFormView() +{ + // Nothing to do +} + +void VPropertyFormView::build() +{ + VPropertyFormWidget::build(); + + // Go through all sub widgets and connect + connectPropertyFormWidget(this); +} + +void VPropertyFormView::setModel(VPropertyModel *model) +{ + // Remove old model or set + removeModelAndSet(); + + // Set model + static_cast(d_ptr)->Model = model; + if(model) { + // Set the property list + if(model->getPropertySet()) + d_ptr->Properties = model->getPropertySet()->getRootProperties(); + + // Connect signals // todo: more signals neccesary!!! + connect(model, SIGNAL(destroyed()), this, SLOT(modelDestroyed())); + connect(model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(rowsInserted(QModelIndex,int,int))); + connect(model, SIGNAL(modelReset()), this, SLOT(modelReset())); + connect(model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); + } + + // Build the widget + updatePropertyList(); +} + +void VPropertyFormView::setPropertySet(VPropertySet* property_set) +{ + // Remove old model or set + removeModelAndSet(); + + // Set property set + static_cast(d_ptr)->PropertySet = property_set; + if(property_set) { + // Set the property list + d_ptr->Properties = property_set->getRootProperties(); + } + + // Build the widget + updatePropertyList(); +} + +void VPropertyFormView::rowsRemoved(const QModelIndex &parent, int start, int end) +{ + // todo: Only rebuild the neccessary parts + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + updatePropertyList(); +} + +void VPropertyFormView::rowsInserted(const QModelIndex &parent, int start, int end) +{ + // todo: Only rebuild the neccessary parts + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + updatePropertyList(); +} + +void VPropertyFormView::modelReset() +{ + updatePropertyList(); +} + +void VPropertyFormView::modelDestroyed() +{ + removeModelAndSet(); + updatePropertyList(); +} + +void VPropertyFormView::dataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right) +{ + if(static_cast(d_ptr)->IgnoreDataChangedSignal) + return; + // todo: handle data changes +} + +void VPropertyFormView::dataSubmitted(VProperty *property) +{ + VPropertyModel* tmpModel = static_cast(d_ptr)->Model; + + if(tmpModel && d_ptr->UpdateEditors) { + static_cast(d_ptr)->IgnoreDataChangedSignal = true; + //tmpModel->onDataChangedByModel(property); + tmpModel->showDataChangedByEditor(property); + + static_cast(d_ptr)->IgnoreDataChangedSignal = false; + } +} + +void VPropertyFormView::showEvent(QShowEvent *event) +{ + Q_UNUSED(event) + if(static_cast(d_ptr)->NeedsRebuild) + build(); + static_cast(d_ptr)->NeedsRebuild = false; +} + +void VPropertyFormView::updatePropertyList() +{ + VPropertyModel* tmpModel = static_cast(d_ptr)->Model; + VPropertySet* tmpSet = static_cast(d_ptr)->PropertySet; + + if(tmpModel && tmpModel->getPropertySet()) + d_ptr->Properties = tmpModel->getPropertySet()->getRootProperties(); + else if(tmpSet) + d_ptr->Properties = tmpSet->getRootProperties(); + else + d_ptr->Properties.clear(); + + if(isVisible()) + build(); + else + static_cast(d_ptr)->NeedsRebuild = true; +} + +void VPropertyFormView::removeModelAndSet() +{ + if(static_cast(d_ptr)->Model) { + disconnect(static_cast(d_ptr)->Model, 0, this, 0); + static_cast(d_ptr)->Model = nullptr; + } + + static_cast(d_ptr)->NeedsRebuild = true; + d_ptr->Properties.clear(); + static_cast(d_ptr)->PropertySet = nullptr; +} + +void VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget) +{ + if(!widget) + return; + + connect(widget, SIGNAL(propertyDataSubmitted(VProperty*)), this, SLOT(dataSubmitted(VProperty*))); + QList tmpList = widget->getChildPropertyFormWidgets(); + + foreach(VPropertyFormWidget* tmpEditorWidget, tmpList) { + connectPropertyFormWidget(tmpEditorWidget); + } +} diff --git a/src/libs/vpropertyexplorer/vpropertyformview.h b/src/libs/vpropertyexplorer/vpropertyformview.h new file mode 100644 index 000000000..5e679fd39 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformview.h @@ -0,0 +1,81 @@ +#ifndef VPROPERTYFORMVIEW_H +#define VPROPERTYFORMVIEW_H + +#include "vpropertyexplorer_global.h" +#include +#include "vpropertyformwidget.h" + +namespace VPE { + +class VProperty; +class VPropertyModel; +class VPropertySet; + +//! This class populates a form layout with the properties in a model +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyFormView : public VPropertyFormWidget +{ + Q_OBJECT +public: + //! Constructor + explicit VPropertyFormView(QWidget *parent = 0); + + //! Constructor + explicit VPropertyFormView(VPropertyModel* model, QWidget *parent = 0); + + //! Constructor + explicit VPropertyFormView(VPropertySet* property_set, QWidget *parent = 0); + + //! Destructor + virtual ~VPropertyFormView(); + + +public slots: + //! Rebuilds the whole form + virtual void build(); + + //! Set the source model. Leads to the rebuild of the form + //! \param model The model to use + void setModel(VPropertyModel* model); + + //! Set the property set to use. Note that if using a property set directly, adding and removing properties to the property set leads to undifined behaviour for the property set misses notification signals. + //! \param model The property set to use + void setPropertySet(VPropertySet* property_set); + + //! Called when a row gets removed in the model + void rowsRemoved(const QModelIndex& parent, int start, int end); + + //! Called when a new row is being inserted into the model + void rowsInserted(const QModelIndex& parent, int start, int end); + + //! Called when the model is being reset + void modelReset(); + + +private slots: + //! Called, when the model gets destroyed + void modelDestroyed(); + + //! Called when data in the model gets changed + void dataChanged(const QModelIndex& top_left, const QModelIndex& bottom_right); + + //! Updates the model when data was submitted by the view + void dataSubmitted(VProperty* property); + +protected: + void showEvent(QShowEvent* event); + + //! Rebuilds the widegt only if it is visible + void updatePropertyList(); + + //! Removes the model and property set if they were set + void removeModelAndSet(); + + //! Function to handle newly created VPropertyWidgets + virtual void connectPropertyFormWidget(VPropertyFormWidget* widget); + + +}; + +} // Namespace VPE + +#endif // VPROPERTYFORMVIEW_H diff --git a/src/libs/vpropertyexplorer/vpropertyformview_p.h b/src/libs/vpropertyexplorer/vpropertyformview_p.h new file mode 100644 index 000000000..c34ddcba5 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformview_p.h @@ -0,0 +1,40 @@ +#ifndef VPROPERTYFORMVIEW_P_H +#define VPROPERTYFORMVIEW_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include "vpropertyformwidget_p.h" + +namespace VPE { + +class VPropertyModel; +class VPropertySet; + +class VPropertyFormViewPrivate : public VPropertyFormWidgetPrivate +{ +public: + //! The current property model + VPropertyModel* Model; + + //! The currently used property set + VPropertySet* PropertySet; + + //! Determines whether the widget needs to be rebuild + bool NeedsRebuild; + + //! Helper variable + bool IgnoreDataChangedSignal; + + VPropertyFormViewPrivate() + : VPropertyFormWidgetPrivate(), Model(NULL), PropertySet(NULL), NeedsRebuild(false) {} + + VPropertyFormViewPrivate(VPropertyModel* prop_model) + : VPropertyFormWidgetPrivate(), Model(prop_model), PropertySet(NULL), NeedsRebuild(false) {} + + VPropertyFormViewPrivate(VPropertySet* prop_set) + : VPropertyFormWidgetPrivate(), Model(NULL), PropertySet(prop_set), NeedsRebuild(false) {} +}; + +} + +#endif // VPROPERTYFORMVIEW_P_H diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp new file mode 100644 index 000000000..45b35f33e --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp @@ -0,0 +1,223 @@ +#include "vpropertyformwidget.h" + +#include +#include "vpropertyformwidget_p.h" + +#include "plugins/vwidgetproperty.h" +#include +#include +#include "vproperty.h" + +using namespace VPE; + +VPropertyFormWidget::VPropertyFormWidget(const QString &title, const QString &description, const QList& properties, QWidget *parent) + : QGroupBox(title, parent), d_ptr(new VPropertyFormWidgetPrivate(properties)) +{ + build(); + setToolTip(description); + setWhatsThis(description); +} + +VPropertyFormWidget::VPropertyFormWidget(VProperty *parent_property, QWidget *parent) + : QGroupBox(parent), d_ptr(new VPropertyFormWidgetPrivate()) +{ + if(parent_property) { + d_ptr->Properties = parent_property->getChildren(); + build(); + setTitle(parent_property->getName()); + setToolTip(parent_property->getDescription()); + setWhatsThis(parent_property->getDescription()); + } +} + +VPropertyFormWidget::VPropertyFormWidget(VPropertyFormWidgetPrivate *d_pointer, QWidget *parent, const QString &title, const QString &description) + : QGroupBox(title, parent), d_ptr(d_pointer) +{ + build(); + setToolTip(description); + setWhatsThis(description); +} + +VPropertyFormWidget::~VPropertyFormWidget() +{ + delete d_ptr; +} + + +void VPropertyFormWidget::build() +{ + // Clear the old content, delete old widgets + d_ptr->EditorWidgets.clear(); + if(layout()) { + QLayoutItem *child; + while (layout()->count() > 0 && (child = layout()->takeAt(0)) != 0) { + if(child->widget()) + delete child->widget(); + delete child; + } + delete layout(); + } + + // Create new content + if(d_ptr->Properties.isEmpty()) return; //... only if there are properties + + QFormLayout* tmpFormLayout = new QFormLayout(this); + setLayout(tmpFormLayout); + + for(int i = 0; i < d_ptr->Properties.count(); ++i) { + // Get the current property + VProperty* tmpProperty = d_ptr->Properties.value(i, nullptr); + if(!tmpProperty) continue; + + if(tmpProperty->getRowCount() > 0) { + // Child properties, the property itself is not being added + VPropertyFormWidget* tmpNewFormWidget = new VPropertyFormWidget(tmpProperty, this); + tmpFormLayout->addRow(tmpNewFormWidget); + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpNewFormWidget)); + tmpNewFormWidget->setCommitBehaviour(d_ptr->UpdateEditors); + } else if(tmpProperty->type() == "widget") { + VWidgetProperty* tmpWidgetProperty = static_cast(tmpProperty); + tmpFormLayout->addRow(tmpWidgetProperty->getWidget()); + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpWidgetProperty->getWidget())); + } else { + // Add property (no child properties) + // Create the editor (if it doesn't work, create empty widget) + QWidget* tmpEditor = tmpProperty->createEditor(this, QStyleOptionViewItem(), nullptr); + if(!tmpEditor) + tmpEditor = new QWidget(this); + + // set tooltip and whats this + tmpEditor->setToolTip(tmpProperty->getDescription()); + tmpEditor->setWhatsThis(tmpProperty->getDescription()); + + // Install event filter + tmpEditor->installEventFilter(this); + + // Set the editor data + tmpProperty->setEditorData(tmpEditor); + + // add new row + tmpFormLayout->addRow(tmpProperty->getName(), tmpEditor); + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpEditor)); + } + } +} + +void VPropertyFormWidget::commitData() +{ + for(int i = 0; i < d_ptr->Properties.count(); ++i) + commitData(i); +} + +void VPropertyFormWidget::loadData() +{ + for(int i = 0; i < d_ptr->Properties.count(); ++i) + loadData(i); +} + +void VPropertyFormWidget::commitData(int row) +{ + if(row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count()) return; + + VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[row]; + VProperty* tmpProperty = d_ptr->Properties[row]; + if(tmpEditorWidget.FormWidget) + tmpEditorWidget.FormWidget->commitData(); + else if(tmpEditorWidget.Editor && tmpProperty) { + QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor); + QVariant oldValue = tmpProperty->data(VProperty::DPC_Data); + if (oldValue != newValue) + { + tmpProperty->setValue(tmpProperty->getEditorData(tmpEditorWidget.Editor)); + emit propertyDataSubmitted(tmpProperty); + } + } +} + +void VPropertyFormWidget::loadData(int row) +{ + if(row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count()) return; + + VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[row]; + VProperty* tmpProperty = d_ptr->Properties[row]; + if(tmpEditorWidget.FormWidget) + tmpEditorWidget.FormWidget->loadData(); + else if(tmpEditorWidget.Editor && tmpProperty) { + tmpProperty->setEditorData(tmpEditorWidget.Editor); + } +} + +void VPropertyFormWidget::setCommitBehaviour(bool auto_commit) +{ + d_ptr->UpdateEditors = auto_commit; + + QList tmpChildFormWidgets = getChildPropertyFormWidgets(); + foreach(VPropertyFormWidget* tmpChild, tmpChildFormWidgets) { + if(tmpChild) + tmpChild->setCommitBehaviour(auto_commit); + } +} + +QList VPropertyFormWidget::getChildPropertyFormWidgets() const +{ + QList tmpResult; + foreach(const VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget, d_ptr->EditorWidgets) { + if(tmpEditorWidget.FormWidget) + tmpResult.append(tmpEditorWidget.FormWidget); + } + + return tmpResult; +} + +bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event) +{ + if(!d_ptr->UpdateEditors) + return false; + + QWidget* editor = qobject_cast(object); + if (!editor) + return false; + + if (event->type() == QEvent::KeyPress) { + switch (static_cast(event)->key()) { + case Qt::Key_Tab: + case Qt::Key_Backtab: + case Qt::Key_Enter: + case Qt::Key_Return: + case Qt::Key_Escape: + commitData(editor); + event->accept(); + return true; + default: + return false; + } + } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) { + commitData(editor); + return false; + } else if (event->type() == QEvent::ShortcutOverride) { + if (static_cast(event)->key() == Qt::Key_Escape) { + commitData(editor); + event->accept(); + return true; + } + } else if (event->type() == MyCustomEventType) { + commitData(editor); + event->accept(); + return true; + } + + // Default: + return false; +} + +void VPropertyFormWidget::commitData(QWidget *editor) +{ + if(!editor) + return; + + for(int i = 0; i < d_ptr->EditorWidgets.count(); ++i) { + VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[i]; + if(tmpEditorWidget.Editor == editor) + commitData(i); + } +} diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.h b/src/libs/vpropertyexplorer/vpropertyformwidget.h new file mode 100644 index 000000000..4cc3f0ad9 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.h @@ -0,0 +1,73 @@ +#ifndef VPROPERTYFORMWIDGET_H +#define VPROPERTYFORMWIDGET_H + +#include +#include +#include "vproperty.h" + +namespace VPE { + +class VPropertyFormWidgetPrivate; +class VPropertySet; + +//! Class that displays the sub properties of a property using a form layout +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyFormWidget : public QGroupBox +{ + Q_OBJECT +public: + //! Constructor + VPropertyFormWidget(const QString& title, const QString& description, const QList& properties, QWidget* parent); + + //! Constructor + VPropertyFormWidget(VProperty* parent_property, QWidget* parent); + + //! Destructor + ~VPropertyFormWidget(); + + + //! Returns a list of all child property form widgets (note that indirect children will not be in the list) + QList getChildPropertyFormWidgets() const; + +public slots: + //! Rebuilds the whole form + virtual void build(); + + //! Reads the data from the editors and commits it to the properties + void commitData(); + + //! Refills the editors with the propertie's data + void loadData(); + + //! Reads the data from row'th editor and commits it to the property + void commitData(int row); + + //! Reads the data from row'th property + void loadData(int row); + + //! Sets the update behaviour + //! \param auto_commit If set to true, whenever an event like focusOut is triggered on an editor, the data will be submitted to the property. + void setCommitBehaviour(bool auto_commit = true); + +signals: + //! Emitted whenever a property data changes + void propertyDataSubmitted(VProperty* property); + +protected: + //! Protected Constructor + VPropertyFormWidget(VPropertyFormWidgetPrivate* d_pointer, QWidget* parent, const QString &title = QString(), + const QString &description = QString()); + + //! The protected data + VPropertyFormWidgetPrivate* d_ptr; + + //! Event filter for the editor widgets + bool eventFilter(QObject *object, QEvent *event); + + //! Commits data of an editor + void commitData(QWidget* editor); + +}; + +} // Namespace VPE + +#endif // VPROPERTYFORMWIDGET_H diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget_p.h b/src/libs/vpropertyexplorer/vpropertyformwidget_p.h new file mode 100644 index 000000000..e1cdc6589 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformwidget_p.h @@ -0,0 +1,44 @@ +#ifndef VPROPERTYFORMWIDGET_P_H +#define VPROPERTYFORMWIDGET_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include "vproperty.h" + +namespace VPE { + +class VPropertyFormWidgetPrivate { +public: + //! Stores either another VPropertyFormWidget (then Editor is null) or an editor widget (then FormWidget is null) + struct SEditorWidget { + SEditorWidget() : FormWidget(nullptr), Editor(nullptr) {} + SEditorWidget(VPropertyFormWidget* form_widget) : FormWidget(form_widget), Editor(nullptr) {} + SEditorWidget(QWidget* editor_widget) : FormWidget(nullptr), Editor(editor_widget) {} + + VPropertyFormWidget* FormWidget; + QWidget* Editor; + }; + + //! The root property to use + QList Properties; + + //! Binds the properties to their editors + QList EditorWidgets; + + //! Determines the behaviour of the editors. If this is true, when a focus out event etc. happens, the data will be submitted to the VProperty. If false, you will have to call commitData() yourself. + bool UpdateEditors; + + //! Default constructor + VPropertyFormWidgetPrivate() + : UpdateEditors(true) + {} + + //! Constructor + VPropertyFormWidgetPrivate(const QList& properties) + : Properties(properties), UpdateEditors(true) {} +}; + +} + +#endif // VPROPERTYFORMWIDGET_P_H diff --git a/src/libs/vpropertyexplorer/vpropertymodel.cpp b/src/libs/vpropertyexplorer/vpropertymodel.cpp new file mode 100644 index 000000000..368689200 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertymodel.cpp @@ -0,0 +1,290 @@ +#include "vpropertymodel.h" + +#include +#include "vpropertyset.h" + +using namespace VPE; + +#include "vpropertymodel_p.h" + +VPropertyModel::VPropertyModel(VPropertyModelPrivate *d, QObject *parent) + : QAbstractItemModel(parent), d_ptr(d) +{ +} + + +VPropertyModel::VPropertyModel(QObject * parent) : + QAbstractItemModel(parent), d_ptr(new VPropertyModelPrivate()) +{ +} + +VPropertyModel::~VPropertyModel() +{ + if(d_ptr->Properties) + delete d_ptr->Properties; + + delete d_ptr; +} + +//! Adds the property to the model and attaches it to the parentid +bool VPropertyModel::addProperty(VProperty* property, const QString& id, const QString &parentid, bool emitsignals) +{ + if(!property) + return false; + + if(!d_ptr->Properties) // If not existant, create property set + d_ptr->Properties = new VPropertySet(); + + if(emitsignals) { + VProperty* tmpParent = getProperty(parentid); + int tmpRow = tmpParent != nullptr ? tmpParent->getRowCount() : d_ptr->Properties->getRootPropertyCount(); + beginInsertRows((tmpParent != nullptr ? getIndexFromProperty(tmpParent) : QModelIndex()), tmpRow, tmpRow); + } + + d_ptr->Properties->addProperty(property, id, parentid); + + if(emitsignals) + endInsertRows(); + + return true; + +} + +//! Creates a property and adds it to the model +VProperty* VPropertyModel::createProperty(const QString& id, const QString& name, const QString& parentid, const QVariant& data) +{ + VProperty* tmpProp = new VProperty(name); + tmpProp->setValue(data); + if(tmpProp && addProperty(tmpProp, id, parentid)) + return tmpProp; + else + return nullptr; +} + +//! Gets a property by it's ID +VProperty* VPropertyModel::getProperty(const QString& id) +{ + return d_ptr->Properties != nullptr ? d_ptr->Properties->getProperty(id) : nullptr; +} + + + +//! Returns the model index at row/column +QModelIndex VPropertyModel::index(int row, int column, const QModelIndex& parent) const +{ + if (d_ptr->Properties == nullptr || (parent.isValid() && parent.column() > 1)) + return QModelIndex(); + + if(parent.isValid()) { + // Get the parent index + VProperty* parentItem = getProperty(parent); + if(parentItem) { + VProperty* childItem = parentItem->getChild(row); + if (childItem) + return createIndex(row, column, childItem); + } + } else if(row >= 0 && row < d_ptr->Properties->count()) { + return createIndex(row, column, d_ptr->Properties->getRootProperty(row)); + } + + return QModelIndex(); +} + +//! Returns the parent of one model index +QModelIndex VPropertyModel::parent ( const QModelIndex & index ) const +{ + if (!index.isValid()) + return QModelIndex(); + + VProperty* childItem = getProperty(index); + if(childItem) { + VProperty* parentItem = childItem->getParent(); + if(parentItem) { + VProperty* grandParentItem = parentItem->getParent(); + int parents_row = grandParentItem != nullptr ? grandParentItem->getChildRow(parentItem) : d_ptr->Properties->getRootProperties().indexOf(parentItem); + + if(parents_row >= 0) + return createIndex(parents_row, 0, parentItem); + } + } + + return QModelIndex(); +} + +//! Returns the item flags for the given index +Qt::ItemFlags VPropertyModel::flags (const QModelIndex& index) const +{ + VProperty* tmpProperty = getProperty(index); + if(!tmpProperty) + return Qt::NoItemFlags; + else + return tmpProperty->flags(index.column()); +} + +//! Sets the role data for the item at index to value +bool VPropertyModel::setData (const QModelIndex& index, const QVariant& value, int role) +{ + VProperty* tmpProperty = getProperty(index); + if(index.column() == 1 && tmpProperty) { + bool tmpHasChanged = tmpProperty->setData(value, role); + if(tmpProperty->getUpdateParent() && tmpHasChanged) { // If neccessary, update the parent as well + QModelIndex tmpParentIndex = parent(index); + emit dataChanged(tmpParentIndex, tmpParentIndex); + } + + if(tmpHasChanged) + emit onDataChangedByEditor(tmpProperty); + } + + + return true; +} + + +//! Returns the data of an model index +QVariant VPropertyModel::data ( const QModelIndex & index, int role ) const +{ + VProperty* tmpProperty = getProperty(index); + if(!tmpProperty) + return QVariant(); + else + return tmpProperty->data(index.column(), role); +} + + +QVariant VPropertyModel::headerData (int section, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal && role == Qt::DisplayRole) { + // Header data + if (section == 0) return d_ptr->HeadlineProperty; + else if (section == 1) return d_ptr->HeadlineValue; + } + else if(role == Qt::DisplayRole) + return QVariant(section); + + return QVariant(); +} + + +//! Returns the number of rows +int VPropertyModel::rowCount ( const QModelIndex & parent ) const +{ + if(parent.isValid()) { + VProperty* tmpParent = getProperty(parent); + if(tmpParent) + return tmpParent->getRowCount(); + } + + // Return the root property count + if(d_ptr->Properties) + return d_ptr->Properties->getRootPropertyCount(); + + return 0; +} + + +//! Returns the number of columns +int VPropertyModel::columnCount ( const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return 2; +} + + +//! Gets a property by its ModelIndex +VProperty* VPropertyModel::getProperty(const QModelIndex &index) const +{ + if (index.isValid()) { + VProperty* prop = static_cast(index.internalPointer()); + + if (prop) + return prop; + } + return nullptr; +} + +QString VPropertyModel::getPropertyID(VProperty *prop) const +{ + return d_ptr->Properties != nullptr ? d_ptr->Properties->getPropertyID(prop) : QString(); +} + +QModelIndex VPropertyModel::getIndexFromProperty(VProperty* property, int column) const +{ + if (!property || column > columnCount() || column < 0) + return QModelIndex(); + + VProperty* parentItem = property->getParent(); + int row = 0; + + if(parentItem) { + row = parentItem->getChildRow(property); + } + + return createIndex(row, column, property); +} + + +void VPropertyModel::onDataChangedByModel(VProperty* property) +{ + QModelIndex tmpIndex = getIndexFromProperty(property, 1); + if(tmpIndex.isValid()) + { + emit dataChanged(tmpIndex, tmpIndex); + } +} + +void VPropertyModel::showDataChangedByEditor(VProperty *property) +{ + emit onDataChangedByEditor(property); +} + +const VPropertySet *VPropertyModel::getPropertySet() const +{ + return d_ptr->Properties; +} + +void VPropertyModel::clear(bool emit_signals) +{ + setPropertySet(nullptr, emit_signals); +} + +VPropertySet *VPropertyModel::takePropertySet(VPropertySet *new_property_set, bool emit_signals) +{ + VPropertySet* tmpOldPropertySet = d_ptr->Properties; + + if(emit_signals) emit beginResetModel(); + d_ptr->Properties = new_property_set; + if(emit_signals) emit endResetModel(); + + return tmpOldPropertySet; +} + +void VPropertyModel::setPropertySet(VPropertySet *property_set, bool emit_signals) +{ + VPropertySet* tmpOldPropertySet = takePropertySet(property_set, emit_signals); + if(tmpOldPropertySet) + delete tmpOldPropertySet; +} + +VProperty *VPropertyModel::takeProperty(const QString &id) +{ + QModelIndex tmpIndex = getIndexFromProperty(getProperty(id)); + if(d_ptr->Properties && tmpIndex.isValid()) { + beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row()); + VProperty* tmpProp = d_ptr->Properties->takeProperty(id); + endRemoveRows(); + return tmpProp; + } + + return nullptr; +} + +void VPropertyModel::removeProperty(const QString &id) +{ + QModelIndex tmpIndex = getIndexFromProperty(getProperty(id)); + if(d_ptr->Properties && tmpIndex.isValid()) { + beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row()); + d_ptr->Properties->removeProperty(id); + endRemoveRows(); + } +} diff --git a/src/libs/vpropertyexplorer/vpropertymodel.h b/src/libs/vpropertyexplorer/vpropertymodel.h new file mode 100644 index 000000000..59de7b4a6 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertymodel.h @@ -0,0 +1,142 @@ +#ifndef VPROPERTYMODEL_H +#define VPROPERTYMODEL_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include + +#include "vproperty.h" + +namespace VPE { + +class VPropertyModelPrivate; +class VPropertySet; + +//! \brief This is the base model for managing all the properties +//! and passing them to the view. +//! +//! When you create your own "proxy models", this is the place to +//! start: just subclass VPropertyModel and extend the new class. +//! Have a look at existing examples of proxies. +//! +//! Note that in this context, the term "proxy model" does not refer +//! to VProxyModel as that is another concept. +//! The idea behind "proxy models" in the QtPropertyExplorer framework +//! is to provide an convenient interface which takes data as your +//! application (or a third-party-library) provides it, and converts this +//! data to VProperty-objects, manage them and produce output for the views. +//! +//! In most cases, you will not need to rewrite the basic functions of +//! QAbstractItemModel, as VPropertyModel provides standard implementations +//! to work with. Thus, instead of subclassing VPropertyModel, it is also +//! possible to use VPropertyModel directly (as it is not an abstract class). +//! This might be more convenient in some cases. +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit VPropertyModel(QObject * parent = 0); + virtual ~VPropertyModel(); + + //! Adds the property to the model and attaches it to the parentid + //! \param emitsignals If this is set to false, this function will not call beginInsertRows() and endInsertRows(), so it has to be called from a subclass + virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid = QString(), + bool emitsignals = true); + + //! Creates a property and adds it to the model + virtual VProperty* createProperty(const QString& id, const QString& name, const QString& parentid = QString(), + const QVariant& data = QVariant()); + + //! Gets a property by it's ID + virtual VProperty* getProperty(const QString& id); + + //! Returns the item flags for the given index + virtual Qt::ItemFlags flags (const QModelIndex& index) const; + + //! Sets the role data for the item at index to value + virtual bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + + //! Returns the model index at row/column + virtual QModelIndex index (int row, int column, const QModelIndex & parent = QModelIndex() ) const; + + //! Returns the parent of one model index + virtual QModelIndex parent (const QModelIndex& index) const; + + //! Returns the data of an model index + virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; + + //! Returns the data for the given role and section in the header with the specified orientation. + virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + //! Returns the number of rows + virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const; + + //! Returns the number of columns + virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const; + + + + //! Gets a property by its ModelIndex + //! \param index The modelIndex of the property. + //! \return Returns the property with the given index, or NULL if none such property exists + virtual VProperty* getProperty(const QModelIndex &index) const; + + //! Returns the ID of the property within the model + //! The concept of property IDs is, that the object that manages the properties + //! and not the properties themselves handle the IDs. + //! \param property + //! \return Returns the ID under which the property is stored within the model + virtual QString getPropertyID(VProperty* prop) const; + + //! Returns a const pointer to the property set managed by this model. If you want to manipulate the property set, either use the methods provided by the model or use takePropertySet() and setPropertySet(). + //! \return A constant pointer to the property set or NULL if there currently is none. + virtual const VPropertySet* getPropertySet() const; + + //! Clears the model, deletes the property set managed by this model. + //! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals + virtual void clear(bool emit_signals = true); + + //! Removes the current property set and returns it. If new_property_set is set, the old one will be replaced by the new one + //! \param new_property_set The new property set to replace the old one with. Default: NULL + //! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals + //! \return A constant pointer to the property set or NULL if there currently is none. + virtual VPropertySet* takePropertySet(VPropertySet* new_property_set = nullptr, bool emit_signals = true); + + //! Sets a new property set. The model will take ownership of the property set. The old property set will be deleted. + //! \param property_set The new property set. Setting this to NULL has the same effect as calling clear. + //! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals + //! \return A constant pointer to the property set or NULL if there currently is none. + virtual void setPropertySet(VPropertySet* property_set, bool emit_signals = true); + + //! Removes a property from the model and returns it + virtual VProperty* takeProperty(const QString& id); + + //! Removes a property from the model and deletes it + virtual void removeProperty(const QString& id); + +signals: + //! This signal is being emitted, when the setData method is being called + void onDataChangedByEditor(VProperty* property); + +public slots: + //! This function causes the views to update the property + void onDataChangedByModel(VProperty* property); + + void showDataChangedByEditor(VProperty* property); + +protected: + //! Gets a property by its ModelIndex + virtual QModelIndex getIndexFromProperty(VProperty* property, int column = 0) const; + + //! Protected constructor passing the private object + VPropertyModel(VPropertyModelPrivate* d, QObject* parent = 0); + + //! The model data + VPropertyModelPrivate* d_ptr; +}; + +} + +#endif // VPROPERTYMODEL_H diff --git a/src/libs/vpropertyexplorer/vpropertymodel_p.h b/src/libs/vpropertyexplorer/vpropertymodel_p.h new file mode 100644 index 000000000..9109a3e90 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertymodel_p.h @@ -0,0 +1,40 @@ +#ifndef VPROPERTYMODEL_P_H +#define VPROPERTYMODEL_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include +#include + +namespace VPE { + +class VProperty; +class VPropertySet; + +class VPropertyModelPrivate { +public: + //! The property set holding the properties + VPropertySet* Properties; + + //! The header data for the property name column + QString HeadlineProperty; + + //! The header data for the value column + QString HeadlineValue; + + //! Constructor + VPropertyModelPrivate() + : Properties(nullptr) + { + //: The text that appears in the first column header + HeadlineProperty = QObject::tr("Property"); + + //: The text that appears in the second column header + HeadlineValue = QObject::tr("Value"); + } +}; + +} + +#endif // VPROPERTYMODEL_P_H diff --git a/src/libs/vpropertyexplorer/vpropertyset.cpp b/src/libs/vpropertyexplorer/vpropertyset.cpp new file mode 100644 index 000000000..7be540da8 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyset.cpp @@ -0,0 +1,211 @@ +#include "vpropertyset.h" +using namespace VPE; + +#include "vpropertyset_p.h" + + +VPropertySet::VPropertySet() + : d_ptr(new VPropertySetPrivate()) +{ +} + + +VPropertySet::~VPropertySet() +{ + // Delete all the properties + clear(true); + + delete d_ptr; +} + +bool VPropertySet::addProperty(VProperty *property, const QString &id, const QString &parentid) +{ + // Check if the property to add is not a null pointer + if(!property) + return false; + + VProperty* tmpParent = parentid.isEmpty() ? NULL : getProperty(parentid); + return addProperty(property, id, tmpParent); +} + +bool VPropertySet::addProperty(VProperty *property, const QString &id, VProperty *parent_property) +{ + // Check if the property to add is not a null pointer + if(!property) + return false; + + QString tmpOldID = getPropertyID(property); + if(!tmpOldID.isEmpty()) + d_ptr->Properties.remove(tmpOldID); + + if(parent_property) + parent_property->addChild(property); + else { + d_ptr->RootProperties.append(property); + if(property->getParent()) + property->getParent()->removeChild(property); + } + + if(!id.isEmpty()) + d_ptr->Properties.insert(id, property); + + return true; +} + +bool VPropertySet::hasProperty(VProperty *property) const +{ + if(!property) + return false; + + return hasProperty(property, NULL); +} + +VProperty *VPropertySet::getProperty(const QString &id) const +{ + return d_ptr->Properties.value(id, NULL); +} + +VProperty *VPropertySet::takeProperty(const QString &id) +{ + VProperty* tmpProp = getProperty(id); + removeProperty(tmpProp, false); + + // Return the property + return tmpProp; +} + +void VPropertySet::removeProperty(const QString &id) +{ + VProperty* tmpProp = takeProperty(id); + if(tmpProp) + delete tmpProp; +} + +void VPropertySet::removeProperty(VProperty* prop, bool delete_property) +{ + // Remove all the children + removePropertyFromSet(prop); + + // Remove from parent and optionally delete + if(prop) { + prop->setParent(NULL); + + if(delete_property) + delete prop; + } +} + +int VPropertySet::count() const +{ + return d_ptr->Properties.count(); +} + +void VPropertySet::clear(bool delete_properties) +{ + d_ptr->Properties.clear(); + while(!d_ptr->RootProperties.isEmpty()) { + VProperty* tmpProp = d_ptr->RootProperties.takeLast(); + if(tmpProp != NULL && delete_properties) { + delete tmpProp; + } + } +} + +QString VPropertySet::getPropertyID(const VProperty *prop, bool look_for_parent_id) const +{ + QString tmpResult; + const VProperty* tmpCurrentProp = prop; + + while(tmpCurrentProp && (look_for_parent_id || prop == tmpCurrentProp) && tmpResult.isEmpty()) { + + // todo: The following code doesn't work, because .key() doesn't accept a const VProperty* pointer ... + //tmpResult = d_ptr->Properties.key(tmpCurrentProp, QString()); + + // ... which is why we need the code below + for (QMap::const_iterator i = d_ptr->Properties.constBegin(); i != d_ptr->Properties.constEnd(); ++i) { + if(tmpCurrentProp == (*i)) + return i.key(); + } + + tmpCurrentProp = tmpCurrentProp->getParent(); + } + + return tmpResult; +} + +const QMap &VPropertySet::getPropertiesMap() const +{ + return d_ptr->Properties; +} + +const QList &VPropertySet::getRootProperties() const +{ + return d_ptr->RootProperties; +} + +VProperty *VPropertySet::getRootProperty(int row) const +{ + return d_ptr->RootProperties.value(row, NULL); +} + +int VPropertySet::getRootPropertyCount() const +{ + return d_ptr->RootProperties.count(); +} + +VPropertySet* VPropertySet::clone() const +{ + VPropertySet* tmpResult = new VPropertySet(); + + foreach(VProperty* tmpProperty, d_ptr->RootProperties) + cloneProperty(tmpProperty, NULL, tmpResult); + + + return tmpResult; +} + + + +bool VPropertySet::hasProperty(VProperty *property, VProperty *parent) const +{ + if(!property) + return false; + + const QList& tmpChildrenList = (parent != NULL ? parent->getChildren() : d_ptr->RootProperties); + foreach(VProperty* tmpProp, tmpChildrenList) { + if(!tmpProp) + continue; + else if(tmpProp == property || hasProperty(property, tmpProp)) + return true; + } + + return false; +} + +void VPropertySet::cloneProperty(VProperty* property_to_clone, VProperty *parent_property, VPropertySet *output_set) const +{ + if(!output_set || !property_to_clone || !hasProperty(property_to_clone)) + return; + + QString tmpID = getPropertyID(property_to_clone, false); + VProperty* tmpNewProperty = property_to_clone->clone(false); // We want to clone the children ourselves (because of the IDs) + + output_set->addProperty(tmpNewProperty, tmpID, parent_property); + for(int i = 0; i < property_to_clone->getRowCount(); ++i) + cloneProperty(property_to_clone->getChild(i), tmpNewProperty, output_set); +} + +void VPropertySet::removePropertyFromSet(VProperty *prop) +{ + // Remove all the children + foreach(VProperty* tmpChild, prop->getChildren()) + removeProperty(tmpChild); + + + QList tmpKeys = d_ptr->Properties.keys(prop); + foreach(const QString& tmpID, tmpKeys) + d_ptr->Properties.remove(tmpID); + + // Remove from list + d_ptr->RootProperties.removeAll(prop); +} diff --git a/src/libs/vpropertyexplorer/vpropertyset.h b/src/libs/vpropertyexplorer/vpropertyset.h new file mode 100644 index 000000000..1a7ff9ca0 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyset.h @@ -0,0 +1,111 @@ +#ifndef VPROPERTYSET_H +#define VPROPERTYSET_H + +#include "vpropertyexplorer_global.h" + +#include +#include + +#include "vproperty.h" + +namespace VPE { + +// Forward declaration +class VPropertySetPrivate; + +// todo: better description +//! \brief VPropertySet is a simple class for managing a set of properties. +//! If you don't need all the Model-functionality, chose this class +//! over VPropertyModel. +//! + +//! +class VPROPERTYEXPLORERSHARED_EXPORT VPropertySet +{ +public: + //! Default constructor, creating an empty property set + explicit VPropertySet(); + + //! Destructor + virtual ~VPropertySet(); + + //! Adds the property to the model and attaches it to the parentid. Note that if the property has a parent which is not part of this set, it will be removed from that parent. + //! \param property The property to add + //! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added. If the property was filed under another ID before, that will no longer be valid. + //! \param parentid The property's ID to which to add the property as child. Pass empty string to add it to the root properties. + virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid); + + //! Adds the property to the model and attaches it to the parent property. + //! \param property The property to add + //! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added. If the property was filed under another ID before, that will no longer be valid. + //! \param parentid The property to which to add the property as child. Pass NULL to add it to the root properties. + virtual bool addProperty(VProperty* property, const QString& id, VProperty* parent_property = nullptr); + + //! Checks whether a property belongs to this set and returns the result + //! \param property The property to check for + //! \return True, if the property is part of this set, false otherwise + virtual bool hasProperty(VProperty* property) const; + + //! Gets a property by it's ID + virtual VProperty* getProperty(const QString& id) const; + + //! Removes a property from the set and returns it + virtual VProperty* takeProperty(const QString& id); + + //! Removes a property from the set and deletes it + virtual void removeProperty(const QString& id); + + //! Removes a property from the set and deletes it optionally + virtual void removeProperty(VProperty* prop, bool delete_property = true); + + //! Returns the number of properties with in ID that are directly accessable by getProperty() + virtual int count() const; + + //! Clears the set and (optionally) deletes all properties + //! \param delete_properties Set this to false, if you don't want the properties to get deleted. + virtual void clear(bool delete_properties = true); + + //! Returns the ID of the property within the set + //! The concept of property IDs is, that the object that manages the properties + //! and not the properties themselves handle the IDs. + //! \param prop The property of which to get the ID. + //! \param look_for_parent_id If this is TRUE and the property has no ID, all the parent properties are checked. + //! \return Returns the ID under which the property is stored within the set + virtual QString getPropertyID(const VProperty* prop, bool look_for_parent_id = true) const; + + //! Returns a const reference to the map of properties + const QMap& getPropertiesMap() const; + + //! Returns a const reference to the list of root properties + const QList& getRootProperties() const; + + //! Returns the root property in a certain row + //! \param row The root row in which to look for the root property + VProperty* getRootProperty(int row) const; + + //! Returns the number of independent properties + int getRootPropertyCount() const; + + //! Clones the property set + VPropertySet* clone() const; + +protected: + //! Checks whether a property belongs to this set and returns the result + //! \param property The property to check for + //! \param parent The parent property from which to start checking all the children + //! \return True, if the property is part of this set, false otherwise + virtual bool hasProperty(VProperty* property, VProperty* parent) const; + + //! Clones a property into another property set + void cloneProperty(VProperty* property_to_clone, VProperty* parent_property, VPropertySet* output_set) const; + + //! Recursivly removes a property's child properties from the set, but not from the parent + virtual void removePropertyFromSet(VProperty* prop); + + //! The data + VPropertySetPrivate* d_ptr; +}; + +} + +#endif // VPROPERTYMODEL_H diff --git a/src/libs/vpropertyexplorer/vpropertyset_p.h b/src/libs/vpropertyexplorer/vpropertyset_p.h new file mode 100644 index 000000000..b4750abe2 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyset_p.h @@ -0,0 +1,29 @@ +#ifndef VPROPERTYSET_P_H +#define VPROPERTYSET_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include + +namespace VPE { + +class VProperty; + +class VPropertySetPrivate { +public: + //! Property map (ID, Property) + QMap Properties; // All the Properties managed by this model are being stored in this map for quick access + + //! List containing the root properties + QList RootProperties; + + //! Constructor + VPropertySetPrivate() + { + } +}; + +} + +#endif // VPROPERTYMODEL_P_H diff --git a/src/libs/vpropertyexplorer/vpropertytreeview.cpp b/src/libs/vpropertyexplorer/vpropertytreeview.cpp new file mode 100644 index 000000000..7f36602ef --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertytreeview.cpp @@ -0,0 +1,57 @@ +#include "vpropertytreeview.h" + +#include "vpropertydelegate.h" +#include "vpropertymodel.h" + +#include "vpropertytreeview_p.h" + +using namespace VPE; + +VPropertyTreeView::VPropertyTreeView(QWidget *parent) + : QTreeView(parent), d_ptr(new VPropertyTreeViewPrivate()) +{ + init(); +} + +VPropertyTreeView::VPropertyTreeView(VPropertyModel *model, QWidget *parent) + : QTreeView(parent), d_ptr(new VPropertyTreeViewPrivate()) +{ + init(); + + if(model) + setModel(model); +} + +VPropertyTreeView::VPropertyTreeView(VPropertyTreeViewPrivate *d, bool init_, QWidget *parent) + : QTreeView(parent), d_ptr(d) +{ + if(init_) + init(); +} + +VPropertyTreeView::~VPropertyTreeView() +{ + delete d_ptr; +} + + +void VPropertyTreeView::setRowHeight(int height, bool add_to_standard) +{ + d_ptr->PropertyDelegate->setRowHeight(height, add_to_standard); +} + +void VPropertyTreeView::init() +{ + setAlternatingRowColors(true); + setUniformRowHeights(true); + d_ptr->PropertyDelegate = new VPropertyDelegate(this); + setItemDelegate(d_ptr->PropertyDelegate); + + setSelectionMode(QTreeView::SingleSelection); + setSelectionBehavior(QTreeView::SelectRows); + setRootIsDecorated(true); + + setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::SelectedClicked); +} + + diff --git a/src/libs/vpropertyexplorer/vpropertytreeview.h b/src/libs/vpropertyexplorer/vpropertytreeview.h new file mode 100644 index 000000000..3e9bb5946 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertytreeview.h @@ -0,0 +1,45 @@ +#ifndef VPROPERTYTREEVIEW_H +#define VPROPERTYTREEVIEW_H + +#include +#include "vpropertyexplorer_global.h" + +namespace VPE { + +class VPropertyTreeViewPrivate; + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyDelegate; +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyModel; + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyTreeView : public QTreeView +{ + Q_OBJECT +public: + //! Default constructor + explicit VPropertyTreeView(QWidget *parent = 0); + + //! The destructor, taking a model and setting it to the tree view + //! \param The model to set as model for this tree view + VPropertyTreeView(VPropertyModel* model, QWidget *parent = 0); + + //! Destructor + virtual ~VPropertyTreeView(); + + //! Sets the height for each row. Set this to 0 in order to let the standard delegate decide + void setRowHeight(int height = 0, bool add_to_standard = false); + + +protected: + //! This method is called by the constructors to initialize the view + virtual void init(); + + //! protected constructor + explicit VPropertyTreeView(VPropertyTreeViewPrivate* d, bool init_, QWidget *parent = 0); + + //! The protected data + VPropertyTreeViewPrivate* d_ptr; +}; + +} + +#endif // VPROPERTYTREEVIEWEEVIEW_H diff --git a/src/libs/vpropertyexplorer/vpropertytreeview_p.h b/src/libs/vpropertyexplorer/vpropertytreeview_p.h new file mode 100644 index 000000000..e5075517a --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertytreeview_p.h @@ -0,0 +1,30 @@ +#ifndef VPROPERTYTREEVIEW_P_H +#define VPROPERTYTREEVIEW_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include + +namespace VPE { + +class VPropertyDelegate; + +class VPropertyTreeViewPrivate +{ +public: + //! Property Delegate + VPropertyDelegate* PropertyDelegate; + + //! Constructor + VPropertyTreeViewPrivate(VPropertyDelegate* delegate) + : PropertyDelegate(delegate) {} + + //! Constructor + VPropertyTreeViewPrivate() + : PropertyDelegate(nullptr) {} +}; + +} + +#endif // VPROPERTYTREEVIEW_P_H diff --git a/src/libs/vpropertyexplorer/vserializedproperty.cpp b/src/libs/vpropertyexplorer/vserializedproperty.cpp new file mode 100644 index 000000000..1b4602833 --- /dev/null +++ b/src/libs/vpropertyexplorer/vserializedproperty.cpp @@ -0,0 +1,49 @@ +#include "vserializedproperty.h" + +using namespace VPE; + +VSerializedProperty::VSerializedProperty() + : ID(), Type(), Value() +{ +} + +/*! Creates a new VSerializedProperty from an existing property + +*/ +VSerializedProperty::VSerializedProperty(const VProperty* property, const VPropertySet* set) + : ID(), Type(property ? property->type() : QString()), Value(property ? property->getValue() : QVariant()) +{ + if(set) { + ID = set->getPropertyID(property); + + initChildren(property, set); + } +} + +VSerializedProperty::VSerializedProperty(const VProperty *property, const QString &id, const VPropertySet *set) + : ID(id), Type(property ? property->type() : QString()), Value(property ? property->getValue() : QVariant()) +{ + initChildren(property, set); +} + +VSerializedProperty::VSerializedProperty(const QString &id, const QString &type, const QVariant &value) + : ID(id), Type(type), Value(value) +{ +} + +VPE::VSerializedProperty::~VSerializedProperty() +{ + // +} + +void VSerializedProperty::initChildren(const VProperty *property, const VPropertySet *set) +{ + if(property && set) { + const QList& tmpChildren = property->getChildren(); + foreach(const VProperty* tmpChild, tmpChildren) { + QString tmpChildID = set->getPropertyID(property); + Children.append(VSerializedProperty(tmpChild, tmpChildID, set)); + } + } +} + diff --git a/src/libs/vpropertyexplorer/vserializedproperty.h b/src/libs/vpropertyexplorer/vserializedproperty.h new file mode 100644 index 000000000..b5b7597f7 --- /dev/null +++ b/src/libs/vpropertyexplorer/vserializedproperty.h @@ -0,0 +1,52 @@ +#ifndef VSERIALIZEDPROPERTY_H +#define VSERIALIZEDPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include + +#include "vproperty.h" +#include "vpropertyset.h" + +namespace VPE { + + +class VPROPERTYEXPLORERSHARED_EXPORT VSerializedProperty +{ +public: + //! Constructor + VSerializedProperty(); + + //! Constructor + VSerializedProperty(const VProperty* property, const VPropertySet* set); + + //! Constructor + VSerializedProperty(const VProperty* property, const QString& id, const VPropertySet* set); + + //! Constructor + VSerializedProperty(const QString& id, const QString& type, const QVariant& value); + + //! Destructor + ~VSerializedProperty(); + + //! The property type + QString ID; + + //! The property type + QString Type; + + //! The serialized value of the property + QVariant Value; + + //! List of child properties + QList Children; + +private: + void initChildren(const VProperty* property, const VPropertySet* set); +}; + +} + +#endif // VSERIALIZEDPROPERTY_H diff --git a/src/libs/vpropertyexplorer/vstandardpropertyFactory.cpp b/src/libs/vpropertyexplorer/vstandardpropertyFactory.cpp new file mode 100644 index 000000000..a9a05ea46 --- /dev/null +++ b/src/libs/vpropertyexplorer/vstandardpropertyFactory.cpp @@ -0,0 +1,66 @@ +#include "vstandardpropertyfactory.h" + +#include "vpropertyfactorymanager.h" + +// Supported Properties +#include "vproperty.h" +#include "plugins/vboolproperty.h" +#include "plugins/vcolorproperty.h" +#include "plugins/vemptyproperty.h" +#include "plugins/venumproperty.h" +#include "plugins/vfileproperty.h" +#include "plugins/vnumberproperty.h" +#include "plugins/vshortcutproperty.h" +#include "plugins/Vector3d/vvector3dproperty.h" + + +using namespace VPE; + +VStandardPropertyFactory::VStandardPropertyFactory() + : VAbstractPropertyFactory() +{ +} + +VStandardPropertyFactory::VStandardPropertyFactory(VPropertyFactoryManager *manager) + : VAbstractPropertyFactory() +{ + if(manager) { + manager->registerFactory("string", this); + manager->registerFactory("bool", this); + manager->registerFactory("color", this); + manager->registerFactory("empty", this); + manager->registerFactory("enum", this); + manager->registerFactory("file", this); + manager->registerFactory("integer", this); + manager->registerFactory("double", this); + manager->registerFactory("shortcut", this); + manager->registerFactory("vector3d", this); + } +} + +VProperty *VStandardPropertyFactory::createProperty(const QString &type, const QString &name) +{ + if(type == QString("string")) { + return new VProperty(name); + } else if(type == QString("bool")) { + return new VBoolProperty(name); + } else if(type == QString("color")) { + return new QColorProperty(name); + } else if(type == QString("empty")) { + return new VEmptyProperty(name); + } else if(type == QString("enum")) { + return new VEnumProperty(name); + } else if(type == QString("file")) { + return new VFileProperty(name); + } else if(type == QString("integer")) { + return new VIntegerProperty(name); + } else if(type == QString("double")) { + return new VDoubleProperty(name); + } else if(type == QString("shortcut")) { + return new VShortcutProperty(name); + } else if(type == QString("vector3d")) { + return new QVector3DProperty(name); + } + else + return nullptr; +} diff --git a/src/libs/vpropertyexplorer/vstandardpropertyfactory.h b/src/libs/vpropertyexplorer/vstandardpropertyfactory.h new file mode 100644 index 000000000..b095c3641 --- /dev/null +++ b/src/libs/vpropertyexplorer/vstandardpropertyfactory.h @@ -0,0 +1,33 @@ +#ifndef VASTANDARDPROPERTYFACTORY_H +#define VASTANDARDPROPERTYFACTORY_H + +#include "vpropertyexplorer_global.h" +#include "vabstractpropertyfactory.h" + +namespace VPE { + +class VProperty; + +class VPropertyFactoryManager; + +//! The standard property factory is able to create all the properties that are included in QtPropertyExplorer +//! by default. +class VPROPERTYEXPLORERSHARED_EXPORT VStandardPropertyFactory : public VAbstractPropertyFactory +{ +public: + //! Constructor + VStandardPropertyFactory(); + + //! Constructor + //! \param manager Registers this factory at the manager for all it's types + VStandardPropertyFactory(VPropertyFactoryManager* manager); + + //! Creates a new property of a certain type and assigns a name and description (otionally) + //! \param type The type of the property as string + //! \return Returns the created property or NULL if it couldn't be be created + virtual VProperty* createProperty(const QString& type, const QString &name); +}; + +} + +#endif // VASTANDARDPROPERTYFACTORY_H diff --git a/src/libs/vpropertyexplorer/vwidgetproperty_p.h b/src/libs/vpropertyexplorer/vwidgetproperty_p.h new file mode 100644 index 000000000..24dca698f --- /dev/null +++ b/src/libs/vpropertyexplorer/vwidgetproperty_p.h @@ -0,0 +1,35 @@ +#ifndef VWIDGETPROPERTY_P_H +#define VWIDGETPROPERTY_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include "vproperty_p.h" + +#include +#include + +namespace VPE { + +class VWidgetPropertyPrivate : public VPropertyPrivate { +public: + //! The widget to show + QPointer Widget; + + //! Constructor passing name and type + VWidgetPropertyPrivate(const QString& name, QVariant::Type type, QWidget* widget = nullptr) + : VPropertyPrivate(name, type), Widget(widget) {} + + //! Constructor + VWidgetPropertyPrivate() + : VPropertyPrivate(), Widget(nullptr) {} + + //! Destructor + ~VWidgetPropertyPrivate() { + if(Widget) + Widget->deleteLater(); + } +}; + +} + +#endif // VWIDGETPROPERTY_P_H From 8343f209985c6c188a9a5624e9bb079ea74f1917 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 26 Aug 2014 20:23:08 +0300 Subject: [PATCH 02/52] Prepare to build. --HG-- branch : feature --- src/app/mainwindow.cpp | 22 ++ src/app/mainwindow.h | 7 + src/app/options.h | 62 +++-- src/app/widgets/vmaingraphicsview.cpp | 3 + src/app/widgets/vmaingraphicsview.h | 3 +- .../widgets/vtooloptionspropertybrowser.cpp | 224 ++++++++++++++++++ src/app/widgets/vtooloptionspropertybrowser.h | 75 ++++++ src/app/widgets/widgets.pri | 6 +- .../vpropertyexplorer/vpropertyexplorer.cpp | 34 --- .../vpropertyexplorer/vpropertyexplorer.h | 41 ---- .../vpropertyexplorer/vpropertyexplorer.pro | 4 +- 11 files changed, 384 insertions(+), 97 deletions(-) create mode 100644 src/app/widgets/vtooloptionspropertybrowser.cpp create mode 100644 src/app/widgets/vtooloptionspropertybrowser.h delete mode 100644 src/libs/vpropertyexplorer/vpropertyexplorer.cpp delete mode 100644 src/libs/vpropertyexplorer/vpropertyexplorer.h diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index f547d6610..4f282b910 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -41,6 +41,7 @@ #include "widgets/vapplication.h" #include "widgets/undoevent.h" #include "undocommands/renamepp.h" +#include "vtooloptionspropertybrowser.h" #include #include @@ -112,6 +113,7 @@ MainWindow::MainWindow(QWidget *parent) ui->toolBox->setCurrentIndex(0); ReadSettings(); + PropertyBrowser(); setCurrentFile(""); } @@ -1959,6 +1961,26 @@ void MainWindow::CreateMenus() separatorAct = new QAction(this); separatorAct->setSeparator(true); ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct); + AddDocks(); +} + +void MainWindow::AddDocks() +{ + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, ui->dockWidgetHistory->toggleViewAction()); + ui->dockWidgetHistory->close();//Default don't show hostory + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, ui->dockWidgetToolOptions->toggleViewAction()); + + separatorAct = new QAction(this); + separatorAct->setSeparator(true); + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::PropertyBrowser() +{ + toolOptions = new VToolOptionsPropertyBrowser(ui->dockWidgetToolOptions); + + connect(ui->view, &VMainGraphicsView::itemClicked, toolOptions, &VToolOptionsPropertyBrowser::itemClicked); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index b749251a9..4c860bd2b 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -44,6 +44,8 @@ namespace Ui class MainWindow; } +class VToolOptionsPropertyBrowser; + /** * @brief The MainWindow class main windows. */ @@ -194,6 +196,8 @@ private: bool guiEnabled; QComboBox *gradationHeights; QComboBox *gradationSizes; + VToolOptionsPropertyBrowser *toolOptions; + void ToolBarOption(); void ToolBarDraws(); void ToolBarTools(); @@ -243,6 +247,9 @@ private: void UpdateSizesList(const QStringList &list); void SetDefaultHeight(int value); void SetDefaultSize(int value); + + void AddDocks(); + void PropertyBrowser(); }; #endif // MAINWINDOW_H diff --git a/src/app/options.h b/src/app/options.h index 2baec9341..e2a2a7d4d 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -42,25 +42,29 @@ class QString; #define NULL_ID 0//use this value for initialization variables that keeps id values. 0 mean uknown id value. enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; -enum class Tool : char +enum class Tool : unsigned char { - ArrowTool, - SinglePointTool, - EndLineTool, - LineTool, - AlongLineTool, - ShoulderPointTool, - NormalTool, - BisectorTool, - LineIntersectTool, - SplineTool, - CutSplineTool, - CutArcTool, - ArcTool, - SplinePathTool, - CutSplinePathTool, + Arrow, + Point, + LinePoint, + AbstractSpline, + Cut, + SinglePoint, + EndLine, + Line, + AlongLine, + ShoulderPoint, + Normal, + Bisector, + LineIntersect, + Spline, + CutSpline, + CutArc, + Arc, + SplinePath, + CutSplinePath, PointOfContact, - DetailTool, + Detail, NodePoint, NodeArc, NodeSpline, @@ -71,6 +75,30 @@ enum class Tool : char UnionDetails }; +enum class Vis : unsigned char +{ + ControlPointSpline, + GraphicsSimpleTextItem, + Line, + Path, + ToolAlongLine, + ToolArc, + ToolBisector, + ToolCutArc, + ToolEndLine, + ToolHeight, + ToolLine, + ToolLineIntersect, + ToolNormal, + ToolPointOfContact, + ToolPointOfIntersection, + ToolShoulderPoint, + ToolSpline, + ToolTriangle, + SimpleCurvePoint, + SimpleSplinePath +}; + enum class Source : char { FromGui, FromFile, FromTool }; enum class Draw : char { Calculation, Modeling }; enum class Unit : char { Mm, Cm, Inch }; diff --git a/src/app/widgets/vmaingraphicsview.cpp b/src/app/widgets/vmaingraphicsview.cpp index 46ad814ac..a11e3b0d9 100644 --- a/src/app/widgets/vmaingraphicsview.cpp +++ b/src/app/widgets/vmaingraphicsview.cpp @@ -220,6 +220,9 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) case Qt::ControlModifier: QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); break; + case Qt::NoModifier: + emit itemClicked(itemAt(mousePress->pos())); + break; default: break; } diff --git a/src/app/widgets/vmaingraphicsview.h b/src/app/widgets/vmaingraphicsview.h index e34baf781..8df21f47c 100644 --- a/src/app/widgets/vmaingraphicsview.h +++ b/src/app/widgets/vmaingraphicsview.h @@ -108,7 +108,8 @@ signals: * * Usefull when you need show dialog after working with tool visualization. */ - void MouseRelease(); + void MouseRelease(); + void itemClicked(QGraphicsItem *item); public slots: void ZoomIn(); void ZoomOut(); diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp new file mode 100644 index 000000000..dbd56109e --- /dev/null +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -0,0 +1,224 @@ +/************************************************************************ + ** + ** @file vtooloptionspropertybrowser.cpp + ** @author Roman Telezhynskyi + ** @date 22 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 . + ** + *************************************************************************/ + +#include "vtooloptionspropertybrowser.h" +#include "tools/drawTools/drawtools.h" +#include "widgets/vapplication.h" +#include "widgets/vmaingraphicsview.h" +#include "visualization/vgraphicssimpletextitem.h" +#include "visualization/vcontrolpointspline.h" + +#include +#include + +using namespace VPE; + +//--------------------------------------------------------------------------------------------------------------------- +VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) + :QObject(parent), + currentItem(nullptr), + propertyToId(QMap()), + idToProperty(QMap()) +{ + PropertyModel = new VPropertyModel(this); + TreeView = new VPropertyFormView(PropertyModel); + TreeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QScrollArea *scroll = new QScrollArea(); + scroll->setWidgetResizable(true); + scroll->setWidget(TreeView); + + QHBoxLayout* layout = new QHBoxLayout(); + parent->setLayout(layout); + layout->setSpacing(5); + layout->setMargin(0); + layout->addWidget(scroll); + + connect(PropertyModel, SIGNAL(onDataChangedByEditor(VProperty*)), this, SLOT(userChangedData(VProperty*))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) +{ + QMap::ConstIterator itProp = propertyToId.constBegin(); + while (itProp != propertyToId.constEnd()) + { + delete itProp.key(); + itProp++; + } + propertyToId.clear(); + idToProperty.clear(); + + currentItem = item; + PropertyModel->clear(); + if (currentItem == nullptr) + { + return; + } + + ShowItemOptions(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) +{ + if (!propertyToId.contains(property)) + { + return; + } + + if (!currentItem) + { + return; + } + + QVariant variant = property->data(VProperty::DPC_Data); + + QString id = propertyToId[property]; + switch (currentItem->type()) + { + case VToolSinglePoint::Type: + { + 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()); + } + } + } + else if (id == QLatin1String("posX")) + { + currentItem->setX(variant.toDouble()); + } + else if (id == QLatin1String("posY")) + { + currentItem->setY(variant.toDouble()); + } + break; + } +// case VGraphicsSimpleTextItem::Type: +// ShowItemOptions(currentItem->parentItem()); +// break; +// case VControlPointSpline::Type: +// ShowItemOptions(currentItem->parentItem()); +// break; + default: + break; + } + qApp->getSceneView()->update(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptions() +{ + if (currentItem == nullptr) + { + return; + } + + switch (currentItem->type()) + { + case VToolSinglePoint::Type: + { + VToolSinglePoint *i = qgraphicsitem_cast(currentItem); + idToProperty[QLatin1String("name")]->setValue(i->name()); + idToProperty[QLatin1String("posX")]->setValue(i->x()); + idToProperty[QLatin1String("posY")]->setValue(i->y()); + break; + } + case VGraphicsSimpleTextItem::Type: + ShowItemOptions(currentItem->parentItem()); + break; + case VControlPointSpline::Type: + ShowItemOptions(currentItem->parentItem()); + break; + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString &id) +{ + propertyToId[property] = id; + idToProperty[id] = property; + PropertyModel->addProperty(property, QLatin1String("name")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) +{ + switch (item->type()) + { + case VToolSinglePoint::Type: + { + VToolSinglePoint *i = qgraphicsitem_cast(item); + + VProperty* itemName = new VProperty(tr("Point name")); + itemName->setValue(i->name()); + AddProperty(itemName, QLatin1String("name")); + + VDoubleProperty* positionX = new VDoubleProperty(tr("Position X")); + positionX->setValue(i->x()); + AddProperty(positionX, QLatin1String("posX")); + + VDoubleProperty* positionY = new VDoubleProperty(tr("Position Y")); + positionY->setValue(i->y()); + AddProperty(positionY, QLatin1String("posY")); + +// QtVariantProperty *position = variantManager->addProperty(QVariant::PointF, tr("Position")); +// position->setValue(i->pos()); +// AddProperty(position, QLatin1String("position")); +// mainGroup->addSubProperty(position); + break; + } + case VGraphicsSimpleTextItem::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + case VControlPointSpline::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + default: + break; + } +} diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h new file mode 100644 index 000000000..16c72eeda --- /dev/null +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -0,0 +1,75 @@ +/************************************************************************ + ** + ** @file vtooloptionspropertybrowser.h + ** @author Roman Telezhynskyi + ** @date 22 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 VTOOLOPTIONSPROPERTYBROWSER_H +#define VTOOLOPTIONSPROPERTYBROWSER_H + +#include +#include + +#include "../libs/vpropertyexplorer/vproperty.h" +#include "../libs/vpropertyexplorer/vpropertymodel.h" +#include "../libs/vpropertyexplorer/vpropertyformview.h" +#include "../libs/vpropertyexplorer/plugins/vnumberproperty.h" + +class QDockWidget; +class QGraphicsItem; +class QScrollArea; + +using namespace VPE; + +class VToolOptionsPropertyBrowser : public QObject +{ + Q_OBJECT +public: + VToolOptionsPropertyBrowser(QDockWidget *parent); +public slots: + void itemClicked(QGraphicsItem *item); + void userChangedData(VProperty* property); + void UpdateOptions(); +private: + Q_DISABLE_COPY(VToolOptionsPropertyBrowser) + + VPropertyModel* PropertyModel; + VPropertyFormView* TreeView; + +// class QtGroupPropertyManager *groupManager; +// class VVariantPropertyManager *variantManager; + +// QtProperty *mainGroup; + +// QtGroupBoxPropertyBrowser *propertyEditor; + QGraphicsItem *currentItem; + QMap propertyToId; + QMap idToProperty; + + void AddProperty(VProperty *property, const QString &id); + void ShowItemOptions(QGraphicsItem *item); +}; + +#endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/widgets/widgets.pri b/src/app/widgets/widgets.pri index 9f100cc0d..8def2ed00 100644 --- a/src/app/widgets/widgets.pri +++ b/src/app/widgets/widgets.pri @@ -7,7 +7,8 @@ HEADERS += \ widgets/doubledelegate.h \ widgets/textdelegate.h \ widgets/vtranslation.h \ - widgets/undoevent.h + widgets/undoevent.h \ + widgets/vtooloptionspropertybrowser.h SOURCES += \ widgets/vtablegraphicsview.cpp \ @@ -18,4 +19,5 @@ SOURCES += \ widgets/doubledelegate.cpp \ widgets/textdelegate.cpp \ widgets/vtranslation.cpp \ - widgets/undoevent.cpp + widgets/undoevent.cpp \ + widgets/vtooloptionspropertybrowser.cpp diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.cpp b/src/libs/vpropertyexplorer/vpropertyexplorer.cpp deleted file mode 100644 index 67bf08c0b..000000000 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/************************************************************************ - ** - ** @file vpropertyexplorer.cpp - ** @author Roman Telezhynskyi - ** @date 26 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 . - ** - *************************************************************************/ - -#include "vpropertyexplorer.h" - - -Vpropertyexplorer::Vpropertyexplorer() -{ -} diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.h b/src/libs/vpropertyexplorer/vpropertyexplorer.h deleted file mode 100644 index 36c1d5917..000000000 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.h +++ /dev/null @@ -1,41 +0,0 @@ -/************************************************************************ - ** - ** @file vpropertyexplorer.h - ** @author Roman Telezhynskyi - ** @date 26 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 VPROPERTYEXPLORER_H -#define VPROPERTYEXPLORER_H - -#include "vpropertyexplorer_global.h" - -class VPROPERTYEXPLORERSHARED_EXPORT Vpropertyexplorer -{ - -public: - Vpropertyexplorer(); -}; - -#endif // VPROPERTYEXPLORER_H diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro index a32c23255..ee82ff976 100644 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.pro +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -15,7 +15,7 @@ CONFIG += c++11 DEFINES += VPROPERTYEXPLORER_LIBRARY -SOURCES += vpropertyexplorer.cpp \ +SOURCES += \ vproperty.cpp \ vpropertydelegate.cpp \ vpropertyfactorymanager.cpp \ @@ -39,7 +39,7 @@ SOURCES += vpropertyexplorer.cpp \ plugins/vnumberproperty.cpp \ plugins/Vector3d/vvector3dproperty.cpp -HEADERS += vpropertyexplorer.h\ +HEADERS +=\ vpropertyexplorer_global.h \ vpropertyfactorymanager_p.h \ vpropertytreeview_p.h \ From 988be1732f088554360dc7af6e92334a5af6e2d2 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 26 Aug 2014 20:25:43 +0300 Subject: [PATCH 03/52] Ignore *.rej files. --HG-- branch : feature --- .hgignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.hgignore b/.hgignore index d4f666f85..8f850c89e 100644 --- a/.hgignore +++ b/.hgignore @@ -38,5 +38,7 @@ cov-int/ # Ignore Mercurial .orig files *.orig +*.rej + # Ignore Makefile Makefile From bdfd2923869676c758dd7351b80637cfd96bce7c Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 26 Aug 2014 21:31:28 +0300 Subject: [PATCH 04/52] First build. --HG-- branch : feature --- src/app/dialogs/app/dialoghistory.cpp | 32 ++++----- src/app/mainwindow.cpp | 66 +++++++++---------- src/app/tools/drawTools/vabstractspline.h | 2 + src/app/tools/drawTools/vtoolalongline.cpp | 2 +- src/app/tools/drawTools/vtoolalongline.h | 2 + src/app/tools/drawTools/vtoolarc.cpp | 2 +- src/app/tools/drawTools/vtoolarc.h | 2 + src/app/tools/drawTools/vtoolbisector.cpp | 2 +- src/app/tools/drawTools/vtoolbisector.h | 2 + src/app/tools/drawTools/vtoolcut.h | 2 + src/app/tools/drawTools/vtoolcutarc.cpp | 2 +- src/app/tools/drawTools/vtoolcutarc.h | 2 + src/app/tools/drawTools/vtoolcutspline.cpp | 2 +- src/app/tools/drawTools/vtoolcutspline.h | 2 + .../tools/drawTools/vtoolcutsplinepath.cpp | 2 +- src/app/tools/drawTools/vtoolcutsplinepath.h | 2 + src/app/tools/drawTools/vtoolendline.cpp | 2 +- src/app/tools/drawTools/vtoolendline.h | 2 + src/app/tools/drawTools/vtoolheight.h | 2 + src/app/tools/drawTools/vtoolline.cpp | 2 +- src/app/tools/drawTools/vtoolline.h | 2 + .../tools/drawTools/vtoollineintersect.cpp | 2 +- src/app/tools/drawTools/vtoollineintersect.h | 2 + src/app/tools/drawTools/vtoollinepoint.h | 2 + src/app/tools/drawTools/vtoolnormal.cpp | 2 +- src/app/tools/drawTools/vtoolnormal.h | 2 + src/app/tools/drawTools/vtoolpointofcontact.h | 2 + .../drawTools/vtoolpointofintersection.h | 2 + .../tools/drawTools/vtoolshoulderpoint.cpp | 2 +- src/app/tools/drawTools/vtoolshoulderpoint.h | 2 + src/app/tools/drawTools/vtoolsinglepoint.cpp | 18 +++++ src/app/tools/drawTools/vtoolsinglepoint.h | 4 ++ src/app/tools/drawTools/vtoolspline.cpp | 2 +- src/app/tools/drawTools/vtoolspline.h | 2 + src/app/tools/drawTools/vtoolsplinepath.cpp | 2 +- src/app/tools/drawTools/vtoolsplinepath.h | 2 + src/app/tools/drawTools/vtooltriangle.h | 2 + src/app/tools/nodeDetails/vnodearc.h | 2 + src/app/tools/nodeDetails/vnodepoint.h | 2 + src/app/tools/nodeDetails/vnodespline.h | 2 + src/app/tools/nodeDetails/vnodesplinepath.h | 2 + src/app/tools/vtooldetail.cpp | 2 +- src/app/tools/vtooldetail.h | 2 + src/app/visualization/vcontrolpointspline.h | 2 + .../visualization/vgraphicssimpletextitem.h | 3 + src/app/visualization/visline.h | 2 + src/app/visualization/vispath.h | 2 + src/app/visualization/vistoolalongline.h | 2 + src/app/visualization/vistoolarc.h | 2 + src/app/visualization/vistoolbisector.h | 2 + src/app/visualization/vistoolcutarc.h | 2 + src/app/visualization/vistoolendline.h | 2 + src/app/visualization/vistoolheight.h | 2 + src/app/visualization/vistoolline.h | 2 + src/app/visualization/vistoollineintersect.h | 2 + src/app/visualization/vistoolnormal.h | 2 + src/app/visualization/vistoolpointofcontact.h | 2 + .../vistoolpointofintersection.h | 2 + src/app/visualization/vistoolshoulderpoint.h | 2 + src/app/visualization/vistoolspline.h | 3 + src/app/visualization/vistooltriangle.h | 3 + src/app/visualization/vsimplecurve.h | 3 + src/app/visualization/vsimplesplinepath.h | 3 + .../widgets/vtooloptionspropertybrowser.cpp | 16 +++-- src/app/xml/vpattern.cpp | 34 +++++----- src/app/xml/vtoolrecord.cpp | 2 +- .../vpropertyexplorer/vpropertyexplorer.pro | 11 ++++ 67 files changed, 218 insertions(+), 88 deletions(-) diff --git a/src/app/dialogs/app/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index 188efdb7a..d0950ed16 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -213,44 +213,44 @@ QString DialogHistory::Record(const VToolRecord &tool) { switch ( tool.getTypeTool() ) { - case Tool::ArrowTool: + case Tool::Arrow: Q_UNREACHABLE(); break; - case Tool::SinglePointTool: + case Tool::SinglePoint: { return QString(tr("%1 - Base point")).arg(PointName(tool.getId())); } - case Tool::EndLineTool: + case Tool::EndLine: { return QString(tr("%1_%2 - Line from point %1 to point %2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint))) .arg(PointName(tool.getId())); } - case Tool::LineTool: + case Tool::Line: { return QString(tr("%1_%2 - Line from point %1 to point %2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))); } - case Tool::AlongLineTool: + case Tool::AlongLine: { return QString(tr("%3 - Point along line %1_%2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(tool.getId())); } - case Tool::ShoulderPointTool: + case Tool::ShoulderPoint: { return QString(tr("%1 - Point of shoulder")).arg(PointName(tool.getId())); } - case Tool::NormalTool: + case Tool::Normal: { return QString(tr("%3 - normal to line %1_%2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(tool.getId())); } - case Tool::BisectorTool: + case Tool::Bisector: { return QString(tr("%4 - bisector of angle %1_%2_%3")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) @@ -258,7 +258,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrThirdPoint))) .arg(PointName(tool.getId())); } - case Tool::LineIntersectTool: + case Tool::LineIntersect: { return QString(tr("%5 - intersection of lines %1_%2 and %3_%4")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line1))) @@ -267,19 +267,19 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line2))) .arg(PointName(tool.getId())); } - case Tool::SplineTool: + case Tool::Spline: { const QSharedPointer spl = data->GeometricObject(tool.getId()); SCASSERT(spl != nullptr); return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id())); } - case Tool::ArcTool: + case Tool::Arc: { const QSharedPointer arc = data->GeometricObject(tool.getId()); SCASSERT(arc != nullptr); return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id())); } - case Tool::SplinePathTool: + case Tool::SplinePath: { const QSharedPointer splPath = data->GeometricObject(tool.getId()); SCASSERT(splPath != nullptr); @@ -331,7 +331,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))); } - case Tool::CutArcTool: + case Tool::CutArc: { const QSharedPointer arc = data->GeometricObject(AttrUInt(domElem, VToolCutArc::AttrArc)); SCASSERT(arc != nullptr); @@ -339,7 +339,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(tool.getId())) .arg(PointName(arc->GetCenter().id())); } - case Tool::CutSplineTool: + case Tool::CutSpline: { const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); const QSharedPointer spl = data->GeometricObject(splineId); @@ -349,7 +349,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(spl->GetP1().id())) .arg(PointName(spl->GetP4().id())); } - case Tool::CutSplinePathTool: + case Tool::CutSplinePath: { const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); const QSharedPointer splPath = data->GeometricObject(splinePathId); @@ -375,7 +375,7 @@ QString DialogHistory::Record(const VToolRecord &tool) } //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. - case Tool::DetailTool: + case Tool::Detail: break; case Tool::UnionDetails: break; diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 4f282b910..ef80a0c92 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -61,7 +61,7 @@ * @param parent parent widget. */ MainWindow::MainWindow(QWidget *parent) - :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Tool::ArrowTool), + :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Tool::Arrow), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), dialogTable(nullptr), dialogTool(nullptr), dialogHistory(nullptr), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), @@ -202,7 +202,7 @@ void MainWindow::ActionNewPP() QHash* tools = doc->getTools(); SCASSERT(tools != nullptr); tools->insert(id, spoint); - VDrawTool::AddRecord(id, Tool::SinglePointTool, doc); + VDrawTool::AddRecord(id, Tool::SinglePoint, doc); SetEnableTool(true); SetEnableWidgets(true); @@ -387,7 +387,7 @@ void MainWindow::ApplyDialog() */ void MainWindow::ToolEndLine(bool checked) { - SetToolButtonWithApply(checked, Tool::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), + SetToolButtonWithApply(checked, Tool::EndLine, ":/cursor/endline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -399,7 +399,7 @@ void MainWindow::ToolEndLine(bool checked) */ void MainWindow::ToolLine(bool checked) { - SetToolButtonWithApply(checked, Tool::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), + SetToolButtonWithApply(checked, Tool::Line, ":/cursor/line_cursor.png", tr("Select first point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -411,7 +411,7 @@ void MainWindow::ToolLine(bool checked) */ void MainWindow::ToolAlongLine(bool checked) { - SetToolButtonWithApply(checked, Tool::AlongLineTool, ":/cursor/alongline_cursor.png", + SetToolButtonWithApply(checked, Tool::AlongLine, ":/cursor/alongline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -423,7 +423,7 @@ void MainWindow::ToolAlongLine(bool checked) */ void MainWindow::ToolShoulderPoint(bool checked) { - SetToolButtonWithApply(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + SetToolButtonWithApply(checked, Tool::ShoulderPoint, ":/cursor/shoulder_cursor.png", tr("Select point of shoulder"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -436,7 +436,7 @@ void MainWindow::ToolShoulderPoint(bool checked) */ void MainWindow::ToolNormal(bool checked) { - SetToolButtonWithApply(checked, Tool::NormalTool, ":/cursor/normal_cursor.png", + SetToolButtonWithApply(checked, Tool::Normal, ":/cursor/normal_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -449,7 +449,7 @@ void MainWindow::ToolNormal(bool checked) */ void MainWindow::ToolBisector(bool checked) { - SetToolButtonWithApply(checked, Tool::BisectorTool, ":/cursor/bisector_cursor.png", + SetToolButtonWithApply(checked, Tool::Bisector, ":/cursor/bisector_cursor.png", tr("Select first point of angle"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -462,7 +462,7 @@ void MainWindow::ToolBisector(bool checked) */ void MainWindow::ToolLineIntersect(bool checked) { - SetToolButtonWithApply(checked, Tool::LineIntersectTool, ":/cursor/intersect_cursor.png", + SetToolButtonWithApply(checked, Tool::LineIntersect, ":/cursor/intersect_cursor.png", tr("Select first point of first line"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -475,7 +475,7 @@ void MainWindow::ToolLineIntersect(bool checked) */ void MainWindow::ToolSpline(bool checked) { - SetToolButtonWithApply(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", + SetToolButtonWithApply(checked, Tool::Spline, ":/cursor/spline_cursor.png", tr("Select first point curve"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -488,7 +488,7 @@ void MainWindow::ToolSpline(bool checked) */ void MainWindow::ToolCutSpline(bool checked) { - SetToolButton(checked, Tool::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", + SetToolButton(checked, Tool::CutSpline, ":/cursor/spline_cut_point_cursor.png", tr("Select simple curve"), &MainWindow::ClosedDialog); } @@ -499,7 +499,7 @@ void MainWindow::ToolCutSpline(bool checked) */ void MainWindow::ToolArc(bool checked) { - SetToolButtonWithApply(checked, Tool::ArcTool, ":/cursor/arc_cursor.png", + SetToolButtonWithApply(checked, Tool::Arc, ":/cursor/arc_cursor.png", tr("Select point of center of arc"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -511,7 +511,7 @@ void MainWindow::ToolArc(bool checked) */ void MainWindow::ToolSplinePath(bool checked) { - SetToolButton(checked, Tool::SplinePathTool, ":/cursor/splinepath_cursor.png", + SetToolButton(checked, Tool::SplinePath, ":/cursor/splinepath_cursor.png", tr("Select point of curve path"), &MainWindow::ClosedDialog); } @@ -522,7 +522,7 @@ void MainWindow::ToolSplinePath(bool checked) */ void MainWindow::ToolCutSplinePath(bool checked) { - SetToolButton(checked, Tool::CutSplinePathTool, + SetToolButton(checked, Tool::CutSplinePath, ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), &MainWindow::ClosedDialog); } @@ -547,7 +547,7 @@ void MainWindow::ToolPointOfContact(bool checked) */ void MainWindow::ToolDetail(bool checked) { - SetToolButton(checked, Tool::DetailTool, "://cursor/new_detail_cursor.png", + SetToolButton(checked, Tool::Detail, "://cursor/new_detail_cursor.png", tr("Select points, arcs, curves clockwise."), &MainWindow::ClosedDialogDetail); } @@ -636,7 +636,7 @@ void MainWindow::ClosedDialogUnionDetails(int result) */ void MainWindow::ToolCutArc(bool checked) { - SetToolButtonWithApply(checked, Tool::CutArcTool, ":/cursor/arc_cut_cursor.png", + SetToolButtonWithApply(checked, Tool::CutArc, ":/cursor/arc_cut_cursor.png", tr("Select arc"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -944,60 +944,60 @@ void MainWindow::CancelTool() dialogTool = nullptr; switch ( tool ) { - case Tool::ArrowTool: + case Tool::Arrow: ui->actionArrowTool->setChecked(false); helpLabel->setText(""); break; - case Tool::SinglePointTool: + case Tool::SinglePoint: Q_UNREACHABLE(); //Nothing to do here because we can't create this tool from main window. break; - case Tool::EndLineTool: + case Tool::EndLine: ui->toolButtonEndLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::LineTool: + case Tool::Line: ui->toolButtonLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearFocus(); break; - case Tool::AlongLineTool: + case Tool::AlongLine: ui->toolButtonAlongLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::ShoulderPointTool: + case Tool::ShoulderPoint: ui->toolButtonShoulderPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::NormalTool: + case Tool::Normal: ui->toolButtonNormal->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::BisectorTool: + case Tool::Bisector: ui->toolButtonBisector->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::LineIntersectTool: + case Tool::LineIntersect: ui->toolButtonLineIntersect->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::SplineTool: + case Tool::Spline: ui->toolButtonSpline->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::ArcTool: + case Tool::Arc: ui->toolButtonArc->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::SplinePathTool: + case Tool::SplinePath: ui->toolButtonSplinePath->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1007,7 +1007,7 @@ void MainWindow::CancelTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::DetailTool: + case Tool::Detail: ui->toolButtonNewDetail->setChecked(false); break; case Tool::Height: @@ -1025,12 +1025,12 @@ void MainWindow::CancelTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutSplineTool: + case Tool::CutSpline: ui->toolButtonSplineCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutSplinePathTool: + case Tool::CutSplinePath: ui->toolButtonSplinePathCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1040,7 +1040,7 @@ void MainWindow::CancelTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutArcTool: + case Tool::CutArc: ui->toolButtonArcCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1063,7 +1063,7 @@ void MainWindow::ArrowTool() { CancelTool(); ui->actionArrowTool->setChecked(true); - tool = Tool::ArrowTool; + tool = Tool::Arrow; QCursor cur(Qt::ArrowCursor); ui->view->setCursor(cur); helpLabel->setText(""); diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index 2dfe1fa88..1b5f10b0a 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -40,6 +40,8 @@ public: VAbstractSpline(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); static const QString TagName; virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::AbstractSpline)}; public slots: virtual void FullUpdateFromFile (); void Disable(bool disable); diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 1840e143e..411039c70 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -272,7 +272,7 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::AlongLineTool, doc); + VDrawTool::AddRecord(id, Tool::AlongLine, doc); if (parse == Document::FullParse) { VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index 1b2218604..7708abca5 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -49,6 +49,8 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::AlongLine)}; public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 1bbd344fe..c7f4a6b07 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -149,7 +149,7 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::ArcTool, doc); + VDrawTool::AddRecord(id, Tool::Arc, doc); if (parse == Document::FullParse) { VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 6e943e7d2..6417cf8c0 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -46,6 +46,8 @@ public: const Source &typeCreation); static const QString TagName; static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Arc)}; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index d6ff4d469..69116db27 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -196,7 +196,7 @@ VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, const doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::BisectorTool, doc); + VDrawTool::AddRecord(id, Tool::Bisector, doc); if (parse == Document::FullParse) { VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index 1b6bf211a..f824fd5bf 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -53,6 +53,8 @@ public: VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Bisector)}; public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolcut.h b/src/app/tools/drawTools/vtoolcut.h index d4bd20487..838b58fed 100644 --- a/src/app/tools/drawTools/vtoolcut.h +++ b/src/app/tools/drawTools/vtoolcut.h @@ -38,6 +38,8 @@ class VToolCut : public VToolPoint public: VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, const quint32 &curveCutId, const quint32 &curve1id, const quint32 &curve2id, QGraphicsItem * parent = nullptr); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Cut)}; public slots: virtual void ChangedActivDraw(const QString &newName); virtual void CurveChoosed(quint32 id)=0; diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index b89cdcdad..75f432d5a 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -163,7 +163,7 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS } } - VDrawTool::AddRecord(id, Tool::CutArcTool, doc); + VDrawTool::AddRecord(id, Tool::CutArc, doc); if (parse == Document::FullParse) { VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, arc1id, arc2id, typeCreation); diff --git a/src/app/tools/drawTools/vtoolcutarc.h b/src/app/tools/drawTools/vtoolcutarc.h index a7a762bef..a64e4eff5 100644 --- a/src/app/tools/drawTools/vtoolcutarc.h +++ b/src/app/tools/drawTools/vtoolcutarc.h @@ -48,6 +48,8 @@ public: VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrArc; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::CutArc)}; public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 7ab7352e5..95a5aaee2 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -163,7 +163,7 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::CutSplineTool, doc); + VDrawTool::AddRecord(id, Tool::CutSpline, doc); if (parse == Document::FullParse) { VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation); diff --git a/src/app/tools/drawTools/vtoolcutspline.h b/src/app/tools/drawTools/vtoolcutspline.h index 318851ab4..221b0a278 100644 --- a/src/app/tools/drawTools/vtoolcutspline.h +++ b/src/app/tools/drawTools/vtoolcutspline.h @@ -49,6 +49,8 @@ public: const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrSpline; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::CutSpline)}; public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 5148330a2..c252f325a 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -217,7 +217,7 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt } } - VDrawTool::AddRecord(id, Tool::CutSplinePathTool, doc); + VDrawTool::AddRecord(id, Tool::CutSplinePath, doc); if (parse == Document::FullParse) { VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, splPath1id, diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.h b/src/app/tools/drawTools/vtoolcutsplinepath.h index 9bb29913c..7a0c0050c 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.h +++ b/src/app/tools/drawTools/vtoolcutsplinepath.h @@ -50,6 +50,8 @@ public: const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrSplinePath; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::CutSplinePath)}; public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index b77479a13..a5cc6650b 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -154,7 +154,7 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::EndLineTool, doc); + VDrawTool::AddRecord(id, Tool::EndLine, doc); if (parse == Document::FullParse) { VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formulaLength, formulaAngle, basePointId, diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 22798fcb4..414ba671d 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -49,6 +49,8 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::EndLine)}; public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/drawTools/vtoolheight.h b/src/app/tools/drawTools/vtoolheight.h index b8e680930..c7fb5b146 100644 --- a/src/app/tools/drawTools/vtoolheight.h +++ b/src/app/tools/drawTools/vtoolheight.h @@ -50,6 +50,8 @@ public: VContainer *data, const Document &parse, const Source &typeCreation); static QPointF FindPoint(const QLineF &line, const QPointF &point); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Height)}; public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index ef718f501..d05b337e5 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -147,7 +147,7 @@ VToolLine * VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, con doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::LineTool, doc); + VDrawTool::AddRecord(id, Tool::Line, doc); if (parse == Document::FullParse) { VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeLine, typeCreation); diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 74ef14a59..8dfbd4c0e 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -48,6 +48,8 @@ public: const Document &parse, const Source &typeCreation); static const QString TagName; virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Line)}; public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 84c594214..1a83b0013 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -166,7 +166,7 @@ VToolLineIntersect* VToolLineIntersect::Create(const quint32 _id, const quint32 doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::LineIntersectTool, doc); + VDrawTool::AddRecord(id, Tool::LineIntersect, doc); if (parse == Document::FullParse) { VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, diff --git a/src/app/tools/drawTools/vtoollineintersect.h b/src/app/tools/drawTools/vtoollineintersect.h index 7a8e3fd1c..fe1802353 100644 --- a/src/app/tools/drawTools/vtoollineintersect.h +++ b/src/app/tools/drawTools/vtoollineintersect.h @@ -48,6 +48,8 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::LineIntersect)}; public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 08a0e34f9..6ba31b80a 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -40,6 +40,8 @@ class VToolLinePoint : public VToolPoint public: VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula, const quint32 &basePointId, const qreal &angle, QGraphicsItem * parent = nullptr); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::LinePoint)}; public slots: virtual void ChangedActivDraw(const QString &newName); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 41ea76357..4359363ae 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -157,7 +157,7 @@ VToolNormal* VToolNormal::Create(const quint32 _id, QString &formula, const quin doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::NormalTool, doc); + VDrawTool::AddRecord(id, Tool::Normal, doc); if (parse == Document::FullParse) { VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, diff --git a/src/app/tools/drawTools/vtoolnormal.h b/src/app/tools/drawTools/vtoolnormal.h index e1e65921e..c5b1f8d0b 100644 --- a/src/app/tools/drawTools/vtoolnormal.h +++ b/src/app/tools/drawTools/vtoolnormal.h @@ -50,6 +50,8 @@ public: static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, const qreal &angle = 0); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Normal)}; public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index 942378c17..7bdb63e8b 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -51,6 +51,8 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::PointOfContact) }; public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolpointofintersection.h b/src/app/tools/drawTools/vtoolpointofintersection.h index ef8518dce..55dcd021f 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.h +++ b/src/app/tools/drawTools/vtoolpointofintersection.h @@ -49,6 +49,8 @@ public: VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::PointOfIntersection) }; public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index da67ecb83..5221a18de 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -199,7 +199,7 @@ VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formu doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::ShoulderPointTool, doc); + VDrawTool::AddRecord(id, Tool::ShoulderPoint, doc); if (parse == Document::FullParse) { VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index c6acd946e..f1592ed2a 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -51,6 +51,8 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::ShoulderPoint) }; public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 408af790e..b888bd27e 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -82,6 +82,24 @@ 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) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +int VToolSinglePoint::type() const +{ + return Type; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToFile add tag with informations about tool into file. diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index c3b34f9d5..d66deaed4 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -43,6 +43,10 @@ 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)}; public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 47e71f20d..9ddabb672 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -172,7 +172,7 @@ VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const qui doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::SplineTool, doc); + VDrawTool::AddRecord(id, Tool::Spline, doc); if (parse == Document::FullParse) { VToolSpline *spl = new VToolSpline(doc, data, id, typeCreation); diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index 153d4f917..f1607e17a 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -48,6 +48,8 @@ public: VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Spline)}; public slots: void ControlPointChangePosition (const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index d66847b4e..c3e25c609 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -146,7 +146,7 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::SplinePathTool, doc); + VDrawTool::AddRecord(id, Tool::SplinePath, doc); if (parse == Document::FullParse) { VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation); diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index c5e39955c..b94ffc919 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -46,6 +46,8 @@ public: VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static void UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::SplinePath)}; signals: /** * @brief RefreshLine refresh control line. diff --git a/src/app/tools/drawTools/vtooltriangle.h b/src/app/tools/drawTools/vtooltriangle.h index f845c4786..d8cca4530 100644 --- a/src/app/tools/drawTools/vtooltriangle.h +++ b/src/app/tools/drawTools/vtooltriangle.h @@ -51,6 +51,8 @@ public: static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, const QPointF &secondPoint); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Triangle)}; public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/nodeDetails/vnodearc.h b/src/app/tools/nodeDetails/vnodearc.h index f0bd899be..b199855cb 100644 --- a/src/app/tools/nodeDetails/vnodearc.h +++ b/src/app/tools/nodeDetails/vnodearc.h @@ -49,6 +49,8 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::NodeArc)}; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/tools/nodeDetails/vnodepoint.h b/src/app/tools/nodeDetails/vnodepoint.h index 2e3a7f535..0201af254 100644 --- a/src/app/tools/nodeDetails/vnodepoint.h +++ b/src/app/tools/nodeDetails/vnodepoint.h @@ -55,6 +55,8 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::NodePoint)}; public slots: virtual void FullUpdateFromFile(); void NameChangePosition(const QPointF &pos); diff --git a/src/app/tools/nodeDetails/vnodespline.h b/src/app/tools/nodeDetails/vnodespline.h index 0492d9381..ea29108a2 100644 --- a/src/app/tools/nodeDetails/vnodespline.h +++ b/src/app/tools/nodeDetails/vnodespline.h @@ -49,6 +49,8 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::NodeSpline)}; public slots: virtual void FullUpdateFromFile (); protected: diff --git a/src/app/tools/nodeDetails/vnodesplinepath.h b/src/app/tools/nodeDetails/vnodesplinepath.h index 91026e642..7be54d734 100644 --- a/src/app/tools/nodeDetails/vnodesplinepath.h +++ b/src/app/tools/nodeDetails/vnodesplinepath.h @@ -48,6 +48,8 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::SplinePath)}; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index 747b3f185..d93488eaf 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -216,7 +216,7 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap doc->UpdateToolData(id, data); } } - VAbstractTool::AddRecord(id, Tool::DetailTool, doc); + VAbstractTool::AddRecord(id, Tool::Detail, doc); if (parse == Document::FullParse) { VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); diff --git a/src/app/tools/vtooldetail.h b/src/app/tools/vtooldetail.h index df90ad8e5..cd0c9bec8 100644 --- a/src/app/tools/vtooldetail.h +++ b/src/app/tools/vtooldetail.h @@ -82,6 +82,8 @@ public: static const QString NodeSplinePath; void Remove(bool ask); static void AddNode(VPattern *doc, QDomElement &domElement, const VNodeDetail &node); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Detail)}; public slots: virtual void FullUpdateFromFile (); virtual void FullUpdateFromGuiOk(int result); diff --git a/src/app/visualization/vcontrolpointspline.h b/src/app/visualization/vcontrolpointspline.h index 0ae115fc7..e72c78951 100644 --- a/src/app/visualization/vcontrolpointspline.h +++ b/src/app/visualization/vcontrolpointspline.h @@ -43,6 +43,8 @@ public: VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, const QPointF &splinePoint, QGraphicsItem * parent = nullptr); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ControlPointSpline)}; signals: /** * @brief ControlPointChangePosition emit when control point change position. diff --git a/src/app/visualization/vgraphicssimpletextitem.h b/src/app/visualization/vgraphicssimpletextitem.h index b6622feda..122b02b20 100644 --- a/src/app/visualization/vgraphicssimpletextitem.h +++ b/src/app/visualization/vgraphicssimpletextitem.h @@ -31,6 +31,7 @@ #include #include +#include "../options.h" /** * @brief The VGraphicsSimpleTextItem class pointer label. @@ -44,6 +45,8 @@ public: qint32 FontSize()const; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::GraphicsSimpleTextItem)}; signals: /** * @brief NameChangePosition emit when label change position. diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index ec7933a1f..8f8c4d884 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -42,6 +42,8 @@ public: VisLine(const VContainer *data, QGraphicsItem *parent = 0); virtual ~VisLine(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::Line)}; protected: QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle); qreal CorrectAngle(const qreal &angle) const; diff --git a/src/app/visualization/vispath.h b/src/app/visualization/vispath.h index 67ef9974a..54d226863 100644 --- a/src/app/visualization/vispath.h +++ b/src/app/visualization/vispath.h @@ -39,6 +39,8 @@ public: VisPath(const VContainer *data, QGraphicsItem *parent = 0); virtual ~VisPath(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::Path)}; protected: virtual void InitPen(); virtual void AddOnScene(); diff --git a/src/app/visualization/vistoolalongline.h b/src/app/visualization/vistoolalongline.h index 791d2cf1d..45d6d61e3 100644 --- a/src/app/visualization/vistoolalongline.h +++ b/src/app/visualization/vistoolalongline.h @@ -43,6 +43,8 @@ public: virtual void RefreshGeometry(); void setPoint2Id(const quint32 &value); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolAlongLine)}; private: Q_DISABLE_COPY(VisToolAlongLine) quint32 point2Id; diff --git a/src/app/visualization/vistoolarc.h b/src/app/visualization/vistoolarc.h index 3c06737c8..5e44d0f1a 100644 --- a/src/app/visualization/vistoolarc.h +++ b/src/app/visualization/vistoolarc.h @@ -43,6 +43,8 @@ public: void setRadius(const QString &expression); void setF1(const QString &expression); void setF2(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolArc)}; private: Q_DISABLE_COPY(VisToolArc) QGraphicsEllipseItem *arcCenter; diff --git a/src/app/visualization/vistoolbisector.h b/src/app/visualization/vistoolbisector.h index 9b8aade23..be85db27b 100644 --- a/src/app/visualization/vistoolbisector.h +++ b/src/app/visualization/vistoolbisector.h @@ -42,6 +42,8 @@ public: void setPoint2Id(const quint32 &value); void setPoint3Id(const quint32 &value); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolBisector)}; private: Q_DISABLE_COPY(VisToolBisector) quint32 point2Id; diff --git a/src/app/visualization/vistoolcutarc.h b/src/app/visualization/vistoolcutarc.h index a97b7d5bb..84aa695be 100644 --- a/src/app/visualization/vistoolcutarc.h +++ b/src/app/visualization/vistoolcutarc.h @@ -40,6 +40,8 @@ public: virtual void RefreshGeometry(); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCutArc)}; protected: Q_DISABLE_COPY(VisToolCutArc) QGraphicsEllipseItem *point; diff --git a/src/app/visualization/vistoolendline.h b/src/app/visualization/vistoolendline.h index 288dbde67..7b44f697f 100644 --- a/src/app/visualization/vistoolendline.h +++ b/src/app/visualization/vistoolendline.h @@ -44,6 +44,8 @@ public: QString Angle() const; void setAngle(const QString &expression); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolEndLine)}; private: Q_DISABLE_COPY(VisToolEndLine) qreal length; diff --git a/src/app/visualization/vistoolheight.h b/src/app/visualization/vistoolheight.h index 07b0bcd28..0b17b78bb 100644 --- a/src/app/visualization/vistoolheight.h +++ b/src/app/visualization/vistoolheight.h @@ -42,6 +42,8 @@ public: void setLineP1Id(const quint32 &value); void setLineP2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolHeight)}; private: Q_DISABLE_COPY(VisToolHeight) //base point in parent class diff --git a/src/app/visualization/vistoolline.h b/src/app/visualization/vistoolline.h index d28e6be49..48347dbe7 100644 --- a/src/app/visualization/vistoolline.h +++ b/src/app/visualization/vistoolline.h @@ -40,6 +40,8 @@ public: virtual void RefreshGeometry(); void setPoint2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolLine)}; private: Q_DISABLE_COPY(VisToolLine) quint32 point2Id; diff --git a/src/app/visualization/vistoollineintersect.h b/src/app/visualization/vistoollineintersect.h index 568c4c242..b69d03ff7 100644 --- a/src/app/visualization/vistoollineintersect.h +++ b/src/app/visualization/vistoollineintersect.h @@ -43,6 +43,8 @@ public: void setLine1P2Id(const quint32 &value); void setLine2P1Id(const quint32 &value); void setLine2P2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolLineIntersect)}; private: Q_DISABLE_COPY(VisToolLineIntersect) quint32 line1P2Id; diff --git a/src/app/visualization/vistoolnormal.h b/src/app/visualization/vistoolnormal.h index 649164851..1593d03f5 100644 --- a/src/app/visualization/vistoolnormal.h +++ b/src/app/visualization/vistoolnormal.h @@ -44,6 +44,8 @@ public: void setLength(const QString &expression); qreal getAngle() const; void setAngle(const qreal &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolNormal)}; private: Q_DISABLE_COPY(VisToolNormal) quint32 point2Id; diff --git a/src/app/visualization/vistoolpointofcontact.h b/src/app/visualization/vistoolpointofcontact.h index bb638790d..4edc79ea0 100644 --- a/src/app/visualization/vistoolpointofcontact.h +++ b/src/app/visualization/vistoolpointofcontact.h @@ -42,6 +42,8 @@ public: void setLineP2Id(const quint32 &value); void setRadiusId(const quint32 &value); void setRadius(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPointOfContact)}; private: Q_DISABLE_COPY(VisToolPointOfContact) quint32 lineP2Id; diff --git a/src/app/visualization/vistoolpointofintersection.h b/src/app/visualization/vistoolpointofintersection.h index e17c1ee05..a2c594f75 100644 --- a/src/app/visualization/vistoolpointofintersection.h +++ b/src/app/visualization/vistoolpointofintersection.h @@ -41,6 +41,8 @@ public: virtual void RefreshGeometry(); void setPoint2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPointOfIntersection)}; private: Q_DISABLE_COPY(VisToolPointOfIntersection) quint32 point2Id; diff --git a/src/app/visualization/vistoolshoulderpoint.h b/src/app/visualization/vistoolshoulderpoint.h index 6511f253b..bfda38bc5 100644 --- a/src/app/visualization/vistoolshoulderpoint.h +++ b/src/app/visualization/vistoolshoulderpoint.h @@ -42,6 +42,8 @@ public: void setLineP1Id(const quint32 &value); void setLineP2Id(const quint32 &value); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolShoulderPoint)}; private: Q_DISABLE_COPY(VisToolShoulderPoint) quint32 lineP1Id; diff --git a/src/app/visualization/vistoolspline.h b/src/app/visualization/vistoolspline.h index 1a2c9f9f9..56c12d021 100644 --- a/src/app/visualization/vistoolspline.h +++ b/src/app/visualization/vistoolspline.h @@ -46,6 +46,9 @@ public: void setKAsm1(const qreal &value); void setKAsm2(const qreal &value); void setKCurve(const qreal &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolSpline)}; protected: Q_DISABLE_COPY(VisToolSpline) quint32 point4Id; diff --git a/src/app/visualization/vistooltriangle.h b/src/app/visualization/vistooltriangle.h index b34b5cd0e..a15defaf7 100644 --- a/src/app/visualization/vistooltriangle.h +++ b/src/app/visualization/vistooltriangle.h @@ -43,6 +43,9 @@ public: void setPoint2Id(const quint32 &value); void setHypotenuseP1Id(const quint32 &value); void setHypotenuseP2Id(const quint32 &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolTriangle)}; private: Q_DISABLE_COPY(VisToolTriangle) quint32 point2Id;//axis second point diff --git a/src/app/visualization/vsimplecurve.h b/src/app/visualization/vsimplecurve.h index 4fb9a8704..bf6cb6683 100644 --- a/src/app/visualization/vsimplecurve.h +++ b/src/app/visualization/vsimplecurve.h @@ -45,6 +45,9 @@ public: qreal *factor = nullptr, QObject *parent = 0); void ChangedActivDraw(const bool &flag); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::SimpleCurvePoint)}; signals: /** * @brief Choosed send id when clicked. diff --git a/src/app/visualization/vsimplesplinepath.h b/src/app/visualization/vsimplesplinepath.h index 50fe8ec67..3ff124b0a 100644 --- a/src/app/visualization/vsimplesplinepath.h +++ b/src/app/visualization/vsimplesplinepath.h @@ -42,6 +42,9 @@ class VSimpleSplinePath : public VAbstractTool, public QGraphicsPathItem public: VSimpleSplinePath(VPattern *doc, VContainer *data, quint32 id, qreal *factor); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::SimpleSplinePath)}; protected: virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index dbd56109e..bfe5d341d 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -46,18 +46,20 @@ VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) idToProperty(QMap()) { PropertyModel = new VPropertyModel(this); - TreeView = new VPropertyFormView(PropertyModel); + TreeView = new VPropertyFormView(PropertyModel, parent); TreeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - QScrollArea *scroll = new QScrollArea(); + QScrollArea *scroll = new QScrollArea(parent); scroll->setWidgetResizable(true); scroll->setWidget(TreeView); - QHBoxLayout* layout = new QHBoxLayout(); - parent->setLayout(layout); - layout->setSpacing(5); - layout->setMargin(0); - layout->addWidget(scroll); +// QLayout* layout = parent->layout(); +// layout->setSpacing(5); +// layout->setMargin(0); +// layout->addWidget(scroll); +// parent->setLayout(layout); + + parent->setWidget(scroll); connect(PropertyModel, SIGNAL(onDataChangedByEditor(VProperty*)), this, SLOT(userChangedData(VProperty*))); } diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 33edc92a2..9142e6e4e 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1095,7 +1095,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem const qreal y = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrY, "10.0")); data->UpdateGObject(id, new VPointF(x, y, name, mx, my)); - VDrawTool::AddRecord(id, Tool::SinglePointTool, this); + VDrawTool::AddRecord(id, Tool::SinglePoint, this); if (parse != Document::FullParse) { UpdateToolData(id, data); @@ -2424,40 +2424,40 @@ QRectF VPattern::ActiveDrawBoundingRect() const { switch ( tool.getTypeTool() ) { - case Tool::ArrowTool: + case Tool::Arrow: Q_UNREACHABLE(); break; - case Tool::SinglePointTool: + case Tool::SinglePoint: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::EndLineTool: + case Tool::EndLine: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::LineTool: + case Tool::Line: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::AlongLineTool: + case Tool::AlongLine: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::ShoulderPointTool: + case Tool::ShoulderPoint: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::NormalTool: + case Tool::Normal: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::BisectorTool: + case Tool::Bisector: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::LineIntersectTool: + case Tool::LineIntersect: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::SplineTool: + case Tool::Spline: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::ArcTool: + case Tool::Arc: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::SplinePathTool: + case Tool::SplinePath: rec = ToolBoundingRect(rec, tool.getId()); break; case Tool::PointOfContact: @@ -2472,18 +2472,18 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::PointOfIntersection: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::CutArcTool: + case Tool::CutArc: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::CutSplineTool: + case Tool::CutSpline: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::CutSplinePathTool: + case Tool::CutSplinePath: rec = ToolBoundingRect(rec, tool.getId()); break; //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. - case Tool::DetailTool: + case Tool::Detail: break; case Tool::UnionDetails: break; diff --git a/src/app/xml/vtoolrecord.cpp b/src/app/xml/vtoolrecord.cpp index 1b6fcbd19..046334f14 100644 --- a/src/app/xml/vtoolrecord.cpp +++ b/src/app/xml/vtoolrecord.cpp @@ -33,7 +33,7 @@ * @brief VToolRecord default constructor. */ VToolRecord::VToolRecord() - :id(NULL_ID), typeTool(Tool::ArrowTool), nameDraw(QString()) + :id(NULL_ID), typeTool(Tool::Arrow), nameDraw(QString()) {} //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro index ee82ff976..4c998c79a 100644 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.pro +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -15,6 +15,15 @@ CONFIG += c++11 DEFINES += VPROPERTYEXPLORER_LIBRARY +# directory for executable file +DESTDIR = bin + +# files created moc +MOC_DIR = moc + +# objecs files +OBJECTS_DIR = obj + SOURCES += \ vproperty.cpp \ vpropertydelegate.cpp \ @@ -78,3 +87,5 @@ unix { target.path = /usr/lib INSTALLS += target } + +QMAKE_CXXFLAGS += -gdwarf-3 From 70a17f118e38d3899390cf1bc86a595d88ec9f29 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 26 Aug 2014 22:34:27 +0300 Subject: [PATCH 05/52] Update options after move. --HG-- branch : feature --- src/app/mainwindow.cpp | 1 + src/app/widgets/vtooloptionspropertybrowser.cpp | 12 ++++++------ .../vpropertyexplorer/plugins/vnumberproperty.cpp | 6 ++++-- src/libs/vpropertyexplorer/vproperty.cpp | 1 - src/libs/vpropertyexplorer/vpropertyset.cpp | 12 ++++++------ 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index ef80a0c92..fa38d777f 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1981,6 +1981,7 @@ void MainWindow::PropertyBrowser() toolOptions = new VToolOptionsPropertyBrowser(ui->dockWidgetToolOptions); connect(ui->view, &VMainGraphicsView::itemClicked, toolOptions, &VToolOptionsPropertyBrowser::itemClicked); + connect(doc, &VPattern::FullUpdateFromFile, toolOptions, &VToolOptionsPropertyBrowser::UpdateOptions); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index bfe5d341d..ac5b3c4f5 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -53,12 +53,6 @@ VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) scroll->setWidgetResizable(true); scroll->setWidget(TreeView); -// QLayout* layout = parent->layout(); -// layout->setSpacing(5); -// layout->setMargin(0); -// layout->addWidget(scroll); -// parent->setLayout(layout); - parent->setWidget(scroll); connect(PropertyModel, SIGNAL(onDataChangedByEditor(VProperty*)), this, SLOT(userChangedData(VProperty*))); @@ -67,6 +61,12 @@ VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) { + if (currentItem == item) + { + UpdateOptions(); + return; + } + QMap::ConstIterator itProp = propertyToId.constBegin(); while (itProp != propertyToId.constEnd()) { diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp index 8cf45b399..9ec0e7ccf 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp @@ -39,7 +39,8 @@ QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionView tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tmpEditor->setValue(d_ptr->VariantValue.toInt()); - return tmpEditor; + d_ptr->editor = tmpEditor; + return d_ptr->editor; } //! Gets the data from the widget @@ -126,7 +127,8 @@ QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewI tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tmpEditor->setValue(d_ptr->VariantValue.toDouble()); - return tmpEditor; + d_ptr->editor = tmpEditor; + return d_ptr->editor; } //! Gets the data from the widget diff --git a/src/libs/vpropertyexplorer/vproperty.cpp b/src/libs/vpropertyexplorer/vproperty.cpp index b845891db..59f96238e 100644 --- a/src/libs/vpropertyexplorer/vproperty.cpp +++ b/src/libs/vpropertyexplorer/vproperty.cpp @@ -86,7 +86,6 @@ QWidget* VProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& o QItemEditorFactory::setDefaultFactory(factory); d_ptr->editor = factory->createEditor(d_ptr->PropertyVariantType, parent); - //return factory->createEditor(d_ptr->PropertyVariantType, parent); return d_ptr->editor; } diff --git a/src/libs/vpropertyexplorer/vpropertyset.cpp b/src/libs/vpropertyexplorer/vpropertyset.cpp index 7be540da8..ca7f0f871 100644 --- a/src/libs/vpropertyexplorer/vpropertyset.cpp +++ b/src/libs/vpropertyexplorer/vpropertyset.cpp @@ -103,12 +103,12 @@ int VPropertySet::count() const void VPropertySet::clear(bool delete_properties) { d_ptr->Properties.clear(); - while(!d_ptr->RootProperties.isEmpty()) { - VProperty* tmpProp = d_ptr->RootProperties.takeLast(); - if(tmpProp != NULL && delete_properties) { - delete tmpProp; - } - } +// while(!d_ptr->RootProperties.isEmpty()) { +// VProperty* tmpProp = d_ptr->RootProperties.takeLast(); +// if(tmpProp != NULL && delete_properties) { +// delete tmpProp; +// } +// } } QString VPropertySet::getPropertyID(const VProperty *prop, bool look_for_parent_id) const From 670e185465e55a7d96d8458fced9156091bd8ae5 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 26 Aug 2014 23:04:01 +0300 Subject: [PATCH 06/52] Don't need delete properties in method itemClicked. --HG-- branch : feature --- src/app/widgets/vtooloptionspropertybrowser.cpp | 9 ++------- src/libs/vpropertyexplorer/vpropertyset.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index ac5b3c4f5..d050e37d2 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -67,17 +67,12 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) return; } - QMap::ConstIterator itProp = propertyToId.constBegin(); - while (itProp != propertyToId.constEnd()) - { - delete itProp.key(); - itProp++; - } + PropertyModel->clear(); propertyToId.clear(); idToProperty.clear(); currentItem = item; - PropertyModel->clear(); + if (currentItem == nullptr) { return; diff --git a/src/libs/vpropertyexplorer/vpropertyset.cpp b/src/libs/vpropertyexplorer/vpropertyset.cpp index ca7f0f871..d5554acd9 100644 --- a/src/libs/vpropertyexplorer/vpropertyset.cpp +++ b/src/libs/vpropertyexplorer/vpropertyset.cpp @@ -103,12 +103,12 @@ int VPropertySet::count() const void VPropertySet::clear(bool delete_properties) { d_ptr->Properties.clear(); -// while(!d_ptr->RootProperties.isEmpty()) { -// VProperty* tmpProp = d_ptr->RootProperties.takeLast(); -// if(tmpProp != NULL && delete_properties) { -// delete tmpProp; -// } -// } + while(!d_ptr->RootProperties.isEmpty()) { + VProperty* tmpProp = d_ptr->RootProperties.takeLast(); + if(tmpProp != nullptr && delete_properties) { + delete tmpProp; + } + } } QString VPropertySet::getPropertyID(const VProperty *prop, bool look_for_parent_id) const From 4356861f78994fcd63fe19b263396cf727b00923 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 27 Aug 2014 10:24:41 +0300 Subject: [PATCH 07/52] Show tool name in dock widget title. --HG-- branch : feature --- src/app/widgets/vtooloptionspropertybrowser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index d050e37d2..91972430e 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -75,6 +75,8 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) if (currentItem == nullptr) { + QDockWidget *parent = qobject_cast(this->parent()); + parent->setWindowTitle(tr("Tool options")); return; } @@ -188,6 +190,8 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolSinglePoint::Type: { VToolSinglePoint *i = qgraphicsitem_cast(item); + QDockWidget *parent = qobject_cast(this->parent()); + parent->setWindowTitle(tr("Tool options (Base point)")); VProperty* itemName = new VProperty(tr("Point name")); itemName->setValue(i->name()); From ea8e8338c84bad96319d2fbc1ec5ed5060d1c10e Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 23 Aug 2014 09:59:48 +0300 Subject: [PATCH 08/52] Hide options for tool in previous pattern piece. --HG-- branch : feature --- src/app/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index fa38d777f..a7fbc7192 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -2236,6 +2236,7 @@ void MainWindow::ChangePP(int index, bool zoomBestFit) ui->view->NewFactor(ui->view->transform().m11()); } } + toolOptions->itemClicked(nullptr);//hide options for tool in previous pattern piece } } From 35b5a65eedb36fa34d299755eda70e2b6942ffe0 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 27 Aug 2014 10:31:58 +0300 Subject: [PATCH 09/52] Save label name. --HG-- branch : feature --- src/app/tools/drawTools/vtoolsinglepoint.cpp | 47 +++++++++++++++----- src/app/tools/drawTools/vtoolsinglepoint.h | 1 + 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index b888bd27e..35b066c8f 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -33,6 +33,7 @@ #include "../../undocommands/addpatternpiece.h" #include "../../undocommands/deletepatternpiece.h" #include "../../geometry/vpointf.h" +#include "../../undocommands/savetooloptions.h" #include @@ -91,7 +92,23 @@ QString VToolSinglePoint::name() const //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::setName(const QString &name) { + QDomElement oldDomElement = doc->elementById(QString().setNum(id)); + if (oldDomElement.isElement()) + { + QDomElement newDomElement = oldDomElement.cloneNode().toElement(); + VPointF newPoint = VPointF(*VAbstractTool::data.GeometricObject(id).data()); + newPoint.setName(name); + SaveOptions(newDomElement, newPoint); + + 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; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -112,13 +129,7 @@ void VToolSinglePoint::AddToFile() QDomElement sPoint = doc->createElement(TagName); // Create SPoint tag - doc->SetAttribute(sPoint, VDomDocument::AttrId, id); - doc->SetAttribute(sPoint, AttrType, ToolType); - doc->SetAttribute(sPoint, AttrName, point->name()); - doc->SetAttribute(sPoint, AttrX, qApp->fromPixel(point->x())); - doc->SetAttribute(sPoint, AttrY, qApp->fromPixel(point->y())); - doc->SetAttribute(sPoint, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(sPoint, AttrMy, qApp->fromPixel(point->my())); + SaveOptions(sPoint, *point.data()); //Create pattern piece structure QDomElement patternPiece = doc->createElement(VPattern::TagDraw); @@ -147,11 +158,11 @@ void VToolSinglePoint::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(point->x()))); - doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(point->y()))); - doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(point->mx()))); - doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(point->my()))); + SaveOptions(domElement, *point.data()); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } } @@ -292,6 +303,18 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) lineName->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::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, AttrX, qApp->fromPixel(point.x())); + doc->SetAttribute(tag, AttrY, qApp->fromPixel(point.y())); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point.mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point.my())); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index d66deaed4..cc87d3725 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -73,6 +73,7 @@ private: QString namePP; QString mPath; void setColorLabel(const Qt::GlobalColor & color); + void SaveOptions(QDomElement &tag, const VPointF &point); }; #endif // VTOOLSINGLEPOINT_H From 0d0bcb9005315856d1d5b7d774b46069776a86cf Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 27 Aug 2014 13:42:54 +0300 Subject: [PATCH 10/52] New property for string type. --HG-- branch : feature --- .../widgets/vtooloptionspropertybrowser.cpp | 2 + src/app/widgets/vtooloptionspropertybrowser.h | 7 - src/libs/vpropertyexplorer/LICENSE.txt | 165 ++++++++++++++++++ .../plugins/vstringproperty.cpp | 105 +++++++++++ .../plugins/vstringproperty.h | 75 ++++++++ .../vpropertyexplorer/vpropertyexplorer.pro | 8 +- ...ctory.cpp => vstandardpropertyfactory.cpp} | 0 .../vstandardpropertyfactory.h | 2 +- 8 files changed, 353 insertions(+), 11 deletions(-) create mode 100644 src/libs/vpropertyexplorer/LICENSE.txt create mode 100644 src/libs/vpropertyexplorer/plugins/vstringproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vstringproperty.h rename src/libs/vpropertyexplorer/{vstandardpropertyFactory.cpp => vstandardpropertyfactory.cpp} (100%) diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 91972430e..a2f2fa7ed 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -32,6 +32,8 @@ #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 #include diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h index 16c72eeda..e915e989d 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.h +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -35,7 +35,6 @@ #include "../libs/vpropertyexplorer/vproperty.h" #include "../libs/vpropertyexplorer/vpropertymodel.h" #include "../libs/vpropertyexplorer/vpropertyformview.h" -#include "../libs/vpropertyexplorer/plugins/vnumberproperty.h" class QDockWidget; class QGraphicsItem; @@ -58,12 +57,6 @@ private: VPropertyModel* PropertyModel; VPropertyFormView* TreeView; -// class QtGroupPropertyManager *groupManager; -// class VVariantPropertyManager *variantManager; - -// QtProperty *mainGroup; - -// QtGroupBoxPropertyBrowser *propertyEditor; QGraphicsItem *currentItem; QMap propertyToId; QMap idToProperty; diff --git a/src/libs/vpropertyexplorer/LICENSE.txt b/src/libs/vpropertyexplorer/LICENSE.txt new file mode 100644 index 000000000..65c5ca88a --- /dev/null +++ b/src/libs/vpropertyexplorer/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp new file mode 100644 index 000000000..5803dbf61 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -0,0 +1,105 @@ +/************************************************************************ + ** + ** @file vstringproperty.cpp + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @brief + ** @copyright + ** This program 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. + ** + ** This program 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 this program. If not, see . + ** + *************************************************************************/ + +#include "vstringproperty.h" + +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + + +VPE::VStringProperty::VStringProperty(const QString &name, const QMap &settings) + : VProperty(name, QVariant::String), readOnly(false) +{ + VProperty::setSettings(settings); + d_ptr->VariantValue.setValue(QStringLiteral("")); + d_ptr->VariantValue.convert(QVariant::String); +} + +VPE::VStringProperty::VStringProperty(const QString &name) + : VProperty(name), readOnly(false) +{ + d_ptr->VariantValue.setValue(QStringLiteral("")); + d_ptr->VariantValue.convert(QVariant::String); +} + +QWidget *VPE::VStringProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options, + const QAbstractItemDelegate *delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + QLineEdit* tmpEditor = new QLineEdit(parent); + tmpEditor->setReadOnly(readOnly); + tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + tmpEditor->setText(d_ptr->VariantValue.toString()); + + d_ptr->editor = tmpEditor; + return d_ptr->editor; +} + +QVariant VPE::VStringProperty::getEditorData(QWidget *editor) const +{ + QLineEdit* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->text(); + + return QVariant(QStringLiteral("")); +} + +void VPE::VStringProperty::setReadOnly(bool readOnly) +{ + this->readOnly = readOnly; +} + +void VPE::VStringProperty::setSetting(const QString &key, const QVariant &value) +{ + if(key == "ReadOnly") + setReadOnly(value.toBool()); +} + +QVariant VPE::VStringProperty::getSetting(const QString &key) const +{ + if(key == "ReadOnly") + return readOnly; + else + return VProperty::getSetting(key); +} + +QStringList VPE::VStringProperty::getSettingKeys() const +{ + return QStringList("ReadOnly"); +} + +QString VPE::VStringProperty::type() const +{ + return "string"; +} + +VPE::VProperty *VPE::VStringProperty::clone(bool include_children, VPE::VProperty *container) const +{ + return VProperty::clone(include_children, container ? container : new VStringProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h new file mode 100644 index 000000000..9edcf74fe --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -0,0 +1,75 @@ +/************************************************************************ + ** + ** @file vstringproperty.h + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @brief + ** @copyright + ** This program 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. + ** + ** This program 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 this program. If not, see . + ** + *************************************************************************/ + +#ifndef VSTRINGPROPERTY_H +#define VSTRINGPROPERTY_H + +#include "vpropertyexplorer_global.h" +#include "vproperty.h" + +namespace VPE { + + +//! Class for holding a string property +class VPROPERTYEXPLORERSHARED_EXPORT VStringProperty : public VProperty +{ +public: + VStringProperty(const QString& name, const QMap& settings); + + VStringProperty(const QString& name); + + //! 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); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + void setReadOnly(bool readOnly); + + //! Sets the settings. + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! 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; + +protected: + bool readOnly; +}; + +} +#endif // VSTRINGPROPERTY_H diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro index 4c998c79a..d87858fe8 100644 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.pro +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -34,7 +34,6 @@ SOURCES += \ vpropertyset.cpp \ vpropertytreeview.cpp \ vserializedproperty.cpp \ - vstandardpropertyFactory.cpp \ plugins/vwidgetproperty.cpp \ plugins/vemptyproperty.cpp \ plugins/vboolproperty.cpp \ @@ -46,7 +45,9 @@ SOURCES += \ plugins/vcolorpropertyeditor.cpp \ plugins/vfilepropertyeditor.cpp \ plugins/vnumberproperty.cpp \ - plugins/Vector3d/vvector3dproperty.cpp + plugins/Vector3d/vvector3dproperty.cpp \ + vstandardpropertyfactory.cpp \ + plugins/vstringproperty.cpp HEADERS +=\ vpropertyexplorer_global.h \ @@ -81,7 +82,8 @@ HEADERS +=\ plugins/vnumberproperty.h \ plugins/Vector3d/vvector3dproperty.h \ vpropertyfactorymanager.h \ - vserializedproperty.h + vserializedproperty.h \ + plugins/vstringproperty.h unix { target.path = /usr/lib diff --git a/src/libs/vpropertyexplorer/vstandardpropertyFactory.cpp b/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp similarity index 100% rename from src/libs/vpropertyexplorer/vstandardpropertyFactory.cpp rename to src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp diff --git a/src/libs/vpropertyexplorer/vstandardpropertyfactory.h b/src/libs/vpropertyexplorer/vstandardpropertyfactory.h index b095c3641..b8bc877fe 100644 --- a/src/libs/vpropertyexplorer/vstandardpropertyfactory.h +++ b/src/libs/vpropertyexplorer/vstandardpropertyfactory.h @@ -10,7 +10,7 @@ class VProperty; class VPropertyFactoryManager; -//! The standard property factory is able to create all the properties that are included in QtPropertyExplorer +//! The standard property factory is able to create all the properties that are included in VPropertyExplorer //! by default. class VPROPERTYEXPLORERSHARED_EXPORT VStandardPropertyFactory : public VAbstractPropertyFactory { From c48c6276823f603e1857fae4cbb63ab78ebf2aa8 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 27 Aug 2014 15:39:54 +0300 Subject: [PATCH 11/52] New property for point type. --HG-- branch : feature --- .../widgets/vtooloptionspropertybrowser.cpp | 45 +++--- .../plugins/Vector3d/vvector3dproperty.h | 3 +- .../plugins/vpointfproperty.cpp | 129 ++++++++++++++++++ .../plugins/vpointfproperty.h | 71 ++++++++++ .../plugins/vstringproperty.cpp | 17 +-- .../plugins/vstringproperty.h | 17 +-- .../vpropertyexplorer/vpropertyexplorer.pro | 6 +- .../vpropertyexplorer/vpropertyformview.cpp | 2 +- 8 files changed, 240 insertions(+), 50 deletions(-) create mode 100644 src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp create mode 100644 src/libs/vpropertyexplorer/plugins/vpointfproperty.h diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index a2f2fa7ed..9ed2b58dd 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -34,6 +34,7 @@ #include "visualization/vcontrolpointspline.h" #include "../libs/vpropertyexplorer/plugins/vnumberproperty.h" #include "../libs/vpropertyexplorer/plugins/vstringproperty.h" +#include "../libs/vpropertyexplorer/plugins/vpointfproperty.h" #include #include @@ -88,9 +89,17 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) { - if (!propertyToId.contains(property)) + VProperty *prop = property; + if (!propertyToId.contains(prop)) { - return; + if (!propertyToId.contains(prop->getParent()))// Maybe we know parent + { + return; + } + else + { + prop = prop->getParent(); + } } if (!currentItem) @@ -98,9 +107,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) return; } - QVariant variant = property->data(VProperty::DPC_Data); + QVariant variant = prop->data(VProperty::DPC_Data); - QString id = propertyToId[property]; + QString id = propertyToId[prop]; switch (currentItem->type()) { case VToolSinglePoint::Type: @@ -125,13 +134,9 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } } } - else if (id == QLatin1String("posX")) + else if (id == QLatin1String("position")) { - currentItem->setX(variant.toDouble()); - } - else if (id == QLatin1String("posY")) - { - currentItem->setY(variant.toDouble()); + currentItem->setPos(variant.toPointF()); } break; } @@ -161,8 +166,7 @@ void VToolOptionsPropertyBrowser::UpdateOptions() { VToolSinglePoint *i = qgraphicsitem_cast(currentItem); idToProperty[QLatin1String("name")]->setValue(i->name()); - idToProperty[QLatin1String("posX")]->setValue(i->x()); - idToProperty[QLatin1String("posY")]->setValue(i->y()); + idToProperty[QLatin1String("position")]->setValue(i->pos()); break; } case VGraphicsSimpleTextItem::Type: @@ -181,7 +185,7 @@ void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString { propertyToId[property] = id; idToProperty[id] = property; - PropertyModel->addProperty(property, QLatin1String("name")); + PropertyModel->addProperty(property, id); } //--------------------------------------------------------------------------------------------------------------------- @@ -199,18 +203,9 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) itemName->setValue(i->name()); AddProperty(itemName, QLatin1String("name")); - VDoubleProperty* positionX = new VDoubleProperty(tr("Position X")); - positionX->setValue(i->x()); - AddProperty(positionX, QLatin1String("posX")); - - VDoubleProperty* positionY = new VDoubleProperty(tr("Position Y")); - positionY->setValue(i->y()); - AddProperty(positionY, QLatin1String("posY")); - -// QtVariantProperty *position = variantManager->addProperty(QVariant::PointF, tr("Position")); -// position->setValue(i->pos()); -// AddProperty(position, QLatin1String("position")); -// mainGroup->addSubProperty(position); + VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); + itemPosition->setValue(i->pos()); + AddProperty(itemPosition, QLatin1String("position")); break; } case VGraphicsSimpleTextItem::Type: diff --git a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h index 12eb17aeb..56f343639 100644 --- a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h +++ b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h @@ -31,8 +31,7 @@ public: Q_DECLARE_METATYPE(QPE::Vector3D) // todo - -namespace QPE{*/ +*/ class VPROPERTYEXPLORERSHARED_EXPORT QVector3DProperty : public VProperty { diff --git a/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp b/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp new file mode 100644 index 000000000..8d923502d --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp @@ -0,0 +1,129 @@ +/************************************************************************ + ** + ** @file vpointfproperty.cpp + ** @author Roman Telezhynskyi + ** @date 27 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 "vpointfproperty.h" + +using namespace VPE; + +#include "vproperty_p.h" +#include "vnumberproperty.h" +#include + +VPE::VPointFProperty::VPointFProperty(const QString &name) + : VProperty(name, QVariant::PointF) +{ + d_ptr->VariantValue.setValue(0); + d_ptr->VariantValue.convert(QVariant::PointF); + + VDoubleProperty* tmpX = new VDoubleProperty("X"); + addChild(tmpX); + tmpX->setUpdateBehaviour(true, false); + + VDoubleProperty* tmpY = new VDoubleProperty("Y"); + addChild(tmpY); + tmpY->setUpdateBehaviour(true, false); + + setValue(QPointF()); +} + +QVariant VPointFProperty::data(int column, int role) const +{ + if(column == DPC_Data && Qt::DisplayRole == role) + { + return getPointF(); + } + else + return VProperty::data(column, role); +} + +Qt::ItemFlags VPointFProperty::flags(int column) const +{ + if(column == DPC_Name || column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + +QPointF VPointFProperty::getPointF() const +{ + QPointF tmpValue; + + if(d_ptr->Children.count() < 2) + return tmpValue; + + tmpValue.setX(d_ptr->Children.at(0)->getValue().toDouble()); + tmpValue.setY(d_ptr->Children.at(1)->getValue().toDouble()); + + return tmpValue; +} + +void VPointFProperty::setPointF(const QPointF &point) +{ + setPointF(point.x(), point.y()); +} + +void VPointFProperty::setPointF(qreal x, qreal y) +{ + if(d_ptr->Children.count() < 2) + return; + + QVariant tmpX(x); + tmpX.convert(QVariant::Double); + + QVariant tmpY(y); + tmpY.convert(QVariant::Double); + + d_ptr->Children.at(0)->setValue(tmpX); + d_ptr->Children.at(1)->setValue(tmpY); +} + +QString VPointFProperty::type() const +{ + return "pointF"; +} + +VProperty *VPointFProperty::clone(bool include_children, VProperty *container) const +{ + if(!container) { + container = new VPointFProperty(getName()); + + if(!include_children) { + QList tmpChildren = container->getChildren(); + foreach(VProperty* tmpChild, tmpChildren) { + container->removeChild(tmpChild); + delete tmpChild; + } + } + } + + return VProperty::clone(false, container); // Child +} + +void VPointFProperty::setValue(const QVariant &value) +{ + QPointF tmpPoint = value.toPointF(); + setPointF(tmpPoint); +} + +QVariant VPointFProperty::getValue() const +{ + QPointF tmpValue = getPointF(); + return QString("%1,%2").arg(QString::number(tmpValue.x()), QString::number(tmpValue.y())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vpointfproperty.h b/src/libs/vpropertyexplorer/plugins/vpointfproperty.h new file mode 100644 index 000000000..2029dd304 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vpointfproperty.h @@ -0,0 +1,71 @@ +/************************************************************************ + ** + ** @file vpointfproperty.h + ** @author Roman Telezhynskyi + ** @date 27 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 VPOINTFPROPERTY_H +#define VPOINTFPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VPointFProperty : public VProperty +{ +public: + VPointFProperty(const QString& name); + + virtual ~VPointFProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns item flags + Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns the QPointF + virtual QPointF getPointF() const; + + //! Sets the QPointF + virtual void setPointF(const QPointF& point); + + //! Sets the QPointF + virtual void setPointF(qreal x, qreal y); + + //! 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 = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + +}; + +} + +#endif // VPOINTFPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp index 5803dbf61..00cd08061 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -6,18 +6,15 @@ ** ** @brief ** @copyright - ** This program 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. + ** 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 program is distributed in the hope that it will be useful, + ** 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 General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. ** *************************************************************************/ diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h index 9edcf74fe..5182e8e69 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -6,18 +6,15 @@ ** ** @brief ** @copyright - ** This program 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. + ** 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 program is distributed in the hope that it will be useful, + ** 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 General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with this program. If not, see . + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + ** Lesser General Public License for more details. ** *************************************************************************/ diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro index d87858fe8..8e41c380a 100644 --- a/src/libs/vpropertyexplorer/vpropertyexplorer.pro +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -47,7 +47,8 @@ SOURCES += \ plugins/vnumberproperty.cpp \ plugins/Vector3d/vvector3dproperty.cpp \ vstandardpropertyfactory.cpp \ - plugins/vstringproperty.cpp + plugins/vstringproperty.cpp \ + plugins/vpointfproperty.cpp HEADERS +=\ vpropertyexplorer_global.h \ @@ -83,7 +84,8 @@ HEADERS +=\ plugins/Vector3d/vvector3dproperty.h \ vpropertyfactorymanager.h \ vserializedproperty.h \ - plugins/vstringproperty.h + plugins/vstringproperty.h \ + plugins/vpointfproperty.h unix { target.path = /usr/lib diff --git a/src/libs/vpropertyexplorer/vpropertyformview.cpp b/src/libs/vpropertyexplorer/vpropertyformview.cpp index a11061f70..a443ee250 100644 --- a/src/libs/vpropertyexplorer/vpropertyformview.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformview.cpp @@ -121,7 +121,7 @@ void VPropertyFormView::dataSubmitted(VProperty *property) if(tmpModel && d_ptr->UpdateEditors) { static_cast(d_ptr)->IgnoreDataChangedSignal = true; - //tmpModel->onDataChangedByModel(property); + tmpModel->onDataChangedByModel(property); tmpModel->showDataChangedByEditor(property); static_cast(d_ptr)->IgnoreDataChangedSignal = false; From a8a99febf4062ae8b25ae5271c16840ddb4f1be5 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 28 Aug 2014 11:17:36 +0300 Subject: [PATCH 12/52] Fix calling multiple time slot VPropertyFormView::dataSubmitted. --HG-- branch : feature --- .../widgets/vtooloptionspropertybrowser.cpp | 10 ++++ .../plugins/venumproperty.cpp | 31 +++++++++--- .../vpropertyexplorer/plugins/venumproperty.h | 6 ++- .../plugins/vnumberproperty.cpp | 48 ++++++++++++------- .../plugins/vnumberproperty.h | 7 ++- .../vpropertyexplorer/vpropertyformview.cpp | 5 +- .../vpropertyexplorer/vpropertyformwidget.cpp | 9 +++- src/libs/vpropertyexplorer/vpropertymodel.cpp | 6 +-- src/libs/vpropertyexplorer/vpropertymodel.h | 2 - 9 files changed, 84 insertions(+), 40 deletions(-) diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 9ed2b58dd..558cb9024 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -35,6 +35,7 @@ #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 #include @@ -138,6 +139,10 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) { currentItem->setPos(variant.toPointF()); } +// else if (id == QLatin1String("list")) +// { +// qDebug()<data(VProperty::DPC_Data, Qt::DisplayRole); +// } break; } // case VGraphicsSimpleTextItem::Type: @@ -206,6 +211,11 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); itemPosition->setValue(i->pos()); AddProperty(itemPosition, QLatin1String("position")); + +// VEnumProperty *enumProperty = new VEnumProperty(tr("list")); +// QStringList list = QStringList()<<"a1"<<"a2"<<"a3"; +// enumProperty->setLiterals(list); +// AddProperty(enumProperty, QLatin1String("list")); break; } case VGraphicsSimpleTextItem::Type: diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp index b8285235e..e03504bbb 100644 --- a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp @@ -2,14 +2,15 @@ #include "vproperty_p.h" #include +#include using namespace VPE; VEnumProperty::VEnumProperty(const QString& name) - : VProperty(name, QVariant::Int) + : QObject(), VProperty(name, QVariant::Int) { - d_ptr->VariantValue = 0; - d_ptr->VariantValue.convert(QVariant::Int); + VProperty::d_ptr->VariantValue = 0; + VProperty::d_ptr->VariantValue.convert(QVariant::Int); } @@ -19,7 +20,7 @@ QVariant VEnumProperty::data (int column, int role) const if(EnumerationLiterals.empty()) return QVariant(); - int tmpIndex = d_ptr->VariantValue.toInt(); + int tmpIndex = VProperty::d_ptr->VariantValue.toInt(); if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) tmpIndex = 0; @@ -41,9 +42,12 @@ QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewIte QComboBox* tmpEditor = new QComboBox(parent); tmpEditor->clear(); tmpEditor->addItems(EnumerationLiterals); - tmpEditor->setCurrentIndex(d_ptr->VariantValue.toInt()); + tmpEditor->setCurrentIndex(VProperty::d_ptr->VariantValue.toInt()); + connect(tmpEditor, static_cast(&QComboBox::currentIndexChanged), this, + &VEnumProperty::currentIndexChanged); - return tmpEditor; + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; } //! Gets the data from the widget @@ -76,7 +80,13 @@ void VEnumProperty::setValue(const QVariant& value) if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) tmpIndex = 0; - d_ptr->VariantValue.setValue(tmpIndex); + VProperty::d_ptr->VariantValue = tmpIndex; + VProperty::d_ptr->VariantValue.convert(QVariant::Int); + + if (VProperty::d_ptr->editor != nullptr) + { + setEditorData(VProperty::d_ptr->editor); + } } QString VEnumProperty::type() const @@ -107,3 +117,10 @@ QStringList VEnumProperty::getSettingKeys() const { return QStringList("literals"); } + +void VEnumProperty::currentIndexChanged(int index) +{ + Q_UNUSED(index) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.h b/src/libs/vpropertyexplorer/plugins/venumproperty.h index 72748529d..c43761bf2 100644 --- a/src/libs/vpropertyexplorer/plugins/venumproperty.h +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.h @@ -7,8 +7,9 @@ namespace VPE{ -class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public QObject, public VProperty { + Q_OBJECT public: //! Constructor VEnumProperty(const QString& name); @@ -57,6 +58,9 @@ public: //! Returns the list of keys of the property's settings virtual QStringList getSettingKeys() const; +public slots: + void currentIndexChanged(int index); + protected: //! The list of possible options to choose frome QStringList EnumerationLiterals; diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp index 9ec0e7ccf..07fb5cf65 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "vproperty_p.h" @@ -13,18 +14,18 @@ const int VIntegerProperty::StandardMin = -1000000; const int VIntegerProperty::StandardMax = 1000000; VIntegerProperty::VIntegerProperty(const QString& name, const QMap& settings) - : VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) + : QObject(), VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) { VProperty::setSettings(settings); - d_ptr->VariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Int); + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Int); } VIntegerProperty::VIntegerProperty(const QString &name) - : VProperty(name), Min(StandardMin), Max(StandardMax) + : QObject(), VProperty(name), Min(StandardMin), Max(StandardMax) { - d_ptr->VariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Int); + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Int); } //! Returns an editor widget, or NULL if it doesn't supply one @@ -37,10 +38,12 @@ QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionView tmpEditor->setMinimum(Min); tmpEditor->setMaximum(Max); tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - tmpEditor->setValue(d_ptr->VariantValue.toInt()); + tmpEditor->setValue(VProperty::d_ptr->VariantValue.toInt()); + connect(tmpEditor, static_cast(&QSpinBox::valueChanged), this, + &VIntegerProperty::valueChanged); - d_ptr->editor = tmpEditor; - return d_ptr->editor; + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; } //! Gets the data from the widget @@ -92,6 +95,13 @@ VProperty* VIntegerProperty::clone(bool include_children, VProperty* container) return VProperty::clone(include_children, container ? container : new VIntegerProperty(getName())); } +void VIntegerProperty::valueChanged(int i) +{ + Q_UNUSED(i) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} + @@ -102,17 +112,17 @@ VDoubleProperty::VDoubleProperty(const QString& name, const QMapVariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Double); - d_ptr->PropertyVariantType = QVariant::Double; + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Double); + VProperty::d_ptr->PropertyVariantType = QVariant::Double; } VDoubleProperty::VDoubleProperty(const QString &name) : VIntegerProperty(name), Precision(StandardPrecision) { - d_ptr->VariantValue.setValue(0); - d_ptr->VariantValue.convert(QVariant::Double); - d_ptr->PropertyVariantType = QVariant::Double; + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Double); + VProperty::d_ptr->PropertyVariantType = QVariant::Double; } //! Returns an editor widget, or NULL if it doesn't supply one @@ -125,10 +135,12 @@ QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewI tmpEditor->setMaximum(Max); tmpEditor->setDecimals(Precision); tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - tmpEditor->setValue(d_ptr->VariantValue.toDouble()); + tmpEditor->setValue(VProperty::d_ptr->VariantValue.toDouble()); + connect(tmpEditor, static_cast(&QDoubleSpinBox::valueChanged), this, + &VIntegerProperty::valueChanged); - d_ptr->editor = tmpEditor; - return d_ptr->editor; + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; } //! Gets the data from the widget diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h index fa4fbcf4b..155357933 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h @@ -8,8 +8,9 @@ namespace VPE { //! Class for holding an integer property -class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public QObject, public VProperty { + Q_OBJECT public: VIntegerProperty(const QString& name, const QMap& settings); @@ -49,7 +50,8 @@ public: //! \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 = NULL) const; - +public slots: + void valueChanged(int i); protected: int Min, Max; @@ -61,6 +63,7 @@ protected: //! Class for holding a double property class VPROPERTYEXPLORERSHARED_EXPORT VDoubleProperty : public VIntegerProperty { + Q_OBJECT public: VDoubleProperty(const QString& name, const QMap& settings); diff --git a/src/libs/vpropertyexplorer/vpropertyformview.cpp b/src/libs/vpropertyexplorer/vpropertyformview.cpp index a443ee250..2661aec7c 100644 --- a/src/libs/vpropertyexplorer/vpropertyformview.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformview.cpp @@ -122,8 +122,6 @@ void VPropertyFormView::dataSubmitted(VProperty *property) if(tmpModel && d_ptr->UpdateEditors) { static_cast(d_ptr)->IgnoreDataChangedSignal = true; tmpModel->onDataChangedByModel(property); - tmpModel->showDataChangedByEditor(property); - static_cast(d_ptr)->IgnoreDataChangedSignal = false; } } @@ -171,7 +169,8 @@ void VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget) if(!widget) return; - connect(widget, SIGNAL(propertyDataSubmitted(VProperty*)), this, SLOT(dataSubmitted(VProperty*))); + connect(widget, &VPropertyFormWidget::propertyDataSubmitted, this, &VPropertyFormView::dataSubmitted, + Qt::UniqueConnection); QList tmpList = widget->getChildPropertyFormWidgets(); foreach(VPropertyFormWidget* tmpEditorWidget, tmpList) { diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp index 45b35f33e..ef0f17937 100644 --- a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp @@ -7,6 +7,7 @@ #include #include #include "vproperty.h" +#include using namespace VPE; @@ -125,10 +126,10 @@ void VPropertyFormWidget::commitData(int row) tmpEditorWidget.FormWidget->commitData(); else if(tmpEditorWidget.Editor && tmpProperty) { QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor); - QVariant oldValue = tmpProperty->data(VProperty::DPC_Data); + QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole); if (oldValue != newValue) { - tmpProperty->setValue(tmpProperty->getEditorData(tmpEditorWidget.Editor)); + tmpProperty->setValue(newValue); emit propertyDataSubmitted(tmpProperty); } } @@ -205,6 +206,10 @@ bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event) event->accept(); return true; } + else + { + return QGroupBox::eventFilter(object, event); + } // Default: return false; diff --git a/src/libs/vpropertyexplorer/vpropertymodel.cpp b/src/libs/vpropertyexplorer/vpropertymodel.cpp index 368689200..1cb82a24f 100644 --- a/src/libs/vpropertyexplorer/vpropertymodel.cpp +++ b/src/libs/vpropertyexplorer/vpropertymodel.cpp @@ -230,14 +230,10 @@ void VPropertyModel::onDataChangedByModel(VProperty* property) if(tmpIndex.isValid()) { emit dataChanged(tmpIndex, tmpIndex); + emit onDataChangedByEditor(property); } } -void VPropertyModel::showDataChangedByEditor(VProperty *property) -{ - emit onDataChangedByEditor(property); -} - const VPropertySet *VPropertyModel::getPropertySet() const { return d_ptr->Properties; diff --git a/src/libs/vpropertyexplorer/vpropertymodel.h b/src/libs/vpropertyexplorer/vpropertymodel.h index 59de7b4a6..fb9df7a39 100644 --- a/src/libs/vpropertyexplorer/vpropertymodel.h +++ b/src/libs/vpropertyexplorer/vpropertymodel.h @@ -124,8 +124,6 @@ public slots: //! This function causes the views to update the property void onDataChangedByModel(VProperty* property); - void showDataChangedByEditor(VProperty* property); - protected: //! Gets a property by its ModelIndex virtual QModelIndex getIndexFromProperty(VProperty* property, int column = 0) const; From a9667aac092c2c68f51c9620d5c0b80d01fa1bda Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 28 Aug 2014 14:05:58 +0300 Subject: [PATCH 13/52] 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 From 37ec49065ab4dc45820254827665d5a24dc732d9 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 28 Aug 2014 14:23:28 +0300 Subject: [PATCH 14/52] Show line type for tool endLine. --HG-- branch : feature --- src/app/tools/vabstracttool.cpp | 2 +- src/app/tools/vabstracttool.h | 2 +- .../widgets/vtooloptionspropertybrowser.cpp | 23 ++++++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 452b6d859..3dea9ee93 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -289,7 +289,7 @@ Qt::PenStyle VAbstractTool::LineStyle(const QString &typeLine) break; } } -QString VAbstractTool::getTypeLine() const +QString VAbstractTool::getLineType() const { return typeLine; } diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index 74ab724b7..b945ec805 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -101,7 +101,7 @@ public: static Qt::PenStyle LineStyle(const QString &typeLine); const VContainer *getData() const; - QString getTypeLine() const; + QString getLineType() const; //void setTypeLine(const QString &value)=0; QMap PointsList() const; public slots: diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 8893b4b6e..787821ded 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -128,15 +128,20 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } case VToolEndLine::Type: { + VToolEndLine *i = qgraphicsitem_cast(currentItem); if (id == QLatin1String("name")) { SetPointName(variant.toString()); } else if (id == QLatin1String("basePoint")) { - VToolEndLine *i = qgraphicsitem_cast(currentItem); i->setBasePointId(variant.toUInt()); } + else if (id == QLatin1String("lineType")) + { + + i->setTypeLine(variant.toString()); + } break; } default: @@ -194,6 +199,10 @@ void VToolOptionsPropertyBrowser::UpdateOptions() idToProperty[QLatin1String("name")]->setValue(i->name()); idToProperty[QLatin1String("basePoint")]->setValue(i->getBasePointId()); + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[QLatin1String("lineType")]->setValue(index); + break; } case VGraphicsSimpleTextItem::Type: @@ -240,7 +249,7 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { VToolEndLine *i = qgraphicsitem_cast(item); QDockWidget *parent = qobject_cast(this->parent()); - parent->setWindowTitle(tr("Tool options (End of line)")); + parent->setWindowTitle(tr("Tool options (Point at distance and angle)")); VProperty* itemName = new VProperty(tr("Point name")); itemName->setValue(i->name()); @@ -252,10 +261,12 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) pointsProperty->setValue(i->getBasePointId()); AddProperty(pointsProperty, QLatin1String("basePoint")); -// VEnumProperty *enumProperty = new VEnumProperty(tr("list")); -// QStringList list = QStringList()<<"a1"<<"a2"<<"a3"; -// enumProperty->setLiterals(list); -// AddProperty(enumProperty, QLatin1String("list")); + VEnumProperty *lineTypeProperty = new VEnumProperty(tr("Line type")); + lineTypeProperty->setLiterals(VAbstractTool::Styles()); + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + lineTypeProperty->setValue(index); + AddProperty(lineTypeProperty, QLatin1String("lineType")); break; } case VGraphicsSimpleTextItem::Type: From 2b83e18773895486205ce654a57f1e666c86c841 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 29 Aug 2014 12:19:11 +0300 Subject: [PATCH 15/52] New property formula. --HG-- branch : feature --- src/app/container/container.pri | 6 +- src/app/container/vformula.cpp | 238 ++++++++++++++++++ src/app/container/vformula.h | 80 ++++++ src/app/dialogs/tools/dialogarc.ui | 3 + .../dialogs/tools/dialogeditwrongformula.cpp | 29 ++- .../dialogs/tools/dialogeditwrongformula.h | 6 + src/app/widgets/vformulaproperty.cpp | 207 +++++++++++++++ src/app/widgets/vformulaproperty.h | 88 +++++++ src/app/widgets/vformulapropertyeditor.cpp | 127 ++++++++++ src/app/widgets/vformulapropertyeditor.h | 78 ++++++ .../widgets/vtooloptionspropertybrowser.cpp | 27 +- src/app/widgets/widgets.pri | 8 +- .../plugins/vcolorproperty.cpp | 16 +- .../plugins/vcolorproperty.h | 4 +- .../plugins/venumproperty.cpp | 2 +- .../vpropertyexplorer/plugins/venumproperty.h | 2 +- .../plugins/vnumberproperty.cpp | 4 +- .../plugins/vnumberproperty.h | 2 +- .../plugins/vobjectproperty.cpp | 2 +- .../plugins/vobjectproperty.h | 2 +- .../plugins/vstringproperty.cpp | 36 ++- .../plugins/vstringproperty.h | 6 + src/libs/vpropertyexplorer/vproperty.cpp | 17 +- src/libs/vpropertyexplorer/vproperty.h | 12 +- src/libs/vpropertyexplorer/vproperty_p.h | 4 +- .../vpropertyexplorer/vpropertyformwidget.cpp | 103 ++++++-- .../vpropertyexplorer/vpropertyformwidget.h | 4 + .../vstandardpropertyfactory.cpp | 2 +- 28 files changed, 1051 insertions(+), 64 deletions(-) create mode 100644 src/app/container/vformula.cpp create mode 100644 src/app/container/vformula.h create mode 100644 src/app/widgets/vformulaproperty.cpp create mode 100644 src/app/widgets/vformulaproperty.h create mode 100644 src/app/widgets/vformulapropertyeditor.cpp create mode 100644 src/app/widgets/vformulapropertyeditor.h diff --git a/src/app/container/container.pri b/src/app/container/container.pri index 758aaf921..2c1e50367 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -9,7 +9,8 @@ SOURCES += \ container/varclength.cpp \ container/vcurvelength.cpp \ container/vlinelength.cpp \ - container/vsplinelength.cpp + container/vsplinelength.cpp \ + container/vformula.cpp HEADERS += \ container/vcontainer.h \ @@ -30,4 +31,5 @@ HEADERS += \ container/vcurvelength_p.h \ container/vlineangle_p.h \ container/vlinelength_p.h \ - container/vmeasurement_p.h + container/vmeasurement_p.h \ + container/vformula.h diff --git a/src/app/container/vformula.cpp b/src/app/container/vformula.cpp new file mode 100644 index 000000000..eb3cf4d0d --- /dev/null +++ b/src/app/container/vformula.cpp @@ -0,0 +1,238 @@ +/************************************************************************ + ** + ** @file vformula.cpp + ** @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 . + ** + *************************************************************************/ + +#include "vformula.h" +#include "../container/calculator.h" +#include "../container/vcontainer.h" +#include "../widgets/vapplication.h" + +//VFormula +//--------------------------------------------------------------------------------------------------------------------- +VFormula::VFormula() + :formula(QString()), value(QString(tr("Error"))), checkZero(true), data(nullptr), toolId(NULL_ID), + postfix(QStringLiteral("")), _error(true) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula::VFormula(const QString &formula, const VContainer *container) + :formula(formula), value(QString(tr("Error"))), checkZero(true), data(container), toolId(NULL_ID), + postfix(QStringLiteral("")), _error(true) +{ + this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist + Eval(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula &VFormula::operator=(const VFormula &formula) +{ + if ( &formula == this ) + { + return *this; + } + this->formula = formula.getFormula(); + this->value = formula.getValue(); + this->checkZero = formula.getCheckZero(); + this->data = formula.getData(); + this->toolId = formula.getToolId(); + this->postfix = formula.getPostfix(); + this->_error = formula.error(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula::VFormula(const VFormula &formula) + :formula(formula.getFormula()), value(formula.getValue()), checkZero(formula.getCheckZero()), + data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormula::operator==(const VFormula &formula) const +{ + bool isEqual = false; + if (this->formula == formula.getFormula() && this->value == formula.getValue() && + this->checkZero == formula.getCheckZero() && this->data == formula.getData() && + this->toolId == formula.getToolId() && this->postfix == formula.getPostfix() && + this->_error == formula.error()) + { + isEqual = true; + } + return isEqual; +} + +bool VFormula::operator!=(const VFormula &formula) const +{ + return !VFormula::operator==(formula); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormula::getFormula() const +{ + return formula; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setFormula(const QString &value) +{ + if (formula != value) + { + formula = value; + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormula::getValue() const +{ + return value; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormula::getCheckZero() const +{ + return checkZero; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setCheckZero(bool value) +{ + if (checkZero != value) + { + checkZero = value; + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +const VContainer *VFormula::getData() const +{ + return data; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setData(const VContainer *value) +{ + if (data != value && value != nullptr) + { + data = value; + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VFormula::getToolId() const +{ + return toolId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setToolId(const quint32 &value) +{ + toolId = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormula::getPostfix() const +{ + return postfix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setPostfix(const QString &value) +{ + if (postfix != value) + { + postfix = value; + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormula::error() const +{ + return _error; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VFormula::FormulaTypeId() +{ + return qMetaTypeId(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::Eval() +{ + if (data == nullptr) + { + return; + } + if (formula.isEmpty()) + { + value = QString(tr("Error")); + _error = true; + } + else + { + try + { + Calculator *cal = new Calculator(data); + const qreal result = cal->EvalFormula(formula); + delete cal; + + //if result equal 0 + if (checkZero && qFuzzyCompare(1 + result, 1 + 0)) + { + value = QString("0"); + _error = true; + } + else + { + QLocale loc; + if (qApp->getSettings()->value("configuration/osSeparator", 1).toBool()) + { + loc = QLocale::system(); + } + else + { + loc = QLocale(QLocale::C); + } + value = QString(loc.toString(result) + " " + postfix); + _error = false; + } + } + catch (qmu::QmuParserError &e) + { + value = QString(tr("Error")); + _error = true; + qDebug() << "\nMath parser error:\n" + << "--------------------------------------\n" + << "Message: " << e.GetMsg() << "\n" + << "Expression: " << e.GetExpr() << "\n" + << "--------------------------------------"; + } + } +} diff --git a/src/app/container/vformula.h b/src/app/container/vformula.h new file mode 100644 index 000000000..c624ed829 --- /dev/null +++ b/src/app/container/vformula.h @@ -0,0 +1,80 @@ +/************************************************************************ + ** + ** @file vformula.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 VFORMULA_H +#define VFORMULA_H + +#include + +class VContainer; + +class VFormula +{ + Q_DECLARE_TR_FUNCTIONS(VFormula) +public: + VFormula(); + VFormula(const QString &formula, const VContainer *container); + VFormula &operator=(const VFormula &formula); + VFormula(const VFormula &formula); + bool operator==(const VFormula &formula) const; + bool operator!=(const VFormula &formula) const; + + QString getFormula() const; + void setFormula(const QString &value); + + QString getValue() const; + + bool getCheckZero() const; + void setCheckZero(bool value); + + const VContainer *getData() const; + void setData(const VContainer *value); + + quint32 getToolId() const; + void setToolId(const quint32 &value); + + QString getPostfix() const; + void setPostfix(const QString &value); + + bool error() const; + + static int FormulaTypeId(); +private: + QString formula; + QString value; + bool checkZero; + const VContainer *data; + quint32 toolId; + QString postfix; + bool _error; + + void Eval(); +}; +Q_DECLARE_METATYPE(VFormula) + +#endif // VFORMULA_H diff --git a/src/app/dialogs/tools/dialogarc.ui b/src/app/dialogs/tools/dialogarc.ui index 8689df614..9e751d4ee 100644 --- a/src/app/dialogs/tools/dialogarc.ui +++ b/src/app/dialogs/tools/dialogarc.ui @@ -522,6 +522,9 @@ + + 9 + diff --git a/src/app/dialogs/tools/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index 34b7e8c6a..3c2797d95 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -31,7 +31,8 @@ //--------------------------------------------------------------------------------------------------------------------- DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0) + :DialogTool(data, toolId, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0), + checkZero(false), postfix(QStringLiteral("")), restoreCursor(false) { ui->setupUi(this); InitVariables(ui); @@ -51,7 +52,11 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const qui //Disable Qt::WaitCursor #ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); + if (QApplication::overrideCursor()->shape() == Qt::WaitCursor) + { + restoreCursor = true; + QApplication::restoreOverrideCursor(); + } #endif } @@ -59,7 +64,10 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const qui DialogEditWrongFormula::~DialogEditWrongFormula() { #ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); + if (restoreCursor) + { + QApplication::setOverrideCursor(Qt::WaitCursor); + } #endif delete ui; } @@ -91,8 +99,7 @@ void DialogEditWrongFormula::EvalFormula() { SCASSERT(plainTextEditFormula != nullptr); SCASSERT(labelResultCalculation != nullptr); - const QString postfix = QStringLiteral(""); - Eval(plainTextEditFormula->toPlainText(), flagFormula, timerFormula, labelResultCalculation, postfix); + Eval(plainTextEditFormula->toPlainText(), flagFormula, timerFormula, labelResultCalculation, postfix, checkZero); } //--------------------------------------------------------------------------------------------------------------------- @@ -115,6 +122,18 @@ void DialogEditWrongFormula::setFormula(const QString &value) ui->plainTextEditFormula->setPlainText(formula); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditWrongFormula::setCheckZero(bool value) +{ + checkZero = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditWrongFormula::setPostfix(const QString &value) +{ + postfix = value; +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogEditWrongFormula::getFormula() const { diff --git a/src/app/dialogs/tools/dialogeditwrongformula.h b/src/app/dialogs/tools/dialogeditwrongformula.h index 5e070c2b0..8a6de06e9 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.h +++ b/src/app/dialogs/tools/dialogeditwrongformula.h @@ -53,6 +53,8 @@ public: QString getFormula() const; void setFormula(const QString &value); + void setCheckZero(bool value); + void setPostfix(const QString &value); public slots: virtual void DialogAccepted(); virtual void DialogRejected(); @@ -72,6 +74,10 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + bool checkZero; + QString postfix; + bool restoreCursor; }; diff --git a/src/app/widgets/vformulaproperty.cpp b/src/app/widgets/vformulaproperty.cpp new file mode 100644 index 000000000..752a8103b --- /dev/null +++ b/src/app/widgets/vformulaproperty.cpp @@ -0,0 +1,207 @@ +/************************************************************************ + ** + ** @file vformulaproperty.cpp + ** @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 . + ** + *************************************************************************/ + +#include "vformulaproperty.h" +#include "vformulapropertyeditor.h" + +#include "../libs/vpropertyexplorer/vproperty_p.h" +#include "vformulapropertyeditor.h" +#include "../libs/vpropertyexplorer/vproperties.h" +#include "../container/vformula.h" + +enum class ChildType : char {Invalid = 0, Value = 1, Formula = 2}; + +using namespace VPE; + +//--------------------------------------------------------------------------------------------------------------------- +VFormulaProperty::VFormulaProperty(const QString &name) : + VProperty(name, static_cast(VFormula::FormulaTypeId())) +{ + d_ptr->type = Property::Complex; + + VStringProperty* tmpValue = new VStringProperty(QStringLiteral("Value")); + addChild(tmpValue); + tmpValue->setUpdateBehaviour(true, false); + tmpValue->setReadOnly(true); + tmpValue->setTypeForParent(static_cast(ChildType::Value)); + + VStringProperty* tmpFormula = new VStringProperty(QStringLiteral("Formula")); + addChild(tmpFormula); + tmpFormula->setUpdateBehaviour(true, false); + tmpFormula->setTypeForParent(static_cast(ChildType::Formula)); + + setValue(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Get the data how it should be displayed +QVariant VFormulaProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return getValue(); + else + return VProperty::data(column, role); +} + +Qt::ItemFlags VFormulaProperty::flags(int column) const +{ + if(column == DPC_Name || column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VFormulaProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, + const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + VFormula formula = VProperty::d_ptr->VariantValue.value(); + VFormulaPropertyEditor* tmpEditor = new VFormulaPropertyEditor(parent); + + tmpEditor->setFormula(formula); + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Sets the property's data to the editor (returns false, if the standard delegate should do that) +bool VFormulaProperty::setEditorData(QWidget* editor) +{ + VFormulaPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + { + VFormula formula = VProperty::d_ptr->VariantValue.value(); + tmpWidget->setFormula(formula); + } + else + return false; + + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Gets the data from the widget +QVariant VFormulaProperty::getEditorData(QWidget* editor) const +{ + VFormulaPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + { + QVariant value; + value.setValue(tmpWidget->getFormula()); + return value; + } + + return QVariant(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormulaProperty::type() const +{ + return "formula"; +} + +//--------------------------------------------------------------------------------------------------------------------- +VProperty *VFormulaProperty::clone(bool include_children, VProperty *container) const +{ + if(!container) { + container = new VFormulaProperty(getName()); + + if(!include_children) { + QList tmpChildren = container->getChildren(); + foreach(VProperty* tmpChild, tmpChildren) { + container->removeChild(tmpChild); + delete tmpChild; + } + } + } + + return VProperty::clone(false, container); // Child + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaProperty::setValue(const QVariant &value) +{ + VFormula tmpFormula = value.value(); + setFormula(tmpFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVariant VFormulaProperty::getValue() const +{ + VFormula tmpFormula = getFormula(); + QVariant value; + value.setValue(tmpFormula); + return value; +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VFormulaProperty::getFormula() const +{ + return VProperty::d_ptr->VariantValue.value(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaProperty::setFormula(const VFormula &formula) +{ + if(d_ptr->Children.count() < 2) + return; + + QVariant value; + value.setValue(formula); + value.convert(VFormula::FormulaTypeId()); + VProperty::d_ptr->VariantValue = value; + + QVariant tmpValue(formula.getValue()); + tmpValue.convert(QVariant::String); + + QVariant tmpFormula(formula.getFormula()); + tmpFormula.convert(QVariant::String); + + VProperty::d_ptr->Children.at(0)->setValue(tmpValue); + VProperty::d_ptr->Children.at(1)->setValue(tmpFormula); + + if (VProperty::d_ptr->editor != nullptr) + { + setEditorData(VProperty::d_ptr->editor); + } +} + +void VFormulaProperty::ValueChildChanged(const QVariant &value, int typeForParent) +{ + if (typeForParent == static_cast(ChildType::Formula)) + { + VFormula newFormula = getFormula(); + newFormula.setFormula(value.toString()); + setFormula(newFormula); + } +} diff --git a/src/app/widgets/vformulaproperty.h b/src/app/widgets/vformulaproperty.h new file mode 100644 index 000000000..848e698b8 --- /dev/null +++ b/src/app/widgets/vformulaproperty.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file vformulaproperty.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 VFORMULAPROPERTY_H +#define VFORMULAPROPERTY_H + +#include "../libs/vpropertyexplorer/vproperty.h" + +class VFormula; + +using namespace VPE; + +class VFormulaProperty : public VProperty +{ + +public: + VFormulaProperty(const QString &name); + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns item flags + Qt::ItemFlags flags(int column = DPC_Name) 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; + + //! 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 = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + + //! Returns the formula + virtual VFormula getFormula() const; + + //! Sets the formula + virtual void setFormula(const VFormula &formula); + +public slots: + virtual void ValueChildChanged(const QVariant &value, int typeForParent); + +}; + +#endif // VFORMULAPROPERTY_H diff --git a/src/app/widgets/vformulapropertyeditor.cpp b/src/app/widgets/vformulapropertyeditor.cpp new file mode 100644 index 000000000..baa7de4b6 --- /dev/null +++ b/src/app/widgets/vformulapropertyeditor.cpp @@ -0,0 +1,127 @@ +/************************************************************************ + ** + ** @file vformulapropertyeditor.cpp + ** @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 . + ** + *************************************************************************/ + +#include "vformulapropertyeditor.h" + +#include +#include +#include +#include +#include + +#include "../libs/vpropertyexplorer/vproperty.h" +#include "../dialogs/tools/dialogeditwrongformula.h" + +using namespace VPE; + +// VFormulaPropertyEditor +//--------------------------------------------------------------------------------------------------------------------- +VFormulaPropertyEditor::VFormulaPropertyEditor(QWidget *parent) : + QWidget(parent) +{ + setAutoFillBackground(true); + + // Create the tool button + ToolButton = new QToolButton(this); + ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); + ToolButton->setText(tr("...")); + ToolButton->setFixedWidth(20); + ToolButton->installEventFilter(this); + setFocusProxy(ToolButton); // Make the ToolButton the focus proxy + setFocusPolicy(ToolButton->focusPolicy()); + connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked())); + + // Create the text label + TextLabel = new QLabel(this); + TextLabel->setText(formula.getValue()); + + // Spacer (this is needed for proper display of the label and button) + Spacer = new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(3); + layout->setMargin(0); + layout->addWidget(TextLabel); + layout->addItem(Spacer); + layout->addWidget(ToolButton); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaPropertyEditor::setFormula(const VFormula& formula) +{ + if (this->formula != formula) + { + this->formula = formula; + TextLabel->setText(this->formula.getValue()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaPropertyEditor::onToolButtonClicked() +{ + DialogEditWrongFormula* tmpWidget = new DialogEditWrongFormula(formula.getData(), formula.getToolId()); + tmpWidget->setCheckZero(formula.getCheckZero()); + tmpWidget->setPostfix(formula.getPostfix()); + tmpWidget->setFormula(formula.getFormula()); + + if (tmpWidget->exec() == QDialog::Accepted) + { + formula.setFormula(tmpWidget->getFormula()); + TextLabel->setText(formula.getValue()); + delete tmpWidget; + emit dataChangedByUser(formula, this); + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( this, event ); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormulaPropertyEditor::eventFilter(QObject *obj, QEvent *ev) +{ + if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress)) + { + // Ignore the event, so that eventually the delegate gets the event. + ev->ignore(); + return true; + } + + return QWidget::eventFilter(obj, ev); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormulaPropertyEditor::~VFormulaPropertyEditor() +{ + // +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VFormulaPropertyEditor::getFormula() +{ + return formula; +} diff --git a/src/app/widgets/vformulapropertyeditor.h b/src/app/widgets/vformulapropertyeditor.h new file mode 100644 index 000000000..622facc76 --- /dev/null +++ b/src/app/widgets/vformulapropertyeditor.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file vformulapropertyeditor.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 VFORMULAPROPERTYEDITOR_H +#define VFORMULAPROPERTYEDITOR_H + +#include +#include +#include +#include +#include + +#include "../container/vformula.h" + +class VFormulaPropertyEditor : public QWidget +{ + Q_OBJECT + +public: + //! Constructor taking a widget as parent + VFormulaPropertyEditor(QWidget *parent); + + //! Destructor + virtual ~VFormulaPropertyEditor(); + + //! Returns the formula currently set + VFormula getFormula(); + + //! Needed for proper event handling + bool eventFilter(QObject *obj, QEvent *ev); + +signals: + //! This is emitted, when the user changes the color + void dataChangedByUser(const VFormula &getFormula, VFormulaPropertyEditor* editor); + + void dataChanged(); + +public slots: + //! Sets the color of the widget + void setFormula(const VFormula &formula); + +private slots: + void onToolButtonClicked(); + +private: + VFormula formula; + QToolButton* ToolButton; + QLabel* TextLabel; + QSpacerItem* Spacer; +}; + + +#endif // VFORMULAPROPERTYEDITOR_H diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 787821ded..5fdae5e54 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -33,6 +33,8 @@ #include "visualization/vgraphicssimpletextitem.h" #include "visualization/vcontrolpointspline.h" #include "../libs/vpropertyexplorer/vproperties.h" +#include "vformulaproperty.h" +#include "../container/vformula.h" #include #include @@ -139,9 +141,16 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) } else if (id == QLatin1String("lineType")) { - i->setTypeLine(variant.toString()); } + else if (id == QLatin1String("formulaLength")) + { + VFormula formula = variant.value(); + if (formula.error() == false) + { + i->setFormulaLength(variant.value().getFormula()); + } + } break; } default: @@ -203,6 +212,14 @@ void VToolOptionsPropertyBrowser::UpdateOptions() qint32 index = styles.indexOf(i->getLineType()); idToProperty[QLatin1String("lineType")]->setValue(index); + VFormula formula(i->getFormulaLength(), i->getData()); + formula.setCheckZero(true); + formula.setToolId(i->getId()); + formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + QVariant value; + value.setValue(formula); + idToProperty[QLatin1String("formulaLength")]->setValue(value); + break; } case VGraphicsSimpleTextItem::Type: @@ -267,6 +284,14 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) qint32 index = styles.indexOf(i->getLineType()); lineTypeProperty->setValue(index); AddProperty(lineTypeProperty, QLatin1String("lineType")); + + VFormulaProperty* itemLength = new VFormulaProperty(tr("Length")); + VFormula formula(i->getFormulaLength(), i->getData()); + formula.setCheckZero(true); + formula.setToolId(i->getId()); + formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + itemLength->setFormula(formula); + AddProperty(itemLength, QLatin1String("formulaLength")); break; } case VGraphicsSimpleTextItem::Type: diff --git a/src/app/widgets/widgets.pri b/src/app/widgets/widgets.pri index 8def2ed00..4c2ac1298 100644 --- a/src/app/widgets/widgets.pri +++ b/src/app/widgets/widgets.pri @@ -8,7 +8,9 @@ HEADERS += \ widgets/textdelegate.h \ widgets/vtranslation.h \ widgets/undoevent.h \ - widgets/vtooloptionspropertybrowser.h + widgets/vtooloptionspropertybrowser.h \ + widgets/vformulapropertyeditor.h \ + widgets/vformulaproperty.h SOURCES += \ widgets/vtablegraphicsview.cpp \ @@ -20,4 +22,6 @@ SOURCES += \ widgets/textdelegate.cpp \ widgets/vtranslation.cpp \ widgets/undoevent.cpp \ - widgets/vtooloptionspropertybrowser.cpp + widgets/vtooloptionspropertybrowser.cpp \ + widgets/vformulapropertyeditor.cpp \ + widgets/vformulaproperty.cpp diff --git a/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp b/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp index 7d3152eda..dbf2a1838 100644 --- a/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp @@ -5,14 +5,14 @@ using namespace VPE; -QColorProperty::QColorProperty(const QString &name) : +VColorProperty::VColorProperty(const QString &name) : VProperty(name, QVariant::Color) { } //! Get the data how it should be displayed -QVariant QColorProperty::data (int column, int role) const +QVariant VColorProperty::data (int column, int role) const { if(column == DPC_Data && (Qt::DisplayRole == role)) return VColorPropertyEditor::getColorString(d_ptr->VariantValue.value()); @@ -25,7 +25,7 @@ QVariant QColorProperty::data (int column, int role) const } //! Returns an editor widget, or NULL if it doesn't supply one -QWidget* QColorProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +QWidget* VColorProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) { Q_UNUSED(options); Q_UNUSED(delegate); @@ -36,7 +36,7 @@ QWidget* QColorProperty::createEditor(QWidget* parent, const QStyleOptionViewIte } //! Sets the property's data to the editor (returns false, if the standard delegate should do that) -bool QColorProperty::setEditorData(QWidget* editor) +bool VColorProperty::setEditorData(QWidget* editor) { VColorPropertyEditor* tmpWidget = qobject_cast(editor); if(tmpWidget) @@ -48,7 +48,7 @@ bool QColorProperty::setEditorData(QWidget* editor) } //! Gets the data from the widget -QVariant QColorProperty::getEditorData(QWidget* editor) const +QVariant VColorProperty::getEditorData(QWidget* editor) const { VColorPropertyEditor* tmpWidget = qobject_cast(editor); if(tmpWidget) @@ -57,12 +57,12 @@ QVariant QColorProperty::getEditorData(QWidget* editor) const return QVariant(); } -QString QColorProperty::type() const +QString VColorProperty::type() const { return "color"; } -VProperty *QColorProperty::clone(bool include_children, VProperty *container) const +VProperty *VColorProperty::clone(bool include_children, VProperty *container) const { - return VProperty::clone(include_children, container ? container : new QColorProperty(getName())); + return VProperty::clone(include_children, container ? container : new VColorProperty(getName())); } diff --git a/src/libs/vpropertyexplorer/plugins/vcolorproperty.h b/src/libs/vpropertyexplorer/plugins/vcolorproperty.h index d61802f1f..cad37a0e7 100644 --- a/src/libs/vpropertyexplorer/plugins/vcolorproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vcolorproperty.h @@ -7,11 +7,11 @@ namespace VPE { -class VPROPERTYEXPLORERSHARED_EXPORT QColorProperty : public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VColorProperty : public VProperty { public: - QColorProperty(const QString &name); + VColorProperty(const QString &name); //! Get the data how it should be displayed virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp index e03504bbb..8e8d69902 100644 --- a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp @@ -7,7 +7,7 @@ using namespace VPE; VEnumProperty::VEnumProperty(const QString& name) - : QObject(), VProperty(name, QVariant::Int) + : VProperty(name, QVariant::Int) { VProperty::d_ptr->VariantValue = 0; VProperty::d_ptr->VariantValue.convert(QVariant::Int); diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.h b/src/libs/vpropertyexplorer/plugins/venumproperty.h index c43761bf2..07be616b5 100644 --- a/src/libs/vpropertyexplorer/plugins/venumproperty.h +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.h @@ -7,7 +7,7 @@ namespace VPE{ -class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public QObject, public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public VProperty { Q_OBJECT public: diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp index 07fb5cf65..f82c510aa 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp @@ -14,7 +14,7 @@ const int VIntegerProperty::StandardMin = -1000000; const int VIntegerProperty::StandardMax = 1000000; VIntegerProperty::VIntegerProperty(const QString& name, const QMap& settings) - : QObject(), VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) + : VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) { VProperty::setSettings(settings); VProperty::d_ptr->VariantValue.setValue(0); @@ -22,7 +22,7 @@ VIntegerProperty::VIntegerProperty(const QString& name, const QMapVariantValue.setValue(0); VProperty::d_ptr->VariantValue.convert(QVariant::Int); diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h index 155357933..b1fdbcafb 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h @@ -8,7 +8,7 @@ namespace VPE { //! Class for holding an integer property -class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public QObject, public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public VProperty { Q_OBJECT public: diff --git a/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp b/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp index 321c09231..1687dc2cf 100644 --- a/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp @@ -28,7 +28,7 @@ using namespace VPE; VObjectProperty::VObjectProperty(const QString& name) - : QObject(), VProperty(name, QVariant::Int) + : VProperty(name, QVariant::Int) { VProperty::d_ptr->VariantValue = 0; VProperty::d_ptr->VariantValue.convert(QVariant::UInt); diff --git a/src/libs/vpropertyexplorer/plugins/vobjectproperty.h b/src/libs/vpropertyexplorer/plugins/vobjectproperty.h index a3e7b49d4..7ea6246bd 100644 --- a/src/libs/vpropertyexplorer/plugins/vobjectproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vobjectproperty.h @@ -29,7 +29,7 @@ class QComboBox; namespace VPE{ -class VPROPERTYEXPLORERSHARED_EXPORT VObjectProperty : public QObject, public VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VObjectProperty : public VProperty { Q_OBJECT public: diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp index 00cd08061..89ad53579 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -29,7 +29,7 @@ using namespace VPE; VPE::VStringProperty::VStringProperty(const QString &name, const QMap &settings) - : VProperty(name, QVariant::String), readOnly(false) + : VProperty(name, QVariant::String), readOnly(false), typeForParent(0) { VProperty::setSettings(settings); d_ptr->VariantValue.setValue(QStringLiteral("")); @@ -37,7 +37,7 @@ VPE::VStringProperty::VStringProperty(const QString &name, const QMapVariantValue.setValue(QStringLiteral("")); d_ptr->VariantValue.convert(QVariant::String); @@ -74,29 +74,51 @@ void VPE::VStringProperty::setReadOnly(bool readOnly) void VPE::VStringProperty::setSetting(const QString &key, const QVariant &value) { - if(key == "ReadOnly") + if(key == QLatin1String("ReadOnly")) setReadOnly(value.toBool()); + if(key == QLatin1String("TypeForParent")) + setTypeForParent(value.toInt()); } QVariant VPE::VStringProperty::getSetting(const QString &key) const { - if(key == "ReadOnly") + if(key == QLatin1String("ReadOnly")) return readOnly; + else if (key == QLatin1String("TypeForParent")) + return typeForParent; else return VProperty::getSetting(key); } QStringList VPE::VStringProperty::getSettingKeys() const { - return QStringList("ReadOnly"); + QStringList settings; + settings << QStringLiteral("ReadOnly") << QStringLiteral("TypeForParent"); + return settings; } QString VPE::VStringProperty::type() const { - return "string"; + return QStringLiteral("string"); } VPE::VProperty *VPE::VStringProperty::clone(bool include_children, VPE::VProperty *container) const { - return VProperty::clone(include_children, container ? container : new VStringProperty(getName())); + return VProperty::clone(include_children, container ? container : new VStringProperty(getName(), getSettings())); } + +void VStringProperty::UpdateParent(const QVariant &value) +{ + emit childChanged(value, typeForParent); +} + +int VStringProperty::getTypeForParent() const +{ + return typeForParent; +} + +void VStringProperty::setTypeForParent(int value) +{ + typeForParent = value; +} + diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h index 5182e8e69..105fa7deb 100644 --- a/src/libs/vpropertyexplorer/plugins/vstringproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -64,8 +64,14 @@ public: //! \return Returns the newly created property (or container, if it was not NULL) virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + virtual void UpdateParent(const QVariant &value); + + int getTypeForParent() const; + void setTypeForParent(int value); + protected: bool readOnly; + int typeForParent; }; } diff --git a/src/libs/vpropertyexplorer/vproperty.cpp b/src/libs/vpropertyexplorer/vproperty.cpp index 59f96238e..30be44c00 100644 --- a/src/libs/vpropertyexplorer/vproperty.cpp +++ b/src/libs/vpropertyexplorer/vproperty.cpp @@ -10,7 +10,7 @@ using namespace VPE; //! Standard constructor, takes a name and a parent property as argument VProperty::VProperty(const QString& name, QVariant::Type type) - : d_ptr(new VPropertyPrivate(name, type)) + : QObject(), d_ptr(new VPropertyPrivate(name, type)) { } @@ -342,3 +342,18 @@ VProperty* VProperty::clone(bool include_children, VProperty* container) const return container; } + +Property VProperty::propertyType() const +{ + return d_ptr->type; +} + +void VProperty::UpdateParent(const QVariant &value) +{ + Q_UNUSED(value); +} + +void VProperty::ValueChildChanged(const QVariant &value, int typeForParent) +{ + +} diff --git a/src/libs/vpropertyexplorer/vproperty.h b/src/libs/vpropertyexplorer/vproperty.h index 26e80f60b..2a433a9fd 100644 --- a/src/libs/vpropertyexplorer/vproperty.h +++ b/src/libs/vpropertyexplorer/vproperty.h @@ -12,6 +12,8 @@ namespace VPE { +enum class Property : char{Simple, Complex}; + static const int MyCustomEventType = 1099; class UserChangeEvent : public QEvent @@ -22,8 +24,9 @@ public: class VPropertyPrivate; -class VPROPERTYEXPLORERSHARED_EXPORT VProperty +class VPROPERTYEXPLORERSHARED_EXPORT VProperty : public QObject { + Q_OBJECT public: enum DPC_DisplayColumn { DPC_Name = 0, @@ -158,6 +161,13 @@ public: //! \return Returns the newly created property (or container, if it was not NULL) virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + Property propertyType() const; + + virtual void UpdateParent(const QVariant &value); +public slots: + virtual void ValueChildChanged(const QVariant &value, int typeForParent); +signals: + void childChanged(const QVariant &value, int typeForParent); protected: //! Protected constructor diff --git a/src/libs/vpropertyexplorer/vproperty_p.h b/src/libs/vpropertyexplorer/vproperty_p.h index deaecdfed..6937e32c7 100644 --- a/src/libs/vpropertyexplorer/vproperty_p.h +++ b/src/libs/vpropertyexplorer/vproperty_p.h @@ -40,13 +40,15 @@ public: QWidget* editor; + Property type; + //! List of child properties QList Children; //! Constructor passing name and type VPropertyPrivate(const QString& name, QVariant::Type type) : VariantValue(type), Name(name), PropertyVariantType(type), UpdateParent(false), UpdateChildren(false), - Parent(nullptr), editor(nullptr) + Parent(nullptr), editor(nullptr), type(Property::Simple) {} //! Constructor diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp index ef0f17937..9dcef9d9d 100644 --- a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp @@ -71,39 +71,79 @@ void VPropertyFormWidget::build() if(!tmpProperty) continue; if(tmpProperty->getRowCount() > 0) { - // Child properties, the property itself is not being added - VPropertyFormWidget* tmpNewFormWidget = new VPropertyFormWidget(tmpProperty, this); - tmpFormLayout->addRow(tmpNewFormWidget); - d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpNewFormWidget)); - tmpNewFormWidget->setCommitBehaviour(d_ptr->UpdateEditors); + if (tmpProperty->propertyType() == Property::Complex) + { + buildEditor(tmpProperty, tmpFormLayout, Property::Complex); + QWidget *group = new QWidget(this); + tmpFormLayout->addRow(group); + + QFormLayout* subFormLayout = new QFormLayout(group); + QMargins margins = subFormLayout->contentsMargins(); + margins.setTop(0); + margins.setLeft(14); + subFormLayout->setContentsMargins(margins); + + group->setLayout(subFormLayout); + QList children = tmpProperty->getChildren(); + for (int j = 0; j < children.size(); ++j) + { + buildEditor(children[j], subFormLayout); + connect(children[j], &VProperty::childChanged, tmpProperty, &VProperty::ValueChildChanged, + Qt::UniqueConnection); + ++i; + d_ptr->Properties.insert(i, children[j]); + } + } + else + { + // Child properties, the property itself is not being added + VPropertyFormWidget* tmpNewFormWidget = new VPropertyFormWidget(tmpProperty, this); + tmpFormLayout->addRow(tmpNewFormWidget); + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpNewFormWidget)); + tmpNewFormWidget->setCommitBehaviour(d_ptr->UpdateEditors); + } } else if(tmpProperty->type() == "widget") { VWidgetProperty* tmpWidgetProperty = static_cast(tmpProperty); tmpFormLayout->addRow(tmpWidgetProperty->getWidget()); d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpWidgetProperty->getWidget())); } else { - // Add property (no child properties) - // Create the editor (if it doesn't work, create empty widget) - QWidget* tmpEditor = tmpProperty->createEditor(this, QStyleOptionViewItem(), nullptr); - if(!tmpEditor) - tmpEditor = new QWidget(this); - - // set tooltip and whats this - tmpEditor->setToolTip(tmpProperty->getDescription()); - tmpEditor->setWhatsThis(tmpProperty->getDescription()); - - // Install event filter - tmpEditor->installEventFilter(this); - - // Set the editor data - tmpProperty->setEditorData(tmpEditor); - - // add new row - tmpFormLayout->addRow(tmpProperty->getName(), tmpEditor); - d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpEditor)); + buildEditor(tmpProperty, tmpFormLayout); } } } +void VPropertyFormWidget::buildEditor(VProperty* property, QFormLayout* formLayout, Property type) +{ + // Add property (no child properties) + // Create the editor (if it doesn't work, create empty widget) + QWidget* tmpEditor = property->createEditor(this, QStyleOptionViewItem(), nullptr); + if(!tmpEditor) + tmpEditor = new QWidget(this); + + // set tooltip and whats this + tmpEditor->setToolTip(property->getDescription()); + tmpEditor->setWhatsThis(property->getDescription()); + + // Install event filter + tmpEditor->installEventFilter(this); + + // Set the editor data + property->setEditorData(tmpEditor); + + // add new row + if (type == Property::Complex) + { + QString name = ""+property->getName()+""; + formLayout->addRow(name, tmpEditor); + } + else + { + formLayout->addRow(property->getName(), tmpEditor); + } + + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpEditor)); +} + void VPropertyFormWidget::commitData() { for(int i = 0; i < d_ptr->Properties.count(); ++i) @@ -129,8 +169,19 @@ void VPropertyFormWidget::commitData(int row) QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole); if (oldValue != newValue) { - tmpProperty->setValue(newValue); - emit propertyDataSubmitted(tmpProperty); + if (VProperty *parent = tmpProperty->getParent()) + { + if (parent->propertyType() == Property::Complex) + { + tmpProperty->UpdateParent(newValue); + emit propertyDataSubmitted(parent); + } + } + else + { + tmpProperty->setValue(newValue); + emit propertyDataSubmitted(tmpProperty); + } } } } diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.h b/src/libs/vpropertyexplorer/vpropertyformwidget.h index 4cc3f0ad9..c407bc603 100644 --- a/src/libs/vpropertyexplorer/vpropertyformwidget.h +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.h @@ -5,6 +5,8 @@ #include #include "vproperty.h" +class QFormLayout; + namespace VPE { class VPropertyFormWidgetPrivate; @@ -32,6 +34,8 @@ public slots: //! Rebuilds the whole form virtual void build(); + void buildEditor(VProperty *property, QFormLayout *formLayout, Property type = Property::Simple); + //! Reads the data from the editors and commits it to the properties void commitData(); diff --git a/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp b/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp index a9a05ea46..8b175764c 100644 --- a/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp +++ b/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp @@ -45,7 +45,7 @@ VProperty *VStandardPropertyFactory::createProperty(const QString &type, const Q } else if(type == QString("bool")) { return new VBoolProperty(name); } else if(type == QString("color")) { - return new QColorProperty(name); + return new VColorProperty(name); } else if(type == QString("empty")) { return new VEmptyProperty(name); } else if(type == QString("enum")) { From 44d1465881d498b42548b80b26030cfea2277040 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 29 Aug 2014 16:42:53 +0300 Subject: [PATCH 16/52] Disable multiple subexpression mode. One expresiion per time. --HG-- branch : feature --- src/app/container/calculator.cpp | 82 +------------------ src/app/container/calculator.h | 3 - src/app/container/vformula.cpp | 28 +++++-- src/app/container/vformula.h | 6 +- src/app/widgets/vformulapropertyeditor.cpp | 4 +- .../widgets/vtooloptionspropertybrowser.cpp | 2 +- src/libs/qmuparser/qmuparserbase.cpp | 14 +++- src/libs/qmuparser/qmuparserbase.h | 4 + 8 files changed, 48 insertions(+), 95 deletions(-) diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 3ea4cb7f1..87bdd1f8d 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -55,14 +55,7 @@ Calculator::Calculator(const VContainer *data) :QmuParser(), vVarVal(nullptr), data(data) { InitCharacterSets(); - - // Add unary operators - DefinePostfixOprt(cm_Oprt, CmUnit); - DefinePostfixOprt(mm_Oprt, MmUnit); - DefinePostfixOprt(in_Oprt, InchUnit); - - SetArgSep(','); - SetDecSep('.'); + setAllowSubexpressions(false);//Only one expression per time } //--------------------------------------------------------------------------------------------------------------------- @@ -85,15 +78,12 @@ Calculator::Calculator(const QString &formula, bool fromUser) :QmuParser(), vVarVal(nullptr), data(nullptr) { InitCharacterSets(); + setAllowSubexpressions(false);//Only one expression per time SetVarFactory(AddVariable, this); // Add unary operators if (fromUser) { - DefinePostfixOprt(qApp->PostfixOperator(cm_Oprt), CmUnit); - DefinePostfixOprt(qApp->PostfixOperator(mm_Oprt), MmUnit); - DefinePostfixOprt(qApp->PostfixOperator(in_Oprt), InchUnit); - bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool(); if (osSeparatorValue) @@ -111,16 +101,13 @@ Calculator::Calculator(const QString &formula, bool fromUser) } else { - DefinePostfixOprt(cm_Oprt, CmUnit); - DefinePostfixOprt(mm_Oprt, MmUnit); - DefinePostfixOprt(in_Oprt, InchUnit); SetArgSep(','); SetDecSep('.'); } SetExpr(formula); - //Need run for making tokens. Don't catch exception here, because because we want know if formula has error. + //Need run for making tokens. Don't catch exception here, because we want know if formula has error. Eval(); } @@ -221,69 +208,6 @@ void Calculator::InitCharacterSets() DefineOprtChars(symbols + QStringLiteral("+-*^/?<>=#!$%&|~'_")); } -//--------------------------------------------------------------------------------------------------------------------- -qreal Calculator::CmUnit(qreal val) -{ - qreal unit = val; - switch (qApp->patternUnit()) - { - case Unit::Mm: - unit = val * 10.0; - break; - case Unit::Cm: - break; - case Unit::Inch: - unit = val / 2.54; - break; - default: - break; - } - - return unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal Calculator::MmUnit(qreal val) -{ - qreal unit = val; - switch (qApp->patternUnit()) - { - case Unit::Mm: - break; - case Unit::Cm: - unit = val / 10.0; - break; - case Unit::Inch: - unit = val / 25.4; - break; - default: - break; - } - - return unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal Calculator::InchUnit(qreal val) -{ - qreal unit = val; - switch (qApp->patternUnit()) - { - case Unit::Mm: - unit = val * 25.4; - break; - case Unit::Cm: - unit = val * 2.54; - break; - case Unit::Inch: - break; - default: - break; - } - - return unit; -} - //--------------------------------------------------------------------------- // Factory function for creating new parser variables // This could as well be a function performing database queries. diff --git a/src/app/container/calculator.h b/src/app/container/calculator.h index 9ec6c303d..22ec079f3 100644 --- a/src/app/container/calculator.h +++ b/src/app/container/calculator.h @@ -66,9 +66,6 @@ private: const VContainer *data; void InitVariables(const VContainer *data, const QMap &tokens); void InitCharacterSets(); - static qreal CmUnit(qreal val); - static qreal MmUnit(qreal val); - static qreal InchUnit(qreal val); static qreal* AddVariable(const QString &a_szName, void *a_pUserData); }; diff --git a/src/app/container/vformula.cpp b/src/app/container/vformula.cpp index eb3cf4d0d..412934508 100644 --- a/src/app/container/vformula.cpp +++ b/src/app/container/vformula.cpp @@ -40,7 +40,7 @@ VFormula::VFormula() //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula(const QString &formula, const VContainer *container) - :formula(formula), value(QString(tr("Error"))), checkZero(true), data(container), toolId(NULL_ID), + :formula(qApp->FormulaToUser(formula)), value(QString(tr("Error"))), checkZero(true), data(container), toolId(NULL_ID), postfix(QStringLiteral("")), _error(true) { this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist @@ -90,17 +90,32 @@ bool VFormula::operator!=(const VFormula &formula) const } //--------------------------------------------------------------------------------------------------------------------- -QString VFormula::getFormula() const +QString VFormula::getFormula(FormulaType type) const { - return formula; + if (type == FormulaType::ToUser) + { + return formula; + } + else + { + return qApp->FormulaFromUser(formula); + } } //--------------------------------------------------------------------------------------------------------------------- -void VFormula::setFormula(const QString &value) +void VFormula::setFormula(const QString &value, FormulaType type) { if (formula != value) { - formula = value; + if (type == FormulaType::ToUser) + { + formula = value; + } + else + { + formula = qApp->FormulaToUser(value); + } + formula.replace("\n", " ");// Replace line return with spaces for calc if exist Eval(); } } @@ -200,7 +215,8 @@ void VFormula::Eval() try { Calculator *cal = new Calculator(data); - const qreal result = cal->EvalFormula(formula); + QString expression = qApp->FormulaFromUser(formula); + const qreal result = cal->EvalFormula(expression); delete cal; //if result equal 0 diff --git a/src/app/container/vformula.h b/src/app/container/vformula.h index c624ed829..c60453de7 100644 --- a/src/app/container/vformula.h +++ b/src/app/container/vformula.h @@ -31,6 +31,8 @@ #include +enum class FormulaType : char{ToUser, FromUser}; + class VContainer; class VFormula @@ -44,8 +46,8 @@ public: bool operator==(const VFormula &formula) const; bool operator!=(const VFormula &formula) const; - QString getFormula() const; - void setFormula(const QString &value); + QString getFormula(FormulaType type = FormulaType::ToUser) const; + void setFormula(const QString &value, FormulaType type = FormulaType::ToUser); QString getValue() const; diff --git a/src/app/widgets/vformulapropertyeditor.cpp b/src/app/widgets/vformulapropertyeditor.cpp index baa7de4b6..3118979aa 100644 --- a/src/app/widgets/vformulapropertyeditor.cpp +++ b/src/app/widgets/vformulapropertyeditor.cpp @@ -88,11 +88,11 @@ void VFormulaPropertyEditor::onToolButtonClicked() DialogEditWrongFormula* tmpWidget = new DialogEditWrongFormula(formula.getData(), formula.getToolId()); tmpWidget->setCheckZero(formula.getCheckZero()); tmpWidget->setPostfix(formula.getPostfix()); - tmpWidget->setFormula(formula.getFormula()); + tmpWidget->setFormula(formula.getFormula(FormulaType::FromUser)); if (tmpWidget->exec() == QDialog::Accepted) { - formula.setFormula(tmpWidget->getFormula()); + formula.setFormula(tmpWidget->getFormula(), FormulaType::ToUser); TextLabel->setText(formula.getValue()); delete tmpWidget; emit dataChangedByUser(formula, this); diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 5fdae5e54..a085a493f 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -148,7 +148,7 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) VFormula formula = variant.value(); if (formula.error() == false) { - i->setFormulaLength(variant.value().getFormula()); + i->setFormulaLength(variant.value().getFormula(FormulaType::FromUser)); } } break; diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index 3bf001f68..c4c30f0ee 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -65,7 +65,7 @@ QmuParserBase::QmuParserBase() :m_pParseFormula(&QmuParserBase::ParseString), m_vRPN(), m_vStringBuf(), m_vStringVarBuf(), m_pTokenReader(), m_FunDef(), m_PostOprtDef(), m_InfixOprtDef(), m_OprtDef(), m_ConstDef(), m_StrVarDef(), m_VarDef(), m_bBuiltInOp(true), m_sNameChars(), m_sOprtChars(), m_sInfixOprtChars(), m_nIfElseCounter(0), m_vStackBuffer(), - m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()) + m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()), allowSubexpressions(true) { InitTokenReader(); } @@ -80,7 +80,7 @@ QmuParserBase::QmuParserBase(const QmuParserBase &a_Parser) :m_pParseFormula(&QmuParserBase::ParseString), m_vRPN(), m_vStringBuf(), m_vStringVarBuf(), m_pTokenReader(), m_FunDef(), m_PostOprtDef(), m_InfixOprtDef(), m_OprtDef(), m_ConstDef(), m_StrVarDef(), m_VarDef(), m_bBuiltInOp(true), m_sNameChars(), m_sOprtChars(), m_sInfixOprtChars(), m_nIfElseCounter(0), m_vStackBuffer(), - m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()) + m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()), allowSubexpressions(true) { m_pTokenReader.reset(new token_reader_type(this)); Assign(a_Parser); @@ -219,6 +219,12 @@ void QmuParserBase::OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) Q_UNUSED(nEnd); } +//--------------------------------------------------------------------------------------------------------------------- +void QmuParserBase::setAllowSubexpressions(bool value) +{ + allowSubexpressions = value; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Returns the version of muparser. @@ -1323,6 +1329,10 @@ void QmuParserBase::CreateRPN() const { Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); } + if (stOpt.empty() && allowSubexpressions == false) + { + Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); + } ++stArgCount.top(); // fallthrough intentional (no break!) case cmEND: diff --git a/src/libs/qmuparser/qmuparserbase.h b/src/libs/qmuparser/qmuparserbase.h index d7d92c090..59d8b7c59 100644 --- a/src/libs/qmuparser/qmuparserbase.h +++ b/src/libs/qmuparser/qmuparserbase.h @@ -120,6 +120,8 @@ public: { AddCallback( a_strName, QmuParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars() ); } + void setAllowSubexpressions(bool value); + protected: static const QStringList c_DefaultOprt; static std::locale s_locale; ///< The locale used by the parser @@ -235,6 +237,8 @@ private: mutable QMap m_Tokens;///< Keep all tokens that we can translate mutable QMap m_Numbers;///< Keep all numbers what exist in formula + bool allowSubexpressions; + void Assign(const QmuParserBase &a_Parser); void InitTokenReader(); void ReInit() const; From b2b78545981796f3f7a90e81d42781de3448a2ce Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 29 Aug 2014 16:57:12 +0300 Subject: [PATCH 17/52] Check if internal cursor stack is empty. --HG-- branch : feature --- .../dialogs/tools/dialogeditwrongformula.cpp | 9 +++-- src/app/widgets/vformulapropertyeditor.cpp | 3 +- .../widgets/vtooloptionspropertybrowser.cpp | 40 +++++++++++++++---- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/app/dialogs/tools/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index 3c2797d95..6c81c10bb 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -52,10 +52,13 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const qui //Disable Qt::WaitCursor #ifndef QT_NO_CURSOR - if (QApplication::overrideCursor()->shape() == Qt::WaitCursor) + if (QApplication::overrideCursor() != nullptr) { - restoreCursor = true; - QApplication::restoreOverrideCursor(); + if (QApplication::overrideCursor()->shape() == Qt::WaitCursor) + { + restoreCursor = true; + QApplication::restoreOverrideCursor(); + } } #endif } diff --git a/src/app/widgets/vformulapropertyeditor.cpp b/src/app/widgets/vformulapropertyeditor.cpp index 3118979aa..f286d6154 100644 --- a/src/app/widgets/vformulapropertyeditor.cpp +++ b/src/app/widgets/vformulapropertyeditor.cpp @@ -85,7 +85,8 @@ void VFormulaPropertyEditor::setFormula(const VFormula& formula) //--------------------------------------------------------------------------------------------------------------------- void VFormulaPropertyEditor::onToolButtonClicked() { - DialogEditWrongFormula* tmpWidget = new DialogEditWrongFormula(formula.getData(), formula.getToolId()); + DialogEditWrongFormula* tmpWidget = new DialogEditWrongFormula(formula.getData(), formula.getToolId(), + qApp->getMainWindow()); tmpWidget->setCheckZero(formula.getCheckZero()); tmpWidget->setPostfix(formula.getPostfix()); tmpWidget->setFormula(formula.getFormula(FormulaType::FromUser)); diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index a085a493f..42e803b42 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -151,6 +151,14 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) i->setFormulaLength(variant.value().getFormula(FormulaType::FromUser)); } } + else if (id == QLatin1String("formulaAngle")) + { + VFormula formula = variant.value(); + if (formula.error() == false) + { + i->setFormulaAngle(variant.value().getFormula(FormulaType::FromUser)); + } + } break; } default: @@ -216,9 +224,17 @@ void VToolOptionsPropertyBrowser::UpdateOptions() formula.setCheckZero(true); formula.setToolId(i->getId()); formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); - QVariant value; - value.setValue(formula); - idToProperty[QLatin1String("formulaLength")]->setValue(value); + QVariant valueFormula; + valueFormula.setValue(formula); + idToProperty[QLatin1String("formulaLength")]->setValue(valueFormula); + + VFormula formulaAngle(i->getFormulaAngle(), i->getData()); + formulaAngle.setCheckZero(false); + formulaAngle.setToolId(i->getId()); + formulaAngle.setPostfix(QStringLiteral("°")); + QVariant valueAngle; + valueAngle.setValue(formulaAngle); + idToProperty[QLatin1String("formulaAngle")]->setValue(valueAngle); break; } @@ -286,12 +302,20 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) AddProperty(lineTypeProperty, QLatin1String("lineType")); VFormulaProperty* itemLength = new VFormulaProperty(tr("Length")); - VFormula formula(i->getFormulaLength(), i->getData()); - formula.setCheckZero(true); - formula.setToolId(i->getId()); - formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); - itemLength->setFormula(formula); + VFormula formulaLength(i->getFormulaLength(), i->getData()); + formulaLength.setCheckZero(true); + formulaLength.setToolId(i->getId()); + formulaLength.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + itemLength->setFormula(formulaLength); AddProperty(itemLength, QLatin1String("formulaLength")); + + VFormulaProperty* itemAngle = new VFormulaProperty(tr("Angle")); + VFormula formulaAngle(i->getFormulaAngle(), i->getData()); + formulaAngle.setCheckZero(false); + formulaAngle.setToolId(i->getId()); + formulaAngle.setPostfix(QStringLiteral("°")); + itemAngle->setFormula(formulaAngle); + AddProperty(itemAngle, QLatin1String("formulaAngle")); break; } case VGraphicsSimpleTextItem::Type: From ae4bab9d07b6f82f6f1031873a1b142d4c7f9425 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 29 Aug 2014 17:10:47 +0300 Subject: [PATCH 18/52] Don't set cursor "arrow close hand" after double mouse click. --HG-- branch : feature --- src/app/tools/drawTools/vtoolsinglepoint.cpp | 4 ++-- src/app/visualization/vcontrolpointspline.cpp | 4 ++-- src/app/visualization/vgraphicssimpletextitem.cpp | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 36af6b6af..83e23ed44 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -263,7 +263,7 @@ void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { #ifndef QT_NO_CURSOR QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); @@ -276,7 +276,7 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand #ifndef QT_NO_CURSOR diff --git a/src/app/visualization/vcontrolpointspline.cpp b/src/app/visualization/vcontrolpointspline.cpp index ba1644310..70b73bda3 100644 --- a/src/app/visualization/vcontrolpointspline.cpp +++ b/src/app/visualization/vcontrolpointspline.cpp @@ -127,7 +127,7 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { #ifndef QT_NO_CURSOR QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); @@ -140,7 +140,7 @@ void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand #ifndef QT_NO_CURSOR diff --git a/src/app/visualization/vgraphicssimpletextitem.cpp b/src/app/visualization/vgraphicssimpletextitem.cpp index 9de68966f..825362721 100644 --- a/src/app/visualization/vgraphicssimpletextitem.cpp +++ b/src/app/visualization/vgraphicssimpletextitem.cpp @@ -31,6 +31,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -141,7 +142,7 @@ void VGraphicsSimpleTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *e //--------------------------------------------------------------------------------------------------------------------- void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { #ifndef QT_NO_CURSOR QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); @@ -154,7 +155,7 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand #ifndef QT_NO_CURSOR From a251c9e378678b41a870d26fc2e6bae997bd1b48 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 29 Aug 2014 17:29:24 +0300 Subject: [PATCH 19/52] Fix clone property and commit data for "simple" property type. --HG-- branch : feature --- src/libs/vpropertyexplorer/vproperty.cpp | 6 ++++++ src/libs/vpropertyexplorer/vproperty.h | 1 + .../vpropertyexplorer/vpropertyformwidget.cpp | 18 +++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libs/vpropertyexplorer/vproperty.cpp b/src/libs/vpropertyexplorer/vproperty.cpp index 30be44c00..caab96b48 100644 --- a/src/libs/vpropertyexplorer/vproperty.cpp +++ b/src/libs/vpropertyexplorer/vproperty.cpp @@ -334,6 +334,7 @@ VProperty* VProperty::clone(bool include_children, VProperty* container) const container->setValue(getValue()); container->setSettings(getSettings()); container->setUpdateBehaviour(getUpdateParent(), getUpdateChildren()); + container->setPropertyType(propertyType()); if(include_children) { foreach(VProperty* tmpChild, d_ptr->Children) @@ -348,6 +349,11 @@ Property VProperty::propertyType() const return d_ptr->type; } +void VProperty::setPropertyType(const Property &type) +{ + d_ptr->type = type; +} + void VProperty::UpdateParent(const QVariant &value) { Q_UNUSED(value); diff --git a/src/libs/vpropertyexplorer/vproperty.h b/src/libs/vpropertyexplorer/vproperty.h index 2a433a9fd..b01531f86 100644 --- a/src/libs/vpropertyexplorer/vproperty.h +++ b/src/libs/vpropertyexplorer/vproperty.h @@ -162,6 +162,7 @@ public: virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; Property propertyType() const; + void setPropertyType(const Property &type); virtual void UpdateParent(const QVariant &value); public slots: diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp index 9dcef9d9d..598fecdd8 100644 --- a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp @@ -164,18 +164,22 @@ void VPropertyFormWidget::commitData(int row) VProperty* tmpProperty = d_ptr->Properties[row]; if(tmpEditorWidget.FormWidget) tmpEditorWidget.FormWidget->commitData(); - else if(tmpEditorWidget.Editor && tmpProperty) { + else if(tmpEditorWidget.Editor && tmpProperty) + { QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor); QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole); if (oldValue != newValue) { - if (VProperty *parent = tmpProperty->getParent()) + VProperty *parent = tmpProperty->getParent(); + if (parent == nullptr) { - if (parent->propertyType() == Property::Complex) - { - tmpProperty->UpdateParent(newValue); - emit propertyDataSubmitted(parent); - } + tmpProperty->setValue(newValue); + emit propertyDataSubmitted(tmpProperty); + } + else if (parent->propertyType() == Property::Complex) + { + tmpProperty->UpdateParent(newValue); + emit propertyDataSubmitted(parent); } else { From fa4a7fb7b8458f5a9b7f079c6a9a7ba56740b6b8 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 29 Aug 2014 17:38:43 +0300 Subject: [PATCH 20/52] Show Error message when formula broken. --HG-- branch : feature --- src/app/dialogs/tools/dialogeditwrongformula.ui | 2 +- src/app/dialogs/tools/dialogtool.cpp | 6 ++++++ src/app/tools/drawTools/vdrawtool.cpp | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/dialogs/tools/dialogeditwrongformula.ui b/src/app/dialogs/tools/dialogeditwrongformula.ui index 1c240dfa3..c24142095 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.ui +++ b/src/app/dialogs/tools/dialogeditwrongformula.ui @@ -14,7 +14,7 @@ - Edit wrong formula + Edit formula diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 515ab0109..444fec323 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -377,11 +377,13 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) SCASSERT(edit != nullptr); SCASSERT(timer != nullptr); SCASSERT(labelEditFormula != nullptr); + SCASSERT(labelResultCalculation != nullptr); if (edit->text().isEmpty()) { flag = false; CheckState(); ChangeColor(labelEditFormula, Qt::red); + labelResultCalculation->setText(tr("Error")); return; } timer->start(1000); @@ -392,11 +394,13 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim SCASSERT(edit != nullptr); SCASSERT(timer != nullptr); SCASSERT(labelEditFormula != nullptr); + SCASSERT(labelResultCalculation != nullptr); if (edit->toPlainText().isEmpty()) { flag = false; CheckState(); ChangeColor(labelEditFormula, Qt::red); + labelResultCalculation->setText(tr("Error")); return; } timer->setSingleShot(true); @@ -423,6 +427,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la { flag = false; ChangeColor(labelEditFormula, Qt::red); + label->setText(tr("Error")); } else { @@ -441,6 +446,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la { flag = false; ChangeColor(labelEditFormula, Qt::red); + label->setText(tr("Error")); } else { diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 2eda94d91..106025ada 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -209,6 +209,7 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine if (resultUndo == UndoButton::Fix) { DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow()); + dialog->setWindowTitle(tr("Edit wrong formula")); dialog->setFormula(formula); if (dialog->exec() == QDialog::Accepted) { From 5d1212232588ff98da324f11312f8229c21bd839 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 29 Aug 2014 17:48:48 +0300 Subject: [PATCH 21/52] Show tool name in options title. --HG-- branch : feature --- src/app/widgets/vtooloptionspropertybrowser.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 42e803b42..b8d73b06b 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -78,8 +78,7 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) if (currentItem == nullptr) { - QDockWidget *parent = qobject_cast(this->parent()); - parent->setWindowTitle(tr("Tool options")); + TreeView->setTitle(tr("")); return; } @@ -122,10 +121,6 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) { currentItem->setPos(variant.toPointF()); } -// else if (id == QLatin1String("list")) -// { -// qDebug()<data(VProperty::DPC_Data, Qt::DisplayRole); -// } break; } case VToolEndLine::Type: @@ -265,8 +260,7 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolSinglePoint::Type: { VToolSinglePoint *i = qgraphicsitem_cast(item); - QDockWidget *parent = qobject_cast(this->parent()); - parent->setWindowTitle(tr("Tool options (Base point)")); + TreeView->setTitle(tr("Base point")); VProperty* itemName = new VProperty(tr("Point name")); itemName->setValue(i->name()); @@ -281,8 +275,7 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) case VToolEndLine::Type: { VToolEndLine *i = qgraphicsitem_cast(item); - QDockWidget *parent = qobject_cast(this->parent()); - parent->setWindowTitle(tr("Tool options (Point at distance and angle)")); + TreeView->setTitle(tr("Point at distance and angle")); VProperty* itemName = new VProperty(tr("Point name")); itemName->setValue(i->name()); From 87d32d9445f54856e4e6f0076bef382cdecfc670 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 30 Aug 2014 13:41:21 +0300 Subject: [PATCH 22/52] Show property tool "Point at distance along line". --HG-- branch : feature --- src/app/tools/drawTools/vtoolalongline.cpp | 112 ++++- src/app/tools/drawTools/vtoolalongline.h | 8 + src/app/tools/drawTools/vtoolendline.cpp | 37 +- src/app/tools/drawTools/vtoolendline.h | 6 +- src/app/tools/drawTools/vtoollinepoint.cpp | 9 +- src/app/tools/drawTools/vtoollinepoint.h | 3 +- .../widgets/vtooloptionspropertybrowser.cpp | 447 +++++++++++------- src/app/widgets/vtooloptionspropertybrowser.h | 18 + 8 files changed, 431 insertions(+), 209 deletions(-) diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 411039c70..9fe4bcd0a 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogalongline.h" #include "../../geometry/vpointf.h" #include "exception/vexceptionobjecterror.h" +#include "../undocommands/savetooloptions.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); @@ -122,16 +123,7 @@ void VToolAlongLine::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, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); + SaveOptions(domElement, *point.data()); AddToCalculation(domElement); } @@ -146,13 +138,11 @@ void VToolAlongLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); + SaveOptions(domElement, *point.data()); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } } @@ -182,6 +172,94 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::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, AttrFirstPoint, basePointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::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; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolAlongLine::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setSecondPointId(const quint32 &value) +{ + secondPointId = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setName(const QString &name) +{ + VPointF newPoint = VPointF(*VAbstractTool::data.GeometricObject(id).data()); + newPoint.setName(name); + SaveOption(newPoint); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setTypeLine(const QString &value) +{ + typeLine = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setFormulaLength(const VFormula &value) +{ + if (value.error() == false) + { + formulaLength = value.getFormula(FormulaType::FromUser); + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setFirstPointId(const quint32 &value) +{ + basePointId = value; + + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDialog set dialog when user want change tool option. diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index 7708abca5..9d4d49e1a 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -51,6 +51,12 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::AlongLine)}; + void setFirstPointId(const quint32 &value); + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + void setName(const QString &name); + void setTypeLine(const QString &value); + void setFormulaLength(const VFormula &value); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); @@ -64,6 +70,8 @@ protected: private: /** @brief secondPointId id second point of line. */ quint32 secondPointId; + void SaveOptions(QDomElement &tag, const VPointF &point); + void SaveOption(const VPointF &point); }; #endif // VTOOLALONGLINE_H diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index cbdf3b2f5..83e9d7133 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -197,7 +197,7 @@ void VToolEndLine::setName(const QString &name) SaveOption(newPoint); } -void VToolEndLine::setBasePointId(const quint32 &value) +void VToolEndLine::setBasePointId(const quint32 &value) { if (value != NULL_ID) { @@ -208,12 +208,15 @@ void VToolEndLine::setBasePointId(const quint32 &value) } } -void VToolEndLine::setFormulaLength(const QString &value) +void VToolEndLine::setFormulaLength(const VFormula &value) { - formulaLength = value; + if (value.error() == false) + { + formulaLength = value.getFormula(FormulaType::FromUser); - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -279,6 +282,10 @@ void VToolEndLine::RefreshDataInFile() { SaveOptions(domElement, *point.data()); } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -313,20 +320,28 @@ void VToolEndLine::SaveOptions(QDomElement &tag, const VPointF &point) } //--------------------------------------------------------------------------------------------------------------------- -QString VToolEndLine::getFormulaAngle() const +VFormula VToolEndLine::getFormulaAngle() const { - return formulaAngle; + VFormula fAngle(formulaAngle, getData()); + fAngle.setCheckZero(false); + fAngle.setToolId(id); + fAngle.setPostfix(QStringLiteral("°")); + return fAngle; } //--------------------------------------------------------------------------------------------------------------------- -void VToolEndLine::setFormulaAngle(const QString &value) +void VToolEndLine::setFormulaAngle(const VFormula &value) { - formulaAngle = value; + if (value.error() == false) + { + formulaAngle = value.getFormula(FormulaType::FromUser); - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); + const QSharedPointer point = VAbstractTool::data.GeometricObject(id); + SaveOption(*point.data()); + } } +//--------------------------------------------------------------------------------------------------------------------- void VToolEndLine::setTypeLine(const QString &value) { typeLine = value; diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 2be6d1558..89448b29b 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -52,10 +52,10 @@ public: 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); + VFormula getFormulaAngle() const; + void setFormulaAngle(const VFormula &value); void setTypeLine(const QString &value); - void setFormulaLength(const QString &value); + void setFormulaLength(const VFormula &value); void setBasePointId(const quint32 &value); public slots: virtual void FullUpdateFromFile(); diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 9cd09944a..fb02060e0 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -113,7 +113,12 @@ quint32 VToolLinePoint::getBasePointId() const return basePointId; } -QString VToolLinePoint::getFormulaLength() const +VFormula VToolLinePoint::getFormulaLength() const { - return formulaLength; + VFormula fLength(formulaLength, this->getData()); + fLength.setCheckZero(true); + fLength.setToolId(id); + fLength.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + + return fLength; } diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 1ad64bbf3..4929381d1 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -30,6 +30,7 @@ #define VTOOLLINEPOINT_H #include "vtoolpoint.h" +#include "../container/vformula.h" /** * @brief The VToolLinePoint class parent for all tools what create point with line. @@ -42,7 +43,7 @@ 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; + VFormula getFormulaLength() const; //void setFormulaLength(const QString &value)=0; quint32 getBasePointId() const; diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index b8d73b06b..ac0c877b2 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -62,27 +62,122 @@ VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) } //--------------------------------------------------------------------------------------------------------------------- -void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) +void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) { - if (currentItem == item) + switch (item->type()) { - UpdateOptions(); - return; + case VToolSinglePoint::Type: + { + VToolSinglePoint *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Base point")); + + AddPropertyPointName(i, tr("Point name")); + + VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); + itemPosition->setValue(i->pos()); + AddProperty(itemPosition, QLatin1String("position")); + break; + } + case VToolEndLine::Type: + { + VToolEndLine *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Point at distance and angle")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + AddPropertyFormula(tr("Angle"), i->getFormulaLength(), VAbstractTool::AttrAngle); + break; + } + case VToolAlongLine::Type: + { + VToolAlongLine *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Point at distance along line")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("First point"), i->getBasePointId(), VAbstractTool::AttrFirstPoint); + AddPropertyPointsList(i, tr("Second point"), i->getSecondPointId(), VAbstractTool::AttrSecondPoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + break; + } + case VGraphicsSimpleTextItem::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + case VControlPointSpline::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + default: + break; } +} - PropertyModel->clear(); - propertyToId.clear(); - idToProperty.clear(); - - currentItem = item; - +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptions() +{ if (currentItem == nullptr) { - TreeView->setTitle(tr("")); return; } - ShowItemOptions(currentItem); + switch (currentItem->type()) + { + case VToolSinglePoint::Type: + { + VToolSinglePoint *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[QLatin1String("position")]->setValue(i->pos()); + break; + } + case VToolEndLine::Type: + { + VToolEndLine *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[VAbstractTool::AttrBasePoint]->setValue(i->getBasePointId()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + QVariant valueAngle; + valueAngle.setValue(i->getFormulaAngle()); + idToProperty[VAbstractTool::AttrAngle]->setValue(valueAngle); + + break; + } + case VToolAlongLine::Type: + { + VToolAlongLine *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[VAbstractTool::AttrFirstPoint]->setValue(i->getBasePointId()); + idToProperty[VAbstractTool::AttrSecondPoint]->setValue(i->getSecondPointId()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + break; + } + case VGraphicsSimpleTextItem::Type: + ShowItemOptions(currentItem->parentItem()); + break; + case VControlPointSpline::Type: + ShowItemOptions(currentItem->parentItem()); + break; + default: + break; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -106,62 +201,90 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) return; } - QVariant variant = prop->data(VProperty::DPC_Data, Qt::DisplayRole); - - QString id = propertyToId[prop]; switch (currentItem->type()) { case VToolSinglePoint::Type: - { - if (id == QLatin1String("name")) - { - SetPointName(variant.toString()); - } - else if (id == QLatin1String("position")) - { - currentItem->setPos(variant.toPointF()); - } + ChangeDataToolSinglePoint(prop); break; - } case VToolEndLine::Type: - { - VToolEndLine *i = qgraphicsitem_cast(currentItem); - if (id == QLatin1String("name")) - { - SetPointName(variant.toString()); - } - else if (id == QLatin1String("basePoint")) - { - i->setBasePointId(variant.toUInt()); - } - else if (id == QLatin1String("lineType")) - { - i->setTypeLine(variant.toString()); - } - else if (id == QLatin1String("formulaLength")) - { - VFormula formula = variant.value(); - if (formula.error() == false) - { - i->setFormulaLength(variant.value().getFormula(FormulaType::FromUser)); - } - } - else if (id == QLatin1String("formulaAngle")) - { - VFormula formula = variant.value(); - if (formula.error() == false) - { - i->setFormulaAngle(variant.value().getFormula(FormulaType::FromUser)); - } - } + ChangeDataToolEndLine(prop); + break; + case VToolAlongLine::Type: + ChangeDataToolAlongLine(prop); break; - } default: break; } qApp->getSceneView()->update(); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) +{ + if (currentItem == item) + { + UpdateOptions(); + return; + } + + PropertyModel->clear(); + propertyToId.clear(); + idToProperty.clear(); + + currentItem = item; + + if (currentItem == nullptr) + { + TreeView->setTitle(""); + return; + } + + ShowItemOptions(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::AddPropertyFormula(const QString &propertyName, const VFormula &formula, + const QString &attrName) +{ + VFormulaProperty* itemLength = new VFormulaProperty(propertyName); + itemLength->setFormula(formula); + AddProperty(itemLength, attrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &propertyName) +{ + VProperty* itemName = new VProperty(propertyName); + itemName->setValue(i->name()); + AddProperty(itemName, VAbstractTool::AttrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value, + const QString &attrName) +{ + VObjectProperty *pointsProperty = new VObjectProperty(propertyName); + QMap pointsList = i->PointsList(); + pointsProperty->setObjectsList(pointsList); + pointsProperty->setValue(value); + AddProperty(pointsProperty, attrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName) +{ + VEnumProperty *lineTypeProperty = new VEnumProperty(propertyName); + lineTypeProperty->setLiterals(VAbstractTool::Styles()); + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + lineTypeProperty->setValue(index); + AddProperty(lineTypeProperty, VAbstractTool::AttrTypeLine); +} + +//--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::SetPointName(const QString &name) { @@ -174,7 +297,7 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) if (name.isEmpty()) { - idToProperty[QLatin1String("name")]->setValue(i->name()); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } else { @@ -188,62 +311,6 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) } } -//--------------------------------------------------------------------------------------------------------------------- -void VToolOptionsPropertyBrowser::UpdateOptions() -{ - if (currentItem == nullptr) - { - return; - } - - switch (currentItem->type()) - { - case VToolSinglePoint::Type: - { - VToolSinglePoint *i = qgraphicsitem_cast(currentItem); - idToProperty[QLatin1String("name")]->setValue(i->name()); - 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()); - - QStringList styles = VAbstractTool::Styles(); - qint32 index = styles.indexOf(i->getLineType()); - idToProperty[QLatin1String("lineType")]->setValue(index); - - VFormula formula(i->getFormulaLength(), i->getData()); - formula.setCheckZero(true); - formula.setToolId(i->getId()); - formula.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); - QVariant valueFormula; - valueFormula.setValue(formula); - idToProperty[QLatin1String("formulaLength")]->setValue(valueFormula); - - VFormula formulaAngle(i->getFormulaAngle(), i->getData()); - formulaAngle.setCheckZero(false); - formulaAngle.setToolId(i->getId()); - formulaAngle.setPostfix(QStringLiteral("°")); - QVariant valueAngle; - valueAngle.setValue(formulaAngle); - idToProperty[QLatin1String("formulaAngle")]->setValue(valueAngle); - - break; - } - case VGraphicsSimpleTextItem::Type: - ShowItemOptions(currentItem->parentItem()); - break; - case VControlPointSpline::Type: - ShowItemOptions(currentItem->parentItem()); - break; - default: - break; - } -} - //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString &id) { @@ -253,73 +320,103 @@ void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString } //--------------------------------------------------------------------------------------------------------------------- -void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) +void VToolOptionsPropertyBrowser::ChangeDataToolSinglePoint(VProperty *property) { - switch (item->type()) + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + switch (PropertiesList().indexOf(id)) { - case VToolSinglePoint::Type: - { - VToolSinglePoint *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Base point")); - - VProperty* itemName = new VProperty(tr("Point name")); - itemName->setValue(i->name()); - AddProperty(itemName, QLatin1String("name")); - - VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); - itemPosition->setValue(i->pos()); - AddProperty(itemPosition, QLatin1String("position")); - + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); break; - } - case VToolEndLine::Type: - { - VToolEndLine *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Point at distance and angle")); - - 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 *lineTypeProperty = new VEnumProperty(tr("Line type")); - lineTypeProperty->setLiterals(VAbstractTool::Styles()); - QStringList styles = VAbstractTool::Styles(); - qint32 index = styles.indexOf(i->getLineType()); - lineTypeProperty->setValue(index); - AddProperty(lineTypeProperty, QLatin1String("lineType")); - - VFormulaProperty* itemLength = new VFormulaProperty(tr("Length")); - VFormula formulaLength(i->getFormulaLength(), i->getData()); - formulaLength.setCheckZero(true); - formulaLength.setToolId(i->getId()); - formulaLength.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); - itemLength->setFormula(formulaLength); - AddProperty(itemLength, QLatin1String("formulaLength")); - - VFormulaProperty* itemAngle = new VFormulaProperty(tr("Angle")); - VFormula formulaAngle(i->getFormulaAngle(), i->getData()); - formulaAngle.setCheckZero(false); - formulaAngle.setToolId(i->getId()); - formulaAngle.setPostfix(QStringLiteral("°")); - itemAngle->setFormula(formulaAngle); - AddProperty(itemAngle, QLatin1String("formulaAngle")); - break; - } - case VGraphicsSimpleTextItem::Type: - currentItem = item->parentItem(); - ShowItemOptions(currentItem); - break; - case VControlPointSpline::Type: - currentItem = item->parentItem(); - ShowItemOptions(currentItem); + case 1: // QLatin1String("position") + currentItem->setPos(value.toPointF()); break; default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolEndLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 2: // VAbstractTool::AttrBasePoint + i->setBasePointId(value.toUInt()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 5: // VAbstractTool::AttrAngle + i->setFormulaAngle(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolAlongLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 6: // VAbstractTool::AttrFirstPoint + i->setFirstPointId(value.toUInt()); + break; + case 7: // VAbstractTool::AttrSecondPoint + i->setSecondPointId(value.toUInt()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "< void SetPointName(const QString &name); + + template + void AddPropertyPointName(Tool *i, const QString &propertyName); + + template + void AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value, const QString &attrName); + + template + void AddPropertyLineType(Tool *i, const QString &propertyName); + + void AddPropertyFormula(const QString &propertyName, const VFormula &formula, const QString &attrName); + + QStringList PropertiesList() const; + + void ChangeDataToolSinglePoint(VProperty *property); + void ChangeDataToolEndLine(VProperty *property); + void ChangeDataToolAlongLine(VProperty *property); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H From c412d0c51b070e23c2a482625bfdadeaca230ef7 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 30 Aug 2014 22:58:31 +0300 Subject: [PATCH 23/52] Refactoring. Prepare for showing tools options. --HG-- branch : feature --- src/app/mainwindow.cpp | 10 +- src/app/tools/drawTools/vabstractspline.cpp | 6 + src/app/tools/drawTools/vabstractspline.h | 1 + src/app/tools/drawTools/vdrawtool.cpp | 30 +++++ src/app/tools/drawTools/vdrawtool.h | 2 + src/app/tools/drawTools/vtoolalongline.cpp | 106 ++---------------- src/app/tools/drawTools/vtoolalongline.h | 11 +- src/app/tools/drawTools/vtoolarc.cpp | 56 ++++----- src/app/tools/drawTools/vtoolarc.h | 4 +- src/app/tools/drawTools/vtoolbisector.cpp | 64 ++++------- src/app/tools/drawTools/vtoolbisector.h | 3 +- src/app/tools/drawTools/vtoolcutarc.cpp | 55 +++------ src/app/tools/drawTools/vtoolcutarc.h | 3 +- src/app/tools/drawTools/vtoolcutspline.cpp | 74 +++++------- src/app/tools/drawTools/vtoolcutspline.h | 11 +- .../tools/drawTools/vtoolcutsplinepath.cpp | 76 +++++-------- src/app/tools/drawTools/vtoolcutsplinepath.h | 12 +- src/app/tools/drawTools/vtoolendline.cpp | 105 ++--------------- src/app/tools/drawTools/vtoolendline.h | 11 +- src/app/tools/drawTools/vtoolheight.cpp | 62 +++------- src/app/tools/drawTools/vtoolheight.h | 3 +- src/app/tools/drawTools/vtoolline.cpp | 33 ++++-- src/app/tools/drawTools/vtoolline.h | 2 + .../tools/drawTools/vtoollineintersect.cpp | 61 +++------- src/app/tools/drawTools/vtoollineintersect.h | 3 +- src/app/tools/drawTools/vtoollinepoint.cpp | 26 +++++ src/app/tools/drawTools/vtoollinepoint.h | 4 +- src/app/tools/drawTools/vtoolnormal.cpp | 64 ++++------- src/app/tools/drawTools/vtoolnormal.h | 3 +- src/app/tools/drawTools/vtoolpoint.cpp | 14 +++ src/app/tools/drawTools/vtoolpoint.h | 5 +- .../tools/drawTools/vtoolpointofcontact.cpp | 61 +++------- src/app/tools/drawTools/vtoolpointofcontact.h | 3 +- .../drawTools/vtoolpointofintersection.cpp | 55 +++------ .../drawTools/vtoolpointofintersection.h | 3 +- .../tools/drawTools/vtoolshoulderpoint.cpp | 64 ++++------- src/app/tools/drawTools/vtoolshoulderpoint.h | 3 +- src/app/tools/drawTools/vtoolsinglepoint.cpp | 66 ++--------- src/app/tools/drawTools/vtoolsinglepoint.h | 7 +- src/app/tools/drawTools/vtoolspline.cpp | 59 +++------- src/app/tools/drawTools/vtoolspline.h | 3 +- src/app/tools/drawTools/vtoolsplinepath.cpp | 51 +++++---- src/app/tools/drawTools/vtoolsplinepath.h | 8 +- src/app/tools/drawTools/vtooltriangle.cpp | 61 +++------- src/app/tools/drawTools/vtooltriangle.h | 3 +- src/app/tools/nodeDetails/vabstractnode.cpp | 6 + src/app/tools/nodeDetails/vabstractnode.h | 1 + src/app/tools/nodeDetails/vnodearc.cpp | 10 +- src/app/tools/nodeDetails/vnodearc.h | 1 + src/app/tools/nodeDetails/vnodepoint.cpp | 10 +- src/app/tools/nodeDetails/vnodepoint.h | 1 + src/app/tools/nodeDetails/vnodespline.cpp | 10 +- src/app/tools/nodeDetails/vnodespline.h | 1 + src/app/tools/nodeDetails/vnodesplinepath.cpp | 6 + src/app/tools/nodeDetails/vnodesplinepath.h | 1 + src/app/tools/vabstracttool.cpp | 34 +++++- src/app/tools/vabstracttool.h | 7 +- src/app/tools/vtooldetail.cpp | 12 ++ src/app/tools/vtooldetail.h | 2 + src/app/tools/vtooluniondetails.cpp | 30 +++-- src/app/tools/vtooluniondetails.h | 12 +- src/app/widgets/vmaingraphicsview.cpp | 14 ++- src/app/widgets/vmaingraphicsview.h | 3 + .../widgets/vtooloptionspropertybrowser.cpp | 2 +- 64 files changed, 610 insertions(+), 920 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index a7fbc7192..3be346f08 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -255,6 +255,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons QCursor cur(pixmap, 2, 3); ui->view->setCursor(cur); helpLabel->setText(toolTip); + ui->view->setShowToolOptions(false); dialogTool = new Dialog(pattern, 0, this); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); @@ -292,6 +293,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur QPixmap pixmap(cursor); QCursor cur(pixmap, 2, 3); ui->view->setCursor(cur); + ui->view->setShowToolOptions(false); helpLabel->setText(toolTip); dialogTool = new Dialog(pattern, 0, this); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); @@ -321,7 +323,8 @@ void MainWindow::ClosedDialog(int result) SCASSERT(dialogTool != nullptr); if (result == QDialog::Accepted) { - DrawTool::Create(dialogTool, currentScene, doc, pattern); + QGraphicsItem *tool = dynamic_cast(DrawTool::Create(dialogTool, currentScene, doc, pattern)); + ui->view->itemClicked(tool); } ArrowTool(); } @@ -349,9 +352,11 @@ void MainWindow::ClosedDialogWithApply(int result) vtool->FullUpdateFromGuiApply(); } } + QGraphicsItem *tool = dynamic_cast(dialogTool->GetAssociatedTool()); + ui->view->itemClicked(tool); if (dialogTool->GetAssociatedTool() != nullptr) { - VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + VDrawTool *vtool= static_cast(dialogTool->GetAssociatedTool()); vtool->DialogLinkDestroy(); } ArrowTool(); @@ -1067,6 +1072,7 @@ void MainWindow::ArrowTool() QCursor cur(Qt::ArrowCursor); ui->view->setCursor(cur); helpLabel->setText(""); + ui->view->setShowToolOptions(true); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index 78bbdfd57..108194901 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -52,6 +52,12 @@ void VAbstractSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *o QGraphicsPathItem::paint(painter, &myOption, widget); } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractSpline::getTagName() const +{ + return VAbstractSpline::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index 1b5f10b0a..810dd1c2a 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -42,6 +42,7 @@ public: virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::AbstractSpline)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile (); void Disable(bool disable); diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 106025ada..408b07b97 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -148,6 +148,36 @@ void VDrawTool::SaveDialogChange() } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief AddToFile add tag with informations about tool into file. + */ +void VDrawTool::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOptions(domElement, obj); + AddToCalculation(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. + */ +void VDrawTool::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOptions(domElement, obj); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogLinkDestroy removes dialog pointer diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index eeb750398..9d11576e8 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -81,6 +81,8 @@ protected: /** @brief SaveDialog save options into file after change in dialog. */ virtual void SaveDialog(QDomElement &domElement)=0; void SaveDialogChange(); + virtual void AddToFile(); + virtual void RefreshDataInFile(); template /** diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 9fe4bcd0a..0fe0eb783 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -31,7 +31,6 @@ #include "../../dialogs/tools/dialogalongline.h" #include "../../geometry/vpointf.h" #include "exception/vexceptionobjecterror.h" -#include "../undocommands/savetooloptions.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); @@ -114,38 +113,6 @@ void VToolAlongLine::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolAlongLine::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - SaveOptions(domElement, *point.data()); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolAlongLine::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SaveOptions(domElement, *point.data()); - } - else - { - qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -173,13 +140,16 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement) } //--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::SaveOptions(QDomElement &tag, const VPointF &point) +void VToolAlongLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) { + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + 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, 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); @@ -187,26 +157,6 @@ void VToolAlongLine::SaveOptions(QDomElement &tag, const VPointF &point) doc->SetAttribute(tag, AttrSecondPoint, secondPointId); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::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; - } -} - //--------------------------------------------------------------------------------------------------------------------- quint32 VToolAlongLine::getSecondPointId() const { @@ -218,46 +168,8 @@ void VToolAlongLine::setSecondPointId(const quint32 &value) { secondPointId = value; - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::setName(const QString &name) -{ - VPointF newPoint = VPointF(*VAbstractTool::data.GeometricObject(id).data()); - newPoint.setName(name); - SaveOption(newPoint); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::setTypeLine(const QString &value) -{ - typeLine = value; - - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::setFormulaLength(const VFormula &value) -{ - if (value.error() == false) - { - formulaLength = value.getFormula(FormulaType::FromUser); - - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VToolAlongLine::setFirstPointId(const quint32 &value) -{ - basePointId = value; - - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index 9d4d49e1a..a469b0d34 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -51,27 +51,22 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::AlongLine)}; - void setFirstPointId(const quint32 &value); + quint32 getSecondPointId() const; void setSecondPointId(const quint32 &value); - void setName(const QString &name); - void setTypeLine(const QString &value); - void setFormulaLength(const VFormula &value); + public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief secondPointId id second point of line. */ quint32 secondPointId; - void SaveOptions(QDomElement &tag, const VPointF &point); - void SaveOption(const VPointF &point); }; #endif // VTOOLALONGLINE_H diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index c7f4a6b07..3fe7d4bae 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -164,6 +164,12 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolArc::getTagName() const +{ + return VToolArc::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -183,42 +189,6 @@ void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolArc::AddToFile() -{ - const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); - doc->SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); - doc->SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); - doc->SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolArc::RefreshDataInFile() -{ - const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); - doc->SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); - doc->SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); - doc->SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -244,6 +214,20 @@ void VToolArc::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrAngle2, dialogTool->GetF2()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer arc = qSharedPointerDynamicCast(obj); + SCASSERT(arc.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrCenter, arc->GetCenter().id()); + doc->SetAttribute(tag, AttrRadius, arc->GetFormulaRadius()); + doc->SetAttribute(tag, AttrAngle1, arc->GetFormulaF1()); + doc->SetAttribute(tag, AttrAngle2, arc->GetFormulaF2()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 6417cf8c0..30a63acfb 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -48,14 +48,14 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Arc)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: void RefreshGeometry(); }; diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 69116db27..7f25bde4d 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -263,51 +263,6 @@ void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolBisector::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, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, basePointId); - doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolBisector::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, basePointId); - doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -335,3 +290,22 @@ void VToolBisector::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); doc->SetAttribute(domElement, AttrThirdPoint, QString().setNum(dialogTool->getThirdPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, basePointId); + doc->SetAttribute(tag, AttrThirdPoint, thirdPointId); +} diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index f824fd5bf..8bc7bd0e5 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -61,10 +61,9 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief firstPointId id first point of angle. */ quint32 firstPointId; diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index 75f432d5a..e110c1d6b 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -219,45 +219,6 @@ void VToolCutArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolCutArc::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, AttrLength, formula); - doc->SetAttribute(domElement, AttrArc, curveCutId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolCutArc::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrLength, formula); - doc->SetAttribute(domElement, AttrArc, curveCutId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -296,3 +257,19 @@ void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurve } curve->setPath(path); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutArc::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrLength, formula); + doc->SetAttribute(tag, AttrArc, curveCutId); +} diff --git a/src/app/tools/drawTools/vtoolcutarc.h b/src/app/tools/drawTools/vtoolcutarc.h index a64e4eff5..204871f43 100644 --- a/src/app/tools/drawTools/vtoolcutarc.h +++ b/src/app/tools/drawTools/vtoolcutarc.h @@ -56,11 +56,10 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, PathDirection direction = PathDirection::Hide); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolCutArc) }; diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 95a5aaee2..4f6f6332e 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -88,7 +88,7 @@ void VToolCutSpline::setDialog() * @param doc dom document container. * @param data container with variables. */ -void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, +VToolCutSpline* VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); @@ -97,7 +97,13 @@ void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); const quint32 splineId = dialogTool->getSplineId(); - Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolCutSpline* point = nullptr; + point = Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- @@ -115,9 +121,10 @@ void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splineId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splineId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) { const QSharedPointer spl = data->GeometricObject(splineId); @@ -175,7 +182,9 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString doc->AddTool(spl1id, point); doc->AddTool(spl2id, point); doc->IncrementReferens(splineId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -217,45 +226,6 @@ void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolCutSpline::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, AttrLength, formula); - doc->SetAttribute(domElement, AttrSpline, curveCutId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolCutSpline::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrLength, formula); - doc->SetAttribute(domElement, AttrSpline, curveCutId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -294,3 +264,19 @@ void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCu } curve->setPath(path); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrLength, formula); + doc->SetAttribute(tag, AttrSpline, curveCutId); +} diff --git a/src/app/tools/drawTools/vtoolcutspline.h b/src/app/tools/drawTools/vtoolcutspline.h index 221b0a278..ba4111e4d 100644 --- a/src/app/tools/drawTools/vtoolcutspline.h +++ b/src/app/tools/drawTools/vtoolcutspline.h @@ -43,10 +43,10 @@ public: const quint32 &splineId, const quint32 &spl1id, const quint32 &spl2id, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splineId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolCutSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolCutSpline *Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splineId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrSpline; virtual int type() const {return Type;} @@ -57,11 +57,10 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, PathDirection direction = PathDirection::Hide); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolCutSpline) }; diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index c252f325a..b9a62baca 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -91,7 +91,8 @@ void VToolCutSplinePath::setDialog() * @param doc dom document container. * @param data container with variables. */ -void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolCutSplinePath* VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data) { SCASSERT(dialog != nullptr); DialogCutSplinePath *dialogTool = qobject_cast(dialog); @@ -99,7 +100,13 @@ void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, V const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); const quint32 splinePathId = dialogTool->getSplinePathId(); - Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolCutSplinePath* point = nullptr; + point = Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- @@ -117,10 +124,10 @@ void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, V * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QString &formula, - const quint32 &splinePathId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splinePathId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) { const QSharedPointer splPath = data->GeometricObject(splinePathId); SCASSERT(splPath != nullptr); @@ -230,7 +237,9 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt doc->AddTool(splPath1id, point); doc->AddTool(splPath2id, point); doc->IncrementReferens(splinePathId); + return point; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -272,45 +281,6 @@ void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolCutSplinePath::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, AttrLength, formula); - doc->SetAttribute(domElement, AttrSplinePath, curveCutId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolCutSplinePath::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrLength, formula); - doc->SetAttribute(domElement, AttrSplinePath, curveCutId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -351,3 +321,19 @@ void VToolCutSplinePath::RefreshCurve(VSimpleCurve *curve, quint32 curveId, Simp } curve->setPath(path); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSplinePath::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrLength, formula); + doc->SetAttribute(tag, AttrSplinePath, curveCutId); +} diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.h b/src/app/tools/drawTools/vtoolcutsplinepath.h index 7a0c0050c..a7de665f2 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.h +++ b/src/app/tools/drawTools/vtoolcutsplinepath.h @@ -44,10 +44,11 @@ public: const quint32 &splinePathId, const quint32 &splPath1id, const quint32 &splPath2id, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splinePathId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolCutSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolCutSplinePath *Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splinePathId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrSplinePath; virtual int type() const {return Type;} @@ -58,11 +59,10 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, PathDirection direction = PathDirection::Hide); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolCutSplinePath) }; diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 83e9d7133..645df23c1 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -32,7 +32,6 @@ #include "../../dialogs/tools/dialogendline.h" #include "../../dialogs/tools/dialogeditwrongformula.h" #include "../../geometry/vpointf.h" -#include "../../undocommands/savetooloptions.h" const QString VToolEndLine::ToolType = QStringLiteral("endLine"); @@ -171,54 +170,6 @@ 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 VFormula &value) -{ - if (value.error() == false) - { - formulaLength = value.getFormula(FormulaType::FromUser); - - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -256,38 +207,6 @@ void VToolEndLine::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolEndLine::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - SaveOptions(domElement, *point.data()); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolEndLine::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SaveOptions(domElement, *point.data()); - } - else - { - qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -305,13 +224,16 @@ void VToolEndLine::SaveDialog(QDomElement &domElement) } //--------------------------------------------------------------------------------------------------------------------- -void VToolEndLine::SaveOptions(QDomElement &tag, const VPointF &point) +void VToolEndLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) { + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + 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, 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); @@ -336,16 +258,7 @@ void VToolEndLine::setFormulaAngle(const VFormula &value) { formulaAngle = value.getFormula(FormulaType::FromUser); - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - SaveOption(*point.data()); + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); } } - -//--------------------------------------------------------------------------------------------------------------------- -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 89448b29b..16c58c7ea 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -51,24 +51,19 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::EndLine)}; - void setName(const QString &name); + VFormula getFormulaAngle() const; void setFormulaAngle(const VFormula &value); - void setTypeLine(const QString &value); - void setFormulaLength(const VFormula &value); - void setBasePointId(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); 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/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index 8425e50f7..067cab00c 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -224,50 +224,6 @@ void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolHeight::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, AttrBasePoint, basePointId); - doc->SetAttribute(domElement, AttrP1Line, p1LineId); - doc->SetAttribute(domElement, AttrP2Line, p2LineId); - - AddToCalculation(domElement); - -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolHeight::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrBasePoint, basePointId); - doc->SetAttribute(domElement, AttrP1Line, p1LineId); - doc->SetAttribute(domElement, AttrP2Line, p2LineId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -283,3 +239,21 @@ void VToolHeight::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1LineId())); doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2LineId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrBasePoint, basePointId); + doc->SetAttribute(tag, AttrP1Line, p1LineId); + doc->SetAttribute(tag, AttrP2Line, p2LineId); +} diff --git a/src/app/tools/drawTools/vtoolheight.h b/src/app/tools/drawTools/vtoolheight.h index c7fb5b146..bbbfabf3a 100644 --- a/src/app/tools/drawTools/vtoolheight.h +++ b/src/app/tools/drawTools/vtoolheight.h @@ -57,9 +57,8 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief p1LineId id first point of line. */ quint32 p1LineId; diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index d05b337e5..abe37eba0 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -176,6 +176,12 @@ void VToolLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QGraphicsLineItem::paint(painter, &myOption, widget); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolLine::getTagName() const +{ + return VToolLine::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -254,11 +260,8 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void VToolLine::AddToFile() { QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrFirstPoint, firstPoint); - doc->SetAttribute(domElement, AttrSecondPoint, secondPoint); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - + QSharedPointer obj = QSharedPointer (); + SaveOptions(domElement, obj); AddToCalculation(domElement); } @@ -271,9 +274,12 @@ void VToolLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - doc->SetAttribute(domElement, AttrFirstPoint, firstPoint); - doc->SetAttribute(domElement, AttrSecondPoint, secondPoint); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); + QSharedPointer obj = QSharedPointer (); + SaveOptions(domElement, obj); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } } @@ -366,6 +372,17 @@ void VToolLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + Q_UNUSED(obj) + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrFirstPoint, firstPoint); + doc->SetAttribute(tag, AttrSecondPoint, secondPoint); + doc->SetAttribute(tag, AttrTypeLine, typeLine); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 8dfbd4c0e..722258cf4 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -50,6 +50,7 @@ public: virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Line)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); @@ -66,6 +67,7 @@ protected: virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void keyReleaseEvent(QKeyEvent * event); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief firstPoint id first line point. */ quint32 firstPoint; diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 1a83b0013..7ddc33983 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -234,49 +234,6 @@ void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolLineIntersect::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, AttrP1Line1, p1Line1); - doc->SetAttribute(domElement, AttrP2Line1, p2Line1); - doc->SetAttribute(domElement, AttrP1Line2, p1Line2); - doc->SetAttribute(domElement, AttrP2Line2, p2Line2); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolLineIntersect::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrP1Line1, p1Line1); - doc->SetAttribute(domElement, AttrP2Line1, p2Line1); - doc->SetAttribute(domElement, AttrP1Line2, p1Line2); - doc->SetAttribute(domElement, AttrP2Line2, p2Line2); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -304,3 +261,21 @@ void VToolLineIntersect::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrP1Line2, QString().setNum(dialogTool->getP1Line2())); doc->SetAttribute(domElement, AttrP2Line2, QString().setNum(dialogTool->getP2Line2())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrP1Line1, p1Line1); + doc->SetAttribute(tag, AttrP2Line1, p2Line1); + doc->SetAttribute(tag, AttrP1Line2, p1Line2); + doc->SetAttribute(tag, AttrP2Line2, p2Line2); +} diff --git a/src/app/tools/drawTools/vtoollineintersect.h b/src/app/tools/drawTools/vtoollineintersect.h index fe1802353..8a415c01e 100644 --- a/src/app/tools/drawTools/vtoollineintersect.h +++ b/src/app/tools/drawTools/vtoollineintersect.h @@ -56,10 +56,9 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief p1Line1 id first point first line. */ quint32 p1Line1; diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index fb02060e0..da3a06392 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -108,11 +108,25 @@ void VToolLinePoint::SetFactor(qreal factor) RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- quint32 VToolLinePoint::getBasePointId() const { return basePointId; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::setBasePointId(const quint32 &value) +{ + if (value != NULL_ID) + { + basePointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- VFormula VToolLinePoint::getFormulaLength() const { VFormula fLength(formulaLength, this->getData()); @@ -122,3 +136,15 @@ VFormula VToolLinePoint::getFormulaLength() const return fLength; } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::setFormulaLength(const VFormula &value) +{ + if (value.error() == false) + { + formulaLength = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 4929381d1..9640e1316 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -44,10 +44,10 @@ public: virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::LinePoint)}; VFormula getFormulaLength() const; - //void setFormulaLength(const QString &value)=0; + void setFormulaLength(const VFormula &value); quint32 getBasePointId() const; - //void setBasePointId(const quint32 &value)=0; + void setBasePointId(const quint32 &value); public slots: virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 4359363ae..e46e6ae4d 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -242,51 +242,6 @@ void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolNormal::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, angle); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolNormal::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, angle); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -313,3 +268,22 @@ void VToolNormal::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolNormal::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, angle); + doc->SetAttribute(tag, AttrFirstPoint, basePointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} diff --git a/src/app/tools/drawTools/vtoolnormal.h b/src/app/tools/drawTools/vtoolnormal.h index c5b1f8d0b..1f0458ade 100644 --- a/src/app/tools/drawTools/vtoolnormal.h +++ b/src/app/tools/drawTools/vtoolnormal.h @@ -58,10 +58,9 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief secondPointId id second line point. */ quint32 secondPointId; diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 13dd87e5c..8a40360a1 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -78,6 +78,20 @@ QString VToolPoint::name() const return VAbstractTool::data.GeometricObject(id)->name(); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPoint::setName(const QString &name) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + obj->setName(name); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPoint::getTagName() const +{ + return VToolPoint::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NameChangePosition handle change posion point label. diff --git a/src/app/tools/drawTools/vtoolpoint.h b/src/app/tools/drawTools/vtoolpoint.h index d06188241..5c19d073a 100644 --- a/src/app/tools/drawTools/vtoolpoint.h +++ b/src/app/tools/drawTools/vtoolpoint.h @@ -44,10 +44,11 @@ class VToolPoint: public VDrawTool, public QGraphicsEllipseItem public: VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); 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; + void setName(const QString &name); + virtual QString getTagName() const; + static const QString TagName; public slots: void NameChangePosition(const QPointF &pos); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 0f7ae3e28..e81d5aaae 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -260,49 +260,6 @@ void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolPointOfContact::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, AttrRadius, arcRadius); - doc->SetAttribute(domElement, AttrCenter, center); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolPointOfContact::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrRadius, arcRadius); - doc->SetAttribute(domElement, AttrCenter, center); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -329,3 +286,21 @@ void VToolPointOfContact::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrRadius, arcRadius); + doc->SetAttribute(tag, AttrCenter, center); + doc->SetAttribute(tag, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index 7bdb63e8b..cbbefba91 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -59,10 +59,9 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief radius string with formula radius arc. */ QString arcRadius; diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index 10790a8b4..bd7d845cc 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -203,45 +203,6 @@ void VToolPointOfIntersection::contextMenuEvent(QGraphicsSceneContextMenuEvent * ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolPointOfIntersection::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, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolPointOfIntersection::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -255,3 +216,19 @@ void VToolPointOfIntersection::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} diff --git a/src/app/tools/drawTools/vtoolpointofintersection.h b/src/app/tools/drawTools/vtoolpointofintersection.h index 55dcd021f..9a82ad1f9 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.h +++ b/src/app/tools/drawTools/vtoolpointofintersection.h @@ -57,9 +57,8 @@ public slots: protected: virtual void RemoveReferens(); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolPointOfIntersection) /** @brief firstPointId id first line point. */ diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 5221a18de..0d6cb2a2c 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -267,51 +267,6 @@ void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolShoulderPoint::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, AttrP1Line, basePointId); - doc->SetAttribute(domElement, AttrP2Line, p2Line); - doc->SetAttribute(domElement, AttrPShoulder, pShoulder); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolShoulderPoint::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrP1Line, basePointId); - doc->SetAttribute(domElement, AttrP2Line, p2Line); - doc->SetAttribute(domElement, AttrPShoulder, pShoulder); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -339,3 +294,22 @@ void VToolShoulderPoint::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2Line())); doc->SetAttribute(domElement, AttrPShoulder, QString().setNum(dialogTool->getPShoulder())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrP1Line, basePointId); + doc->SetAttribute(tag, AttrP2Line, p2Line); + doc->SetAttribute(tag, AttrPShoulder, pShoulder); +} diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index f1592ed2a..8c8b30a1d 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -59,10 +59,9 @@ public slots: virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief p2Line id second line point. */ quint32 p2Line; diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 83e23ed44..c8a9461fb 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -33,7 +33,6 @@ #include "../../undocommands/addpatternpiece.h" #include "../../undocommands/deletepatternpiece.h" #include "../../geometry/vpointf.h" -#include "../../undocommands/savetooloptions.h" #include @@ -83,34 +82,6 @@ void VToolSinglePoint::setDialog() dialogTool->setData(p->name(), p->toQPointF()); } -//--------------------------------------------------------------------------------------------------------------------- -void VToolSinglePoint::setName(const QString &name) -{ - QDomElement oldDomElement = doc->elementById(QString().setNum(id)); - if (oldDomElement.isElement()) - { - QDomElement newDomElement = oldDomElement.cloneNode().toElement(); - - VPointF newPoint = VPointF(*VAbstractTool::data.GeometricObject(id).data()); - newPoint.setName(name); - SaveOptions(newDomElement, newPoint); - - 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; - } -} - -//--------------------------------------------------------------------------------------------------------------------- -int VToolSinglePoint::type() const -{ - return Type; -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToFile add tag with informations about tool into file. @@ -119,11 +90,11 @@ void VToolSinglePoint::AddToFile() { Q_ASSERT_X(namePP.isEmpty() == false, "AddToFile", "name pattern piece is empty"); - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); QDomElement sPoint = doc->createElement(TagName); // Create SPoint tag - SaveOptions(sPoint, *point.data()); + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOptions(sPoint, obj); //Create pattern piece structure QDomElement patternPiece = doc->createElement(VPattern::TagDraw); @@ -142,24 +113,6 @@ void VToolSinglePoint::AddToFile() qApp->getUndoStack()->push(addPP); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolSinglePoint::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - SaveOptions(domElement, *point.data()); - } - else - { - qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief itemChange handle tool change. @@ -298,15 +251,18 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) } //--------------------------------------------------------------------------------------------------------------------- -void VToolSinglePoint::SaveOptions(QDomElement &tag, const VPointF &point) +void VToolSinglePoint::SaveOptions(QDomElement &tag, QSharedPointer &obj) { + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + doc->SetAttribute(tag, VDomDocument::AttrId, id); doc->SetAttribute(tag, AttrType, ToolType); - doc->SetAttribute(tag, AttrName, point.name()); - doc->SetAttribute(tag, AttrX, qApp->fromPixel(point.x())); - doc->SetAttribute(tag, AttrY, qApp->fromPixel(point.y())); - doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point.mx())); - doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point.my())); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrX, qApp->fromPixel(point->x())); + doc->SetAttribute(tag, AttrY, qApp->fromPixel(point->y())); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index 48c7494a0..98a60bcd5 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -43,8 +43,7 @@ public: const QString &namePP, const QString &mPath, QGraphicsItem * parent = nullptr ); virtual void setDialog(); static const QString ToolType; - void setName(const QString &name); - virtual int type()const; + virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::SinglePoint)}; public slots: virtual void FullUpdateFromFile(); @@ -59,7 +58,6 @@ signals: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); - virtual void RefreshDataInFile(); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void decrementReferens(); virtual void DeleteTool(bool ask = true); @@ -68,11 +66,12 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: QString namePP; QString mPath; void setColorLabel(const Qt::GlobalColor & color); - void SaveOptions(QDomElement &tag, const VPointF &point); + }; #endif // VTOOLSINGLEPOINT_H diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 9ddabb672..be3d9c641 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -225,48 +225,6 @@ void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolSpline::AddToFile() -{ - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); - doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); - doc->SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); - doc->SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); - doc->SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); - doc->SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); - doc->SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolSpline::RefreshDataInFile() -{ - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); - doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); - doc->SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); - doc->SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); - doc->SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); - doc->SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); - doc->SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -313,6 +271,23 @@ void VToolSpline::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrKCurve, spl.GetKcurve()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer spl = qSharedPointerDynamicCast(obj); + SCASSERT(spl.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrPoint1, spl->GetP1().id()); + doc->SetAttribute(tag, AttrPoint4, spl->GetP4().id()); + doc->SetAttribute(tag, AttrAngle1, spl->GetAngle1()); + doc->SetAttribute(tag, AttrAngle2, spl->GetAngle2()); + doc->SetAttribute(tag, AttrKAsm1, spl->GetKasm1()); + doc->SetAttribute(tag, AttrKAsm2, spl->GetKasm2()); + doc->SetAttribute(tag, AttrKCurve, spl->GetKcurve()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index f1607e17a..7d7cf2ca5 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -55,10 +55,9 @@ public slots: const QPointF &pos); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile (); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: void RefreshGeometry (); }; diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index c3e25c609..e157340fe 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -104,7 +104,7 @@ void VToolSplinePath::setDialog() * @param doc dom document container. * @param data container with variables. */ -void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolSplinePath* VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); DialogSplinePath *dialogTool = qobject_cast(dialog); @@ -114,7 +114,13 @@ void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPat { doc->IncrementReferens((*path)[i].P().id()); } - Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui); + VToolSplinePath* spl = nullptr; + spl = Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui); + if (spl != nullptr) + { + spl->dialog=dialogTool; + } + return spl; } //--------------------------------------------------------------------------------------------------------------------- @@ -128,7 +134,7 @@ void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPat * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, +VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) { quint32 id = _id; @@ -155,7 +161,9 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSplinePath::SetFactor); connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolSplinePath::Disable); doc->AddTool(id, spl); + return spl; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -266,27 +274,6 @@ void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolSplinePath::AddToFile() -{ - VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrKCurve, splPath.getKCurve()); - - for (qint32 i = 0; i < splPath.CountPoint(); ++i) - { - AddPathPoint(domElement, splPath.at(i)); - } - - AddToCalculation(domElement); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. @@ -352,6 +339,22 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement) UpdatePathPoint(doc, domElement, splPath); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer splPath = qSharedPointerDynamicCast(obj); + SCASSERT(splPath.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrKCurve, splPath->getKCurve()); + + for (qint32 i = 0; i < splPath->CountPoint(); ++i) + { + AddPathPoint(tag, splPath->at(i)); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index b94ffc919..e854c6d4f 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -41,9 +41,9 @@ public: VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation); + static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static void UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path); virtual int type() const {return Type;} @@ -69,10 +69,10 @@ public slots: const QPointF &pos); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: void RefreshGeometry(); void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index 73021e3f2..e41d547ba 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -263,49 +263,6 @@ void VToolTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolTriangle::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, AttrAxisP1, axisP1Id); - doc->SetAttribute(domElement, AttrAxisP2, axisP2Id); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolTriangle::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - 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, AttrAxisP1, axisP1Id); - doc->SetAttribute(domElement, AttrAxisP2, axisP2Id); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -321,3 +278,21 @@ void VToolTriangle::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + 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, AttrAxisP1, axisP1Id); + doc->SetAttribute(tag, AttrAxisP2, axisP2Id); + doc->SetAttribute(tag, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} diff --git a/src/app/tools/drawTools/vtooltriangle.h b/src/app/tools/drawTools/vtooltriangle.h index d8cca4530..4e36d4835 100644 --- a/src/app/tools/drawTools/vtooltriangle.h +++ b/src/app/tools/drawTools/vtooltriangle.h @@ -59,9 +59,8 @@ public slots: protected: virtual void RemoveReferens(); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolTriangle) /** @brief axisP1Id id first axis point. */ diff --git a/src/app/tools/nodeDetails/vabstractnode.cpp b/src/app/tools/nodeDetails/vabstractnode.cpp index 09f6e1da8..e8268da8d 100644 --- a/src/app/tools/nodeDetails/vabstractnode.cpp +++ b/src/app/tools/nodeDetails/vabstractnode.cpp @@ -130,3 +130,9 @@ void VAbstractNode::RestoreReferens() doc->IncrementReferens(idNode); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractNode::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + +} diff --git a/src/app/tools/nodeDetails/vabstractnode.h b/src/app/tools/nodeDetails/vabstractnode.h index 9cca668bf..3d167618b 100644 --- a/src/app/tools/nodeDetails/vabstractnode.h +++ b/src/app/tools/nodeDetails/vabstractnode.h @@ -56,6 +56,7 @@ protected: virtual void decrementReferens(); virtual void RemoveReferens(); virtual void RestoreReferens(); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); }; #endif // VABSTRACTNODE_H diff --git a/src/app/tools/nodeDetails/vnodearc.cpp b/src/app/tools/nodeDetails/vnodearc.cpp index 802265e19..829d86b22 100644 --- a/src/app/tools/nodeDetails/vnodearc.cpp +++ b/src/app/tools/nodeDetails/vnodearc.cpp @@ -124,6 +124,12 @@ void VNodeArc::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodeArc::getTagName() const +{ + return VNodeArc::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -144,7 +150,7 @@ void VNodeArc::AddToFile() doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } @@ -162,7 +168,7 @@ void VNodeArc::RefreshDataInFile() if (domElement.isElement()) { doc->SetAttribute(domElement, AttrIdObject, idNode); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } diff --git a/src/app/tools/nodeDetails/vnodearc.h b/src/app/tools/nodeDetails/vnodearc.h index b199855cb..5341a3f99 100644 --- a/src/app/tools/nodeDetails/vnodearc.h +++ b/src/app/tools/nodeDetails/vnodearc.h @@ -51,6 +51,7 @@ public: virtual void RestoreNode(); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::NodeArc)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/tools/nodeDetails/vnodepoint.cpp b/src/app/tools/nodeDetails/vnodepoint.cpp index 5e02e2443..cce6c8629 100644 --- a/src/app/tools/nodeDetails/vnodepoint.cpp +++ b/src/app/tools/nodeDetails/vnodepoint.cpp @@ -136,6 +136,12 @@ void VNodePoint::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodePoint::getTagName() const +{ + return VNodePoint::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -159,7 +165,7 @@ void VNodePoint::AddToFile() doc->SetAttribute(domElement, AttrIdObject, idNode); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } @@ -180,7 +186,7 @@ void VNodePoint::RefreshDataInFile() doc->SetAttribute(domElement, AttrIdObject, idNode); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } diff --git a/src/app/tools/nodeDetails/vnodepoint.h b/src/app/tools/nodeDetails/vnodepoint.h index 0201af254..23e666aa8 100644 --- a/src/app/tools/nodeDetails/vnodepoint.h +++ b/src/app/tools/nodeDetails/vnodepoint.h @@ -57,6 +57,7 @@ public: virtual void RestoreNode(); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::NodePoint)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); void NameChangePosition(const QPointF &pos); diff --git a/src/app/tools/nodeDetails/vnodespline.cpp b/src/app/tools/nodeDetails/vnodespline.cpp index ffbe5327d..73227ca84 100644 --- a/src/app/tools/nodeDetails/vnodespline.cpp +++ b/src/app/tools/nodeDetails/vnodespline.cpp @@ -127,6 +127,12 @@ void VNodeSpline::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodeSpline::getTagName() const +{ + return VNodeSpline::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -147,7 +153,7 @@ void VNodeSpline::AddToFile() doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } @@ -165,7 +171,7 @@ void VNodeSpline::RefreshDataInFile() if (domElement.isElement()) { doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } diff --git a/src/app/tools/nodeDetails/vnodespline.h b/src/app/tools/nodeDetails/vnodespline.h index ea29108a2..4ae2225f5 100644 --- a/src/app/tools/nodeDetails/vnodespline.h +++ b/src/app/tools/nodeDetails/vnodespline.h @@ -51,6 +51,7 @@ public: virtual void RestoreNode(); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::NodeSpline)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile (); protected: diff --git a/src/app/tools/nodeDetails/vnodesplinepath.cpp b/src/app/tools/nodeDetails/vnodesplinepath.cpp index 9451e3f11..5047aea9d 100644 --- a/src/app/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/app/tools/nodeDetails/vnodesplinepath.cpp @@ -130,6 +130,12 @@ void VNodeSplinePath::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodeSplinePath::getTagName() const +{ + return VNodeSplinePath::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/tools/nodeDetails/vnodesplinepath.h b/src/app/tools/nodeDetails/vnodesplinepath.h index 7be54d734..d92bed5a3 100644 --- a/src/app/tools/nodeDetails/vnodesplinepath.h +++ b/src/app/tools/nodeDetails/vnodesplinepath.h @@ -50,6 +50,7 @@ public: virtual void RestoreNode(); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::SplinePath)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 3dea9ee93..adf2d4f5a 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -32,6 +32,7 @@ #include "../undocommands/deltool.h" #include "../widgets/vapplication.h" #include "../geometry/vpointf.h" +#include "../undocommands/savetooloptions.h" const QString VAbstractTool::AttrType = QStringLiteral("type"); const QString VAbstractTool::AttrMx = QStringLiteral("mx"); @@ -289,11 +290,23 @@ Qt::PenStyle VAbstractTool::LineStyle(const QString &typeLine) break; } } + +//--------------------------------------------------------------------------------------------------------------------- QString VAbstractTool::getLineType() const { return typeLine; } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractTool::setTypeLine(const QString &value) +{ + typeLine = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- QMap VAbstractTool::PointsList() const { const QHash > *objs = data.DataGObjects(); @@ -314,7 +327,6 @@ QMap VAbstractTool::PointsList() const return list; } - //--------------------------------------------------------------------------------------------------------------------- int VAbstractTool::ConfirmDeletion() { @@ -327,6 +339,26 @@ int VAbstractTool::ConfirmDeletion() return msgBox.exec(); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractTool::SaveOption(QSharedPointer &obj) +{ + QDomElement oldDomElement = doc->elementById(QString().setNum(id)); + if (oldDomElement.isElement()) + { + QDomElement newDomElement = oldDomElement.cloneNode().toElement(); + + SaveOptions(newDomElement, obj); + + 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; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief LineCoefficients coefficient for equation of segment. Segment equestion ax+by+c=0. diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index b945ec805..210b02480 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -102,8 +102,10 @@ public: const VContainer *getData() const; QString getLineType() const; - //void setTypeLine(const QString &value)=0; + void setTypeLine(const QString &value); QMap PointsList() const; + virtual QString getTagName() const =0; + public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -139,6 +141,7 @@ protected: /** @brief typeLine line type. */ QString typeLine; + /** * @brief AddToFile add tag with informations about tool into file. */ @@ -153,6 +156,8 @@ protected: virtual void RemoveReferens(){} virtual void DeleteTool(bool ask = true); static int ConfirmDeletion(); + void SaveOption(QSharedPointer &obj); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj)=0; private: Q_DISABLE_COPY(VAbstractTool) }; diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index d93488eaf..010e96b04 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -370,6 +370,12 @@ void VToolDetail::keyReleaseEvent(QKeyEvent *event) QGraphicsItem::keyReleaseEvent ( event ); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief mouseReleaseEvent handle mouse release events. @@ -475,6 +481,12 @@ void VToolDetail::AddNode(VPattern *doc, QDomElement &domElement, const VNodeDet domElement.appendChild(nod); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolDetail::getTagName() const +{ + return VToolDetail::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/vtooldetail.h b/src/app/tools/vtooldetail.h index cd0c9bec8..3b33c0695 100644 --- a/src/app/tools/vtooldetail.h +++ b/src/app/tools/vtooldetail.h @@ -84,6 +84,7 @@ public: static void AddNode(VPattern *doc, QDomElement &domElement, const VNodeDetail &node); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Detail)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile (); virtual void FullUpdateFromGuiOk(int result); @@ -95,6 +96,7 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void RemoveReferens(); virtual void keyReleaseEvent(QKeyEvent * event); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolDetail) /** @brief dialog dialog options. */ diff --git a/src/app/tools/vtooluniondetails.cpp b/src/app/tools/vtooluniondetails.cpp index 76b9dfc7c..a8cbcd6b3 100644 --- a/src/app/tools/vtooluniondetails.cpp +++ b/src/app/tools/vtooluniondetails.cpp @@ -435,6 +435,12 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q point->setY(line.p2().y()); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolUnionDetails::getTagName() const +{ + return VToolUnionDetails::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool from GUI. @@ -442,7 +448,8 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q * @param doc dom document container. * @param data container with variables. */ -void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolUnionDetails* VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data) { SCASSERT(dialog != nullptr); DialogUnionDetails *dialogTool = qobject_cast(dialog); @@ -452,9 +459,11 @@ void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VP quint32 indexD1 = static_cast(dialogTool->getIndexD1()); quint32 indexD2 = static_cast(dialogTool->getIndexD2()); qApp->getUndoStack()->beginMacro("union details"); - Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolUnionDetails* tool = nullptr; + tool = Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, + Document::FullParse, Source::FromGui); qApp->getUndoStack()->endMacro(); + return tool; } //--------------------------------------------------------------------------------------------------------------------- @@ -473,10 +482,10 @@ void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VP * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, - const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2, + const quint32 &d1id, const quint32 &d2id, const quint32 &indexD1, + const quint32 &indexD2, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation) { VToolUnionDetails *unionDetails = 0; quint32 id = _id; @@ -609,6 +618,7 @@ void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDeta } } while (i &obj) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddDetail add detail to xml file. diff --git a/src/app/tools/vtooluniondetails.h b/src/app/tools/vtooluniondetails.h index bc610a0c3..2d4168c55 100644 --- a/src/app/tools/vtooluniondetails.h +++ b/src/app/tools/vtooluniondetails.h @@ -50,11 +50,11 @@ public: * @brief setDialog set dialog when user want change tool option. */ virtual void setDialog() {} - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, - const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, VMainGraphicsScene *scene, - VPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolUnionDetails *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolUnionDetails *Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, + const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); static void PointsOnEdge(const VDetail &d, const quint32 &index, VPointF &p1, VPointF &p2, VContainer *data); static void FindJ(const qint32 &pointsD2, const VDetail &d2, const quint32 &indexD2, qint32 &j); static QVector GetDetailFromFile(VPattern *doc, const QDomElement &domElement); @@ -76,6 +76,7 @@ public: const qreal &angle = 0); static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, const qreal &angle); + virtual QString getTagName() const; public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -84,6 +85,7 @@ public slots: protected: virtual void AddToFile(); virtual void RefreshDataInFile(); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolUnionDetails) /** @brief d1 first detail. */ diff --git a/src/app/widgets/vmaingraphicsview.cpp b/src/app/widgets/vmaingraphicsview.cpp index a11e3b0d9..4a7ef658b 100644 --- a/src/app/widgets/vmaingraphicsview.cpp +++ b/src/app/widgets/vmaingraphicsview.cpp @@ -157,7 +157,7 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event) * @param parent parent object. */ VMainGraphicsView::VMainGraphicsView(QWidget *parent) - :QGraphicsView(parent), zoom(nullptr) + :QGraphicsView(parent), zoom(nullptr), showToolOptions(true) { zoom = new GraphicsViewZoom(this); this->setResizeAnchor(QGraphicsView::AnchorUnderMouse); @@ -221,7 +221,10 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); break; case Qt::NoModifier: - emit itemClicked(itemAt(mousePress->pos())); + if (showToolOptions) + { + emit itemClicked(itemAt(mousePress->pos())); + } break; default: break; @@ -244,3 +247,10 @@ void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event) emit MouseRelease(); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsView::setShowToolOptions(bool value) +{ + showToolOptions = value; +} + diff --git a/src/app/widgets/vmaingraphicsview.h b/src/app/widgets/vmaingraphicsview.h index 8df21f47c..abec4a09e 100644 --- a/src/app/widgets/vmaingraphicsview.h +++ b/src/app/widgets/vmaingraphicsview.h @@ -97,6 +97,8 @@ class VMainGraphicsView : public QGraphicsView public: explicit VMainGraphicsView(QWidget *parent = nullptr); + void setShowToolOptions(bool value); + signals: /** * @brief NewFactor send new scale factor. @@ -120,6 +122,7 @@ protected: void mouseReleaseEvent(QMouseEvent *event); private: GraphicsViewZoom* zoom; + bool showToolOptions; }; #endif // VMAINGRAPHICSVIEW_H diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index ac0c877b2..d2ecf97e3 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -390,7 +390,7 @@ void VToolOptionsPropertyBrowser::ChangeDataToolAlongLine(VProperty *property) SetPointName(value.toString()); break; case 6: // VAbstractTool::AttrFirstPoint - i->setFirstPointId(value.toUInt()); + i->setBasePointId(value.toUInt()); break; case 7: // VAbstractTool::AttrSecondPoint i->setSecondPointId(value.toUInt()); From d4a71f76646de5dec34922beb88ce0af0dc6ca6a Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 14:01:50 +0300 Subject: [PATCH 24/52] Hide options when use context menu. --HG-- branch : feature --- src/app/tools/drawTools/vdrawtool.h | 3 +++ src/app/widgets/vtooloptionspropertybrowser.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index 9d11576e8..0254e5363 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -36,6 +36,7 @@ #include "../../dialogs/tools/dialogtool.h" #include "../../widgets/vmaingraphicsscene.h" #include "../../xml/vpattern.h" +#include "../../widgets/vmaingraphicsview.h" /** * @brief The VDrawTool abstract class for all draw tool. @@ -120,6 +121,7 @@ protected: QAction *selectedAction = menu.exec(event->screenPos()); if (selectedAction == actionOption) { + qApp->getSceneView()->itemClicked(nullptr); dialog = new Dialog(getData(), id, qApp->getMainWindow()); dialog->setModal(true); @@ -136,6 +138,7 @@ protected: } if (selectedAction == actionRemove) { + qApp->getSceneView()->itemClicked(nullptr); DeleteTool(); } } diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index d2ecf97e3..b3a0c9a32 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -87,7 +87,7 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); AddPropertyLineType(i, tr("Line type")); AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); - AddPropertyFormula(tr("Angle"), i->getFormulaLength(), VAbstractTool::AttrAngle); + AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); break; } case VToolAlongLine::Type: From 8412cb464a1999c43c151182f9f4754767bddc56 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 15:53:57 +0300 Subject: [PATCH 25/52] Draft. --HG-- branch : feature --- .../widgets/vtooloptionspropertybrowser.cpp | 557 +++++++++++++++--- src/app/widgets/vtooloptionspropertybrowser.h | 53 ++ 2 files changed, 542 insertions(+), 68 deletions(-) diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index b3a0c9a32..bd3fda554 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -67,41 +67,59 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) switch (item->type()) { case VToolSinglePoint::Type: - { - VToolSinglePoint *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Base point")); - - AddPropertyPointName(i, tr("Point name")); - - VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); - itemPosition->setValue(i->pos()); - AddProperty(itemPosition, QLatin1String("position")); + ShowOptionsToolSinglePoint(item); break; - } case VToolEndLine::Type: - { - VToolEndLine *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Point at distance and angle")); - - AddPropertyPointName(i, tr("Point name")); - AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); - AddPropertyLineType(i, tr("Line type")); - AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); - AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); + ShowOptionsToolEndLine(item); break; - } case VToolAlongLine::Type: - { - VToolAlongLine *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Point at distance along line")); - - AddPropertyPointName(i, tr("Point name")); - AddPropertyPointsList(i, tr("First point"), i->getBasePointId(), VAbstractTool::AttrFirstPoint); - AddPropertyPointsList(i, tr("Second point"), i->getSecondPointId(), VAbstractTool::AttrSecondPoint); - AddPropertyLineType(i, tr("Line type")); - AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + ShowOptionsToolAlongLine(item); + break; + case VToolArc::Type: + ShowOptionsToolArc(item); + break; + case VToolBisector::Type: + ShowOptionsToolBisector(item); + break; + case VToolCutArc::Type: + ShowOptionsToolCutArc(item); + break; + case VToolCutSpline::Type: + ShowOptionsToolCutSpline(item); + break; + case VToolCutSplinePath::Type: + ShowOptionsToolCutSplinePath(item); + break; + case VToolHeight::Type: + ShowOptionsToolHeight(item); + break; + case VToolLine::Type: + ShowOptionsToolLine(item); + break; + case VToolLineIntersect::Type: + ShowOptionsToolLineIntersect(item); + break; + case VToolNormal::Type: + ShowOptionsToolNormal(item); + break; + case VToolPointOfContact::Type: + ShowOptionsToolPointOfContact(item); + break; + case VToolPointOfIntersection::Type: + ShowOptionsToolPointOfIntersection(item); + break; + case VToolShoulderPoint::Type: + ShowOptionsToolShoulderPoint(item); + break; + case VToolSpline::Type: + ShowOptionsToolSpline(item); + break; + case VToolSplinePath::Type: + ShowOptionsToolSplinePath(item); + break; + case VToolTriangle::Type: + ShowOptionsToolTriangle(item); break; - } case VGraphicsSimpleTextItem::Type: currentItem = item->parentItem(); ShowItemOptions(currentItem); @@ -126,49 +144,59 @@ void VToolOptionsPropertyBrowser::UpdateOptions() switch (currentItem->type()) { case VToolSinglePoint::Type: - { - VToolSinglePoint *i = qgraphicsitem_cast(currentItem); - idToProperty[VAbstractTool::AttrName]->setValue(i->name()); - idToProperty[QLatin1String("position")]->setValue(i->pos()); + UpdateOptionsToolSinglePoint(); break; - } case VToolEndLine::Type: - { - VToolEndLine *i = qgraphicsitem_cast(currentItem); - idToProperty[VAbstractTool::AttrName]->setValue(i->name()); - idToProperty[VAbstractTool::AttrBasePoint]->setValue(i->getBasePointId()); - - QStringList styles = VAbstractTool::Styles(); - qint32 index = styles.indexOf(i->getLineType()); - idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); - - QVariant valueFormula; - valueFormula.setValue(i->getFormulaLength()); - idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); - - QVariant valueAngle; - valueAngle.setValue(i->getFormulaAngle()); - idToProperty[VAbstractTool::AttrAngle]->setValue(valueAngle); - + UpdateOptionsToolEndLine(); break; - } case VToolAlongLine::Type: - { - VToolAlongLine *i = qgraphicsitem_cast(currentItem); - idToProperty[VAbstractTool::AttrName]->setValue(i->name()); - idToProperty[VAbstractTool::AttrFirstPoint]->setValue(i->getBasePointId()); - idToProperty[VAbstractTool::AttrSecondPoint]->setValue(i->getSecondPointId()); - - QStringList styles = VAbstractTool::Styles(); - qint32 index = styles.indexOf(i->getLineType()); - idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); - - QVariant valueFormula; - valueFormula.setValue(i->getFormulaLength()); - idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); - + UpdateOptionsToolAlongLine(); + break; + case VToolArc::Type: + UpdateOptionsToolArc(); + break; + case VToolBisector::Type: + UpdateOptionsToolBisector(); + break; + case VToolCutArc::Type: + UpdateOptionsToolCutArc(); + break; + case VToolCutSpline::Type: + UpdateOptionsToolCutSpline(); + break; + case VToolCutSplinePath::Type: + UpdateOptionsToolCutSplinePath(); + break; + case VToolHeight::Type: + UpdateOptionsToolHeight(); + break; + case VToolLine::Type: + UpdateOptionsToolLine(); + break; + case VToolLineIntersect::Type: + UpdateOptionsToolLineIntersect(); + break; + case VToolNormal::Type: + UpdateOptionsToolNormal(); + break; + case VToolPointOfContact::Type: + UpdateOptionsToolPointOfContact(); + break; + case VToolPointOfIntersection::Type: + UpdateOptionsToolPointOfIntersection(); + break; + case VToolShoulderPoint::Type: + UpdateOptionsToolShoulderPoint(); + break; + case VToolSpline::Type: + UpdateOptionsToolSpline(); + break; + case VToolSplinePath::Type: + UpdateOptionsToolSplinePath(); + break; + case VToolTriangle::Type: + UpdateOptionsToolTriangle(); break; - } case VGraphicsSimpleTextItem::Type: ShowItemOptions(currentItem->parentItem()); break; @@ -212,6 +240,51 @@ void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) case VToolAlongLine::Type: ChangeDataToolAlongLine(prop); break; + case VToolArc::Type: + ChangeDataToolArc(prop); + break; + case VToolBisector::Type: + ChangeDataToolBisector(prop); + break; + case VToolCutArc::Type: + ChangeDataToolCutArc(prop); + break; + case VToolCutSpline::Type: + ChangeDataToolCutSpline(prop); + break; + case VToolCutSplinePath::Type: + ChangeDataToolCutSplinePath(prop); + break; + case VToolHeight::Type: + ChangeDataToolHeight(prop); + break; + case VToolLine::Type: + ChangeDataToolLine(prop); + break; + case VToolLineIntersect::Type: + ChangeDataToolLineIntersect(prop); + break; + case VToolNormal::Type: + ChangeDataToolNormal(prop); + break; + case VToolPointOfContact::Type: + ChangeDataToolPointOfContact(prop); + break; + case VToolPointOfIntersection::Type: + ChangeDataToolPointOfIntersection(prop); + break; + case VToolShoulderPoint::Type: + ChangeDataToolShoulderPoint(prop); + break; + case VToolSpline::Type: + ChangeDataToolSpline(prop); + break; + case VToolSplinePath::Type: + ChangeDataToolSplinePath(prop); + break; + case VToolTriangle::Type: + ChangeDataToolTriangle(prop); + break; default: break; } @@ -407,6 +480,354 @@ void VToolOptionsPropertyBrowser::ChangeDataToolAlongLine(VProperty *property) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolArc(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolBisector(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolCutArc(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolCutSpline(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolCutSplinePath(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolHeight(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolLine(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolLineIntersect(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolNormal(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolPointOfContact(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolPointOfIntersection(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolShoulderPoint(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolSpline(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolSplinePath(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolTriangle(VProperty *property) +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolSinglePoint(QGraphicsItem *item) +{ + VToolSinglePoint *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Base point")); + + AddPropertyPointName(i, tr("Point name")); + + VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); + itemPosition->setValue(i->pos()); + AddProperty(itemPosition, QLatin1String("position")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item) +{ + VToolEndLine *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Point at distance and angle")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item) +{ + VToolAlongLine *i = qgraphicsitem_cast(item); + TreeView->setTitle(tr("Point at distance along line")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("First point"), i->getBasePointId(), VAbstractTool::AttrFirstPoint); + AddPropertyPointsList(i, tr("Second point"), i->getSecondPointId(), VAbstractTool::AttrSecondPoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolArc(QGraphicsItem *item) +{ + VToolArc *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item) +{ + VToolBisector *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolCutArc(QGraphicsItem *item) +{ + VToolCutArc *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolCutSpline(QGraphicsItem *item) +{ + VToolCutSpline *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolCutSplinePath(QGraphicsItem *item) +{ + VToolCutSplinePath *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolHeight(QGraphicsItem *item) +{ + VToolHeight *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolLine(QGraphicsItem *item) +{ + VToolLine *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersect(QGraphicsItem *item) +{ + VToolLineIntersect *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolNormal(QGraphicsItem *item) +{ + VToolNormal *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfContact(QGraphicsItem *item) +{ + VToolPointOfContact *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersection(QGraphicsItem *item) +{ + VToolPointOfIntersection *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *item) +{ + VToolShoulderPoint *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) +{ + VToolSpline *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item) +{ + VToolSplinePath *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item) +{ + VToolTriangle *i = qgraphicsitem_cast(item); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() +{ + VToolSinglePoint *i = qgraphicsitem_cast(currentItem); + TreeView->setTitle(tr("Base point")); + + AddPropertyPointName(i, tr("Point name")); + + VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); + itemPosition->setValue(i->pos()); + AddProperty(itemPosition, QLatin1String("position")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolEndLine() +{ + VToolEndLine *i = qgraphicsitem_cast(currentItem); + TreeView->setTitle(tr("Point at distance and angle")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolAlongLine() +{ + VToolAlongLine *i = qgraphicsitem_cast(currentItem); + TreeView->setTitle(tr("Point at distance along line")); + + AddPropertyPointName(i, tr("Point name")); + AddPropertyPointsList(i, tr("First point"), i->getBasePointId(), VAbstractTool::AttrFirstPoint); + AddPropertyPointsList(i, tr("Second point"), i->getSecondPointId(), VAbstractTool::AttrSecondPoint); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolArc() +{ + VToolArc *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolBisector() +{ + VToolBisector *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCutArc() +{ + VToolCutArc *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSpline() +{ + VToolCutSpline *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSplinePath() +{ + VToolCutSplinePath *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolHeight() +{ + VToolHeight *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolLine() +{ + VToolLine *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolLineIntersect() +{ + VToolLineIntersect *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolNormal() +{ + VToolNormal *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfContact() +{ + VToolPointOfContact *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfIntersection() +{ + VToolPointOfIntersection *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolShoulderPoint() +{ + VToolShoulderPoint *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() +{ + VToolSpline *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() +{ + VToolSplinePath *i = qgraphicsitem_cast(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle() +{ + VToolTriangle *i = qgraphicsitem_cast(currentItem); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h index f66a62d1e..5a6b57e81 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.h +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -84,6 +84,59 @@ private: void ChangeDataToolSinglePoint(VProperty *property); void ChangeDataToolEndLine(VProperty *property); void ChangeDataToolAlongLine(VProperty *property); + void ChangeDataToolArc(VProperty *property); + void ChangeDataToolBisector(VProperty *property); + void ChangeDataToolCutArc(VProperty *property); + void ChangeDataToolCutSpline(VProperty *property); + void ChangeDataToolCutSplinePath(VProperty *property); + void ChangeDataToolHeight(VProperty *property); + void ChangeDataToolLine(VProperty *property); + void ChangeDataToolLineIntersect(VProperty *property); + void ChangeDataToolNormal(VProperty *property); + void ChangeDataToolPointOfContact(VProperty *property); + void ChangeDataToolPointOfIntersection(VProperty *property); + void ChangeDataToolShoulderPoint(VProperty *property); + void ChangeDataToolSpline(VProperty *property); + void ChangeDataToolSplinePath(VProperty *property); + void ChangeDataToolTriangle(VProperty *property); + + void ShowOptionsToolSinglePoint(QGraphicsItem *item); + void ShowOptionsToolEndLine(QGraphicsItem *item); + void ShowOptionsToolAlongLine(QGraphicsItem *item); + void ShowOptionsToolArc(QGraphicsItem *item); + void ShowOptionsToolBisector(QGraphicsItem *item); + void ShowOptionsToolCutArc(QGraphicsItem *item); + void ShowOptionsToolCutSpline(QGraphicsItem *item); + void ShowOptionsToolCutSplinePath(QGraphicsItem *item); + void ShowOptionsToolHeight(QGraphicsItem *item); + void ShowOptionsToolLine(QGraphicsItem *item); + void ShowOptionsToolLineIntersect(QGraphicsItem *item); + void ShowOptionsToolNormal(QGraphicsItem *item); + void ShowOptionsToolPointOfContact(QGraphicsItem *item); + void ShowOptionsToolPointOfIntersection(QGraphicsItem *item); + void ShowOptionsToolShoulderPoint(QGraphicsItem *item); + void ShowOptionsToolSpline(QGraphicsItem *item); + void ShowOptionsToolSplinePath(QGraphicsItem *item); + void ShowOptionsToolTriangle(QGraphicsItem *item); + + void UpdateOptionsToolSinglePoint(); + void UpdateOptionsToolEndLine(); + void UpdateOptionsToolAlongLine(); + void UpdateOptionsToolArc(); + void UpdateOptionsToolBisector(); + void UpdateOptionsToolCutArc(); + void UpdateOptionsToolCutSpline(); + void UpdateOptionsToolCutSplinePath(); + void UpdateOptionsToolHeight(); + void UpdateOptionsToolLine(); + void UpdateOptionsToolLineIntersect(); + void UpdateOptionsToolNormal(); + void UpdateOptionsToolPointOfContact(); + void UpdateOptionsToolPointOfIntersection(); + void UpdateOptionsToolShoulderPoint(); + void UpdateOptionsToolSpline(); + void UpdateOptionsToolSplinePath(); + void UpdateOptionsToolTriangle(); }; #endif // VTOOLOPTIONSPROPERTYBROWSER_H From 3d3282ae61118d6717573ddd94953918bd25b651 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 17:34:45 +0300 Subject: [PATCH 26/52] Setter and getter for options VToolArc. --HG-- branch : feature --- src/app/container/vformula.cpp | 28 ++++-- src/app/container/vformula.h | 4 +- src/app/geometry/varc.cpp | 29 +++++++ src/app/geometry/varc.h | 11 ++- src/app/tools/drawTools/vtoolarc.cpp | 99 +++++++++++++++++++++- src/app/tools/drawTools/vtoolarc.h | 14 +++ src/app/widgets/vformulaproperty.cpp | 2 +- src/app/widgets/vformulapropertyeditor.cpp | 6 +- 8 files changed, 178 insertions(+), 15 deletions(-) diff --git a/src/app/container/vformula.cpp b/src/app/container/vformula.cpp index 412934508..b9a9719ea 100644 --- a/src/app/container/vformula.cpp +++ b/src/app/container/vformula.cpp @@ -35,13 +35,13 @@ //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula() :formula(QString()), value(QString(tr("Error"))), checkZero(true), data(nullptr), toolId(NULL_ID), - postfix(QStringLiteral("")), _error(true) + postfix(QStringLiteral("")), _error(true), dValue(0) {} //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula(const QString &formula, const VContainer *container) :formula(qApp->FormulaToUser(formula)), value(QString(tr("Error"))), checkZero(true), data(container), toolId(NULL_ID), - postfix(QStringLiteral("")), _error(true) + postfix(QStringLiteral("")), _error(true), dValue(0) { this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist Eval(); @@ -55,29 +55,31 @@ VFormula &VFormula::operator=(const VFormula &formula) return *this; } this->formula = formula.getFormula(); - this->value = formula.getValue(); + this->value = formula.getStringValue(); this->checkZero = formula.getCheckZero(); this->data = formula.getData(); this->toolId = formula.getToolId(); this->postfix = formula.getPostfix(); this->_error = formula.error(); + this->dValue = formula.getDoubleValue(); return *this; } //--------------------------------------------------------------------------------------------------------------------- VFormula::VFormula(const VFormula &formula) - :formula(formula.getFormula()), value(formula.getValue()), checkZero(formula.getCheckZero()), - data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()) + :formula(formula.getFormula()), value(formula.getStringValue()), checkZero(formula.getCheckZero()), + data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()), + dValue(formula.getDoubleValue()) {} //--------------------------------------------------------------------------------------------------------------------- bool VFormula::operator==(const VFormula &formula) const { bool isEqual = false; - if (this->formula == formula.getFormula() && this->value == formula.getValue() && + if (this->formula == formula.getFormula() && this->value == formula.getStringValue() && this->checkZero == formula.getCheckZero() && this->data == formula.getData() && this->toolId == formula.getToolId() && this->postfix == formula.getPostfix() && - this->_error == formula.error()) + this->_error == formula.error() && this->dValue == formula.getDoubleValue()) { isEqual = true; } @@ -121,11 +123,17 @@ void VFormula::setFormula(const QString &value, FormulaType type) } //--------------------------------------------------------------------------------------------------------------------- -QString VFormula::getValue() const +QString VFormula::getStringValue() const { return value; } +//--------------------------------------------------------------------------------------------------------------------- +qreal VFormula::getDoubleValue() const +{ + return dValue; +} + //--------------------------------------------------------------------------------------------------------------------- bool VFormula::getCheckZero() const { @@ -209,6 +217,7 @@ void VFormula::Eval() { value = QString(tr("Error")); _error = true; + dValue = 0; } else { @@ -224,6 +233,7 @@ void VFormula::Eval() { value = QString("0"); _error = true; + dValue = 0; } else { @@ -236,6 +246,7 @@ void VFormula::Eval() { loc = QLocale(QLocale::C); } + dValue = result; value = QString(loc.toString(result) + " " + postfix); _error = false; } @@ -244,6 +255,7 @@ void VFormula::Eval() { value = QString(tr("Error")); _error = true; + dValue = 0; qDebug() << "\nMath parser error:\n" << "--------------------------------------\n" << "Message: " << e.GetMsg() << "\n" diff --git a/src/app/container/vformula.h b/src/app/container/vformula.h index c60453de7..222845442 100644 --- a/src/app/container/vformula.h +++ b/src/app/container/vformula.h @@ -49,7 +49,8 @@ public: QString getFormula(FormulaType type = FormulaType::ToUser) const; void setFormula(const QString &value, FormulaType type = FormulaType::ToUser); - QString getValue() const; + QString getStringValue() const; + qreal getDoubleValue() const; bool getCheckZero() const; void setCheckZero(bool value); @@ -74,6 +75,7 @@ private: quint32 toolId; QString postfix; bool _error; + qreal dValue; void Eval(); }; diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index b2773455e..6d97b2c3d 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -37,6 +37,8 @@ # include // for M_PI on Windows #endif /*Q_OS_WIN32*/ +#include "../container/vformula.h" + //--------------------------------------------------------------------------------------------------------------------- /** @@ -247,6 +249,13 @@ QString VArc::GetFormulaF1() const return d->formulaF1; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaF1(const VFormula &value) +{ + d->formulaF1 = value.getFormula(FormulaType::FromUser); + d->f1 = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetF1 return formula for start angle. @@ -267,6 +276,13 @@ QString VArc::GetFormulaF2() const return d->formulaF2; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaF2(const VFormula &value) +{ + d->formulaF2 = value.getFormula(FormulaType::FromUser); + d->f2 = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetF2 return formula for end angle. @@ -287,6 +303,13 @@ QString VArc::GetFormulaRadius() const return d->formulaRadius; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaRadius(const VFormula &value) +{ + d->formulaRadius = value.getFormula(FormulaType::FromUser); + d->radius = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetRadius return formula for radius. @@ -306,3 +329,9 @@ VPointF VArc::GetCenter() const { return d->center; } + +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetCenter(const VPointF &value) +{ + d->center = value; +} diff --git a/src/app/geometry/varc.h b/src/app/geometry/varc.h index bd48b8568..53003724f 100644 --- a/src/app/geometry/varc.h +++ b/src/app/geometry/varc.h @@ -35,6 +35,7 @@ class QPainterPath; class VArcData; +class VFormula; /** * @brief VArc class for anticlockwise arc. @@ -52,13 +53,21 @@ public: virtual ~VArc(); QString GetFormulaF1 () const; + void SetFormulaF1 (const VFormula &value); qreal GetF1 () const; + QString GetFormulaF2 () const; + void SetFormulaF2 (const VFormula &value); qreal GetF2 () const; - qreal GetLength () const; + QString GetFormulaRadius () const; + void SetFormulaRadius (const VFormula &value); qreal GetRadius () const; + VPointF GetCenter () const; + void SetCenter (const VPointF &value); + + qreal GetLength () const; QPointF GetP1() const; QPointF GetP2 () const; qreal AngleArc() const; diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 3fe7d4bae..6a5b1f625 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -29,8 +29,10 @@ #include "vtoolarc.h" #include "../../container/calculator.h" #include "../../dialogs/tools/dialogarc.h" -#include #include "../../geometry/varc.h" +#include "../container/vformula.h" + +#include const QString VToolArc::TagName = QStringLiteral("arc"); const QString VToolArc::ToolType = QStringLiteral("simple"); @@ -170,6 +172,101 @@ QString VToolArc::getTagName() const return VToolArc::TagName; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolArc::getCenter() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + return arc->GetCenter().id(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setCenter(const quint32 &value) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + + QSharedPointer point = VAbstractTool::data.GeometricObject(value); + arc->SetCenter(*point.data()); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaRadius() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula radius(arc->GetFormulaRadius(), getData()); + radius.setCheckZero(true); + radius.setToolId(id); + radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return radius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaRadius(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaRadius(value); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaF1() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula f1(arc->GetFormulaF1(), getData()); + f1.setCheckZero(false); + f1.setToolId(id); + f1.setPostfix(QStringLiteral("°")); + return f1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaF1(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaF1(value); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaF2() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula f2(arc->GetFormulaF2(), getData()); + f2.setCheckZero(false); + f2.setToolId(id); + f2.setPostfix(QStringLiteral("°")); + return f2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaF2(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaF2(value); + SaveOption(obj); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 30a63acfb..a7ba24b52 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -31,6 +31,8 @@ #include "vabstractspline.h" +class VFormula; + /** * @brief The VToolArc class tool for creation arc. */ @@ -49,6 +51,18 @@ public: virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Arc)}; virtual QString getTagName() const; + + quint32 getCenter() const; + void setCenter(const quint32 &value); + + VFormula getFormulaRadius() const; + void setFormulaRadius(const VFormula &value); + + VFormula getFormulaF1() const; + void setFormulaF1(const VFormula &value); + + VFormula getFormulaF2() const; + void setFormulaF2(const VFormula &value); public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/widgets/vformulaproperty.cpp b/src/app/widgets/vformulaproperty.cpp index 752a8103b..d01a91621 100644 --- a/src/app/widgets/vformulaproperty.cpp +++ b/src/app/widgets/vformulaproperty.cpp @@ -181,7 +181,7 @@ void VFormulaProperty::setFormula(const VFormula &formula) value.convert(VFormula::FormulaTypeId()); VProperty::d_ptr->VariantValue = value; - QVariant tmpValue(formula.getValue()); + QVariant tmpValue(formula.getStringValue()); tmpValue.convert(QVariant::String); QVariant tmpFormula(formula.getFormula()); diff --git a/src/app/widgets/vformulapropertyeditor.cpp b/src/app/widgets/vformulapropertyeditor.cpp index f286d6154..b445e9715 100644 --- a/src/app/widgets/vformulapropertyeditor.cpp +++ b/src/app/widgets/vformulapropertyeditor.cpp @@ -58,7 +58,7 @@ VFormulaPropertyEditor::VFormulaPropertyEditor(QWidget *parent) : // Create the text label TextLabel = new QLabel(this); - TextLabel->setText(formula.getValue()); + TextLabel->setText(formula.getStringValue()); // Spacer (this is needed for proper display of the label and button) Spacer = new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored); @@ -78,7 +78,7 @@ void VFormulaPropertyEditor::setFormula(const VFormula& formula) if (this->formula != formula) { this->formula = formula; - TextLabel->setText(this->formula.getValue()); + TextLabel->setText(this->formula.getStringValue()); } } @@ -94,7 +94,7 @@ void VFormulaPropertyEditor::onToolButtonClicked() if (tmpWidget->exec() == QDialog::Accepted) { formula.setFormula(tmpWidget->getFormula(), FormulaType::ToUser); - TextLabel->setText(formula.getValue()); + TextLabel->setText(formula.getStringValue()); delete tmpWidget; emit dataChangedByUser(formula, this); UserChangeEvent *event = new UserChangeEvent(); From 162794c70b1d4d627cfef23dafae6bdc17a09ec2 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 17:47:44 +0300 Subject: [PATCH 27/52] Setter and getter for options VToolBisector. --HG-- branch : feature --- src/app/options.h | 4 ++- src/app/tools/drawTools/vtoolalongline.cpp | 9 ++++-- src/app/tools/drawTools/vtoolarc.cpp | 13 +++++--- src/app/tools/drawTools/vtoolbisector.cpp | 37 ++++++++++++++++++++++ src/app/tools/drawTools/vtoolbisector.h | 7 ++++ 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/app/options.h b/src/app/options.h index e2a2a7d4d..364068ddf 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -37,9 +37,11 @@ class QString; +static const quint32 null_id = 0; + #define SceneSize 50000 #define DefPointRadius 2.0//mm -#define NULL_ID 0//use this value for initialization variables that keeps id values. 0 mean uknown id value. +#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value. enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; enum class Tool : unsigned char diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 0fe0eb783..a8785b98a 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -166,10 +166,13 @@ quint32 VToolAlongLine::getSecondPointId() const //--------------------------------------------------------------------------------------------------------------------- void VToolAlongLine::setSecondPointId(const quint32 &value) { - secondPointId = value; + if (value != NULL_ID) + { + secondPointId = value; - QSharedPointer obj = VAbstractTool::data.GetGObject(id); - SaveOption(obj); + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 6a5b1f625..5b22e6a92 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -184,12 +184,15 @@ quint32 VToolArc::getCenter() const //--------------------------------------------------------------------------------------------------------------------- void VToolArc::setCenter(const quint32 &value) { - QSharedPointer obj = VAbstractTool::data.GetGObject(id); - QSharedPointer arc = qSharedPointerDynamicCast(obj); + if (value != NULL_ID) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); - QSharedPointer point = VAbstractTool::data.GeometricObject(value); - arc->SetCenter(*point.data()); - SaveOption(obj); + QSharedPointer point = VAbstractTool::data.GeometricObject(value); + arc->SetCenter(*point.data()); + SaveOption(obj); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index 7f25bde4d..cd4f9eee6 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -309,3 +309,40 @@ void VToolBisector::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrSecondPoint, basePointId); doc->SetAttribute(tag, AttrThirdPoint, thirdPointId); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolBisector::getThirdPointId() const +{ + return thirdPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::setThirdPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + thirdPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolBisector::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::setFirstPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index 8bc7bd0e5..c0cee1b78 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -55,6 +55,13 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Bisector)}; + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getThirdPointId() const; + void setThirdPointId(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); From 109b071134dc2ff6232ee9c25d6fe0f29b075aef Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 18:07:21 +0300 Subject: [PATCH 28/52] Setter and getter for options VToolCut. --HG-- branch : feature --- src/app/tools/drawTools/vtoolcut.cpp | 37 ++++++++++++++++++++++++++++ src/app/tools/drawTools/vtoolcut.h | 9 +++++++ 2 files changed, 46 insertions(+) diff --git a/src/app/tools/drawTools/vtoolcut.cpp b/src/app/tools/drawTools/vtoolcut.cpp index 4593f5112..1a870021c 100644 --- a/src/app/tools/drawTools/vtoolcut.cpp +++ b/src/app/tools/drawTools/vtoolcut.cpp @@ -28,6 +28,7 @@ #include "vtoolcut.h" #include "../../geometry/vpointf.h" +#include "../../container/vformula.h" //--------------------------------------------------------------------------------------------------------------------- VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, @@ -84,6 +85,42 @@ void VToolCut::HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirecti } } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolCut::getCurveCutId() const +{ + return curveCutId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::setCurveCutId(const quint32 &value) +{ + if (value != NULL_ID) + { + curveCutId = value; + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolCut::getFormula() const +{ + VFormula val(formula, getData()); + val.setCheckZero(true); + val.setToolId(id); + val.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return val; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::setFormula(const VFormula &value) +{ + if (value.error() == false) + { + formula = value.getFormula(FormulaType::FromUser); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolcut.h b/src/app/tools/drawTools/vtoolcut.h index 838b58fed..f99e82847 100644 --- a/src/app/tools/drawTools/vtoolcut.h +++ b/src/app/tools/drawTools/vtoolcut.h @@ -32,6 +32,8 @@ #include "vtoolpoint.h" #include "../../visualization/vsimplecurve.h" +class VFormula; + class VToolCut : public VToolPoint { Q_OBJECT @@ -40,6 +42,13 @@ public: const quint32 &curve1id, const quint32 &curve2id, QGraphicsItem * parent = nullptr); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Cut)}; + + VFormula getFormula() const; + void setFormula(const VFormula &value); + + quint32 getCurveCutId() const; + void setCurveCutId(const quint32 &value); + public slots: virtual void ChangedActivDraw(const QString &newName); virtual void CurveChoosed(quint32 id)=0; From 80d5637bcbcef62a642de5f1b2e95bf99aa4bdbe Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 18:27:20 +0300 Subject: [PATCH 29/52] Setter and getter for options VToolHeight. --HG-- branch : feature --- src/app/tools/drawTools/vtoolheight.cpp | 37 +++++++++++++++++++++++++ src/app/tools/drawTools/vtoolheight.h | 7 +++++ 2 files changed, 44 insertions(+) diff --git a/src/app/tools/drawTools/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index 067cab00c..a77417454 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -257,3 +257,40 @@ void VToolHeight::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrP1Line, p1LineId); doc->SetAttribute(tag, AttrP2Line, p2LineId); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolHeight::getP2LineId() const +{ + return p2LineId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::setP2LineId(const quint32 &value) +{ + if (value != NULL_ID) + { + p2LineId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolHeight::getP1LineId() const +{ + return p1LineId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::setP1LineId(const quint32 &value) +{ + if (value != NULL_ID) + { + p1LineId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolheight.h b/src/app/tools/drawTools/vtoolheight.h index bbbfabf3a..34e7b6c09 100644 --- a/src/app/tools/drawTools/vtoolheight.h +++ b/src/app/tools/drawTools/vtoolheight.h @@ -52,6 +52,13 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Height)}; + + quint32 getP1LineId() const; + void setP1LineId(const quint32 &value); + + quint32 getP2LineId() const; + void setP2LineId(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); From 1d33304de4afcc83643661b77bc5a10039c244dd Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 18:29:43 +0300 Subject: [PATCH 30/52] Setter and getter for options VToolLine. --HG-- branch : feature --- src/app/tools/drawTools/vtoolline.cpp | 36 +++++++++++++++++++++++++++ src/app/tools/drawTools/vtoolline.h | 6 +++++ 2 files changed, 42 insertions(+) diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index abe37eba0..c105989a2 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -383,6 +383,42 @@ void VToolLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrTypeLine, typeLine); } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLine::getSecondPoint() const +{ + return secondPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::setSecondPoint(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPoint = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLine::getFirstPoint() const +{ + return firstPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::setFirstPoint(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPoint = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 722258cf4..888940e32 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -51,6 +51,12 @@ public: virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Line)}; virtual QString getTagName() const; + quint32 getFirstPoint() const; + void setFirstPoint(const quint32 &value); + + quint32 getSecondPoint() const; + void setSecondPoint(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); From eb6eff3486b40a0ce841ca1f372b05581ac2d25c Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 18:32:28 +0300 Subject: [PATCH 31/52] Setter and getter for options VToolLineIntersect. --HG-- branch : feature --- .../tools/drawTools/vtoollineintersect.cpp | 73 +++++++++++++++++++ src/app/tools/drawTools/vtoollineintersect.h | 13 ++++ 2 files changed, 86 insertions(+) diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 7ddc33983..ff0a010ef 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -279,3 +279,76 @@ void VToolLineIntersect::SaveOptions(QDomElement &tag, QSharedPointer doc->SetAttribute(tag, AttrP1Line2, p1Line2); doc->SetAttribute(tag, AttrP2Line2, p2Line2); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP2Line2() const +{ + return p2Line2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP2Line2(const quint32 &value) +{ + if (value != NULL_ID) + { + p2Line2 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP1Line2() const +{ + return p1Line2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP1Line2(const quint32 &value) +{ + if (value != NULL_ID) + { + p1Line2 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP2Line1() const +{ + return p2Line1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP2Line1(const quint32 &value) +{ + if (value != NULL_ID) + { + p2Line1 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP1Line1() const +{ + return p1Line1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP1Line1(const quint32 &value) +{ + if (value != NULL_ID) + { + p1Line1 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoollineintersect.h b/src/app/tools/drawTools/vtoollineintersect.h index 8a415c01e..89f9f5e36 100644 --- a/src/app/tools/drawTools/vtoollineintersect.h +++ b/src/app/tools/drawTools/vtoollineintersect.h @@ -50,6 +50,19 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::LineIntersect)}; + + quint32 getP1Line1() const; + void setP1Line1(const quint32 &value); + + quint32 getP2Line1() const; + void setP2Line1(const quint32 &value); + + quint32 getP1Line2() const; + void setP1Line2(const quint32 &value); + + quint32 getP2Line2() const; + void setP2Line2(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); From 4a6a3f3cc9c64d75cf6715606439cb144fca74cc Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 18:36:08 +0300 Subject: [PATCH 32/52] Setter and getter for options VToolNormal. --HG-- branch : feature --- src/app/tools/drawTools/vtoollinepoint.cpp | 14 ++++++++++++++ src/app/tools/drawTools/vtoollinepoint.h | 3 +++ src/app/tools/drawTools/vtoolnormal.cpp | 19 +++++++++++++++++++ src/app/tools/drawTools/vtoolnormal.h | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index da3a06392..8f66014ac 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -108,6 +108,20 @@ void VToolLinePoint::SetFactor(qreal factor) RefreshGeometry(); } +//--------------------------------------------------------------------------------------------------------------------- +qreal VToolLinePoint::getAngle() const +{ + return angle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::setAngle(const qreal &value) +{ + angle = value; + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLinePoint::getBasePointId() const { diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 9640e1316..dc77b5962 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -49,6 +49,9 @@ public: quint32 getBasePointId() const; void setBasePointId(const quint32 &value); + qreal getAngle() const; + void setAngle(const qreal &value); + public slots: virtual void ChangedActivDraw(const QString &newName); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index e46e6ae4d..c902f527b 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -287,3 +287,22 @@ void VToolNormal::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrFirstPoint, basePointId); doc->SetAttribute(tag, AttrSecondPoint, secondPointId); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolNormal::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolNormal::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolnormal.h b/src/app/tools/drawTools/vtoolnormal.h index 1f0458ade..8c41676ca 100644 --- a/src/app/tools/drawTools/vtoolnormal.h +++ b/src/app/tools/drawTools/vtoolnormal.h @@ -52,6 +52,10 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Normal)}; + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); From bf79d8f0bd9e29484bc2104d4b9e87d1291b0337 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 19:19:41 +0300 Subject: [PATCH 33/52] Setter and getter for options VToolPointOfContact. --HG-- branch : feature --- .../tools/drawTools/vtoolpointofcontact.cpp | 67 +++++++++++++++++++ src/app/tools/drawTools/vtoolpointofcontact.h | 21 +++++- 2 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index e81d5aaae..35780776d 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -30,6 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogpointofcontact.h" #include "../../geometry/vpointf.h" +#include "../../container/vformula.h" const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact"); @@ -304,3 +305,69 @@ void VToolPointOfContact::SaveOptions(QDomElement &tag, QSharedPointer doc->SetAttribute(tag, AttrFirstPoint, firstPointId); doc->SetAttribute(tag, AttrSecondPoint, secondPointId); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfContact::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setSecondPointId(const quint32 &value) +{ + secondPointId = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfContact::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setFirstPointId(const quint32 &value) +{ + firstPointId = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfContact::getCenter() const +{ + return center; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setCenter(const quint32 &value) +{ + if (value != NULL_ID) + { + center = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolPointOfContact::getArcRadius() const +{ + VFormula radius(arcRadius, this->getData()); + radius.setCheckZero(true); + radius.setToolId(id); + radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + + return radius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setArcRadius(const VFormula &value) +{ + if (value.error() == false) + { + arcRadius = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index cbbefba91..60c4924ef 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -31,6 +31,8 @@ #include "vtoolpoint.h" +class VFormula; + /** * @brief The VToolPointOfContact class tool for creation point intersection line and arc. */ @@ -53,6 +55,19 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::PointOfContact) }; + + VFormula getArcRadius() const; + void setArcRadius(const VFormula &value); + + quint32 getCenter() const; + void setCenter(const quint32 &value); + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); @@ -67,13 +82,13 @@ private: QString arcRadius; /** @brief center id center arc point. */ - quint32 center; + quint32 center; /** @brief firstPointId id first line point. */ - quint32 firstPointId; + quint32 firstPointId; /** @brief secondPointId id second line point. */ - quint32 secondPointId; + quint32 secondPointId; }; #endif // VTOOLPOINTOFCONTACT_H From 5e304e841523d95c250aadb16d899b316375cf42 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 19:21:42 +0300 Subject: [PATCH 34/52] Setter and getter for options VToolPointOfIntersection. --HG-- branch : feature --- .../tools/drawTools/vtoolpointofcontact.cpp | 1 - .../drawTools/vtoolpointofintersection.cpp | 36 +++++++++++++++++++ .../drawTools/vtoolpointofintersection.h | 7 ++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 35780776d..5c11e34e7 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -370,4 +370,3 @@ void VToolPointOfContact::setArcRadius(const VFormula &value) SaveOption(obj); } } - diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index bd7d845cc..ad53b8536 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -232,3 +232,39 @@ void VToolPointOfIntersection::SaveOptions(QDomElement &tag, QSharedPointerSetAttribute(tag, AttrFirstPoint, firstPointId); doc->SetAttribute(tag, AttrSecondPoint, secondPointId); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfIntersection::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfIntersection::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::setFirstPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} diff --git a/src/app/tools/drawTools/vtoolpointofintersection.h b/src/app/tools/drawTools/vtoolpointofintersection.h index 9a82ad1f9..eef98a9b1 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.h +++ b/src/app/tools/drawTools/vtoolpointofintersection.h @@ -51,6 +51,13 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::PointOfIntersection) }; + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); From 754901bff1a039b7c2db65dfc010d51136bceab4 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 19:25:04 +0300 Subject: [PATCH 35/52] Setter and getter for options VToolShoulderPoint. --HG-- branch : feature --- .../tools/drawTools/vtoolshoulderpoint.cpp | 37 +++++++++++++++++++ src/app/tools/drawTools/vtoolshoulderpoint.h | 7 ++++ 2 files changed, 44 insertions(+) diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 0d6cb2a2c..a4b9d3f95 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -313,3 +313,40 @@ void VToolShoulderPoint::SaveOptions(QDomElement &tag, QSharedPointer doc->SetAttribute(tag, AttrP2Line, p2Line); doc->SetAttribute(tag, AttrPShoulder, pShoulder); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolShoulderPoint::getPShoulder() const +{ + return pShoulder; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::setPShoulder(const quint32 &value) +{ + if (value != NULL_ID) + { + pShoulder = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolShoulderPoint::getP2Line() const +{ + return p2Line; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::setP2Line(const quint32 &value) +{ + if (value != NULL_ID) + { + p2Line = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index 8c8b30a1d..e8d8c63be 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -53,6 +53,13 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::ShoulderPoint) }; + + quint32 getP2Line() const; + void setP2Line(const quint32 &value); + + quint32 getPShoulder() const; + void setPShoulder(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); From 82d82f9b0a309117934e0ac6016c58e1918cbc01 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 19:27:30 +0300 Subject: [PATCH 36/52] Setter and getter for options VToolTriangle. --HG-- branch : feature --- src/app/tools/drawTools/vtooltriangle.cpp | 72 +++++++++++++++++++++++ src/app/tools/drawTools/vtooltriangle.h | 13 ++++ 2 files changed, 85 insertions(+) diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index e41d547ba..5b2493641 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -296,3 +296,75 @@ void VToolTriangle::SaveOptions(QDomElement &tag, QSharedPointer &obj) doc->SetAttribute(tag, AttrFirstPoint, firstPointId); doc->SetAttribute(tag, AttrSecondPoint, secondPointId); } + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setFirstPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getAxisP2Id() const +{ + return axisP2Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setAxisP2Id(const quint32 &value) +{ + if (value != NULL_ID) + { + axisP2Id = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getAxisP1Id() const +{ + return axisP1Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setAxisP1Id(const quint32 &value) +{ + if (value != NULL_ID) + { + axisP1Id = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} diff --git a/src/app/tools/drawTools/vtooltriangle.h b/src/app/tools/drawTools/vtooltriangle.h index 4e36d4835..9b168f721 100644 --- a/src/app/tools/drawTools/vtooltriangle.h +++ b/src/app/tools/drawTools/vtooltriangle.h @@ -53,6 +53,19 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Triangle)}; + + quint32 getAxisP1Id() const; + void setAxisP1Id(const quint32 &value); + + quint32 getAxisP2Id() const; + void setAxisP2Id(const quint32 &value); + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); From e6f9b81dbae55f7c108aa949b853eb189a8e42e2 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 19:36:15 +0300 Subject: [PATCH 37/52] Setter and getter for options VToolSpline. --HG-- branch : feature --- src/app/tools/drawTools/vtoolspline.cpp | 16 ++++++++++++++++ src/app/tools/drawTools/vtoolspline.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index be3d9c641..822aa2aaa 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -188,6 +188,22 @@ VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const qui return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +VSpline VToolSpline::getSpline() const +{ + QSharedPointer spline = VAbstractTool::data.GeometricObject(id); + return *spline.data(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::setSpline(const VSpline &spl) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer spline = qSharedPointerDynamicCast(obj); + *spline.data() = spl; + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ControlPointChangePosition handle change position control point. diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index 7d7cf2ca5..cbbb09f92 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -50,6 +50,9 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Spline)}; + + VSpline getSpline()const; + void setSpline(const VSpline &spl); public slots: void ControlPointChangePosition (const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos); From df2c9853a169f3bc12bd3991c8e40b91b128182c Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 1 Sep 2014 19:39:16 +0300 Subject: [PATCH 38/52] Setter and getter for options VToolSplinePath. --HG-- branch : feature --- src/app/tools/drawTools/vtoolsplinepath.cpp | 16 ++++++++++++++++ src/app/tools/drawTools/vtoolsplinepath.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index e157340fe..5521027c4 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -264,6 +264,22 @@ void VToolSplinePath::UpdatePathPoint(VPattern *doc, QDomNode& node, const VSpli } } +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VToolSplinePath::getSplinePath() const +{ + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + return *splPath.data(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::setSplinePath(const VSplinePath &splPath) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer splinePath = qSharedPointerDynamicCast(obj); + *splinePath.data() = splPath; + SaveOption(obj); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index e854c6d4f..cd8046a89 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -48,6 +48,9 @@ public: static void UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path); virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::SplinePath)}; + + VSplinePath getSplinePath()const; + void setSplinePath(const VSplinePath &splPath); signals: /** * @brief RefreshLine refresh control line. From f59009c5fc75d033862d9ea04b9186f2fec55e6c Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 3 Sep 2014 14:10:51 +0300 Subject: [PATCH 39/52] Show lite tool options in options browser. --HG-- branch : feature --- src/app/geometry/vspline.cpp | 9 + src/app/geometry/vspline.h | 1 + src/app/geometry/vspline_p.h | 2 +- src/app/geometry/vsplinepath.cpp | 5 +- src/app/options.h | 2 +- src/app/tools/drawTools/vtoolcut.cpp | 3 + src/app/tools/drawTools/vtoolsplinepath.cpp | 1 + .../widgets/vtooloptionspropertybrowser.cpp | 576 ++++++++++++++++-- src/app/widgets/vtooloptionspropertybrowser.h | 5 +- .../plugins/vnumberproperty.cpp | 77 ++- .../plugins/vnumberproperty.h | 6 +- 11 files changed, 582 insertions(+), 105 deletions(-) diff --git a/src/app/geometry/vspline.cpp b/src/app/geometry/vspline.cpp index 09f9bc161..978ceec63 100644 --- a/src/app/geometry/vspline.cpp +++ b/src/app/geometry/vspline.cpp @@ -750,3 +750,12 @@ qreal VSpline::GetKcurve() const { return d->kCurve; } + +//--------------------------------------------------------------------------------------------------------------------- +void VSpline::SetKcurve(qreal factor) +{ + if (factor > 0) + { + d->kCurve = factor; + } +} diff --git a/src/app/geometry/vspline.h b/src/app/geometry/vspline.h index 48f724613..c70a84b03 100644 --- a/src/app/geometry/vspline.h +++ b/src/app/geometry/vspline.h @@ -63,6 +63,7 @@ public: qreal GetKasm1() const; qreal GetKasm2() const; qreal GetKcurve() const; + void SetKcurve(qreal factor); // cppcheck-suppress unusedFunction QLineF::IntersectType CrossingSplLine(const QLineF &line, QPointF *intersectionPoint ) const; qreal LengthT(qreal t) const; diff --git a/src/app/geometry/vspline_p.h b/src/app/geometry/vspline_p.h index d91951474..49863caaa 100644 --- a/src/app/geometry/vspline_p.h +++ b/src/app/geometry/vspline_p.h @@ -48,7 +48,7 @@ public: VSplineData ( const VSplineData &spline ) :QSharedData(spline), p1(spline.p1), p2(spline.p2), p3(spline.p3), p4(spline.p4), angle1(spline.angle1), - angle2(spline.angle2), kAsm1(spline.angle2), kAsm2(spline.kAsm1), kCurve(spline.kCurve) + angle2(spline.angle2), kAsm1(spline.kAsm1), kAsm2(spline.kAsm2), kCurve(spline.kCurve) {} VSplineData (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve) diff --git a/src/app/geometry/vsplinepath.cpp b/src/app/geometry/vsplinepath.cpp index 98d99ffd1..4fa7736d9 100644 --- a/src/app/geometry/vsplinepath.cpp +++ b/src/app/geometry/vsplinepath.cpp @@ -258,7 +258,10 @@ qreal VSplinePath::getKCurve() const //--------------------------------------------------------------------------------------------------------------------- void VSplinePath::setKCurve(const qreal &value) { - d->kCurve = value; + if (value > 0) + { + d->kCurve = value; + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/options.h b/src/app/options.h index 364068ddf..d2de5312e 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -79,7 +79,7 @@ enum class Tool : unsigned char enum class Vis : unsigned char { - ControlPointSpline, + ControlPointSpline = 29, // increase this value if need more positions in Tool enum GraphicsSimpleTextItem, Line, Path, diff --git a/src/app/tools/drawTools/vtoolcut.cpp b/src/app/tools/drawTools/vtoolcut.cpp index 1a870021c..984cf2729 100644 --- a/src/app/tools/drawTools/vtoolcut.cpp +++ b/src/app/tools/drawTools/vtoolcut.cpp @@ -118,6 +118,9 @@ void VToolCut::setFormula(const VFormula &value) if (value.error() == false) { formula = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); } } diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index 5521027c4..f63b1e836 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -365,6 +365,7 @@ void VToolSplinePath::SaveOptions(QDomElement &tag, QSharedPointer &ob doc->SetAttribute(tag, AttrType, ToolType); doc->SetAttribute(tag, AttrKCurve, splPath->getKCurve()); + doc->RemoveAllChild(tag); for (qint32 i = 0; i < splPath->CountPoint(); ++i) { AddPathPoint(tag, splPath->at(i)); diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index bd3fda554..614a80ba2 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -49,12 +49,12 @@ VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) idToProperty(QMap()) { PropertyModel = new VPropertyModel(this); - TreeView = new VPropertyFormView(PropertyModel, parent); - TreeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + formView = new VPropertyFormView(PropertyModel, parent); + formView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QScrollArea *scroll = new QScrollArea(parent); scroll->setWidgetResizable(true); - scroll->setWidget(TreeView); + scroll->setWidget(formView); parent->setWidget(scroll); @@ -128,6 +128,10 @@ void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) currentItem = item->parentItem(); ShowItemOptions(currentItem); break; + case VSimpleCurve::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; default: break; } @@ -308,7 +312,6 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) if (currentItem == nullptr) { - TreeView->setTitle(""); return; } @@ -333,26 +336,18 @@ void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &p AddProperty(itemName, VAbstractTool::AttrName); } -//--------------------------------------------------------------------------------------------------------------------- -template -void VToolOptionsPropertyBrowser::AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value, - const QString &attrName) -{ - VObjectProperty *pointsProperty = new VObjectProperty(propertyName); - QMap pointsList = i->PointsList(); - pointsProperty->setObjectsList(pointsList); - pointsProperty->setValue(value); - AddProperty(pointsProperty, attrName); -} - //--------------------------------------------------------------------------------------------------------------------- template void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName) { VEnumProperty *lineTypeProperty = new VEnumProperty(propertyName); - lineTypeProperty->setLiterals(VAbstractTool::Styles()); QStringList styles = VAbstractTool::Styles(); + lineTypeProperty->setLiterals(styles); qint32 index = styles.indexOf(i->getLineType()); + if (index == -1) + { + qWarning()<<"Can't find line style" << i->getLineType()<<"in list"; + } lineTypeProperty->setValue(index); AddProperty(lineTypeProperty, VAbstractTool::AttrTypeLine); } @@ -429,9 +424,6 @@ void VToolOptionsPropertyBrowser::ChangeDataToolEndLine(VProperty *property) case 0: // VAbstractTool::AttrName SetPointName(value.toString()); break; - case 2: // VAbstractTool::AttrBasePoint - i->setBasePointId(value.toUInt()); - break; case 3: // VAbstractTool::AttrTypeLine i->setTypeLine(value.toString()); break; @@ -460,13 +452,7 @@ void VToolOptionsPropertyBrowser::ChangeDataToolAlongLine(VProperty *property) switch (PropertiesList().indexOf(id)) { case 0: // VAbstractTool::AttrName - SetPointName(value.toString()); - break; - case 6: // VAbstractTool::AttrFirstPoint - i->setBasePointId(value.toUInt()); - break; - case 7: // VAbstractTool::AttrSecondPoint - i->setSecondPointId(value.toUInt()); + SetPointName(value.toString()); break; case 3: // VAbstractTool::AttrTypeLine i->setTypeLine(value.toString()); @@ -483,100 +469,375 @@ void VToolOptionsPropertyBrowser::ChangeDataToolAlongLine(VProperty *property) //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ChangeDataToolArc(VProperty *property) { + SCASSERT(property != nullptr) + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolArc *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 8: // VAbstractTool::AttrRadius + i->setFormulaRadius(value.value()); + break; + case 9: // VAbstractTool::AttrAngle1 + i->setFormulaF1(value.value()); + break; + case 10: // VAbstractTool::AttrAngle2 + i->setFormulaF2(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolBisector *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCutArc *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormula(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCutSpline *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormula(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCutSplinePath *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormula(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolHeight *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolLineIntersect *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolNormal *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 22: // VAbstractTool::AttrAngle + i->setAngle(value.toDouble()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolPointOfContact *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 8: // VAbstractTool::AttrRadius + i->setArcRadius(value.value()); + break; + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolPointOfIntersection *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolShoulderPoint *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolSpline *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 26: // VAbstractTool::AttrKCurve + { + VSpline spl = i->getSpline(); + spl.SetKcurve(value.toDouble()); + i->setSpline(spl); + break; + } + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolSplinePath *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 26: // VAbstractTool::AttrKCurve + { + VSplinePath splPath = i->getSplinePath(); + splPath.setKCurve(value.toDouble()); + i->setSplinePath(splPath); + break; + } + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolTriangle *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<(item); - TreeView->setTitle(tr("Base point")); + formView->setTitle(tr("Base point")); - AddPropertyPointName(i, tr("Point name")); + AddPropertyPointName(i, tr("Point label")); VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); itemPosition->setValue(i->pos()); @@ -587,10 +848,9 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSinglePoint(QGraphicsItem *item void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item) { VToolEndLine *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Point at distance and angle")); + formView->setTitle(tr("Point at distance and angle")); - AddPropertyPointName(i, tr("Point name")); - AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); + AddPropertyPointName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type")); AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); @@ -600,11 +860,9 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item) { VToolAlongLine *i = qgraphicsitem_cast(item); - TreeView->setTitle(tr("Point at distance along line")); + formView->setTitle(tr("Point at distance along line")); - AddPropertyPointName(i, tr("Point name")); - AddPropertyPointsList(i, tr("First point"), i->getBasePointId(), VAbstractTool::AttrFirstPoint); - AddPropertyPointsList(i, tr("Second point"), i->getSecondPointId(), VAbstractTool::AttrSecondPoint); + AddPropertyPointName(i, tr("Point label")); AddPropertyLineType(i, tr("Line type")); AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); } @@ -613,231 +871,423 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolArc(QGraphicsItem *item) { VToolArc *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Arc")); + + AddPropertyFormula(tr("Radius"), i->getFormulaRadius(), VAbstractTool::AttrRadius); + AddPropertyFormula(tr("First angle"), i->getFormulaF1(), VAbstractTool::AttrAngle1); + AddPropertyFormula(tr("Second angle"), i->getFormulaF2(), VAbstractTool::AttrAngle2); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item) { VToolBisector *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Point along bisector")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolCutArc(QGraphicsItem *item) { VToolCutArc *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Cut arc tool")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Length"), i->getFormula(), VAbstractTool::AttrLength); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolCutSpline(QGraphicsItem *item) { VToolCutSpline *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Tool for segmenting a curve")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Length"), i->getFormula(), VAbstractTool::AttrLength); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolCutSplinePath(QGraphicsItem *item) { VToolCutSplinePath *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Tool segment a pathed curve")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Length"), i->getFormula(), VAbstractTool::AttrLength); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolHeight(QGraphicsItem *item) { VToolHeight *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Perpendicular point along line")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolLine(QGraphicsItem *item) { VToolLine *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Line between points")); + + AddPropertyLineType(i, tr("Line type")); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersect(QGraphicsItem *item) { VToolLineIntersect *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Point at line intersection")); + + AddPropertyPointName(i, tr("Point label")); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolNormal(QGraphicsItem *item) { VToolNormal *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Point along perpendicular")); + + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + + VDoubleProperty* itemAngle = new VDoubleProperty(tr("Additional angle degrees")); + itemAngle->setValue(i->getAngle()); + itemAngle->setSetting("Min", 0); + itemAngle->setSetting("Max", 360); + itemAngle->setSetting("Precision", 3); + AddProperty(itemAngle, VAbstractTool::AttrAngle); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfContact(QGraphicsItem *item) { VToolPointOfContact *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Point at intersection of arc and line")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Radius"), i->getArcRadius(), VAbstractTool::AttrRadius); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersection(QGraphicsItem *item) { VToolPointOfIntersection *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Tool to make point from x & y of two other points")); + + AddPropertyPointName(i, tr("Point label")); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *item) { VToolShoulderPoint *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Special point on shoulder")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) { VToolSpline *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Curve tool")); + + VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); + VSpline spl = i->getSpline(); + itemFactor->setSetting("Min", 0.1); + itemFactor->setSetting("Max", 1000); + itemFactor->setSetting("Step", 0.01); + itemFactor->setSetting("Precision", 3); + itemFactor->setValue(spl.GetKcurve()); + AddProperty(itemFactor, VAbstractTool::AttrKCurve); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item) { VToolSplinePath *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Tool for path curve")); + + VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); + VSplinePath splPath = i->getSplinePath(); + itemFactor->setSetting("Min", 0.1); + itemFactor->setSetting("Max", 1000); + itemFactor->setSetting("Step", 0.01); + itemFactor->setSetting("Precision", 3); + itemFactor->setValue(splPath.getKCurve()); + AddProperty(itemFactor, VAbstractTool::AttrKCurve); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item) { VToolTriangle *i = qgraphicsitem_cast(item); + formView->setTitle(tr("Tool triangle")); + + AddPropertyPointName(i, tr("Point label")); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() { VToolSinglePoint *i = qgraphicsitem_cast(currentItem); - TreeView->setTitle(tr("Base point")); - - AddPropertyPointName(i, tr("Point name")); - - VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); - itemPosition->setValue(i->pos()); - AddProperty(itemPosition, QLatin1String("position")); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[QLatin1String("position")]->setValue(i->pos()); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolEndLine() { VToolEndLine *i = qgraphicsitem_cast(currentItem); - TreeView->setTitle(tr("Point at distance and angle")); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); - AddPropertyPointName(i, tr("Point name")); - AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint); - AddPropertyLineType(i, tr("Line type")); - AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); - AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + QVariant valueAngle; + valueAngle.setValue(i->getFormulaAngle()); + idToProperty[VAbstractTool::AttrAngle]->setValue(valueAngle); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolAlongLine() { VToolAlongLine *i = qgraphicsitem_cast(currentItem); - TreeView->setTitle(tr("Point at distance along line")); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); - AddPropertyPointName(i, tr("Point name")); - AddPropertyPointsList(i, tr("First point"), i->getBasePointId(), VAbstractTool::AttrFirstPoint); - AddPropertyPointsList(i, tr("Second point"), i->getSecondPointId(), VAbstractTool::AttrSecondPoint); - AddPropertyLineType(i, tr("Line type")); - AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolArc() { VToolArc *i = qgraphicsitem_cast(currentItem); + + + QVariant valueRadius; + valueRadius.setValue(i->getFormulaRadius()); + idToProperty[VAbstractTool::AttrRadius]->setValue(valueRadius); + + QVariant valueFirstAngle; + valueFirstAngle.setValue(i->getFormulaF1()); + idToProperty[VAbstractTool::AttrAngle1]->setValue(valueFirstAngle); + + QVariant valueSecondAngle; + valueSecondAngle.setValue(i->getFormulaF2()); + idToProperty[VAbstractTool::AttrAngle2]->setValue(valueSecondAngle); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolBisector() { VToolBisector *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolCutArc() { VToolCutArc *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormula()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSpline() { VToolCutSpline *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormula()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSplinePath() { VToolCutSplinePath *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormula()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolHeight() { VToolHeight *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolLine() { VToolLine *i = qgraphicsitem_cast(currentItem); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolLineIntersect() { VToolLineIntersect *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolNormal() { VToolNormal *i = qgraphicsitem_cast(currentItem); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + idToProperty[VAbstractTool::AttrAngle]->setValue( i->getAngle()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfContact() { VToolPointOfContact *i = qgraphicsitem_cast(currentItem); + + QVariant valueFormula; + valueFormula.setValue(i->getArcRadius()); + idToProperty[VAbstractTool::AttrRadius]->setValue(valueFormula); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfIntersection() { VToolPointOfIntersection *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolShoulderPoint() { VToolShoulderPoint *i = qgraphicsitem_cast(currentItem); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() { VToolSpline *i = qgraphicsitem_cast(currentItem); + + VSpline spl = i->getSpline(); + idToProperty[VAbstractTool::AttrKCurve]->setValue(spl.GetKcurve()); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() { VToolSplinePath *i = qgraphicsitem_cast(currentItem); + + VSplinePath splPath = i->getSplinePath(); + idToProperty[VAbstractTool::AttrKCurve]->setValue(splPath.getKCurve()); } //--------------------------------------------------------------------------------------------------------------------- void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle() { VToolTriangle *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } //--------------------------------------------------------------------------------------------------------------------- QStringList VToolOptionsPropertyBrowser::PropertiesList() const { - QStringList attr{VAbstractTool::AttrName, /* 0 */ - QLatin1String("position"), /* 1 */ - VAbstractTool::AttrBasePoint, /* 2 */ - VAbstractTool::AttrTypeLine, /* 3 */ - VAbstractTool::AttrLength, /* 4 */ - VAbstractTool::AttrAngle, /* 5 */ - VAbstractTool::AttrFirstPoint, /* 6 */ - VAbstractTool::AttrSecondPoint};/* 7 */ + QStringList attr{VAbstractTool::AttrName, /* 0 */ + QLatin1String("position"), /* 1 */ + VAbstractTool::AttrBasePoint, /* 2 */ + VAbstractTool::AttrTypeLine, /* 3 */ + VAbstractTool::AttrLength, /* 4 */ + VAbstractTool::AttrAngle, /* 5 */ + VAbstractTool::AttrFirstPoint, /* 6 */ + VAbstractTool::AttrSecondPoint, /* 7 */ + VAbstractTool::AttrRadius, /* 8 */ + VAbstractTool::AttrAngle1, /* 9 */ + VAbstractTool::AttrAngle2, /* 10 */ + VAbstractTool::AttrCenter, /* 11 */ + VAbstractTool::AttrThirdPoint, /* 12 */ + VToolCutArc::AttrArc, /* 13 */ + VToolCutSpline::AttrSpline, /* 14 */ + VToolCutSplinePath::AttrSplinePath, /* 15 */ + VAbstractTool::AttrP1Line, /* 16 */ + VAbstractTool::AttrP2Line, /* 17 */ + VAbstractTool::AttrP1Line1, /* 18 */ + VAbstractTool::AttrP2Line1, /* 19 */ + VAbstractTool::AttrP1Line2, /* 20 */ + VAbstractTool::AttrP2Line2, /* 21 */ + VAbstractTool::AttrAngle, /* 22 */ + VAbstractTool::AttrPShoulder, /* 23 */ + VAbstractTool::AttrAxisP1, /* 24 */ + VAbstractTool::AttrAxisP2, /* 25 */ + VAbstractTool::AttrKCurve}; /* 26 */ return attr; } diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h index 5a6b57e81..fd7ad093d 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.h +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -56,7 +56,7 @@ private: Q_DISABLE_COPY(VToolOptionsPropertyBrowser) VPropertyModel* PropertyModel; - VPropertyFormView* TreeView; + VPropertyFormView* formView; QGraphicsItem *currentItem; QMap propertyToId; @@ -71,9 +71,6 @@ private: template void AddPropertyPointName(Tool *i, const QString &propertyName); - template - void AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value, const QString &attrName); - template void AddPropertyLineType(Tool *i, const QString &propertyName); diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp index f82c510aa..7ccae32b6 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp @@ -14,7 +14,7 @@ const int VIntegerProperty::StandardMin = -1000000; const int VIntegerProperty::StandardMax = 1000000; VIntegerProperty::VIntegerProperty(const QString& name, const QMap& settings) - : VProperty(name, QVariant::Int), Min(StandardMin), Max(StandardMax) + : VProperty(name, QVariant::Int), min(StandardMin), max(StandardMax), singleStep(1.0) { VProperty::setSettings(settings); VProperty::d_ptr->VariantValue.setValue(0); @@ -22,7 +22,7 @@ VIntegerProperty::VIntegerProperty(const QString& name, const QMapVariantValue.setValue(0); VProperty::d_ptr->VariantValue.convert(QVariant::Int); @@ -35,8 +35,9 @@ QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionView Q_UNUSED(delegate); QSpinBox* tmpEditor = new QSpinBox(parent); - tmpEditor->setMinimum(Min); - tmpEditor->setMaximum(Max); + tmpEditor->setMinimum(min); + tmpEditor->setMaximum(max); + tmpEditor->setSingleStep(singleStep); tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tmpEditor->setValue(VProperty::d_ptr->VariantValue.toInt()); connect(tmpEditor, static_cast(&QSpinBox::valueChanged), this, @@ -56,33 +57,38 @@ QVariant VIntegerProperty::getEditorData(QWidget* editor) const return QVariant(0); } -void VIntegerProperty::setSettings(int minimum, int maxiumum) +void VIntegerProperty::setSettings(int minimum, int maxiumum, int singleStep) { - Min = minimum; - Max = maxiumum; + min = minimum; + max = maxiumum; + this->singleStep = singleStep; } void VIntegerProperty::setSetting(const QString& key, const QVariant& value) { - if(key == "Min") - setSettings(value.toInt(), Max); - else if(key == "Max") - setSettings(Min, value.toInt()); + if(key == QLatin1String("Min")) + setSettings(value.toInt(), max); + else if(key == QLatin1String("Max")) + setSettings(min, value.toInt()); + else if(key == QLatin1String("Step")) + setSettings(singleStep, value.toInt()); } QVariant VIntegerProperty::getSetting(const QString& key) const { - if(key == "Min") - return Min; - if(key == "Max") - return Max; + if(key == QLatin1String("Min")) + return min; + if(key == QLatin1String("Max")) + return max; + if(key == QLatin1String("Step")) + return singleStep; else return VProperty::getSetting(key); } QStringList VIntegerProperty::getSettingKeys() const { - return (QStringList("Min") << "Max"); + return (QStringList("Min") << "Max" << "Step"); } QString VIntegerProperty::type() const @@ -131,9 +137,10 @@ QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewI Q_UNUSED(options); Q_UNUSED(delegate); QDoubleSpinBox* tmpEditor = new QDoubleSpinBox(parent); - tmpEditor->setMinimum(Min); - tmpEditor->setMaximum(Max); + tmpEditor->setMinimum(min); + tmpEditor->setMaximum(max); tmpEditor->setDecimals(Precision); + tmpEditor->setSingleStep(singleStep); tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); tmpEditor->setValue(VProperty::d_ptr->VariantValue.toDouble()); connect(tmpEditor, static_cast(&QDoubleSpinBox::valueChanged), this, @@ -153,29 +160,35 @@ QVariant VDoubleProperty::getEditorData(QWidget* editor) const return QVariant(0); } -void VDoubleProperty::setSettings(double minimum, double maxiumum, int precision) +void VDoubleProperty::setSettings(double minimum, double maxiumum, double singleStep, int precision) { - VIntegerProperty::setSettings(minimum, maxiumum); + min = minimum; + max = maxiumum; + this->singleStep = singleStep; Precision = precision; } void VDoubleProperty::setSetting(const QString& key, const QVariant& value) { - if(key == "Min") - setSettings(value.toDouble(), Max, Precision); - else if(key == "Max") - setSettings(Min, value.toDouble(), Precision); - else if(key == "Precision") - setSettings(Min, Max, value.toDouble()); + if(key == QLatin1String("Min")) + setSettings(value.toDouble(), max, singleStep, Precision); + else if(key == QLatin1String("Max")) + setSettings(min, value.toDouble(), singleStep, Precision); + else if(key == QLatin1String("Step")) + setSettings(min, max, value.toDouble(), Precision); + else if(key == QLatin1String("Precision")) + setSettings(min, max, singleStep, value.toDouble()); } QVariant VDoubleProperty::getSetting(const QString& key) const { - if(key == "Min") - return Min; - if(key == "Max") - return Max; - if(key == "Precision") + if(key == QLatin1String("Min")) + return min; + if(key == QLatin1String("Max")) + return max; + if(key == QLatin1String("Step")) + return singleStep; + if(key == QLatin1String("Precision")) return Precision; else return VProperty::getSetting(key); @@ -183,7 +196,7 @@ QVariant VDoubleProperty::getSetting(const QString& key) const QStringList VDoubleProperty::getSettingKeys() const { - return (QStringList("Min") << "Max" << "Precision"); + return (QStringList("Min") << "Max" << "Step" << "Precision"); } QString VDoubleProperty::type() const diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h index b1fdbcafb..bef7000df 100644 --- a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h @@ -28,7 +28,7 @@ public: //! Sets the settings of a basic integer property //! \param minimum The minimum value //! \param maxiumum The maximum value - virtual void setSettings(int minimum, int maxiumum); + virtual void setSettings(int minimum, int maxiumum, int singleStep = 1.0); //! Sets the settings. Available settings: //! @@ -53,7 +53,7 @@ public: public slots: void valueChanged(int i); protected: - int Min, Max; + double min, max, singleStep; static const int StandardMin;// = -1000000; static const int StandardMax;// = 1000000; @@ -82,7 +82,7 @@ public: //! \param minimum The minimum value //! \param maxiumum The maximum value //! \param precision The number of decimal places - virtual void setSettings(double minimum, double maxiumum, int precision); + virtual void setSettings(double minimum, double maxiumum, double singleStep, int precision); //! Sets the settings. Available settings: //! From 6fb280663a24758aa88a6a68872c5e82afd2d544 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 3 Sep 2014 16:52:16 +0300 Subject: [PATCH 40/52] Show tool visualization when selected. --HG-- branch : feature --- src/app/tools/drawTools/vtoolalongline.cpp | 46 ++++++++++++++++ src/app/tools/drawTools/vtoolalongline.h | 2 +- src/app/tools/drawTools/vtoolarc.cpp | 51 ++++++++++++++++-- src/app/tools/drawTools/vtoolarc.h | 4 +- src/app/tools/drawTools/vtoolbisector.cpp | 48 +++++++++++++++++ src/app/tools/drawTools/vtoolbisector.h | 1 + src/app/tools/drawTools/vtoolcutarc.cpp | 42 +++++++++++++++ src/app/tools/drawTools/vtoolcutarc.h | 1 + src/app/tools/drawTools/vtoolcutspline.cpp | 32 +++++++++++ src/app/tools/drawTools/vtoolcutspline.h | 1 + .../tools/drawTools/vtoolcutsplinepath.cpp | 32 +++++++++++ src/app/tools/drawTools/vtoolcutsplinepath.h | 1 + src/app/tools/drawTools/vtoolendline.cpp | 46 ++++++++++++++++ src/app/tools/drawTools/vtoolendline.h | 2 +- src/app/tools/drawTools/vtoolheight.cpp | 45 ++++++++++++++++ src/app/tools/drawTools/vtoolheight.h | 1 + src/app/tools/drawTools/vtoolline.cpp | 44 +++++++++++++++ src/app/tools/drawTools/vtoolline.h | 1 + .../tools/drawTools/vtoollineintersect.cpp | 46 ++++++++++++++++ src/app/tools/drawTools/vtoollineintersect.h | 1 + src/app/tools/drawTools/vtoolnormal.cpp | 48 +++++++++++++++++ src/app/tools/drawTools/vtoolnormal.h | 1 + .../tools/drawTools/vtoolpointofcontact.cpp | 46 ++++++++++++++++ src/app/tools/drawTools/vtoolpointofcontact.h | 1 + .../drawTools/vtoolpointofintersection.cpp | 42 +++++++++++++++ .../drawTools/vtoolpointofintersection.h | 1 + .../tools/drawTools/vtoolshoulderpoint.cpp | 48 +++++++++++++++++ src/app/tools/drawTools/vtoolshoulderpoint.h | 1 + src/app/tools/drawTools/vtoolsinglepoint.cpp | 6 +++ src/app/tools/drawTools/vtoolsinglepoint.h | 1 + src/app/tools/drawTools/vtoolspline.cpp | 53 +++++++++++++++++++ src/app/tools/drawTools/vtoolspline.h | 2 + src/app/tools/drawTools/vtoolsplinepath.cpp | 32 +++++++++++ src/app/tools/drawTools/vtoolsplinepath.h | 2 + src/app/tools/drawTools/vtooltriangle.cpp | 46 ++++++++++++++++ src/app/tools/drawTools/vtooltriangle.h | 1 + src/app/tools/nodeDetails/vabstractnode.cpp | 6 +++ src/app/tools/nodeDetails/vabstractnode.h | 1 + src/app/tools/vabstracttool.cpp | 9 +++- src/app/tools/vabstracttool.h | 7 ++- src/app/tools/vtooldetail.cpp | 6 +++ src/app/tools/vtooldetail.h | 1 + src/app/tools/vtooluniondetails.cpp | 6 +++ src/app/tools/vtooluniondetails.h | 1 + .../widgets/vtooloptionspropertybrowser.cpp | 26 ++++++++- 45 files changed, 828 insertions(+), 13 deletions(-) diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index a8785b98a..cfb079e64 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogalongline.h" #include "../../geometry/vpointf.h" #include "exception/vexceptionobjecterror.h" +#include "../../visualization/vistoolalongline.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); @@ -79,6 +80,16 @@ void VToolAlongLine::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolAlongLine * visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -175,6 +186,41 @@ void VToolAlongLine::setSecondPointId(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolAlongLine *visual = new VisToolAlongLine(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolAlongLine * visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDialog set dialog when user want change tool option. diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index a469b0d34..09b44ef31 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -54,7 +54,7 @@ public: quint32 getSecondPointId() const; void setSecondPointId(const quint32 &value); - + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 5b22e6a92..43e99971d 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogarc.h" #include "../../geometry/varc.h" #include "../container/vformula.h" +#include "../../visualization/vistoolarc.h" #include @@ -271,12 +272,40 @@ void VToolArc::setFormulaF2(const VFormula &value) } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief FullUpdateFromFile update tool data form file. - */ -void VToolArc::FullUpdateFromFile() +void VToolArc::ShowVisualization(bool show) { - RefreshGeometry(); + if (show) + { + if (vis == nullptr) + { + VisToolArc * visual = new VisToolArc(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + + visual->setPoint1Id(arc->GetCenter().id()); + visual->setRadius(arc->GetFormulaRadius()); + visual->setF1(arc->GetFormulaF1()); + visual->setF2(arc->GetFormulaF2()); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolArc *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -336,4 +365,16 @@ void VToolArc::RefreshGeometry() { this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setPath(ToolPath()); + + if (vis != nullptr) + { + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + VisToolArc *visual = qobject_cast(vis); + + visual->setPoint1Id(arc->GetCenter().id()); + visual->setRadius(arc->GetFormulaRadius()); + visual->setF1(arc->GetFormulaF1()); + visual->setF2(arc->GetFormulaF2()); + visual->RefreshGeometry(); + } } diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index a7ba24b52..b8264694b 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -63,8 +63,8 @@ public: VFormula getFormulaF2() const; void setFormulaF2(const VFormula &value); -public slots: - virtual void FullUpdateFromFile(); + + virtual void ShowVisualization(bool show); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void RemoveReferens(); diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index cd4f9eee6..467d4ca8c 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -30,6 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogbisector.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolbisector.h" const QString VToolBisector::ToolType = QStringLiteral("bisector"); @@ -230,6 +231,17 @@ void VToolBisector::FullUpdateFromFile() thirdPointId = domElement.attribute(AttrThirdPoint, "").toUInt(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolBisector *visual = qobject_cast(vis); + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(basePointId); + visual->setPoint3Id(thirdPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -328,6 +340,42 @@ void VToolBisector::setThirdPointId(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolBisector * visual = new VisToolBisector(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(basePointId); + visual->setPoint3Id(thirdPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolBisector *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolBisector::getFirstPointId() const { diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index c0cee1b78..42ac58091 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -62,6 +62,7 @@ public: quint32 getThirdPointId() const; void setThirdPointId(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index e110c1d6b..f7cad6a1f 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogcutarc.h" #include "../../geometry/vpointf.h" #include "../../geometry/varc.h" +#include "../../visualization/vistoolcutarc.h" const QString VToolCutArc::ToolType = QStringLiteral("cutArc"); const QString VToolCutArc::AttrArc = QStringLiteral("arc"); @@ -180,6 +181,39 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutArc::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolCutArc * visual = new VisToolCutArc(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolCutArc *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -187,6 +221,14 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS void VToolCutArc::FullUpdateFromFile() { FullUpdateCurveFromFile(AttrArc); + + if (vis != nullptr) + { + VisToolCutArc *visual = qobject_cast(vis); + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolcutarc.h b/src/app/tools/drawTools/vtoolcutarc.h index 204871f43..2e852cdca 100644 --- a/src/app/tools/drawTools/vtoolcutarc.h +++ b/src/app/tools/drawTools/vtoolcutarc.h @@ -50,6 +50,7 @@ public: static const QString AttrArc; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::CutArc)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 4f6f6332e..2231cbc64 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -187,6 +187,38 @@ VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointNa return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSpline::ShowVisualization(bool show) +{ +// if (show) +// { +// if (vis == nullptr) +// { +// VisTool * visual = new VisTool(getData()); +// VMainGraphicsScene *scene = qApp->getCurrentScene(); +// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); +// scene->addItem(visual); + +// // add options +// visual->RefreshGeometry(); +// vis = visual; +// } +// else +// { +// VisTool * visual = qobject_cast(vis); +// if (visual != nullptr) +// { +// visual->show(); +// } +// } +// } +// else +// { +// delete vis; +// vis = nullptr; +// } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/tools/drawTools/vtoolcutspline.h b/src/app/tools/drawTools/vtoolcutspline.h index ba4111e4d..d1b184edc 100644 --- a/src/app/tools/drawTools/vtoolcutspline.h +++ b/src/app/tools/drawTools/vtoolcutspline.h @@ -51,6 +51,7 @@ public: static const QString AttrSpline; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::CutSpline)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index b9a62baca..4d54f0494 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -242,6 +242,38 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSplinePath::ShowVisualization(bool show) +{ +// if (show) +// { +// if (vis == nullptr) +// { +// VisTool * visual = new VisTool(getData()); +// VMainGraphicsScene *scene = qApp->getCurrentScene(); +// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); +// scene->addItem(visual); + +// // add options +// visual->RefreshGeometry(); +// vis = visual; +// } +// else +// { +// VisTool * visual = qobject_cast(vis); +// if (visual != nullptr) +// { +// visual->show(); +// } +// } +// } +// else +// { +// delete vis; +// vis = nullptr; +// } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.h b/src/app/tools/drawTools/vtoolcutsplinepath.h index a7de665f2..6f5db493c 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.h +++ b/src/app/tools/drawTools/vtoolcutsplinepath.h @@ -53,6 +53,7 @@ public: static const QString AttrSplinePath; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::CutSplinePath)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index 645df23c1..5ddad6a71 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 "./../visualization/vistoolendline.h" const QString VToolEndLine::ToolType = QStringLiteral("endLine"); @@ -185,6 +186,16 @@ void VToolEndLine::FullUpdateFromFile() formulaAngle = domElement.attribute(AttrAngle, ""); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolEndLine *visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setLength(formulaLength); + visual->setAngle(formulaAngle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -262,3 +273,38 @@ void VToolEndLine::setFormulaAngle(const VFormula &value) SaveOption(obj); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolEndLine::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolEndLine * visual = new VisToolEndLine(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setLength(formulaLength); + visual->setAngle(formulaAngle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolEndLine *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 16c58c7ea..794f51cfe 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -54,7 +54,7 @@ public: VFormula getFormulaAngle() const; void setFormulaAngle(const VFormula &value); - + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/drawTools/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index a77417454..19e24e9c3 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -29,6 +29,7 @@ #include "vtoolheight.h" #include "../../dialogs/tools/dialogheight.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolheight.h" const QString VToolHeight::ToolType = QStringLiteral("height"); @@ -202,6 +203,15 @@ void VToolHeight::FullUpdateFromFile() } RefreshGeometry(); + if (vis != nullptr) + { + VisToolHeight *visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setLineP1Id(p1LineId); + visual->setLineP2Id(p2LineId); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -276,6 +286,41 @@ void VToolHeight::setP2LineId(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolHeight * visual = new VisToolHeight(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setLineP1Id(p1LineId); + visual->setLineP2Id(p2LineId); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolHeight *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolHeight::getP1LineId() const { diff --git a/src/app/tools/drawTools/vtoolheight.h b/src/app/tools/drawTools/vtoolheight.h index 34e7b6c09..79dcfe08f 100644 --- a/src/app/tools/drawTools/vtoolheight.h +++ b/src/app/tools/drawTools/vtoolheight.h @@ -59,6 +59,7 @@ public: quint32 getP2LineId() const; void setP2LineId(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index c105989a2..5f9db41c6 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -31,6 +31,7 @@ #include #include "../../geometry/vpointf.h" #include "../../dialogs/tools/dialogline.h" +#include "../../visualization/vistoolline.h" const QString VToolLine::TagName = QStringLiteral("line"); @@ -189,6 +190,15 @@ QString VToolLine::getTagName() const void VToolLine::FullUpdateFromFile() { RefreshGeometry(); + + if (vis != nullptr) + { + VisToolLine *visual = qobject_cast(vis); + visual->setPoint1Id(firstPoint); + visual->setPoint2Id(secondPoint); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -401,6 +411,40 @@ void VToolLine::setSecondPoint(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolLine * visual = new VisToolLine(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPoint); + visual->setPoint2Id(secondPoint); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolLine *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLine::getFirstPoint() const { diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 888940e32..5e333e391 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -57,6 +57,7 @@ public: quint32 getSecondPoint() const; void setSecondPoint(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index ff0a010ef..286605a05 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -29,6 +29,7 @@ #include "vtoollineintersect.h" #include "../../dialogs/tools/dialoglineintersect.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoollineintersect.h" const QString VToolLineIntersect::ToolType = QStringLiteral("lineIntersect"); @@ -201,6 +202,16 @@ void VToolLineIntersect::FullUpdateFromFile() p2Line2 = domElement.attribute(AttrP2Line2, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolLineIntersect *visual = qobject_cast(vis); + visual->setPoint1Id(p1Line1); + visual->setLine1P2Id(p2Line1); + visual->setLine2P1Id(p1Line2); + visual->setLine2P2Id(p2Line2); + vis->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -298,6 +309,41 @@ void VToolLineIntersect::setP2Line2(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolLineIntersect * visual = new VisToolLineIntersect(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(p1Line1); + visual->setLine1P2Id(p2Line1); + visual->setLine2P1Id(p1Line2); + visual->setLine2P2Id(p2Line2); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolLineIntersect *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolLineIntersect::getP1Line2() const { diff --git a/src/app/tools/drawTools/vtoollineintersect.h b/src/app/tools/drawTools/vtoollineintersect.h index 89f9f5e36..dd28d16b9 100644 --- a/src/app/tools/drawTools/vtoollineintersect.h +++ b/src/app/tools/drawTools/vtoollineintersect.h @@ -63,6 +63,7 @@ public: quint32 getP2Line2() const; void setP2Line2(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index c902f527b..ff9334dfc 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -30,6 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialognormal.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolnormal.h" const QString VToolNormal::ToolType = QStringLiteral("normal"); @@ -209,6 +210,17 @@ void VToolNormal::FullUpdateFromFile() angle = domElement.attribute(AttrAngle, "").toDouble(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolNormal *visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setAngle(angle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -306,3 +318,39 @@ void VToolNormal::setSecondPointId(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolNormal::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolNormal * visual = new VisToolNormal(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setAngle(angle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolNormal *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + diff --git a/src/app/tools/drawTools/vtoolnormal.h b/src/app/tools/drawTools/vtoolnormal.h index 8c41676ca..3c85cb439 100644 --- a/src/app/tools/drawTools/vtoolnormal.h +++ b/src/app/tools/drawTools/vtoolnormal.h @@ -56,6 +56,7 @@ public: quint32 getSecondPointId() const; void setSecondPointId(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 5c11e34e7..dd8d4f27e 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogpointofcontact.h" #include "../../geometry/vpointf.h" #include "../../container/vformula.h" +#include "../../visualization/vistoolpointofcontact.h" const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact"); @@ -228,6 +229,16 @@ void VToolPointOfContact::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolPointOfContact *visual = qobject_cast(vis); + visual->setPoint1Id(firstPointId); + visual->setLineP2Id(secondPointId); + visual->setRadiusId(center); + visual->setRadius(arcRadius); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -318,6 +329,41 @@ void VToolPointOfContact::setSecondPointId(const quint32 &value) secondPointId = value; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolPointOfContact * visual = new VisToolPointOfContact(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPointId); + visual->setLineP2Id(secondPointId); + visual->setRadiusId(center); + visual->setRadius(arcRadius); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolPointOfContact *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolPointOfContact::getFirstPointId() const { diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index 60c4924ef..1cbc84815 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -68,6 +68,7 @@ public: quint32 getSecondPointId() const; void setSecondPointId(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index ad53b8536..52ef71132 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -29,6 +29,7 @@ #include "vtoolpointofintersection.h" #include "../../dialogs/tools/dialogpointofintersection.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolpointofintersection.h" const QString VToolPointOfIntersection::ToolType = QStringLiteral("pointOfIntersection"); @@ -171,6 +172,14 @@ void VToolPointOfIntersection::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolPointOfIntersection *visual = qobject_cast(vis); + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -251,6 +260,39 @@ void VToolPointOfIntersection::setSecondPointId(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolPointOfIntersection * visual = new VisToolPointOfIntersection(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolPointOfIntersection *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolPointOfIntersection::getFirstPointId() const { diff --git a/src/app/tools/drawTools/vtoolpointofintersection.h b/src/app/tools/drawTools/vtoolpointofintersection.h index eef98a9b1..80e2980de 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.h +++ b/src/app/tools/drawTools/vtoolpointofintersection.h @@ -58,6 +58,7 @@ public: quint32 getSecondPointId() const; void setSecondPointId(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index a4b9d3f95..679fa0929 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -30,6 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogshoulderpoint.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolshoulderpoint.h" const QString VToolShoulderPoint::ToolType = QStringLiteral("shoulder"); @@ -234,6 +235,17 @@ void VToolShoulderPoint::FullUpdateFromFile() pShoulder = domElement.attribute(AttrPShoulder, "").toUInt(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolShoulderPoint *visual = qobject_cast(vis); + visual->setPoint1Id(pShoulder); + visual->setLineP1Id(basePointId); + visual->setLineP2Id(p2Line); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -332,6 +344,42 @@ void VToolShoulderPoint::setPShoulder(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolShoulderPoint * visual = new VisToolShoulderPoint(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(pShoulder); + visual->setLineP1Id(basePointId); + visual->setLineP2Id(p2Line); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolShoulderPoint *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolShoulderPoint::getP2Line() const { diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index e8d8c63be..ef8c08df6 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -60,6 +60,7 @@ public: quint32 getPShoulder() const; void setPShoulder(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index c8a9461fb..45bd66058 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -82,6 +82,12 @@ void VToolSinglePoint::setDialog() dialogTool->setData(p->name(), p->toQPointF()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::ShowVisualization(bool show) +{ + Q_UNUSED(show); //don't have any visualization for base point yet +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToFile add tag with informations about tool into file. diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index 98a60bcd5..2e9aa14f1 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -45,6 +45,7 @@ public: static const QString ToolType; virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::SinglePoint)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 822aa2aaa..1b4ebd96b 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -30,6 +30,7 @@ #include "../../geometry/vspline.h" #include "../../dialogs/tools/dialogspline.h" #include "../../undocommands/movespline.h" +#include "../../visualization/vistoolspline.h" const QString VToolSpline::ToolType = QStringLiteral("simple"); @@ -204,6 +205,45 @@ void VToolSpline::setSpline(const VSpline &spl) SaveOption(obj); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolSpline *visual = new VisToolSpline(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); + visual->setPoint1Id(spl->GetP1().id()); + visual->setPoint4Id(spl->GetP4().id()); + visual->setAngle1(spl->GetAngle1()); + visual->setAngle2(spl->GetAngle2()); + visual->setKAsm1(spl->GetKasm1()); + visual->setKAsm2(spl->GetKasm2()); + visual->setKCurve(spl->GetKcurve()); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolSpline *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ControlPointChangePosition handle change position control point. @@ -336,4 +376,17 @@ void VToolSpline::RefreshGeometry() controlPoints[0]->blockSignals(false); controlPoints[1]->blockSignals(false); + + if (vis != nullptr) + { + VisToolSpline *visual = qobject_cast(vis); + visual->setPoint1Id(spl->GetP1().id()); + visual->setPoint4Id(spl->GetP4().id()); + visual->setAngle1(spl->GetAngle1()); + visual->setAngle2(spl->GetAngle2()); + visual->setKAsm1(spl->GetKasm1()); + visual->setKAsm2(spl->GetKasm2()); + visual->setKCurve(spl->GetKcurve()); + visual->RefreshGeometry(); + } } diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index cbbb09f92..a0c8faa33 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -53,6 +53,8 @@ public: VSpline getSpline()const; void setSpline(const VSpline &spl); + + virtual void ShowVisualization(bool show); public slots: void ControlPointChangePosition (const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index f63b1e836..baad7c2fc 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -280,6 +280,38 @@ void VToolSplinePath::setSplinePath(const VSplinePath &splPath) SaveOption(obj); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::ShowVisualization(bool show) +{ +// if (show) +// { +// if (vis == nullptr) +// { +// VisTool * visual = new VisTool(getData()); +// VMainGraphicsScene *scene = qApp->getCurrentScene(); +// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); +// scene->addItem(visual); + +// // add options +// visual->RefreshGeometry(); +// vis = visual; +// } +// else +// { +// VisTool * visual = qobject_cast(vis); +// if (visual != nullptr) +// { +// visual->show(); +// } +// } +// } +// else +// { +// delete vis; +// vis = nullptr; +// } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index cd8046a89..3943a4626 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -51,6 +51,8 @@ public: VSplinePath getSplinePath()const; void setSplinePath(const VSplinePath &splPath); + + virtual void ShowVisualization(bool show); signals: /** * @brief RefreshLine refresh control line. diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index 5b2493641..6c1eee49c 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -29,6 +29,7 @@ #include "vtooltriangle.h" #include "../../dialogs/tools/dialogtriangle.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistooltriangle.h" #include @@ -229,6 +230,16 @@ void VToolTriangle::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolTriangle * visual = qobject_cast(vis); + visual->setPoint1Id(axisP1Id); + visual->setPoint2Id(axisP2Id); + visual->setHypotenuseP1Id(firstPointId); + visual->setHypotenuseP2Id(secondPointId); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -315,6 +326,41 @@ void VToolTriangle::setSecondPointId(const quint32 &value) } } +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolTriangle * visual = new VisToolTriangle(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(axisP1Id); + visual->setPoint2Id(axisP2Id); + visual->setHypotenuseP1Id(firstPointId); + visual->setHypotenuseP2Id(secondPointId); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolTriangle * visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VToolTriangle::getFirstPointId() const { diff --git a/src/app/tools/drawTools/vtooltriangle.h b/src/app/tools/drawTools/vtooltriangle.h index 9b168f721..5ae0743dc 100644 --- a/src/app/tools/drawTools/vtooltriangle.h +++ b/src/app/tools/drawTools/vtooltriangle.h @@ -66,6 +66,7 @@ public: quint32 getSecondPointId() const; void setSecondPointId(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); diff --git a/src/app/tools/nodeDetails/vabstractnode.cpp b/src/app/tools/nodeDetails/vabstractnode.cpp index e8268da8d..ae02381c8 100644 --- a/src/app/tools/nodeDetails/vabstractnode.cpp +++ b/src/app/tools/nodeDetails/vabstractnode.cpp @@ -69,6 +69,12 @@ void VAbstractNode::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractNode::ShowVisualization(bool show) +{ + Q_UNUSED(show) +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToModeling add tag to modeling tag current pattern peace. diff --git a/src/app/tools/nodeDetails/vabstractnode.h b/src/app/tools/nodeDetails/vabstractnode.h index 3d167618b..61f505ccc 100644 --- a/src/app/tools/nodeDetails/vabstractnode.h +++ b/src/app/tools/nodeDetails/vabstractnode.h @@ -45,6 +45,7 @@ public: static const QString AttrIdTool; virtual void DeleteNode(); virtual void RestoreNode(); + virtual void ShowVisualization(bool show); protected: /** @brief idNodenode id. */ quint32 idNode; diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index adf2d4f5a..90a6e66d1 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -84,7 +84,8 @@ const QString VAbstractTool::TypeLineDashDotDotLine = QStringLiteral("dashDotDot * @param parent parent object. */ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent) - :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine) + :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine), + vis(nullptr) { SCASSERT(doc != nullptr); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange); @@ -92,6 +93,12 @@ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObjec connect(this, &VAbstractTool::LiteUpdateTree, this->doc, &VPattern::LiteParseTree); } +//--------------------------------------------------------------------------------------------------------------------- +VAbstractTool::~VAbstractTool() +{ + delete vis; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view. diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index 210b02480..3ae5b9246 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -39,6 +39,7 @@ class QGraphicsScene; class QGraphicsView; class QGraphicsItem; class QRectF; +class Visualization; /** * @brief The VAbstractTool abstract class for all tools. @@ -48,7 +49,7 @@ class VAbstractTool: public VDataTool Q_OBJECT public: VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent = nullptr); - virtual ~VAbstractTool(){} + virtual ~VAbstractTool(); static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view); static QPointF LineIntersectRect(QRectF rec, QLineF line); static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, @@ -105,7 +106,7 @@ public: void setTypeLine(const QString &value); QMap PointsList() const; virtual QString getTagName() const =0; - + virtual void ShowVisualization(bool show) =0; public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -142,6 +143,8 @@ protected: /** @brief typeLine line type. */ QString typeLine; + Visualization *vis; + /** * @brief AddToFile add tag with informations about tool into file. */ diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index 010e96b04..4cbe065ba 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -487,6 +487,12 @@ QString VToolDetail::getTagName() const return VToolDetail::TagName; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::ShowVisualization(bool show) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/vtooldetail.h b/src/app/tools/vtooldetail.h index 3b33c0695..61cf79210 100644 --- a/src/app/tools/vtooldetail.h +++ b/src/app/tools/vtooldetail.h @@ -85,6 +85,7 @@ public: virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::Detail)}; virtual QString getTagName() const; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile (); virtual void FullUpdateFromGuiOk(int result); diff --git a/src/app/tools/vtooluniondetails.cpp b/src/app/tools/vtooluniondetails.cpp index a8cbcd6b3..54db8727d 100644 --- a/src/app/tools/vtooluniondetails.cpp +++ b/src/app/tools/vtooluniondetails.cpp @@ -441,6 +441,12 @@ QString VToolUnionDetails::getTagName() const return VToolUnionDetails::TagName; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolUnionDetails::ShowVisualization(bool show) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool from GUI. diff --git a/src/app/tools/vtooluniondetails.h b/src/app/tools/vtooluniondetails.h index 2d4168c55..737778532 100644 --- a/src/app/tools/vtooluniondetails.h +++ b/src/app/tools/vtooluniondetails.h @@ -77,6 +77,7 @@ public: static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, const qreal &angle); virtual QString getTagName() const; + virtual void ShowVisualization(bool show); public slots: /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 614a80ba2..8a4167768 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -308,10 +308,16 @@ void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) propertyToId.clear(); idToProperty.clear(); - currentItem = item; + VAbstractTool *previousTool = dynamic_cast(currentItem); + if (previousTool != nullptr) + { + previousTool->ShowVisualization(false); // hide for previous tool + } + currentItem = item; if (currentItem == nullptr) { + formView->setTitle(""); return; } @@ -835,6 +841,7 @@ void VToolOptionsPropertyBrowser::ChangeDataToolTriangle(VProperty *property) void VToolOptionsPropertyBrowser::ShowOptionsToolSinglePoint(QGraphicsItem *item) { VToolSinglePoint *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Base point")); AddPropertyPointName(i, tr("Point label")); @@ -848,6 +855,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSinglePoint(QGraphicsItem *item void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item) { VToolEndLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Point at distance and angle")); AddPropertyPointName(i, tr("Point label")); @@ -860,6 +868,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item) { VToolAlongLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Point at distance along line")); AddPropertyPointName(i, tr("Point label")); @@ -871,6 +880,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolArc(QGraphicsItem *item) { VToolArc *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Arc")); AddPropertyFormula(tr("Radius"), i->getFormulaRadius(), VAbstractTool::AttrRadius); @@ -882,6 +892,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolArc(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item) { VToolBisector *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Point along bisector")); AddPropertyPointName(i, tr("Point label")); @@ -893,6 +904,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolCutArc(QGraphicsItem *item) { VToolCutArc *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Cut arc tool")); AddPropertyPointName(i, tr("Point label")); @@ -903,6 +915,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutArc(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolCutSpline(QGraphicsItem *item) { VToolCutSpline *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Tool for segmenting a curve")); AddPropertyPointName(i, tr("Point label")); @@ -913,6 +926,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutSpline(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolCutSplinePath(QGraphicsItem *item) { VToolCutSplinePath *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Tool segment a pathed curve")); AddPropertyPointName(i, tr("Point label")); @@ -923,6 +937,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolCutSplinePath(QGraphicsItem *it void VToolOptionsPropertyBrowser::ShowOptionsToolHeight(QGraphicsItem *item) { VToolHeight *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Perpendicular point along line")); AddPropertyPointName(i, tr("Point label")); @@ -933,6 +948,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolHeight(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolLine(QGraphicsItem *item) { VToolLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Line between points")); AddPropertyLineType(i, tr("Line type")); @@ -942,6 +958,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolLine(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersect(QGraphicsItem *item) { VToolLineIntersect *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Point at line intersection")); AddPropertyPointName(i, tr("Point label")); @@ -951,6 +968,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersect(QGraphicsItem *it void VToolOptionsPropertyBrowser::ShowOptionsToolNormal(QGraphicsItem *item) { VToolNormal *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Point along perpendicular")); AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); @@ -969,6 +987,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolNormal(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfContact(QGraphicsItem *item) { VToolPointOfContact *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Point at intersection of arc and line")); AddPropertyPointName(i, tr("Point label")); @@ -979,6 +998,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfContact(QGraphicsItem *i void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersection(QGraphicsItem *item) { VToolPointOfIntersection *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Tool to make point from x & y of two other points")); AddPropertyPointName(i, tr("Point label")); @@ -988,6 +1008,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersection(QGraphicsIt void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *item) { VToolShoulderPoint *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Special point on shoulder")); AddPropertyPointName(i, tr("Point label")); @@ -999,6 +1020,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *it void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) { VToolSpline *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Curve tool")); VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); @@ -1015,6 +1037,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item) { VToolSplinePath *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Tool for path curve")); VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); @@ -1031,6 +1054,7 @@ void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item) void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item) { VToolTriangle *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); formView->setTitle(tr("Tool triangle")); AddPropertyPointName(i, tr("Point label")); From aee0c1fed666b52eea06e87bf189cd418475e406 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 3 Sep 2014 19:09:59 +0300 Subject: [PATCH 41/52] Ignore visualization if need show tool under visualization. --HG-- branch : feature --- src/app/options.h | 5 +- src/app/visualization/visualization.pri | 2 - src/app/visualization/vsimplecurve.h | 2 +- src/app/visualization/vsimplesplinepath.cpp | 94 --------------------- src/app/visualization/vsimplesplinepath.h | 58 ------------- src/app/widgets/vmaingraphicsview.cpp | 16 +++- 6 files changed, 18 insertions(+), 159 deletions(-) delete mode 100644 src/app/visualization/vsimplesplinepath.cpp delete mode 100644 src/app/visualization/vsimplesplinepath.h diff --git a/src/app/options.h b/src/app/options.h index d2de5312e..601214707 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -81,6 +81,7 @@ enum class Vis : unsigned char { ControlPointSpline = 29, // increase this value if need more positions in Tool enum GraphicsSimpleTextItem, + SimpleSplinePath, Line, Path, ToolAlongLine, @@ -96,9 +97,7 @@ enum class Vis : unsigned char ToolPointOfIntersection, ToolShoulderPoint, ToolSpline, - ToolTriangle, - SimpleCurvePoint, - SimpleSplinePath + ToolTriangle }; enum class Source : char { FromGui, FromFile, FromTool }; diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index b3397108a..f811878f2 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -1,7 +1,6 @@ HEADERS += \ visualization/vgraphicssimpletextitem.h \ visualization/vcontrolpointspline.h \ - visualization/vsimplesplinepath.h \ visualization/vsimplecurve.h \ visualization/visline.h \ visualization/vistoolline.h \ @@ -24,7 +23,6 @@ HEADERS += \ SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ visualization/vcontrolpointspline.cpp \ - visualization/vsimplesplinepath.cpp \ visualization/vsimplecurve.cpp \ visualization/visline.cpp \ visualization/vistoolline.cpp \ diff --git a/src/app/visualization/vsimplecurve.h b/src/app/visualization/vsimplecurve.h index bf6cb6683..d33afb269 100644 --- a/src/app/visualization/vsimplecurve.h +++ b/src/app/visualization/vsimplecurve.h @@ -47,7 +47,7 @@ public: virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); virtual int type() const {return Type;} - enum { Type = UserType + static_cast(Vis::SimpleCurvePoint)}; + enum { Type = UserType + static_cast(Vis::SimpleSplinePath)}; signals: /** * @brief Choosed send id when clicked. diff --git a/src/app/visualization/vsimplesplinepath.cpp b/src/app/visualization/vsimplesplinepath.cpp deleted file mode 100644 index 68ca539be..000000000 --- a/src/app/visualization/vsimplesplinepath.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/************************************************************************ - ** - ** @file vsimplesplinepath.cpp - ** @author Roman Telezhynskyi - ** @date 17 12, 2013 - ** - ** @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) 2013 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 . - ** - *************************************************************************/ - -#include "vsimplesplinepath.h" -#include "../widgets/vapplication.h" -#include -#include -#include - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VSimpleSplinePath constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id spline path id. - * @param factor scale factor. - */ -VSimpleSplinePath::VSimpleSplinePath(VPattern *doc, VContainer *data, quint32 id, qreal *factor) - :VAbstractTool(doc, data, id), QGraphicsPathItem(), factor(factor) -{} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleSplinePath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - /* From question on StackOverflow - * https://stackoverflow.com/questions/10985028/how-to-remove-border-around-qgraphicsitem-when-selected - * - * There's no interface to disable the drawing of the selection border for the build-in QGraphicsItems. The only way - * I can think of is derive your own items from the build-in ones and override the paint() function:*/ - QStyleOptionGraphicsItem myOption(*option); - myOption.state &= ~QStyle::State_Selected; - QGraphicsPathItem::paint(painter, &myOption, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief mouseReleaseEvent handle mouse release events. - * @param event mouse release event. - */ -void VSimpleSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) - { - emit ChoosedTool(id, SceneObject::SplinePath); - } - QGraphicsPathItem::mouseReleaseEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. - */ -void VSimpleSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor)); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverLeaveEvent handle hover leave events. - * @param event hover leave event. - */ -void VSimpleSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); -} diff --git a/src/app/visualization/vsimplesplinepath.h b/src/app/visualization/vsimplesplinepath.h deleted file mode 100644 index 3ff124b0a..000000000 --- a/src/app/visualization/vsimplesplinepath.h +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************ - ** - ** @file vsimplesplinepath.h - ** @author Roman Telezhynskyi - ** @date 17 12, 2013 - ** - ** @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) 2013 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 VSIMPLESPLINEPATH_H -#define VSIMPLESPLINEPATH_H - -#include -#include "../tools/vabstracttool.h" - -/** - * @brief The VSimpleSplinePath class for simple spline path. This object used when we cut spline path and want show - * peaces. - */ -class VSimpleSplinePath : public VAbstractTool, public QGraphicsPathItem -{ - Q_OBJECT -public: - VSimpleSplinePath(VPattern *doc, VContainer *data, quint32 id, qreal *factor); - virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); - - virtual int type() const {return Type;} - enum { Type = UserType + static_cast(Vis::SimpleSplinePath)}; -protected: - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); -private: - Q_DISABLE_COPY(VSimpleSplinePath) - /** @brief factor scale factor. */ - qreal *factor; -}; - -#endif // VSIMPLESPLINEPATH_H diff --git a/src/app/widgets/vmaingraphicsview.cpp b/src/app/widgets/vmaingraphicsview.cpp index 4a7ef658b..07c61aaa5 100644 --- a/src/app/widgets/vmaingraphicsview.cpp +++ b/src/app/widgets/vmaingraphicsview.cpp @@ -33,7 +33,9 @@ #include #include #include "../tools/vabstracttool.h" +#include "../visualization/vsimplecurve.h" +#include #include #include @@ -223,7 +225,19 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) case Qt::NoModifier: if (showToolOptions) { - emit itemClicked(itemAt(mousePress->pos())); + QList list = items(mousePress->pos()); + if (list.size() == 0) + { + emit itemClicked(nullptr); + break; + } + for (int i = 0; i < list.size(); ++i) + { + if (list.at(i)->type() <= VSimpleCurve::Type && list.at(i)->type() > QGraphicsItem::UserType) + { + emit itemClicked(list.at(i)); + } + } } break; default: From 483c7a0e568bb09ffcb1ed036aca4bb0d1731e34 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 4 Sep 2014 08:20:41 +0300 Subject: [PATCH 42/52] Check if point name unique. --HG-- branch : feature --- src/app/container/vcontainer.cpp | 16 ++++++++++++++++ src/app/container/vcontainer.h | 5 +++++ src/app/widgets/vtooloptionspropertybrowser.cpp | 3 +-- src/app/xml/vpattern.cpp | 4 ++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 0e9960bd4..865c79c56 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -37,6 +37,7 @@ quint32 VContainer::_id = NULL_ID; qreal VContainer::_size = 50; qreal VContainer::_height = 176; +QSet VContainer::uniqueNames = QSet(); //--------------------------------------------------------------------------------------------------------------------- /** @@ -138,6 +139,7 @@ quint32 VContainer::AddGObject(VGObject *obj) { SCASSERT(obj != nullptr); QSharedPointer pointer(obj); + uniqueNames.insert(obj->name()); return AddObject(d->gObjects, pointer); } @@ -210,6 +212,7 @@ void VContainer::Clear() d->details.clear(); ClearVariables(); ClearGObjects(); + ClearUniqueNames(); } //--------------------------------------------------------------------------------------------------------------------- @@ -334,6 +337,7 @@ void VContainer::UpdateGObject(quint32 id, VGObject* obj) SCASSERT(obj != nullptr); QSharedPointer pointer(obj); UpdateObject(d->gObjects, id, pointer); + uniqueNames.insert(obj->name()); } //--------------------------------------------------------------------------------------------------------------------- @@ -407,6 +411,12 @@ const QMap > VContainer::DataAngleLines() co return DataVar(VarType::LineAngle); } +//--------------------------------------------------------------------------------------------------------------------- +bool VContainer::IsUnique(const QString &name) +{ + return !uniqueNames.contains(name); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VariableExist check if exist variable this same name. @@ -442,6 +452,12 @@ void VContainer::ClearDetails() d->details.clear(); } +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::ClearUniqueNames() +{ + uniqueNames.clear(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetSize set value of size diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 08cc0fa86..18eff2599 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -37,6 +37,7 @@ #include #include +#include #ifdef Q_CC_GNU #pragma GCC diagnostic push @@ -186,6 +187,7 @@ public: } } d->variables[name] = QSharedPointer(var); + uniqueNames.insert(name); } void UpdateGObject(quint32 id, VGObject* obj); @@ -196,6 +198,7 @@ public: void ClearCalculationGObjects(); void ClearVariables(const VarType &type = VarType::Unknown); void ClearDetails(); + static void ClearUniqueNames(); void SetSize(qreal size); void SetSizeName(const QString &name); @@ -221,6 +224,7 @@ public: const QMap > DataLengthArcs() const; const QMap > DataAngleLines() const; + static bool IsUnique(const QString &name); private: /** @@ -229,6 +233,7 @@ private: static quint32 _id; static qreal _size; static qreal _height; + static QSet uniqueNames; QSharedDataPointer d; diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index 8a4167768..d224da1b3 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -369,13 +369,12 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) return; } - if (name.isEmpty()) + if (name.isEmpty() || VContainer::IsUnique(name) == false) { idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } else { - //TODO check if label name is unique i->setName(name); } } diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 9142e6e4e..bbab2102d 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2326,6 +2326,10 @@ void VPattern::PrepareForParse(const Document &parse) cursor = 0; history.clear(); } + else if (parse == Document::LiteParse) + { + data->ClearUniqueNames(); + } } //--------------------------------------------------------------------------------------------------------------------- From 4c913f485d35f272fc6996aa64014f728a80b74b Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 4 Sep 2014 16:42:16 +0300 Subject: [PATCH 43/52] RegExp for validation label name. --HG-- branch : feature --- src/app/dialogs/app/dialogincrements.cpp | 4 +--- src/app/options.cpp | 3 +++ src/app/options.h | 2 ++ src/app/tools/vabstracttool.cpp | 4 +--- src/app/widgets/vmaingraphicsview.h | 2 ++ src/app/widgets/vtooloptionspropertybrowser.cpp | 3 ++- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index d2fd0853f..e40893726 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -69,9 +69,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par } } - //Same regex in pattern.xsd shema file. Don't forget synchronize. - TextDelegate *textDelegate = new TextDelegate("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$", - data, ui->tableWidgetIncrement); + TextDelegate *textDelegate = new TextDelegate(nameRegExp, data, ui->tableWidgetIncrement); ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value diff --git a/src/app/options.cpp b/src/app/options.cpp index 5e2f5139c..58b9da8da 100644 --- a/src/app/options.cpp +++ b/src/app/options.cpp @@ -29,6 +29,9 @@ #include "options.h" #include +//Same regexp in pattern.xsd shema file. Don't forget synchronize. +const QString nameRegExp = QStringLiteral("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$"); + // Keep synchronize all names with initialization in VApllication class. //measurements const QString headGirth_M = QStringLiteral("head_girth"); diff --git a/src/app/options.h b/src/app/options.h index 601214707..b12d19129 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -43,6 +43,8 @@ static const quint32 null_id = 0; #define DefPointRadius 2.0//mm #define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value. +extern const QString nameRegExp; + enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; enum class Tool : unsigned char { diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 90a6e66d1..3147abb45 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -95,9 +95,7 @@ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObjec //--------------------------------------------------------------------------------------------------------------------- VAbstractTool::~VAbstractTool() -{ - delete vis; -} +{} //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/app/widgets/vmaingraphicsview.h b/src/app/widgets/vmaingraphicsview.h index abec4a09e..810b83427 100644 --- a/src/app/widgets/vmaingraphicsview.h +++ b/src/app/widgets/vmaingraphicsview.h @@ -84,6 +84,7 @@ private: bool eventFilter(QObject* object, QEvent* event); private: + Q_DISABLE_COPY(GraphicsViewZoom) /** @brief _numScheduledScalings keep number scheduled scalings. */ qint32 _numScheduledScalings; }; @@ -121,6 +122,7 @@ protected: void mousePressEvent(QMouseEvent *mousePress); void mouseReleaseEvent(QMouseEvent *event); private: + Q_DISABLE_COPY(VMainGraphicsView) GraphicsViewZoom* zoom; bool showToolOptions; }; diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp index d224da1b3..e55e5bd51 100644 --- a/src/app/widgets/vtooloptionspropertybrowser.cpp +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -369,7 +369,8 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name) return; } - if (name.isEmpty() || VContainer::IsUnique(name) == false) + QRegExp rx(nameRegExp); + if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.exactMatch(name) == false) { idToProperty[VAbstractTool::AttrName]->setValue(i->name()); } From a65faff8d913374b08aaa23f5ee874cb84416c63 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 5 Sep 2014 11:01:46 +0300 Subject: [PATCH 44/52] Auto creation label. --HG-- branch : feature --- .../app/configpages/configurationpage.cpp | 52 +++++++- .../app/configpages/configurationpage.h | 5 + src/app/dialogs/tools/dialogalongline.cpp | 3 +- src/app/dialogs/tools/dialogalongline.ui | 37 ------ src/app/dialogs/tools/dialogbisector.cpp | 2 +- src/app/dialogs/tools/dialogbisector.ui | 37 ------ src/app/dialogs/tools/dialogcutarc.cpp | 3 +- src/app/dialogs/tools/dialogcutarc.ui | 37 ------ src/app/dialogs/tools/dialogcutspline.cpp | 3 +- src/app/dialogs/tools/dialogcutspline.ui | 37 ------ src/app/dialogs/tools/dialogcutsplinepath.cpp | 3 +- src/app/dialogs/tools/dialogcutsplinepath.ui | 37 ------ src/app/dialogs/tools/dialogendline.cpp | 2 +- src/app/dialogs/tools/dialogendline.ui | 37 ------ src/app/dialogs/tools/dialogheight.cpp | 2 +- src/app/dialogs/tools/dialogheight.ui | 37 ------ src/app/dialogs/tools/dialoglineintersect.cpp | 3 +- src/app/dialogs/tools/dialoglineintersect.ui | 37 ------ src/app/dialogs/tools/dialognormal.cpp | 2 +- src/app/dialogs/tools/dialognormal.ui | 37 ------ .../dialogs/tools/dialogpointofcontact.cpp | 3 +- src/app/dialogs/tools/dialogpointofcontact.ui | 37 ------ .../tools/dialogpointofintersection.cpp | 3 +- .../tools/dialogpointofintersection.ui | 37 ------ src/app/dialogs/tools/dialogshoulderpoint.cpp | 2 +- src/app/dialogs/tools/dialogshoulderpoint.ui | 37 ------ src/app/dialogs/tools/dialogsinglepoint.ui | 37 ------ src/app/dialogs/tools/dialogtriangle.cpp | 3 +- src/app/dialogs/tools/dialogtriangle.ui | 37 ------ src/app/mainwindow.cpp | 4 +- src/app/widgets/vapplication.cpp | 2 +- src/app/widgets/vapplication.h | 19 +++ src/app/xml/vpattern.cpp | 123 ++++++++++++++++++ src/app/xml/vpattern.h | 4 + 34 files changed, 225 insertions(+), 536 deletions(-) diff --git a/src/app/dialogs/app/configpages/configurationpage.cpp b/src/app/dialogs/app/configpages/configurationpage.cpp index 6c91267d1..46bddce59 100644 --- a/src/app/dialogs/app/configpages/configurationpage.cpp +++ b/src/app/dialogs/app/configpages/configurationpage.cpp @@ -43,8 +43,8 @@ //--------------------------------------------------------------------------------------------------------------------- ConfigurationPage::ConfigurationPage(QWidget *parent) - : QWidget(parent), autoSaveCheck(nullptr), autoTime(nullptr), langCombo(nullptr), unitCombo(nullptr), - osOptionCheck(nullptr), langChanged(false), unitChanged(false) + : QWidget(parent), autoSaveCheck(nullptr), autoTime(nullptr), langCombo(nullptr), labelCombo(nullptr), + unitCombo(nullptr), osOptionCheck(nullptr), langChanged(false), unitChanged(false), labelLangChanged(false) { QGroupBox *saveGroup = SaveGroup(); QGroupBox *langGroup = LangGroup(); @@ -93,6 +93,12 @@ void ConfigurationPage::Apply() QString text = QString(tr("Default unit updated and will be used the next pattern creation")); QMessageBox::information(this, QApplication::applicationName(), text); } + if (labelLangChanged) + { + QString locale = qvariant_cast(labelCombo->itemData(labelCombo->currentIndex())); + qApp->getSettings()->setValue("configuration/label_language", locale); + labelLangChanged = false; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -107,6 +113,12 @@ void ConfigurationPage::UnitChanged() this->unitChanged = true; } +//--------------------------------------------------------------------------------------------------------------------- +void ConfigurationPage::LabelLangChanged() +{ + labelLangChanged = true; +} + //--------------------------------------------------------------------------------------------------------------------- QGroupBox *ConfigurationPage::SaveGroup() { @@ -227,13 +239,47 @@ QGroupBox *ConfigurationPage::LangGroup() UnitLayout->addWidget(unitLabel); UnitLayout->addWidget(this->unitCombo); - //----------------------- Unit setup + //----------------------- Label language + + QLabel *labelName = new QLabel(tr("Label language")); + labelCombo = new QComboBox; + + QString checkedLabelLocale = settings->value("configuration/label_language", defaultLocale).toString(); + + QStringList list{"de", "en" , "fr" , "ru" , "uk"}; + SetLabelComboBox(list); + + index = labelCombo->findData(checkedLabelLocale); + if (index != -1) + { + labelCombo->setCurrentIndex(index); + } + connect(labelCombo, static_cast(&QComboBox::currentIndexChanged), this, + &ConfigurationPage::LabelLangChanged); + + QHBoxLayout *labelLangLayout = new QHBoxLayout; + labelLangLayout->addWidget(labelName); + labelLangLayout->addWidget(labelCombo); + + //----------------------- QVBoxLayout *langLayout = new QVBoxLayout; langLayout->addLayout(guiLangLayout); langLayout->addLayout(separatorLayout); langLayout->addLayout(UnitLayout); + langLayout->addLayout(labelLangLayout); langGroup->setLayout(langLayout); return langGroup; } + +//--------------------------------------------------------------------------------------------------------------------- +void ConfigurationPage::SetLabelComboBox(const QStringList &list) +{ + for (int i = 0; i < list.size(); ++i) + { + QString lang = QLocale(list.at(i)).nativeLanguageName(); + QIcon ico(QString("%1/%2.png").arg("://icon/flags").arg(list.at(i))); + labelCombo->addItem(ico, lang, list.at(i)); + } +} diff --git a/src/app/dialogs/app/configpages/configurationpage.h b/src/app/dialogs/app/configpages/configurationpage.h index 9e32fee0e..0bad4043c 100644 --- a/src/app/dialogs/app/configpages/configurationpage.h +++ b/src/app/dialogs/app/configpages/configurationpage.h @@ -46,17 +46,22 @@ public: public slots: void LangChanged(); void UnitChanged(); + void LabelLangChanged(); private: Q_DISABLE_COPY(ConfigurationPage) QCheckBox *autoSaveCheck; QSpinBox *autoTime; QComboBox *langCombo; + QComboBox *labelCombo; QComboBox *unitCombo; QCheckBox *osOptionCheck; bool langChanged; bool unitChanged; + bool labelLangChanged; + QGroupBox *SaveGroup(); QGroupBox *LangGroup(); + void SetLabelComboBox(const QStringList &list); }; #endif // CONFIGURATIONPAGE_H diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index c2b67d9bb..90eaa2119 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -48,12 +48,13 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; + this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index 37da60097..7fea4abba 100644 --- a/src/app/dialogs/tools/dialogalongline.ui +++ b/src/app/dialogs/tools/dialogalongline.ui @@ -220,43 +220,6 @@ - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 2526aa7d4..edc00b560 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -49,12 +49,12 @@ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QW ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogbisector.ui b/src/app/dialogs/tools/dialogbisector.ui index 0172c1140..e004708ac 100644 --- a/src/app/dialogs/tools/dialogbisector.ui +++ b/src/app/dialogs/tools/dialogbisector.ui @@ -217,43 +217,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 599960f14..e681290de 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -33,6 +33,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoolcutarc.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -47,12 +48,12 @@ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidge ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxArcs(ui->comboBoxArc); diff --git a/src/app/dialogs/tools/dialogcutarc.ui b/src/app/dialogs/tools/dialogcutarc.ui index 7efe094bc..f13d05840 100644 --- a/src/app/dialogs/tools/dialogcutarc.ui +++ b/src/app/dialogs/tools/dialogcutarc.ui @@ -238,43 +238,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 985c1d512..13cd130c3 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -31,6 +31,7 @@ #include "../../geometry/vspline.h" #include "../../container/vcontainer.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -45,12 +46,12 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancel(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxSplines(ui->comboBoxSpline); diff --git a/src/app/dialogs/tools/dialogcutspline.ui b/src/app/dialogs/tools/dialogcutspline.ui index ea8f6e9b9..4e474569d 100644 --- a/src/app/dialogs/tools/dialogcutspline.ui +++ b/src/app/dialogs/tools/dialogcutspline.ui @@ -238,43 +238,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index 7448318a9..2d4acf4ae 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -31,6 +31,7 @@ #include "../../geometry/vsplinepath.h" #include "../../container/vcontainer.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -45,12 +46,12 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancel(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxSplinesPath(ui->comboBoxSplinePath); diff --git a/src/app/dialogs/tools/dialogcutsplinepath.ui b/src/app/dialogs/tools/dialogcutsplinepath.ui index 881de2939..3a1cb2a0f 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.ui +++ b/src/app/dialogs/tools/dialogcutsplinepath.ui @@ -238,43 +238,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index f1bc2253e..a6e281666 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -49,13 +49,13 @@ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWid ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); this->formulaBaseHeightAngle = ui->plainTextEditAngle->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxBasePoint); diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 49b0313da..cdee81112 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -423,43 +423,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index 5fb40d6b1..aa09f8012 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -46,9 +46,9 @@ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidge typeLine(QString()), basePointId(NULL_ID), p1LineId(NULL_ID), p2LineId(NULL_ID), line(nullptr) { ui->setupUi(this); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxBasePoint); diff --git a/src/app/dialogs/tools/dialogheight.ui b/src/app/dialogs/tools/dialogheight.ui index 006e1817b..5acad9cd7 100644 --- a/src/app/dialogs/tools/dialogheight.ui +++ b/src/app/dialogs/tools/dialogheight.ui @@ -31,43 +31,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 674eb5ac9..7b6ca9fed 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -33,6 +33,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoollineintersect.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -47,8 +48,8 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 & ui->setupUi(this); number = 0; InitOkCancelApply(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; - flagName = false; FillComboBoxPoints(ui->comboBoxP1Line1); FillComboBoxPoints(ui->comboBoxP2Line1); diff --git a/src/app/dialogs/tools/dialoglineintersect.ui b/src/app/dialogs/tools/dialoglineintersect.ui index 96d2bc764..53e5d3f89 100644 --- a/src/app/dialogs/tools/dialoglineintersect.ui +++ b/src/app/dialogs/tools/dialoglineintersect.ui @@ -31,43 +31,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index 72122f60f..e28916508 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -45,12 +45,12 @@ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidge ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialognormal.ui b/src/app/dialogs/tools/dialognormal.ui index 4ec34e02b..6ea7bf7f6 100644 --- a/src/app/dialogs/tools/dialognormal.ui +++ b/src/app/dialogs/tools/dialognormal.ui @@ -220,43 +220,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 207306b3c..6d39c8fac 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -32,6 +32,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoolpointofcontact.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -46,12 +47,12 @@ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogpointofcontact.ui b/src/app/dialogs/tools/dialogpointofcontact.ui index 30ed3122d..8098355be 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.ui +++ b/src/app/dialogs/tools/dialogpointofcontact.ui @@ -220,43 +220,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index 4dd2c5bd9..b38cc5884 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -33,6 +33,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoolpointofintersection.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -45,10 +46,10 @@ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, con firstPointId(NULL_ID), secondPointId(NULL_ID), line(nullptr) { ui->setupUi(this); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogpointofintersection.ui b/src/app/dialogs/tools/dialogpointofintersection.ui index db3a4c052..f31727a7c 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.ui +++ b/src/app/dialogs/tools/dialogpointofintersection.ui @@ -28,43 +28,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 2fbaf4b69..9ae01db84 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -49,12 +49,12 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 & ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxTypeLine(ui->comboBoxLineType); diff --git a/src/app/dialogs/tools/dialogshoulderpoint.ui b/src/app/dialogs/tools/dialogshoulderpoint.ui index 2696419e7..1325d9919 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.ui +++ b/src/app/dialogs/tools/dialogshoulderpoint.ui @@ -220,43 +220,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogsinglepoint.ui b/src/app/dialogs/tools/dialogsinglepoint.ui index 24aa830f2..aa0bcbc91 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.ui +++ b/src/app/dialogs/tools/dialogsinglepoint.ui @@ -73,43 +73,6 @@ 17 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index a4e4f0112..fb8a8f5b5 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -32,6 +32,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistooltriangle.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -44,10 +45,10 @@ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QW axisP2Id(NULL_ID), firstPointId(NULL_ID), secondPointId(NULL_ID), line (nullptr) { ui->setupUi(this); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxAxisP1); diff --git a/src/app/dialogs/tools/dialogtriangle.ui b/src/app/dialogs/tools/dialogtriangle.ui index 4ac997de3..b743f48f3 100644 --- a/src/app/dialogs/tools/dialogtriangle.ui +++ b/src/app/dialogs/tools/dialogtriangle.ui @@ -31,43 +31,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 3be346f08..bd4121e9e 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -105,6 +105,7 @@ MainWindow::MainWindow(QWidget *parent) connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile); connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI); connect(doc, &VPattern::CheckLayout, this, &MainWindow::Layout); + qApp->setCurrentDocument(doc); connect(qApp->getUndoStack(), &QUndoStack::cleanChanged, this, &MainWindow::PatternWasModified); @@ -194,7 +195,8 @@ void MainWindow::ActionNewPP() pattern->ClearGObjects(); //Create single point - const quint32 id = pattern->AddGObject(new VPointF(20+comboBoxDraws->count()*5, 20, "А", 5, 10)); + QString label = doc->GenerateLabel(LabelType::NewPatternPiece); + const quint32 id = pattern->AddGObject(new VPointF(30+comboBoxDraws->count()*5, 40, label, 5, 10)); VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Source::FromGui, patternPieceName, path); sceneDraw->addItem(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index ecd8e5c0f..f7399e2d8 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -58,7 +58,7 @@ VApplication::VApplication(int &argc, char **argv) guiTexts(QMap()), descriptions(QMap()), variables(QMap()), functions(QMap()), postfixOperators(QMap()), undoStack(nullptr), sceneView(nullptr), currentScene(nullptr), - autoSaveTimer(nullptr), mainWindow(nullptr), openingPattern(false), settings(nullptr) + autoSaveTimer(nullptr), mainWindow(nullptr), openingPattern(false), settings(nullptr), doc(nullptr) { undoStack = new QUndoStack(this); diff --git a/src/app/widgets/vapplication.h b/src/app/widgets/vapplication.h index 8cdbb5e11..a80b72fe5 100644 --- a/src/app/widgets/vapplication.h +++ b/src/app/widgets/vapplication.h @@ -38,6 +38,7 @@ class VApplication;// used in define class QUndoStack; class VMainGraphicsView; class VMainGraphicsScene; +class VPattern; #if defined(qApp) #undef qApp @@ -91,6 +92,9 @@ public: QSettings *getSettings(); VMainGraphicsScene *getCurrentScene() const; void setCurrentScene(VMainGraphicsScene *value); + + void setCurrentDocument(VPattern *doc); + VPattern *getCurrentDocument()const; private: Q_DISABLE_COPY(VApplication) Unit _patternUnit; @@ -121,6 +125,8 @@ private: * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. */ QSettings *settings; + + VPattern *doc; void InitLineWidth(); void InitMeasurements(); void InitVariables(); @@ -197,4 +203,17 @@ inline void VApplication::setAutoSaveTimer(QTimer *value) autoSaveTimer = value; } +//--------------------------------------------------------------------------------------------------------------------- +inline void VApplication::setCurrentDocument(VPattern *doc) +{ + this->doc = doc; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline VPattern *VApplication::getCurrentDocument() const +{ + SCASSERT(doc != nullptr) + return doc; +} + #endif // VAPPLICATION_H diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index bbab2102d..f0fb41f94 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -45,6 +45,7 @@ #include #include +#include const QString VPattern::TagPattern = QStringLiteral("pattern"); const QString VPattern::TagCalculation = QStringLiteral("calculation"); @@ -1619,6 +1620,68 @@ void VPattern::CheckTagExists(const QString &tag) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GetLabelBase(unsigned int index) const +{ + QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" + defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" + QString checkedLocale = qApp->getSettings()->value("configuration/label_language", defaultLocale).toString(); + + QStringList list{"de", "en" , "fr" , "ru" , "uk"}; + + QStringList alphabet; + switch(list.indexOf(checkedLocale)) + { + case 0: // de + { + QString al = QStringLiteral("A,Ä,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Ö,P,Q,R,S,ß,T,U,Ü,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + case 1: // en + { + QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + case 2: // fr + { + QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + case 3: // ru + { + QString al = QStringLiteral("А,Б,В,Г,Д,Е,Ж,З,И,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Э,Ю,Я"); + alphabet = al.split(","); + break; + } + case 4: // uk + { + QString al = QStringLiteral("А,Б,В,Г,Д,Е,Ж,З,І,Ї,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Є,Ю,Я"); + alphabet = al.split(","); + break; + } + default: // en + { + QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + } + + QString base; + int count = qFloor(index/alphabet.size()); + int number = index - alphabet.size() * count; + int i = 0; + do + { + base.append(alphabet.at(number)); + ++i; + } while (i < count); + return base; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseSplineElement parse spline tag. @@ -2280,6 +2343,66 @@ void VPattern::SetVersion() emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GenerateLabel(const LabelType &type) const +{ + QDomNodeList drawList = elementsByTagName(TagDraw); + + if (type == LabelType::NewPatternPiece) + { + QString name; + int i = 0; + for(;;) + { + name = GetLabelBase(drawList.size() + i); + if (data->IsUnique(name)) + { + return name; + } + if (i == INT_MAX) + { + break; + } + ++i; + } + return name; + } + else if (type == LabelType::NewLabel) + { + if (drawList.isEmpty()) + { + return GetLabelBase(0); + } + + int index = 0; + for (int i = 0; i < drawList.size(); ++i) + { + QDomElement node = drawList.at(i).toElement(); + if (node.attribute(AttrName) == nameActivPP) + { + index = i; + break; + } + } + + QString labelBase = GetLabelBase(index); + + qint32 num = 1; + QString name; + do + { + name = QString("%1%2").arg(labelBase).arg(num); + num++; + if (num == INT_MAX) + { + break; + } + } while (data->IsUnique(name) == false); + return name; + } + return QString(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique. diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 1a264244c..d2e76a447 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -36,6 +36,7 @@ class VDataTool; class VMainGraphicsScene; enum class Document : char { LiteParse, LitePPParse, FullParse }; +enum class LabelType : char {NewPatternPiece, NewLabel}; /* VAL_VERSION is (major << 16) + (minor << 8) + patch. @@ -179,6 +180,8 @@ public: QString GetVersion() const; void SetVersion(); + + QString GenerateLabel(const LabelType &type)const; signals: /** * @brief ChangedActivDraw change active pattern peace. @@ -280,6 +283,7 @@ private: QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; void ParseCurrentPP(); void CheckTagExists(const QString &tag); + QString GetLabelBase(unsigned int index)const; }; //--------------------------------------------------------------------------------------------------------------------- From 5837ad186644bd33469c2ce45c958d75e24d66f7 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 5 Sep 2014 11:35:32 +0300 Subject: [PATCH 45/52] Show options base point of new pattern piece after creation. --HG-- branch : feature --- src/app/mainwindow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index bd4121e9e..d07ce9f11 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -195,10 +195,12 @@ void MainWindow::ActionNewPP() pattern->ClearGObjects(); //Create single point + ui->view->itemClicked(nullptr);//hide options previous tool QString label = doc->GenerateLabel(LabelType::NewPatternPiece); const quint32 id = pattern->AddGObject(new VPointF(30+comboBoxDraws->count()*5, 40, label, 5, 10)); VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Source::FromGui, patternPieceName, path); sceneDraw->addItem(spoint); + ui->view->itemClicked(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); QHash* tools = doc->getTools(); From afbc8d8c30df277fdc381ad0a4f10b6f55808068 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 5 Sep 2014 11:46:07 +0300 Subject: [PATCH 46/52] Update .hgignore file. --HG-- branch : feature --- .hgignore | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/.hgignore b/.hgignore index 8f850c89e..305d6889b 100644 --- a/.hgignore +++ b/.hgignore @@ -26,19 +26,61 @@ uic/ rcc/ man/ -#Ignore Coverity Scan Build Tool +# Ignore Coverity Scan Build Tool cov-int/ -# Ignore file used QtCreator for user profile. -*.pro.user +# Compiled Object files +*.slo +*.lo +*.o +*.obj -# Ignore file Qt translation. +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Qt-es +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.moc +moc_*.cpp +qrc_*.cpp +ui_*.h +Makefile* +*-build-* + +# Ignore Qt translation file . *.qm +# QtCreator +*.autosave + # Ignore Mercurial .orig files *.orig *.rej -# Ignore Makefile -Makefile +# QtCtreator Qml +*.qmlproject.user +*.qmlproject.user.* From 6c784fcdca78917b520672f06ef278179f5dc49f Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 6 Sep 2014 11:14:59 +0300 Subject: [PATCH 47/52] Check unique label name in dialog. Fixed catch broken expression. --HG-- branch : feature --- src/app/container/calculator.cpp | 19 +++++++++++++------ src/app/container/calculator.h | 2 +- src/app/dialogs/tools/dialogalongline.cpp | 2 +- src/app/dialogs/tools/dialogalongline.h | 3 --- src/app/dialogs/tools/dialogbisector.cpp | 2 +- src/app/dialogs/tools/dialogbisector.h | 3 --- src/app/dialogs/tools/dialogcutarc.cpp | 2 +- src/app/dialogs/tools/dialogcutarc.h | 3 --- src/app/dialogs/tools/dialogcutspline.cpp | 2 +- src/app/dialogs/tools/dialogcutspline.h | 3 --- src/app/dialogs/tools/dialogcutsplinepath.cpp | 2 +- src/app/dialogs/tools/dialogcutsplinepath.h | 3 --- src/app/dialogs/tools/dialogendline.cpp | 2 +- src/app/dialogs/tools/dialogendline.h | 3 --- src/app/dialogs/tools/dialogheight.cpp | 2 +- src/app/dialogs/tools/dialogheight.h | 3 --- src/app/dialogs/tools/dialoglineintersect.cpp | 2 +- src/app/dialogs/tools/dialoglineintersect.h | 3 --- src/app/dialogs/tools/dialognormal.cpp | 2 +- src/app/dialogs/tools/dialognormal.h | 3 --- .../dialogs/tools/dialogpointofcontact.cpp | 2 +- src/app/dialogs/tools/dialogpointofcontact.h | 3 --- .../tools/dialogpointofintersection.cpp | 2 +- .../dialogs/tools/dialogpointofintersection.h | 3 --- src/app/dialogs/tools/dialogshoulderpoint.cpp | 2 +- src/app/dialogs/tools/dialogshoulderpoint.h | 3 --- src/app/dialogs/tools/dialogtool.cpp | 6 ++++-- src/app/dialogs/tools/dialogtool.h | 3 +++ src/app/dialogs/tools/dialogtriangle.cpp | 2 +- src/app/dialogs/tools/dialogtriangle.h | 3 --- src/app/xml/vpattern.cpp | 3 ++- 31 files changed, 36 insertions(+), 62 deletions(-) diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 87bdd1f8d..adcafbdc0 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -139,15 +139,12 @@ qreal Calculator::EvalFormula(const QString &formula) } // Add variables - InitVariables(data, tokens); - - result = Eval(); - - return result; + InitVariables(data, tokens, formula); + return Eval(); } //--------------------------------------------------------------------------------------------------------------------- -void Calculator::InitVariables(const VContainer *data, const QMap &tokens) +void Calculator::InitVariables(const VContainer *data, const QMap &tokens, const QString &formula) { if (qApp->patternType() == MeasurementsType::Standard) { @@ -156,9 +153,11 @@ void Calculator::InitVariables(const VContainer *data, const QMap const QHash > *vars = data->DataVariables(); + bool found = false; QMap::const_iterator i = tokens.constBegin(); while (i != tokens.constEnd()) { + found = false; if (vars->contains(i.value())) { QSharedPointer var = vars->value(i.value()); @@ -169,6 +168,7 @@ void Calculator::InitVariables(const VContainer *data, const QMap m->SetValue(data->size(), data->height()); } DefineVar(i.value(), var->GetValue()); + found = true; } if (qApp->patternType() == MeasurementsType::Standard) @@ -177,14 +177,21 @@ void Calculator::InitVariables(const VContainer *data, const QMap { vVarVal[0] = data->size(); DefineVar(data->SizeName(), &vVarVal[0]); + found = true; } if (i.value() == data->HeightName()) { vVarVal[1] = data->height(); DefineVar(data->HeightName(), &vVarVal[1]); + found = true; } } + + if (found == false) + { + throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN , i.value(), formula, i.key()); + } ++i; } } diff --git a/src/app/container/calculator.h b/src/app/container/calculator.h index 22ec079f3..c0c11b090 100644 --- a/src/app/container/calculator.h +++ b/src/app/container/calculator.h @@ -64,7 +64,7 @@ private: qreal *vVarVal; static int iVal; const VContainer *data; - void InitVariables(const VContainer *data, const QMap &tokens); + void InitVariables(const VContainer *data, const QMap &tokens, const QString &formula); void InitCharacterSets(); static qreal* AddVariable(const QString &a_szName, void *a_pUserData); }; diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 90eaa2119..3ccc55d5a 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -41,7 +41,7 @@ * @param parent parent widget */ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0), typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr) { diff --git a/src/app/dialogs/tools/dialogalongline.h b/src/app/dialogs/tools/dialogalongline.h index 4eeb9265a..335ffd22a 100644 --- a/src/app/dialogs/tools/dialogalongline.h +++ b/src/app/dialogs/tools/dialogalongline.h @@ -87,9 +87,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index edc00b560..8b8c5ec0f 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), thirdPointId(NULL_ID), formulaBaseHeight(0), line(nullptr), prepare(false) { diff --git a/src/app/dialogs/tools/dialogbisector.h b/src/app/dialogs/tools/dialogbisector.h index 12fbdfacf..6a0816a45 100644 --- a/src/app/dialogs/tools/dialogbisector.h +++ b/src/app/dialogs/tools/dialogbisector.h @@ -92,9 +92,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index e681290de..312354b2c 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent) - : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), + : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), formula(QString()), arcId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogcutarc.h b/src/app/dialogs/tools/dialogcutarc.h index a01f5c1e5..a320b7e37 100644 --- a/src/app/dialogs/tools/dialogcutarc.h +++ b/src/app/dialogs/tools/dialogcutarc.h @@ -78,9 +78,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutArc *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 13cd130c3..0e96cecd7 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -40,7 +40,7 @@ * @param parent parent widget */ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()), splineId(NULL_ID), formulaBaseHeight(0) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogcutspline.h b/src/app/dialogs/tools/dialogcutspline.h index 11833bd25..c541cb58a 100644 --- a/src/app/dialogs/tools/dialogcutspline.h +++ b/src/app/dialogs/tools/dialogcutspline.h @@ -71,9 +71,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutSpline *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index 2d4acf4ae..c6ad759b1 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -40,7 +40,7 @@ * @param parent parent widget */ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), pointName(QString()), formula(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()), splinePathId(NULL_ID), formulaBaseHeight(0) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogcutsplinepath.h b/src/app/dialogs/tools/dialogcutsplinepath.h index a6676629a..46d299379 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.h +++ b/src/app/dialogs/tools/dialogcutsplinepath.h @@ -71,9 +71,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutSplinePath *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index a6e281666..e1009d46a 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), typeLine(QString()), formulaLength(QString()), formulaAngle(QString()), basePointId(NULL_ID), formulaBaseHeight(0), formulaBaseHeightAngle(0), line(nullptr) { diff --git a/src/app/dialogs/tools/dialogendline.h b/src/app/dialogs/tools/dialogendline.h index b0a9eed1c..6fa3ebfc4 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -89,9 +89,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogEndLine *ui; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index aa09f8012..020c12a7b 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0), typeLine(QString()), basePointId(NULL_ID), p1LineId(NULL_ID), p2LineId(NULL_ID), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogheight.h b/src/app/dialogs/tools/dialogheight.h index 8d4c33f01..8c384b145 100644 --- a/src/app/dialogs/tools/dialogheight.h +++ b/src/app/dialogs/tools/dialogheight.h @@ -81,9 +81,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 7b6ca9fed..4de620302 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0), p1Line1(NULL_ID), p2Line1(NULL_ID), p1Line2(NULL_ID), p2Line2(NULL_ID), flagPoint(true), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialoglineintersect.h b/src/app/dialogs/tools/dialoglineintersect.h index 474261208..93f686f73 100644 --- a/src/app/dialogs/tools/dialoglineintersect.h +++ b/src/app/dialogs/tools/dialoglineintersect.h @@ -85,9 +85,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief p1Line1 id first point of first line */ quint32 p1Line1; diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index e28916508..01dd8bdde 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -39,7 +39,7 @@ * @param parent parent widget */ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), typeLine(QString()), formula(QString()), angle(0), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialognormal.h b/src/app/dialogs/tools/dialognormal.h index 4c52ad887..222ced37b 100644 --- a/src/app/dialogs/tools/dialognormal.h +++ b/src/app/dialogs/tools/dialognormal.h @@ -91,9 +91,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 6d39c8fac..a4f6331c8 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -41,7 +41,7 @@ * @param parent parent widget */ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), radius(QString()), center(NULL_ID), firstPoint(NULL_ID), secondPoint(NULL_ID), formulaBaseHeight(0), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogpointofcontact.h b/src/app/dialogs/tools/dialogpointofcontact.h index 5887ec95a..11fd4ed7a 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.h +++ b/src/app/dialogs/tools/dialogpointofcontact.h @@ -89,9 +89,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief radius radius of arc */ QString radius; diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index b38cc5884..0788a791c 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), firstPointId(NULL_ID), secondPointId(NULL_ID), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogpointofintersection.h b/src/app/dialogs/tools/dialogpointofintersection.h index ef1074baf..00fb7648b 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.h +++ b/src/app/dialogs/tools/dialogpointofintersection.h @@ -75,9 +75,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief firstPointId id first point of line */ quint32 firstPointId; diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 9ae01db84..eed3962de 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0), typeLine(QString()), formula(QString()), p1Line(NULL_ID), p2Line(NULL_ID), pShoulder(NULL_ID), formulaBaseHeight(0), line (nullptr) { diff --git a/src/app/dialogs/tools/dialogshoulderpoint.h b/src/app/dialogs/tools/dialogshoulderpoint.h index 192cd7387..f4e09d955 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.h +++ b/src/app/dialogs/tools/dialogshoulderpoint.h @@ -91,9 +91,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 444fec323..686ec0752 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -63,7 +63,8 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), radioButtonLengthCurve(nullptr), radioButtonAngleLine(nullptr), lineStyles(VAbstractTool::Styles()), - okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false) + okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false), + pointName(QString()) { SCASSERT(data != nullptr); timerFormula = new QTimer(this); @@ -659,7 +660,8 @@ void DialogTool::NamePointChanged() if (edit) { QString name = edit->text(); - if (name.isEmpty() || name.contains(" ")) + name.replace(" ", ""); + if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false)) { flagName = false; ChangeColor(labelEditNamePoint, Qt::red); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 5d2ab7950..659cc7069 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -200,6 +200,9 @@ protected: /** @brief prepare show if we prepare. Show dialog after finish working with visual part of tool*/ bool prepare; + /** @brief pointName name of point */ + QString pointName; + virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); void FillComboBoxPoints(QComboBox *box)const; diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index fb8a8f5b5..065b03093 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -41,7 +41,7 @@ * @param parent parent widget */ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), pointName(QString()), axisP1Id(NULL_ID), + :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), axisP1Id(NULL_ID), axisP2Id(NULL_ID), firstPointId(NULL_ID), secondPointId(NULL_ID), line (nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogtriangle.h b/src/app/dialogs/tools/dialogtriangle.h index 5c0828e1e..51c2e52b7 100644 --- a/src/app/dialogs/tools/dialogtriangle.h +++ b/src/app/dialogs/tools/dialogtriangle.h @@ -80,9 +80,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief axisP1Id id first point of axis */ quint32 axisP1Id; diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index f0fb41f94..58f901c37 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1139,7 +1139,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem //Rewrite attribute formula. Need for situation when we have wrong formula. if (f != formula || angleFix != angle) { - SetAttribute(domElement, VAbstractTool::AttrRadius, f); + SetAttribute(domElement, VAbstractTool::AttrLength, f); SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix); haveLiteChange(); } @@ -2452,6 +2452,7 @@ void VPattern::PrepareForParse(const Document &parse) else if (parse == Document::LiteParse) { data->ClearUniqueNames(); + data->ClearVariables(); } } From f6d3068d0ffb71cfecb8b7be3950aeef23553649 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 6 Sep 2014 11:38:30 +0300 Subject: [PATCH 48/52] Show in tooltip parser error message. --HG-- branch : feature --- src/app/dialogs/tools/dialogendline.ui | 2 +- src/app/dialogs/tools/dialogtool.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index cdee81112..e541832af 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -323,7 +323,7 @@ - Value of length + Value of angle _ diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 686ec0752..f3c2e443f 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -429,6 +429,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la flag = false; ChangeColor(labelEditFormula, Qt::red); label->setText(tr("Error")); + label->setToolTip(tr("Empty field")); } else { @@ -448,6 +449,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la flag = false; ChangeColor(labelEditFormula, Qt::red); label->setText(tr("Error")); + label->setToolTip(tr("Value can't be 0")); } else { @@ -463,6 +465,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la label->setText(loc.toString(result) + postfix); flag = true; ChangeColor(labelEditFormula, okColor); + label->setToolTip(tr("Value")); emit ToolTip(""); } } @@ -472,6 +475,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la flag = false; ChangeColor(labelEditFormula, Qt::red); emit ToolTip("Parser error: "+e.GetMsg()); + label->setToolTip("Parser error: "+e.GetMsg()); qDebug() << "\nMath parser error:\n" << "--------------------------------------\n" << "Message: " << e.GetMsg() << "\n" From d2e5be50b4346f3f770cf63223dd32337f773ac2 Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 6 Sep 2014 11:51:46 +0300 Subject: [PATCH 49/52] Show curve foot if only is selected. --HG-- branch : feature --- src/app/tools/drawTools/vabstractspline.cpp | 9 +++++++++ src/app/tools/drawTools/vabstractspline.h | 1 + src/app/tools/drawTools/vtoolspline.cpp | 3 +++ 3 files changed, 13 insertions(+) diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index 108194901..305eb11d9 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -217,3 +217,12 @@ QPainterPath VAbstractSpline::ToolPath(PathDirection direction) const path.setFillRule( Qt::WindingFill ); return path; } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::ShowFoot(bool show) +{ + for (int i = 0; i < controlPoints.size(); ++i) + { + controlPoints.at(i)->setVisible(show); + } +} diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index 810dd1c2a..f366384de 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -81,6 +81,7 @@ protected: virtual void keyReleaseEvent(QKeyEvent * event); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const; + void ShowFoot(bool show); }; #endif // VABSTRACTSPLINE_H diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 1b4ebd96b..983f37bb0 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -72,6 +72,8 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Sour connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint2); + ShowFoot(false); + if (typeCreation == Source::FromGui) { AddToFile(); @@ -242,6 +244,7 @@ void VToolSpline::ShowVisualization(bool show) delete vis; vis = nullptr; } + ShowFoot(show); } //--------------------------------------------------------------------------------------------------------------------- From 2a4eef76958bbca5a386f6b9a8ec4b383845b42c Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 6 Sep 2014 15:47:25 +0300 Subject: [PATCH 50/52] Visualization for VToolCutSpline. --HG-- branch : feature --- src/app/dialogs/tools/dialogcutspline.cpp | 28 +++++++- src/app/dialogs/tools/dialogcutspline.h | 5 ++ src/app/dialogs/tools/dialogcutspline.ui | 2 +- src/app/geometry/vspline.cpp | 14 ++++ src/app/geometry/vspline.h | 1 + src/app/mainwindow.cpp | 6 +- src/app/options.h | 5 +- src/app/tools/drawTools/vabstractspline.h | 2 +- src/app/tools/drawTools/vtoolcutspline.cpp | 67 +++++++++++-------- src/app/visualization/vistoolcutspline.cpp | 76 ++++++++++++++++++++++ src/app/visualization/vistoolcutspline.h | 53 +++++++++++++++ src/app/visualization/visualization.pri | 6 +- 12 files changed, 230 insertions(+), 35 deletions(-) create mode 100644 src/app/visualization/vistoolcutspline.cpp create mode 100644 src/app/visualization/vistoolcutspline.h diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 0e96cecd7..c99c3338c 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -32,6 +32,7 @@ #include "../../geometry/vspline.h" #include "../../container/vcontainer.h" #include "../../xml/vpattern.h" +#include "../../visualization/vistoolcutspline.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -41,7 +42,7 @@ */ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()), - splineId(NULL_ID), formulaBaseHeight(0) + splineId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); InitVariables(ui); @@ -50,7 +51,7 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; CheckState(); @@ -62,11 +63,14 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSpline::FormulaChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit); + + path = new VisToolCutSpline(data); } //--------------------------------------------------------------------------------------------------------------------- DialogCutSpline::~DialogCutSpline() { + delete path; delete ui; } @@ -96,6 +100,7 @@ void DialogCutSpline::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + path->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -106,6 +111,7 @@ void DialogCutSpline::setFormula(const QString &value) void DialogCutSpline::setSplineId(const quint32 &value) { setCurrentSplineId(ui->comboBoxSpline, splineId, value, ComboBoxCutSpline::CutSpline); + path->setPoint1Id(splineId); } //--------------------------------------------------------------------------------------------------------------------- @@ -122,6 +128,8 @@ void DialogCutSpline::ChosenObject(quint32 id, const SceneObject &type) { if (SetObject(id, ui->comboBoxSpline, "")) { + path->VisualMode(id); + prepare = true; this->setModal(true); this->show(); } @@ -136,6 +144,10 @@ void DialogCutSpline::SaveData() formula = ui->plainTextEditFormula->toPlainText(); formula.replace("\n", " "); splineId = getCurrentObjectId(ui->comboBoxSpline); + + path->setPoint1Id(splineId); + path->setLength(formula); + path->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -143,3 +155,15 @@ void DialogCutSpline::DeployFormulaTextEdit() { DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSpline::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); + scene->addItem(path); + path->RefreshGeometry(); + } +} diff --git a/src/app/dialogs/tools/dialogcutspline.h b/src/app/dialogs/tools/dialogcutspline.h index c541cb58a..257324c54 100644 --- a/src/app/dialogs/tools/dialogcutspline.h +++ b/src/app/dialogs/tools/dialogcutspline.h @@ -36,6 +36,8 @@ namespace Ui class DialogCutSpline; } +class VisToolCutSpline; + /** * @brief The DialogCutSpline class dialog for ToolCutSpline. */ @@ -61,6 +63,7 @@ public slots: */ void DeployFormulaTextEdit(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -79,6 +82,8 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + VisToolCutSpline *path; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutspline.ui b/src/app/dialogs/tools/dialogcutspline.ui index 4e474569d..c17f5f0c5 100644 --- a/src/app/dialogs/tools/dialogcutspline.ui +++ b/src/app/dialogs/tools/dialogcutspline.ui @@ -392,7 +392,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/geometry/vspline.cpp b/src/app/geometry/vspline.cpp index 978ceec63..ec695751a 100644 --- a/src/app/geometry/vspline.cpp +++ b/src/app/geometry/vspline.cpp @@ -241,6 +241,20 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo return p1234; } +//--------------------------------------------------------------------------------------------------------------------- +QPointF VSpline::CutSpline(qreal length, VSpline &spl1, VSpline &spl2) const +{ + QPointF spl1p2; + QPointF spl1p3; + QPointF spl2p2; + QPointF spl2p3; + QPointF cutPoint = CutSpline (length, spl1p2, spl1p3, spl2p2, spl2p3 ); + + spl1 = VSpline(GetP1(), spl1p2, spl1p3, cutPoint, GetKcurve()); + spl2 = VSpline(cutPoint, spl2p2, spl2p3, GetP4(), GetKcurve()); + return cutPoint; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetPoints return list with spline points. diff --git a/src/app/geometry/vspline.h b/src/app/geometry/vspline.h index c70a84b03..cf57a0fe1 100644 --- a/src/app/geometry/vspline.h +++ b/src/app/geometry/vspline.h @@ -68,6 +68,7 @@ public: QLineF::IntersectType CrossingSplLine(const QLineF &line, QPointF *intersectionPoint ) const; qreal LengthT(qreal t) const; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; + QPointF CutSpline ( qreal length, VSpline &spl1, VSpline &spl2) const; QVector GetPoints () const; // cppcheck-suppress unusedFunction static QVector SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index d07ce9f11..cbbdd3ba5 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -497,8 +497,10 @@ void MainWindow::ToolSpline(bool checked) */ void MainWindow::ToolCutSpline(bool checked) { - SetToolButton(checked, Tool::CutSpline, ":/cursor/spline_cut_point_cursor.png", - tr("Select simple curve"), &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::CutSpline, ":/cursor/spline_cut_point_cursor.png", + tr("Select simple curve"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/options.h b/src/app/options.h index b12d19129..cf4c82516 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -99,7 +99,10 @@ enum class Vis : unsigned char ToolPointOfIntersection, ToolShoulderPoint, ToolSpline, - ToolTriangle + ToolTriangle, + ToolCutSpline, + ToolSplinePath, + ToolCutSplinePath }; enum class Source : char { FromGui, FromFile, FromTool }; diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index f366384de..96ac5d289 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -43,6 +43,7 @@ public: virtual int type() const {return Type;} enum { Type = UserType + static_cast(Tool::AbstractSpline)}; virtual QString getTagName() const; + void ShowFoot(bool show); public slots: virtual void FullUpdateFromFile (); void Disable(bool disable); @@ -81,7 +82,6 @@ protected: virtual void keyReleaseEvent(QKeyEvent * event); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); QPainterPath ToolPath(PathDirection direction = PathDirection::Hide) const; - void ShowFoot(bool show); }; #endif // VABSTRACTSPLINE_H diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 2231cbc64..1af6dbb10 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -30,6 +30,8 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogcutspline.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolcutspline.h" +#include "vabstractspline.h" #include @@ -190,33 +192,38 @@ VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointNa //--------------------------------------------------------------------------------------------------------------------- void VToolCutSpline::ShowVisualization(bool show) { -// if (show) -// { -// if (vis == nullptr) -// { -// VisTool * visual = new VisTool(getData()); -// VMainGraphicsScene *scene = qApp->getCurrentScene(); -// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); -// scene->addItem(visual); + if (show) + { + if (vis == nullptr) + { + VisToolCutSpline * visual = new VisToolCutSpline(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); -// // add options -// visual->RefreshGeometry(); -// vis = visual; -// } -// else -// { -// VisTool * visual = qobject_cast(vis); -// if (visual != nullptr) -// { -// visual->show(); -// } -// } -// } -// else -// { -// delete vis; -// vis = nullptr; -// } + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolCutSpline * visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + if (VAbstractSpline *parentCurve = qobject_cast(doc->getTool(curveCutId))) + { + parentCurve->ShowFoot(show); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -226,6 +233,14 @@ void VToolCutSpline::ShowVisualization(bool show) void VToolCutSpline::FullUpdateFromFile() { FullUpdateCurveFromFile(AttrSpline); + + if (vis != nullptr) + { + VisToolCutSpline *visual = qobject_cast(vis); + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolcutspline.cpp b/src/app/visualization/vistoolcutspline.cpp new file mode 100644 index 000000000..6d41865fa --- /dev/null +++ b/src/app/visualization/vistoolcutspline.cpp @@ -0,0 +1,76 @@ +/************************************************************************ + ** + ** @file vistoolcutspline.cpp + ** @author Roman Telezhynskyi + ** @date 6 9, 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 . + ** + *************************************************************************/ + +#include "vistoolcutspline.h" +#include "../geometry/vspline.h" +#include "../container/vcontainer.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSpline::VisToolCutSpline(const VContainer *data, QGraphicsItem *parent) + :VisPath(data, parent), point(nullptr), spl1(nullptr), spl2(nullptr), length(0) +{ + spl1 = InitItem(Qt::darkGreen, this); + spl1->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + spl2 = InitItem(Qt::darkRed, this); + spl2->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + + point = InitPoint(mainColor, this); + point->setZValue(2); + point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSpline::~VisToolCutSpline() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSpline::RefreshGeometry() +{ + if (point1Id > 0) + { + const QSharedPointer spl = Visualization::data->GeometricObject(point1Id); + DrawPath(this, spl->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + VSpline sp1; + VSpline sp2; + QPointF p = spl->CutSpline(length, sp1, sp2); + DrawPoint(point, p, mainColor); + + DrawPath(spl1, sp1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(spl2, sp2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSpline::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vistoolcutspline.h b/src/app/visualization/vistoolcutspline.h new file mode 100644 index 000000000..5967f3ba5 --- /dev/null +++ b/src/app/visualization/vistoolcutspline.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file vistoolcutspline.h + ** @author Roman Telezhynskyi + ** @date 6 9, 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 VISTOOLCUTSPLINE_H +#define VISTOOLCUTSPLINE_H + +#include "vispath.h" + +class VisToolCutSpline : public VisPath +{ + Q_OBJECT +public: + VisToolCutSpline(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolCutSpline(); + + virtual void RefreshGeometry(); + void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCutSpline)}; +protected: + Q_DISABLE_COPY(VisToolCutSpline) + QGraphicsEllipseItem *point; + QGraphicsPathItem *spl1; + QGraphicsPathItem *spl2; + qreal length; +}; + +#endif // VISTOOLCUTSPLINE_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index f811878f2..996302879 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -18,7 +18,8 @@ HEADERS += \ visualization/vistoolarc.h \ visualization/vispath.h \ visualization/vistoolcutarc.h \ - visualization/vistoolspline.h + visualization/vistoolspline.h \ + visualization/vistoolcutspline.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -40,4 +41,5 @@ SOURCES += \ visualization/vistoolarc.cpp \ visualization/vispath.cpp \ visualization/vistoolcutarc.cpp \ - visualization/vistoolspline.cpp + visualization/vistoolspline.cpp \ + visualization/vistoolcutspline.cpp From e75ed95561d8c872cc169fb33ee5cfa67b69c1e5 Mon Sep 17 00:00:00 2001 From: dismine Date: Sun, 7 Sep 2014 19:51:22 +0300 Subject: [PATCH 51/52] Visualization for VToolSplinePath. --HG-- branch : feature --- src/app/dialogs/tools/dialogsplinepath.cpp | 80 ++++++++++-- src/app/dialogs/tools/dialogsplinepath.h | 8 ++ src/app/dialogs/tools/dialogsplinepath.ui | 2 +- src/app/main.cpp | 6 +- src/app/mainwindow.cpp | 6 +- src/app/tools/drawTools/vtoolsplinepath.cpp | 68 +++++++---- src/app/visualization/vistoolsplinepath.cpp | 127 ++++++++++++++++++++ src/app/visualization/vistoolsplinepath.h | 67 +++++++++++ src/app/visualization/visualization.pri | 6 +- 9 files changed, 325 insertions(+), 45 deletions(-) create mode 100644 src/app/visualization/vistoolsplinepath.cpp create mode 100644 src/app/visualization/vistoolsplinepath.h diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index 833737387..7a05b4c45 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -30,6 +30,7 @@ #include "ui_dialogsplinepath.h" #include "../../geometry/vsplinepoint.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistoolsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -38,10 +39,10 @@ * @param parent parent widget */ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) + :DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()), visPath(nullptr) { ui->setupUi(this); - InitOkCancel(ui); + InitOkCancelApply(ui); bOk->setEnabled(false); FillComboBoxPoints(ui->comboBoxPoint); @@ -57,11 +58,14 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId this, &DialogSplinePath::KAsm1Changed); connect(ui->doubleSpinBoxKasm2, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::KAsm2Changed); + + visPath = new VisToolSplinePath(data); } //--------------------------------------------------------------------------------------------------------------------- DialogSplinePath::~DialogSplinePath() { + delete visPath; delete ui; } @@ -73,6 +77,7 @@ DialogSplinePath::~DialogSplinePath() void DialogSplinePath::SetPath(const VSplinePath &value) { this->path = value; + ui->listWidget->blockSignals(true); ui->listWidget->clear(); for (qint32 i = 0; i < path.CountPoint(); ++i) { @@ -80,6 +85,9 @@ void DialogSplinePath::SetPath(const VSplinePath &value) } ui->listWidget->setFocus(Qt::OtherFocusReason); ui->doubleSpinBoxKcurve->setValue(path.getKCurve()); + + visPath->setPath(path); + ui->listWidget->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -94,20 +102,29 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type) { NewItem(id, 1, 0, 1, 180); emit ToolTip(tr("Select point of curve path")); - this->show(); + + SavePath(); + visPath->setPath(path); + if (path.CountPoint() == 1) + { + visPath->VisualMode(NULL_ID); + connect(visPath, &VisToolSplinePath::ToolTip, this, &DialogTool::ShowVisToolTip); + connect(visPath, &VisToolSplinePath::PathChanged, this, &DialogSplinePath::PathUpdated); + } + else + { + visPath->RefreshGeometry(); + } } } //--------------------------------------------------------------------------------------------------------------------- void DialogSplinePath::SaveData() { - path.Clear(); - for (qint32 i = 0; i < ui->listWidget->count(); ++i) - { - QListWidgetItem *item = ui->listWidget->item(i); - path.append( qvariant_cast(item->data(Qt::UserRole))); - } - path.setKCurve(ui->doubleSpinBoxKcurve->value()); + SavePath(); + + visPath->setPath(path); + visPath->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -214,6 +231,35 @@ void DialogSplinePath::UpdateList() */ } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::ShowDialog(bool click) +{ + if (click == false) + { + emit ToolTip(""); + DialogAccepted(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::PathUpdated(const VSplinePath &path) +{ + SetPath(path); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor); + scene->addItem(visPath); + visPath->setMode(Mode::Show); + visPath->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewItem add point to list @@ -228,7 +274,7 @@ void DialogSplinePath::NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm const QSharedPointer point = data->GeometricObject(id); QListWidgetItem *item = new QListWidgetItem(point->name()); item->setFont(QFont("Times", 12, QFont::Bold)); - VSplinePoint p(*point, kAsm1, angle1, kAsm2, angle2); + VSplinePoint p(*point.data(), kAsm1, angle1, kAsm2, angle2); DataPoint(point->id(), kAsm1, angle1, kAsm2, angle2); item->setData(Qt::UserRole, QVariant::fromValue(p)); ui->listWidget->addItem(item); @@ -295,3 +341,15 @@ void DialogSplinePath::EnableFields() return; } } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::SavePath() +{ + path.Clear(); + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + QListWidgetItem *item = ui->listWidget->item(i); + path.append( qvariant_cast(item->data(Qt::UserRole))); + } + path.setKCurve(ui->doubleSpinBoxKcurve->value()); +} diff --git a/src/app/dialogs/tools/dialogsplinepath.h b/src/app/dialogs/tools/dialogsplinepath.h index 52c5356f8..4316ddefd 100644 --- a/src/app/dialogs/tools/dialogsplinepath.h +++ b/src/app/dialogs/tools/dialogsplinepath.h @@ -37,6 +37,8 @@ namespace Ui class DialogSplinePath; } +class VisToolSplinePath; + /** * @brief The DialogSplinePath class dialog for ToolSplinePath. Help create spline path and edit option. */ @@ -58,7 +60,10 @@ public slots: void KAsm1Changed(qreal d); void KAsm2Changed(qreal d); virtual void UpdateList(); + virtual void ShowDialog(bool click); + void PathUpdated(const VSplinePath &path); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -72,9 +77,12 @@ private: /** @brief path spline path */ VSplinePath path; + VisToolSplinePath *visPath; + void NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void EnableFields(); + void SavePath(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogsplinepath.ui b/src/app/dialogs/tools/dialogsplinepath.ui index 22ce120d6..e620b6de0 100644 --- a/src/app/dialogs/tools/dialogsplinepath.ui +++ b/src/app/dialogs/tools/dialogsplinepath.ui @@ -191,7 +191,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/main.cpp b/src/app/main.cpp index ccb002022..0f628032c 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -80,21 +80,21 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con case QtWarningMsg: messageBox.setIcon(QMessageBox::Warning); messageBox.setInformativeText(msg); - messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + messageBox.setStandardButtons(QMessageBox::Ok); fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtCriticalMsg: messageBox.setIcon(QMessageBox::Critical); messageBox.setInformativeText(msg); - messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + messageBox.setStandardButtons(QMessageBox::Ok); fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtFatalMsg: messageBox.setIcon(QMessageBox::Critical); messageBox.setInformativeText(msg); - messageBox.setStandardButtons(QMessageBox::Cancel); + messageBox.setStandardButtons(QMessageBox::Ok); fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index cbbdd3ba5..e4558ee3a 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -522,8 +522,10 @@ void MainWindow::ToolArc(bool checked) */ void MainWindow::ToolSplinePath(bool checked) { - SetToolButton(checked, Tool::SplinePath, ":/cursor/splinepath_cursor.png", - tr("Select point of curve path"), &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::SplinePath, ":/cursor/splinepath_cursor.png", + tr("Select point of curve path"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index baad7c2fc..6b00f1c27 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -29,6 +29,7 @@ #include "vtoolsplinepath.h" #include "../../dialogs/tools/dialogsplinepath.h" #include "../../undocommands/movesplinepath.h" +#include "../../visualization/vistoolsplinepath.h" const QString VToolSplinePath::ToolType = QStringLiteral("path"); @@ -73,6 +74,9 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint); } + + ShowFoot(false); + if (typeCreation == Source::FromGui) { AddToFile(); @@ -283,33 +287,36 @@ void VToolSplinePath::setSplinePath(const VSplinePath &splPath) //--------------------------------------------------------------------------------------------------------------------- void VToolSplinePath::ShowVisualization(bool show) { -// if (show) -// { -// if (vis == nullptr) -// { -// VisTool * visual = new VisTool(getData()); -// VMainGraphicsScene *scene = qApp->getCurrentScene(); -// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); -// scene->addItem(visual); + if (show) + { + if (vis == nullptr) + { + VisToolSplinePath *visual = new VisToolSplinePath(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); -// // add options -// visual->RefreshGeometry(); -// vis = visual; -// } -// else -// { -// VisTool * visual = qobject_cast(vis); -// if (visual != nullptr) -// { -// visual->show(); -// } -// } -// } -// else -// { -// delete vis; -// vis = nullptr; -// } + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + visual->setPath(*splPath.data()); + visual->setMode(Mode::Show); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolSplinePath *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + ShowFoot(show); } //--------------------------------------------------------------------------------------------------------------------- @@ -441,4 +448,13 @@ void VToolSplinePath::RefreshGeometry() controlPoints[j-2]->blockSignals(false); controlPoints[j-1]->blockSignals(false); } + + if (vis != nullptr) + { + VisToolSplinePath *visual = qobject_cast(vis); + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + visual->setPath(*splPath.data()); + visual->setMode(Mode::Show); + visual->RefreshGeometry(); + } } diff --git a/src/app/visualization/vistoolsplinepath.cpp b/src/app/visualization/vistoolsplinepath.cpp new file mode 100644 index 000000000..b4698e350 --- /dev/null +++ b/src/app/visualization/vistoolsplinepath.cpp @@ -0,0 +1,127 @@ +/************************************************************************ + ** + ** @file vistoolsplinepath.cpp + ** @author Roman Telezhynskyi + ** @date 7 9, 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 . + ** + *************************************************************************/ + +#include "vistoolsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), points(QVector()), line(nullptr), path(VSplinePath()), + mode(Mode::Creation) +{ + line = InitItem(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolSplinePath::~VisToolSplinePath() +{ + qDeleteAll(points.begin(), points.end()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::RefreshGeometry() +{ + if (path.CountPoint() > 0) + { + QVector pathPoints = path.GetSplinePath(); + if (path.CountPoint() == 1) + { + QGraphicsEllipseItem *point = this->getPoint(0); + DrawPoint(point, pathPoints.at(0).P().toQPointF(), supportColor); + + if (mode == Mode::Creation) + { + QLineF sceneLine = QLineF(pathPoints.at(0).P().toQPointF(), Visualization::scenePos); + DrawLine(line, sceneLine, mainColor, lineStyle); + + path[0].SetAngle2(sceneLine.angle()); + emit PathChanged(path); + } + } + else + { + for (int i = 0; i < pathPoints.size(); ++i) + { + QGraphicsEllipseItem *point = this->getPoint(i); + DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor); + } + + if (mode == Mode::Creation) + { + QLineF sceneLine = QLineF(pathPoints.at(pathPoints.size() - 1).P().toQPointF(), + Visualization::scenePos); + DrawLine(line, sceneLine, mainColor, lineStyle); + + path[pathPoints.size() - 1].SetAngle2(sceneLine.angle()); + emit PathChanged(path); + } + + DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); + } + Visualization::toolTip = QString(tr("Curve path: Enter - finish creation")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::setPath(const VSplinePath &value) +{ + path = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VisToolSplinePath::getPath() +{ + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +Mode VisToolSplinePath::getMode() const +{ + return mode; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::setMode(const Mode &value) +{ + mode = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolSplinePath::getPoint(unsigned int i) +{ + if (points.size() - 1 >= i && points.isEmpty() == false) + { + return points.at(i); + } + else + { + QGraphicsEllipseItem * point = InitPoint(supportColor, this); + points.append(point); + return point; + } + return nullptr; +} diff --git a/src/app/visualization/vistoolsplinepath.h b/src/app/visualization/vistoolsplinepath.h new file mode 100644 index 000000000..be9dc2b3c --- /dev/null +++ b/src/app/visualization/vistoolsplinepath.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vistoolsplinepath.h + ** @author Roman Telezhynskyi + ** @date 7 9, 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 VISTOOLSPLINEPATH_H +#define VISTOOLSPLINEPATH_H + +#include "vispath.h" +#include "../geometry/vsplinepath.h" + +enum class Mode : char {Creation, Show}; + +class VisToolSplinePath : public VisPath +{ + Q_OBJECT +public: + VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolSplinePath(); + + virtual void RefreshGeometry(); + + void setPath(const VSplinePath &value); + VSplinePath getPath(); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolSplinePath)}; + + Mode getMode() const; + void setMode(const Mode &value); +signals: + void PathChanged(const VSplinePath &path); + +protected: + Q_DISABLE_COPY(VisToolSplinePath) + QVector points; + QGraphicsLineItem *line; + VSplinePath path; + Mode mode; + + QGraphicsEllipseItem * getPoint(unsigned int i); +}; + +#endif // VISTOOLSPLINEPATH_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index 996302879..e35bd2fe8 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -19,7 +19,8 @@ HEADERS += \ visualization/vispath.h \ visualization/vistoolcutarc.h \ visualization/vistoolspline.h \ - visualization/vistoolcutspline.h + visualization/vistoolcutspline.h \ + visualization/vistoolsplinepath.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -42,4 +43,5 @@ SOURCES += \ visualization/vispath.cpp \ visualization/vistoolcutarc.cpp \ visualization/vistoolspline.cpp \ - visualization/vistoolcutspline.cpp + visualization/vistoolcutspline.cpp \ + visualization/vistoolsplinepath.cpp From ede640618f4db0446c434e0cf17d617bba2d6e25 Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 8 Sep 2014 11:23:53 +0300 Subject: [PATCH 52/52] Visualization for VToolCutSplinePath. Fixed issue #16. --HG-- branch : feature --- src/app/dialogs/tools/dialogcutsplinepath.cpp | 28 ++++- src/app/dialogs/tools/dialogcutsplinepath.h | 5 + src/app/dialogs/tools/dialogcutsplinepath.ui | 2 +- src/app/mainwindow.cpp | 7 +- .../tools/drawTools/vtoolcutsplinepath.cpp | 83 +++++++----- .../visualization/vistoolcutsplinepath.cpp | 118 ++++++++++++++++++ src/app/visualization/vistoolcutsplinepath.h | 53 ++++++++ src/app/visualization/visualization.pri | 6 +- src/app/xml/vpattern.cpp | 5 +- 9 files changed, 264 insertions(+), 43 deletions(-) create mode 100644 src/app/visualization/vistoolcutsplinepath.cpp create mode 100644 src/app/visualization/vistoolcutsplinepath.h diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index c6ad759b1..6c01dd21d 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -32,6 +32,7 @@ #include "../../geometry/vsplinepath.h" #include "../../container/vcontainer.h" #include "../../xml/vpattern.h" +#include "../../visualization/vistoolcutsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -41,7 +42,7 @@ */ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()), - splinePathId(NULL_ID), formulaBaseHeight(0) + splinePathId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); InitVariables(ui); @@ -50,7 +51,7 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; CheckState(); @@ -62,11 +63,14 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSplinePath::DeployFormulaTextEdit); + + path = new VisToolCutSplinePath(data); } //--------------------------------------------------------------------------------------------------------------------- DialogCutSplinePath::~DialogCutSplinePath() { + delete path; delete ui; } @@ -96,6 +100,7 @@ void DialogCutSplinePath::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + path->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -106,6 +111,7 @@ void DialogCutSplinePath::setFormula(const QString &value) void DialogCutSplinePath::setSplinePathId(const quint32 &value) { setCurrentSplinePathId(ui->comboBoxSplinePath, splinePathId, value, ComboBoxCutSpline::CutSpline); + path->setPoint1Id(splinePathId); } //--------------------------------------------------------------------------------------------------------------------- @@ -122,6 +128,8 @@ void DialogCutSplinePath::ChosenObject(quint32 id, const SceneObject &type) { if (SetObject(id, ui->comboBoxSplinePath, "")) { + path->VisualMode(id); + prepare = true; this->setModal(true); this->show(); } @@ -136,6 +144,10 @@ void DialogCutSplinePath::SaveData() formula = ui->plainTextEditFormula->toPlainText(); formula.replace("\n", " "); splinePathId = getCurrentObjectId(ui->comboBoxSplinePath); + + path->setPoint1Id(splinePathId); + path->setLength(formula); + path->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -143,3 +155,15 @@ void DialogCutSplinePath::DeployFormulaTextEdit() { DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSplinePath::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); + scene->addItem(path); + path->RefreshGeometry(); + } +} diff --git a/src/app/dialogs/tools/dialogcutsplinepath.h b/src/app/dialogs/tools/dialogcutsplinepath.h index 46d299379..ff06576c1 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.h +++ b/src/app/dialogs/tools/dialogcutsplinepath.h @@ -36,6 +36,8 @@ namespace Ui class DialogCutSplinePath; } +class VisToolCutSplinePath; + /** * @brief The DialogCutSplinePath class dialog for ToolCutSplinePath. */ @@ -61,6 +63,7 @@ public slots: */ void DeployFormulaTextEdit(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -79,6 +82,8 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + VisToolCutSplinePath *path; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutsplinepath.ui b/src/app/dialogs/tools/dialogcutsplinepath.ui index 3a1cb2a0f..788de6c27 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.ui +++ b/src/app/dialogs/tools/dialogcutsplinepath.ui @@ -392,7 +392,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index e4558ee3a..9ec7f6495 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -535,9 +535,10 @@ void MainWindow::ToolSplinePath(bool checked) */ void MainWindow::ToolCutSplinePath(bool checked) { - SetToolButton(checked, Tool::CutSplinePath, - ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), - &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::CutSplinePath, + ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 4d54f0494..fc8d73562 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -30,6 +30,8 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogcutsplinepath.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolcutsplinepath.h" +#include "vabstractspline.h" #include "../../geometry/vsplinepath.h" @@ -169,16 +171,16 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), spl1.GetAngle1())); VSplinePoint cutPoint; - if (typeCreation == Source::FromGui) - { - cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl1.GetAngle2()+180, - spl1.GetAngle2()); - } - else - { +// if (typeCreation == Source::FromGui) +// { +// cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), +// spl1.GetAngle2()); +// } +// else +// { cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), spl1.GetAngle2()+180); - } +// } splPath1->append(cutPoint); continue; } @@ -245,33 +247,38 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString //--------------------------------------------------------------------------------------------------------------------- void VToolCutSplinePath::ShowVisualization(bool show) { -// if (show) -// { -// if (vis == nullptr) -// { -// VisTool * visual = new VisTool(getData()); -// VMainGraphicsScene *scene = qApp->getCurrentScene(); -// connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); -// scene->addItem(visual); + if (show) + { + if (vis == nullptr) + { + VisToolCutSplinePath *visual = new VisToolCutSplinePath(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); -// // add options -// visual->RefreshGeometry(); -// vis = visual; -// } -// else -// { -// VisTool * visual = qobject_cast(vis); -// if (visual != nullptr) -// { -// visual->show(); -// } -// } -// } -// else -// { -// delete vis; -// vis = nullptr; -// } + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolCutSplinePath *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + if (VAbstractSpline *parentCurve = qobject_cast(doc->getTool(curveCutId))) + { + parentCurve->ShowFoot(show); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -281,6 +288,14 @@ void VToolCutSplinePath::ShowVisualization(bool show) void VToolCutSplinePath::FullUpdateFromFile() { FullUpdateCurveFromFile(AttrSplinePath); + + if (vis != nullptr) + { + VisToolCutSplinePath *visual = qobject_cast(vis); + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolcutsplinepath.cpp b/src/app/visualization/vistoolcutsplinepath.cpp new file mode 100644 index 000000000..9bf157428 --- /dev/null +++ b/src/app/visualization/vistoolcutsplinepath.cpp @@ -0,0 +1,118 @@ +/************************************************************************ + ** + ** @file vistoolcutsplinepath.cpp + ** @author Roman Telezhynskyi + ** @date 7 9, 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 . + ** + *************************************************************************/ + +#include "vistoolcutsplinepath.h" +#include "../container/vcontainer.h" +#include "../geometry/vsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent) + :VisPath(data, parent), point(nullptr), splPath1(nullptr), splPath2(nullptr), length(0) +{ + splPath1 = InitItem(Qt::darkGreen, this); + splPath1->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + splPath2 = InitItem(Qt::darkRed, this); + splPath2->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + + point = InitPoint(mainColor, this); + point->setZValue(2); + point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSplinePath::~VisToolCutSplinePath() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSplinePath::RefreshGeometry() +{ + if (point1Id > 0) + { + const QSharedPointer splPath = Visualization::data->GeometricObject(point1Id); + DrawPath(this, splPath->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + QPointF spl1p2, spl1p3, spl2p2, spl2p3; + qint32 p1 = 0, p2 = 0; + + const QPointF cutPoint = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); + VPointF p = VPointF(cutPoint); + + VSplinePoint splP1 = splPath->at(p1); + VSplinePoint splP2 = splPath->at(p2); + const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, p, splPath->getKCurve()); + const VSpline spl2 = VSpline(p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve()); + + VSplinePath spPath1 = VSplinePath(); + VSplinePath spPath2 = VSplinePath(); + + for (qint32 i = 0; i < splPath->CountPoint(); i++) + { + if (i <= p1 && i < p2) + { + if (i == p1) + { + spPath1.append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), + spl1.GetAngle1())); + VSplinePoint cutPoint; + cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), + spl1.GetAngle2()+180); + spPath1.append(cutPoint); + continue; + } + spPath1.append(splPath->at(i)); + } + else + { + if (i == p2) + { + const VSplinePoint cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl2.GetAngle1()+180, + spl2.GetKasm1(), spl2.GetAngle1()); + spPath2.append(cutPoint); + spPath2.append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(), + spl2.GetAngle2()+180)); + continue; + } + spPath2.append(splPath->at(i)); + } + } + + DrawPoint(point, cutPoint, mainColor); + + DrawPath(splPath1, spPath1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(splPath2, spPath2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSplinePath::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vistoolcutsplinepath.h b/src/app/visualization/vistoolcutsplinepath.h new file mode 100644 index 000000000..6dd4bdfcb --- /dev/null +++ b/src/app/visualization/vistoolcutsplinepath.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file vistoolcutsplinepath.h + ** @author Roman Telezhynskyi + ** @date 7 9, 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 VISTOOLCUTSPLINEPATH_H +#define VISTOOLCUTSPLINEPATH_H + +#include "vispath.h" + +class VisToolCutSplinePath : public VisPath +{ + Q_OBJECT +public: + VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolCutSplinePath(); + + virtual void RefreshGeometry(); + void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCutSpline)}; +protected: + Q_DISABLE_COPY(VisToolCutSplinePath) + QGraphicsEllipseItem *point; + QGraphicsPathItem *splPath1; + QGraphicsPathItem *splPath2; + qreal length; +}; + +#endif // VISTOOLCUTSPLINEPATH_H diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index e35bd2fe8..abd4a6ea3 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -20,7 +20,8 @@ HEADERS += \ visualization/vistoolcutarc.h \ visualization/vistoolspline.h \ visualization/vistoolcutspline.h \ - visualization/vistoolsplinepath.h + visualization/vistoolsplinepath.h \ + visualization/vistoolcutsplinepath.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ @@ -44,4 +45,5 @@ SOURCES += \ visualization/vistoolcutarc.cpp \ visualization/vistoolspline.cpp \ visualization/vistoolcutspline.cpp \ - visualization/vistoolsplinepath.cpp + visualization/vistoolsplinepath.cpp \ + visualization/vistoolcutsplinepath.cpp diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 58f901c37..4d575376b 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -2452,7 +2452,10 @@ void VPattern::PrepareForParse(const Document &parse) else if (parse == Document::LiteParse) { data->ClearUniqueNames(); - data->ClearVariables(); + data->ClearVariables(VarType::ArcLength); + data->ClearVariables(VarType::LineAngle); + data->ClearVariables(VarType::LineLength); + data->ClearVariables(VarType::SplineLength); } }