Reconcile style differences between TextNode and ColorNode classes.

This commit is contained in:
Jim Evins
2017-01-06 02:51:44 -05:00
parent 90ea790e7a
commit 5b65f069dd
7 changed files with 83 additions and 58 deletions
+4 -4
View File
@@ -67,7 +67,7 @@ void ColorButton::setColorNode( ColorNode colorNode )
mColorNode = colorNode; mColorNode = colorNode;
if ( colorNode.fieldFlag() ) if ( colorNode.isField() )
{ {
setIcon( QIcon() ); setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) ); setText( QString("${%1}").arg( colorNode.key() ) );
@@ -86,7 +86,7 @@ void ColorButton::setColor( QColor color )
{ {
mIsDefault = false; mIsDefault = false;
mColorNode.setFieldFlag( false ); mColorNode.setField( false );
mColorNode.setColor( color ); mColorNode.setColor( color );
mColorNode.setKey( "" ); mColorNode.setKey( "" );
@@ -99,7 +99,7 @@ void ColorButton::setToDefault()
{ {
mIsDefault = true; mIsDefault = true;
mColorNode.setFieldFlag( false ); mColorNode.setField( false );
mColorNode.setColor( mDefaultColor ); mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" ); mColorNode.setKey( "" );
@@ -158,7 +158,7 @@ void ColorButton::onPaletteDialogChanged( ColorNode colorNode, bool isDefault )
mColorNode = colorNode; mColorNode = colorNode;
mIsDefault = isDefault; mIsDefault = isDefault;
if ( colorNode.fieldFlag() ) if ( colorNode.isField() )
{ {
setIcon( QIcon() ); setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) ); setText( QString("${%1}").arg( colorNode.key() ) );
+29 -23
View File
@@ -1,6 +1,6 @@
/* ColorNode.cpp /* ColorNode.cpp
* *
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com> * Copyright (C) 2017 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -27,7 +27,7 @@
/// Default Constructor /// Default Constructor
/// ///
ColorNode::ColorNode() ColorNode::ColorNode()
: mFieldFlag(false), mColor(QColor::fromRgba(0x00000000)), mKey("") : mIsField(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
{ {
} }
@@ -35,8 +35,8 @@ ColorNode::ColorNode()
/// ///
/// Constructor From Data /// Constructor From Data
/// ///
ColorNode::ColorNode( bool fieldFlag, const QColor& color, const QString& key ) ColorNode::ColorNode( bool isField, const QColor& color, const QString& key )
: mFieldFlag(fieldFlag), mColor(color), mKey(key) : mIsField(isField), mColor(color), mKey(key)
{ {
} }
@@ -44,8 +44,8 @@ ColorNode::ColorNode( bool fieldFlag, const QColor& color, const QString& key )
/// ///
/// Constructor From Data /// Constructor From Data
/// ///
ColorNode::ColorNode( bool fieldFlag, uint32_t rgba, const QString& key ) ColorNode::ColorNode( bool isField, uint32_t rgba, const QString& key )
: mFieldFlag(fieldFlag), mKey(key) : mIsField(isField), mKey(key)
{ {
mColor = QColor( (rgba >> 24) & 0xFF, mColor = QColor( (rgba >> 24) & 0xFF,
(rgba >> 16) & 0xFF, (rgba >> 16) & 0xFF,
@@ -58,7 +58,7 @@ ColorNode::ColorNode( bool fieldFlag, uint32_t rgba, const QString& key )
/// Constructor From Color /// Constructor From Color
/// ///
ColorNode::ColorNode( const QColor& color ) ColorNode::ColorNode( const QColor& color )
: mFieldFlag(false), mColor(color), mKey("") : mIsField(false), mColor(color), mKey("")
{ {
} }
@@ -67,7 +67,7 @@ ColorNode::ColorNode( const QColor& color )
/// Constructor From Key /// Constructor From Key
/// ///
ColorNode::ColorNode( const QString& key ) ColorNode::ColorNode( const QString& key )
: mFieldFlag(true), mColor(QColor::fromRgba(0x00000000)), mKey(key) : mIsField(true), mColor(QColor::fromRgba(0x00000000)), mKey(key)
{ {
} }
@@ -77,9 +77,9 @@ ColorNode::ColorNode( const QString& key )
/// ///
bool ColorNode::operator==( const ColorNode& cn ) bool ColorNode::operator==( const ColorNode& cn )
{ {
return ( (mFieldFlag == cn.mFieldFlag) && return ( (mIsField == cn.mIsField) &&
(mColor == cn.mColor) && (mColor == cn.mColor) &&
(mKey == cn.mKey) ); (mKey == cn.mKey) );
} }
@@ -88,34 +88,34 @@ bool ColorNode::operator==( const ColorNode& cn )
/// ///
bool ColorNode::operator!=( const ColorNode& cn ) bool ColorNode::operator!=( const ColorNode& cn )
{ {
return ( (mFieldFlag != cn.mFieldFlag) || return ( (mIsField != cn.mIsField) ||
(mColor != cn.mColor) || (mColor != cn.mColor) ||
(mKey != cn.mKey) ); (mKey != cn.mKey) );
} }
/// ///
/// Field Flag Property Getter /// Field Flag Property Getter
/// ///
bool ColorNode::fieldFlag( void ) const bool ColorNode::isField() const
{ {
return mFieldFlag; return mIsField;
} }
/// ///
/// Field Flag Property Setter /// Field Flag Property Setter
/// ///
void ColorNode::setFieldFlag( bool fieldFlag ) void ColorNode::setField( bool isField )
{ {
mFieldFlag = fieldFlag; mIsField = isField;
} }
/// ///
/// Color Property Getter /// Color Property Getter
/// ///
const QColor& ColorNode::color( void ) const const QColor& ColorNode::color() const
{ {
return mColor; return mColor;
} }
@@ -133,7 +133,7 @@ void ColorNode::setColor( const QColor& color )
/// ///
/// Key Property Getter /// Key Property Getter
/// ///
const QString& ColorNode::key( void ) const const QString& ColorNode::key() const
{ {
return mKey; return mKey;
} }
@@ -148,7 +148,10 @@ void ColorNode::setKey( const QString& key )
} }
uint32_t ColorNode::rgba( void ) const ///
/// Get color encoded as an RGBA 32-bit number
///
uint32_t ColorNode::rgba() const
{ {
uint32_t c = uint32_t c =
mColor.red() << 24 | mColor.red() << 24 |
@@ -159,10 +162,13 @@ uint32_t ColorNode::rgba( void ) const
return c; return c;
} }
///
/// Get color, expand if necessary
///
QColor ColorNode::color( merge::Record* record ) const QColor ColorNode::color( merge::Record* record ) const
{ {
if ( mFieldFlag ) if ( mIsField )
{ {
if ( record == 0 ) if ( record == 0 )
{ {
+11 -12
View File
@@ -1,6 +1,6 @@
/* ColorNode.h /* ColorNode.h
* *
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com> * Copyright (C) 2017 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -23,7 +23,7 @@
#include <QString> #include <QString>
#include <QColor> #include <QColor>
#include <stdint.h> #include <cstdint>
#include "Merge/Record.h" #include "Merge/Record.h"
@@ -39,9 +39,9 @@ struct ColorNode
public: public:
ColorNode(); ColorNode();
ColorNode( bool fieldFlag, const QColor& color, const QString& key ); ColorNode( bool isField, const QColor& color, const QString& key );
ColorNode( bool fieldFlag, uint32_t rgba, const QString& key ); ColorNode( bool isField, uint32_t rgba, const QString& key );
ColorNode( const QColor& color ); ColorNode( const QColor& color );
@@ -64,30 +64,29 @@ public:
// //
// Field Flag Property // Field Flag Property
// //
bool fieldFlag( void ) const; bool isField() const;
void setFieldFlag( bool fieldFlag ); void setField( bool isField );
// //
// Color Property // Color Property
// //
const QColor& color( void ) const; const QColor& color() const;
void setColor( const QColor& color ); void setColor( const QColor& color );
// //
// Key Property // Key Property
// //
const QString& key( void ) const; const QString& key() const;
void setKey( const QString& key ); void setKey( const QString& key );
///////////////////////////////// /////////////////////////////////
// Methods // Misc. Methods
///////////////////////////////// /////////////////////////////////
public: public:
uint32_t rgba( void ) const; uint32_t rgba() const;
QColor color( merge::Record* record ) const; QColor color( merge::Record* record ) const;
@@ -95,7 +94,7 @@ public:
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
bool mFieldFlag; bool mIsField;
QColor mColor; QColor mColor;
QString mKey; QString mKey;
+5 -5
View File
@@ -213,7 +213,7 @@ void ColorPaletteDialog::clearKeys()
void ColorPaletteDialog::onDefaultItemActivated() void ColorPaletteDialog::onDefaultItemActivated()
{ {
mColorNode.setFieldFlag( false ); mColorNode.setField( false );
mColorNode.setColor( mDefaultColor ); mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" ); mColorNode.setKey( "" );
@@ -224,7 +224,7 @@ void ColorPaletteDialog::onDefaultItemActivated()
void ColorPaletteDialog::onPaletteItemActivated( int id ) void ColorPaletteDialog::onPaletteItemActivated( int id )
{ {
mColorNode.setFieldFlag( false ); mColorNode.setField( false );
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) ); mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
mColorNode.setKey( "" ); mColorNode.setKey( "" );
@@ -235,7 +235,7 @@ void ColorPaletteDialog::onPaletteItemActivated( int id )
void ColorPaletteDialog::onHistoryItemActivated( int id ) void ColorPaletteDialog::onHistoryItemActivated( int id )
{ {
mColorNode.setFieldFlag( false ); mColorNode.setField( false );
mColorNode.setColor( mColorHistory->getColors()[id] ); mColorNode.setColor( mColorHistory->getColors()[id] );
mColorNode.setKey( "" ); mColorNode.setKey( "" );
@@ -253,7 +253,7 @@ void ColorPaletteDialog::onCustomColorItemActivated()
{ {
ColorNode newColorNode; ColorNode newColorNode;
newColorNode.setFieldFlag( false ); newColorNode.setField( false );
newColorNode.setColor( dlg.currentColor() ); newColorNode.setColor( dlg.currentColor() );
newColorNode.setKey( "" ); newColorNode.setKey( "" );
@@ -300,7 +300,7 @@ void ColorPaletteDialog::onComboIndexChanged( int index )
{ {
if ( index != 0 ) if ( index != 0 )
{ {
mColorNode.setFieldFlag( true ); mColorNode.setField( true );
mColorNode.setColor( QColor("#eeeeec") ); mColorNode.setColor( QColor("#eeeeec") );
mColorNode.setKey( mKeys[index-1] ); mColorNode.setKey( mKeys[index-1] );
+21 -3
View File
@@ -1,6 +1,6 @@
/* TextNode.cpp /* TextNode.cpp
* *
* Copyright (C) 2013 Jim Evins <evins@snaught.com> * Copyright (C) 2017 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -62,21 +62,39 @@ bool TextNode::operator!=( const TextNode& other )
/// ///
/// isField? Property Getter /// isField? Property Getter
/// ///
bool TextNode::isField( void ) const bool TextNode::isField() const
{ {
return mIsField; return mIsField;
} }
///
/// isField Flag Property Setter
///
void TextNode::setField( bool isField )
{
mIsField = isField;
}
/// ///
/// Data Property Getter /// Data Property Getter
/// ///
const QString& TextNode::data( void ) const const QString& TextNode::data() const
{ {
return mData; return mData;
} }
///
/// Data Property Setter
///
void TextNode::setData( const QString& data )
{
mData = data;
}
/// ///
/// Get text, expand if necessary /// Get text, expand if necessary
/// ///
+6 -4
View File
@@ -1,6 +1,6 @@
/* TextNode.h /* TextNode.h
* *
* Copyright (C) 2013 Jim Evins <evins@snaught.com> * Copyright (C) 2017 Jim Evins <evins@snaught.com>
* *
* This file is part of gLabels-qt. * This file is part of gLabels-qt.
* *
@@ -56,16 +56,18 @@ public:
// //
// is field? Property // is field? Property
// //
bool isField( void ) const; bool isField() const;
void setField( bool isField );
// //
// Data Property // Data Property
// //
const QString& data( void ) const; const QString& data() const;
void setData( const QString& data );
///////////////////////////////// /////////////////////////////////
// Methods // Misc. Methods
///////////////////////////////// /////////////////////////////////
QString text( merge::Record* record ) const; QString text( merge::Record* record ) const;
bool isEmptyField( merge::Record* record ) const; bool isEmptyField( merge::Record* record ) const;
+7 -7
View File
@@ -176,7 +176,7 @@ XmlLabelCreator::createObjectBoxNode( QDomElement &parent, const LabelModelBoxOb
/* line attrs */ /* line attrs */
glabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); glabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() );
if ( object->lineColorNode().fieldFlag() ) if ( object->lineColorNode().isField() )
{ {
glabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); glabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() );
} }
@@ -186,7 +186,7 @@ XmlLabelCreator::createObjectBoxNode( QDomElement &parent, const LabelModelBoxOb
} }
/* fill attrs */ /* fill attrs */
if ( object->fillColorNode().fieldFlag() ) if ( object->fillColorNode().isField() )
{ {
glabels::XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() ); glabels::XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() );
} }
@@ -220,7 +220,7 @@ XmlLabelCreator::createObjectEllipseNode( QDomElement &parent, const LabelModelE
/* line attrs */ /* line attrs */
glabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); glabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() );
if ( object->lineColorNode().fieldFlag() ) if ( object->lineColorNode().isField() )
{ {
glabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); glabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() );
} }
@@ -230,7 +230,7 @@ XmlLabelCreator::createObjectEllipseNode( QDomElement &parent, const LabelModelE
} }
/* fill attrs */ /* fill attrs */
if ( object->fillColorNode().fieldFlag() ) if ( object->fillColorNode().isField() )
{ {
glabels::XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() ); glabels::XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() );
} }
@@ -264,7 +264,7 @@ XmlLabelCreator::createObjectLineNode( QDomElement &parent, const LabelModelLine
/* line attrs */ /* line attrs */
glabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); glabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() );
if ( object->lineColorNode().fieldFlag() ) if ( object->lineColorNode().isField() )
{ {
glabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); glabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() );
} }
@@ -338,7 +338,7 @@ XmlLabelCreator::createObjectTextNode( QDomElement &parent, const LabelModelText
glabels::XmlUtil::setLengthAttr( node, "h", object->h() ); glabels::XmlUtil::setLengthAttr( node, "h", object->h() );
/* color attr */ /* color attr */
if ( object->textColorNode().fieldFlag() ) if ( object->textColorNode().isField() )
{ {
glabels::XmlUtil::setStringAttr( node, "color_field", object->textColorNode().key() ); glabels::XmlUtil::setStringAttr( node, "color_field", object->textColorNode().key() );
} }
@@ -410,7 +410,7 @@ XmlLabelCreator::createShadowAttrs( QDomElement &node, const LabelModelObject* o
glabels::XmlUtil::setLengthAttr( node, "shadow_x", object->shadowX() ); glabels::XmlUtil::setLengthAttr( node, "shadow_x", object->shadowX() );
glabels::XmlUtil::setLengthAttr( node, "shadow_y", object->shadowY() ); glabels::XmlUtil::setLengthAttr( node, "shadow_y", object->shadowY() );
if ( object->fillColorNode().fieldFlag() ) if ( object->fillColorNode().isField() )
{ {
glabels::XmlUtil::setStringAttr( node, "shadow_color_field", object->shadowColorNode().key() ); glabels::XmlUtil::setStringAttr( node, "shadow_color_field", object->shadowColorNode().key() );
} }