Show property tool "Point at distance along line".
--HG-- branch : feature
This commit is contained in:
parent
1d639edb6c
commit
87d32d9445
|
@ -31,6 +31,7 @@
|
||||||
#include "../../dialogs/tools/dialogalongline.h"
|
#include "../../dialogs/tools/dialogalongline.h"
|
||||||
#include "../../geometry/vpointf.h"
|
#include "../../geometry/vpointf.h"
|
||||||
#include "exception/vexceptionobjecterror.h"
|
#include "exception/vexceptionobjecterror.h"
|
||||||
|
#include "../undocommands/savetooloptions.h"
|
||||||
|
|
||||||
const QString VToolAlongLine::ToolType = QStringLiteral("alongLine");
|
const QString VToolAlongLine::ToolType = QStringLiteral("alongLine");
|
||||||
|
|
||||||
|
@ -122,16 +123,7 @@ void VToolAlongLine::AddToFile()
|
||||||
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||||
QDomElement domElement = doc->createElement(TagName);
|
QDomElement domElement = doc->createElement(TagName);
|
||||||
|
|
||||||
doc->SetAttribute(domElement, VDomDocument::AttrId, id);
|
SaveOptions(domElement, *point.data());
|
||||||
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);
|
|
||||||
|
|
||||||
AddToCalculation(domElement);
|
AddToCalculation(domElement);
|
||||||
}
|
}
|
||||||
|
@ -146,13 +138,11 @@ void VToolAlongLine::RefreshDataInFile()
|
||||||
QDomElement domElement = doc->elementById(QString().setNum(id));
|
QDomElement domElement = doc->elementById(QString().setNum(id));
|
||||||
if (domElement.isElement())
|
if (domElement.isElement())
|
||||||
{
|
{
|
||||||
doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx()));
|
SaveOptions(domElement, *point.data());
|
||||||
doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my()));
|
}
|
||||||
doc->SetAttribute(domElement, AttrName, point->name());
|
else
|
||||||
doc->SetAttribute(domElement, AttrTypeLine, typeLine);
|
{
|
||||||
doc->SetAttribute(domElement, AttrLength, formulaLength);
|
qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO;
|
||||||
doc->SetAttribute(domElement, AttrFirstPoint, basePointId);
|
|
||||||
doc->SetAttribute(domElement, AttrSecondPoint, secondPointId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +172,94 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement)
|
||||||
doc->SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId());
|
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<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||||
|
SaveOption(*point.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolAlongLine::setName(const QString &name)
|
||||||
|
{
|
||||||
|
VPointF newPoint = VPointF(*VAbstractTool::data.GeometricObject<VPointF>(id).data());
|
||||||
|
newPoint.setName(name);
|
||||||
|
SaveOption(newPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolAlongLine::setTypeLine(const QString &value)
|
||||||
|
{
|
||||||
|
typeLine = value;
|
||||||
|
|
||||||
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||||
|
SaveOption(*point.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolAlongLine::setFormulaLength(const VFormula &value)
|
||||||
|
{
|
||||||
|
if (value.error() == false)
|
||||||
|
{
|
||||||
|
formulaLength = value.getFormula(FormulaType::FromUser);
|
||||||
|
|
||||||
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||||
|
SaveOption(*point.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolAlongLine::setFirstPointId(const quint32 &value)
|
||||||
|
{
|
||||||
|
basePointId = value;
|
||||||
|
|
||||||
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||||
|
SaveOption(*point.data());
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief setDialog set dialog when user want change tool option.
|
* @brief setDialog set dialog when user want change tool option.
|
||||||
|
|
|
@ -51,6 +51,12 @@ public:
|
||||||
static const QString ToolType;
|
static const QString ToolType;
|
||||||
virtual int type() const {return Type;}
|
virtual int type() const {return Type;}
|
||||||
enum { Type = UserType + static_cast<int>(Tool::AlongLine)};
|
enum { Type = UserType + static_cast<int>(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:
|
public slots:
|
||||||
virtual void FullUpdateFromFile();
|
virtual void FullUpdateFromFile();
|
||||||
virtual void SetFactor(qreal factor);
|
virtual void SetFactor(qreal factor);
|
||||||
|
@ -64,6 +70,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
/** @brief secondPointId id second point of line. */
|
/** @brief secondPointId id second point of line. */
|
||||||
quint32 secondPointId;
|
quint32 secondPointId;
|
||||||
|
void SaveOptions(QDomElement &tag, const VPointF &point);
|
||||||
|
void SaveOption(const VPointF &point);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VTOOLALONGLINE_H
|
#endif // VTOOLALONGLINE_H
|
||||||
|
|
|
@ -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<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||||
SaveOption(*point.data());
|
SaveOption(*point.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -279,6 +282,10 @@ void VToolEndLine::RefreshDataInFile()
|
||||||
{
|
{
|
||||||
SaveOptions(domElement, *point.data());
|
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<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
|
||||||
SaveOption(*point.data());
|
SaveOption(*point.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolEndLine::setTypeLine(const QString &value)
|
void VToolEndLine::setTypeLine(const QString &value)
|
||||||
{
|
{
|
||||||
typeLine = value;
|
typeLine = value;
|
||||||
|
|
|
@ -52,10 +52,10 @@ public:
|
||||||
virtual int type() const {return Type;}
|
virtual int type() const {return Type;}
|
||||||
enum { Type = UserType + static_cast<int>(Tool::EndLine)};
|
enum { Type = UserType + static_cast<int>(Tool::EndLine)};
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
QString getFormulaAngle() const;
|
VFormula getFormulaAngle() const;
|
||||||
void setFormulaAngle(const QString &value);
|
void setFormulaAngle(const VFormula &value);
|
||||||
void setTypeLine(const QString &value);
|
void setTypeLine(const QString &value);
|
||||||
void setFormulaLength(const QString &value);
|
void setFormulaLength(const VFormula &value);
|
||||||
void setBasePointId(const quint32 &value);
|
void setBasePointId(const quint32 &value);
|
||||||
public slots:
|
public slots:
|
||||||
virtual void FullUpdateFromFile();
|
virtual void FullUpdateFromFile();
|
||||||
|
|
|
@ -113,7 +113,12 @@ quint32 VToolLinePoint::getBasePointId() const
|
||||||
return basePointId;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#define VTOOLLINEPOINT_H
|
#define VTOOLLINEPOINT_H
|
||||||
|
|
||||||
#include "vtoolpoint.h"
|
#include "vtoolpoint.h"
|
||||||
|
#include "../container/vformula.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The VToolLinePoint class parent for all tools what create point with line.
|
* @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);
|
const quint32 &basePointId, const qreal &angle, QGraphicsItem * parent = nullptr);
|
||||||
virtual int type() const {return Type;}
|
virtual int type() const {return Type;}
|
||||||
enum { Type = UserType + static_cast<int>(Tool::LinePoint)};
|
enum { Type = UserType + static_cast<int>(Tool::LinePoint)};
|
||||||
QString getFormulaLength() const;
|
VFormula getFormulaLength() const;
|
||||||
//void setFormulaLength(const QString &value)=0;
|
//void setFormulaLength(const QString &value)=0;
|
||||||
|
|
||||||
quint32 getBasePointId() const;
|
quint32 getBasePointId() const;
|
||||||
|
|
|
@ -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();
|
case VToolSinglePoint::Type:
|
||||||
return;
|
{
|
||||||
|
VToolSinglePoint *i = qgraphicsitem_cast<VToolSinglePoint *>(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<VToolEndLine *>(item);
|
||||||
|
TreeView->setTitle(tr("Point at distance and angle"));
|
||||||
|
|
||||||
PropertyModel->clear();
|
AddPropertyPointName(i, tr("Point name"));
|
||||||
propertyToId.clear();
|
AddPropertyPointsList(i, tr("Base point"), i->getBasePointId(), VAbstractTool::AttrBasePoint);
|
||||||
idToProperty.clear();
|
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<VToolAlongLine *>(item);
|
||||||
|
TreeView->setTitle(tr("Point at distance along line"));
|
||||||
|
|
||||||
currentItem = item;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolOptionsPropertyBrowser::UpdateOptions()
|
||||||
|
{
|
||||||
if (currentItem == nullptr)
|
if (currentItem == nullptr)
|
||||||
{
|
{
|
||||||
TreeView->setTitle(tr(""));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowItemOptions(currentItem);
|
switch (currentItem->type())
|
||||||
|
{
|
||||||
|
case VToolSinglePoint::Type:
|
||||||
|
{
|
||||||
|
VToolSinglePoint *i = qgraphicsitem_cast<VToolSinglePoint *>(currentItem);
|
||||||
|
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
|
||||||
|
idToProperty[QLatin1String("position")]->setValue(i->pos());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case VToolEndLine::Type:
|
||||||
|
{
|
||||||
|
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(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<VToolAlongLine *>(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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant variant = prop->data(VProperty::DPC_Data, Qt::DisplayRole);
|
|
||||||
|
|
||||||
QString id = propertyToId[prop];
|
|
||||||
switch (currentItem->type())
|
switch (currentItem->type())
|
||||||
{
|
{
|
||||||
case VToolSinglePoint::Type:
|
case VToolSinglePoint::Type:
|
||||||
{
|
ChangeDataToolSinglePoint(prop);
|
||||||
if (id == QLatin1String("name"))
|
|
||||||
{
|
|
||||||
SetPointName<VToolSinglePoint>(variant.toString());
|
|
||||||
}
|
|
||||||
else if (id == QLatin1String("position"))
|
|
||||||
{
|
|
||||||
currentItem->setPos(variant.toPointF());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case VToolEndLine::Type:
|
case VToolEndLine::Type:
|
||||||
{
|
ChangeDataToolEndLine(prop);
|
||||||
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(currentItem);
|
break;
|
||||||
if (id == QLatin1String("name"))
|
case VToolAlongLine::Type:
|
||||||
{
|
ChangeDataToolAlongLine(prop);
|
||||||
SetPointName<VToolEndLine>(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<VFormula>();
|
|
||||||
if (formula.error() == false)
|
|
||||||
{
|
|
||||||
i->setFormulaLength(variant.value<VFormula>().getFormula(FormulaType::FromUser));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (id == QLatin1String("formulaAngle"))
|
|
||||||
{
|
|
||||||
VFormula formula = variant.value<VFormula>();
|
|
||||||
if (formula.error() == false)
|
|
||||||
{
|
|
||||||
i->setFormulaAngle(variant.value<VFormula>().getFormula(FormulaType::FromUser));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
qApp->getSceneView()->update();
|
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<class Tool>
|
||||||
|
void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &propertyName)
|
||||||
|
{
|
||||||
|
VProperty* itemName = new VProperty(propertyName);
|
||||||
|
itemName->setValue(i->name());
|
||||||
|
AddProperty(itemName, VAbstractTool::AttrName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
template<class Tool>
|
||||||
|
void VToolOptionsPropertyBrowser::AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value,
|
||||||
|
const QString &attrName)
|
||||||
|
{
|
||||||
|
VObjectProperty *pointsProperty = new VObjectProperty(propertyName);
|
||||||
|
QMap<QString, quint32> pointsList = i->PointsList();
|
||||||
|
pointsProperty->setObjectsList(pointsList);
|
||||||
|
pointsProperty->setValue(value);
|
||||||
|
AddProperty(pointsProperty, attrName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
template<class Tool>
|
||||||
|
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<class Tool>
|
template<class Tool>
|
||||||
void VToolOptionsPropertyBrowser::SetPointName(const QString &name)
|
void VToolOptionsPropertyBrowser::SetPointName(const QString &name)
|
||||||
{
|
{
|
||||||
|
@ -174,7 +297,7 @@ void VToolOptionsPropertyBrowser::SetPointName(const QString &name)
|
||||||
|
|
||||||
if (name.isEmpty())
|
if (name.isEmpty())
|
||||||
{
|
{
|
||||||
idToProperty[QLatin1String("name")]->setValue(i->name());
|
idToProperty[VAbstractTool::AttrName]->setValue(i->name());
|
||||||
}
|
}
|
||||||
else
|
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<VToolSinglePoint *>(currentItem);
|
|
||||||
idToProperty[QLatin1String("name")]->setValue(i->name());
|
|
||||||
idToProperty[QLatin1String("position")]->setValue(i->pos());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case VToolEndLine::Type:
|
|
||||||
{
|
|
||||||
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(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)
|
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:
|
case 0: // VAbstractTool::AttrName
|
||||||
{
|
SetPointName<VToolSinglePoint>(value.toString());
|
||||||
VToolSinglePoint *i = qgraphicsitem_cast<VToolSinglePoint *>(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"));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
case 1: // QLatin1String("position")
|
||||||
case VToolEndLine::Type:
|
currentItem->setPos(value.toPointF());
|
||||||
{
|
|
||||||
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(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<QString, quint32> 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);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
qWarning()<<"Unknown property type. id = "<<id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolOptionsPropertyBrowser::ChangeDataToolEndLine(VProperty *property)
|
||||||
|
{
|
||||||
|
SCASSERT(property != nullptr)
|
||||||
|
|
||||||
|
QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole);
|
||||||
|
const QString id = propertyToId[property];
|
||||||
|
|
||||||
|
VToolEndLine *i = qgraphicsitem_cast<VToolEndLine *>(currentItem);
|
||||||
|
SCASSERT(i != nullptr);
|
||||||
|
switch (PropertiesList().indexOf(id))
|
||||||
|
{
|
||||||
|
case 0: // VAbstractTool::AttrName
|
||||||
|
SetPointName<VToolEndLine>(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<VFormula>());
|
||||||
|
break;
|
||||||
|
case 5: // VAbstractTool::AttrAngle
|
||||||
|
i->setFormulaAngle(value.value<VFormula>());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qWarning()<<"Unknown property type. id = "<<id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolOptionsPropertyBrowser::ChangeDataToolAlongLine(VProperty *property)
|
||||||
|
{
|
||||||
|
SCASSERT(property != nullptr)
|
||||||
|
|
||||||
|
QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole);
|
||||||
|
const QString id = propertyToId[property];
|
||||||
|
|
||||||
|
VToolAlongLine *i = qgraphicsitem_cast<VToolAlongLine *>(currentItem);
|
||||||
|
SCASSERT(i != nullptr);
|
||||||
|
switch (PropertiesList().indexOf(id))
|
||||||
|
{
|
||||||
|
case 0: // VAbstractTool::AttrName
|
||||||
|
SetPointName<VToolEndLine>(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<VFormula>());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qWarning()<<"Unknown property type. id = "<<id;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
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 */
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
class QDockWidget;
|
class QDockWidget;
|
||||||
class QGraphicsItem;
|
class QGraphicsItem;
|
||||||
class QScrollArea;
|
class QScrollArea;
|
||||||
|
class VFormula;
|
||||||
|
|
||||||
using namespace VPE;
|
using namespace VPE;
|
||||||
|
|
||||||
|
@ -66,6 +67,23 @@ private:
|
||||||
|
|
||||||
template<class Tool>
|
template<class Tool>
|
||||||
void SetPointName(const QString &name);
|
void SetPointName(const QString &name);
|
||||||
|
|
||||||
|
template<class Tool>
|
||||||
|
void AddPropertyPointName(Tool *i, const QString &propertyName);
|
||||||
|
|
||||||
|
template<class Tool>
|
||||||
|
void AddPropertyPointsList(Tool *i, const QString &propertyName, const quint32 &value, const QString &attrName);
|
||||||
|
|
||||||
|
template<class Tool>
|
||||||
|
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
|
#endif // VTOOLOPTIONSPROPERTYBROWSER_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user