Correctly handle invalid barcode data cases in label editor.
This commit is contained in:
@@ -348,34 +348,60 @@ namespace glabels
|
|||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Draw text in editor from cached information
|
/// Draw barcode in editor from cached information
|
||||||
///
|
///
|
||||||
void LabelModelBarcodeObject::drawBcInEditor( QPainter* painter, const QColor& color ) const
|
void LabelModelBarcodeObject::drawBcInEditor( QPainter* painter, const QColor& color ) const
|
||||||
{
|
{
|
||||||
painter->setPen( QPen( color ) );
|
if ( mBcData.isEmpty() )
|
||||||
|
|
||||||
if ( mEditorBarcode->isDataValid() )
|
|
||||||
{
|
{
|
||||||
|
drawPlaceHolder( painter, color, tr("No barcode data") );
|
||||||
|
}
|
||||||
|
else if ( mBcData.hasPlaceHolders() )
|
||||||
|
{
|
||||||
|
drawPlaceHolder( painter, color, mBcData.toString() );
|
||||||
|
}
|
||||||
|
else if ( mEditorBarcode->isDataValid() )
|
||||||
|
{
|
||||||
|
painter->setPen( QPen( color ) );
|
||||||
glbarcode::QtRenderer renderer(painter);
|
glbarcode::QtRenderer renderer(painter);
|
||||||
mEditorBarcode->render( renderer );
|
mEditorBarcode->render( renderer );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString text;
|
drawPlaceHolder( painter, color, tr("Invalid barcode data") );
|
||||||
|
|
||||||
if ( mBcData.isEmpty() )
|
|
||||||
{
|
|
||||||
text = tr("No barcode data");
|
|
||||||
}
|
}
|
||||||
else if ( mBcData.hasPlaceHolders() )
|
|
||||||
{
|
|
||||||
text = mBcData.toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
text = tr("Invalid barcode data");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Draw barcode in final printout or preview
|
||||||
|
///
|
||||||
|
void
|
||||||
|
LabelModelBarcodeObject::drawBc( QPainter* painter,
|
||||||
|
const QColor& color,
|
||||||
|
merge::Record* record ) const
|
||||||
|
{
|
||||||
|
painter->setPen( QPen( color ) );
|
||||||
|
|
||||||
|
glbarcode::Barcode* bc = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
||||||
|
bc->setChecksum(mBcChecksumFlag);
|
||||||
|
bc->setShowText(mBcTextFlag);
|
||||||
|
|
||||||
|
bc->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
||||||
|
|
||||||
|
glbarcode::QtRenderer renderer(painter);
|
||||||
|
bc->render( renderer );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Draw place holder in editor
|
||||||
|
///
|
||||||
|
void
|
||||||
|
LabelModelBarcodeObject::drawPlaceHolder( QPainter* painter,
|
||||||
|
const QColor& color,
|
||||||
|
const QString& text ) const
|
||||||
|
{
|
||||||
painter->setPen( Qt::NoPen );
|
painter->setPen( Qt::NoPen );
|
||||||
painter->setBrush( QBrush( emptyFillColor ) );
|
painter->setBrush( QBrush( emptyFillColor ) );
|
||||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||||
@@ -401,27 +427,6 @@ namespace glabels
|
|||||||
Qt::AlignCenter,
|
Qt::AlignCenter,
|
||||||
text );
|
text );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Draw text in final printout or preview
|
|
||||||
///
|
|
||||||
void
|
|
||||||
LabelModelBarcodeObject::drawBc( QPainter* painter,
|
|
||||||
const QColor& color,
|
|
||||||
merge::Record* record ) const
|
|
||||||
{
|
|
||||||
painter->setPen( QPen( color ) );
|
|
||||||
|
|
||||||
glbarcode::Barcode* bc = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
|
|
||||||
bc->setChecksum(mBcChecksumFlag);
|
|
||||||
bc->setShowText(mBcTextFlag);
|
|
||||||
|
|
||||||
bc->build( mBcData.toStdString(), mW.pt(), mH.pt() );
|
|
||||||
|
|
||||||
glbarcode::QtRenderer renderer(painter);
|
|
||||||
bc->render( renderer );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace glabels
|
} // namespace glabels
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ namespace glabels
|
|||||||
|
|
||||||
void drawBcInEditor( QPainter* painter, const QColor& color ) const;
|
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 ) const;
|
||||||
|
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1115,12 +1115,12 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>glabels::LabelModelBarcodeObject</name>
|
<name>glabels::LabelModelBarcodeObject</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="368"/>
|
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="357"/>
|
||||||
<source>No barcode data</source>
|
<source>No barcode data</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="376"/>
|
<location filename="../glabels/LabelModelBarcodeObject.cpp" line="371"/>
|
||||||
<source>Invalid barcode data</source>
|
<source>Invalid barcode data</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
|||||||
Reference in New Issue
Block a user