From 80fcf30776c7713993312ba938fc448cb355aac8 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 27 Jun 2016 11:06:51 +0200 Subject: [PATCH] Moving, resizing and editing both labels now works --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 11 ++- src/libs/ifc/xml/vabstractpattern.cpp | 94 ++++++++++----------- src/libs/ifc/xml/vabstractpattern.h | 6 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 2 + src/libs/vtools/tools/vtooldetail.cpp | 5 +- src/libs/vtools/tools/vtooldetail.h | 2 +- 6 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b90ec26c2..fa5141149 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -138,7 +138,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagCreationDate; + << TagCreationDate << TagLabelPos << TagLabelWidth << TagLabelFont; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -213,6 +213,15 @@ void VPattern::Parse(const Document &parse) case 14: // TagCreationDate qCDebug(vXML, "Creation date."); break; + case 15: // TagLabelPos + qCDebug(vXML, "Label position."); + break; + case 16: // TagLabelWidth + qCDebug(vXML, "Label width."); + break; + case 17: // TagLabelFont + qCDebug(vXML, "Label font size."); + break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); break; diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 70915c8df..fc9a8e0ae 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -67,7 +67,9 @@ const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber" const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); -const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel"); +const QString VAbstractPattern::TagLabelPos = QStringLiteral("labelPosition"); +const QString VAbstractPattern::TagLabelWidth = QStringLiteral("labelWidth"); +const QString VAbstractPattern::TagLabelFont = QStringLiteral("fontSize"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -79,8 +81,6 @@ const QString VAbstractPattern::AttrMaterial = QStringLiteral("material"); const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); -const QString VAbstractPattern::AttrWidth = QStringLiteral("width"); -const QString VAbstractPattern::AttrFont = QStringLiteral("font"); const QString VAbstractPattern::AttrAll = QStringLiteral("all"); @@ -1081,21 +1081,19 @@ QDate VAbstractPattern::GetCreationDate() const //--------------------------------------------------------------------------------------------------------------------- QPointF VAbstractPattern::GetLabelPosition() const { - QPointF ptPos(0.0, 0.0); - QDomNodeList li = elementsByTagName(TagPatternLabel); - if (li.count() == 0) + QStringList qsl = UniqueTagText(TagLabelPos).split(","); + QPointF ptPos(0, 0); + if (qsl.count() == 2) { - return ptPos; - } - - QDomNamedNodeMap attr = li.at(0).attributes(); - if (attr.contains(AttrMx) == true) - { - ptPos.setX(attr.namedItem(AttrMx).nodeValue().toDouble()); - } - if (attr.contains(AttrMy) == true) - { - ptPos.setY(attr.namedItem(AttrMy).nodeValue().toDouble()); + bool bOKX; + bool bOKY; + double fX = qsl[0].toDouble(&bOKX); + double fY = qsl[1].toDouble(&bOKY); + if (bOKX == true && bOKY == true) + { + ptPos.setX(fX); + ptPos.setY(fY); + } } return ptPos; } @@ -1103,28 +1101,20 @@ QPointF VAbstractPattern::GetLabelPosition() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetLabelPosition(const QPointF& ptPos) { - CheckTagExists(TagPatternLabel); - QDomNode node = elementsByTagName(TagPatternLabel).at(0); - node.toElement().setAttribute(AttrMx, ptPos.x()); - node.toElement().setAttribute(AttrMy, ptPos.y()); + CheckTagExists(TagLabelPos); + setTagText(TagLabelPos, QString::number(ptPos.x(), 'f', 3) + "," + QString::number(ptPos.y(), 'f', 3)); + modified = true; emit patternChanged(false); - - qDebug() << "LABEL POSITION" << GetLabelPosition(); } //--------------------------------------------------------------------------------------------------------------------- qreal VAbstractPattern::GetLabelWidth() const { - qreal fW = 0.0; - QDomNodeList li = elementsByTagName(TagPatternLabel); - if (li.count() == 0) + bool bOK; + qreal fW = UniqueTagText(TagLabelWidth).toDouble(&bOK); + if (bOK == false) { - return fW; - } - QDomNamedNodeMap attr = li.at(0).attributes(); - if (attr.contains(AttrWidth) == true) - { - fW = attr.namedItem(AttrWidth).nodeName().toDouble(); + fW = 0; } return fW; } @@ -1132,25 +1122,20 @@ qreal VAbstractPattern::GetLabelWidth() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetLabelWidth(qreal fW) { - CheckTagExists(TagPatternLabel); - QDomNode node = elementsByTagName(TagPatternLabel).at(0); - node.toElement().setAttribute(AttrWidth, fW); + CheckTagExists(TagLabelWidth); + setTagText(TagLabelWidth, QString::number(fW, 'f', 3)); + modified = true; emit patternChanged(false); } //--------------------------------------------------------------------------------------------------------------------- int VAbstractPattern::GetFontSize() const { - int iFS = 0; - QDomNodeList li = elementsByTagName(TagPatternLabel); - if (li.count() == 0) + bool bOK; + int iFS = UniqueTagText(TagLabelFont).toInt(&bOK); + if (bOK == false) { - return iFS; - } - QDomNamedNodeMap attr = li.at(0).attributes(); - if (attr.contains(AttrFont) == true) - { - iFS = attr.namedItem(AttrFont).nodeName().toInt(); + iFS = 0; } return iFS; } @@ -1158,9 +1143,9 @@ int VAbstractPattern::GetFontSize() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetFontSize(int iFS) { - CheckTagExists(TagPatternLabel); - QDomNode node = elementsByTagName(TagPatternLabel).at(0); - node.toElement().setAttribute(AttrWidth, iFS); + CheckTagExists(TagLabelFont); + setTagText(TagLabelFont, QString::number(iFS)); + modified = true; emit patternChanged(false); } @@ -1289,7 +1274,8 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagCreationDate << TagPatternLabel; + << TagCustomerName << TagCreationDate << TagLabelPos << TagLabelWidth + << TagLabelFont; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1357,7 +1343,17 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) } case 11: { - element = createElement(TagPatternLabel); + element = createElement(TagLabelPos); + break; + } + case 12: + { + element = createElement(TagLabelWidth); + break; + } + case 13: + { + element = createElement(TagLabelFont); break; } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 11ccd3308..fe6a44094 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -179,7 +179,9 @@ public: static const QString TagCompanyName; static const QString TagCustomerName; static const QString TagCreationDate; - static const QString TagPatternLabel; + static const QString TagLabelPos; + static const QString TagLabelWidth; + static const QString TagLabelFont; static const QString AttrName; static const QString AttrVisible; @@ -191,8 +193,6 @@ public: static const QString AttrUserDefined; static const QString AttrCutNumber; static const QString AttrPlacement; - static const QString AttrWidth; - static const QString AttrFont; static const QString AttrAll; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 853d65039..1d27cc508 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -139,6 +139,7 @@ void VTextGraphicsItem::Reset() { m_eMode = mNormal; UpdateFont(); + setZValue(2); } //--------------------------------------------------------------------------------------------------------------------- @@ -174,6 +175,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { m_eMode = mMove; } + setZValue(3); Update(); } diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index bc3f7e079..f4430d494 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -117,7 +117,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); - connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChild); + connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChildren); if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) { AddToFile(); @@ -942,9 +942,10 @@ void VToolDetail::AllowSelecting(bool enabled) } //--------------------------------------------------------------------------------------------------------------------- -void VToolDetail::ResetChild() +void VToolDetail::ResetChildren() { dataLabel->Reset(); + patternInfo->Reset(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 9f5f2d1a7..a68891276 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -91,7 +91,7 @@ public slots: void EnableToolMove(bool move); virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - virtual void ResetChild(); + virtual void ResetChildren(); virtual void UpdateAll(); protected: virtual void AddToFile () Q_DECL_OVERRIDE;