Complited refactoring VPattern.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-06-16 12:04:48 +03:00
parent f166f2521b
commit d969cfb2d5
4 changed files with 468 additions and 461 deletions

View file

@ -52,8 +52,7 @@
//---------------------------------------------------------------------------------------------------------------------
VPattern::VPattern(VContainer *data, Draw *mode, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail, QObject *parent)
: VAbstractPattern(parent), data(data), patternPieces(QStringList()), mode(mode), sceneDraw(sceneDraw),
sceneDetail(sceneDetail)
: VAbstractPattern(parent), data(data), mode(mode), sceneDraw(sceneDraw), sceneDetail(sceneDetail)
{
SCASSERT(sceneDraw != nullptr);
SCASSERT(sceneDetail != nullptr);
@ -409,38 +408,6 @@ void VPattern::LiteParseTree(const Document &parse)
qCDebug(vXML, "Scene size updated.");
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief haveLiteChange we have unsaved change.
*/
void VPattern::haveLiteChange()
{
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowHistoryTool hightlight tool.
* @param id tool id.
* @param enable enable or diasable hightlight.
*/
void VPattern::ShowHistoryTool(quint32 id, bool enable)
{
emit ShowTool(id, enable);
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::NeedFullParsing()
{
emit UndoCommand();
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::ClearScene()
{
emit ClearMainWindow();
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
void VPattern::customEvent(QEvent *event)
@ -1356,75 +1323,6 @@ void VPattern::ParseCurrentPP()
emit CheckLayout();
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::CheckTagExists(const QString &tag)
{
QDomNodeList list = elementsByTagName(tag);
if (list.size() == 0)
{
QStringList tags = QStringList() << TagVersion << TagAuthor << TagDescription << TagNotes << TagGradation;
QDomElement pattern = documentElement();
switch (tags.indexOf(tag))
{
case 0: //TagVersion
break;// Mandatory tag
case 1: //TagAuthor
pattern.insertAfter(createElement(TagAuthor), elementsByTagName(TagVersion).at(0));
SetVersion();
break;
case 2: //TagDescription
{
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
{
QDomNodeList list = elementsByTagName(tags.at(i));
if (list.isEmpty())
{
continue;
}
pattern.insertAfter(createElement(TagDescription), list.at(0));
}
SetVersion();
break;
}
case 3: //TagNotes
{
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
{
QDomNodeList list = elementsByTagName(tags.at(i));
if (list.isEmpty())
{
continue;
}
pattern.insertAfter(createElement(TagNotes), list.at(0));
}
SetVersion();
break;
}
case 4: //TagGradation
{
QDomElement gradation = createElement(TagGradation);
gradation.appendChild(createElement(TagHeights));
gradation.appendChild(createElement(TagSizes));
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
{
QDomNodeList list = elementsByTagName(tags.at(i));
if (list.isEmpty())
{
continue;
}
pattern.insertAfter(gradation, list.at(0));
break;
}
SetVersion();
break;
}
default:
break;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VPattern::GetLabelBase(unsigned int index) const
{
@ -1834,288 +1732,6 @@ void VPattern::ParseIncrementsElement(const QDomNode &node)
}
}
//---------------------------------------------------------------------------------------------------------------------
QMap<GHeights, bool> VPattern::GetGradationHeights() const
{
QMap<GHeights, bool> map;
map.insert(GHeights::ALL, true);
map.insert(GHeights::H92, true);
map.insert(GHeights::H98, true);
map.insert(GHeights::H104, true);
map.insert(GHeights::H110, true);
map.insert(GHeights::H116, true);
map.insert(GHeights::H122, true);
map.insert(GHeights::H128, true);
map.insert(GHeights::H134, true);
map.insert(GHeights::H140, true);
map.insert(GHeights::H146, true);
map.insert(GHeights::H152, true);
map.insert(GHeights::H158, true);
map.insert(GHeights::H164, true);
map.insert(GHeights::H170, true);
map.insert(GHeights::H176, true);
map.insert(GHeights::H182, true);
map.insert(GHeights::H188, true);
map.insert(GHeights::H194, true);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
return map;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
const QString defValue = QStringLiteral("true");
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
if (GetParametrBool(domElement, AttrAll, defValue))
{
return map;
}
else
{
map.insert(GHeights::ALL, false);
}
map.insert(GHeights::H92, GetParametrBool(domElement, AttrH92, defValue));
map.insert(GHeights::H98, GetParametrBool(domElement, AttrH98, defValue));
map.insert(GHeights::H104, GetParametrBool(domElement, AttrH104, defValue));
map.insert(GHeights::H110, GetParametrBool(domElement, AttrH110, defValue));
map.insert(GHeights::H116, GetParametrBool(domElement, AttrH116, defValue));
map.insert(GHeights::H122, GetParametrBool(domElement, AttrH122, defValue));
map.insert(GHeights::H128, GetParametrBool(domElement, AttrH128, defValue));
map.insert(GHeights::H134, GetParametrBool(domElement, AttrH134, defValue));
map.insert(GHeights::H140, GetParametrBool(domElement, AttrH140, defValue));
map.insert(GHeights::H146, GetParametrBool(domElement, AttrH146, defValue));
map.insert(GHeights::H152, GetParametrBool(domElement, AttrH152, defValue));
map.insert(GHeights::H158, GetParametrBool(domElement, AttrH158, defValue));
map.insert(GHeights::H164, GetParametrBool(domElement, AttrH164, defValue));
map.insert(GHeights::H170, GetParametrBool(domElement, AttrH170, defValue));
map.insert(GHeights::H176, GetParametrBool(domElement, AttrH176, defValue));
map.insert(GHeights::H182, GetParametrBool(domElement, AttrH182, defValue));
map.insert(GHeights::H188, GetParametrBool(domElement, AttrH188, defValue));
map.insert(GHeights::H194, GetParametrBool(domElement, AttrH194, defValue));
return map;
break;
case 1: // TagSizes
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
return map;
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::SetGradationHeights(const QMap<GHeights, bool> &options)
{
CheckTagExists(TagGradation);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
return;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
SetAttribute(domElement, AttrAll, options.value(GHeights::ALL));
SetAttribute(domElement, AttrH92, options.value(GHeights::H92));
SetAttribute(domElement, AttrH98, options.value(GHeights::H98));
SetAttribute(domElement, AttrH104, options.value(GHeights::H104));
SetAttribute(domElement, AttrH110, options.value(GHeights::H110));
SetAttribute(domElement, AttrH116, options.value(GHeights::H116));
SetAttribute(domElement, AttrH122, options.value(GHeights::H122));
SetAttribute(domElement, AttrH128, options.value(GHeights::H128));
SetAttribute(domElement, AttrH134, options.value(GHeights::H134));
SetAttribute(domElement, AttrH140, options.value(GHeights::H140));
SetAttribute(domElement, AttrH146, options.value(GHeights::H146));
SetAttribute(domElement, AttrH152, options.value(GHeights::H152));
SetAttribute(domElement, AttrH158, options.value(GHeights::H158));
SetAttribute(domElement, AttrH164, options.value(GHeights::H164));
SetAttribute(domElement, AttrH170, options.value(GHeights::H170));
SetAttribute(domElement, AttrH176, options.value(GHeights::H176));
SetAttribute(domElement, AttrH182, options.value(GHeights::H182));
SetAttribute(domElement, AttrH188, options.value(GHeights::H188));
SetAttribute(domElement, AttrH194, options.value(GHeights::H194));
emit patternChanged(false);
return;
break;
case 1: // TagSizes
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
}
//---------------------------------------------------------------------------------------------------------------------
QMap<GSizes, bool> VPattern::GetGradationSizes() const
{
QMap<GSizes, bool> map;
map.insert(GSizes::ALL, true);
map.insert(GSizes::S22, true);
map.insert(GSizes::S24, true);
map.insert(GSizes::S26, true);
map.insert(GSizes::S28, true);
map.insert(GSizes::S30, true);
map.insert(GSizes::S32, true);
map.insert(GSizes::S34, true);
map.insert(GSizes::S36, true);
map.insert(GSizes::S38, true);
map.insert(GSizes::S40, true);
map.insert(GSizes::S42, true);
map.insert(GSizes::S44, true);
map.insert(GSizes::S46, true);
map.insert(GSizes::S48, true);
map.insert(GSizes::S50, true);
map.insert(GSizes::S52, true);
map.insert(GSizes::S54, true);
map.insert(GSizes::S56, true);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
return map;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
const QString defValue = QStringLiteral("true");
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
break;
case 1: // TagSizes
if (GetParametrBool(domElement, AttrAll, defValue))
{
return map;
}
else
{
map.insert(GSizes::ALL, false);
}
map.insert(GSizes::S22, GetParametrBool(domElement, AttrS22, defValue));
map.insert(GSizes::S24, GetParametrBool(domElement, AttrS24, defValue));
map.insert(GSizes::S26, GetParametrBool(domElement, AttrS26, defValue));
map.insert(GSizes::S28, GetParametrBool(domElement, AttrS28, defValue));
map.insert(GSizes::S30, GetParametrBool(domElement, AttrS30, defValue));
map.insert(GSizes::S32, GetParametrBool(domElement, AttrS32, defValue));
map.insert(GSizes::S34, GetParametrBool(domElement, AttrS34, defValue));
map.insert(GSizes::S36, GetParametrBool(domElement, AttrS36, defValue));
map.insert(GSizes::S38, GetParametrBool(domElement, AttrS38, defValue));
map.insert(GSizes::S40, GetParametrBool(domElement, AttrS40, defValue));
map.insert(GSizes::S42, GetParametrBool(domElement, AttrS42, defValue));
map.insert(GSizes::S44, GetParametrBool(domElement, AttrS44, defValue));
map.insert(GSizes::S46, GetParametrBool(domElement, AttrS46, defValue));
map.insert(GSizes::S48, GetParametrBool(domElement, AttrS48, defValue));
map.insert(GSizes::S50, GetParametrBool(domElement, AttrS50, defValue));
map.insert(GSizes::S52, GetParametrBool(domElement, AttrS52, defValue));
map.insert(GSizes::S54, GetParametrBool(domElement, AttrS54, defValue));
map.insert(GSizes::S56, GetParametrBool(domElement, AttrS56, defValue));
return map;
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
return map;
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::SetGradationSizes(const QMap<GSizes, bool> &options)
{
CheckTagExists(TagGradation);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
return;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
break;
case 1: // TagSizes
SetAttribute(domElement, AttrAll, options.value(GSizes::ALL));
SetAttribute(domElement, AttrS22, options.value(GSizes::S22));
SetAttribute(domElement, AttrS24, options.value(GSizes::S24));
SetAttribute(domElement, AttrS26, options.value(GSizes::S26));
SetAttribute(domElement, AttrS28, options.value(GSizes::S28));
SetAttribute(domElement, AttrS30, options.value(GSizes::S30));
SetAttribute(domElement, AttrS32, options.value(GSizes::S32));
SetAttribute(domElement, AttrS34, options.value(GSizes::S34));
SetAttribute(domElement, AttrS36, options.value(GSizes::S36));
SetAttribute(domElement, AttrS38, options.value(GSizes::S38));
SetAttribute(domElement, AttrS40, options.value(GSizes::S40));
SetAttribute(domElement, AttrS42, options.value(GSizes::S42));
SetAttribute(domElement, AttrS44, options.value(GSizes::S44));
SetAttribute(domElement, AttrS46, options.value(GSizes::S46));
SetAttribute(domElement, AttrS48, options.value(GSizes::S48));
SetAttribute(domElement, AttrS50, options.value(GSizes::S50));
SetAttribute(domElement, AttrS52, options.value(GSizes::S52));
SetAttribute(domElement, AttrS54, options.value(GSizes::S54));
SetAttribute(domElement, AttrS56, options.value(GSizes::S56));
emit patternChanged(false);
return;
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VPattern::GetAuthor() const
{
@ -2130,47 +1746,6 @@ void VPattern::SetAuthor(const QString &text)
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VPattern::GetDescription() const
{
return UniqueTagText(TagDescription);
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::SetDescription(const QString &text)
{
CheckTagExists(TagDescription);
setTagText(TagDescription, text);
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VPattern::GetNotes() const
{
return UniqueTagText(TagNotes);
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::SetNotes(const QString &text)
{
CheckTagExists(TagNotes);
setTagText(TagNotes, text);
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VPattern::GetVersion() const
{
return UniqueTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
}
//---------------------------------------------------------------------------------------------------------------------
void VPattern::SetVersion()
{
setTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VPattern::GenerateLabel(const LabelType &type) const
{

View file

@ -62,48 +62,28 @@ public:
quint32 SPointActiveDraw();
virtual bool SaveDocument(const QString &fileName, QString &error) const;
QStringList getPatternPieces() const;
QRectF ActiveDrawBoundingRect() const;
QMap<GHeights, bool> GetGradationHeights() const;
void SetGradationHeights(const QMap<GHeights, bool> &options);
QString GetAuthor() const;
void SetAuthor(const QString &text);
QMap<GSizes, bool> GetGradationSizes() const;
void SetGradationSizes(const QMap<GSizes, bool> &options);
QString GetAuthor() const;
void SetAuthor(const QString &text);
QString GetDescription() const;
void SetDescription(const QString &text);
QString GetNotes() const;
void SetNotes(const QString &text);
QString GetVersion() const;
void SetVersion();
QString GenerateLabel(const LabelType &type)const;
QString GenerateLabel(const LabelType &type)const;
public slots:
void LiteParseTree(const Document &parse);
void haveLiteChange();
void ShowHistoryTool(quint32 id, bool enable);
void NeedFullParsing();
void ClearScene();
protected:
virtual void customEvent(QEvent * event);
private:
Q_DISABLE_COPY(VPattern)
/** @brief data container with data. */
VContainer *data;
/** @brief patternPieces list of patern pieces names for combobox*/
QStringList patternPieces;
/** @brief mode current draw mode. */
Draw *mode;
Draw *mode;
VMainGraphicsScene *sceneDraw;
VMainGraphicsScene *sceneDetail;
@ -137,14 +117,7 @@ private:
template <typename T>
QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const;
void ParseCurrentPP();
void CheckTagExists(const QString &tag);
QString GetLabelBase(unsigned int index)const;
};
//---------------------------------------------------------------------------------------------------------------------
inline QStringList VPattern::getPatternPieces() const
{
return patternPieces;
}
#endif // VPATTERN_H

View file

@ -29,6 +29,7 @@
#include "vabstractpattern.h"
#include "../vmisc/def.h"
#include "exception/vexceptionbadid.h"
#include "vpatternconverter.h"
const QString VAbstractPattern::TagPattern = QStringLiteral("pattern");
const QString VAbstractPattern::TagCalculation = QStringLiteral("calculation");
@ -103,7 +104,7 @@ const QString VAbstractPattern::IncrementDescription = QStringLiteral("descripti
//---------------------------------------------------------------------------------------------------------------------
VAbstractPattern::VAbstractPattern(QObject *parent)
: QObject(parent), VDomDocument(), nameActivPP(QString()), cursor(0), tools(QHash<quint32, VDataTool*>()),
history(QVector<VToolRecord>())
history(QVector<VToolRecord>()), patternPieces(QStringList())
{}
//---------------------------------------------------------------------------------------------------------------------
@ -538,6 +539,367 @@ quint32 VAbstractPattern::SiblingNodeId(const quint32 &nodeId) const
return siblingId;
}
//---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::getPatternPieces() const
{
return patternPieces;
}
//---------------------------------------------------------------------------------------------------------------------
QMap<GHeights, bool> VAbstractPattern::GetGradationHeights() const
{
QMap<GHeights, bool> map;
map.insert(GHeights::ALL, true);
map.insert(GHeights::H92, true);
map.insert(GHeights::H98, true);
map.insert(GHeights::H104, true);
map.insert(GHeights::H110, true);
map.insert(GHeights::H116, true);
map.insert(GHeights::H122, true);
map.insert(GHeights::H128, true);
map.insert(GHeights::H134, true);
map.insert(GHeights::H140, true);
map.insert(GHeights::H146, true);
map.insert(GHeights::H152, true);
map.insert(GHeights::H158, true);
map.insert(GHeights::H164, true);
map.insert(GHeights::H170, true);
map.insert(GHeights::H176, true);
map.insert(GHeights::H182, true);
map.insert(GHeights::H188, true);
map.insert(GHeights::H194, true);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
return map;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
const QString defValue = QStringLiteral("true");
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
if (GetParametrBool(domElement, AttrAll, defValue))
{
return map;
}
else
{
map.insert(GHeights::ALL, false);
}
map.insert(GHeights::H92, GetParametrBool(domElement, AttrH92, defValue));
map.insert(GHeights::H98, GetParametrBool(domElement, AttrH98, defValue));
map.insert(GHeights::H104, GetParametrBool(domElement, AttrH104, defValue));
map.insert(GHeights::H110, GetParametrBool(domElement, AttrH110, defValue));
map.insert(GHeights::H116, GetParametrBool(domElement, AttrH116, defValue));
map.insert(GHeights::H122, GetParametrBool(domElement, AttrH122, defValue));
map.insert(GHeights::H128, GetParametrBool(domElement, AttrH128, defValue));
map.insert(GHeights::H134, GetParametrBool(domElement, AttrH134, defValue));
map.insert(GHeights::H140, GetParametrBool(domElement, AttrH140, defValue));
map.insert(GHeights::H146, GetParametrBool(domElement, AttrH146, defValue));
map.insert(GHeights::H152, GetParametrBool(domElement, AttrH152, defValue));
map.insert(GHeights::H158, GetParametrBool(domElement, AttrH158, defValue));
map.insert(GHeights::H164, GetParametrBool(domElement, AttrH164, defValue));
map.insert(GHeights::H170, GetParametrBool(domElement, AttrH170, defValue));
map.insert(GHeights::H176, GetParametrBool(domElement, AttrH176, defValue));
map.insert(GHeights::H182, GetParametrBool(domElement, AttrH182, defValue));
map.insert(GHeights::H188, GetParametrBool(domElement, AttrH188, defValue));
map.insert(GHeights::H194, GetParametrBool(domElement, AttrH194, defValue));
return map;
break;
case 1: // TagSizes
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
return map;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetGradationHeights(const QMap<GHeights, bool> &options)
{
CheckTagExists(TagGradation);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
return;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
SetAttribute(domElement, AttrAll, options.value(GHeights::ALL));
SetAttribute(domElement, AttrH92, options.value(GHeights::H92));
SetAttribute(domElement, AttrH98, options.value(GHeights::H98));
SetAttribute(domElement, AttrH104, options.value(GHeights::H104));
SetAttribute(domElement, AttrH110, options.value(GHeights::H110));
SetAttribute(domElement, AttrH116, options.value(GHeights::H116));
SetAttribute(domElement, AttrH122, options.value(GHeights::H122));
SetAttribute(domElement, AttrH128, options.value(GHeights::H128));
SetAttribute(domElement, AttrH134, options.value(GHeights::H134));
SetAttribute(domElement, AttrH140, options.value(GHeights::H140));
SetAttribute(domElement, AttrH146, options.value(GHeights::H146));
SetAttribute(domElement, AttrH152, options.value(GHeights::H152));
SetAttribute(domElement, AttrH158, options.value(GHeights::H158));
SetAttribute(domElement, AttrH164, options.value(GHeights::H164));
SetAttribute(domElement, AttrH170, options.value(GHeights::H170));
SetAttribute(domElement, AttrH176, options.value(GHeights::H176));
SetAttribute(domElement, AttrH182, options.value(GHeights::H182));
SetAttribute(domElement, AttrH188, options.value(GHeights::H188));
SetAttribute(domElement, AttrH194, options.value(GHeights::H194));
emit patternChanged(false);
return;
break;
case 1: // TagSizes
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
}
//---------------------------------------------------------------------------------------------------------------------
QMap<GSizes, bool> VAbstractPattern::GetGradationSizes() const
{
QMap<GSizes, bool> map;
map.insert(GSizes::ALL, true);
map.insert(GSizes::S22, true);
map.insert(GSizes::S24, true);
map.insert(GSizes::S26, true);
map.insert(GSizes::S28, true);
map.insert(GSizes::S30, true);
map.insert(GSizes::S32, true);
map.insert(GSizes::S34, true);
map.insert(GSizes::S36, true);
map.insert(GSizes::S38, true);
map.insert(GSizes::S40, true);
map.insert(GSizes::S42, true);
map.insert(GSizes::S44, true);
map.insert(GSizes::S46, true);
map.insert(GSizes::S48, true);
map.insert(GSizes::S50, true);
map.insert(GSizes::S52, true);
map.insert(GSizes::S54, true);
map.insert(GSizes::S56, true);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
return map;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
const QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
const QString defValue = QStringLiteral("true");
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
break;
case 1: // TagSizes
if (GetParametrBool(domElement, AttrAll, defValue))
{
return map;
}
else
{
map.insert(GSizes::ALL, false);
}
map.insert(GSizes::S22, GetParametrBool(domElement, AttrS22, defValue));
map.insert(GSizes::S24, GetParametrBool(domElement, AttrS24, defValue));
map.insert(GSizes::S26, GetParametrBool(domElement, AttrS26, defValue));
map.insert(GSizes::S28, GetParametrBool(domElement, AttrS28, defValue));
map.insert(GSizes::S30, GetParametrBool(domElement, AttrS30, defValue));
map.insert(GSizes::S32, GetParametrBool(domElement, AttrS32, defValue));
map.insert(GSizes::S34, GetParametrBool(domElement, AttrS34, defValue));
map.insert(GSizes::S36, GetParametrBool(domElement, AttrS36, defValue));
map.insert(GSizes::S38, GetParametrBool(domElement, AttrS38, defValue));
map.insert(GSizes::S40, GetParametrBool(domElement, AttrS40, defValue));
map.insert(GSizes::S42, GetParametrBool(domElement, AttrS42, defValue));
map.insert(GSizes::S44, GetParametrBool(domElement, AttrS44, defValue));
map.insert(GSizes::S46, GetParametrBool(domElement, AttrS46, defValue));
map.insert(GSizes::S48, GetParametrBool(domElement, AttrS48, defValue));
map.insert(GSizes::S50, GetParametrBool(domElement, AttrS50, defValue));
map.insert(GSizes::S52, GetParametrBool(domElement, AttrS52, defValue));
map.insert(GSizes::S54, GetParametrBool(domElement, AttrS54, defValue));
map.insert(GSizes::S56, GetParametrBool(domElement, AttrS56, defValue));
return map;
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
return map;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetGradationSizes(const QMap<GSizes, bool> &options)
{
CheckTagExists(TagGradation);
QDomNodeList tags = elementsByTagName(TagGradation);
if (tags.size() == 0)
{
qDebug()<<"Can't save tag "<<TagGradation<<Q_FUNC_INFO;
return;
}
QStringList gTags = QStringList() << TagHeights << TagSizes;
QDomNode domNode = tags.at(0).firstChild();
while (domNode.isNull() == false)
{
if (domNode.isElement())
{
QDomElement domElement = domNode.toElement();
if (domElement.isNull() == false)
{
switch (gTags.indexOf(domElement.tagName()))
{
case 0: // TagHeights
break;
case 1: // TagSizes
SetAttribute(domElement, AttrAll, options.value(GSizes::ALL));
SetAttribute(domElement, AttrS22, options.value(GSizes::S22));
SetAttribute(domElement, AttrS24, options.value(GSizes::S24));
SetAttribute(domElement, AttrS26, options.value(GSizes::S26));
SetAttribute(domElement, AttrS28, options.value(GSizes::S28));
SetAttribute(domElement, AttrS30, options.value(GSizes::S30));
SetAttribute(domElement, AttrS32, options.value(GSizes::S32));
SetAttribute(domElement, AttrS34, options.value(GSizes::S34));
SetAttribute(domElement, AttrS36, options.value(GSizes::S36));
SetAttribute(domElement, AttrS38, options.value(GSizes::S38));
SetAttribute(domElement, AttrS40, options.value(GSizes::S40));
SetAttribute(domElement, AttrS42, options.value(GSizes::S42));
SetAttribute(domElement, AttrS44, options.value(GSizes::S44));
SetAttribute(domElement, AttrS46, options.value(GSizes::S46));
SetAttribute(domElement, AttrS48, options.value(GSizes::S48));
SetAttribute(domElement, AttrS50, options.value(GSizes::S50));
SetAttribute(domElement, AttrS52, options.value(GSizes::S52));
SetAttribute(domElement, AttrS54, options.value(GSizes::S54));
SetAttribute(domElement, AttrS56, options.value(GSizes::S56));
emit patternChanged(false);
return;
break;
default:
break;
}
}
}
domNode = domNode.nextSibling();
}
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetDescription() const
{
return UniqueTagText(TagDescription);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetDescription(const QString &text)
{
CheckTagExists(TagDescription);
setTagText(TagDescription, text);
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetNotes() const
{
return UniqueTagText(TagNotes);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetNotes(const QString &text)
{
CheckTagExists(TagNotes);
setTagText(TagNotes, text);
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
QString VAbstractPattern::GetVersion() const
{
return UniqueTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::SetVersion()
{
setTagText(TagVersion, VPatternConverter::PatternMaxVerStr);
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief haveLiteChange we have unsaved change.
*/
void VAbstractPattern::haveLiteChange()
{
emit patternChanged(false);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ShowHistoryTool hightlight tool.
* @param id tool id.
* @param enable enable or diasable hightlight.
*/
void VAbstractPattern::ShowHistoryTool(quint32 id, bool enable)
{
emit ShowTool(id, enable);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::NeedFullParsing()
{
emit UndoCommand();
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::ClearScene()
{
emit ClearMainWindow();
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::ToolExists(const quint32 &id) const
{
@ -558,3 +920,72 @@ void VAbstractPattern::SetActivPP(const QString &name)
this->nameActivPP = name;
emit ChangedActivPP(name);
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::CheckTagExists(const QString &tag)
{
QDomNodeList list = elementsByTagName(tag);
if (list.size() == 0)
{
QStringList tags = QStringList() << TagVersion << TagAuthor << TagDescription << TagNotes << TagGradation;
QDomElement pattern = documentElement();
switch (tags.indexOf(tag))
{
case 0: //TagVersion
break;// Mandatory tag
case 1: //TagAuthor
pattern.insertAfter(createElement(TagAuthor), elementsByTagName(TagVersion).at(0));
SetVersion();
break;
case 2: //TagDescription
{
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
{
QDomNodeList list = elementsByTagName(tags.at(i));
if (list.isEmpty())
{
continue;
}
pattern.insertAfter(createElement(TagDescription), list.at(0));
}
SetVersion();
break;
}
case 3: //TagNotes
{
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
{
QDomNodeList list = elementsByTagName(tags.at(i));
if (list.isEmpty())
{
continue;
}
pattern.insertAfter(createElement(TagNotes), list.at(0));
}
SetVersion();
break;
}
case 4: //TagGradation
{
QDomElement gradation = createElement(TagGradation);
gradation.appendChild(createElement(TagHeights));
gradation.appendChild(createElement(TagSizes));
for (int i = tags.indexOf(tag)-1; i >= 0; --i)
{
QDomNodeList list = elementsByTagName(tags.at(i));
if (list.isEmpty())
{
continue;
}
pattern.insertAfter(gradation, list.at(0));
break;
}
SetVersion();
break;
}
default:
break;
}
}
}

View file

@ -78,6 +78,23 @@ public:
quint32 SiblingNodeId(const quint32 &nodeId) const;
QStringList getPatternPieces() const;
QMap<GHeights, bool> GetGradationHeights() const;
void SetGradationHeights(const QMap<GHeights, bool> &options);
QMap<GSizes, bool> GetGradationSizes() const;
void SetGradationSizes(const QMap<GSizes, bool> &options);
QString GetDescription() const;
void SetDescription(const QString &text);
QString GetNotes() const;
void SetNotes(const QString &text);
QString GetVersion() const;
void SetVersion();
static const QString TagPattern;
static const QString TagCalculation;
static const QString TagModeling;
@ -187,6 +204,12 @@ signals:
void CheckLayout();
void SetCurrentPP(const QString &patterPiece);
public slots:
void haveLiteChange();
void ShowHistoryTool(quint32 id, bool enable);
void NeedFullParsing();
void ClearScene();
protected:
/** @brief nameActivDraw name current pattern peace. */
QString nameActivPP;
@ -200,10 +223,15 @@ protected:
/** @brief history history records. */
QVector<VToolRecord> history;
/** @brief patternPieces list of patern pieces names for combobox*/
QStringList patternPieces;
void ToolExists(const quint32 &id) const;
void SetActivPP(const QString& name);
void CheckTagExists(const QString &tag);
private:
Q_DISABLE_COPY(VAbstractPattern)
};