diff --git a/glabels/ui/VariablesView.ui b/glabels/ui/VariablesView.ui index 04ec15b..801bb2c 100644 --- a/glabels/ui/VariablesView.ui +++ b/glabels/ui/VariablesView.ui @@ -38,6 +38,9 @@ 5 + + false + Name diff --git a/model/Variable.cpp b/model/Variable.cpp index e4a3432..b424a6b 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -95,6 +95,23 @@ namespace glabels } + Variable::Type Variable::idStringToType( const QString& string ) + { + if ( string == "numeric" ) + { + return Type::NUMERIC; + } + else if ( string == "string" ) + { + return Type::STRING; + } + else + { + return Type::STRING; // Default + } + } + + QString Variable::incrementToI18nString( Increment increment ) { switch (increment) @@ -127,5 +144,30 @@ namespace glabels } + Variable::Increment Variable::idStringToIncrement( const QString& string ) + { + if ( string == "never" ) + { + return Increment::NEVER; + } + else if ( string == "per_copy" ) + { + return Increment::PER_COPY; + } + else if ( string == "per_merge_record" ) + { + return Increment::PER_MERGE_RECORD; + } + else if ( string == "per_page" ) + { + return Increment::PER_PAGE; + } + else + { + return Increment::NEVER; // Default + } + } + + } } diff --git a/model/Variable.h b/model/Variable.h index d314642..0a90733 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -70,11 +70,13 @@ namespace glabels QString stepSize() const; - static QString typeToI18nString( Type type ); - static QString typeToIdString( Type type ); + static QString typeToI18nString( Type type ); + static QString typeToIdString( Type type ); + static Type idStringToType( const QString& string ); - static QString incrementToI18nString( Increment increment ); - static QString incrementToIdString( Increment increment ); + static QString incrementToI18nString( Increment increment ); + static QString incrementToIdString( Increment increment ); + static Increment idStringToIncrement( const QString& string ); private: diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp index 87b3114..2a31cf0 100644 --- a/model/XmlLabelCreator.cpp +++ b/model/XmlLabelCreator.cpp @@ -29,6 +29,7 @@ #include "ModelImageObject.h" #include "ModelTextObject.h" #include "DataCache.h" +#include "Variables.h" #include "XmlTemplateCreator.h" #include "XmlUtil.h" @@ -116,6 +117,11 @@ namespace glabels createMergeNode( root, label ); } + if ( label->variables()->size() != 0 ) + { + createVariablesNode( root, label ); + } + createDataNode( root, label->objectList() ); } @@ -466,6 +472,35 @@ namespace glabels } + void + XmlLabelCreator::createVariablesNode( QDomElement &parent, const Model* label ) + { + QDomDocument doc = parent.ownerDocument(); + QDomElement node = doc.createElement( "Variables" ); + parent.appendChild( node ); + + for ( const auto& v : *label->variables() ) + { + createVariableNode( node, v ); + } + } + + + void + XmlLabelCreator::createVariableNode( QDomElement &parent, const Variable& v ) + { + QDomDocument doc = parent.ownerDocument(); + QDomElement node = doc.createElement( "Variable" ); + parent.appendChild( node ); + + XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) ); + XmlUtil::setStringAttr( node, "name", v.name() ); + XmlUtil::setStringAttr( node, "value", v.value() ); + XmlUtil::setStringAttr( node, "increment", Variable::incrementToIdString( v.increment() ) ); + XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); + } + + void XmlLabelCreator::createDataNode( QDomElement &parent, const QList& objects ) { diff --git a/model/XmlLabelCreator.h b/model/XmlLabelCreator.h index 93c235e..2e3d87a 100644 --- a/model/XmlLabelCreator.h +++ b/model/XmlLabelCreator.h @@ -40,6 +40,7 @@ namespace glabels class ModelImageObject; class ModelBarcodeObject; class ModelTextObject; + class Variable; /// @@ -72,6 +73,8 @@ namespace glabels static void createAffineAttrs( QDomElement &node, const ModelObject* object ); static void createShadowAttrs( QDomElement &node, const ModelObject* object ); static void createMergeNode( QDomElement &parent, const Model* label ); + static void createVariablesNode( QDomElement &parent, const Model* label ); + static void createVariableNode( QDomElement &parent, const Variable& v ); static void createDataNode( QDomElement &parent, const QList& objects ); static void createPngFileNode( QDomElement &parent, const QString& name, const QImage& image ); static void createSvgFileNode( QDomElement &parent, const QString& name, const QByteArray& svg ); diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index 779149c..9412dd7 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -286,6 +286,10 @@ namespace glabels { parseMergeNode( child.toElement(), label ); } + else if ( tagName == "Variables" ) + { + parseVariablesNode( child.toElement(), label ); + } else if ( tagName == "Data" ) { /* Handled in pass 1. */ @@ -719,6 +723,42 @@ namespace glabels } + void + XmlLabelParser::parseVariablesNode( const QDomElement &node, Model* label ) + { + for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() ) + { + QString tagName = child.toElement().tagName(); + + if ( tagName == "Variable" ) + { + parseVariableNode( child.toElement(), label ); + } + else if ( !child.isComment() ) + { + qWarning() << "Unexpected" << node.tagName() << "child:" << tagName; + } + } + } + + + void + XmlLabelParser::parseVariableNode( const QDomElement &node, Model* label ) + { + QString typeString = XmlUtil::getStringAttr( node, "type", "string" ); + QString name = XmlUtil::getStringAttr( node, "name", "unknown" ); + QString value = XmlUtil::getStringAttr( node, "value", "0" ); + QString incrementString = XmlUtil::getStringAttr( node, "increment", "never" ); + QString stepSize = XmlUtil::getStringAttr( node, "stepSize", "0" ); + + auto type = Variable::idStringToType( typeString ); + auto increment = Variable::idStringToIncrement( incrementString ); + + Variable v( type, name, value, increment, stepSize ); + label->variables()->addVariable( v ); + } + + void XmlLabelParser::parseDataNode( const QDomElement &node, DataCache& data ) { @@ -738,13 +778,6 @@ namespace glabels } - void - XmlLabelParser::parsePixdataNode( const QDomElement& node, DataCache& data ) - { - // TODO, compatibility with glabels-3 - } - - void XmlLabelParser::parseFileNode( const QDomElement& node, DataCache& data ) { diff --git a/model/XmlLabelParser.h b/model/XmlLabelParser.h index f135860..c13edf4 100644 --- a/model/XmlLabelParser.h +++ b/model/XmlLabelParser.h @@ -68,8 +68,9 @@ namespace glabels static QString parsePNode( const QDomElement &node ); static bool parseRotateAttr( const QDomElement &node ); static void parseMergeNode( const QDomElement &node, Model* label ); + static void parseVariablesNode( const QDomElement &node, Model* label ); + static void parseVariableNode( const QDomElement &node, Model* label ); static void parseDataNode( const QDomElement &node, DataCache& data ); - static void parsePixdataNode( const QDomElement &node, DataCache& data ); static void parseFileNode( const QDomElement &node, DataCache& data ); }; diff --git a/templates/glabels-4.0.dtd b/templates/glabels-4.0.dtd index 5834460..a883c94 100644 --- a/templates/glabels-4.0.dtd +++ b/templates/glabels-4.0.dtd @@ -87,6 +87,10 @@ iec16022)" --> + + + + @@ -139,7 +143,7 @@ - + + + + + + + + +