Revamp struct sequenceStruct to class sequentialNumbers.

Element now use methods (toXml and fromXml) of sequentialNumbers to store and load sequential.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4803 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-12-08 15:06:46 +00:00
parent 18df62cea1
commit 9f014d55af
11 changed files with 196 additions and 113 deletions

View File

@@ -20,12 +20,114 @@
#include "element.h"
#include "diagramposition.h"
#include "qetapp.h"
#include "qetxml.h"
#include <QVariant>
#include <QStringList>
namespace autonum
{
/**
* @brief sequentialNumbers::sequentialNumbers
*/
sequentialNumbers::sequentialNumbers()
{}
sequentialNumbers &sequentialNumbers::operator=(const sequentialNumbers &other)
{
if (&other == this || other == *this)
return (*this);
unit = other.unit;
unit_folio = other.unit_folio;
ten = other.ten;
ten_folio = other.ten_folio;
hundred = other.hundred;
hundred_folio = other.hundred_folio;
return (*this);
}
bool sequentialNumbers::operator==(const sequentialNumbers &other) const
{
if (unit == other.unit && \
unit_folio == other.unit_folio && \
ten == other.ten && \
ten_folio == other.ten_folio && \
hundred == other.hundred && \
hundred_folio == other.hundred_folio)
return true;
else
return false;
}
bool sequentialNumbers::operator!=(const sequentialNumbers &other) const
{
if (*this == other)
return false;
else
return true;
}
/**
* @brief sequentialNumbers::toXml
* export this sequential numbers into a QDomElement.
* @param document : QDomDocument used to create the QDomElement
* @param tag_name : the tag name used for the QDomElement.
* @return A QDomElement, if this sequential have no value, the returned QDomELement is empty
*/
QDomElement sequentialNumbers::toXml(QDomDocument &document, QString tag_name) const
{
QDomElement element = document.createElement(tag_name);
if (!unit.isEmpty())
element.appendChild(QETXML::textToDomElement(document, "unit", unit.join(";")));
if (!unit_folio.isEmpty())
element.appendChild(QETXML::textToDomElement(document, "unitFolio", unit_folio.join(";")));
if(!ten.isEmpty())
element.appendChild(QETXML::textToDomElement(document, "ten", ten.join(";")));
if(!ten_folio.isEmpty())
element.appendChild(QETXML::textToDomElement(document, "tenFolio", ten_folio.join(";")));
if(!hundred.isEmpty())
element.appendChild(QETXML::textToDomElement(document, "hundred", hundred.join(";")));
if(!hundred_folio.isEmpty())
element.appendChild(QETXML::textToDomElement(document, "hundredFolio", hundred_folio.join(";")));
return element;
}
/**
* @brief sequentialNumbers::fromXml
* Import sequential values from a QDomElement
* @param element
*/
void sequentialNumbers::fromXml(const QDomElement &element)
{
if (!element.hasChildNodes())
return;
QDomElement from;
from = element.firstChildElement("unit");
unit = from.text().split(";");
from = element.firstChildElement("unitFolio");
unit_folio = from.text().split(";");
from = element.firstChildElement("ten");
ten = from.text().split(";");
from = element.firstChildElement("tenFolio");
ten_folio = from.text().split(";");
from = element.firstChildElement("hundred");
hundred = from.text().split(";");
from = element.firstChildElement("hundredFolio");
hundred_folio = from.text().split(";");
}
/**
* @brief AssignVariables::formulaToLabel
* Return the @formula with variable assigned (ready to be displayed)
@@ -35,14 +137,14 @@ namespace autonum
* @param elmt - parent element (if any) of the formula
* @return the string with variable assigned.
*/
QString AssignVariables::formulaToLabel(QString formula, sequenceStruct &seqStruct, Diagram *diagram, const Element *elmt)
QString AssignVariables::formulaToLabel(QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt)
{
AssignVariables av(formula, seqStruct, diagram, elmt);
seqStruct = av.m_seq_struct;
return av.m_assigned_label;
}
AssignVariables::AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, const Element *elmt):
AssignVariables::AssignVariables(QString formula, sequentialNumbers seqStruct , Diagram *diagram, const Element *elmt):
m_diagram(diagram),
m_arg_formula(formula),
m_assigned_label(formula),
@@ -203,7 +305,7 @@ namespace autonum
* to keep up to date the current sequential of folio.
* @param hashKey : the hash key used to store the sequential for folio type.
*/
void setSequential(QString label, sequenceStruct &seqStruct, NumerotationContext &context, Diagram *diagram, QString hashKey)
void setSequential(QString label, sequentialNumbers &seqStruct, NumerotationContext &context, Diagram *diagram, QString hashKey)
{
if (!context.isEmpty())
{
@@ -394,5 +496,4 @@ namespace autonum
return QString();
}
}

View File

@@ -30,7 +30,18 @@ class ElementsLocation;
namespace autonum
{
struct sequenceStruct {
class sequentialNumbers
{
public:
sequentialNumbers();
sequentialNumbers &operator= (const sequentialNumbers &other);
bool operator== (const sequentialNumbers &other) const;
bool operator!= (const sequentialNumbers &other) const;
QDomElement toXml(QDomDocument &document, QString tag_name = QString("sequentialNumbers")) const;
void fromXml(const QDomElement &element);
QStringList unit;
QStringList unit_folio;
QStringList ten;
@@ -47,10 +58,10 @@ namespace autonum
class AssignVariables
{
public:
static QString formulaToLabel (QString formula, sequenceStruct &seqStruct, Diagram *diagram, const Element *elmt = nullptr);
static QString formulaToLabel (QString formula, sequentialNumbers &seqStruct, Diagram *diagram, const Element *elmt = nullptr);
private:
AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, const Element *elmt = nullptr);
AssignVariables(QString formula, sequentialNumbers seqStruct , Diagram *diagram, const Element *elmt = nullptr);
void assignTitleBlockVar();
void assignProjectVar();
void assignSequence();
@@ -58,13 +69,13 @@ namespace autonum
Diagram *m_diagram = nullptr;
QString m_arg_formula;
QString m_assigned_label;
sequenceStruct m_seq_struct;
sequentialNumbers m_seq_struct;
const Element *m_element = nullptr;
};
void setSequentialToList(QStringList &list, NumerotationContext &nc, QString type);
void setFolioSequentialToHash(QStringList &list, QHash<QString, QStringList> &hash, QString autoNumName);
void setSequential(QString label, autonum::sequenceStruct &seqStruct, NumerotationContext &context, Diagram *diagram, QString hashKey);
void setSequential(QString label, autonum::sequentialNumbers &seqStruct, NumerotationContext &context, Diagram *diagram, QString hashKey);
QString numerotationContextToFormula(const NumerotationContext &nc);
QString elementPrefixForLocation(const ElementsLocation &location);
}