Moved pattern info geometry into VDetail class

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-07-02 01:49:38 +02:00
parent 438cb466d7
commit f52f97740d
15 changed files with 329 additions and 169 deletions

View File

@ -48,6 +48,7 @@
#include "../core/vapplication.h" #include "../core/vapplication.h"
#include "../vpatterndb/calculator.h" #include "../vpatterndb/calculator.h"
#include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatternpiecedata.h"
#include "../vpatterndb/vpatterninfogeometry.h"
#include <QMessageBox> #include <QMessageBox>
#include <QUndoStack> #include <QUndoStack>
@ -138,7 +139,7 @@ void VPattern::Parse(const Document &parse)
QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes
<< TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit
<< TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName
<< TagCreationDate << TagLabelPos << TagLabelSize << TagLabelFont; << TagCreationDate;
PrepareForParse(parse); PrepareForParse(parse);
QDomNode domNode = documentElement().firstChild(); QDomNode domNode = documentElement().firstChild();
while (domNode.isNull() == false) while (domNode.isNull() == false)
@ -213,15 +214,6 @@ void VPattern::Parse(const Document &parse)
case 14: // TagCreationDate case 14: // TagCreationDate
qCDebug(vXML, "Creation date."); qCDebug(vXML, "Creation date.");
break; break;
case 15: // TagLabelPos
qCDebug(vXML, "Label position.");
break;
case 16: // TagLabelSize
qCDebug(vXML, "Label size.");
break;
case 17: // TagLabelFont
qCDebug(vXML, "Label font size.");
break;
default: default:
qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName()));
break; break;
@ -695,6 +687,21 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
detail.GetPatternPieceData().Append(mcp); detail.GetPatternPieceData().Append(mcp);
} }
} }
else if (element.tagName() == TagPatternInfo)
{
QPointF ptPos;
ptPos.setX(element.attribute(AttrMx, "0").toDouble());
ptPos.setY(element.attribute(AttrMy, "0").toDouble());
detail.GetPatternInfo().SetPos(ptPos);
qreal dLW = element.attribute(VToolDetail::AttrWidth, "0").toDouble();
detail.GetPatternInfo().SetLabelWidth(dLW);
qreal dLH = element.attribute(VToolDetail::AttrHeight, "0").toDouble();
detail.GetPatternInfo().SetLabelHeight(dLH);
int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt();
detail.GetPatternInfo().SetFontSize(iFS);
qreal dRot = element.attribute(VToolDetail::AttrRotation, "0").toDouble();
detail.GetPatternInfo().SetRotation(dRot);
}
} }
} }
VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile);

View File

@ -23,10 +23,6 @@
<xs:element name="company" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="company" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="customer" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="customer" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="created" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element> <xs:element name="created" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="labelPosition" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="labelSize" type="xs:string" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="fontSize" type="xs:unsignedInt" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="rotation" type="xs:double" minOccurs="0" maxOccurs="1"></xs:element>
<xs:element name="gradation" minOccurs="0" maxOccurs="1"> <xs:element name="gradation" minOccurs="0" maxOccurs="1">
<xs:complexType> <xs:complexType>
<xs:sequence> <xs:sequence>
@ -364,6 +360,16 @@
<xs:attribute name="rotation" type="xs:double"></xs:attribute> <xs:attribute name="rotation" type="xs:double"></xs:attribute>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
<xs:element name="patternInfo" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="fontSize" type="xs:unsignedInt"></xs:attribute>
<xs:attribute name="mx" type="xs:double"></xs:attribute>
<xs:attribute name="my" type="xs:double"></xs:attribute>
<xs:attribute name="width" type="xs:double"></xs:attribute>
<xs:attribute name="height" type="xs:double"></xs:attribute>
<xs:attribute name="rotation" type="xs:double"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="node" maxOccurs="unbounded"> <xs:element name="node" maxOccurs="unbounded">
<xs:complexType> <xs:complexType>
<xs:attribute name="nodeType" type="xs:string"></xs:attribute> <xs:attribute name="nodeType" type="xs:string"></xs:attribute>

View File

@ -61,16 +61,13 @@ const QString VAbstractPattern::TagHeights = QStringLiteral("heights");
const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes");
const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); const QString VAbstractPattern::TagUnit = QStringLiteral("unit");
const QString VAbstractPattern::TagData = QStringLiteral("data"); const QString VAbstractPattern::TagData = QStringLiteral("data");
const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo");
const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); const QString VAbstractPattern::TagMCP = QStringLiteral("mcp");
const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName"); const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName");
const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber");
const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer");
const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company");
const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created");
const QString VAbstractPattern::TagLabelPos = QStringLiteral("labelPosition");
const QString VAbstractPattern::TagLabelSize = QStringLiteral("labelSize");
const QString VAbstractPattern::TagLabelFont = QStringLiteral("fontSize");
const QString VAbstractPattern::TagLabelRot = QStringLiteral("rotation");
const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrName = QStringLiteral("name");
const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible");
@ -1079,106 +1076,6 @@ QDate VAbstractPattern::GetCreationDate() const
return QDate::currentDate(); return QDate::currentDate();
} }
//---------------------------------------------------------------------------------------------------------------------
QPointF VAbstractPattern::GetLabelPosition() const
{
QStringList qsl = UniqueTagText(TagLabelPos).split(",");
QPointF ptPos(0, 0);
if (qsl.count() == 2)
{
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;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetLabelPosition(const QPointF& ptPos)
{
CheckTagExists(TagLabelPos);
setTagText(TagLabelPos, QString::number(ptPos.x(), 'f', 3) + "," + QString::number(ptPos.y(), 'f', 3));
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VAbstractPattern::GetLabelSize() const
{
QStringList qsl = UniqueTagText(TagLabelSize).split(",");
QSizeF sz(0, 0);
if (qsl.count() == 2)
{
bool bOKW;
bool bOKH;
double fW = qsl[0].toDouble(&bOKW);
double fH = qsl[1].toDouble(&bOKH);
if (bOKW == true && bOKH == true)
{
sz.setWidth(fW);
sz.setHeight(fH);
}
}
return sz;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetLabelSize(QSizeF sz)
{
CheckTagExists(TagLabelSize);
setTagText(TagLabelSize, QString::number(sz.width(), 'f', 3) + "," + QString::number(sz.height(), 'f', 3));
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
int VAbstractPattern::GetFontSize() const
{
bool bOK;
int iFS = UniqueTagText(TagLabelFont).toInt(&bOK);
if (bOK == false)
{
iFS = 0;
}
return iFS;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetFontSize(int iFS)
{
CheckTagExists(TagLabelFont);
setTagText(TagLabelFont, QString::number(iFS));
modified = true;
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
qreal VAbstractPattern::GetRotation() const
{
bool bOK;
qreal dRot = UniqueTagText(TagLabelRot).toDouble(&bOK);
if (bOK == false)
{
dRot = 0;
}
return dRot;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetRotation(qreal dRot)
{
CheckTagExists(TagLabelRot);
setTagText(TagLabelRot, QString::number(dRot, 'f', 3));
modified = true;
emit patternChanged(false);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetImage() const QString VAbstractPattern::GetImage() const
{ {
@ -1304,8 +1201,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
{ {
const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes
<< TagGradation << TagPatternName << TagPatternNum << TagCompanyName << TagGradation << TagPatternName << TagPatternNum << TagCompanyName
<< TagCustomerName << TagCreationDate << TagLabelPos << TagLabelSize << TagCustomerName << TagCreationDate;
<< TagLabelFont << TagLabelRot;
switch (tags.indexOf(tag)) switch (tags.indexOf(tag))
{ {
case 0: //TagUnit case 0: //TagUnit
@ -1371,27 +1267,6 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag)
element = createElement(TagCreationDate); element = createElement(TagCreationDate);
break; break;
} }
case 11:
{
element = createElement(TagLabelPos);
break;
}
case 12:
{
element = createElement(TagLabelSize);
break;
}
case 13:
{
element = createElement(TagLabelFont);
break;
}
case 14:
{
element = createElement(TagLabelRot);
break;
}
default: default:
{ {

View File

@ -117,14 +117,6 @@ public:
QString GetCustomerName() const; QString GetCustomerName() const;
void SetCustomerName(QString qsName); void SetCustomerName(QString qsName);
QDate GetCreationDate() const; QDate GetCreationDate() const;
QPointF GetLabelPosition() const;
void SetLabelPosition(const QPointF& ptPos);
QSizeF GetLabelSize() const;
void SetLabelSize(QSizeF sz);
int GetFontSize() const;
void SetFontSize(int iFS);
qreal GetRotation() const;
void SetRotation(qreal dRot);
QString GetImage() const; QString GetImage() const;
QString GetImageExtension() const; QString GetImageExtension() const;
@ -175,16 +167,13 @@ public:
static const QString TagSizes; static const QString TagSizes;
static const QString TagUnit; static const QString TagUnit;
static const QString TagData; static const QString TagData;
static const QString TagPatternInfo;
static const QString TagMCP; static const QString TagMCP;
static const QString TagPatternName; static const QString TagPatternName;
static const QString TagPatternNum; static const QString TagPatternNum;
static const QString TagCompanyName; static const QString TagCompanyName;
static const QString TagCustomerName; static const QString TagCustomerName;
static const QString TagCreationDate; static const QString TagCreationDate;
static const QString TagLabelPos;
static const QString TagLabelSize;
static const QString TagLabelFont;
static const QString TagLabelRot;
static const QString AttrName; static const QString AttrName;
static const QString AttrVisible; static const QString AttrVisible;

View File

@ -527,7 +527,7 @@ QVector<VNodeDetail> VDetail::listNodePoint() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief Returns the full access to the pattern piece data object * @brief Returns full access to the pattern piece data object
* @return pattern piece data object * @return pattern piece data object
*/ */
VPatternPieceData& VDetail::GetPatternPieceData() VPatternPieceData& VDetail::GetPatternPieceData()
@ -545,6 +545,26 @@ const VPatternPieceData& VDetail::GetPatternPieceData() const
return d->m_ppData; return d->m_ppData;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Returns full access to the pattern info geometry object
* @return pattern info geometry object
*/
VPatternInfoGeometry& VDetail::GetPatternInfo()
{
return d->m_piPatternInfo;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Returns the read only reference to the pattern info geometry object
* @return pattern info geometry object
*/
const VPatternInfoGeometry& VDetail::GetPatternInfo() const
{
return d->m_piPatternInfo;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief indexOfNode return index in list node using id object. * @brief indexOfNode return index in list node using id object.

View File

@ -38,6 +38,7 @@ class VDetailData;
class VContainer; class VContainer;
class QPainterPath; class QPainterPath;
class VPatternPieceData; class VPatternPieceData;
class VPatternInfoGeometry;
/** /**
* @brief The VDetail class for path of object (points, arcs, splines). * @brief The VDetail class for path of object (points, arcs, splines).
@ -90,6 +91,8 @@ public:
QVector<VNodeDetail> listNodePoint()const; QVector<VNodeDetail> listNodePoint()const;
VPatternPieceData& GetPatternPieceData(); VPatternPieceData& GetPatternPieceData();
const VPatternPieceData& GetPatternPieceData() const; const VPatternPieceData& GetPatternPieceData() const;
VPatternInfoGeometry& GetPatternInfo();
const VPatternInfoGeometry& GetPatternInfo() const;
private: private:
QSharedDataPointer<VDetailData> d; QSharedDataPointer<VDetailData> d;

View File

@ -32,6 +32,7 @@
#include <QSharedData> #include <QSharedData>
#include "vnodedetail.h" #include "vnodedetail.h"
#include "vpatternpiecedata.h" #include "vpatternpiecedata.h"
#include "vpatterninfogeometry.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
#ifdef Q_CC_GNU #ifdef Q_CC_GNU
@ -52,7 +53,7 @@ public:
VDetailData(const VDetailData &detail) VDetailData(const VDetailData &detail)
:QSharedData(detail), _id(NULL_ID), nodes(detail.nodes), mx(detail.mx), my(detail.my), :QSharedData(detail), _id(NULL_ID), nodes(detail.nodes), mx(detail.mx), my(detail.my),
m_ppData(detail.m_ppData), inLayout(detail.inLayout) m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), inLayout(detail.inLayout)
{} {}
~VDetailData() {} ~VDetailData() {}
@ -71,6 +72,8 @@ public:
/** @brief Pattern piece data */ /** @brief Pattern piece data */
VPatternPieceData m_ppData; VPatternPieceData m_ppData;
/** @brief Pattern info coordinates */
VPatternInfoGeometry m_piPatternInfo;
bool inLayout; bool inLayout;

View File

@ -101,3 +101,9 @@ CONFIG(debug, debug|release){
} }
} }
HEADERS += \
vpatterninfogeometry.h
SOURCES += \
vpatterninfogeometry.cpp

View File

@ -0,0 +1,108 @@
/************************************************************************
**
** @file vpatterninfogeometry.cpp
** @author Bojan Kverh
** @date June 16, 2016
**
** @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-2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vpatterninfogeometry.h"
//---------------------------------------------------------------------------------------------------------------------
VPatternInfoGeometry::VPatternInfoGeometry() :
m_ptPos(0, 0)
{
m_iFontSize = MIN_FONT_SIZE;
// 0 means unknown width
m_dLabelWidth = 0;
m_dLabelHeight = 0;
m_dRotation = 0;
}
//---------------------------------------------------------------------------------------------------------------------
VPatternInfoGeometry::~VPatternInfoGeometry()
{}
//---------------------------------------------------------------------------------------------------------------------
QPointF VPatternInfoGeometry::GetPos() const
{
return m_ptPos;
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternInfoGeometry::SetPos(const QPointF& ptPos)
{
m_ptPos = ptPos;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPatternInfoGeometry::GetLabelWidth() const
{
return m_dLabelWidth;
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternInfoGeometry::SetLabelWidth(qreal dLabelW)
{
m_dLabelWidth = dLabelW;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPatternInfoGeometry::GetLabelHeight() const
{
return m_dLabelHeight;
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternInfoGeometry::SetLabelHeight(qreal dLabelH)
{
m_dLabelHeight = dLabelH;
}
//---------------------------------------------------------------------------------------------------------------------
int VPatternInfoGeometry::GetFontSize() const
{
return m_iFontSize;
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternInfoGeometry::SetFontSize(int iSize)
{
if (iSize >= MIN_FONT_SIZE)
m_iFontSize = iSize;
else
m_iFontSize = MIN_FONT_SIZE;
}
//---------------------------------------------------------------------------------------------------------------------
qreal VPatternInfoGeometry::GetRotation() const
{
return m_dRotation;
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternInfoGeometry::SetRotation(qreal dRot)
{
m_dRotation = dRot;
}

View File

@ -0,0 +1,70 @@
/************************************************************************
**
** @file vpatterninfogeometry.h
** @author Bojan Kverh
** @date June 16, 2016
**
** @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-2015 Valentina project
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VPATTERNINFOGEOMETRY_H
#define VPATTERNINFOGEOMETRY_H
#define MIN_FONT_SIZE 12
#include <QPointF>
class VPatternInfoGeometry
{
public:
VPatternInfoGeometry();
~VPatternInfoGeometry();
// methods, which set up label parameters
QPointF GetPos() const;
void SetPos(const QPointF& ptPos);
qreal GetLabelWidth() const;
void SetLabelWidth(qreal dLabelW);
qreal GetLabelHeight() const;
void SetLabelHeight(qreal dLabelH);
int GetFontSize() const;
void SetFontSize(int iSize);
qreal GetRotation() const;
void SetRotation(qreal dRot);
private:
QPointF m_ptPos;
/** @brief Label width
*/
qreal m_dLabelWidth;
/** @brief Label height
*/
qreal m_dLabelHeight;
/** @brief Label font size
*/
int m_iFontSize;
/** @brief Label rotation
*/
qreal m_dRotation;
};
#endif // VPATTERNINFOGEOMETRY_H

View File

@ -1,6 +1,6 @@
/************************************************************************ /************************************************************************
** **
** @file vpatternpiecedata.h ** @file vpatternpiecedata.cpp
** @author Bojan Kverh ** @author Bojan Kverh
** @date June 16, 2016 ** @date June 16, 2016
** **
@ -35,6 +35,7 @@ VPatternPieceData::VPatternPieceData() :
m_iFontSize = MIN_FONT_SIZE; m_iFontSize = MIN_FONT_SIZE;
// 0 means unknown width // 0 means unknown width
m_dLabelWidth = 0; m_dLabelWidth = 0;
m_dLabelHeight = 0;
m_dRotation = 0; m_dRotation = 0;
} }

View File

@ -249,7 +249,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME)
} }
double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI; double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI;
setRotation(m_dRotation + dAng); setRotation(m_dRotation + dAng);
emit SignalRotated(rotation()); //emit SignalRotated(rotation());
Update(); Update();
} }
} }

View File

@ -41,6 +41,7 @@
#include "../undocommands/adddet.h" #include "../undocommands/adddet.h"
#include "../undocommands/deletedetail.h" #include "../undocommands/deletedetail.h"
#include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatternpiecedata.h"
#include "../vpatterndb/vpatterninfogeometry.h"
#include <QKeyEvent> #include <QKeyEvent>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
@ -118,6 +119,8 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus
qDebug() << "VToolDetail" << patternInfo;
connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove);
connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolDetail::ResetChildren); connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolDetail::ResetChildren);
if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) if (typeCreation == Source::FromGui || typeCreation == Source::FromTool)
@ -142,6 +145,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo);
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel);
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo);
UpdateLabel(); UpdateLabel();
UpdatePatternInfo(); UpdatePatternInfo();
} }
@ -373,6 +377,15 @@ void VToolDetail::AddToFile()
} }
domElement.appendChild(domData); domElement.appendChild(domData);
domData = doc->createElement(VAbstractPattern::TagPatternInfo);
const VPatternInfoGeometry& geom = detail.GetPatternInfo();
doc->SetAttribute(domData, AttrMx, geom.GetPos().x());
doc->SetAttribute(domData, AttrMy, geom.GetPos().y());
doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, geom.GetFontSize());
doc->SetAttribute(domData, AttrRotation, geom.GetRotation());
for (int i = 0; i < detail.CountNode(); ++i) for (int i = 0; i < detail.CountNode(); ++i)
{ {
AddNode(doc, domElement, detail.at(i)); AddNode(doc, domElement, detail.at(i));
@ -422,6 +435,15 @@ void VToolDetail::RefreshDataInFile()
} }
domElement.appendChild(domData); domElement.appendChild(domData);
domData = doc->createElement(VAbstractPattern::TagPatternInfo);
const VPatternInfoGeometry& geom = det.GetPatternInfo();
doc->SetAttribute(domData, AttrMx, geom.GetPos().x());
doc->SetAttribute(domData, AttrMy, geom.GetPos().y());
doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth());
doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight());
doc->SetAttribute(domData, AttrFont, geom.GetFontSize());
doc->SetAttribute(domData, AttrRotation, geom.GetRotation());
for (int i = 0; i < det.CountNode(); ++i) for (int i = 0; i < det.CountNode(); ++i)
{ {
AddNode(doc, domElement, det.at(i)); AddNode(doc, domElement, det.at(i));
@ -708,17 +730,19 @@ void VToolDetail::UpdateLabel()
*/ */
void VToolDetail::UpdatePatternInfo() void VToolDetail::UpdatePatternInfo()
{ {
const VDetail detail = VAbstractTool::data.GetDetail(id);
const VPatternInfoGeometry& geom = detail.GetPatternInfo();
//patternInfo->Reset(); //patternInfo->Reset();
QFont fnt = qApp->font(); QFont fnt = qApp->font();
int iFS = doc->GetFontSize(); int iFS = geom.GetFontSize();
if (iFS < MIN_FONT_SIZE) if (iFS < MIN_FONT_SIZE)
{ {
iFS = MIN_FONT_SIZE; iFS = MIN_FONT_SIZE;
} }
fnt.setPixelSize(iFS); fnt.setPixelSize(iFS);
patternInfo->SetFont(fnt); patternInfo->SetFont(fnt);
QSizeF sz = doc->GetLabelSize(); patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight());
patternInfo->SetSize(sz.width(), sz.height());
patternInfo->Clear(); patternInfo->Clear();
TextLine tl; TextLine tl;
@ -752,8 +776,8 @@ void VToolDetail::UpdatePatternInfo()
tl.m_qsText = qslDate.last(); tl.m_qsText = qslDate.last();
patternInfo->AddLine(tl); patternInfo->AddLine(tl);
patternInfo->setPos(doc->GetLabelPosition()); patternInfo->setPos(geom.GetPos());
patternInfo->setRotation(doc->GetRotation()); patternInfo->setRotation(geom.GetRotation());
patternInfo->Update(); patternInfo->Update();
} }
@ -802,7 +826,6 @@ void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize)
*/ */
void VToolDetail::SaveRotationDetail(qreal dRot) void VToolDetail::SaveRotationDetail(qreal dRot)
{ {
qDebug() << "SAVEROTATION" << dRot;
VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet; VDetail newDet = oldDet;
newDet.GetPatternPieceData().SetPos(dataLabel->pos()); newDet.GetPatternPieceData().SetPos(dataLabel->pos());
@ -824,8 +847,19 @@ void VToolDetail::SaveRotationDetail(qreal dRot)
*/ */
void VToolDetail::SaveMovePattern(QPointF ptPos) void VToolDetail::SaveMovePattern(QPointF ptPos)
{ {
qDebug() << "Pattern moved to" << ptPos; VDetail oldDet = VAbstractTool::data.GetDetail(id);
doc->SetLabelPosition(ptPos); VDetail newDet = oldDet;
newDet.GetPatternInfo().SetPos(ptPos);
newDet.GetPatternInfo().SetLabelWidth(patternInfo->boundingRect().width());
newDet.GetPatternInfo().SetLabelHeight(patternInfo->boundingRect().height());
newDet.GetPatternInfo().SetFontSize(patternInfo->GetFontSize());
newDet.GetPatternInfo().SetRotation(patternInfo->rotation());
SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
moveCommand->setText(tr("move pattern info label"));
connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(moveCommand);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -834,14 +868,33 @@ void VToolDetail::SaveMovePattern(QPointF ptPos)
*/ */
void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize) void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize)
{ {
doc->SetLabelSize(QSizeF(dLabelW, patternInfo->boundingRect().height())); VDetail oldDet = VAbstractTool::data.GetDetail(id);
doc->SetFontSize(iFontSize); VDetail newDet = oldDet;
newDet.GetPatternInfo().SetLabelWidth(dLabelW);
newDet.GetPatternInfo().SetLabelHeight(patternInfo->boundingRect().height());
newDet.GetPatternInfo().SetFontSize(iFontSize);
newDet.GetPatternInfo().SetRotation(patternInfo->rotation());
SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
resizeCommand->setText(tr("resize pattern info label"));
connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(resizeCommand);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolDetail::SaveRotationPattern(qreal dRot) void VToolDetail::SaveRotationPattern(qreal dRot)
{ {
doc->SetRotation(dRot); VDetail oldDet = VAbstractTool::data.GetDetail(id);
VDetail newDet = oldDet;
newDet.GetPatternInfo().SetPos(patternInfo->pos());
newDet.GetPatternInfo().SetLabelWidth(patternInfo->boundingRect().width());
newDet.GetPatternInfo().SetLabelHeight(patternInfo->boundingRect().height());
newDet.GetPatternInfo().SetFontSize(patternInfo->GetFontSize());
newDet.GetPatternInfo().SetRotation(dRot);
SaveDetailOptions* rotateCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
rotateCommand->setText(tr("rotate pattern info label"));
connect(rotateCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
qApp->getUndoStack()->push(rotateCommand);
} }

View File

@ -31,6 +31,7 @@
#include "../../vwidgets/vmaingraphicsview.h" #include "../../vwidgets/vmaingraphicsview.h"
#include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vabstractpattern.h"
#include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatternpiecedata.h"
#include "../vpatterndb/vpatterninfogeometry.h"
#include <QGraphicsView> #include <QGraphicsView>
@ -58,6 +59,7 @@ void SaveDetailOptions::undo()
SaveDet(domElement, oldDet); SaveDet(domElement, oldDet);
doc->RemoveAllChildren(domElement); doc->RemoveAllChildren(domElement);
SavePatternPieceData(domElement, oldDet); SavePatternPieceData(domElement, oldDet);
SavePatternInfo(domElement, oldDet);
for (int i = 0; i < oldDet.CountNode(); ++i) for (int i = 0; i < oldDet.CountNode(); ++i)
{ {
VToolDetail::AddNode(doc, domElement, oldDet.at(i)); VToolDetail::AddNode(doc, domElement, oldDet.at(i));
@ -83,6 +85,7 @@ void SaveDetailOptions::redo()
SaveDet(domElement, newDet); SaveDet(domElement, newDet);
doc->RemoveAllChildren(domElement); doc->RemoveAllChildren(domElement);
SavePatternPieceData(domElement, newDet); SavePatternPieceData(domElement, newDet);
SavePatternInfo(domElement, newDet);
for (int i = 0; i < newDet.CountNode(); ++i) for (int i = 0; i < newDet.CountNode(); ++i)
{ {
@ -156,3 +159,18 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet
} }
domElement.appendChild(domData); domElement.appendChild(domData);
} }
//---------------------------------------------------------------------------------------------------------------------
void SaveDetailOptions::SavePatternInfo(QDomElement &domElement, const VDetail &det)
{
QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo);
const VPatternInfoGeometry& data = det.GetPatternInfo();
doc->SetAttribute(domData, AttrMx, data.GetPos().x());
doc->SetAttribute(domData, AttrMy, data.GetPos().y());
doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth());
doc->SetAttribute(domData, VToolDetail::AttrHeight, data.GetLabelHeight());
doc->SetAttribute(domData, VToolDetail::AttrFont, data.GetFontSize());
doc->SetAttribute(domData, VToolDetail::AttrRotation, data.GetRotation());
domElement.appendChild(domData);
}

View File

@ -54,6 +54,7 @@ private:
QGraphicsScene *scene; QGraphicsScene *scene;
void SaveDet(QDomElement &domElement, const VDetail &det); void SaveDet(QDomElement &domElement, const VDetail &det);
void SavePatternPieceData(QDomElement &domElement, const VDetail &det); void SavePatternPieceData(QDomElement &domElement, const VDetail &det);
void SavePatternInfo(QDomElement &domElement, const VDetail &det);
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------