From 276756a317ac19f5ce5362b0b8d78c13e1fd4524 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 7 May 2017 22:21:29 -0400 Subject: [PATCH] Read and write barcodes in glabels project files. --- glabels/BarcodeBackends.cpp | 14 ++++++++++++ glabels/BarcodeBackends.h | 1 + glabels/LabelModelBarcodeObject.cpp | 2 ++ glabels/XmlLabelCreator.cpp | 35 ++++++++++++++++++++++++++--- glabels/XmlLabelParser.cpp | 33 +++++++++++++++++++++++---- templates/glabels-4.0.dtd | 5 +---- translations/glabels_C.ts | 4 ++-- 7 files changed, 81 insertions(+), 13 deletions(-) diff --git a/glabels/BarcodeBackends.cpp b/glabels/BarcodeBackends.cpp index b148a57..215ee5b 100644 --- a/glabels/BarcodeBackends.cpp +++ b/glabels/BarcodeBackends.cpp @@ -98,6 +98,20 @@ namespace glabels } + const BarcodeStyle& BarcodeBackends::style( const QString& backendId, const QString& StyleId ) + { + foreach ( const BarcodeStyle& bcStyle, mStyleList ) + { + if ( (bcStyle.backendId() == backendId) && (bcStyle.id() == StyleId) ) + { + return bcStyle; + } + } + + return defaultStyle(); + } + + void BarcodeBackends::registerBackend( QString& id, QString& name) { mBackendNameList.append( name ); diff --git a/glabels/BarcodeBackends.h b/glabels/BarcodeBackends.h index e8c8220..2cf3714 100644 --- a/glabels/BarcodeBackends.h +++ b/glabels/BarcodeBackends.h @@ -56,6 +56,7 @@ namespace glabels public: static const QList& styleList(); static const BarcodeStyle& defaultStyle(); + static const BarcodeStyle& style( const QString& backendId, const QString& StyleId ); ///////////////////////////////// diff --git a/glabels/LabelModelBarcodeObject.cpp b/glabels/LabelModelBarcodeObject.cpp index 7a26b57..a56c6e3 100644 --- a/glabels/LabelModelBarcodeObject.cpp +++ b/glabels/LabelModelBarcodeObject.cpp @@ -72,6 +72,8 @@ namespace glabels mBcData = ""; mBcColorNode = ColorNode( Qt::black ); + mEditorBarcode = nullptr; + update(); // Initialize cached editor layouts } diff --git a/glabels/XmlLabelCreator.cpp b/glabels/XmlLabelCreator.cpp index 884413d..4b19683 100644 --- a/glabels/XmlLabelCreator.cpp +++ b/glabels/XmlLabelCreator.cpp @@ -23,7 +23,7 @@ #include "EnumUtil.h" #include "LabelModel.h" #include "LabelModelObject.h" -//#include "LabelModelBarcodeObject.h" +#include "LabelModelBarcodeObject.h" #include "LabelModelBoxObject.h" #include "LabelModelEllipseObject.h" #include "LabelModelLineObject.h" @@ -147,11 +147,14 @@ namespace glabels { createObjectImageNode( node, imageObject ); } + else if ( LabelModelBarcodeObject* barcodeObject = dynamic_cast(object) ) + { + createObjectBarcodeNode( node, barcodeObject ); + } else if ( LabelModelTextObject* textObject = dynamic_cast(object) ) { createObjectTextNode( node, textObject ); } - // TODO: other object types else { Q_ASSERT_X( false, "XmlLabelCreator::createObjectsNode", "Invalid object type." ); @@ -273,7 +276,33 @@ namespace glabels void XmlLabelCreator::createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object ) { - // TODO + QDomDocument doc = parent.ownerDocument(); + QDomElement node = doc.createElement( "Object-barcode" ); + parent.appendChild( node ); + + /* position attrs */ + createPositionAttrs( node, object ); + + /* size attrs */ + createSizeAttrs( node, object ); + + /* barcode attrs */ + XmlUtil::setStringAttr( node, "backend", object->bcStyle().backendId() ); + XmlUtil::setStringAttr( node, "style", object->bcStyle().id() ); + XmlUtil::setBoolAttr( node, "text", object->bcTextFlag() ); + XmlUtil::setBoolAttr( node, "checksum", object->bcChecksumFlag() ); + if ( object->bcColorNode().isField() ) + { + XmlUtil::setStringAttr( node, "color_field", object->bcColorNode().key() ); + } + else + { + XmlUtil::setUIntAttr( node, "color", object->bcColorNode().rgba() ); + } + XmlUtil::setStringAttr( node, "data", object->bcData() ); + + /* affine attrs */ + createAffineAttrs( node, object ); } diff --git a/glabels/XmlLabelParser.cpp b/glabels/XmlLabelParser.cpp index 00c7162..af17fa4 100644 --- a/glabels/XmlLabelParser.cpp +++ b/glabels/XmlLabelParser.cpp @@ -20,10 +20,11 @@ #include "XmlLabelParser.h" +#include "BarcodeBackends.h" #include "EnumUtil.h" #include "LabelModel.h" #include "LabelModelObject.h" -//#include "LabelModelBarcodeObject.h" +#include "LabelModelBarcodeObject.h" #include "LabelModelBoxObject.h" #include "LabelModelEllipseObject.h" #include "LabelModelImageObject.h" @@ -317,12 +318,10 @@ namespace glabels { list.append( parseObjectImageNode( child.toElement(), data ) ); } -#if 0 else if ( tagName == "Object-barcode" ) { list.append( parseObjectBarcodeNode( child.toElement() ) ); } -#endif else if ( !child.isComment() ) { qWarning() << "Unexpected" << node.tagName() << "child:" << tagName; @@ -466,7 +465,33 @@ namespace glabels LabelModelBarcodeObject* XmlLabelParser::parseObjectBarcodeNode( const QDomElement &node ) { - return nullptr; + LabelModelBarcodeObject* object = new LabelModelBarcodeObject(); + + + /* position attrs */ + parsePositionAttrs( node, object ); + + /* size attrs */ + parseSizeAttrs( node, object ); + + /* barcode attrs */ + BarcodeStyle bcStyle = BarcodeBackends::style( XmlUtil::getStringAttr( node, "backend", "" ), + XmlUtil::getStringAttr( node, "style", "") ); + object->setBcStyle( bcStyle ); + object->setBcTextFlag( XmlUtil::getBoolAttr( node, "text", true ) ); + object->setBcChecksumFlag( XmlUtil::getBoolAttr( node, "checksum", true ) ); + + QString key = XmlUtil::getStringAttr( node, "color_field", "" ); + bool field_flag = !key.isEmpty(); + uint32_t color = XmlUtil::getUIntAttr( node, "color", 0 ); + object->setBcColorNode( ColorNode( field_flag, color, key ) ); + + object->setBcData( XmlUtil::getStringAttr( node, "data", "" ) ); + + /* affine attrs */ + parseAffineAttrs( node, object ); + + return object; } diff --git a/templates/glabels-4.0.dtd b/templates/glabels-4.0.dtd index 46f05d4..b302179 100644 --- a/templates/glabels-4.0.dtd +++ b/templates/glabels-4.0.dtd @@ -411,11 +411,8 @@ checksum %BOOLEAN_TYPE; #REQUIRED color %UINT_TYPE; #IMPLIED color_field %STRING_TYPE; #IMPLIED - data %STRING_TYPE; #IMPLIED - field %STRING_TYPE; #IMPLIED - format %UINT_TYPE; #IMPLIED + data %STRING_TYPE; #REQUIRED %affine_attrs; - %shadow_attrs; > diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 63ca387..eed1e2d 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1115,12 +1115,12 @@ glabels::LabelModelBarcodeObject - + No barcode data - + Invalid barcode data