From e2a3b68ffc281a98da1f3fb442119e8bfea2e34d Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Thu, 16 Mar 2017 22:10:04 -0400 Subject: [PATCH] XmlLabel* cleanup. --- glabels/XmlLabelCreator.cpp | 123 +++++----- glabels/XmlLabelCreator.h | 4 + glabels/XmlLabelParser.cpp | 148 ++++++------ glabels/XmlLabelParser.h | 4 + templates/CMakeLists.txt | 7 +- templates/glabels-4.0.dtd | 462 ++++++++++++++++++++++++++++++++++++ 6 files changed, 606 insertions(+), 142 deletions(-) create mode 100644 templates/glabels-4.0.dtd diff --git a/glabels/XmlLabelCreator.cpp b/glabels/XmlLabelCreator.cpp index 412ada5..9404418 100644 --- a/glabels/XmlLabelCreator.cpp +++ b/glabels/XmlLabelCreator.cpp @@ -169,33 +169,16 @@ namespace glabels parent.appendChild( node ); /* position attrs */ - XmlUtil::setLengthAttr( node, "x", object->x0() ); - XmlUtil::setLengthAttr( node, "y", object->y0() ); + createPositionAttrs( node, object ); /* size attrs */ - XmlUtil::setLengthAttr( node, "w", object->w() ); - XmlUtil::setLengthAttr( node, "h", object->h() ); + createSizeAttrs( node, object ); /* line attrs */ - XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); - if ( object->lineColorNode().isField() ) - { - XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); - } - else - { - XmlUtil::setUIntAttr( node, "line_color", object->lineColorNode().rgba() ); - } + createLineAttrs( node, object ); /* fill attrs */ - if ( object->fillColorNode().isField() ) - { - XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() ); - } - else - { - XmlUtil::setUIntAttr( node, "fill_color", object->fillColorNode().rgba() ); - } + createFillAttrs( node, object ); /* affine attrs */ createAffineAttrs( node, object ); @@ -213,33 +196,16 @@ namespace glabels parent.appendChild( node ); /* position attrs */ - XmlUtil::setLengthAttr( node, "x", object->x0() ); - XmlUtil::setLengthAttr( node, "y", object->y0() ); + createPositionAttrs( node, object ); /* size attrs */ - XmlUtil::setLengthAttr( node, "w", object->w() ); - XmlUtil::setLengthAttr( node, "h", object->h() ); + createSizeAttrs( node, object ); /* line attrs */ - XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); - if ( object->lineColorNode().isField() ) - { - XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); - } - else - { - XmlUtil::setUIntAttr( node, "line_color", object->lineColorNode().rgba() ); - } + createLineAttrs( node, object ); /* fill attrs */ - if ( object->fillColorNode().isField() ) - { - XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() ); - } - else - { - XmlUtil::setUIntAttr( node, "fill_color", object->fillColorNode().rgba() ); - } + createFillAttrs( node, object ); /* affine attrs */ createAffineAttrs( node, object ); @@ -257,23 +223,14 @@ namespace glabels parent.appendChild( node ); /* position attrs */ - XmlUtil::setLengthAttr( node, "x", object->x0() ); - XmlUtil::setLengthAttr( node, "y", object->y0() ); + createPositionAttrs( node, object ); - /* size attrs */ + /* size attrs of line */ XmlUtil::setLengthAttr( node, "dx", object->w() ); XmlUtil::setLengthAttr( node, "dy", object->h() ); /* line attrs */ - XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); - if ( object->lineColorNode().isField() ) - { - XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); - } - else - { - XmlUtil::setUIntAttr( node, "line_color", object->lineColorNode().rgba() ); - } + createLineAttrs( node, object ); /* affine attrs */ createAffineAttrs( node, object ); @@ -291,15 +248,12 @@ namespace glabels parent.appendChild( node ); /* position attrs */ - XmlUtil::setLengthAttr( node, "x", object->x0() ); - XmlUtil::setLengthAttr( node, "y", object->y0() ); + createPositionAttrs( node, object ); /* size attrs */ - XmlUtil::setLengthAttr( node, "w", object->w() ); - XmlUtil::setLengthAttr( node, "h", object->h() ); + createSizeAttrs( node, object ); /* file attrs */ - XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); if ( object->filenameNode().isField() ) { XmlUtil::setStringAttr( node, "src_field", object->filenameNode().data() ); @@ -332,12 +286,10 @@ namespace glabels parent.appendChild( node ); /* position attrs */ - XmlUtil::setLengthAttr( node, "x", object->x0() ); - XmlUtil::setLengthAttr( node, "y", object->y0() ); + createPositionAttrs( node, object ); /* size attrs */ - XmlUtil::setLengthAttr( node, "w", object->w() ); - XmlUtil::setLengthAttr( node, "h", object->h() ); + createSizeAttrs( node, object ); /* color attr */ if ( object->textColorNode().isField() ) @@ -388,6 +340,51 @@ namespace glabels } + void + XmlLabelCreator::createPositionAttrs( QDomElement &node, const LabelModelObject* object ) + { + XmlUtil::setLengthAttr( node, "x", object->x0() ); + XmlUtil::setLengthAttr( node, "y", object->y0() ); + } + + + void + XmlLabelCreator::createSizeAttrs( QDomElement &node, const LabelModelObject* object ) + { + XmlUtil::setLengthAttr( node, "w", object->w() ); + XmlUtil::setLengthAttr( node, "h", object->h() ); + } + + + void + XmlLabelCreator::createLineAttrs( QDomElement &node, const LabelModelObject* object ) + { + XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); + if ( object->lineColorNode().isField() ) + { + XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); + } + else + { + XmlUtil::setUIntAttr( node, "line_color", object->lineColorNode().rgba() ); + } + } + + + void + XmlLabelCreator::createFillAttrs( QDomElement &node, const LabelModelObject* object ) + { + if ( object->fillColorNode().isField() ) + { + XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() ); + } + else + { + XmlUtil::setUIntAttr( node, "fill_color", object->fillColorNode().rgba() ); + } + } + + void XmlLabelCreator::createAffineAttrs( QDomElement &node, const LabelModelObject* object ) { diff --git a/glabels/XmlLabelCreator.h b/glabels/XmlLabelCreator.h index e7a031b..0f462f3 100644 --- a/glabels/XmlLabelCreator.h +++ b/glabels/XmlLabelCreator.h @@ -63,6 +63,10 @@ namespace glabels static void createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object ); static void createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object ); static void createPNode( QDomElement &parent, const QString& blockText ); + static void createPositionAttrs( QDomElement &node, const LabelModelObject* object ); + static void createSizeAttrs( QDomElement &node, const LabelModelObject* object ); + static void createLineAttrs( QDomElement &node, const LabelModelObject* object ); + static void createFillAttrs( QDomElement &node, const LabelModelObject* object ); static void createAffineAttrs( QDomElement &node, const LabelModelObject* object ); static void createShadowAttrs( QDomElement &node, const LabelModelObject* object ); static void createMergeNode( QDomElement &parent, const LabelModel* label ); diff --git a/glabels/XmlLabelParser.cpp b/glabels/XmlLabelParser.cpp index 6874724..eb0075e 100644 --- a/glabels/XmlLabelParser.cpp +++ b/glabels/XmlLabelParser.cpp @@ -339,31 +339,16 @@ namespace glabels /* position attrs */ - object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) ); - object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) ); + parsePositionAttrs( node, object ); /* size attrs */ - object->setW( XmlUtil::getLengthAttr( node, "w", 0 ) ); - object->setH( XmlUtil::getLengthAttr( node, "h", 0 ) ); + parseSizeAttrs( node, object ); /* line attrs */ - object->setLineWidth( XmlUtil::getLengthAttr( node, "line_width", 1.0 ) ); - { - QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); - bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); - - object->setLineColorNode( ColorNode( field_flag, color, key ) ); - } + parseLineAttrs( node, object ); /* fill attrs */ - { - QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); - bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); - - object->setFillColorNode( ColorNode( field_flag, color, key ) ); - } + parseFillAttrs( node, object ); /* affine attrs */ parseAffineAttrs( node, object ); @@ -382,31 +367,16 @@ namespace glabels /* position attrs */ - object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) ); - object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) ); + parsePositionAttrs( node, object ); /* size attrs */ - object->setW( XmlUtil::getLengthAttr( node, "w", 0 ) ); - object->setH( XmlUtil::getLengthAttr( node, "h", 0 ) ); + parseSizeAttrs( node, object ); /* line attrs */ - object->setLineWidth( XmlUtil::getLengthAttr( node, "line_width", 1.0 ) ); - { - QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); - bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); - - object->setLineColorNode( ColorNode( field_flag, color, key ) ); - } + parseLineAttrs( node, object ); /* fill attrs */ - { - QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); - bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); - - object->setFillColorNode( ColorNode( field_flag, color, key ) ); - } + parseFillAttrs( node, object ); /* affine attrs */ parseAffineAttrs( node, object ); @@ -425,22 +395,14 @@ namespace glabels /* position attrs */ - object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) ); - object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) ); + parsePositionAttrs( node, object ); - /* size attrs */ + /* size attrs of line */ object->setW( XmlUtil::getLengthAttr( node, "dx", 0 ) ); object->setH( XmlUtil::getLengthAttr( node, "dy", 0 ) ); /* line attrs */ - object->setLineWidth( XmlUtil::getLengthAttr( node, "line_width", 1.0 ) ); - { - QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); - bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); - - object->setLineColorNode( ColorNode( field_flag, color, key ) ); - } + parseLineAttrs( node, object ); /* affine attrs */ parseAffineAttrs( node, object ); @@ -459,33 +421,29 @@ namespace glabels /* position attrs */ - object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) ); - object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) ); + parsePositionAttrs( node, object ); /* size attrs */ - object->setW( XmlUtil::getLengthAttr( node, "w", 0 ) ); - object->setH( XmlUtil::getLengthAttr( node, "h", 0 ) ); + parseSizeAttrs( node, object ); /* file attrs */ - { - QString key = XmlUtil::getStringAttr( node, "src_field", "" ); - bool field_flag = !key.isEmpty(); - QString filename = XmlUtil::getStringAttr( node, "src", "" ); + QString key = XmlUtil::getStringAttr( node, "src_field", "" ); + bool field_flag = !key.isEmpty(); + QString filename = XmlUtil::getStringAttr( node, "src", "" ); - if ( field_flag ) + if ( field_flag ) + { + object->setFilenameNode( TextNode( true, key ) ); + } + else + { + if ( data.hasImage( filename ) ) { - object->setFilenameNode( TextNode( true, key ) ); + object->setImage( filename, data.getImage( filename ) ); } else { - if ( data.hasImage( filename ) ) - { - object->setImage( filename, data.getImage( filename ) ); - } - else - { - object->setFilenameNode( TextNode( false, filename ) ); - } + object->setFilenameNode( TextNode( false, filename ) ); } } @@ -513,21 +471,17 @@ namespace glabels /* position attrs */ - object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) ); - object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) ); + parsePositionAttrs( node, object ); /* size attrs */ - object->setW( XmlUtil::getLengthAttr( node, "w", 0 ) ); - object->setH( XmlUtil::getLengthAttr( node, "h", 0 ) ); + parseSizeAttrs( node, object ); /* color attr */ - { - QString key = XmlUtil::getStringAttr( node, "color_field", "" ); - bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "color", 0 ); + QString key = XmlUtil::getStringAttr( node, "color_field", "" ); + bool field_flag = !key.isEmpty(); + uint32_t color = XmlUtil::getUIntAttr( node, "color", 0 ); - object->setTextColorNode( ColorNode( field_flag, color, key ) ); - } + object->setTextColorNode( ColorNode( field_flag, color, key ) ); /* font attrs */ object->setFontFamily( XmlUtil::getStringAttr( node, "font_family", "Sans" ) ); @@ -582,6 +536,46 @@ namespace glabels } + void + XmlLabelParser::parsePositionAttrs( const QDomElement &node, LabelModelObject* object ) + { + object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) ); + object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) ); + } + + + void + XmlLabelParser::parseSizeAttrs( const QDomElement &node, LabelModelObject* object ) + { + object->setW( XmlUtil::getLengthAttr( node, "w", 0 ) ); + object->setH( XmlUtil::getLengthAttr( node, "h", 0 ) ); + } + + + void + XmlLabelParser::parseLineAttrs( const QDomElement &node, LabelModelObject* object ) + { + object->setLineWidth( XmlUtil::getLengthAttr( node, "line_width", 1.0 ) ); + + QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); + bool field_flag = !key.isEmpty(); + uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); + + object->setLineColorNode( ColorNode( field_flag, color, key ) ); + } + + + void + XmlLabelParser::parseFillAttrs( const QDomElement &node, LabelModelObject* object ) + { + QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); + bool field_flag = !key.isEmpty(); + uint32_t color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); + + object->setFillColorNode( ColorNode( field_flag, color, key ) ); + } + + void XmlLabelParser::parseAffineAttrs( const QDomElement &node, LabelModelObject* object ) { diff --git a/glabels/XmlLabelParser.h b/glabels/XmlLabelParser.h index 93e4c4d..3de2c25 100644 --- a/glabels/XmlLabelParser.h +++ b/glabels/XmlLabelParser.h @@ -64,6 +64,10 @@ namespace glabels static LabelModelBarcodeObject* parseObjectBarcodeNode( const QDomElement &node ); static LabelModelTextObject* parseObjectTextNode( const QDomElement &node ); static QString parsePNode( const QDomElement &node ); + static void parsePositionAttrs( const QDomElement &node, LabelModelObject* object ); + static void parseSizeAttrs( const QDomElement &node, LabelModelObject* object ); + static void parseLineAttrs( const QDomElement &node, LabelModelObject* object ); + static void parseFillAttrs( const QDomElement &node, LabelModelObject* object ); static void parseAffineAttrs( const QDomElement &node, LabelModelObject* object ); static void parseShadowAttrs( const QDomElement &node, LabelModelObject* object ); static void parseMergeNode( const QDomElement &node, LabelModel* label ); diff --git a/templates/CMakeLists.txt b/templates/CMakeLists.txt index 7576bfe..a569223 100644 --- a/templates/CMakeLists.txt +++ b/templates/CMakeLists.txt @@ -1,7 +1,10 @@ #======================================= # Template Files #======================================= -set (template_dtd glabels-3.0.dtd) +set (dtd_files + glabels-3.0.dtd + glabels-4.0.dtd +) set (template_files ascom-iso-templates.xml @@ -49,6 +52,6 @@ set (other_db_files #======================================= # Install #======================================= -install (FILES ${template_dtd} DESTINATION share/glabels-qt/templates) +install (FILES ${dtd_files} DESTINATION share/glabels-qt/templates) install (FILES ${template_files} DESTINATION share/glabels-qt/templates) install (FILES ${other_db_files} DESTINATION share/glabels-qt/templates) diff --git a/templates/glabels-4.0.dtd b/templates/glabels-4.0.dtd new file mode 100644 index 0000000..46f05d4 --- /dev/null +++ b/templates/glabels-4.0.dtd @@ -0,0 +1,462 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +