From 37f0a8890d195084d02800357072896f69ee77d4 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 24 Mar 2019 17:49:41 -0400 Subject: [PATCH] Implemented variable substitution in simple print jobs. --- glabels/EditVariableDialog.cpp | 42 +++++-- glabels/LabelEditor.cpp | 2 +- glabels/VariablesView.cpp | 6 +- glabels/ui/EditVariableDialog.ui | 6 +- model/Model.cpp | 4 +- model/Model.h | 5 +- model/ModelBarcodeObject.cpp | 13 +- model/ModelBarcodeObject.h | 19 ++- model/ModelBoxObject.cpp | 10 +- model/ModelBoxObject.h | 12 +- model/ModelEllipseObject.cpp | 10 +- model/ModelEllipseObject.h | 12 +- model/ModelImageObject.cpp | 10 +- model/ModelImageObject.h | 12 +- model/ModelLineObject.cpp | 10 +- model/ModelLineObject.h | 12 +- model/ModelObject.cpp | 9 +- model/ModelObject.h | 19 ++- model/ModelTextObject.cpp | 21 ++-- model/ModelTextObject.h | 27 +++- model/PageRenderer.cpp | 62 +++++---- model/PageRenderer.h | 4 +- model/RawText.cpp | 4 +- model/RawText.h | 2 +- model/SubstitutionField.cpp | 18 ++- model/SubstitutionField.h | 3 +- model/Variable.cpp | 139 ++++++++++++++++++--- model/Variable.h | 21 +++- model/Variables.cpp | 48 +++++++ model/Variables.h | 5 + model/XmlLabelCreator.cpp | 2 +- model/XmlLabelParser.cpp | 4 +- model/unit_tests/TestSubstitutionField.cpp | 106 +++++++++------- translations/glabels_C.ts | 38 +++--- 34 files changed, 524 insertions(+), 193 deletions(-) diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index 2abcb12..4d3b84d 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -29,8 +29,9 @@ namespace { // All variable types. (must be in sorted order) const QVector allTypes = { - glabels::model::Variable::Type::NUMERIC, - glabels::model::Variable::Type::STRING + glabels::model::Variable::Type::STRING, + glabels::model::Variable::Type::INTEGER, + glabels::model::Variable::Type::FLOATING_POINT }; // All variable increments. (must be in sorted order) @@ -76,7 +77,7 @@ namespace glabels { typeCombo->setCurrentIndex( static_cast(variable.type()) ); nameEdit->setText( variable.name() ); - valueEdit->setText( variable.value() ); + valueEdit->setText( variable.initialValue() ); incrementCombo->setCurrentIndex( static_cast(variable.increment()) ); stepSizeEdit->setText( variable.stepSize() ); @@ -150,8 +151,20 @@ namespace glabels auto type = static_cast(typeCombo->currentIndex()); auto increment = static_cast(incrementCombo->currentIndex()); - if ( type == model::Variable::Type::NUMERIC ) + switch (type) { + + case model::Variable::Type::INTEGER: + valueEdit->setValidator( new QIntValidator() ); + stepSizeEdit->setValidator( new QIntValidator() ); + + if ( increment == model::Variable::Increment::NEVER ) + { + stepSizeEdit->setText( "0" ); + } + break; + + case model::Variable::Type::FLOATING_POINT: valueEdit->setValidator( new QDoubleValidator() ); stepSizeEdit->setValidator( new QDoubleValidator() ); @@ -159,21 +172,24 @@ namespace glabels { stepSizeEdit->setText( "0" ); } - } - else - { + break; + + default: valueEdit->setValidator( nullptr ); stepSizeEdit->setValidator( nullptr ); incrementCombo->setCurrentIndex( static_cast(model::Variable::Increment::NEVER) ); stepSizeEdit->setText( "" ); + break; + } - incrementLabel->setEnabled( type == model::Variable::Type::NUMERIC ); - incrementCombo->setEnabled( type == model::Variable::Type::NUMERIC ); - stepSizeLabel->setEnabled( (type == model::Variable::Type::NUMERIC) && - (increment != model::Variable::Increment::NEVER) ); - stepSizeEdit->setEnabled( (type == model::Variable::Type::NUMERIC) && - (increment != model::Variable::Increment::NEVER) ); + bool isNumeric = ( type == model::Variable::Type::INTEGER ) || + ( type == model::Variable::Type::FLOATING_POINT ); + + incrementLabel->setEnabled( isNumeric ); + incrementCombo->setEnabled( isNumeric ); + stepSizeLabel->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) ); + stepSizeEdit->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) ); validateCurrentInputs(); } diff --git a/glabels/LabelEditor.cpp b/glabels/LabelEditor.cpp index ef7fe05..82c272a 100644 --- a/glabels/LabelEditor.cpp +++ b/glabels/LabelEditor.cpp @@ -1157,7 +1157,7 @@ namespace glabels void LabelEditor::drawObjectsLayer( QPainter* painter ) { - mModel->draw( painter ); + mModel->draw( painter, true, nullptr, nullptr ); } diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index a54a43f..9487085 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -63,7 +63,7 @@ namespace glabels typeHeaderItem->setFlags( typeHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_TYPE, typeHeaderItem ); - auto* valueHeaderItem = new QTableWidgetItem( tr("Value") ); + auto* valueHeaderItem = new QTableWidgetItem( tr("Initial Value") ); valueHeaderItem->setFlags( valueHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_VALUE, valueHeaderItem ); @@ -122,7 +122,7 @@ namespace glabels { EditVariableDialog dialog( this ); - model::Variable v( model::Variable::Type::NUMERIC, + model::Variable v( model::Variable::Type::INTEGER, "x", "0", model::Variable::Increment::NEVER, @@ -216,7 +216,7 @@ namespace glabels nameItem->setFlags( nameItem->flags() ^ Qt::ItemIsEditable ); table->setItem( iRow, I_COL_NAME, nameItem ); - auto* valueItem = new QTableWidgetItem( v.value() ); + auto* valueItem = new QTableWidgetItem( v.initialValue() ); valueItem->setFlags( valueItem->flags() ^ Qt::ItemIsEditable ); table->setItem( iRow, I_COL_VALUE, valueItem ); diff --git a/glabels/ui/EditVariableDialog.ui b/glabels/ui/EditVariableDialog.ui index 11399a7..af81a20 100644 --- a/glabels/ui/EditVariableDialog.ui +++ b/glabels/ui/EditVariableDialog.ui @@ -19,7 +19,7 @@ - Variable Type: + Variable type: @@ -39,7 +39,7 @@ - Value: + Initial value: @@ -61,7 +61,7 @@ - Step Size: + Step size: diff --git a/model/Model.cpp b/model/Model.cpp index 896970d..4fe8b34 100644 --- a/model/Model.cpp +++ b/model/Model.cpp @@ -1476,11 +1476,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 ); } } diff --git a/model/Model.h b/model/Model.h index 13b9f4c..cfd74c8 100644 --- a/model/Model.h +++ b/model/Model.h @@ -208,7 +208,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; ///////////////////////////////// diff --git a/model/ModelBarcodeObject.cpp b/model/ModelBarcodeObject.cpp index 315632e..3b65e10 100644 --- a/model/ModelBarcodeObject.cpp +++ b/model/ModelBarcodeObject.cpp @@ -311,7 +311,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. } @@ -322,7 +323,8 @@ namespace glabels /// void ModelBarcodeObject::drawObject( QPainter* painter, bool inEditor, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { QColor bcColor = mBcColorNode.color( record ); @@ -332,7 +334,7 @@ namespace glabels } else { - drawBc( painter, bcColor, record ); + drawBc( painter, bcColor, record, variables ); } } @@ -450,7 +452,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 ) ); @@ -458,7 +461,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 ); diff --git a/model/ModelBarcodeObject.h b/model/ModelBarcodeObject.h index 4931ddf..bd32091 100644 --- a/model/ModelBarcodeObject.h +++ b/model/ModelBarcodeObject.h @@ -126,8 +126,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; @@ -139,7 +147,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; diff --git a/model/ModelBoxObject.cpp b/model/ModelBoxObject.cpp index 94e81d5..24a61c6 100644 --- a/model/ModelBoxObject.cpp +++ b/model/ModelBoxObject.cpp @@ -103,7 +103,10 @@ 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 ); @@ -148,7 +151,10 @@ 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 ); diff --git a/model/ModelBoxObject.h b/model/ModelBoxObject.h index 8705c99..3c784c6 100644 --- a/model/ModelBoxObject.h +++ b/model/ModelBoxObject.h @@ -72,8 +72,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; }; diff --git a/model/ModelEllipseObject.cpp b/model/ModelEllipseObject.cpp index c3ca82e..e9e58fd 100644 --- a/model/ModelEllipseObject.cpp +++ b/model/ModelEllipseObject.cpp @@ -103,7 +103,10 @@ 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 ); @@ -148,7 +151,10 @@ 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 ); diff --git a/model/ModelEllipseObject.h b/model/ModelEllipseObject.h index e26e9ba..cd22cc9 100644 --- a/model/ModelEllipseObject.h +++ b/model/ModelEllipseObject.h @@ -72,8 +72,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; }; diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 5848625..bc9eb18 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -395,7 +395,10 @@ 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() ); @@ -424,7 +427,10 @@ 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() ); diff --git a/model/ModelImageObject.h b/model/ModelImageObject.h index ba87078..d1c62a0 100644 --- a/model/ModelImageObject.h +++ b/model/ModelImageObject.h @@ -132,8 +132,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; diff --git a/model/ModelLineObject.cpp b/model/ModelLineObject.cpp index 5d7b5e1..9223f91 100644 --- a/model/ModelLineObject.cpp +++ b/model/ModelLineObject.cpp @@ -186,7 +186,10 @@ 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 ); @@ -204,7 +207,10 @@ 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 ); diff --git a/model/ModelLineObject.h b/model/ModelLineObject.h index 16cfdb6..a09670e 100644 --- a/model/ModelLineObject.h +++ b/model/ModelLineObject.h @@ -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; diff --git a/model/ModelObject.cpp b/model/ModelObject.cpp index 637352c..c79c9f2 100644 --- a/model/ModelObject.cpp +++ b/model/ModelObject.cpp @@ -1200,7 +1200,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() ); @@ -1210,12 +1213,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(); } diff --git a/model/ModelObject.h b/model/ModelObject.h index 6af51e8..e7a6c2f 100644 --- a/model/ModelObject.h +++ b/model/ModelObject.h @@ -27,6 +27,7 @@ #include "Handles.h" #include "Outline.h" #include "TextNode.h" +#include "Variables.h" #include "barcode/Style.h" #include "merge/Record.h" @@ -403,12 +404,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(); diff --git a/model/ModelTextObject.cpp b/model/ModelTextObject.cpp index 434d48b..45c259e 100644 --- a/model/ModelTextObject.cpp +++ b/model/ModelTextObject.cpp @@ -518,7 +518,8 @@ namespace glabels /// void ModelTextObject::drawShadow( QPainter* painter, bool inEditor, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { QColor textColor = mTextColorNode.color( record ); @@ -533,7 +534,7 @@ namespace glabels } else { - drawText( painter, shadowColor, record ); + drawText( painter, shadowColor, record, variables ); } } } @@ -544,7 +545,8 @@ namespace glabels /// void ModelTextObject::drawObject( QPainter* painter, bool inEditor, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { QColor textColor = mTextColorNode.color( record ); @@ -554,7 +556,7 @@ namespace glabels } else { - drawText( painter, textColor, record ); + drawText( painter, textColor, record, variables ); } } @@ -696,7 +698,8 @@ namespace glabels void ModelTextObject::drawText( QPainter* painter, const QColor& color, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { painter->save(); @@ -704,7 +707,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 ); @@ -716,7 +719,7 @@ namespace glabels QFontMetricsF fontMetrics( font ); double dy = fontMetrics.lineSpacing() * mTextLineSpacing; - QTextDocument document( mText.expand( record ) ); + QTextDocument document( mText.expand( record, variables ) ); QList layouts; @@ -790,7 +793,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 ); @@ -802,7 +805,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 ) diff --git a/model/ModelTextObject.h b/model/ModelTextObject.h index 1ab62c6..d15a624 100644 --- a/model/ModelTextObject.h +++ b/model/ModelTextObject.h @@ -185,8 +185,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; @@ -196,10 +204,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; /////////////////////////////////////////////////////////////// diff --git a/model/PageRenderer.cpp b/model/PageRenderer.cpp index 9c2b702..f1ada0f 100644 --- a/model/PageRenderer.cpp +++ b/model/PageRenderer.cpp @@ -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(); } @@ -249,37 +250,44 @@ 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->incrementVariablesOnCopy(); + if ( (iLabel % mNLabelsPerPage) == 0 /* starting a new page */ ) + { + mVariables->incrementVariablesOnPage(); + } } } @@ -317,7 +325,7 @@ namespace glabels painter->save(); clipLabel( painter ); - printLabel( painter, records[iRecord] ); + printLabel( painter, records[iRecord], mVariables ); painter->restore(); // From before clip @@ -411,7 +419,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(); @@ -427,7 +437,7 @@ namespace glabels painter->scale( -1, 1 ); } - mModel->draw( painter, false, record ); + mModel->draw( painter, false, record, variables ); painter->restore(); } diff --git a/model/PageRenderer.h b/model/PageRenderer.h index 2db3ae4..08c93a9 100644 --- a/model/PageRenderer.h +++ b/model/PageRenderer.h @@ -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; diff --git a/model/RawText.cpp b/model/RawText.cpp index 08ee6bf..ed4cd29 100644 --- a/model/RawText.cpp +++ b/model/RawText.cpp @@ -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 { diff --git a/model/RawText.h b/model/RawText.h index 9b19084..2e8ab44 100644 --- a/model/RawText.h +++ b/model/RawText.h @@ -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; diff --git a/model/SubstitutionField.cpp b/model/SubstitutionField.cpp index 178b73e..76c4047 100644 --- a/model/SubstitutionField.cpp +++ b/model/SubstitutionField.cpp @@ -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; } diff --git a/model/SubstitutionField.h b/model/SubstitutionField.h index ec08a00..baaa255 100644 --- a/model/SubstitutionField.h +++ b/model/SubstitutionField.h @@ -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; diff --git a/model/Variable.cpp b/model/Variable.cpp index b424a6b..8b81a86 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -28,12 +28,12 @@ namespace glabels Variable::Variable( Variable::Type type, const QString& name, - const QString& value, + const QString& initialValue, Variable::Increment increment, const QString& stepSize ) : mType(type), mName(name), - mValue(value), + mInitialValue(initialValue), mIncrement(increment), mStepSize(stepSize) { @@ -53,9 +53,9 @@ namespace glabels } - QString Variable::value() const + QString Variable::initialValue() const { - return mValue; + return mInitialValue; } @@ -70,15 +70,110 @@ namespace glabels 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; + } + } + + 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; + } + } + } + + + void Variable::incrementValueOnMerge() + { + if ( mIncrement == Increment::PER_MERGE_RECORD ) + { + switch (mType) + { + case Type::STRING: + // do nothing + break; + case Type::INTEGER: + mIntegerValue += mIntegerStep; + break; + case Type::FLOATING_POINT: + mFloatingPointValue += mFloatingPointStep; + 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; + } + } + } + + + 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 ); + } + } + + QString Variable::typeToI18nString( Type type ) { switch (type) { - case Type::NUMERIC: - return tr("Numeric"); case Type::STRING: return tr("String"); + case Type::INTEGER: + return tr("Integer"); + case Type::FLOATING_POINT: + return tr("Floating Point"); } } @@ -87,24 +182,30 @@ namespace glabels { switch (type) { - case Type::NUMERIC: - return "numeric"; case Type::STRING: return "string"; + case Type::INTEGER: + return "integer"; + case Type::FLOATING_POINT: + return "float"; } } - Variable::Type Variable::idStringToType( const QString& string ) + Variable::Type Variable::idStringToType( const QString& id ) { - if ( string == "numeric" ) - { - return Type::NUMERIC; - } - else if ( string == "string" ) + if ( id == "string" ) { return Type::STRING; } + else if ( id == "integer" ) + { + return Type::INTEGER; + } + else if ( id == "float" ) + { + return Type::FLOATING_POINT; + } else { return Type::STRING; // Default @@ -144,21 +245,21 @@ namespace glabels } - Variable::Increment Variable::idStringToIncrement( const QString& string ) + Variable::Increment Variable::idStringToIncrement( const QString& id ) { - if ( string == "never" ) + if ( id == "never" ) { return Increment::NEVER; } - else if ( string == "per_copy" ) + else if ( id == "per_copy" ) { return Increment::PER_COPY; } - else if ( string == "per_merge_record" ) + else if ( id == "per_merge_record" ) { return Increment::PER_MERGE_RECORD; } - else if ( string == "per_page" ) + else if ( id == "per_page" ) { return Increment::PER_PAGE; } diff --git a/model/Variable.h b/model/Variable.h index 0a90733..3feb694 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -38,8 +38,9 @@ namespace glabels public: enum class Type { - NUMERIC, - STRING + STRING, + INTEGER, + FLOATING_POINT }; enum class Increment @@ -56,7 +57,7 @@ namespace glabels Variable( Type type, const QString& name, - const QString& value, + const QString& initialValue, Increment increment = Increment::NEVER, const QString& stepSize = "0" ); @@ -65,10 +66,15 @@ namespace glabels Type type() const; QString name() const; - QString value() const; + QString initialValue() const; Increment increment() const; QString stepSize() const; + void resetValue(); + void incrementValueOnCopy(); + void incrementValueOnMerge(); + void incrementValueOnPage(); + QString value() const; static QString typeToI18nString( Type type ); static QString typeToIdString( Type type ); @@ -82,10 +88,15 @@ namespace glabels private: Type mType; QString mName; - QString mValue; + QString mInitialValue; Increment mIncrement; QString mStepSize; + long long mIntegerValue; + long long mIntegerStep; + double mFloatingPointValue; + double mFloatingPointStep; + }; } diff --git a/model/Variables.cpp b/model/Variables.cpp index 24d414f..9bf149f 100644 --- a/model/Variables.cpp +++ b/model/Variables.cpp @@ -85,6 +85,54 @@ namespace glabels } + /// + /// Reset variables to their initial values + /// + void Variables::resetVariables() + { + for ( auto& v : *this ) + { + v.resetValue(); + } + } + + + /// + /// Increment variables on copy + /// + void Variables::incrementVariablesOnCopy() + { + for ( auto& v : *this ) + { + v.incrementValueOnCopy(); + } + } + + + /// + /// Increment variables on merge record + /// + void Variables::incrementVariablesOnMerge() + { + for ( auto& v : *this ) + { + v.incrementValueOnMerge(); + } + } + + + /// + /// Increment variables on page + /// + void Variables::incrementVariablesOnPage() + { + for ( auto& v : *this ) + { + v.incrementValueOnPage(); + } + } + + } // namespace model } // namespace glabels diff --git a/model/Variables.h b/model/Variables.h index 0c1a020..ec7b578 100644 --- a/model/Variables.h +++ b/model/Variables.h @@ -63,6 +63,11 @@ namespace glabels void deleteVariable( const QString& name ); void replaceVariable( const QString& name, const Variable& variable ); + void resetVariables(); + void incrementVariablesOnCopy(); + void incrementVariablesOnMerge(); + void incrementVariablesOnPage(); + ///////////////////////////////// // Signals diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp index 2a31cf0..a546d14 100644 --- a/model/XmlLabelCreator.cpp +++ b/model/XmlLabelCreator.cpp @@ -495,7 +495,7 @@ namespace glabels XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) ); XmlUtil::setStringAttr( node, "name", v.name() ); - XmlUtil::setStringAttr( node, "value", v.value() ); + XmlUtil::setStringAttr( node, "initialValue", v.initialValue() ); XmlUtil::setStringAttr( node, "increment", Variable::incrementToIdString( v.increment() ) ); XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); } diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index 9412dd7..07fd543 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -747,14 +747,14 @@ namespace glabels { QString typeString = XmlUtil::getStringAttr( node, "type", "string" ); QString name = XmlUtil::getStringAttr( node, "name", "unknown" ); - QString value = XmlUtil::getStringAttr( node, "value", "0" ); + 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, value, increment, stepSize ); + Variable v( type, name, initialValue, increment, stepSize ); label->variables()->addVariable( v ); } diff --git a/model/unit_tests/TestSubstitutionField.cpp b/model/unit_tests/TestSubstitutionField.cpp index fa9135a..04476b6 100644 --- a/model/unit_tests/TestSubstitutionField.cpp +++ b/model/unit_tests/TestSubstitutionField.cpp @@ -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 } diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index fb84528..f7cdb4e 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -184,24 +184,24 @@ Dialog - - Variable Type: - - Name: - - Value: - - Increment: - Step Size: + Variable type: + + + + Initial value: + + + + Step size: @@ -1060,10 +1060,6 @@ Variable - - Numeric - - String @@ -1084,6 +1080,14 @@ Per page + + Integer + + + + Floating Point + + VariablesView @@ -2141,10 +2145,6 @@ Type - - Value - - Increment @@ -2153,6 +2153,10 @@ Step Size + + Initial Value + + glabels::barcode::Backends