Correctly handle invalid barcode data cases in label editor.
This commit is contained in:
@@ -348,64 +348,33 @@ 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");
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->setPen( Qt::NoPen );
|
|
||||||
painter->setBrush( QBrush( emptyFillColor ) );
|
|
||||||
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
|
||||||
|
|
||||||
QFont font( "Sans" );
|
|
||||||
font.setPointSizeF( 6 );
|
|
||||||
|
|
||||||
QFontMetricsF fm(font);
|
|
||||||
QRectF textRect = fm.boundingRect( text );
|
|
||||||
|
|
||||||
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 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->setFont( font );
|
|
||||||
painter->setPen( QPen( color ) );
|
|
||||||
painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ),
|
|
||||||
Qt::AlignCenter,
|
|
||||||
text );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Draw text in final printout or preview
|
/// Draw barcode in final printout or preview
|
||||||
///
|
///
|
||||||
void
|
void
|
||||||
LabelModelBarcodeObject::drawBc( QPainter* painter,
|
LabelModelBarcodeObject::drawBc( QPainter* painter,
|
||||||
@@ -424,4 +393,40 @@ namespace glabels
|
|||||||
bc->render( renderer );
|
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->setBrush( QBrush( emptyFillColor ) );
|
||||||
|
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
|
||||||
|
|
||||||
|
QFont font( "Sans" );
|
||||||
|
font.setPointSizeF( 6 );
|
||||||
|
|
||||||
|
QFontMetricsF fm(font);
|
||||||
|
QRectF textRect = fm.boundingRect( text );
|
||||||
|
|
||||||
|
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 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->setFont( font );
|
||||||
|
painter->setPen( QPen( color ) );
|
||||||
|
painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ),
|
||||||
|
Qt::AlignCenter,
|
||||||
|
text );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // 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