UserVariables branch merge

This commit is contained in:
gitlost
2019-08-21 03:37:56 +01:00
92 changed files with 3624 additions and 1283 deletions
+3
View File
@@ -56,6 +56,8 @@ set (Model_sources
Template.cpp
TextNode.cpp
Units.cpp
Variable.cpp
Variables.cpp
Vendor.cpp
XmlCategoryParser.cpp
XmlLabelCreator.cpp
@@ -80,6 +82,7 @@ set (Model_qobject_headers
ModelTextObject.h
PageRenderer.h
Settings.h
Variables.h
)
qt5_wrap_cpp (Model_moc_sources ${Model_qobject_headers})
+21 -19
View File
@@ -175,30 +175,32 @@ namespace glabels
///
/// Get color, expand if necessary
///
QColor ColorNode::color( merge::Record* record ) const
QColor ColorNode::color( const merge::Record* record,
const Variables* variables ) const
{
if ( mIsField )
QColor value = QColor( 192, 192, 192, 128 );
bool haveRecordField = mIsField && record &&
record->contains(mKey) &&
!record->value(mKey).isEmpty();
bool haveVariable = mIsField && variables &&
variables->contains(mKey) &&
!(*variables)[mKey].value().isEmpty();
if ( haveRecordField )
{
if ( record == nullptr )
{
return mColor;
}
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
View File
@@ -22,6 +22,7 @@
#define model_ColorNode_h
#include "Variables.h"
#include "merge/Record.h"
#include <QString>
@@ -95,7 +96,8 @@ namespace glabels
/////////////////////////////////
public:
uint32_t rgba() const;
QColor color( merge::Record* record ) const;
QColor color( const merge::Record* record,
const Variables* variables ) const;
/////////////////////////////////
+64 -7
View File
@@ -57,13 +57,17 @@ namespace glabels
Model::Model()
: mUntitledInstance(0), mModified(true), mRotate(false)
{
mVariables = new Variables();
mMerge = new merge::None();
connect( mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) );
}
Model::Model( merge::Merge* merge )
Model::Model( merge::Merge* merge, Variables* variables )
: mUntitledInstance(0), mModified(true), mRotate(false)
{
mVariables = variables; // Shared
mMerge = merge; // Shared
}
@@ -73,7 +77,8 @@ namespace glabels
///
Model::~Model()
{
// Final instance of mMerge to be deleted by Model owner
qDeleteAll( mObjectList );
// Final instance of mMerge and mVariables to be deleted by Model owner
}
@@ -82,7 +87,7 @@ namespace glabels
///
Model* Model::save() const
{
auto* savedModel = new Model( mMerge ); // mMerge shared between models
auto* savedModel = new Model( mMerge, mVariables ); // mMerge and mVariables shared between models
if ( mFileName.isEmpty() && mUntitledInstance == 0 )
{
@@ -283,6 +288,38 @@ namespace glabels
}
///
/// Get directory as a QDir.
///
QDir Model::dir() const
{
if ( mFileName.isEmpty() )
{
return QDir::current();
}
else
{
return QFileInfo( mFileName ).absoluteDir();
}
}
///
/// Get directory as a path.
///
QString Model::dirPath() const
{
if ( mFileName.isEmpty() )
{
return QDir::currentPath();
}
else
{
return QFileInfo( mFileName ).absolutePath();
}
}
///
/// Get short name.
///
@@ -309,6 +346,15 @@ namespace glabels
}
///
/// Get variables object
///
Variables* Model::variables() const
{
return mVariables;
}
///
/// Get merge object
///
@@ -458,6 +504,17 @@ namespace glabels
}
///
/// Variables Changed Slot
///
void Model::onVariablesChanged()
{
setModified();
emit changed();
emit variablesChanged();
}
///
/// Merge Source Changed Slot
///
@@ -1366,7 +1423,7 @@ namespace glabels
QClipboard *clipboard = QApplication::clipboard();
QByteArray buffer;
XmlLabelCreator::serializeObjects( getSelection(), buffer );
XmlLabelCreator::serializeObjects( getSelection(), this, buffer );
auto *mimeData = new QMimeData;
mimeData->setData( MIME_TYPE, buffer );
@@ -1422,7 +1479,7 @@ namespace glabels
{
// Native objects
QByteArray buffer = mimeData->data( MIME_TYPE );
QList <ModelObject*> objects = XmlLabelParser::deserializeObjects( buffer );
QList <ModelObject*> objects = XmlLabelParser::deserializeObjects( buffer, this );
unselectAll();
foreach ( ModelObject* object, objects )
@@ -1459,11 +1516,11 @@ namespace glabels
///
/// Draw label objects
///
void Model::draw( QPainter* painter, bool inEditor, merge::Record* record ) const
void Model::draw( QPainter* painter, bool inEditor, merge::Record* record, Variables* variables ) const
{
foreach ( ModelObject* object, mObjectList )
{
object->draw( painter, inEditor, record );
object->draw( painter, inEditor, record, variables );
}
}
+14 -2
View File
@@ -24,10 +24,12 @@
#include "Settings.h"
#include "Template.h"
#include "Variables.h"
#include "merge/Merge.h"
#include "merge/Record.h"
#include <QDir>
#include <QList>
#include <QObject>
#include <QPainter>
@@ -57,7 +59,7 @@ namespace glabels
/////////////////////////////////
public:
Model();
Model( merge::Merge* merge );
Model( merge::Merge* merge, Variables* variables );
~Model();
@@ -77,6 +79,7 @@ namespace glabels
void sizeChanged();
void selectionChanged();
void modifiedChanged();
void variablesChanged();
void mergeChanged();
void mergeSourceChanged();
void mergeSelectionChanged();
@@ -90,6 +93,8 @@ namespace glabels
void setModified();
void clearModified();
QDir dir() const;
QString dirPath() const;
QString shortName();
const QString& fileName() const;
void setFileName( const QString &fileName );
@@ -108,6 +113,8 @@ namespace glabels
const QList<ModelObject*>& objectList() const;
Variables* variables() const;
merge::Merge* merge() const;
void setMerge( merge::Merge* merge );
@@ -205,7 +212,10 @@ namespace glabels
// Drawing operations
/////////////////////////////////
public:
void draw( QPainter* painter, bool inEditor = true, merge::Record* record = nullptr ) const;
void draw( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const;
/////////////////////////////////
@@ -214,6 +224,7 @@ namespace glabels
private slots:
void onObjectChanged();
void onObjectMoved();
void onVariablesChanged();
void onMergeSourceChanged();
void onMergeSelectionChanged();
@@ -230,6 +241,7 @@ namespace glabels
QList<ModelObject*> mObjectList;
Variables* mVariables;
merge::Merge* mMerge;
};
+9 -6
View File
@@ -312,7 +312,8 @@ namespace glabels
///
void ModelBarcodeObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record ) const
merge::Record* record,
Variables* variables ) const
{
// Barcodes don't support shadows.
}
@@ -323,9 +324,10 @@ namespace glabels
///
void ModelBarcodeObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record ) const
merge::Record* record,
Variables* variables ) const
{
QColor bcColor = mBcColorNode.color( record );
QColor bcColor = mBcColorNode.color( record, variables );
if ( inEditor )
{
@@ -333,7 +335,7 @@ namespace glabels
}
else
{
drawBc( painter, bcColor, record );
drawBc( painter, bcColor, record, variables );
}
}
@@ -451,7 +453,8 @@ namespace glabels
void
ModelBarcodeObject::drawBc( QPainter* painter,
const QColor& color,
merge::Record* record ) const
merge::Record* record,
Variables* variables ) const
{
painter->setPen( QPen( color ) );
@@ -459,7 +462,7 @@ namespace glabels
bc->setChecksum(mBcChecksumFlag);
bc->setShowText(mBcTextFlag);
bc->build( mBcData.expand( record ).toStdString(), mW.pt(), mH.pt() );
bc->build( mBcData.expand( record, variables ).toStdString(), mW.pt(), mH.pt() );
glbarcode::QtRenderer renderer(painter);
bc->render( renderer );
+16 -3
View File
@@ -127,8 +127,16 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -140,7 +148,12 @@ namespace glabels
void update();
void drawBcInEditor( QPainter* painter, const QColor& color ) const;
void drawBc( QPainter* painter, const QColor& color, merge::Record* record ) const;
void drawBc( QPainter* painter,
const QColor& color,
merge::Record* record,
Variables* variables ) const;
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
+13 -7
View File
@@ -104,11 +104,14 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelBoxObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelBoxObject::drawShadow( QPainter* painter,
bool inEditor,
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 );
@@ -149,10 +152,13 @@ namespace glabels
///
/// Draw object itself
///
void ModelBoxObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelBoxObject::drawObject( QPainter* painter,
bool inEditor,
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 );
+10 -2
View File
@@ -73,8 +73,16 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
QPainterPath hoverPath( double scale ) const override;
};
+13 -7
View File
@@ -104,11 +104,14 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelEllipseObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelEllipseObject::drawShadow( QPainter* painter,
bool inEditor,
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 );
@@ -149,10 +152,13 @@ namespace glabels
///
/// Draw object itself
///
void ModelEllipseObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelEllipseObject::drawObject( QPainter* painter,
bool inEditor,
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 );
+10 -2
View File
@@ -73,8 +73,16 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
QPainterPath hoverPath( double scale ) const override;
};
+109 -8
View File
@@ -20,9 +20,11 @@
#include "ModelImageObject.h"
#include "Model.h"
#include "Size.h"
#include <QBrush>
#include <QDir>
#include <QFileInfo>
#include <QImage>
#include <QPen>
@@ -40,6 +42,17 @@ namespace glabels
QImage* ModelImageObject::smDefaultImage = nullptr;
//
// Private
//
namespace
{
const QColor fillColor = QColor( 224, 224, 224, 255 );
const QColor labelColor = QColor( 102, 102, 102, 255 );
const Distance pad = Distance::pt(2);
}
///
/// Constructor
///
@@ -398,28 +411,51 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelImageObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelImageObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
{
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) )
{
QImage* shadowImage = createShadowImage( shadowColor );
QImage* shadowImage = createShadowImage( *mImage, shadowColor );
painter->drawImage( destRect, *shadowImage );
delete shadowImage;
}
else if ( mImage || inEditor )
{
painter->setBrush( shadowColor );
painter->setPen( QPen( Qt::NoPen ) );
painter->drawRect( destRect );
}
else
{
if ( mImage || inEditor )
// Look for image file relative to project file 1st then CWD 2nd
auto* model = dynamic_cast<Model*>( parent() );
QDir::setSearchPaths( "images", {model->dirPath(), QDir::currentPath()} );
QString filename = QString("images:") + mFilenameNode.text( record, variables );
auto* image = new QImage( filename );
if ( !image->isNull() && image->hasAlphaChannel() && (image->depth() == 32) )
{
QImage* shadowImage = createShadowImage( *image, shadowColor );
painter->drawImage( destRect, *shadowImage );
delete shadowImage;
}
else if ( !image->isNull() )
{
painter->setBrush( shadowColor );
painter->setPen( QPen( Qt::NoPen ) );
painter->drawRect( destRect );
}
delete image;
}
}
@@ -427,16 +463,70 @@ namespace glabels
///
/// Draw object itself
///
void ModelImageObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelImageObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
if ( inEditor && (mFilenameNode.isField() || (!mImage && !mSvgRenderer) ) )
{
//
// Render default place holder image
//
painter->save();
painter->setRenderHint( QPainter::SmoothPixmapTransform, false );
painter->drawImage( destRect, *smDefaultImage );
painter->restore();
//
// Print label on top of place holder image, if we have room
//
if ( (mW > 6*pad) && (mH > 4*pad) )
{
QString labelText = tr("No image");
if ( mFilenameNode.isField() )
{
labelText = QString( "${%1}" ).arg( mFilenameNode.data() );
}
// Determine font size for labelText
QFont font( "Sans" );
font.setPointSizeF( 6 );
QFontMetricsF fm( font );
QRectF textRect = fm.boundingRect( labelText );
double wPts = (mW - 2*pad).pt();
double hPts = (mH - 2*pad).pt();
if ( (wPts < textRect.width()) || (hPts < textRect.height()) )
{
double scaleX = wPts / textRect.width();
double scaleY = hPts / textRect.height();
font.setPointSizeF( 6 * std::min( scaleX, scaleY ) );
}
// Render hole for text (font size may have changed above)
fm = QFontMetricsF( font );
textRect = fm.boundingRect( labelText );
QRectF holeRect( (mW.pt() - textRect.width())/2 - pad.pt(),
(mH.pt() - textRect.height())/2 - pad.pt(),
textRect.width() + 2*pad.pt(),
textRect.height() + 2*pad.pt() );
painter->setPen( Qt::NoPen );
painter->setBrush( QBrush( fillColor ) );
painter->drawRect( holeRect );
// Render text
painter->setFont( font );
painter->setPen( QPen( labelColor ) );
painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ),
Qt::AlignCenter,
labelText );
}
}
else if ( mImage )
{
@@ -448,7 +538,17 @@ namespace glabels
}
else if ( mFilenameNode.isField() )
{
// TODO
// Look for image file relative to project file 1st then CWD 2nd
auto* model = dynamic_cast<Model*>( parent() );
QDir::setSearchPaths( "images", {model->dirPath(), QDir::currentPath()} );
QString filename = QString("images:") + mFilenameNode.text( record, variables );
auto* image = new QImage( filename );
if ( !image->isNull() )
{
painter->drawImage( destRect, *image );
}
delete image;
}
}
@@ -547,14 +647,15 @@ namespace glabels
///
/// Create shadow image
///
QImage* ModelImageObject::createShadowImage( const QColor& color ) const
QImage* ModelImageObject::createShadowImage( const QImage& image,
const QColor& color ) const
{
int r = color.red();
int g = color.green();
int b = color.blue();
int a = color.alpha();
auto* shadow = new QImage( *mImage );
auto* shadow = new QImage( image );
for ( int iy = 0; iy < shadow->height(); iy++ )
{
auto* scanLine = (QRgb*)shadow->scanLine( iy );
+13 -3
View File
@@ -135,8 +135,16 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -144,7 +152,9 @@ namespace glabels
// Private
///////////////////////////////////////////////////////////////
void loadImage();
QImage* createShadowImage( const QColor& color ) const;
QImage* createShadowImage( const QImage& image,
const QColor& color ) const;
///////////////////////////////////////////////////////////////
+11 -5
View File
@@ -186,10 +186,13 @@ namespace glabels
///
/// Draw shadow of object
///
void ModelLineObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelLineObject::drawShadow( QPainter* painter,
bool inEditor,
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 );
@@ -204,9 +207,12 @@ namespace glabels
///
/// Draw object itself
///
void ModelLineObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelLineObject::drawObject( QPainter* painter,
bool inEditor,
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() );
+10 -2
View File
@@ -97,8 +97,16 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
QPainterPath hoverPath( double scale ) const override;
+6 -3
View File
@@ -1226,7 +1226,10 @@ namespace glabels
///
/// Draw object + shadow
///
void ModelObject::draw( QPainter* painter, bool inEditor, merge::Record* record ) const
void ModelObject::draw( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const
{
painter->save();
painter->translate( mX0.pt(), mY0.pt() );
@@ -1236,12 +1239,12 @@ namespace glabels
painter->save();
painter->translate( mShadowX.pt(), mShadowY.pt() );
painter->setMatrix( mMatrix, true );
drawShadow( painter, inEditor, record );
drawShadow( painter, inEditor, record, variables );
painter->restore();
}
painter->setMatrix( mMatrix, true );
drawObject( painter, inEditor, record );
drawObject( painter, inEditor, record, variables );
painter->restore();
}
+16 -3
View File
@@ -27,6 +27,7 @@
#include "Handles.h"
#include "Outline.h"
#include "TextNode.h"
#include "Variables.h"
#include "barcode/Style.h"
#include "merge/Record.h"
@@ -411,12 +412,24 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
public:
void draw( QPainter* painter, bool inEditor, merge::Record* record ) const;
void draw( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const;
void drawSelectionHighlight( QPainter* painter, double scale ) const;
protected:
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const = 0;
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const = 0;
virtual void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const = 0;
virtual void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const = 0;
virtual QPainterPath hoverPath( double scale ) const = 0;
virtual void sizeUpdated();
+15 -12
View File
@@ -519,13 +519,14 @@ namespace glabels
///
void ModelTextObject::drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record ) const
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 )
@@ -534,7 +535,7 @@ namespace glabels
}
else
{
drawText( painter, shadowColor, record );
drawText( painter, shadowColor, record, variables );
}
}
}
@@ -545,9 +546,10 @@ namespace glabels
///
void ModelTextObject::drawObject( QPainter* painter,
bool inEditor,
merge::Record* record ) const
merge::Record* record,
Variables* variables ) const
{
QColor textColor = mTextColorNode.color( record );
QColor textColor = mTextColorNode.color( record, variables );
if ( inEditor )
{
@@ -555,7 +557,7 @@ namespace glabels
}
else
{
drawText( painter, textColor, record );
drawText( painter, textColor, record, variables );
}
}
@@ -697,7 +699,8 @@ namespace glabels
void
ModelTextObject::drawText( QPainter* painter,
const QColor& color,
merge::Record* record ) const
merge::Record* record,
Variables* variables ) const
{
painter->save();
@@ -705,7 +708,7 @@ namespace glabels
QFont font;
font.setFamily( mFontFamily );
font.setPointSizeF( mTextAutoShrink ? autoShrinkFontSize( record ) : mFontSize );
font.setPointSizeF( mTextAutoShrink ? autoShrinkFontSize( record, variables ) : mFontSize );
font.setWeight( mFontWeight );
font.setItalic( mFontItalicFlag );
font.setUnderline( mFontUnderlineFlag );
@@ -717,7 +720,7 @@ namespace glabels
QFontMetricsF fontMetrics( font );
double dy = fontMetrics.lineSpacing() * mTextLineSpacing;
QTextDocument document( mText.expand( record ) );
QTextDocument document( mText.expand( record, variables ) );
QList<QTextLayout*> layouts;
@@ -791,7 +794,7 @@ namespace glabels
/// Determine auto shrink font size
///
double
ModelTextObject::autoShrinkFontSize( merge::Record* record ) const
ModelTextObject::autoShrinkFontSize( merge::Record* record, Variables* variables ) const
{
QFont font;
font.setFamily( mFontFamily );
@@ -803,7 +806,7 @@ namespace glabels
textOption.setAlignment( mTextHAlign );
textOption.setWrapMode( mTextWrapMode );
QTextDocument document( mText.expand( record ) );
QTextDocument document( mText.expand( record, variables ) );
double candidateSize = mFontSize;
while ( candidateSize > 1.0 )
+21 -6
View File
@@ -186,8 +186,16 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override;
void drawShadow( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
void drawObject( QPainter* painter,
bool inEditor,
merge::Record* record,
Variables* variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -197,10 +205,17 @@ namespace glabels
private:
void sizeUpdated() override;
void update();
void drawTextInEditor( QPainter* painter, const QColor& color ) const;
void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const;
QString expandText( QString text, merge::Record* record ) const;
double autoShrinkFontSize( merge::Record* record ) const;
void drawTextInEditor( QPainter* painter,
const QColor& color ) const;
void drawText( QPainter* painter,
const QColor& color,
merge::Record* record,
Variables* variables ) const;
double autoShrinkFontSize( merge::Record* record,
Variables* variables ) const;
///////////////////////////////////////////////////////////////
+84 -57
View File
@@ -47,7 +47,7 @@ namespace glabels
PageRenderer::PageRenderer( const Model* model )
: mModel(nullptr), mMerge(nullptr), mNCopies(0), mStartLabel(0), mLastLabel(0),
: mModel(nullptr), mMerge(nullptr), mVariables(nullptr), mNCopies(0), mStartLabel(0), mLastLabel(0),
mPrintOutlines(false), mPrintCropMarks(false), mPrintReverse(false),
mIPage(0), mIsMerge(false), mNPages(0), mNLabelsPerPage(0)
{
@@ -65,6 +65,7 @@ namespace glabels
connect( mModel, SIGNAL(changed()), this, SLOT(onModelChanged()) );
onModelChanged();
mVariables = mModel->variables();
}
@@ -246,83 +247,107 @@ namespace glabels
void PageRenderer::printSimplePage( QPainter* painter, int iPage ) const
{
int iStart = 0;
int iEnd = mNLabelsPerPage;
if ( iPage == 0 )
{
iStart = mStartLabel;
}
if ( (mLastLabel / mNLabelsPerPage) == iPage )
{
iEnd = mLastLabel % mNLabelsPerPage;
}
printCropMarks( painter );
for ( int i = iStart; i < iEnd; i++ )
int iCopy = 0;
int iLabel = mStartLabel;
int iCurrentPage = 0;
mVariables->resetVariables();
while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) )
{
painter->save();
if ( iCurrentPage == iPage )
{
int i = iLabel % mNLabelsPerPage;
painter->save();
painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() );
painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() );
painter->save();
painter->save();
clipLabel( painter );
printLabel( painter, nullptr );
clipLabel( painter );
printLabel( painter, nullptr, mVariables );
painter->restore(); // From before clip
painter->restore(); // From before clip
printOutline( painter );
printOutline( painter );
painter->restore(); // From before translation
painter->restore(); // From before translation
}
iCopy++;
iLabel++;
iCurrentPage = iLabel / mNLabelsPerPage;
mVariables->incrementVariablesOnItem();
mVariables->incrementVariablesOnCopy();
if ( (iLabel % mNLabelsPerPage) == 0 /* starting a new page */ )
{
mVariables->incrementVariablesOnPage();
}
}
}
void PageRenderer::printMergePage( QPainter* painter, int iPage ) const
{
int iRecord = 0;
int iStart = 0;
int iEnd = mNLabelsPerPage;
if ( iPage == 0 )
{
iStart = mStartLabel;
}
if ( (mLastLabel / mNLabelsPerPage) == iPage )
{
iEnd = mLastLabel % mNLabelsPerPage;
}
const QList<merge::Record*> records = mMerge->selectedRecords();
if ( records.size() )
{
iRecord = (iPage*mNLabelsPerPage + iStart - mStartLabel) % records.size();
}
printCropMarks( painter );
for ( int i = iStart; i < iEnd; i++ )
int iCopy = 0;
int iLabel = mStartLabel;
int iCurrentPage = 0;
const QList<merge::Record*> records = mMerge->selectedRecords();
int iRecord = 0;
int nRecords = records.size();
if ( nRecords == 0 )
{
painter->save();
painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() );
return;
}
painter->save();
mVariables->resetVariables();
clipLabel( painter );
printLabel( painter, records[iRecord] );
while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) )
{
if ( iCurrentPage == iPage )
{
int i = iLabel % mNLabelsPerPage;
painter->save();
painter->restore(); // From before clip
printOutline( painter );
painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() );
painter->restore(); // From before translation
painter->save();
iRecord = (iRecord + 1) % records.size();
clipLabel( painter );
printLabel( painter, records[iRecord], mVariables );
painter->restore(); // From before clip
printOutline( painter );
painter->restore(); // From before translation
}
iRecord = (iRecord + 1) % nRecords;
if ( iRecord == 0 )
{
iCopy++;
}
iLabel++;
iCurrentPage = iLabel / mNLabelsPerPage;
mVariables->incrementVariablesOnItem();
if ( iRecord == 0 )
{
mVariables->incrementVariablesOnCopy();
}
if ( (iLabel % mNLabelsPerPage) == 0 /* starting a new page */ )
{
mVariables->incrementVariablesOnPage();
}
}
}
@@ -408,7 +433,9 @@ namespace glabels
}
void PageRenderer::printLabel( QPainter* painter, merge::Record* record ) const
void PageRenderer::printLabel( QPainter* painter,
merge::Record* record,
Variables* variables ) const
{
painter->save();
@@ -424,7 +451,7 @@ namespace glabels
painter->scale( -1, 1 );
}
mModel->draw( painter, false, record );
mModel->draw( painter, false, record, variables );
painter->restore();
}
+3 -1
View File
@@ -23,6 +23,7 @@
#include "Point.h"
#include "Variables.h"
#include "merge/Merge.h"
#include "merge/Record.h"
@@ -100,7 +101,7 @@ namespace glabels
void printCropMarks( QPainter* painter ) const;
void printOutline( QPainter* painter ) const;
void clipLabel( QPainter* painter ) const;
void printLabel( QPainter* painter, merge::Record* record ) const;
void printLabel( QPainter* painter, merge::Record* record, Variables* variables ) const;
/////////////////////////////////
@@ -109,6 +110,7 @@ namespace glabels
private:
const Model* mModel;
const merge::Merge* mMerge;
Variables* mVariables;
int mNCopies;
int mStartLabel;
+2 -2
View File
@@ -66,7 +66,7 @@ namespace glabels
///
/// Expand all place holders
///
QString RawText::expand( merge::Record* record ) const
QString RawText::expand( merge::Record* record, Variables* variables ) const
{
QString text;
@@ -74,7 +74,7 @@ namespace glabels
{
if ( token.isField )
{
text += token.field.evaluate( record );
text += token.field.evaluate( record, variables );
}
else
{
+1 -1
View File
@@ -52,7 +52,7 @@ namespace glabels
/////////////////////////////////
QString toString() const;
std::string toStdString() const;
QString expand( merge::Record* record ) const;
QString expand( merge::Record* record, Variables* variables ) const;
bool hasPlaceHolders() const;
bool isEmpty() const;
+15 -3
View File
@@ -42,21 +42,33 @@ namespace glabels
}
QString SubstitutionField::evaluate( const merge::Record* record ) const
QString SubstitutionField::evaluate( const merge::Record* record,
const Variables* variables ) const
{
QString value = mDefaultValue;
if ( record && record->contains(mFieldName) && !record->value(mFieldName).isEmpty() )
bool haveRecordField = record &&
record->contains(mFieldName) &&
!record->value(mFieldName).isEmpty();
bool haveVariable = variables &&
variables->contains(mFieldName) &&
!(*variables)[mFieldName].value().isEmpty();
if ( haveRecordField )
{
value = record->value(mFieldName);
}
else if ( haveVariable )
{
value = (*variables)[mFieldName].value();
}
if ( !mFormatType.isNull() )
{
value = formatValue( value );
}
if ( record && record->contains(mFieldName) && !record->value(mFieldName).isEmpty() && mNewLine )
if ( mNewLine && (haveRecordField || haveVariable) )
{
value = "\n" + value;
}
+2 -1
View File
@@ -21,6 +21,7 @@
#ifndef model_SubstitutionField_h
#define model_SubstitutionField_h
#include "Variables.h"
#include "merge/Record.h"
@@ -39,7 +40,7 @@ namespace glabels
SubstitutionField();
SubstitutionField( const QString& string );
QString evaluate( const merge::Record* record ) const;
QString evaluate( const merge::Record* record, const Variables* variables ) const;
QString fieldName() const;
QString defaultValue() const;
+21 -35
View File
@@ -105,48 +105,34 @@ namespace glabels
///
/// Get text, expand if necessary
///
QString TextNode::text( merge::Record* record ) const
QString TextNode::text( const merge::Record* record,
const Variables* variables ) const
{
if ( mIsField )
QString value("");
bool haveRecordField = mIsField && record &&
record->contains(mData) &&
!record->value(mData).isEmpty();
bool haveVariable = mIsField && variables &&
variables->contains(mData) &&
!(*variables)[mData].value().isEmpty();
if ( haveRecordField )
{
if ( !record )
{
return QString("${%1}").arg( mData );
}
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
View File
@@ -22,6 +22,7 @@
#define model_TextNode_h
#include "Variables.h"
#include "merge/Record.h"
#include <QString>
@@ -76,8 +77,8 @@ namespace glabels
/////////////////////////////////
// Misc. Methods
/////////////////////////////////
QString text( merge::Record* record ) const;
bool isEmptyField( merge::Record* record ) const;
QString text( const merge::Record* record,
const Variables* variables ) const;
/////////////////////////////////
+306
View File
@@ -0,0 +1,306 @@
/* Variable.cpp
*
* Copyright (C) 2013-2016 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 "Variable.h"
namespace glabels
{
namespace model
{
Variable::Variable( Variable::Type type,
const QString& name,
const QString& initialValue,
Variable::Increment increment,
const QString& stepSize )
: mType(type),
mName(name),
mInitialValue(initialValue),
mIncrement(increment),
mStepSize(stepSize)
{
// empty
}
Variable::Type Variable::type() const
{
return mType;
}
QString Variable::name() const
{
return mName;
}
QString Variable::initialValue() const
{
return mInitialValue;
}
Variable::Increment Variable::increment() const
{
return mIncrement;
}
QString Variable::stepSize() const
{
return mStepSize;
}
void Variable::resetValue()
{
switch (mType)
{
case Type::STRING:
// do nothing
break;
case Type::INTEGER:
mIntegerValue = mInitialValue.toLongLong();
mIntegerStep = mStepSize.toLongLong();
break;
case Type::FLOATING_POINT:
mFloatingPointValue = mInitialValue.toDouble();
mFloatingPointStep = mStepSize.toDouble();
break;
case Type::COLOR:
// do nothing
break;
}
}
void Variable::incrementValueOnItem()
{
if ( mIncrement == Increment::PER_ITEM )
{
switch (mType)
{
case Type::STRING:
// do nothing
break;
case Type::INTEGER:
mIntegerValue += mIntegerStep;
break;
case Type::FLOATING_POINT:
mFloatingPointValue += mFloatingPointStep;
break;
case Type::COLOR:
// do nothing
break;
}
}
}
void Variable::incrementValueOnCopy()
{
if ( mIncrement == Increment::PER_COPY )
{
switch (mType)
{
case Type::STRING:
// do nothing
break;
case Type::INTEGER:
mIntegerValue += mIntegerStep;
break;
case Type::FLOATING_POINT:
mFloatingPointValue += mFloatingPointStep;
break;
case Type::COLOR:
// do nothing
break;
}
}
}
void Variable::incrementValueOnPage()
{
if ( mIncrement == Increment::PER_PAGE )
{
switch (mType)
{
case Type::STRING:
// do nothing
break;
case Type::INTEGER:
mIntegerValue += mIntegerStep;
break;
case Type::FLOATING_POINT:
mFloatingPointValue += mFloatingPointStep;
break;
case Type::COLOR:
// do nothing
break;
}
}
}
QString Variable::value() const
{
switch (mType)
{
case Type::STRING:
return mInitialValue;
case Type::INTEGER:
return QString::number( mIntegerValue );
case Type::FLOATING_POINT:
return QString::number( mFloatingPointValue, 'g', 15 );
case Type::COLOR:
return mInitialValue;
default:
return mInitialValue;
}
}
QString Variable::typeToI18nString( Type type )
{
switch (type)
{
case Type::STRING:
return tr("String");
case Type::INTEGER:
return tr("Integer");
case Type::FLOATING_POINT:
return tr("Floating Point");
case Type::COLOR:
return tr("Color");
default:
return tr("String");
}
}
QString Variable::typeToIdString( Type type )
{
switch (type)
{
case Type::STRING:
return "string";
case Type::INTEGER:
return "integer";
case Type::FLOATING_POINT:
return "float";
case Type::COLOR:
return "color";
default:
return "string";
}
}
Variable::Type Variable::idStringToType( const QString& id )
{
if ( id == "string" )
{
return Type::STRING;
}
else if ( id == "integer" )
{
return Type::INTEGER;
}
else if ( id == "float" )
{
return Type::FLOATING_POINT;
}
if ( id == "color" )
{
return Type::COLOR;
}
else
{
return Type::STRING; // Default
}
}
QString Variable::incrementToI18nString( Increment increment )
{
switch (increment)
{
case Increment::NEVER:
return tr("Never");
case Increment::PER_ITEM:
return tr("Per item");
case Increment::PER_COPY:
return tr("Per copy");
case Increment::PER_PAGE:
return tr("Per page");
default:
return tr("Never");
}
}
QString Variable::incrementToIdString( Increment increment )
{
switch (increment)
{
case Increment::NEVER:
return "never";
case Increment::PER_ITEM:
return "per_item";
case Increment::PER_COPY:
return "per_copy";
case Increment::PER_PAGE:
return "per_page";
default:
return "never";
}
}
Variable::Increment Variable::idStringToIncrement( const QString& id )
{
if ( id == "never" )
{
return Increment::NEVER;
}
else if ( id == "per_item" )
{
return Increment::PER_ITEM;
}
else if ( id == "per_copy" )
{
return Increment::PER_COPY;
}
else if ( id == "per_page" )
{
return Increment::PER_PAGE;
}
else
{
return Increment::NEVER; // Default
}
}
}
}
+107
View File
@@ -0,0 +1,107 @@
/* Variable.h
*
* Copyright (C) 2019 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/>.
*/
#ifndef model_Variable_h
#define model_Variable_h
#include <QCoreApplication>
#include <QString>
namespace glabels
{
namespace model
{
class Variable
{
Q_DECLARE_TR_FUNCTIONS(Variable)
public:
enum class Type
{
STRING,
INTEGER,
FLOATING_POINT,
COLOR
};
enum class Increment
{
NEVER,
PER_ITEM,
PER_COPY,
PER_PAGE
};
public:
Variable() = default;
Variable( Type type,
const QString& name,
const QString& initialValue,
Increment increment = Increment::NEVER,
const QString& stepSize = "0" );
virtual ~Variable() = default;
Type type() const;
QString name() const;
QString initialValue() const;
Increment increment() const;
QString stepSize() const;
void resetValue();
void incrementValueOnItem();
void incrementValueOnCopy();
void incrementValueOnPage();
QString value() const;
static QString typeToI18nString( Type type );
static QString typeToIdString( Type type );
static Type idStringToType( const QString& string );
static QString incrementToI18nString( Increment increment );
static QString incrementToIdString( Increment increment );
static Increment idStringToIncrement( const QString& string );
private:
Type mType;
QString mName;
QString mInitialValue;
Increment mIncrement;
QString mStepSize;
long long mIntegerValue;
long long mIntegerStep;
double mFloatingPointValue;
double mFloatingPointStep;
};
}
}
#endif // model_Variable_h
+138
View File
@@ -0,0 +1,138 @@
/* Variables.cpp
*
* Copyright (C) 2013-2016 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 "Variables.h"
#include <QtDebug>
namespace glabels
{
namespace model
{
///
/// Copy constructor
///
Variables::Variables( const Variables* variables )
: QMap<QString,Variable>(*variables)
{
}
///
/// Clone
///
Variables* Variables::clone() const
{
return new Variables( this );
}
///
/// Do we have variable?
///
bool Variables::hasVariable( const QString& name ) const
{
return contains(name);
}
///
/// Add variable ( will replace if name is the same )
///
void Variables::addVariable( const Variable& variable )
{
insert( variable.name(), variable );
emit changed();
}
///
/// Delete variable
///
void Variables::deleteVariable( const QString& name )
{
remove( name );
emit changed();
}
///
/// Replace variable
///
void Variables::replaceVariable( const QString& origName, const Variable& variable )
{
remove( origName );
insert( variable.name(), variable );
emit changed();
}
///
/// Reset variables to their initial values
///
void Variables::resetVariables()
{
for ( auto& v : *this )
{
v.resetValue();
}
}
///
/// Increment variables on item
///
void Variables::incrementVariablesOnItem()
{
for ( auto& v : *this )
{
v.incrementValueOnItem();
}
}
///
/// Increment variables on copy
///
void Variables::incrementVariablesOnCopy()
{
for ( auto& v : *this )
{
v.incrementValueOnCopy();
}
}
///
/// Increment variables on page
///
void Variables::incrementVariablesOnPage()
{
for ( auto& v : *this )
{
v.incrementValueOnPage();
}
}
} // namespace model
} // namespace glabels
+90
View File
@@ -0,0 +1,90 @@
/* Variables.h
*
* Copyright (C) 2013-2016 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/>.
*/
#ifndef model_Variables_h
#define model_Variables_h
#include "Variable.h"
#include <QMap>
#include <QObject>
#include <QString>
namespace glabels
{
namespace model
{
///
/// Variables Collection
///
class Variables : public QObject, public QMap<QString,Variable>
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
Variables() = default;
Variables( const Variables* variables );
/////////////////////////////////
// Object duplication
/////////////////////////////////
Variables* clone() const;
/////////////////////////////////
// Methods
/////////////////////////////////
bool hasVariable( const QString& name ) const;
void addVariable( const Variable& variable );
void deleteVariable( const QString& name );
void replaceVariable( const QString& name, const Variable& variable );
void resetVariables();
void incrementVariablesOnItem();
void incrementVariablesOnCopy();
void incrementVariablesOnPage();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void changed();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
};
}
}
#endif // model_Variables_h
+107 -28
View File
@@ -29,9 +29,11 @@
#include "ModelImageObject.h"
#include "ModelTextObject.h"
#include "DataCache.h"
#include "Variables.h"
#include "XmlTemplateCreator.h"
#include "XmlUtil.h"
#include "merge/Factory.h"
#include "merge/None.h"
#include <QByteArray>
@@ -48,38 +50,41 @@ namespace glabels
{
void
XmlLabelCreator::writeFile( const Model* label, const QString& fileName )
XmlLabelCreator::writeFile( Model* model, const QString& fileName )
{
QDomDocument doc;
createDoc( doc, label );
QByteArray buffer = doc.toByteArray( 2 );
QFile file( fileName );
if ( !file.open( QFile::WriteOnly | QFile::Text) )
{
qWarning() << "Error: Cannot write file " << fileName
<< ": " << file.errorString();
return;
}
model->setFileName( fileName );
model->clearModified();
QDomDocument doc;
createDoc( doc, model );
QByteArray buffer = doc.toByteArray( 2 );
file.write( buffer.data(), buffer.size() );
}
void
XmlLabelCreator::writeBuffer( const Model* label, QByteArray& buffer )
XmlLabelCreator::writeBuffer( const Model* model, QByteArray& buffer )
{
QDomDocument doc;
createDoc( doc, label );
createDoc( doc, model );
buffer = doc.toByteArray( 2 );
}
void
XmlLabelCreator::serializeObjects( const QList<ModelObject*>& objects,
QByteArray& buffer )
const Model* model,
QByteArray& buffer )
{
QDomDocument doc;
@@ -90,15 +95,15 @@ namespace glabels
doc.appendChild( root );
XmlUtil::setStringAttr( root, "version", "4.0" );
createDataNode( root, objects );
createObjectsNode( root, objects, false );
createDataNode( root, model, objects );
createObjectsNode( root, model, objects, false );
buffer = doc.toByteArray( 2 );
}
void
XmlLabelCreator::createDoc( QDomDocument& doc, const Model* label )
XmlLabelCreator::createDoc( QDomDocument& doc, const Model* model )
{
QDomNode xmlNode( doc.createProcessingInstruction( "xml", "version=\"1.0\"" ) );
doc.appendChild( xmlNode );
@@ -107,21 +112,29 @@ namespace glabels
doc.appendChild( root );
XmlUtil::setStringAttr( root, "version", "4.0" );
XmlTemplateCreator().createTemplateNode( root, label->tmplate() );
XmlTemplateCreator().createTemplateNode( root, model->tmplate() );
createObjectsNode( root, label->objectList(), label->rotate() );
createObjectsNode( root, model, model->objectList(), model->rotate() );
if ( label->merge() && !dynamic_cast<merge::None*>(label->merge()) )
if ( model->merge() && !dynamic_cast<merge::None*>(model->merge()) )
{
createMergeNode( root, label );
createMergeNode( root, model );
}
createDataNode( root, label->objectList() );
if ( model->variables()->size() != 0 )
{
createVariablesNode( root, model );
}
createDataNode( root, model, model->objectList() );
}
void
XmlLabelCreator::createObjectsNode( QDomElement &parent, const QList<ModelObject*>& objects, bool rotate )
XmlLabelCreator::createObjectsNode( QDomElement& parent,
const Model* model,
const QList<ModelObject*>& objects,
bool rotate )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Objects" );
@@ -146,7 +159,7 @@ namespace glabels
}
else if ( auto* imageObject = dynamic_cast<ModelImageObject*>(object) )
{
createObjectImageNode( node, imageObject );
createObjectImageNode( node, model, imageObject );
}
else if ( auto* barcodeObject = dynamic_cast<ModelBarcodeObject*>(object) )
{
@@ -244,7 +257,9 @@ namespace glabels
void
XmlLabelCreator::createObjectImageNode( QDomElement &parent, const ModelImageObject* object )
XmlLabelCreator::createObjectImageNode( QDomElement& parent,
const Model* model,
const ModelImageObject* object )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Object-image" );
@@ -263,7 +278,8 @@ namespace glabels
}
else
{
XmlUtil::setStringAttr( node, "src", object->filenameNode().data() );
QString fn = model->dir().relativeFilePath( object->filenameNode().data() );
XmlUtil::setStringAttr( node, "src", fn );
}
/* affine attrs */
@@ -453,19 +469,80 @@ namespace glabels
void
XmlLabelCreator::createMergeNode( QDomElement &parent, const Model* label )
XmlLabelCreator::createMergeNode( QDomElement &parent, const Model* model )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Merge" );
parent.appendChild( node );
XmlUtil::setStringAttr( node, "type", label->merge()->id() );
XmlUtil::setStringAttr( node, "src", label->merge()->source() );
QString id = model->merge()->id();
QString src = model->merge()->source();
XmlUtil::setStringAttr( node, "type", id );
switch ( merge::Factory::idToType( id ) )
{
case merge::Factory::NONE:
case merge::Factory::FIXED:
break;
case merge::Factory::FILE:
{
QString fn = model->dir().relativeFilePath( src );
XmlUtil::setStringAttr( node, "src", fn );
}
break;
default:
qWarning() << "XmlLabelCreator::createMergeNode(): Should not be reached!";
break;
}
}
void
XmlLabelCreator::createDataNode( QDomElement &parent, const QList<ModelObject*>& objects )
XmlLabelCreator::createVariablesNode( QDomElement &parent, const Model* model )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Variables" );
parent.appendChild( node );
for ( const auto& v : *model->variables() )
{
createVariableNode( node, v );
}
}
void
XmlLabelCreator::createVariableNode( QDomElement &parent, const Variable& v )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Variable" );
parent.appendChild( node );
XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) );
XmlUtil::setStringAttr( node, "name", v.name() );
XmlUtil::setStringAttr( node, "initialValue", v.initialValue() );
if ( (v.type() == Variable::Type::INTEGER) ||
(v.type() == Variable::Type::FLOATING_POINT) )
{
XmlUtil::setStringAttr( node, "increment",
Variable::incrementToIdString( v.increment() ) );
if ( v.increment() != Variable::Increment::NEVER )
{
XmlUtil::setStringAttr( node, "stepSize", v.stepSize() );
}
}
}
void
XmlLabelCreator::createDataNode( QDomElement& parent,
const Model* model,
const QList<ModelObject*>& objects )
{
QDomDocument doc = parent.ownerDocument();
QDomElement node = doc.createElement( "Data" );
@@ -475,12 +552,14 @@ namespace glabels
foreach ( QString name, data.imageNames() )
{
createPngFileNode( node, name, data.getImage( name ) );
QString fn = model->dir().relativeFilePath( name );
createPngFileNode( node, fn, data.getImage( name ) );
}
foreach ( QString name, data.svgNames() )
{
createSvgFileNode( node, name, data.getSvg( name ) );
QString fn = model->dir().relativeFilePath( name );
createSvgFileNode( node, fn, data.getSvg( name ) );
}
}
+80 -23
View File
@@ -40,6 +40,7 @@ namespace glabels
class ModelImageObject;
class ModelBarcodeObject;
class ModelTextObject;
class Variable;
///
@@ -50,31 +51,87 @@ namespace glabels
Q_OBJECT
public:
static void writeFile( const Model* label, const QString& fileName );
static void writeBuffer( const Model* label, QByteArray& buffer );
static void serializeObjects( const QList<ModelObject*>& objects, QByteArray& buffer );
static void writeFile( Model* model,
const QString& fileName );
static void writeBuffer( const Model* model,
QByteArray& buffer );
static void serializeObjects( const QList<ModelObject*>& objects,
const Model* model,
QByteArray& buffer );
private:
static void createDoc( QDomDocument& doc, const Model* label );
static void createRootNode( const Model* label );
static void createObjectsNode( QDomElement &parent, const QList<ModelObject*>& objects, bool rotate );
static void createObjectBoxNode( QDomElement &parent, const ModelBoxObject* object );
static void createObjectEllipseNode( QDomElement &parent, const ModelEllipseObject* object );
static void createObjectLineNode( QDomElement &parent, const ModelLineObject* object );
static void createObjectImageNode( QDomElement &parent, const ModelImageObject* object );
static void createObjectBarcodeNode( QDomElement &parent, const ModelBarcodeObject* object );
static void createObjectTextNode( QDomElement &parent, const ModelTextObject* object );
static void createPNode( QDomElement &parent, const QString& blockText );
static void createPositionAttrs( QDomElement &node, const ModelObject* object );
static void createSizeAttrs( QDomElement &node, const ModelObject* object );
static void createLineAttrs( QDomElement &node, const ModelObject* object );
static void createFillAttrs( QDomElement &node, const ModelObject* object );
static void createAffineAttrs( QDomElement &node, const ModelObject* object );
static void createShadowAttrs( QDomElement &node, const ModelObject* object );
static void createMergeNode( QDomElement &parent, const Model* label );
static void createDataNode( QDomElement &parent, const QList<ModelObject*>& objects );
static void createPngFileNode( QDomElement &parent, const QString& name, const QImage& image );
static void createSvgFileNode( QDomElement &parent, const QString& name, const QByteArray& svg );
static void createDoc( QDomDocument& doc,
const Model* model );
static void createRootNode( const Model* model );
static void createObjectsNode( QDomElement& parent,
const Model* model,
const QList<ModelObject*>& objects,
bool rotate );
static void createObjectBoxNode( QDomElement& parent,
const ModelBoxObject* object );
static void createObjectEllipseNode( QDomElement& parent,
const ModelEllipseObject* object );
static void createObjectLineNode( QDomElement& parent,
const ModelLineObject* object );
static void createObjectImageNode( QDomElement& parent,
const Model* model,
const ModelImageObject* object );
static void createObjectBarcodeNode( QDomElement& parent,
const ModelBarcodeObject* object );
static void createObjectTextNode( QDomElement& parent,
const ModelTextObject* object );
static void createPNode( QDomElement& parent,
const QString& blockText );
static void createPositionAttrs( QDomElement& node,
const ModelObject* object );
static void createSizeAttrs( QDomElement& node,
const ModelObject* object );
static void createLineAttrs( QDomElement& node,
const ModelObject* object );
static void createFillAttrs( QDomElement& node,
const ModelObject* object );
static void createAffineAttrs( QDomElement& node,
const ModelObject* object );
static void createShadowAttrs( QDomElement& node,
const ModelObject* object );
static void createMergeNode( QDomElement& parent,
const Model* model );
static void createVariablesNode( QDomElement& parent,
const Model* model );
static void createVariableNode( QDomElement& parent,
const Variable& v );
static void createDataNode( QDomElement& parent,
const Model* model,
const QList<ModelObject*>& objects );
static void createPngFileNode( QDomElement& parent,
const QString& name,
const QImage& image );
static void createSvgFileNode( QDomElement& parent,
const QString& name,
const QByteArray& svg );
};
+115 -50
View File
@@ -105,7 +105,7 @@ namespace glabels
return nullptr;
}
return parseRootNode( root );
return parseRootNode( root, fileName );
}
@@ -132,12 +132,12 @@ namespace glabels
return nullptr;
}
return parseRootNode( root );
return parseRootNode( root, QString() );
}
QList<ModelObject*>
XmlLabelParser::deserializeObjects( const QByteArray& buffer )
XmlLabelParser::deserializeObjects( const QByteArray& buffer, const Model* model )
{
QList<ModelObject*> list;
@@ -167,7 +167,7 @@ namespace glabels
{
if ( child.toElement().tagName() == "Data" )
{
parseDataNode( child.toElement(), data );
parseDataNode( child.toElement(), model, data );
}
}
@@ -176,9 +176,10 @@ namespace glabels
{
if ( child.toElement().tagName() == "Objects" )
{
list = parseObjectsNode( child.toElement(), data );
list = parseObjectsNode( child.toElement(), model, data );
}
}
return list;
}
@@ -236,7 +237,7 @@ namespace glabels
Model*
XmlLabelParser::parseRootNode( const QDomElement &node )
XmlLabelParser::parseRootNode( const QDomElement &node, const QString& fileName )
{
QString version = XmlUtil::getStringAttr( node, "version", "" );
if ( version != "4.0" )
@@ -245,7 +246,8 @@ namespace glabels
return XmlLabelParser_3::parseRootNode(node);
}
auto* label = new Model();
auto* model = new Model();
model->setFileName( fileName );
/* Pass 1, extract data nodes to pre-load cache. */
DataCache data;
@@ -253,7 +255,7 @@ namespace glabels
{
if ( child.toElement().tagName() == "Data" )
{
parseDataNode( child.toElement(), data );
parseDataNode( child.toElement(), model, data );
}
}
@@ -268,23 +270,27 @@ namespace glabels
if ( tmplate == nullptr )
{
qWarning() << "Unable to parse template";
delete label;
delete model;
return nullptr;
}
label->setTmplate( tmplate );
model->setTmplate( tmplate );
}
else if ( tagName == "Objects" )
{
label->setRotate( parseRotateAttr( child.toElement() ) );
QList<ModelObject*> list = parseObjectsNode( child.toElement(), data );
model->setRotate( parseRotateAttr( child.toElement() ) );
auto list = parseObjectsNode( child.toElement(), model, data );
foreach ( ModelObject* object, list )
{
label->addObject( object );
model->addObject( object );
}
}
else if ( tagName == "Merge" )
{
parseMergeNode( child.toElement(), label );
parseMergeNode( child.toElement(), model );
}
else if ( tagName == "Variables" )
{
parseVariablesNode( child.toElement(), model );
}
else if ( tagName == "Data" )
{
@@ -296,13 +302,15 @@ namespace glabels
}
}
label->clearModified();
return label;
model->clearModified();
return model;
}
QList<ModelObject*>
XmlLabelParser::parseObjectsNode( const QDomElement &node, const DataCache& data )
XmlLabelParser::parseObjectsNode( const QDomElement& node,
const Model* model,
const DataCache& data )
{
QList<ModelObject*> list;
@@ -328,7 +336,7 @@ namespace glabels
}
else if ( tagName == "Object-image" )
{
list.append( parseObjectImageNode( child.toElement(), data ) );
list.append( parseObjectImageNode( child.toElement(), model, data ) );
}
else if ( tagName == "Object-barcode" )
{
@@ -361,13 +369,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 */
@@ -387,7 +395,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, lockAspectRatio,
@@ -415,13 +423,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 */
@@ -441,7 +449,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, lockAspectRatio,
@@ -468,7 +476,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 */
@@ -488,7 +496,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,
@@ -499,7 +507,9 @@ namespace glabels
ModelImageObject*
XmlLabelParser::parseObjectImageNode( const QDomElement &node, const DataCache& data )
XmlLabelParser::parseObjectImageNode( const QDomElement& node,
const Model* model,
const DataCache& data )
{
/* position attrs */
Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 );
@@ -533,7 +543,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() )
@@ -545,17 +555,19 @@ namespace glabels
}
else
{
if ( data.hasImage( filename ) )
QString fn = QDir::cleanPath( model->dir().absoluteFilePath( filename ) );
if ( data.hasImage( fn ) )
{
return new ModelImageObject( x0, y0, w, h, lockAspectRatio,
filename, data.getImage( filename ),
fn, data.getImage( fn ),
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( fn ) )
{
return new ModelImageObject( x0, y0, w, h, lockAspectRatio,
filename, data.getSvg( filename ),
fn, data.getSvg( fn ),
QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ),
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode );
}
@@ -563,7 +575,7 @@ namespace glabels
{
if ( !filename.isEmpty() )
{
qWarning() << "Embedded file" << filename << "missing. Trying actual file.";
qWarning() << "Embedded file" << fn << "missing. Trying actual file.";
}
return new ModelImageObject( x0, y0, w, h, lockAspectRatio,
filenameNode,
@@ -594,7 +606,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", "" );
@@ -629,7 +641,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 */
@@ -663,7 +675,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. */
@@ -715,28 +727,45 @@ namespace glabels
void
XmlLabelParser::parseMergeNode( const QDomElement &node, Model* label )
XmlLabelParser::parseMergeNode( const QDomElement &node, Model* model )
{
QString type = XmlUtil::getStringAttr( node, "type", "None" );
QString src = XmlUtil::getStringAttr( node, "src", "" );
QString id = XmlUtil::getStringAttr( node, "type", "None" );
QString src = XmlUtil::getStringAttr( node, "src", "" );
merge::Merge* merge = merge::Factory::createMerge( type );
merge->setSource( src );
merge::Merge* merge = merge::Factory::createMerge( id );
label->setMerge( merge );
switch ( merge::Factory::idToType( id ) )
{
case merge::Factory::NONE:
case merge::Factory::FIXED:
break;
case merge::Factory::FILE:
{
QString fn = QDir::cleanPath( model->dir().absoluteFilePath( src ) );
merge->setSource( fn );
}
break;
default:
qWarning() << "XmlLabelCreator::createMergeNode(): Should not be reached!";
break;
}
model->setMerge( merge );
}
void
XmlLabelParser::parseDataNode( const QDomElement &node, DataCache& data )
XmlLabelParser::parseVariablesNode( const QDomElement &node, Model* model )
{
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
QString tagName = child.toElement().tagName();
if ( tagName == "File" )
if ( tagName == "Variable" )
{
parseFileNode( child.toElement(), data );
parseVariableNode( child.toElement(), model );
}
else if ( !child.isComment() )
{
@@ -747,19 +776,55 @@ namespace glabels
void
XmlLabelParser::parsePixdataNode( const QDomElement& node, DataCache& data )
XmlLabelParser::parseVariableNode( const QDomElement &node, Model* model )
{
// TODO, compatibility with glabels-3
QString typeString = XmlUtil::getStringAttr( node, "type", "string" );
QString name = XmlUtil::getStringAttr( node, "name", "unknown" );
QString initialValue = XmlUtil::getStringAttr( node, "initialValue", "0" );
QString incrementString = XmlUtil::getStringAttr( node, "increment", "never" );
QString stepSize = XmlUtil::getStringAttr( node, "stepSize", "0" );
auto type = Variable::idStringToType( typeString );
auto increment = Variable::idStringToIncrement( incrementString );
Variable v( type, name, initialValue, increment, stepSize );
model->variables()->addVariable( v );
}
void
XmlLabelParser::parseFileNode( const QDomElement& node, DataCache& data )
XmlLabelParser::parseDataNode( const QDomElement &node,
const Model* model,
DataCache& data )
{
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
QString tagName = child.toElement().tagName();
if ( tagName == "File" )
{
parseFileNode( child.toElement(), model, data );
}
else if ( !child.isComment() )
{
qWarning() << "Unexpected" << node.tagName() << "child:" << tagName;
}
}
}
void
XmlLabelParser::parseFileNode( const QDomElement& node,
const Model* model,
DataCache& data )
{
QString name = XmlUtil::getStringAttr( node, "name", "" );
QString mimetype = XmlUtil::getStringAttr( node, "mimetype", "image/png" );
QString encoding = XmlUtil::getStringAttr( node, "encoding", "base64" );
// Rewrite name as absolute file path
QString fn = QDir::cleanPath( model->dir().absoluteFilePath( name ) );
if ( mimetype == "image/png" )
{
if ( encoding == "base64" )
@@ -769,7 +834,7 @@ namespace glabels
QImage image;
image.loadFromData( ba, "PNG" );
data.addImage( name, image );
data.addImage( fn, image );
}
else
{
@@ -778,7 +843,7 @@ namespace glabels
}
else if ( mimetype == "image/svg+xml" )
{
data.addSvg( name, node.text().toUtf8() );
data.addSvg( fn, node.text().toUtf8() );
}
}
+48 -16
View File
@@ -52,25 +52,57 @@ namespace glabels
public:
static Model* readFile( const QString& fileName );
static Model* readBuffer( const QByteArray& buffer );
static QList<ModelObject*> deserializeObjects( const QByteArray& buffer );
static QList<ModelObject*> deserializeObjects( const QByteArray& buffer,
const Model* model );
private:
static void gunzip( const QByteArray& gzippedData, QByteArray& data );
static Model* parseRootNode( const QDomElement &node );
static QList<ModelObject*> parseObjectsNode( const QDomElement &node, const DataCache& data );
static ModelBoxObject* parseObjectBoxNode( const QDomElement &node );
static ModelEllipseObject* parseObjectEllipseNode( const QDomElement &node );
static ModelLineObject* parseObjectLineNode( const QDomElement &node );
static ModelImageObject* parseObjectImageNode( const QDomElement &node, const DataCache& data );
static ModelBarcodeObject* parseObjectBarcodeNode( const QDomElement &node );
static ModelTextObject* parseObjectTextNode( const QDomElement &node );
static QString parsePNode( const QDomElement &node );
static bool parseRotateAttr( const QDomElement &node );
static void parseMergeNode( const QDomElement &node, Model* label );
static void parseDataNode( const QDomElement &node, DataCache& data );
static void parsePixdataNode( const QDomElement &node, DataCache& data );
static void parseFileNode( const QDomElement &node, DataCache& data );
static void gunzip( const QByteArray& gzippedData,
QByteArray& data );
static Model* parseRootNode( const QDomElement& node,
const QString& fileName );
static QList<ModelObject*> parseObjectsNode( const QDomElement& node,
const Model* model,
const DataCache& data );
static ModelBoxObject* parseObjectBoxNode( const QDomElement& node );
static ModelEllipseObject* parseObjectEllipseNode( const QDomElement& node );
static ModelLineObject* parseObjectLineNode( const QDomElement& node );
static ModelImageObject* parseObjectImageNode( const QDomElement& node,
const Model* model,
const DataCache& data );
static ModelBarcodeObject* parseObjectBarcodeNode( const QDomElement& node );
static ModelTextObject* parseObjectTextNode( const QDomElement& node );
static QString parsePNode( const QDomElement& node );
static bool parseRotateAttr( const QDomElement& node );
static void parseMergeNode( const QDomElement& node,
Model* model );
static void parseVariablesNode( const QDomElement& node,
Model* model );
static void parseVariableNode( const QDomElement& node,
Model* model );
static void parseDataNode( const QDomElement& node,
const Model* model,
DataCache& data );
static void parseFileNode( const QDomElement& node,
const Model* model,
DataCache& data );
};
+13 -12
View File
@@ -45,6 +45,7 @@ void TestColorNode::colorNode()
QColor white = QColor::fromRgba( rgbaWhite );
QColor red = QColor::fromRgba( qRgbaRed );
QColor green80 = QColor::fromRgba( qRgbaGreen80 );
QColor silver80 = QColor( 192, 192, 192, 128 );
Record record;
@@ -53,8 +54,8 @@ void TestColorNode::colorNode()
QCOMPARE( colorNode.color(), blackTransparent );
QCOMPARE( colorNode.key(), QString( "" ) );
QCOMPARE( colorNode.rgba(), rgbaBlackTransparent );
QCOMPARE( colorNode.color( nullptr ), blackTransparent );
QCOMPARE( colorNode.color( &record ), blackTransparent );
QCOMPARE( colorNode.color( nullptr, nullptr ), blackTransparent );
QCOMPARE( colorNode.color( &record, nullptr ), blackTransparent );
colorNode.setField( true );
QVERIFY( colorNode.isField() );
@@ -64,8 +65,8 @@ void TestColorNode::colorNode()
colorNode.setColor( white );
QCOMPARE( colorNode.color(), white );
QCOMPARE( colorNode.rgba(), rgbaWhite );
QCOMPARE( colorNode.color( nullptr ), white );
QCOMPARE( colorNode.color( &record ), white );
QCOMPARE( colorNode.color( nullptr, nullptr ), white );
QCOMPARE( colorNode.color( &record, nullptr ), white );
colorNode.setKey( "key1" );
QCOMPARE( colorNode.key(), QString( "key1" ) );
@@ -102,28 +103,28 @@ void TestColorNode::colorNode()
QVERIFY( colorNode.isField() ); // Defaults to true if given key only
QCOMPARE( colorNode.key(), QString( "key1" ) );
QCOMPARE( colorNode.color(), blackTransparent );
QCOMPARE( colorNode.color( &record ), blackTransparent );
QCOMPARE( colorNode.color( &record, nullptr ), silver80 ); // Defaults to silver if given non-matching record/variables
///
/// Record
///
record["key1"] = "white";
QCOMPARE( colorNode.color( &record ), white );
QCOMPARE( colorNode.color( &record, nullptr ), white );
record["key1"] = "red";
QCOMPARE( colorNode.color( &record ), red );
QCOMPARE( colorNode.color( &record, nullptr ), red );
record["key1"] = "#FF0000";
QCOMPARE( colorNode.color( &record ), red );
QCOMPARE( colorNode.color( &record, nullptr ), red );
record["key1"] = "#FFFF0000"; // ARGB
QCOMPARE( colorNode.color( &record ), red );
QCOMPARE( colorNode.color( &record, nullptr ), red );
record["key1"] = "#8000FF00";
QCOMPARE( colorNode.color( &record ), green80 );
QCOMPARE( colorNode.color( &record, nullptr ), green80 );
colorNode.setKey( "key2" );
QCOMPARE( colorNode.color( &record ), blackTransparent );
QCOMPARE( colorNode.color( &record, nullptr ), silver80 );
record["key2"] = "#8000FF00";
QCOMPARE( colorNode.color( &record ), green80 );
QCOMPARE( colorNode.color( &record, nullptr ), green80 );
}
+10 -10
View File
@@ -42,14 +42,14 @@ void TestRawText::rawText()
QVERIFY( !rawText.hasPlaceHolders() );
QCOMPARE( rawText.toString(), QString( "" ) );
QCOMPARE( rawText.toStdString(), std::string( "" ) );
QCOMPARE( rawText.expand( &record ), QString( "" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "" ) );
rawText = "text";
QVERIFY( !rawText.isEmpty() );
QVERIFY( !rawText.hasPlaceHolders() );
QCOMPARE( rawText.toString(), QString( "text" ) );
QCOMPARE( rawText.toStdString(), std::string( "text" ) );
QCOMPARE( rawText.expand( &record ), QString( "text" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "text" ) );
RawText rawText2( "text" );
QVERIFY( !rawText2.isEmpty() );
@@ -61,34 +61,34 @@ void TestRawText::rawText()
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.toString(), QString( "${key1}" ) );
QCOMPARE( rawText.toStdString(), std::string( "${key1}" ) );
QCOMPARE( rawText.expand( &record ), QString( "" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "" ) );
///
/// Record
///
record["key1"] = "val1";
QCOMPARE( rawText.expand( &record ), QString( "val1" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1" ) );
rawText = "${key1}${key2}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record ), QString( "val1" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1" ) );
record["key2"] = "val2";
QCOMPARE( rawText.expand( &record ), QString( "val1val2" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1val2" ) );
rawText = "${key1}text${key2}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record ), QString( "val1textval2" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1textval2" ) );
rawText = "text1${key1}text2${key2}text3";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record ), QString( "text1val1text2val2text3" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "text1val1text2val2text3" ) );
rawText = "${key1}text${key2}${key3}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record ), QString( "val1textval2" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val1textval2" ) );
rawText = "${key2}${key3}${key1}";
QVERIFY( rawText.hasPlaceHolders() );
QCOMPARE( rawText.expand( &record ), QString( "val2val1" ) );
QCOMPARE( rawText.expand( &record, nullptr ), QString( "val2val1" ) );
}
+59 -47
View File
@@ -139,6 +139,8 @@ void TestSubstitutionField::simpleEvaluation()
{
using namespace glabels;
model::Variables variables;
model::SubstitutionField f1( "${1}" );
model::SubstitutionField f2( "${2}" );
model::SubstitutionField f3( "${3}" );
@@ -150,10 +152,10 @@ void TestSubstitutionField::simpleEvaluation()
record1[ "3" ] = "Opqrstu";
record1[ "4" ] = "Vwxyz!@";
QCOMPARE( f1.evaluate( &record1 ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( &record1 ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( &record1 ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( &record1 ), QString( "Vwxyz!@" ) );
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "Vwxyz!@" ) );
merge::Record record2;
record2[ "1" ] = "1234567";
@@ -161,10 +163,10 @@ void TestSubstitutionField::simpleEvaluation()
record2[ "3" ] = "8901234";
record2[ "4" ] = "#$%^&*";
QCOMPARE( f1.evaluate( &record2 ), QString( "1234567" ) );
QCOMPARE( f2.evaluate( &record2 ), QString( "FooBar" ) );
QCOMPARE( f3.evaluate( &record2 ), QString( "8901234" ) );
QCOMPARE( f4.evaluate( &record2 ), QString( "#$%^&*" ) );
QCOMPARE( f1.evaluate( &record2, &variables ), QString( "1234567" ) );
QCOMPARE( f2.evaluate( &record2, &variables ), QString( "FooBar" ) );
QCOMPARE( f3.evaluate( &record2, &variables ), QString( "8901234" ) );
QCOMPARE( f4.evaluate( &record2, &variables ), QString( "#$%^&*" ) );
}
@@ -172,6 +174,8 @@ void TestSubstitutionField::defaultValueEvaluation()
{
using namespace glabels;
model::Variables variables;
model::SubstitutionField f1( "${1:=foo1}" );
model::SubstitutionField f2( "${2:=foo2}" );
model::SubstitutionField f3( "${3:=foo3}" );
@@ -183,17 +187,17 @@ void TestSubstitutionField::defaultValueEvaluation()
record1[ "3" ] = "Opqrstu";
record1[ "4" ] = "Vwxyz!@";
QCOMPARE( f1.evaluate( &record1 ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( &record1 ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( &record1 ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( &record1 ), QString( "Vwxyz!@" ) );
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "Abcdefg" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "Hijklmn" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "Opqrstu" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "Vwxyz!@" ) );
merge::Record record2; // All fields empty
QCOMPARE( f1.evaluate( &record2 ), QString( "foo1" ) );
QCOMPARE( f2.evaluate( &record2 ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( &record2 ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( &record2 ), QString( "foo4" ) );
QCOMPARE( f1.evaluate( &record2, &variables ), QString( "foo1" ) );
QCOMPARE( f2.evaluate( &record2, &variables ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( &record2, &variables ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( &record2, &variables ), QString( "foo4" ) );
merge::Record record3;
record3[ "1" ] = "xyzzy";
@@ -201,10 +205,10 @@ void TestSubstitutionField::defaultValueEvaluation()
// Field "3" empty
record3[ "4" ] = "plugh";
QCOMPARE( f1.evaluate( &record3 ), QString( "xyzzy" ) );
QCOMPARE( f2.evaluate( &record3 ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( &record3 ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( &record3 ), QString( "plugh" ) );
QCOMPARE( f1.evaluate( &record3, &variables ), QString( "xyzzy" ) );
QCOMPARE( f2.evaluate( &record3, &variables ), QString( "foo2" ) );
QCOMPARE( f3.evaluate( &record3, &variables ), QString( "foo3" ) );
QCOMPARE( f4.evaluate( &record3, &variables ), QString( "plugh" ) );
}
@@ -212,6 +216,8 @@ void TestSubstitutionField::formattedStringEvaluation()
{
using namespace glabels;
model::Variables variables;
model::SubstitutionField f1( "${1:%10s}" );
model::SubstitutionField f2( "${2:%10s}" );
model::SubstitutionField f3( "${3:%10s}" );
@@ -233,15 +239,15 @@ void TestSubstitutionField::formattedStringEvaluation()
record1[ "7" ] = "-100";
record1[ "8" ] = "3.14";
QCOMPARE( f1.evaluate( &record1 ), QString( " 0" ) );
QCOMPARE( f2.evaluate( &record1 ), QString( " 1" ) );
QCOMPARE( f3.evaluate( &record1 ), QString( " -1" ) );
QCOMPARE( f4.evaluate( &record1 ), QString( " 3.14" ) );
QCOMPARE( f1.evaluate( &record1, &variables ), QString( " 0" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( " 1" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( " -1" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( " 3.14" ) );
QCOMPARE( f5.evaluate( &record1 ), QString( "0 " ) );
QCOMPARE( f6.evaluate( &record1 ), QString( "100 " ) );
QCOMPARE( f7.evaluate( &record1 ), QString( "-100 " ) );
QCOMPARE( f8.evaluate( &record1 ), QString( "3.14 " ) );
QCOMPARE( f5.evaluate( &record1, &variables ), QString( "0 " ) );
QCOMPARE( f6.evaluate( &record1, &variables ), QString( "100 " ) );
QCOMPARE( f7.evaluate( &record1, &variables ), QString( "-100 " ) );
QCOMPARE( f8.evaluate( &record1, &variables ), QString( "3.14 " ) );
}
@@ -249,6 +255,8 @@ void TestSubstitutionField::formattedFloatEvaluation()
{
using namespace glabels;
model::Variables variables;
model::SubstitutionField f1( "${1:%+5.2f}" );
model::SubstitutionField f2( "${2:%+5.2f}" );
model::SubstitutionField f3( "${3:%+5.2f}" );
@@ -270,15 +278,15 @@ void TestSubstitutionField::formattedFloatEvaluation()
record1[ "7" ] = "-100";
record1[ "8" ] = "3.14";
QCOMPARE( f1.evaluate( &record1 ), QString( "+0.00" ) );
QCOMPARE( f2.evaluate( &record1 ), QString( "+1.00" ) );
QCOMPARE( f3.evaluate( &record1 ), QString( "-1.00" ) );
QCOMPARE( f4.evaluate( &record1 ), QString( "+3.14" ) );
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "+0.00" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "+1.00" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "-1.00" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "+3.14" ) );
QCOMPARE( f5.evaluate( &record1 ), QString( "+0.00e+00" ) );
QCOMPARE( f6.evaluate( &record1 ), QString( "+1.00e+02" ) );
QCOMPARE( f7.evaluate( &record1 ), QString( "-1.00e+02" ) );
QCOMPARE( f8.evaluate( &record1 ), QString( "+3.14e+00" ) );
QCOMPARE( f5.evaluate( &record1, &variables ), QString( "+0.00e+00" ) );
QCOMPARE( f6.evaluate( &record1, &variables ), QString( "+1.00e+02" ) );
QCOMPARE( f7.evaluate( &record1, &variables ), QString( "-1.00e+02" ) );
QCOMPARE( f8.evaluate( &record1, &variables ), QString( "+3.14e+00" ) );
}
@@ -286,6 +294,8 @@ void TestSubstitutionField::formattedIntEvaluation()
{
using namespace glabels;
model::Variables variables;
model::SubstitutionField f1( "${1:%08d}" );
model::SubstitutionField f2( "${2:%08d}" );
model::SubstitutionField f3( "${3:%08d}" );
@@ -307,15 +317,15 @@ void TestSubstitutionField::formattedIntEvaluation()
record1[ "7" ] = "-1";
record1[ "8" ] = "314";
QCOMPARE( f1.evaluate( &record1 ), QString( "00000000" ) );
QCOMPARE( f2.evaluate( &record1 ), QString( "00000001" ) );
QCOMPARE( f3.evaluate( &record1 ), QString( "-0000001" ) );
QCOMPARE( f4.evaluate( &record1 ), QString( "00000000" ) ); // Invalid integer value
QCOMPARE( f1.evaluate( &record1, &variables ), QString( "00000000" ) );
QCOMPARE( f2.evaluate( &record1, &variables ), QString( "00000001" ) );
QCOMPARE( f3.evaluate( &record1, &variables ), QString( "-0000001" ) );
QCOMPARE( f4.evaluate( &record1, &variables ), QString( "00000000" ) ); // Invalid integer value
QCOMPARE( f5.evaluate( &record1 ), QString( "00000064" ) ); // 100(decimal) == 64(hex)
QCOMPARE( f6.evaluate( &record1 ), QString( "00000100" ) );
QCOMPARE( f7.evaluate( &record1 ), QString( "00000000" ) ); // Invalid unsigned integer
QCOMPARE( f8.evaluate( &record1 ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex)
QCOMPARE( f5.evaluate( &record1, &variables ), QString( "00000064" ) ); // 100(decimal) == 64(hex)
QCOMPARE( f6.evaluate( &record1, &variables ), QString( "00000100" ) );
QCOMPARE( f7.evaluate( &record1, &variables ), QString( "00000000" ) ); // Invalid unsigned integer
QCOMPARE( f8.evaluate( &record1, &variables ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex)
}
@@ -323,6 +333,8 @@ void TestSubstitutionField::newLineEvaluation()
{
using namespace glabels;
model::Variables variables;
model::SubstitutionField addr2( "${ADDR2:n}" );
QCOMPARE( addr2.fieldName(), QString( "ADDR2" ) );
QCOMPARE( addr2.newLine(), true );
@@ -336,7 +348,7 @@ void TestSubstitutionField::newLineEvaluation()
merge::Record record3;
// ADDR2 not defined
QCOMPARE( addr2.evaluate( &record1 ), QString( "\nApt. 5B" ) ); // Prepends a newline
QCOMPARE( addr2.evaluate( &record2 ), QString( "" ) ); // Evaluates empty
QCOMPARE( addr2.evaluate( &record3 ), QString( "" ) ); // Evaluates empty
QCOMPARE( addr2.evaluate( &record1, &variables ), QString( "\nApt. 5B" ) ); // Prepends a newline
QCOMPARE( addr2.evaluate( &record2, &variables ), QString( "" ) ); // Evaluates empty
QCOMPARE( addr2.evaluate( &record3, &variables ), QString( "" ) ); // Evaluates empty
}
+10 -24
View File
@@ -42,32 +42,24 @@ void TestTextNode::textNode()
QCOMPARE( textNode.data(), QString( "" ) );
QVERIFY( textNode == TextNode() );
QVERIFY( !(textNode != TextNode()) );
QCOMPARE( textNode.text( nullptr ), QString( "" ) );
QCOMPARE( textNode.text( &record ), QString( "" ) );
QVERIFY( !textNode.isEmptyField( nullptr ) );
QVERIFY( !textNode.isEmptyField( &record ) );
QCOMPARE( textNode.text( nullptr, nullptr ), QString( "" ) );
QCOMPARE( textNode.text( &record, nullptr ), QString( "" ) );
textNode.setField( true );
QVERIFY( textNode.isField() );
QCOMPARE( textNode.text( &record ), QString( "" ) );
QVERIFY( !textNode.isEmptyField( nullptr ) );
QVERIFY( !textNode.isEmptyField( &record ) );
QCOMPARE( textNode.text( &record, nullptr ), QString( "" ) );
textNode.setField( false );
QVERIFY( !textNode.isField() );
textNode.setData( QString( "data1" ) );
QCOMPARE( textNode.data(), QString( "data1" ) );
QCOMPARE( textNode.text( nullptr ), QString( "data1" ) );
QCOMPARE( textNode.text( &record ), QString( "data1" ) );
QVERIFY( !textNode.isEmptyField( nullptr ) );
QVERIFY( !textNode.isEmptyField( &record ) );
QCOMPARE( textNode.text( nullptr, nullptr ), QString( "data1" ) );
QCOMPARE( textNode.text( &record, nullptr ), QString( "data1" ) );
textNode.setField( true );
QCOMPARE( textNode.text( nullptr ), QString( "${data1}" ) );
QCOMPARE( textNode.text( &record ), QString( "" ) );
QVERIFY( !textNode.isEmptyField( nullptr ) );
QVERIFY( !textNode.isEmptyField( &record ) );
QCOMPARE( textNode.text( nullptr, nullptr ), QString( "" ) );
QCOMPARE( textNode.text( &record, nullptr ), QString( "" ) );
///
/// Constructors
@@ -89,17 +81,11 @@ void TestTextNode::textNode()
/// Record
///
record["key1"] = "";
QCOMPARE( textNode.text( &record ), QString( "" ) );
QVERIFY( !textNode.isEmptyField( nullptr ) );
QVERIFY( !textNode.isEmptyField( &record ) );
QCOMPARE( textNode.text( &record, nullptr ), QString( "" ) );
textNode.setData( QString( "key1" ) );
QCOMPARE( textNode.text( &record ), QString( "" ) );
QVERIFY( !textNode.isEmptyField( nullptr ) );
QVERIFY( textNode.isEmptyField( &record ) );
QCOMPARE( textNode.text( &record, nullptr ), QString( "" ) );
record["key1"] = "val1";
QCOMPARE( textNode.text( &record ), QString( "val1" ) );
QVERIFY( !textNode.isEmptyField( nullptr ) );
QVERIFY( !textNode.isEmptyField( &record ) );
QCOMPARE( textNode.text( &record, nullptr ), QString( "val1" ) );
}
+23 -7
View File
@@ -25,6 +25,7 @@
#include "barcode/Backends.h"
#include "model/ColorNode.h"
#include "model/Model.h"
#include "model/Size.h"
#include "model/ModelBarcodeObject.h"
@@ -55,15 +56,16 @@ void TestXmlLabel::serializeDeserialize()
//
// Empty object list
//
Model* model = new Model();
QList<ModelObject*> objects, outObjects;
QByteArray buffer, outBuffer;
QCOMPARE( objects.count(), 0 );
XmlLabelCreator::serializeObjects( objects, buffer );
outObjects = XmlLabelParser::deserializeObjects( buffer );
XmlLabelCreator::serializeObjects( objects, model, buffer );
outObjects = XmlLabelParser::deserializeObjects( buffer, model );
QCOMPARE( objects.count(), outObjects.count() );
QCOMPARE( objects, outObjects );
XmlLabelCreator::serializeObjects( outObjects, outBuffer );
XmlLabelCreator::serializeObjects( outObjects, model, outBuffer );
QCOMPARE( buffer, outBuffer );
//
@@ -90,10 +92,13 @@ void TestXmlLabel::serializeDeserialize()
QCOMPARE( objects.count(), 10 );
buffer.clear();
XmlLabelCreator::serializeObjects( objects, buffer );
outObjects = XmlLabelParser::deserializeObjects( buffer );
XmlLabelCreator::serializeObjects( objects, model, buffer );
outObjects = XmlLabelParser::deserializeObjects( buffer, model );
QCOMPARE( objects.count(), outObjects.count() );
QString currentPath = QDir::currentPath();
currentPath.append( QDir::separator() );
for ( int i = 0; i < objects.count(); i++ )
{
qDebug() << "object" << i;
@@ -128,7 +133,18 @@ void TestXmlLabel::serializeDeserialize()
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() );
QCOMPARE( objects.at(i)->filenameNode().isField(), outObjects.at(i)->filenameNode().isField() );
QCOMPARE( objects.at(i)->filenameNode().data().isEmpty(), outObjects.at(i)->filenameNode().data().isEmpty() );
if ( objects.at(i)->filenameNode().data().isEmpty() || objects.at(i)->filenameNode().isField() || (!objects.at(i)->image() && objects.at(i)->svg().isEmpty()) )
{
QVERIFY( objects.at(i)->filenameNode() == outObjects.at(i)->filenameNode() );
}
else
{
QVERIFY( objects.at(i)->filenameNode() != outObjects.at(i)->filenameNode() );
QCOMPARE( currentPath + objects.at(i)->filenameNode().data(), outObjects.at(i)->filenameNode().data() );
}
if ( objects.at(i)->image() )
{
QCOMPARE( *(objects.at(i)->image()), *(outObjects.at(i)->image()) );
@@ -157,6 +173,6 @@ void TestXmlLabel::serializeDeserialize()
}
outBuffer.clear();
XmlLabelCreator::serializeObjects( outObjects, outBuffer );
XmlLabelCreator::serializeObjects( outObjects, model, outBuffer );
QCOMPARE( buffer, outBuffer );
}