Position, size and font size of the text label are now saved into VDetail DOM tree. Undo/Redo for moving and resizing the label works.
--HG-- branch : feature
This commit is contained in:
parent
fd47065ae2
commit
6fbffd2834
|
@ -641,6 +641,14 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
|
|||
detail.GetPatternPieceData().SetName(qsName);
|
||||
QString qsLetter = element.attribute(AttrLetter, "");
|
||||
detail.GetPatternPieceData().SetLetter(qsLetter);
|
||||
QPointF ptPos;
|
||||
ptPos.setX(element.attribute(AttrMx, "0").toDouble());
|
||||
ptPos.setY(element.attribute(AttrMy, "0").toDouble());
|
||||
detail.GetPatternPieceData().SetPos(ptPos);
|
||||
qreal dLW = element.attribute(VToolDetail::AttrWidth, "0").toDouble();
|
||||
detail.GetPatternPieceData().SetLabelWidth(dLW);
|
||||
int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt();
|
||||
detail.GetPatternPieceData().SetFontSize(iFS);
|
||||
|
||||
QDomNodeList nodeListMCP = element.childNodes();
|
||||
for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP)
|
||||
|
|
|
@ -29,8 +29,13 @@
|
|||
#include "vpatternpiecedata.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPatternPieceData::VPatternPieceData()
|
||||
{}
|
||||
VPatternPieceData::VPatternPieceData() :
|
||||
m_ptPos(0, 0)
|
||||
{
|
||||
m_iFontSize = MIN_FONT_SIZE;
|
||||
// 0 means unknown width
|
||||
m_dLabelWidth = 0;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VPatternPieceData::~VPatternPieceData()
|
||||
|
@ -113,4 +118,43 @@ void VPatternPieceData::SetName(QString qsName)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPointF VPatternPieceData::GetPos() const
|
||||
{
|
||||
return m_ptPos;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPatternPieceData::SetPos(const QPointF& ptPos)
|
||||
{
|
||||
m_ptPos = ptPos;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal VPatternPieceData::GetLabelWidth() const
|
||||
{
|
||||
return m_dLabelWidth;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPatternPieceData::SetLabelWidth(qreal dLabelW)
|
||||
{
|
||||
m_dLabelWidth = dLabelW;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int VPatternPieceData::GetFontSize() const
|
||||
{
|
||||
return m_iFontSize;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VPatternPieceData::SetFontSize(int iSize)
|
||||
{
|
||||
if (iSize >= MIN_FONT_SIZE)
|
||||
m_iFontSize = iSize;
|
||||
else
|
||||
m_iFontSize = MIN_FONT_SIZE;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -29,8 +29,11 @@
|
|||
#ifndef VPATTERNPIECEDATA_H
|
||||
#define VPATTERNPIECEDATA_H
|
||||
|
||||
#define MIN_FONT_SIZE 24
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QPointF>
|
||||
|
||||
enum class MaterialType : char
|
||||
{
|
||||
|
@ -81,6 +84,14 @@ public:
|
|||
const QString& GetName() const;
|
||||
void SetName(QString qsName);
|
||||
|
||||
// methods, which set up label parameters
|
||||
QPointF GetPos() const;
|
||||
void SetPos(const QPointF& ptPos);
|
||||
qreal GetLabelWidth() const;
|
||||
void SetLabelWidth(qreal dLabelW);
|
||||
int GetFontSize() const;
|
||||
void SetFontSize(int iSize);
|
||||
|
||||
private:
|
||||
/** @brief Pattern piece name
|
||||
*/
|
||||
|
@ -91,6 +102,15 @@ private:
|
|||
/** @brief List of material, cut number and placement 3-tuples
|
||||
*/
|
||||
MCPContainer m_conMCP;
|
||||
/** @brief Location of the label
|
||||
*/
|
||||
QPointF m_ptPos;
|
||||
/** @brief Label width
|
||||
*/
|
||||
qreal m_dLabelWidth;
|
||||
/** @brief Label font size
|
||||
*/
|
||||
int m_iFontSize;
|
||||
};
|
||||
|
||||
#endif // VPATTERNPIECEDATA_H
|
||||
|
|
|
@ -156,6 +156,12 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *pME)
|
|||
if (m_eMode == mMove)
|
||||
{
|
||||
m_eMode = mActivated;
|
||||
emit SignalMoved(pos());
|
||||
}
|
||||
else if (m_eMode == mResize)
|
||||
{
|
||||
m_eMode = mActivated;
|
||||
emit SignalResized(textWidth(), font().pixelSize());
|
||||
}
|
||||
Update();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
class VTextGraphicsItem : public QGraphicsTextItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum Mode {
|
||||
mNormal,
|
||||
mActivated,
|
||||
|
@ -51,6 +53,10 @@ public:
|
|||
void Reset();
|
||||
void SetHTML(const QString& qsHTML);
|
||||
|
||||
signals:
|
||||
void SignalMoved(QPointF ptPos);
|
||||
void SignalResized(qreal dTW, int iFontSize);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent* pME);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent* pME);
|
||||
|
|
|
@ -55,6 +55,7 @@ const QString VToolDetail::AttrClosed = QStringLiteral("closed");
|
|||
const QString VToolDetail::AttrWidth = QStringLiteral("width");
|
||||
const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType");
|
||||
const QString VToolDetail::AttrReverse = QStringLiteral("reverse");
|
||||
const QString VToolDetail::AttrFont = QStringLiteral("fontSize");
|
||||
|
||||
const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour");
|
||||
const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling");
|
||||
|
@ -126,6 +127,9 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32
|
|||
}
|
||||
}
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMove);
|
||||
connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResize);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -298,6 +302,7 @@ void VToolDetail::FullUpdateFromGuiOk(int result)
|
|||
{
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
qDebug() << "FullUpdate" << qApp->getUndoStack()->count();
|
||||
SCASSERT(dialog != nullptr);
|
||||
DialogDetail *dialogTool = qobject_cast<DialogDetail*>(dialog);
|
||||
SCASSERT(dialogTool != nullptr);
|
||||
|
@ -305,15 +310,10 @@ void VToolDetail::FullUpdateFromGuiOk(int result)
|
|||
VDetail newDet = dialogTool->getDetail();
|
||||
VDetail oldDet = VAbstractTool::data.GetDetail(id);
|
||||
|
||||
qDebug() << "VTOOL" << newDet.GetPatternPieceData().GetLetter()
|
||||
<< newDet.GetPatternPieceData().GetName()
|
||||
<< newDet.GetPatternPieceData().GetMCPCount()
|
||||
<< dialogTool->getDetail().GetPatternPieceData().GetName();
|
||||
|
||||
|
||||
SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
|
||||
connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
||||
qApp->getUndoStack()->push(saveCommand);
|
||||
qDebug() << "FullUpdate finished" << qApp->getUndoStack()->count();
|
||||
}
|
||||
delete dialog;
|
||||
dialog = nullptr;
|
||||
|
@ -337,11 +337,17 @@ void VToolDetail::AddToFile()
|
|||
doc->SetAttribute(domElement, AttrWidth, detail.getWidth());
|
||||
|
||||
QDomElement domData = doc->createElement(VAbstractPattern::TagData);
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, detail.GetPatternPieceData().GetLetter());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrName, detail.GetPatternPieceData().GetName());
|
||||
for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i)
|
||||
const VPatternPieceData& data = detail.GetPatternPieceData();
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName());
|
||||
doc->SetAttribute(domData, AttrMx, data.GetPos().x());
|
||||
doc->SetAttribute(domData, AttrMy, data.GetPos().y());
|
||||
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth());
|
||||
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
|
||||
|
||||
for (int i = 0; i < data.GetMCPCount(); ++i)
|
||||
{
|
||||
MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(i);
|
||||
MaterialCutPlacement mcp = data.GetMCP(i);
|
||||
QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP);
|
||||
doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial));
|
||||
doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef);
|
||||
|
@ -378,11 +384,17 @@ void VToolDetail::RefreshDataInFile()
|
|||
doc->RemoveAllChildren(domElement);
|
||||
|
||||
QDomElement domData = doc->createElement(VAbstractPattern::TagData);
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, det.GetPatternPieceData().GetLetter());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrName, det.GetPatternPieceData().GetName());
|
||||
for (int i = 0; i < det.GetPatternPieceData().GetMCPCount(); ++i)
|
||||
const VPatternPieceData& data = det.GetPatternPieceData();
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName());
|
||||
doc->SetAttribute(domData, AttrMx, data.GetPos().x());
|
||||
doc->SetAttribute(domData, AttrMy, data.GetPos().y());
|
||||
doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth());
|
||||
doc->SetAttribute(domData, AttrFont, data.GetFontSize());
|
||||
|
||||
for (int i = 0; i < data.GetMCPCount(); ++i)
|
||||
{
|
||||
MaterialCutPlacement mcp = det.GetPatternPieceData().GetMCP(i);
|
||||
MaterialCutPlacement mcp = data.GetMCP(i);
|
||||
QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP);
|
||||
doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial));
|
||||
doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef);
|
||||
|
@ -617,6 +629,37 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief SaveMove saves the move operation to the undo stack
|
||||
*/
|
||||
void VToolDetail::SaveMove(QPointF ptPos)
|
||||
{
|
||||
VDetail oldDet = VAbstractTool::data.GetDetail(id);
|
||||
VDetail newDet = oldDet;
|
||||
newDet.GetPatternPieceData().SetPos(ptPos);
|
||||
SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
|
||||
moveCommand->setText(tr("move pattern piece label"));
|
||||
connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
||||
qApp->getUndoStack()->push(moveCommand);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief: SaveResize save the resize label operation to the undo stack
|
||||
*/
|
||||
void VToolDetail::SaveResize(qreal dLabelW, int iFontSize)
|
||||
{
|
||||
VDetail oldDet = VAbstractTool::data.GetDetail(id);
|
||||
VDetail newDet = oldDet;
|
||||
newDet.GetPatternPieceData().SetLabelWidth(dLabelW);
|
||||
newDet.GetPatternPieceData().SetFontSize(iFontSize);
|
||||
SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene());
|
||||
resizeCommand->setText(tr("resize pattern piece label"));
|
||||
connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
||||
qApp->getUndoStack()->push(resizeCommand);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* @brief AddNode add node to the file.
|
||||
|
@ -717,7 +760,7 @@ void VToolDetail::RefreshGeometry()
|
|||
QStringList qslPlace;
|
||||
qslPlace << "" << " on Fold";
|
||||
QFont fnt = qApp->font();
|
||||
fnt.setPixelSize(24);
|
||||
fnt.setPixelSize(data.GetFontSize());
|
||||
QFontMetrics fm(fnt);
|
||||
dataLabel->setFont(fnt);
|
||||
int iMinW = 200;
|
||||
|
@ -733,7 +776,12 @@ void VToolDetail::RefreshGeometry()
|
|||
}
|
||||
// also add some offset
|
||||
dataLabel->SetMinimalWidth(iMinW + 10);
|
||||
if (data.GetLabelWidth() > iMinW)
|
||||
{
|
||||
dataLabel->setTextWidth(data.GetLabelWidth());
|
||||
}
|
||||
dataLabel->SetHTML(qsHTML);
|
||||
dataLabel->setPos(data.GetPos());
|
||||
dataLabel->show();
|
||||
}
|
||||
else
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
static const QString AttrWidth;
|
||||
static const QString AttrNodeType;
|
||||
static const QString AttrReverse;
|
||||
static const QString AttrFont;
|
||||
static const QString NodeTypeContour;
|
||||
static const QString NodeTypeModeling;
|
||||
static const QString NodeArc;
|
||||
|
@ -103,6 +104,11 @@ protected:
|
|||
virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE;
|
||||
virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE;
|
||||
virtual void SetVisualization() Q_DECL_OVERRIDE {}
|
||||
|
||||
protected slots:
|
||||
virtual void SaveMove(QPointF ptPos);
|
||||
virtual void SaveResize(qreal dLabelW, int iFontSize);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VToolDetail)
|
||||
/** @brief dialog dialog options. */
|
||||
|
|
|
@ -106,7 +106,7 @@ bool SaveDetailOptions::mergeWith(const QUndoCommand *command)
|
|||
SCASSERT(saveCommand != nullptr);
|
||||
const quint32 id = saveCommand->getDetId();
|
||||
|
||||
if (id != nodeId)
|
||||
if (id != nodeId || text() != command->text())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -134,11 +134,16 @@ void SaveDetailOptions::SaveDet(QDomElement &domElement, const VDetail &det)
|
|||
void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDetail &det)
|
||||
{
|
||||
QDomElement domData = doc->createElement(VAbstractPattern::TagData);
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, det.GetPatternPieceData().GetLetter());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrName, det.GetPatternPieceData().GetName());
|
||||
for (int i = 0; i < det.GetPatternPieceData().GetMCPCount(); ++i)
|
||||
const VPatternPieceData& data = det.GetPatternPieceData();
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter());
|
||||
doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName());
|
||||
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::AttrFont, data.GetFontSize());
|
||||
for (int i = 0; i < data.GetMCPCount(); ++i)
|
||||
{
|
||||
MaterialCutPlacement mcp = det.GetPatternPieceData().GetMCP(i);
|
||||
MaterialCutPlacement mcp = data.GetMCP(i);
|
||||
QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP);
|
||||
doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial));
|
||||
doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef);
|
||||
|
|
Loading…
Reference in New Issue
Block a user