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
+20 -18
View File
@@ -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;
value = QColor( record->value(mKey) );
}
else
else if ( haveVariable )
{
if ( record->contains( mKey ) )
value = QColor( (*variables)[mKey].value() );
}
else if ( !mIsField )
{
return QColor( (*record)[ mKey ] );
}
else
{
return mColor;
}
}
}
else
{
return mColor;
value = mColor;
}
return value;
}
}
+3 -1
View File
@@ -22,6 +22,7 @@
#define model_ColorNode_h
#include "Variables.h"
#include "merge/Record.h"
#include <QString>
@@ -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;
/////////////////////////////////
+1 -1
View File
@@ -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 )
{
+5 -5
View File
@@ -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 );
+5 -5
View File
@@ -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 );
+1 -1
View File
@@ -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) )
+3 -3
View File
@@ -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() );
+3 -3
View File
@@ -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 )
{
+20 -34
View File
@@ -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 );
value = record->value(mData);
}
else
else if ( haveVariable )
{
if ( record->contains( mData ) )
value = (*variables)[mData].value();
}
else if ( !mIsField )
{
return (*record)[ mData ];
}
else
{
return "";
}
}
}
else
{
return mData;
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
#include "Variables.h"
#include "merge/Record.h"
#include <QString>
@@ -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;
/////////////////////////////////
+12 -12
View File
@@ -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. */