Added variables expansion to TextNode and ColorNode.

This commit is contained in:
Jim Evins
2019-07-27 22:00:05 -04:00
parent f6ecdc64e0
commit 57cbf18039
11 changed files with 78 additions and 87 deletions
+21 -19
View File
@@ -175,30 +175,32 @@ namespace glabels
/// ///
/// Get color, expand if necessary /// 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 ) value = QColor( record->value(mKey) );
{
return mColor;
}
else
{
if ( record->contains( mKey ) )
{
return QColor( (*record)[ mKey ] );
}
else
{
return mColor;
}
}
} }
else else if ( haveVariable )
{ {
return mColor; value = QColor( (*variables)[mKey].value() );
} }
else if ( !mIsField )
{
value = mColor;
}
return value;
} }
} }
+3 -1
View File
@@ -22,6 +22,7 @@
#define model_ColorNode_h #define model_ColorNode_h
#include "Variables.h"
#include "merge/Record.h" #include "merge/Record.h"
#include <QString> #include <QString>
@@ -95,7 +96,8 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
uint32_t rgba() const; uint32_t rgba() const;
QColor color( merge::Record* record ) const; QColor color( const merge::Record* record,
const Variables* variables ) const;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -326,7 +326,7 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor bcColor = mBcColorNode.color( record ); QColor bcColor = mBcColorNode.color( record, variables );
if ( inEditor ) if ( inEditor )
{ {
+5 -5
View File
@@ -108,9 +108,9 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record ); QColor fillColor = mFillColorNode.color( record, variables );
QColor shadowColor = mShadowColorNode.color( record ); QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity ); shadowColor.setAlphaF( mShadowOpacity );
@@ -156,8 +156,8 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record ); QColor fillColor = mFillColorNode.color( record, variables );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->setBrush( fillColor ); painter->setBrush( fillColor );
+5 -5
View File
@@ -108,9 +108,9 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record ); QColor fillColor = mFillColorNode.color( record, variables );
QColor shadowColor = mShadowColorNode.color( record ); QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity ); shadowColor.setAlphaF( mShadowOpacity );
@@ -156,8 +156,8 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record ); QColor fillColor = mFillColorNode.color( record, variables );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->setBrush( fillColor ); painter->setBrush( fillColor );
+1 -1
View File
@@ -413,7 +413,7 @@ namespace glabels
{ {
QRectF destRect( 0, 0, mW.pt(), mH.pt() ); QRectF destRect( 0, 0, mW.pt(), mH.pt() );
QColor shadowColor = mShadowColorNode.color( record ); QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity ); shadowColor.setAlphaF( mShadowOpacity );
if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) ) if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) )
+3 -3
View File
@@ -191,8 +191,8 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record, variables );
QColor shadowColor = mShadowColorNode.color( record ); QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity ); shadowColor.setAlphaF( mShadowOpacity );
@@ -212,7 +212,7 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record, variables );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->drawLine( 0, 0, mW.pt(), mH.pt() ); painter->drawLine( 0, 0, mW.pt(), mH.pt() );
+3 -3
View File
@@ -521,11 +521,11 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor textColor = mTextColorNode.color( record ); QColor textColor = mTextColorNode.color( record, variables );
if ( textColor.alpha() ) if ( textColor.alpha() )
{ {
QColor shadowColor = mShadowColorNode.color( record ); QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity ); shadowColor.setAlphaF( mShadowOpacity );
if ( inEditor ) if ( inEditor )
@@ -548,7 +548,7 @@ namespace glabels
merge::Record* record, merge::Record* record,
Variables* variables ) const Variables* variables ) const
{ {
QColor textColor = mTextColorNode.color( record ); QColor textColor = mTextColorNode.color( record, variables );
if ( inEditor ) if ( inEditor )
{ {
+21 -35
View File
@@ -105,48 +105,34 @@ namespace glabels
/// ///
/// Get text, expand if necessary /// 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 ) value = record->value(mData);
{
return QString("${%1}").arg( mData );
}
else
{
if ( record->contains( mData ) )
{
return (*record)[ mData ];
}
else
{
return "";
}
}
} }
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;
}
} }
} }
+3 -2
View File
@@ -22,6 +22,7 @@
#define model_TextNode_h #define model_TextNode_h
#include "Variables.h"
#include "merge/Record.h" #include "merge/Record.h"
#include <QString> #include <QString>
@@ -76,8 +77,8 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
// Misc. Methods // Misc. Methods
///////////////////////////////// /////////////////////////////////
QString text( merge::Record* record ) const; QString text( const merge::Record* record,
bool isEmptyField( merge::Record* record ) const; const Variables* variables ) const;
///////////////////////////////// /////////////////////////////////
+12 -12
View File
@@ -364,13 +364,13 @@ namespace glabels
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty(); 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 ); ColorNode lineColorNode( field_flag, color, key );
/* fill attrs */ /* fill attrs */
key = XmlUtil::getStringAttr( node, "fill_color_field", "" ); key = XmlUtil::getStringAttr( node, "fill_color_field", "" );
field_flag = !key.isEmpty(); field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); color = XmlUtil::getUIntAttr( node, "fill_color", 0xFF );
ColorNode fillColorNode( field_flag, color, key ); ColorNode fillColorNode( field_flag, color, key );
/* affine attrs */ /* affine attrs */
@@ -390,7 +390,7 @@ namespace glabels
key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty(); field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF );
ColorNode shadowColorNode( field_flag, color, key ); ColorNode shadowColorNode( field_flag, color, key );
return new ModelBoxObject( x0, y0, w, h, return new ModelBoxObject( x0, y0, w, h,
@@ -417,13 +417,13 @@ namespace glabels
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty(); 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 ); ColorNode lineColorNode( field_flag, color, key );
/* fill attrs */ /* fill attrs */
key = XmlUtil::getStringAttr( node, "fill_color_field", "" ); key = XmlUtil::getStringAttr( node, "fill_color_field", "" );
field_flag = !key.isEmpty(); field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); color = XmlUtil::getUIntAttr( node, "fill_color", 0xFF );
ColorNode fillColorNode( field_flag, color, key ); ColorNode fillColorNode( field_flag, color, key );
/* affine attrs */ /* affine attrs */
@@ -443,7 +443,7 @@ namespace glabels
key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty(); field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF );
ColorNode shadowColorNode( field_flag, color, key ); ColorNode shadowColorNode( field_flag, color, key );
return new ModelEllipseObject( x0, y0, w, h, return new ModelEllipseObject( x0, y0, w, h,
@@ -470,7 +470,7 @@ namespace glabels
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty(); 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 ); ColorNode lineColorNode( field_flag, color, key );
/* affine attrs */ /* affine attrs */
@@ -490,7 +490,7 @@ namespace glabels
key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty(); field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF );
ColorNode shadowColorNode( field_flag, color, key ); ColorNode shadowColorNode( field_flag, color, key );
return new ModelLineObject( x0, y0, dx, dy, return new ModelLineObject( x0, y0, dx, dy,
@@ -534,7 +534,7 @@ namespace glabels
key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty(); 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 ); ColorNode shadowColorNode( field_flag, color, key );
if ( filenameNode.isField() ) if ( filenameNode.isField() )
@@ -591,7 +591,7 @@ namespace glabels
QString key = XmlUtil::getStringAttr( node, "color_field", "" ); QString key = XmlUtil::getStringAttr( node, "color_field", "" );
bool field_flag = !key.isEmpty(); 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 ); ColorNode bcColorNode( field_flag, color, key );
QString bcData = XmlUtil::getStringAttr( node, "data", "" ); QString bcData = XmlUtil::getStringAttr( node, "data", "" );
@@ -625,7 +625,7 @@ namespace glabels
/* color attr */ /* color attr */
QString key = XmlUtil::getStringAttr( node, "color_field", "" ); QString key = XmlUtil::getStringAttr( node, "color_field", "" );
bool field_flag = !key.isEmpty(); 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 ); ColorNode textColorNode( field_flag, color, key );
/* font attrs */ /* font attrs */
@@ -659,7 +659,7 @@ namespace glabels
key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty(); field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF );
ColorNode shadowColorNode( field_flag, color, key ); ColorNode shadowColorNode( field_flag, color, key );
/* deserialize contents. */ /* deserialize contents. */