Added variables expansion to TextNode and ColorNode.
This commit is contained in:
+21
-19
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-1
@@ -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;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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) )
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
+21
-35
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -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
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user