Save label name.

--HG--
branch : feature
This commit is contained in:
dismine 2014-08-27 10:31:58 +03:00
parent ea8e8338c8
commit 35b5a65eed
2 changed files with 36 additions and 12 deletions

View File

@ -33,6 +33,7 @@
#include "../../undocommands/addpatternpiece.h" #include "../../undocommands/addpatternpiece.h"
#include "../../undocommands/deletepatternpiece.h" #include "../../undocommands/deletepatternpiece.h"
#include "../../geometry/vpointf.h" #include "../../geometry/vpointf.h"
#include "../../undocommands/savetooloptions.h"
#include <QMessageBox> #include <QMessageBox>
@ -91,7 +92,23 @@ QString VToolSinglePoint::name() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::setName(const QString &name) 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<VPointF>(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); QDomElement sPoint = doc->createElement(TagName);
// Create SPoint tag // Create SPoint tag
doc->SetAttribute(sPoint, VDomDocument::AttrId, id); SaveOptions(sPoint, *point.data());
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()));
//Create pattern piece structure //Create pattern piece structure
QDomElement patternPiece = doc->createElement(VPattern::TagDraw); QDomElement patternPiece = doc->createElement(VPattern::TagDraw);
@ -147,11 +158,11 @@ void VToolSinglePoint::RefreshDataInFile()
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, AttrName, point->name()); SaveOptions(domElement, *point.data());
doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(point->x()))); }
doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(point->y()))); else
doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(point->mx()))); {
doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(point->my()))); 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)); 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. * @brief contextMenuEvent handle context menu events.

View File

@ -73,6 +73,7 @@ private:
QString namePP; QString namePP;
QString mPath; QString mPath;
void setColorLabel(const Qt::GlobalColor & color); void setColorLabel(const Qt::GlobalColor & color);
void SaveOptions(QDomElement &tag, const VPointF &point);
}; };
#endif // VTOOLSINGLEPOINT_H #endif // VTOOLSINGLEPOINT_H