Finished the detail dialog

--HG--
branch : feature
This commit is contained in:
BojanKverh 2016-06-21 00:49:22 +02:00
parent 9386ae2ff1
commit c05c51e078
10 changed files with 111 additions and 20 deletions

View File

@ -47,6 +47,7 @@
#include "../vgeometry/vcubicbezierpath.h"
#include "../core/vapplication.h"
#include "../vpatterndb/calculator.h"
#include "vpatternpiecedata.h"
#include <QMessageBox>
#include <QUndoStack>
@ -580,6 +581,11 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null");
try
{
QString qs;
QTextStream ts(&qs, QIODevice::WriteOnly);
domElement.save(ts, 2);
qDebug() << "Parse detail" << qs;
VDetail detail;
const quint32 id = GetParametrId(domElement);
detail.setName(GetParametrString(domElement, AttrName, ""));
@ -628,21 +634,26 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document
throw e;
}
detail.append(VNodeDetail(id, tool, nodeType, mx, my, reverse));
}/*
}
else if (element.tagName() == TagData)
{
try
{
QString qsName = GetParametrString(element, AttrName);
QString qsName = element.attribute(AttrName, "");
detail.GetPatternPieceData().SetName(qsName);
QString qsLetter = GetParametrString(element, AttrLetter);
QString qsLetter = element.attribute(AttrLetter, "");
detail.GetPatternPieceData().SetLetter(qsLetter);
qDebug() << "Data" << qsName << qsLetter;
}
catch(const VException& e)
QDomNodeList nodeListMCP = element.childNodes();
for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP)
{
MaterialCutPlacement mcp;
QDomElement domMCP = nodeListMCP.at(iMCP).toElement();
mcp.m_eMaterial = MaterialType(GetParametrUInt(domMCP, AttrMaterial, 0));
mcp.m_qsMaterialUserDef = GetParametrString(domMCP, AttrUserDefined, "");
mcp.m_iCutNumber = GetParametrUInt(domMCP, AttrCutNumber, 0);
mcp.m_ePlacement = PlacementType(GetParametrUInt(domMCP, AttrPlacement, 0));
detail.GetPatternPieceData().Append(mcp);
}
}
}*/
}
}
VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile);

View File

@ -61,6 +61,7 @@ const QString VAbstractPattern::TagHeights = QStringLiteral("heights");
const QString VAbstractPattern::TagSizes = QStringLiteral("sizes");
const QString VAbstractPattern::TagUnit = QStringLiteral("unit");
const QString VAbstractPattern::TagData = QStringLiteral("data");
const QString VAbstractPattern::TagMCP = QStringLiteral("mcp");
const QString VAbstractPattern::AttrName = QStringLiteral("name");
const QString VAbstractPattern::AttrVisible = QStringLiteral("visible");
@ -68,6 +69,10 @@ const QString VAbstractPattern::AttrObject = QStringLiteral("object");
const QString VAbstractPattern::AttrTool = QStringLiteral("tool");
const QString VAbstractPattern::AttrType = QStringLiteral("type");
const QString VAbstractPattern::AttrLetter = QStringLiteral("letter");
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::AttrAll = QStringLiteral("all");

View File

@ -156,6 +156,7 @@ public:
static const QString TagSizes;
static const QString TagUnit;
static const QString TagData;
static const QString TagMCP;
static const QString AttrName;
static const QString AttrVisible;
@ -163,6 +164,10 @@ public:
static const QString AttrTool;
static const QString AttrType;
static const QString AttrLetter;
static const QString AttrMaterial;
static const QString AttrUserDefined;
static const QString AttrCutNumber;
static const QString AttrPlacement;
static const QString AttrAll;

View File

@ -92,6 +92,7 @@ void VDetail::Clear()
d->nodes.clear();
d->mx = 0;
d->my = 0;
GetPatternPieceData().Clear();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -80,6 +80,14 @@ void VPatternPieceData::RemoveMCP(int i)
m_conMCP.removeAt(i);
}
//---------------------------------------------------------------------------------------------------------------------
void VPatternPieceData::Clear()
{
m_qsLetter = "";
m_qsName = "";
m_conMCP.clear();
}
//---------------------------------------------------------------------------------------------------------------------
const QString& VPatternPieceData::GetLetter() const
{

View File

@ -73,6 +73,7 @@ public:
int GetMCPCount() const;
const MaterialCutPlacement& GetMCP(int i) const;
void RemoveMCP(int i);
void Clear();
// methods, which operate on other members
const QString& GetLetter() const;

View File

@ -171,9 +171,9 @@ void DialogDetail::CheckState()
void DialogDetail::UpdateList()
{
ui.listWidgetMCP->clear();
for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i)
for (int i = 0; i < m_conMCP.count(); ++i)
{
MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(i);
MaterialCutPlacement mcp = m_conMCP[i];
QString qsText = tr("Cut %1 of %2%3").arg(mcp.m_iCutNumber);
if (mcp.m_eMaterial < MaterialType::mtUserDefined)
{
@ -215,13 +215,13 @@ void DialogDetail::AddUpdate()
if (m_bAddMode == true)
{
detail.GetPatternPieceData().Append(mcp);
m_conMCP << mcp;
}
else
{
int iR = ui.listWidgetMCP->currentRow();
SCASSERT(iR >= 0);
detail.GetPatternPieceData().Set(iR, mcp);
m_conMCP[iR] = mcp;
SetAddMode();
}
UpdateList();
@ -240,7 +240,7 @@ void DialogDetail::Remove()
{
int iR = ui.listWidgetMCP->currentRow();
SCASSERT(iR >= 0);
detail.GetPatternPieceData().RemoveMCP(iR);
m_conMCP.removeAt(iR);
UpdateList();
ClearFields();
SetAddMode();
@ -342,9 +342,10 @@ VDetail DialogDetail::CreateDetail() const
detail.GetPatternPieceData().SetLetter(ui.lineEditLetter->text());
detail.GetPatternPieceData().SetName(ui.lineEditName->text());
qDebug() << "DD" << detail.GetPatternPieceData().GetLetter()
<< detail.GetPatternPieceData().GetName()
<< detail.GetPatternPieceData().GetMCPCount();
for (int i = 0; i < m_conMCP.count(); ++i)
{
detail.GetPatternPieceData().Append(m_conMCP[i]);
}
return detail;
}
@ -396,6 +397,13 @@ void DialogDetail::setDetail(const VDetail &value)
ui.lineEditLetter->setText(detail.GetPatternPieceData().GetLetter());
ui.lineEditName->setText(detail.GetPatternPieceData().GetName());
m_conMCP.clear();
for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i)
{
m_conMCP << detail.GetPatternPieceData().GetMCP(i);
}
UpdateList();
ValidObjects(DetailIsValid());

View File

@ -32,6 +32,7 @@
#include "ui_dialogdetail.h"
#include "dialogtool.h"
#include "../vpatterndb/vdetail.h"
#include "vpatternpiecedata.h"
/**
* @brief The DialogDetail class dialog for ToolDetai. Help create detail and edit option.
@ -97,6 +98,8 @@ private:
QStringList m_qslMaterials;
QStringList m_qslPlacements;
// temporary container for Material/Cut/Placement 3-tuples
MCPContainer m_conMCP;
void ClearFields();

View File

@ -331,6 +331,21 @@ void VToolDetail::AddToFile()
doc->SetAttribute(domElement, AttrClosed, static_cast<quint8>(detail.getClosed()));
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)
{
MaterialCutPlacement mcp = detail.GetPatternPieceData().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);
doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber);
doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement));
domData.appendChild(domMCP);
}
domElement.appendChild(domData);
for (int i = 0; i < detail.CountNode(); ++i)
{
AddNode(doc, domElement, detail.at(i));
@ -356,6 +371,22 @@ void VToolDetail::RefreshDataInFile()
doc->SetAttribute(domElement, AttrClosed, QString().setNum(static_cast<quint8>(det.getClosed())));
doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth()));
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)
{
MaterialCutPlacement mcp = det.GetPatternPieceData().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);
doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber);
doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement));
domData.appendChild(domMCP);
}
domElement.appendChild(domData);
for (int i = 0; i < det.CountNode(); ++i)
{
AddNode(doc, domElement, det.at(i));

View File

@ -27,8 +27,10 @@
*************************************************************************/
#include "savedetailoptions.h"
#include "vpatternpiecedata.h"
#include "../tools/nodeDetails/vabstractnode.h"
#include "../../vwidgets/vmaingraphicsview.h"
#include "../ifc/xml/vabstractpattern.h"
#include <QGraphicsView>
@ -79,6 +81,22 @@ void SaveDetailOptions::redo()
{
SaveDet(domElement, newDet);
doc->RemoveAllChildren(domElement);
QDomElement domData = doc->createElement(VAbstractPattern::TagData);
doc->SetAttribute(domData, VAbstractPattern::AttrLetter, newDet.GetPatternPieceData().GetLetter());
doc->SetAttribute(domData, VAbstractPattern::AttrName, newDet.GetPatternPieceData().GetName());
for (int i = 0; i < newDet.GetPatternPieceData().GetMCPCount(); ++i)
{
MaterialCutPlacement mcp = newDet.GetPatternPieceData().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);
doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber);
doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement));
domData.appendChild(domMCP);
}
domElement.appendChild(domData);
for (int i = 0; i < newDet.CountNode(); ++i)
{
VToolDetail::AddNode(doc, domElement, newDet.at(i));