Construct objects in XmlLabelParser atomically.

This commit is contained in:
Jim Evins
2017-05-19 21:06:16 -04:00
parent 720c904d2f
commit 438dccd28f
19 changed files with 721 additions and 166 deletions
+39
View File
@@ -79,6 +79,45 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelBarcodeObject::LabelModelBarcodeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const BarcodeStyle& bcStyle,
bool bcTextFlag,
bool bcChecksumFlag,
QString bcData,
const ColorNode& bcColorNode,
const QMatrix& matrix )
: LabelModelObject( x0, y0, w, h, matrix )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mBcStyle = bcStyle;
mBcTextFlag = bcTextFlag;
mBcChecksumFlag = bcChecksumFlag;
mBcData = bcData;
mBcColorNode = bcColorNode;
mEditorBarcode = nullptr;
mEditorDefaultBarcode = nullptr;
update(); // Initialize cached editor layouts
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+13
View File
@@ -44,7 +44,20 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
LabelModelBarcodeObject(); LabelModelBarcodeObject();
LabelModelBarcodeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const BarcodeStyle& bcStyle,
bool bcTextFlag,
bool bcChecksumFlag,
QString bcData,
const ColorNode& bcColorNode,
const QMatrix& matrix = QMatrix() );
LabelModelBarcodeObject( const LabelModelBarcodeObject* object ); LabelModelBarcodeObject( const LabelModelBarcodeObject* object );
~LabelModelBarcodeObject() override; ~LabelModelBarcodeObject() override;
+25
View File
@@ -45,6 +45,31 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelBoxObject::LabelModelBoxObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelShapeObject( x0, y0, w, h,
lineWidth, lineColorNode, fillColorNode,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
// empty
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+16
View File
@@ -40,7 +40,23 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
LabelModelBoxObject(); LabelModelBoxObject();
LabelModelBoxObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelBoxObject( const LabelModelBoxObject* object ); LabelModelBoxObject( const LabelModelBoxObject* object );
~LabelModelBoxObject() override; ~LabelModelBoxObject() override;
+25
View File
@@ -45,6 +45,31 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelEllipseObject::LabelModelEllipseObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelShapeObject( x0, y0, w, h,
lineWidth, lineColorNode, fillColorNode,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
// empty
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+16
View File
@@ -40,7 +40,23 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
LabelModelEllipseObject(); LabelModelEllipseObject();
LabelModelEllipseObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelEllipseObject( const LabelModelEllipseObject* object ); LabelModelEllipseObject( const LabelModelEllipseObject* object );
~LabelModelEllipseObject() override; ~LabelModelEllipseObject() override;
+124
View File
@@ -61,6 +61,130 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelImageObject::LabelModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const TextNode& filenameNode,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelObject( x0, y0, w, h,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mFilenameNode = filenameNode;
mImage = nullptr;
mSvgRenderer = nullptr;
}
///
/// Constructor
///
LabelModelImageObject::LabelModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QString& filename,
const QImage& image,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelObject( x0, y0, w, h,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mImage = new QImage(image);
mFilenameNode = TextNode( false, filename );
mSvgRenderer = nullptr;
}
///
/// Constructor
///
LabelModelImageObject::LabelModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QString& filename,
const QByteArray& svg,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelObject( x0, y0, w, h,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mSvg = svg;
mSvgRenderer = new QSvgRenderer( mSvg );
mFilenameNode = TextNode( false, filename );
mImage = nullptr;
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+40
View File
@@ -42,7 +42,47 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
LabelModelImageObject(); LabelModelImageObject();
LabelModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const TextNode& filenameNode,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QString& filename,
const QImage& image,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelImageObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QString& filename,
const QByteArray& svg,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelImageObject( const LabelModelImageObject* object ); LabelModelImageObject( const LabelModelImageObject* object );
~LabelModelImageObject() override; ~LabelModelImageObject() override;
+35
View File
@@ -51,6 +51,41 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelLineObject::LabelModelLineObject( const Distance& x0,
const Distance& y0,
const Distance& dx,
const Distance& dy,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelObject( x0, y0, dx, dy,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mLineWidth = lineWidth;
mLineColorNode = lineColorNode;
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+15
View File
@@ -40,7 +40,22 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
LabelModelLineObject(); LabelModelLineObject();
LabelModelLineObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelLineObject( const LabelModelLineObject* object ); LabelModelLineObject( const LabelModelLineObject* object );
~LabelModelLineObject() override; ~LabelModelLineObject() override;
+34
View File
@@ -64,6 +64,40 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelObject::LabelModelObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode ) : QObject(nullptr)
{
mId = msNextId++;
mX0 = x0;
mY0 = y0;
mW = w;
mH = h;
mMatrix = matrix;
mShadowState = shadowState;
mShadowX = shadowX;
mShadowY = shadowY;
mShadowColorNode = shadowColorNode;
mShadowOpacity = shadowOpacity;
mSelectedFlag = false;
mOutline = nullptr;
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+13
View File
@@ -57,7 +57,20 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
LabelModelObject(); LabelModelObject();
LabelModelObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelObject( const LabelModelObject* object ); LabelModelObject( const LabelModelObject* object );
public: public:
~LabelModelObject() override; ~LabelModelObject() override;
+37
View File
@@ -49,6 +49,43 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelShapeObject::LabelModelShapeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelObject( x0, y0, w, h,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mLineWidth = lineWidth;
mLineColorNode = lineColorNode;
mFillColorNode = fillColorNode;
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+15
View File
@@ -40,6 +40,21 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
LabelModelShapeObject(); LabelModelShapeObject();
LabelModelShapeObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const Distance& lineWidth,
const ColorNode& lineColorNode,
const ColorNode& fillColorNode,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode );
LabelModelShapeObject( const LabelModelShapeObject* object ); LabelModelShapeObject( const LabelModelShapeObject* object );
public: public:
~LabelModelShapeObject() override; ~LabelModelShapeObject() override;
+51
View File
@@ -71,6 +71,57 @@ namespace glabels
} }
///
/// Constructor
///
LabelModelTextObject::LabelModelTextObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QString& text,
const QString& fontFamily,
double fontSize,
QFont::Weight fontWeight,
bool fontItalicFlag,
bool fontUnderlineFlag,
ColorNode textColorNode,
Qt::Alignment textHAlign,
Qt::Alignment textVAlign,
double textLineSpacing,
const QMatrix& matrix,
bool shadowState,
const Distance& shadowX,
const Distance& shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
: LabelModelObject( x0, y0, w, h,
matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
{
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this );
mHandles << new HandleNorth( this );
mHandles << new HandleNorthEast( this );
mHandles << new HandleEast( this );
mHandles << new HandleSouthEast( this );
mHandles << new HandleSouth( this );
mHandles << new HandleSouthWest( this );
mHandles << new HandleWest( this );
mText = text;
mFontFamily = fontFamily;
mFontSize = fontSize;
mFontWeight = fontWeight;
mFontItalicFlag = fontItalicFlag;
mFontUnderlineFlag = fontUnderlineFlag;
mTextColorNode = textColorNode;
mTextHAlign = textHAlign;
mTextVAlign = textVAlign;
mTextLineSpacing = textLineSpacing;
}
/// ///
/// Copy constructor /// Copy constructor
/// ///
+23
View File
@@ -43,7 +43,30 @@ namespace glabels
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
LabelModelTextObject(); LabelModelTextObject();
LabelModelTextObject( const Distance& x0,
const Distance& y0,
const Distance& w,
const Distance& h,
const QString& text,
const QString& fontFamily,
double fontSize,
QFont::Weight fontWeight,
bool fontItalicFlag,
bool fontUnderlineFlag,
ColorNode textColorNode,
Qt::Alignment textHAlign,
Qt::Alignment textVAlign,
double textLineSpacing,
const QMatrix& matrix = QMatrix(),
bool shadowState = false,
const Distance& shadowX = 0,
const Distance& shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
LabelModelTextObject( const LabelModelTextObject* object ); LabelModelTextObject( const LabelModelTextObject* object );
~LabelModelTextObject() override; ~LabelModelTextObject() override;
+196 -156
View File
@@ -335,202 +335,314 @@ namespace glabels
LabelModelBoxObject* LabelModelBoxObject*
XmlLabelParser::parseObjectBoxNode( const QDomElement &node ) XmlLabelParser::parseObjectBoxNode( const QDomElement &node )
{ {
LabelModelBoxObject* object = new LabelModelBoxObject();
/* position attrs */ /* position attrs */
parsePositionAttrs( node, object ); Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 );
Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 );
/* size attrs */ /* size attrs */
parseSizeAttrs( node, object ); Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
/* line attrs */ /* line attrs */
parseLineAttrs( node, object ); Distance lineWidth = XmlUtil::getLengthAttr( node, "line_width", 1.0 );
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 );
ColorNode lineColorNode( field_flag, color, key );
/* fill attrs */ /* fill attrs */
parseFillAttrs( node, object ); key = XmlUtil::getStringAttr( node, "fill_color_field", "" );
field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "fill_color", 0 );
ColorNode fillColorNode( field_flag, color, key );
/* affine attrs */ /* affine attrs */
parseAffineAttrs( node, object ); double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 1.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 1.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
/* shadow attrs */ /* shadow attrs */
parseShadowAttrs( node, object ); bool shadowState = XmlUtil::getBoolAttr( node, "shadow", false );
Distance shadowX = XmlUtil::getLengthAttr( node, "shadow_x", 0.0 );
Distance shadowY = XmlUtil::getLengthAttr( node, "shadow_y", 0.0 );
double shadowOpacity = XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 );
return object; key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
ColorNode shadowColorNode( field_flag, color, key );
return new LabelModelBoxObject( x0, y0, w, h,
lineWidth, lineColorNode,
fillColorNode,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
LabelModelEllipseObject* LabelModelEllipseObject*
XmlLabelParser::parseObjectEllipseNode( const QDomElement &node ) XmlLabelParser::parseObjectEllipseNode( const QDomElement &node )
{ {
LabelModelEllipseObject* object = new LabelModelEllipseObject();
/* position attrs */ /* position attrs */
parsePositionAttrs( node, object ); Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 );
Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 );
/* size attrs */ /* size attrs */
parseSizeAttrs( node, object ); Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
/* line attrs */ /* line attrs */
parseLineAttrs( node, object ); Distance lineWidth = XmlUtil::getLengthAttr( node, "line_width", 1.0 );
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 );
ColorNode lineColorNode( field_flag, color, key );
/* fill attrs */ /* fill attrs */
parseFillAttrs( node, object ); key = XmlUtil::getStringAttr( node, "fill_color_field", "" );
field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "fill_color", 0 );
ColorNode fillColorNode( field_flag, color, key );
/* affine attrs */ /* affine attrs */
parseAffineAttrs( node, object ); double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 1.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 1.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
/* shadow attrs */ /* shadow attrs */
parseShadowAttrs( node, object ); bool shadowState = XmlUtil::getBoolAttr( node, "shadow", false );
Distance shadowX = XmlUtil::getLengthAttr( node, "shadow_x", 0.0 );
Distance shadowY = XmlUtil::getLengthAttr( node, "shadow_y", 0.0 );
double shadowOpacity = XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 );
return object; key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
ColorNode shadowColorNode( field_flag, color, key );
return new LabelModelEllipseObject( x0, y0, w, h,
lineWidth, lineColorNode,
fillColorNode,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
LabelModelLineObject* LabelModelLineObject*
XmlLabelParser::parseObjectLineNode( const QDomElement &node ) XmlLabelParser::parseObjectLineNode( const QDomElement &node )
{ {
LabelModelLineObject* object = new LabelModelLineObject();
/* position attrs */ /* position attrs */
parsePositionAttrs( node, object ); Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 );
Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 );
/* size attrs of line */ /* size attrs of line */
object->setW( XmlUtil::getLengthAttr( node, "dx", 0 ) ); Distance dx = XmlUtil::getLengthAttr( node, "dx", 0 );
object->setH( XmlUtil::getLengthAttr( node, "dy", 0 ) ); Distance dy = XmlUtil::getLengthAttr( node, "dy", 0 );
/* line attrs */ /* line attrs */
parseLineAttrs( node, object ); Distance lineWidth = XmlUtil::getLengthAttr( node, "line_width", 1.0 );
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 );
ColorNode lineColorNode( field_flag, color, key );
/* affine attrs */ /* affine attrs */
parseAffineAttrs( node, object ); double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 1.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 1.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
/* shadow attrs */ /* shadow attrs */
parseShadowAttrs( node, object ); bool shadowState = XmlUtil::getBoolAttr( node, "shadow", false );
Distance shadowX = XmlUtil::getLengthAttr( node, "shadow_x", 0.0 );
Distance shadowY = XmlUtil::getLengthAttr( node, "shadow_y", 0.0 );
double shadowOpacity = XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 );
return object; key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
ColorNode shadowColorNode( field_flag, color, key );
return new LabelModelLineObject( x0, y0, dx, dy,
lineWidth, lineColorNode,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
LabelModelImageObject* LabelModelImageObject*
XmlLabelParser::parseObjectImageNode( const QDomElement &node, const DataCache& data ) XmlLabelParser::parseObjectImageNode( const QDomElement &node, const DataCache& data )
{ {
LabelModelImageObject* object = new LabelModelImageObject();
/* position attrs */ /* position attrs */
parsePositionAttrs( node, object ); Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 );
Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 );
/* size attrs */ /* size attrs */
parseSizeAttrs( node, object ); Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
/* file attrs */ /* file attrs */
QString key = XmlUtil::getStringAttr( node, "src_field", "" ); QString key = XmlUtil::getStringAttr( node, "src_field", "" );
bool field_flag = !key.isEmpty(); bool field_flag = !key.isEmpty();
QString filename = XmlUtil::getStringAttr( node, "src", "" ); QString filename = XmlUtil::getStringAttr( node, "src", "" );
TextNode filenameNode( field_flag, field_flag ? key : filename );
if ( field_flag ) /* affine attrs */
double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 1.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 1.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
/* shadow attrs */
bool shadowState = XmlUtil::getBoolAttr( node, "shadow", false );
Distance shadowX = XmlUtil::getLengthAttr( node, "shadow_x", 0.0 );
Distance shadowY = XmlUtil::getLengthAttr( node, "shadow_y", 0.0 );
double shadowOpacity = XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 );
key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
ColorNode shadowColorNode( field_flag, color, key );
if ( filenameNode.isField() )
{ {
object->setFilenameNode( TextNode( true, key ) ); return new LabelModelImageObject( x0, y0, w, h,
filenameNode,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
else else
{ {
if ( data.hasImage( filename ) ) if ( data.hasImage( filename ) )
{ {
object->setImage( filename, data.getImage( filename ) ); return new LabelModelImageObject( x0, y0, w, h,
filename, data.getImage( filename ),
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
else if ( data.hasSvg( filename ) ) else if ( data.hasSvg( filename ) )
{ {
object->setSvg( filename, data.getSvg( filename ) ); return new LabelModelImageObject( x0, y0, w, h,
filename, data.getSvg( filename ),
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
else else
{ {
qWarning() << "Embedded file" << filename << "missing. Trying actual file."; qWarning() << "Embedded file" << filename << "missing. Trying actual file.";
object->setFilenameNode( TextNode( false, filename ) ); return new LabelModelImageObject( x0, y0, w, h,
filenameNode,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
} }
/* affine attrs */
parseAffineAttrs( node, object );
/* shadow attrs */
parseShadowAttrs( node, object );
return object;
} }
LabelModelBarcodeObject* LabelModelBarcodeObject*
XmlLabelParser::parseObjectBarcodeNode( const QDomElement &node ) XmlLabelParser::parseObjectBarcodeNode( const QDomElement &node )
{ {
LabelModelBarcodeObject* object = new LabelModelBarcodeObject();
/* position attrs */ /* position attrs */
parsePositionAttrs( node, object ); Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 );
Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 );
/* size attrs */ /* size attrs */
parseSizeAttrs( node, object ); Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
/* barcode attrs */ /* barcode attrs */
BarcodeStyle bcStyle = BarcodeBackends::style( XmlUtil::getStringAttr( node, "backend", "" ), BarcodeStyle bcStyle = BarcodeBackends::style( XmlUtil::getStringAttr( node, "backend", "" ),
XmlUtil::getStringAttr( node, "style", "") ); XmlUtil::getStringAttr( node, "style", "") );
object->setBcStyle( bcStyle ); bool bcTextFlag = XmlUtil::getBoolAttr( node, "text", true );
object->setBcTextFlag( XmlUtil::getBoolAttr( node, "text", true ) ); bool bcChecksumFlag = XmlUtil::getBoolAttr( node, "checksum", true );
object->setBcChecksumFlag( XmlUtil::getBoolAttr( node, "checksum", true ) );
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", 0 );
object->setBcColorNode( ColorNode( field_flag, color, key ) ); ColorNode bcColorNode( field_flag, color, key );
object->setBcData( XmlUtil::getStringAttr( node, "data", "" ) ); QString bcData = XmlUtil::getStringAttr( node, "data", "" );
/* affine attrs */ /* affine attrs */
parseAffineAttrs( node, object ); double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 1.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 1.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
return object; return new LabelModelBarcodeObject( x0, y0, w, h,
bcStyle, bcTextFlag, bcChecksumFlag, bcData, bcColorNode,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ) );
} }
LabelModelTextObject* LabelModelTextObject*
XmlLabelParser::parseObjectTextNode( const QDomElement &node ) XmlLabelParser::parseObjectTextNode( const QDomElement &node )
{ {
LabelModelTextObject* object = new LabelModelTextObject();
/* position attrs */ /* position attrs */
parsePositionAttrs( node, object ); Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 );
Distance y0 = XmlUtil::getLengthAttr( node, "y", 0.0 );
/* size attrs */ /* size attrs */
parseSizeAttrs( node, object ); Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
/* 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", 0 );
ColorNode textColorNode( field_flag, color, key );
object->setTextColorNode( ColorNode( field_flag, color, key ) );
/* font attrs */ /* font attrs */
object->setFontFamily( XmlUtil::getStringAttr( node, "font_family", "Sans" ) ); QString fontFamily = XmlUtil::getStringAttr( node, "font_family", "Sans" );
object->setFontSize( XmlUtil::getDoubleAttr( node, "font_size", 10 ) ); double fontSize = XmlUtil::getDoubleAttr( node, "font_size", 10 );
object->setFontWeight( EnumUtil::stringToWeight( XmlUtil::getStringAttr( node, "font_weight", "normal" ) ) ); QFont::Weight fontWeight = EnumUtil::stringToWeight( XmlUtil::getStringAttr( node, "font_weight", "normal" ) );
object->setFontItalicFlag( XmlUtil::getBoolAttr( node, "font_italic", false ) ); bool fontItalicFlag = XmlUtil::getBoolAttr( node, "font_italic", false );
object->setFontUnderlineFlag( XmlUtil::getBoolAttr( node, "font_underline", false ) ); bool fontUnderlineFlag = XmlUtil::getBoolAttr( node, "font_underline", false );
/* text attrs */ /* text attrs */
object->setTextLineSpacing( XmlUtil::getDoubleAttr( node, "line_spacing", 1 ) ); double textLineSpacing = XmlUtil::getDoubleAttr( node, "line_spacing", 1 );
object->setTextHAlign( EnumUtil::stringToHAlign( XmlUtil::getStringAttr( node, "align", "left" ) ) ); Qt::Alignment textHAlign = EnumUtil::stringToHAlign( XmlUtil::getStringAttr( node, "align", "left" ) );
object->setTextVAlign( EnumUtil::stringToVAlign( XmlUtil::getStringAttr( node, "valign", "top" ) ) ); Qt::Alignment textVAlign = EnumUtil::stringToVAlign( XmlUtil::getStringAttr( node, "valign", "top" ) );
/* affine attrs */ /* affine attrs */
parseAffineAttrs( node, object ); double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 1.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 1.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
/* shadow attrs */ /* shadow attrs */
parseShadowAttrs( node, object ); bool shadowState = XmlUtil::getBoolAttr( node, "shadow", false );
Distance shadowX = XmlUtil::getLengthAttr( node, "shadow_x", 0.0 );
Distance shadowY = XmlUtil::getLengthAttr( node, "shadow_y", 0.0 );
double shadowOpacity = XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 );
key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
field_flag = !key.isEmpty();
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
ColorNode shadowColorNode( field_flag, color, key );
/* deserialize contents. */ /* deserialize contents. */
QTextDocument document; QTextDocument document;
@@ -554,9 +666,14 @@ namespace glabels
qWarning() << "Unexpected" << node.tagName() << "child:" << tagName; qWarning() << "Unexpected" << node.tagName() << "child:" << tagName;
} }
} }
object->setText( document.toPlainText() ); QString text = document.toPlainText();
return object; return new LabelModelTextObject( x0, y0, w, h,
text,
fontFamily, fontSize, fontWeight, fontItalicFlag, fontUnderlineFlag,
textColorNode, textHAlign, textVAlign, textLineSpacing,
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
} }
@@ -574,83 +691,6 @@ namespace glabels
} }
void
XmlLabelParser::parsePositionAttrs( const QDomElement &node, LabelModelObject* object )
{
object->setX0( XmlUtil::getLengthAttr( node, "x", 0.0 ) );
object->setY0( XmlUtil::getLengthAttr( node, "y", 0.0 ) );
}
void
XmlLabelParser::parseSizeAttrs( const QDomElement &node, LabelModelObject* object )
{
object->setW( XmlUtil::getLengthAttr( node, "w", 0 ) );
object->setH( XmlUtil::getLengthAttr( node, "h", 0 ) );
}
void
XmlLabelParser::parseLineAttrs( const QDomElement &node, LabelModelObject* object )
{
object->setLineWidth( XmlUtil::getLengthAttr( node, "line_width", 1.0 ) );
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 );
object->setLineColorNode( ColorNode( field_flag, color, key ) );
}
void
XmlLabelParser::parseFillAttrs( const QDomElement &node, LabelModelObject* object )
{
QString key = XmlUtil::getStringAttr( node, "line_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "fill_color", 0 );
object->setFillColorNode( ColorNode( field_flag, color, key ) );
}
void
XmlLabelParser::parseAffineAttrs( const QDomElement &node, LabelModelObject* object )
{
double a[6];
a[0] = XmlUtil::getDoubleAttr( node, "a0", 1.0 );
a[1] = XmlUtil::getDoubleAttr( node, "a1", 0.0 );
a[2] = XmlUtil::getDoubleAttr( node, "a2", 0.0 );
a[3] = XmlUtil::getDoubleAttr( node, "a3", 1.0 );
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
object->setMatrix( QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ) );
}
void
XmlLabelParser::parseShadowAttrs( const QDomElement &node, LabelModelObject* object )
{
object->setShadow( XmlUtil::getBoolAttr( node, "shadow", false ) );
if ( object->shadow() )
{
object->setShadowX( XmlUtil::getLengthAttr( node, "shadow_x", 0.0 ) );
object->setShadowY( XmlUtil::getLengthAttr( node, "shadow_y", 0.0 ) );
QString key = XmlUtil::getStringAttr( node, "shadow_color_field", "" );
bool field_flag = !key.isEmpty();
uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
object->setShadowColorNode( ColorNode( field_flag, color, key ) );
object->setShadowOpacity( XmlUtil::getDoubleAttr( node, "shadow_opacity", 1.0 ) );
}
}
void void
XmlLabelParser::parseMergeNode( const QDomElement &node, LabelModel* label ) XmlLabelParser::parseMergeNode( const QDomElement &node, LabelModel* label )
{ {
-6
View File
@@ -65,12 +65,6 @@ namespace glabels
static LabelModelTextObject* parseObjectTextNode( const QDomElement &node ); static LabelModelTextObject* parseObjectTextNode( const QDomElement &node );
static QString parsePNode( const QDomElement &node ); static QString parsePNode( const QDomElement &node );
static bool parseRotateAttr( const QDomElement &node ); static bool parseRotateAttr( const QDomElement &node );
static void parsePositionAttrs( const QDomElement &node, LabelModelObject* object );
static void parseSizeAttrs( const QDomElement &node, LabelModelObject* object );
static void parseLineAttrs( const QDomElement &node, LabelModelObject* object );
static void parseFillAttrs( const QDomElement &node, LabelModelObject* object );
static void parseAffineAttrs( const QDomElement &node, LabelModelObject* object );
static void parseShadowAttrs( const QDomElement &node, LabelModelObject* object );
static void parseMergeNode( const QDomElement &node, LabelModel* label ); static void parseMergeNode( const QDomElement &node, LabelModel* label );
static void parseDataNode( const QDomElement &node, DataCache& data ); static void parseDataNode( const QDomElement &node, DataCache& data );
static void parsePixdataNode( const QDomElement &node, DataCache& data ); static void parsePixdataNode( const QDomElement &node, DataCache& data );
+4 -4
View File
@@ -1115,12 +1115,12 @@
<context> <context>
<name>glabels::LabelModelBarcodeObject</name> <name>glabels::LabelModelBarcodeObject</name>
<message> <message>
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="385"/> <location filename="../glabels/LabelModelBarcodeObject.cpp" line="424"/>
<source>No barcode data</source> <source>No barcode data</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="399"/> <location filename="../glabels/LabelModelBarcodeObject.cpp" line="438"/>
<source>Invalid barcode data</source> <source>Invalid barcode data</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@@ -1128,8 +1128,8 @@
<context> <context>
<name>glabels::LabelModelTextObject</name> <name>glabels::LabelModelTextObject</name>
<message> <message>
<location filename="../glabels/LabelModelTextObject.cpp" line="368"/> <location filename="../glabels/LabelModelTextObject.cpp" line="419"/>
<location filename="../glabels/LabelModelTextObject.cpp" line="490"/> <location filename="../glabels/LabelModelTextObject.cpp" line="541"/>
<source>Text</source> <source>Text</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>