Include variables in glabels project file.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -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:
|
||||
|
||||
@@ -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<ModelObject*>& objects )
|
||||
{
|
||||
|
||||
@@ -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<ModelObject*>& objects );
|
||||
static void createPngFileNode( QDomElement &parent, const QString& name, const QImage& image );
|
||||
static void createSvgFileNode( QDomElement &parent, const QString& name, const QByteArray& svg );
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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 );
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user