Include variables in glabels project file.
This commit is contained in:
@@ -38,6 +38,9 @@
|
|||||||
<property name="columnCount">
|
<property name="columnCount">
|
||||||
<number>5</number>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
|
<attribute name="verticalHeaderVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Name</string>
|
<string>Name</string>
|
||||||
|
|||||||
@@ -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 )
|
QString Variable::incrementToI18nString( Increment increment )
|
||||||
{
|
{
|
||||||
switch (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;
|
QString stepSize() const;
|
||||||
|
|
||||||
|
|
||||||
static QString typeToI18nString( Type type );
|
static QString typeToI18nString( Type type );
|
||||||
static QString typeToIdString( Type type );
|
static QString typeToIdString( Type type );
|
||||||
|
static Type idStringToType( const QString& string );
|
||||||
|
|
||||||
static QString incrementToI18nString( Increment increment );
|
static QString incrementToI18nString( Increment increment );
|
||||||
static QString incrementToIdString( Increment increment );
|
static QString incrementToIdString( Increment increment );
|
||||||
|
static Increment idStringToIncrement( const QString& string );
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "ModelImageObject.h"
|
#include "ModelImageObject.h"
|
||||||
#include "ModelTextObject.h"
|
#include "ModelTextObject.h"
|
||||||
#include "DataCache.h"
|
#include "DataCache.h"
|
||||||
|
#include "Variables.h"
|
||||||
#include "XmlTemplateCreator.h"
|
#include "XmlTemplateCreator.h"
|
||||||
#include "XmlUtil.h"
|
#include "XmlUtil.h"
|
||||||
|
|
||||||
@@ -116,6 +117,11 @@ namespace glabels
|
|||||||
createMergeNode( root, label );
|
createMergeNode( root, label );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( label->variables()->size() != 0 )
|
||||||
|
{
|
||||||
|
createVariablesNode( root, label );
|
||||||
|
}
|
||||||
|
|
||||||
createDataNode( root, label->objectList() );
|
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
|
void
|
||||||
XmlLabelCreator::createDataNode( QDomElement &parent, const QList<ModelObject*>& objects )
|
XmlLabelCreator::createDataNode( QDomElement &parent, const QList<ModelObject*>& objects )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace glabels
|
|||||||
class ModelImageObject;
|
class ModelImageObject;
|
||||||
class ModelBarcodeObject;
|
class ModelBarcodeObject;
|
||||||
class ModelTextObject;
|
class ModelTextObject;
|
||||||
|
class Variable;
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -72,6 +73,8 @@ namespace glabels
|
|||||||
static void createAffineAttrs( QDomElement &node, const ModelObject* object );
|
static void createAffineAttrs( QDomElement &node, const ModelObject* object );
|
||||||
static void createShadowAttrs( QDomElement &node, const ModelObject* object );
|
static void createShadowAttrs( QDomElement &node, const ModelObject* object );
|
||||||
static void createMergeNode( QDomElement &parent, const Model* label );
|
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 createDataNode( QDomElement &parent, const QList<ModelObject*>& objects );
|
||||||
static void createPngFileNode( QDomElement &parent, const QString& name, const QImage& image );
|
static void createPngFileNode( QDomElement &parent, const QString& name, const QImage& image );
|
||||||
static void createSvgFileNode( QDomElement &parent, const QString& name, const QByteArray& svg );
|
static void createSvgFileNode( QDomElement &parent, const QString& name, const QByteArray& svg );
|
||||||
|
|||||||
@@ -286,6 +286,10 @@ namespace glabels
|
|||||||
{
|
{
|
||||||
parseMergeNode( child.toElement(), label );
|
parseMergeNode( child.toElement(), label );
|
||||||
}
|
}
|
||||||
|
else if ( tagName == "Variables" )
|
||||||
|
{
|
||||||
|
parseVariablesNode( child.toElement(), label );
|
||||||
|
}
|
||||||
else if ( tagName == "Data" )
|
else if ( tagName == "Data" )
|
||||||
{
|
{
|
||||||
/* Handled in pass 1. */
|
/* 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
|
void
|
||||||
XmlLabelParser::parseDataNode( const QDomElement &node, DataCache& data )
|
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
|
void
|
||||||
XmlLabelParser::parseFileNode( const QDomElement& node, DataCache& data )
|
XmlLabelParser::parseFileNode( const QDomElement& node, DataCache& data )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,8 +68,9 @@ namespace glabels
|
|||||||
static QString parsePNode( const QDomElement &node );
|
static QString parsePNode( const QDomElement &node );
|
||||||
static bool parseRotateAttr( const QDomElement &node );
|
static bool parseRotateAttr( const QDomElement &node );
|
||||||
static void parseMergeNode( const QDomElement &node, Model* label );
|
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 parseDataNode( const QDomElement &node, DataCache& data );
|
||||||
static void parsePixdataNode( const QDomElement &node, DataCache& data );
|
|
||||||
static void parseFileNode( const QDomElement &node, DataCache& data );
|
static void parseFileNode( const QDomElement &node, DataCache& data );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -87,6 +87,10 @@
|
|||||||
iec16022)"
|
iec16022)"
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<!-- Variable related enumerations/types -->
|
||||||
|
<!ENTITY % VARIABLE_TYPE_TYPE "(numeric | string)">
|
||||||
|
<!ENTITY % VARIABLE_INC_TYPE "(never | per_copy | per_merge_record | per_page )">
|
||||||
|
|
||||||
<!-- Data encoding method -->
|
<!-- Data encoding method -->
|
||||||
<!ENTITY % DATA_ENCODING_TYPE "(cdata | base64)">
|
<!ENTITY % DATA_ENCODING_TYPE "(cdata | base64)">
|
||||||
|
|
||||||
@@ -139,7 +143,7 @@
|
|||||||
<!-- Top-level glabels document -->
|
<!-- Top-level glabels document -->
|
||||||
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
||||||
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
||||||
<!ELEMENT Glabels-document (Template, Objects+, Merge?, Data*)>
|
<!ELEMENT Glabels-document (Template, Objects+, Merge?, Variables?, Data*)>
|
||||||
<!ATTLIST Glabels-document
|
<!ATTLIST Glabels-document
|
||||||
xmlns %STRING_TYPE; #IMPLIED
|
xmlns %STRING_TYPE; #IMPLIED
|
||||||
version %STRING_TYPE; #IMPLIED
|
version %STRING_TYPE; #IMPLIED
|
||||||
@@ -440,6 +444,20 @@
|
|||||||
src %STRING_TYPE; #IMPLIED
|
src %STRING_TYPE; #IMPLIED
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
||||||
|
<!-- Variables Section -->
|
||||||
|
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
||||||
|
<!ELEMENT Variables (Variable*)>
|
||||||
|
|
||||||
|
<!ELEMENT Variable EMPTY>
|
||||||
|
<!ATTLIST Variable
|
||||||
|
type %VARIABLE_TYPE_TYPE; #REQUIRED
|
||||||
|
name %STRING_TYPE; #REQUIRED
|
||||||
|
value %STRING_TYPE; #REQUIRED
|
||||||
|
increment %VARIABLE_INC_TYPE; #REQUIRED
|
||||||
|
stepSize %STRING_TYPE; #REQUIRED
|
||||||
|
>
|
||||||
|
|
||||||
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
||||||
<!-- Data Section -->
|
<!-- Data Section -->
|
||||||
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
<!-- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
|
||||||
|
|||||||
Reference in New Issue
Block a user