diff --git a/model/ColorNode.cpp b/model/ColorNode.cpp index f399a1a..ceee003 100644 --- a/model/ColorNode.cpp +++ b/model/ColorNode.cpp @@ -175,30 +175,32 @@ namespace glabels /// /// Get color, expand if necessary /// - QColor ColorNode::color( merge::Record* record ) const + QColor ColorNode::color( const merge::Record* record, + const Variables* variables ) const { - if ( mIsField ) + QColor value = QColor( 192, 192, 192, 128 ); + + bool haveRecordField = mIsField && record && + record->contains(mKey) && + !record->value(mKey).isEmpty(); + bool haveVariable = mIsField && variables && + variables->contains(mKey) && + !(*variables)[mKey].value().isEmpty(); + + if ( haveRecordField ) { - if ( record == nullptr ) - { - return mColor; - } - else - { - if ( record->contains( mKey ) ) - { - return QColor( (*record)[ mKey ] ); - } - else - { - return mColor; - } - } + value = QColor( record->value(mKey) ); } - else + else if ( haveVariable ) { - return mColor; + value = QColor( (*variables)[mKey].value() ); } + else if ( !mIsField ) + { + value = mColor; + } + + return value; } } diff --git a/model/ColorNode.h b/model/ColorNode.h index 89b0201..dab30af 100644 --- a/model/ColorNode.h +++ b/model/ColorNode.h @@ -22,6 +22,7 @@ #define model_ColorNode_h +#include "Variables.h" #include "merge/Record.h" #include @@ -95,7 +96,8 @@ namespace glabels ///////////////////////////////// public: uint32_t rgba() const; - QColor color( merge::Record* record ) const; + QColor color( const merge::Record* record, + const Variables* variables ) const; ///////////////////////////////// diff --git a/model/ModelBarcodeObject.cpp b/model/ModelBarcodeObject.cpp index 3b65e10..9a1daa4 100644 --- a/model/ModelBarcodeObject.cpp +++ b/model/ModelBarcodeObject.cpp @@ -326,7 +326,7 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor bcColor = mBcColorNode.color( record ); + QColor bcColor = mBcColorNode.color( record, variables ); if ( inEditor ) { diff --git a/model/ModelBoxObject.cpp b/model/ModelBoxObject.cpp index 24a61c6..701574a 100644 --- a/model/ModelBoxObject.cpp +++ b/model/ModelBoxObject.cpp @@ -108,9 +108,9 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); @@ -156,8 +156,8 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setBrush( fillColor ); diff --git a/model/ModelEllipseObject.cpp b/model/ModelEllipseObject.cpp index e9e58fd..85591e9 100644 --- a/model/ModelEllipseObject.cpp +++ b/model/ModelEllipseObject.cpp @@ -108,9 +108,9 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); @@ -156,8 +156,8 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setBrush( fillColor ); diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 9c30a42..9758a8d 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -413,7 +413,7 @@ namespace glabels { QRectF destRect( 0, 0, mW.pt(), mH.pt() ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) ) diff --git a/model/ModelLineObject.cpp b/model/ModelLineObject.cpp index 9223f91..44946a0 100644 --- a/model/ModelLineObject.cpp +++ b/model/ModelLineObject.cpp @@ -191,8 +191,8 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); @@ -212,7 +212,7 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->drawLine( 0, 0, mW.pt(), mH.pt() ); diff --git a/model/ModelTextObject.cpp b/model/ModelTextObject.cpp index 45c259e..1d24f30 100644 --- a/model/ModelTextObject.cpp +++ b/model/ModelTextObject.cpp @@ -521,11 +521,11 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor textColor = mTextColorNode.color( record ); + QColor textColor = mTextColorNode.color( record, variables ); if ( textColor.alpha() ) { - QColor shadowColor = mShadowColorNode.color( record ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); if ( inEditor ) @@ -548,7 +548,7 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor textColor = mTextColorNode.color( record ); + QColor textColor = mTextColorNode.color( record, variables ); if ( inEditor ) { diff --git a/model/TextNode.cpp b/model/TextNode.cpp index 332367e..b0e2271 100644 --- a/model/TextNode.cpp +++ b/model/TextNode.cpp @@ -105,48 +105,34 @@ namespace glabels /// /// Get text, expand if necessary /// - QString TextNode::text( merge::Record* record ) const + QString TextNode::text( const merge::Record* record, + const Variables* variables ) const { - if ( mIsField ) + QString value(""); + + bool haveRecordField = mIsField && record && + record->contains(mData) && + !record->value(mData).isEmpty(); + bool haveVariable = mIsField && variables && + variables->contains(mData) && + !(*variables)[mData].value().isEmpty(); + + if ( haveRecordField ) { - if ( !record ) - { - return QString("${%1}").arg( mData ); - } - else - { - if ( record->contains( mData ) ) - { - return (*record)[ mData ]; - } - else - { - return ""; - } - } + value = record->value(mData); } - else + else if ( haveVariable ) { - return mData; + value = (*variables)[mData].value(); } + else if ( !mIsField ) + { + value = mData; + } + + return value; } - /// - /// Is it an empty field - /// - bool TextNode::isEmptyField( merge::Record* record ) const - { - if ( record && mIsField ) - { - if ( record->contains( mData ) ) - { - return (*record)[mData].isEmpty(); - } - } - - return false; - } - } } diff --git a/model/TextNode.h b/model/TextNode.h index 499f863..c7716d7 100644 --- a/model/TextNode.h +++ b/model/TextNode.h @@ -22,6 +22,7 @@ #define model_TextNode_h +#include "Variables.h" #include "merge/Record.h" #include @@ -76,8 +77,8 @@ namespace glabels ///////////////////////////////// // Misc. Methods ///////////////////////////////// - QString text( merge::Record* record ) const; - bool isEmptyField( merge::Record* record ) const; + QString text( const merge::Record* record, + const Variables* variables ) const; ///////////////////////////////// diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index 07fd543..ed9bdb9 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -364,13 +364,13 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0xFF ); ColorNode lineColorNode( field_flag, color, key ); /* fill attrs */ key = XmlUtil::getStringAttr( node, "fill_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); + color = XmlUtil::getUIntAttr( node, "fill_color", 0xFF ); ColorNode fillColorNode( field_flag, color, key ); /* affine attrs */ @@ -390,7 +390,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); return new ModelBoxObject( x0, y0, w, h, @@ -417,13 +417,13 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0xFF ); ColorNode lineColorNode( field_flag, color, key ); /* fill attrs */ key = XmlUtil::getStringAttr( node, "fill_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); + color = XmlUtil::getUIntAttr( node, "fill_color", 0xFF ); ColorNode fillColorNode( field_flag, color, key ); /* affine attrs */ @@ -443,7 +443,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); return new ModelEllipseObject( x0, y0, w, h, @@ -470,7 +470,7 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0xFF ); ColorNode lineColorNode( field_flag, color, key ); /* affine attrs */ @@ -490,7 +490,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); return new ModelLineObject( x0, y0, dx, dy, @@ -534,7 +534,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); if ( filenameNode.isField() ) @@ -591,7 +591,7 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "color", 0xFF ); ColorNode bcColorNode( field_flag, color, key ); QString bcData = XmlUtil::getStringAttr( node, "data", "" ); @@ -625,7 +625,7 @@ namespace glabels /* color attr */ QString key = XmlUtil::getStringAttr( node, "color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "color", 0xFF ); ColorNode textColorNode( field_flag, color, key ); /* font attrs */ @@ -659,7 +659,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); /* deserialize contents. */