Make lockAspectRatio (sizeAspectCheck) per-object (#63)
* Make lockAspectRatio (sizeAspectCheck) per-object * Added unit tests for XmlLabelCreator and XmlLabelParser.
This commit is contained in:
@@ -469,6 +469,10 @@ namespace glabels
|
||||
mResizeObject = handle->owner();
|
||||
mResizeHandle = handle;
|
||||
mResizeHonorAspect = event->modifiers() & Qt::ControlModifier;
|
||||
if ( mResizeObject->lockAspectRatio() )
|
||||
{
|
||||
mResizeHonorAspect = !mResizeHonorAspect;
|
||||
}
|
||||
|
||||
mState = ArrowResize;
|
||||
}
|
||||
|
||||
@@ -188,6 +188,7 @@ namespace glabels
|
||||
|
||||
sizeWSpin->setValue( mObject->w().inUnits(mUnits) );
|
||||
sizeHSpin->setValue( mObject->h().inUnits(mUnits) );
|
||||
sizeAspectCheck->setChecked( mObject->lockAspectRatio() );
|
||||
|
||||
model::Size originalSize = mObject->naturalSize();
|
||||
QString originalSizeString = QString( "%1: %2 x %3 %4" )
|
||||
@@ -655,6 +656,7 @@ namespace glabels
|
||||
|
||||
if ( sizeAspectCheck->isChecked() )
|
||||
{
|
||||
mObject->setLockAspectRatio( true );
|
||||
if ( fabs(spinW - mObject->w()) > fabs(spinH - mObject->h()) )
|
||||
{
|
||||
mObject->setWHonorAspect( spinW );
|
||||
@@ -668,6 +670,7 @@ namespace glabels
|
||||
}
|
||||
else
|
||||
{
|
||||
mObject->setLockAspectRatio( false );
|
||||
mObject->setSize( spinW, spinH );
|
||||
}
|
||||
|
||||
|
||||
+17
-10
@@ -1202,16 +1202,7 @@
|
||||
<property name="spacing">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@@ -2190,6 +2181,22 @@
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>sizeAspectCheck</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>ObjectEditor</receiver>
|
||||
<slot>onRectSizeControlsChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>231</x>
|
||||
<y>289</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>199</x>
|
||||
<y>319</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>onChanged()</slot>
|
||||
|
||||
@@ -89,13 +89,14 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const barcode::Style& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
QString bcData,
|
||||
const ColorNode& bcColorNode,
|
||||
const QMatrix& matrix )
|
||||
: ModelObject( x0, y0, w, h, matrix )
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio, matrix )
|
||||
{
|
||||
mOutline = new Outline( this );
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const barcode::Style& bcStyle,
|
||||
bool bcTextFlag,
|
||||
bool bcChecksumFlag,
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
@@ -63,7 +64,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelShapeObject( x0, y0, w, h,
|
||||
: ModelShapeObject( x0, y0, w, h, lockAspectRatio,
|
||||
lineWidth, lineColorNode, fillColorNode,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
@@ -63,7 +64,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelShapeObject( x0, y0, w, h,
|
||||
: ModelShapeObject( x0, y0, w, h, lockAspectRatio,
|
||||
lineWidth, lineColorNode, fillColorNode,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const TextNode& filenameNode,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
@@ -77,7 +78,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0, y0, w, h,
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
@@ -111,6 +112,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QImage& image,
|
||||
const QMatrix& matrix,
|
||||
@@ -119,7 +121,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0, y0, w, h,
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
@@ -152,6 +154,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QByteArray& svg,
|
||||
const QMatrix& matrix,
|
||||
@@ -160,7 +163,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0, y0, w, h,
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const TextNode& filenameNode,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
@@ -61,6 +62,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QImage& image,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
@@ -74,6 +76,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const QString& filename,
|
||||
const QByteArray& svg,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0, y0, dx, dy,
|
||||
: ModelObject( x0, y0, dx, dy, false /*lockAspectRatio*/,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace glabels
|
||||
mY0 = 0;
|
||||
mW = 0;
|
||||
mH = 0;
|
||||
mLockAspectRatio = false;
|
||||
mMatrix = QMatrix();
|
||||
|
||||
mShadowState = false;
|
||||
@@ -72,6 +73,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const QMatrix& matrix,
|
||||
bool shadowState,
|
||||
const Distance& shadowX,
|
||||
@@ -85,6 +87,7 @@ namespace glabels
|
||||
mY0 = y0;
|
||||
mW = w;
|
||||
mH = h;
|
||||
mLockAspectRatio = lockAspectRatio;
|
||||
mMatrix = matrix;
|
||||
|
||||
mShadowState = shadowState;
|
||||
@@ -112,6 +115,7 @@ namespace glabels
|
||||
mY0 = object->mY0;
|
||||
mW = object->mW;
|
||||
mH = object->mH;
|
||||
mLockAspectRatio = object->mLockAspectRatio;
|
||||
|
||||
mShadowState = object->mShadowState;
|
||||
mShadowX = object->mShadowX;
|
||||
@@ -272,6 +276,28 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Lock Aspect Ratio Property Getter
|
||||
///
|
||||
bool ModelObject::lockAspectRatio() const
|
||||
{
|
||||
return mLockAspectRatio;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Lock Aspect Ratio Property Setter
|
||||
///
|
||||
void ModelObject::setLockAspectRatio( bool value )
|
||||
{
|
||||
if ( mLockAspectRatio != value )
|
||||
{
|
||||
mLockAspectRatio = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Matrix Property Getter
|
||||
///
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio = false,
|
||||
const QMatrix& matrix = QMatrix(),
|
||||
bool shadowState = false,
|
||||
const Distance& shadowX = 0,
|
||||
@@ -136,6 +137,13 @@ namespace glabels
|
||||
void setH( const Distance& value );
|
||||
|
||||
|
||||
//
|
||||
// Lock Aspect Ratio Property
|
||||
//
|
||||
bool lockAspectRatio() const;
|
||||
void setLockAspectRatio( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Transformation Matrix Property
|
||||
//
|
||||
@@ -424,6 +432,7 @@ namespace glabels
|
||||
Distance mY0;
|
||||
Distance mW;
|
||||
Distance mH;
|
||||
bool mLockAspectRatio;
|
||||
|
||||
bool mShadowState;
|
||||
Distance mShadowX;
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
@@ -67,7 +68,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0, y0, w, h,
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const Distance& lineWidth,
|
||||
const ColorNode& lineColorNode,
|
||||
const ColorNode& fillColorNode,
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
@@ -100,7 +101,7 @@ namespace glabels
|
||||
const Distance& shadowY,
|
||||
double shadowOpacity,
|
||||
const ColorNode& shadowColorNode )
|
||||
: ModelObject( x0, y0, w, h,
|
||||
: ModelObject( x0, y0, w, h, lockAspectRatio,
|
||||
matrix,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
|
||||
{
|
||||
|
||||
@@ -50,6 +50,7 @@ namespace glabels
|
||||
const Distance& y0,
|
||||
const Distance& w,
|
||||
const Distance& h,
|
||||
bool lockAspectRatio,
|
||||
const QString& text,
|
||||
const QString& fontFamily,
|
||||
double fontSize,
|
||||
|
||||
+14
-16
@@ -384,6 +384,7 @@ namespace glabels
|
||||
{
|
||||
XmlUtil::setLengthAttr( node, "w", object->w() );
|
||||
XmlUtil::setLengthAttr( node, "h", object->h() );
|
||||
XmlUtil::setBoolAttr( node, "lock_aspect_ratio", object->lockAspectRatio() );
|
||||
}
|
||||
|
||||
|
||||
@@ -433,24 +434,21 @@ namespace glabels
|
||||
void
|
||||
XmlLabelCreator::createShadowAttrs( QDomElement &node, const ModelObject* object )
|
||||
{
|
||||
if ( object->shadow() )
|
||||
XmlUtil::setBoolAttr( node, "shadow", object->shadow() );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "shadow_x", object->shadowX() );
|
||||
XmlUtil::setLengthAttr( node, "shadow_y", object->shadowY() );
|
||||
|
||||
if ( object->fillColorNode().isField() )
|
||||
{
|
||||
XmlUtil::setBoolAttr( node, "shadow", object->shadow() );
|
||||
|
||||
XmlUtil::setLengthAttr( node, "shadow_x", object->shadowX() );
|
||||
XmlUtil::setLengthAttr( node, "shadow_y", object->shadowY() );
|
||||
|
||||
if ( object->fillColorNode().isField() )
|
||||
{
|
||||
XmlUtil::setStringAttr( node, "shadow_color_field", object->shadowColorNode().key() );
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlUtil::setUIntAttr( node, "shadow_color", object->shadowColorNode().rgba() );
|
||||
}
|
||||
|
||||
XmlUtil::setDoubleAttr( node, "shadow_opacity", object->shadowOpacity() );
|
||||
XmlUtil::setStringAttr( node, "shadow_color_field", object->shadowColorNode().key() );
|
||||
}
|
||||
else
|
||||
{
|
||||
XmlUtil::setUIntAttr( node, "shadow_color", object->shadowColorNode().rgba() );
|
||||
}
|
||||
|
||||
XmlUtil::setDoubleAttr( node, "shadow_opacity", object->shadowOpacity() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -354,6 +354,7 @@ namespace glabels
|
||||
/* size attrs */
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
|
||||
bool lockAspectRatio = XmlUtil::getBoolAttr( node, "lock_aspect_ratio", false );
|
||||
|
||||
/* line attrs */
|
||||
Distance lineWidth = XmlUtil::getLengthAttr( node, "line_width", 1.0 );
|
||||
@@ -389,7 +390,7 @@ namespace glabels
|
||||
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
|
||||
ColorNode shadowColorNode( field_flag, color, key );
|
||||
|
||||
return new ModelBoxObject( x0, y0, w, h,
|
||||
return new ModelBoxObject( x0, y0, w, h, lockAspectRatio,
|
||||
lineWidth, lineColorNode,
|
||||
fillColorNode,
|
||||
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
|
||||
@@ -407,6 +408,7 @@ namespace glabels
|
||||
/* size attrs */
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
|
||||
bool lockAspectRatio = XmlUtil::getBoolAttr( node, "lock_aspect_ratio", false );
|
||||
|
||||
/* line attrs */
|
||||
Distance lineWidth = XmlUtil::getLengthAttr( node, "line_width", 1.0 );
|
||||
@@ -442,7 +444,7 @@ namespace glabels
|
||||
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
|
||||
ColorNode shadowColorNode( field_flag, color, key );
|
||||
|
||||
return new ModelEllipseObject( x0, y0, w, h,
|
||||
return new ModelEllipseObject( x0, y0, w, h, lockAspectRatio,
|
||||
lineWidth, lineColorNode,
|
||||
fillColorNode,
|
||||
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
|
||||
@@ -506,6 +508,7 @@ namespace glabels
|
||||
/* size attrs */
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
|
||||
bool lockAspectRatio = XmlUtil::getBoolAttr( node, "lock_aspect_ratio", false );
|
||||
|
||||
/* file attrs */
|
||||
QString key = XmlUtil::getStringAttr( node, "src_field", "" );
|
||||
@@ -535,7 +538,7 @@ namespace glabels
|
||||
|
||||
if ( filenameNode.isField() )
|
||||
{
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
return new ModelImageObject( x0, y0, w, h, lockAspectRatio,
|
||||
filenameNode,
|
||||
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
@@ -544,22 +547,25 @@ namespace glabels
|
||||
{
|
||||
if ( data.hasImage( filename ) )
|
||||
{
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
return new ModelImageObject( x0, y0, w, h, lockAspectRatio,
|
||||
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 ) )
|
||||
{
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
return new ModelImageObject( x0, y0, w, h, lockAspectRatio,
|
||||
filename, data.getSvg( filename ),
|
||||
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Embedded file" << filename << "missing. Trying actual file.";
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
if ( !filename.isEmpty() )
|
||||
{
|
||||
qWarning() << "Embedded file" << filename << "missing. Trying actual file.";
|
||||
}
|
||||
return new ModelImageObject( x0, y0, w, h, lockAspectRatio,
|
||||
filenameNode,
|
||||
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
@@ -578,6 +584,7 @@ namespace glabels
|
||||
/* size attrs */
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
|
||||
bool lockAspectRatio = XmlUtil::getBoolAttr( node, "lock_aspect_ratio", false );
|
||||
|
||||
/* barcode attrs */
|
||||
barcode::Style bcStyle = barcode::Backends::style( XmlUtil::getStringAttr( node, "backend", "" ),
|
||||
@@ -601,7 +608,7 @@ namespace glabels
|
||||
a[4] = XmlUtil::getDoubleAttr( node, "a4", 0.0 );
|
||||
a[5] = XmlUtil::getDoubleAttr( node, "a5", 0.0 );
|
||||
|
||||
return new ModelBarcodeObject( x0, y0, w, h,
|
||||
return new ModelBarcodeObject( x0, y0, w, h, lockAspectRatio,
|
||||
bcStyle, bcTextFlag, bcChecksumFlag, bcData, bcColorNode,
|
||||
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ) );
|
||||
}
|
||||
@@ -617,6 +624,7 @@ namespace glabels
|
||||
/* size attrs */
|
||||
Distance w = XmlUtil::getLengthAttr( node, "w", 0 );
|
||||
Distance h = XmlUtil::getLengthAttr( node, "h", 0 );
|
||||
bool lockAspectRatio = XmlUtil::getBoolAttr( node, "lock_aspect_ratio", false );
|
||||
|
||||
/* color attr */
|
||||
QString key = XmlUtil::getStringAttr( node, "color_field", "" );
|
||||
@@ -682,7 +690,7 @@ namespace glabels
|
||||
}
|
||||
QString text = document.toPlainText();
|
||||
|
||||
return new ModelTextObject( x0, y0, w, h,
|
||||
return new ModelTextObject( x0, y0, w, h, lockAspectRatio,
|
||||
text,
|
||||
fontFamily, fontSize, fontWeight, fontItalicFlag, fontUnderlineFlag,
|
||||
textColorNode, textHAlign, textVAlign, textWrapMode, textLineSpacing,
|
||||
|
||||
@@ -229,7 +229,7 @@ namespace glabels
|
||||
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
|
||||
const ColorNode shadowColorNode( field_flag, color, key );
|
||||
|
||||
return new ModelBoxObject( x0, y0, w, h,
|
||||
return new ModelBoxObject( x0, y0, w, h, false /*lockAspectRatio*/,
|
||||
lineWidth, lineColorNode,
|
||||
fillColorNode,
|
||||
affineTransformation,
|
||||
@@ -276,7 +276,7 @@ namespace glabels
|
||||
color = XmlUtil::getUIntAttr( node, "shadow_color", 0 );
|
||||
const ColorNode shadowColorNode( field_flag, color, key );
|
||||
|
||||
return new ModelEllipseObject( x0, y0, w, h,
|
||||
return new ModelEllipseObject( x0, y0, w, h, false /*lockAspectRatio*/,
|
||||
lineWidth, lineColorNode,
|
||||
fillColorNode,
|
||||
affineTransformation,
|
||||
@@ -357,27 +357,27 @@ namespace glabels
|
||||
|
||||
if ( filenameNode.isField() )
|
||||
{
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
return new ModelImageObject( x0, y0, w, h, false /*lockAspectRatio*/,
|
||||
filenameNode,
|
||||
affineTransformation,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
}
|
||||
if ( data.hasImage( filename ) )
|
||||
{
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
return new ModelImageObject( x0, y0, w, h, false /*lockAspectRatio*/,
|
||||
filename, data.getImage( filename ),
|
||||
affineTransformation,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
}
|
||||
if ( data.hasSvg( filename ) )
|
||||
{
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
return new ModelImageObject( x0, y0, w, h, false /*lockAspectRatio*/,
|
||||
filename, data.getSvg( filename ),
|
||||
affineTransformation,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
}
|
||||
qWarning() << "Embedded file" << filename << "missing. Trying actual file.";
|
||||
return new ModelImageObject( x0, y0, w, h,
|
||||
return new ModelImageObject( x0, y0, w, h, false /*lockAspectRatio*/,
|
||||
filenameNode,
|
||||
affineTransformation,
|
||||
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
|
||||
@@ -419,7 +419,7 @@ namespace glabels
|
||||
/* affine attrs */
|
||||
const auto affineTransformation = parseAffineTransformation(node);
|
||||
|
||||
return new ModelBarcodeObject( x0, y0, w, h,
|
||||
return new ModelBarcodeObject( x0, y0, w, h, false /*lockAspectRatio*/,
|
||||
bcStyle, bcTextFlag, bcChecksumFlag, bcData, bcColorNode,
|
||||
affineTransformation );
|
||||
}
|
||||
@@ -554,7 +554,7 @@ namespace glabels
|
||||
}
|
||||
const QString text = document.toPlainText();
|
||||
|
||||
auto textNode = new ModelTextObject( x0, y0, w, h, text,
|
||||
auto textNode = new ModelTextObject( x0, y0, w, h, false /*lockAspectRatio*/, text,
|
||||
fontFamily, fontSize, fontWeight, fontItalicFlag, false,
|
||||
textColorNode, textHAlign, textVAlign, textWrapMode, textLineSpacing,
|
||||
textAutoShrink,
|
||||
|
||||
@@ -16,4 +16,12 @@ if (Qt5Test_FOUND)
|
||||
target_link_libraries (TestXmlUtil Model Qt5::Test)
|
||||
add_test (NAME XmlUtil COMMAND TestXmlUtil)
|
||||
|
||||
#=======================================
|
||||
# Test XmlLabelCreator/Parser classes
|
||||
#=======================================
|
||||
qt5_wrap_cpp (TestXmlLabel_moc_sources TestXmlLabel.h)
|
||||
add_executable (TestXmlLabel TestXmlLabel.cpp ${TestXmlLabel_moc_sources})
|
||||
target_link_libraries (TestXmlLabel Model Qt5::Test)
|
||||
add_test (NAME XmlLabel COMMAND TestXmlLabel)
|
||||
|
||||
endif (Qt5Test_FOUND)
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/* TestXmlLabel.cpp
|
||||
*
|
||||
* Copyright (C) 2018 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TestXmlLabel.h"
|
||||
|
||||
#include "model/XmlLabelCreator.h"
|
||||
#include "model/XmlLabelParser.h"
|
||||
|
||||
#include "barcode/Backends.h"
|
||||
#include "model/ColorNode.h"
|
||||
#include "model/Size.h"
|
||||
|
||||
#include "model/ModelBarcodeObject.h"
|
||||
#include "model/ModelBoxObject.h"
|
||||
#include "model/ModelEllipseObject.h"
|
||||
#include "model/ModelLineObject.h"
|
||||
#include "model/ModelImageObject.h"
|
||||
#include "model/ModelTextObject.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
QTEST_MAIN(TestXmlLabel)
|
||||
|
||||
|
||||
void TestXmlLabel::initTestCase()
|
||||
{
|
||||
using namespace glabels::barcode;
|
||||
Backends::init();
|
||||
}
|
||||
|
||||
|
||||
void TestXmlLabel::serializeDeserialize()
|
||||
{
|
||||
using namespace glabels::model;
|
||||
using namespace glabels::barcode;
|
||||
|
||||
//
|
||||
// Empty object list
|
||||
//
|
||||
QList<ModelObject*> objects, outObjects;
|
||||
QByteArray buffer, outBuffer;
|
||||
|
||||
QCOMPARE( objects.count(), 0 );
|
||||
XmlLabelCreator::serializeObjects( objects, buffer );
|
||||
outObjects = XmlLabelParser::deserializeObjects( buffer );
|
||||
QCOMPARE( objects.count(), outObjects.count() );
|
||||
QCOMPARE( objects, outObjects );
|
||||
XmlLabelCreator::serializeObjects( outObjects, outBuffer );
|
||||
QCOMPARE( buffer, outBuffer );
|
||||
|
||||
//
|
||||
// All objects list
|
||||
//
|
||||
bool lock = true, noLock = false, shadow = true, noShadow = false;
|
||||
ColorNode black( Qt::black ), white( Qt::white ), red( Qt::red ), green( Qt::green ), blue( Qt::blue );
|
||||
QMatrix tMatrix( 1, 0, 0, 1, 50.0, 50.0 ), sMatrix( 0.5, 0, 0, 1.0, 0, 0 );
|
||||
QImage png( QFINDTESTDATA( "../../../glabels/images/glabels-logo.png" ) );
|
||||
QByteArray svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"16\" height=\"16\" ><path d=\"M 3,4 l 5.5,11 -4,-2 v 5 h -3 v -5 l -4,2 Z\" /></svg>";
|
||||
Style bcStyle = Backends::defaultStyle();
|
||||
|
||||
objects << new ModelBoxObject( 0, 1, 10, 20, lock, 2, red, green, tMatrix, shadow, 1, 2, 0.7, black );
|
||||
objects << new ModelEllipseObject( 1, 2, 30, 40, noLock, 3, black, white, sMatrix, shadow, 2, 3, 0.8, blue );
|
||||
objects << new ModelImageObject( 2, 3, 50, 50, lock, TextNode( false, "" ), tMatrix, noShadow, 3, 4, 0.9, white );
|
||||
objects << new ModelImageObject( 3, 4, 60, 70, noLock, "image2.png", png, sMatrix, shadow, 6, 4, 0.9, black );
|
||||
objects << new ModelImageObject( 4, 5, 70, 80, lock, "image3.svg", svg );
|
||||
objects << new ModelImageObject( 5, 6, 80, 90, noLock, TextNode( true, "${key}" ), tMatrix, shadow );
|
||||
objects << new ModelImageObject( 6, 7, 90, 100, lock, TextNode( false, "image5.jpg" ) ); // Gives warning that embedded file missing
|
||||
objects << new ModelLineObject( 7, 8, 100, 110, 4, green, sMatrix, shadow, 5, 5, 0.5, red );
|
||||
objects << new ModelTextObject( 8, 9, 110, 120, lock, "text", "Serif", 12, QFont::Bold, true, true, red,
|
||||
Qt::AlignHCenter, Qt::AlignBottom, QTextOption::NoWrap, 1.3, false, sMatrix, shadow, 5, 5, 0.5, red );
|
||||
objects << new ModelBarcodeObject( 9, 10, 50, 50, noLock, bcStyle, true, true, QString("1234"), black, tMatrix );
|
||||
QCOMPARE( objects.count(), 10 );
|
||||
|
||||
buffer.clear();
|
||||
XmlLabelCreator::serializeObjects( objects, buffer );
|
||||
outObjects = XmlLabelParser::deserializeObjects( buffer );
|
||||
QCOMPARE( objects.count(), outObjects.count() );
|
||||
|
||||
for ( int i = 0; i < objects.count(); i++ )
|
||||
{
|
||||
qDebug() << "object" << i;
|
||||
QVERIFY( objects.at(i)->id() != outObjects.at(i)->id() ); // Ids are generated and unique
|
||||
QCOMPARE( objects.at(i)->x0(), outObjects.at(i)->x0() );
|
||||
QCOMPARE( objects.at(i)->x0().pt(), (double)i );
|
||||
QCOMPARE( objects.at(i)->y0(), outObjects.at(i)->y0() );
|
||||
QCOMPARE( objects.at(i)->y0().pt(), (double)(i + 1) );
|
||||
QCOMPARE( objects.at(i)->w().pt(), outObjects.at(i)->w().pt() ); // Use `pt()` so invoke `qFuzzyCompare(double, double)` otherwise get rounding difference for Barcode
|
||||
QCOMPARE( objects.at(i)->h().pt(), outObjects.at(i)->h().pt() ); // Fuzzy
|
||||
QCOMPARE( objects.at(i)->lockAspectRatio(), outObjects.at(i)->lockAspectRatio() );
|
||||
QCOMPARE( objects.at(i)->lockAspectRatio(), (bool)((i + 1) % 2) );
|
||||
QCOMPARE( objects.at(i)->matrix(), outObjects.at(i)->matrix() );
|
||||
QCOMPARE( objects.at(i)->shadow(), outObjects.at(i)->shadow() );
|
||||
QCOMPARE( objects.at(i)->shadowX(), outObjects.at(i)->shadowX() );
|
||||
QCOMPARE( objects.at(i)->shadowY(), outObjects.at(i)->shadowY() );
|
||||
QCOMPARE( objects.at(i)->shadowOpacity(), outObjects.at(i)->shadowOpacity() );
|
||||
QVERIFY( objects.at(i)->shadowColorNode() == outObjects.at(i)->shadowColorNode() );
|
||||
QCOMPARE( objects.at(i)->naturalSize().w().pt(), outObjects.at(i)->naturalSize().w().pt() ); // Fuzzy
|
||||
QCOMPARE( objects.at(i)->naturalSize().h().pt(), outObjects.at(i)->naturalSize().h().pt() ); // Fuzzy
|
||||
|
||||
QCOMPARE( objects.at(i)->text(), outObjects.at(i)->text() );
|
||||
QCOMPARE( objects.at(i)->fontFamily(), outObjects.at(i)->fontFamily() );
|
||||
QCOMPARE( objects.at(i)->fontSize(), outObjects.at(i)->fontSize() );
|
||||
QCOMPARE( objects.at(i)->fontWeight(), outObjects.at(i)->fontWeight() );
|
||||
QCOMPARE( objects.at(i)->fontItalicFlag(), outObjects.at(i)->fontItalicFlag() );
|
||||
QCOMPARE( objects.at(i)->fontUnderlineFlag(), outObjects.at(i)->fontUnderlineFlag() );
|
||||
QVERIFY( objects.at(i)->textColorNode() == outObjects.at(i)->textColorNode() );
|
||||
QCOMPARE( objects.at(i)->textHAlign(), outObjects.at(i)->textHAlign() );
|
||||
QCOMPARE( objects.at(i)->textVAlign(), outObjects.at(i)->textVAlign() );
|
||||
QCOMPARE( objects.at(i)->textWrapMode(), outObjects.at(i)->textWrapMode() );
|
||||
QCOMPARE( objects.at(i)->textLineSpacing(), outObjects.at(i)->textLineSpacing() );
|
||||
QCOMPARE( objects.at(i)->textAutoShrink(), outObjects.at(i)->textAutoShrink() );
|
||||
|
||||
QVERIFY( objects.at(i)->filenameNode() == outObjects.at(i)->filenameNode() );
|
||||
if ( objects.at(i)->image() )
|
||||
{
|
||||
QCOMPARE( *(objects.at(i)->image()), *(outObjects.at(i)->image()) );
|
||||
}
|
||||
else
|
||||
{
|
||||
QCOMPARE( objects.at(i)->image(), outObjects.at(i)->image() );
|
||||
}
|
||||
QCOMPARE( objects.at(i)->svg(), outObjects.at(i)->svg() );
|
||||
|
||||
QCOMPARE( objects.at(i)->lineWidth(), outObjects.at(i)->lineWidth() );
|
||||
QVERIFY( objects.at(i)->lineColorNode() == outObjects.at(i)->lineColorNode() );
|
||||
QVERIFY( objects.at(i)->fillColorNode() == outObjects.at(i)->fillColorNode() );
|
||||
|
||||
QCOMPARE( objects.at(i)->bcData(), outObjects.at(i)->bcData() );
|
||||
QCOMPARE( objects.at(i)->bcTextFlag(), outObjects.at(i)->bcTextFlag() );
|
||||
QCOMPARE( objects.at(i)->bcChecksumFlag(), outObjects.at(i)->bcChecksumFlag() );
|
||||
QVERIFY( objects.at(i)->bcColorNode() == outObjects.at(i)->bcColorNode() );
|
||||
QVERIFY( !( objects.at(i)->bcStyle() != outObjects.at(i)->bcStyle() ) ); // Only != operator
|
||||
QCOMPARE( objects.at(i)->bcFormatDigits(), outObjects.at(i)->bcFormatDigits() );
|
||||
|
||||
QCOMPARE( objects.at(i)->canText(), outObjects.at(i)->canText() );
|
||||
QCOMPARE( objects.at(i)->canFill(), outObjects.at(i)->canFill() );
|
||||
QCOMPARE( objects.at(i)->canLineColor(), outObjects.at(i)->canLineColor() );
|
||||
QCOMPARE( objects.at(i)->canLineWidth(), outObjects.at(i)->canLineWidth() );
|
||||
}
|
||||
|
||||
outBuffer.clear();
|
||||
XmlLabelCreator::serializeObjects( outObjects, outBuffer );
|
||||
QCOMPARE( buffer, outBuffer );
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/* TestXmlLabel.h
|
||||
*
|
||||
* Copyright (C) 2018 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
|
||||
class TestXmlLabel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void serializeDeserialize();
|
||||
};
|
||||
|
||||
|
||||
@@ -323,8 +323,9 @@
|
||||
>
|
||||
|
||||
<!ENTITY % size_attrs
|
||||
"w %LENGTH_TYPE; #REQUIRED
|
||||
h %LENGTH_TYPE; #REQUIRED"
|
||||
"w %LENGTH_TYPE; #REQUIRED
|
||||
h %LENGTH_TYPE; #REQUIRED
|
||||
lock_aspect_ratio %BOOLEAN_TYPE; #IMPLIED"
|
||||
>
|
||||
|
||||
<!ENTITY % line_attrs
|
||||
|
||||
Reference in New Issue
Block a user