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

View File

@ -60,7 +60,8 @@ const QString VAbstractPattern::TagGradation = QStringLiteral("gradation");
const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); 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::TagMCP = QStringLiteral("mcp");
const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrName = QStringLiteral("name");
const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); 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::AttrTool = QStringLiteral("tool");
const QString VAbstractPattern::AttrType = QStringLiteral("type"); const QString VAbstractPattern::AttrType = QStringLiteral("type");
const QString VAbstractPattern::AttrLetter = QStringLiteral("letter"); 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"); const QString VAbstractPattern::AttrAll = QStringLiteral("all");

View File

@ -156,6 +156,7 @@ 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 TagMCP;
static const QString AttrName; static const QString AttrName;
static const QString AttrVisible; static const QString AttrVisible;
@ -163,6 +164,10 @@ public:
static const QString AttrTool; static const QString AttrTool;
static const QString AttrType; static const QString AttrType;
static const QString AttrLetter; static const QString AttrLetter;
static const QString AttrMaterial;
static const QString AttrUserDefined;
static const QString AttrCutNumber;
static const QString AttrPlacement;
static const QString AttrAll; static const QString AttrAll;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -331,6 +331,21 @@ void VToolDetail::AddToFile()
doc->SetAttribute(domElement, AttrClosed, static_cast<quint8>(detail.getClosed())); doc->SetAttribute(domElement, AttrClosed, static_cast<quint8>(detail.getClosed()));
doc->SetAttribute(domElement, AttrWidth, detail.getWidth()); 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) for (int i = 0; i < detail.CountNode(); ++i)
{ {
AddNode(doc, domElement, detail.at(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, AttrClosed, QString().setNum(static_cast<quint8>(det.getClosed())));
doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth()));
doc->RemoveAllChildren(domElement); 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) for (int i = 0; i < det.CountNode(); ++i)
{ {
AddNode(doc, domElement, det.at(i)); AddNode(doc, domElement, det.at(i));

View File

@ -27,8 +27,10 @@
*************************************************************************/ *************************************************************************/
#include "savedetailoptions.h" #include "savedetailoptions.h"
#include "vpatternpiecedata.h"
#include "../tools/nodeDetails/vabstractnode.h" #include "../tools/nodeDetails/vabstractnode.h"
#include "../../vwidgets/vmaingraphicsview.h" #include "../../vwidgets/vmaingraphicsview.h"
#include "../ifc/xml/vabstractpattern.h"
#include <QGraphicsView> #include <QGraphicsView>
@ -79,6 +81,22 @@ void SaveDetailOptions::redo()
{ {
SaveDet(domElement, newDet); SaveDet(domElement, newDet);
doc->RemoveAllChildren(domElement); 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) for (int i = 0; i < newDet.CountNode(); ++i)
{ {
VToolDetail::AddNode(doc, domElement, newDet.at(i)); VToolDetail::AddNode(doc, domElement, newDet.at(i));