Skip to content

Commit d21134d

Browse files
author
mhugent
committed
Fix for some font size problems and for loading composer scalebar from xml
git-svn-id: http://svn.osgeo.org/qgis/trunk@9237 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0ecb47f commit d21134d

9 files changed

+32
-11
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
14221422
addComposerLabel( newLabel );
14231423
mComposition->addItem( newLabel );
14241424
mComposition->update();
1425+
mComposition->clearSelection();
1426+
newLabel->setSelected(true);
1427+
showItemOptions(newLabel);
14251428
}
14261429

14271430
//composer maps
@@ -1434,6 +1437,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
14341437
addComposerMap( newMap );
14351438
mComposition->addItem( newMap );
14361439
mComposition->update();
1440+
mComposition->clearSelection();
1441+
newMap->setSelected(true);
1442+
showItemOptions(newMap);
14371443
}
14381444

14391445
//composer scalebars
@@ -1446,6 +1452,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
14461452
addComposerScaleBar( newScaleBar );
14471453
mComposition->addItem( newScaleBar );
14481454
mComposition->update();
1455+
mComposition->clearSelection();
1456+
newScaleBar->setSelected(true);
1457+
showItemOptions(newScaleBar);
14491458
}
14501459

14511460
//composer legends
@@ -1458,6 +1467,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
14581467
addComposerLegend( newLegend );
14591468
mComposition->addItem( newLegend );
14601469
mComposition->update();
1470+
mComposition->clearSelection();
1471+
newLegend->setSelected(true);
1472+
showItemOptions(newLegend);
14611473
}
14621474

14631475
//composer pictures
@@ -1470,6 +1482,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
14701482
addComposerPicture( newPicture );
14711483
mComposition->addItem( newPicture );
14721484
mComposition->update();
1485+
mComposition->clearSelection();
1486+
newPicture->setSelected(true);
1487+
showItemOptions(newPicture);
14731488
}
14741489

14751490
mComposition->sortZList();

src/app/composer/qgscomposerlabelwidget.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void QgsComposerLabelWidget::on_mMarginDoubleSpinBox_valueChanged( double d )
6464
if ( mComposerLabel )
6565
{
6666
mComposerLabel->setMargin( d );
67-
mComposerLabel->adjustSizeToText();
6867
mComposerLabel->update();
6968
}
7069
}

src/core/composer/qgscomposerlabel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
5151

5252
//support multiline labels
5353
double penWidth = pen().widthF();
54-
QRectF painterRect( penWidth, penWidth, rect().width() - 2 * penWidth,
55-
rect().height() - 2 * penWidth );
54+
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin,
55+
rect().height() - 2 * penWidth - 2 * mMargin);
5656
painter->drawText( painterRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, mText );
5757

5858

src/core/composer/qgscomposerpicture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,5 @@ bool QgsComposerPicture::readXML( const QDomElement& itemElem, const QDomDocumen
226226

227227
mRotation = itemElem.attribute( "rotation" ).toDouble();
228228

229-
return false; //soon...
229+
return true;
230230
}

src/core/composer/qgscomposerscalebar.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,17 @@ QString QgsComposerScaleBar::firstLabelString() const
268268

269269
QFont QgsComposerScaleBar::font() const
270270
{
271-
#if 0 //needed by scale bar style, therefore don't convert back to points
272271
if ( mComposition ) //make pixel to point conversion to show correct point value in dialogs
273272
{
274273
double pointSize = mComposition->pointFontSize( mFont.pixelSize() );
275274
QFont returnFont = mFont;
276275
returnFont.setPointSize( pointSize );
277276
return returnFont;
278277
}
279-
#endif //0
278+
}
279+
280+
QFont QgsComposerScaleBar::fontPixelSize() const
281+
{
280282
return mFont;
281283
}
282284

@@ -311,6 +313,7 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc )
311313
composerScaleBarElem.setAttribute( "numSegments", mNumSegments );
312314
composerScaleBarElem.setAttribute( "numSegmentsLeft", mNumSegmentsLeft );
313315
composerScaleBarElem.setAttribute( "numUnitsPerSegment", mNumUnitsPerSegment );
316+
composerScaleBarElem.setAttribute( "segmentMM", mSegmentMM );
314317
composerScaleBarElem.setAttribute( "numMapUnitsPerScaleBarUnit", mNumMapUnitsPerScaleBarUnit );
315318
composerScaleBarElem.setAttribute( "font", mFont.toString() );
316319
composerScaleBarElem.setAttribute( "outlineWidth", mPen.widthF() );
@@ -353,6 +356,7 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume
353356
mNumSegments = itemElem.attribute( "numSegments", "2" ).toInt();
354357
mNumSegmentsLeft = itemElem.attribute( "numSegmentsLeft", "0" ).toInt();
355358
mNumUnitsPerSegment = itemElem.attribute( "numUnitsPerSegment", "1.0" ).toDouble();
359+
mSegmentMM = itemElem.attribute("segmentMM", "0.0").toDouble();
356360
mNumMapUnitsPerScaleBarUnit = itemElem.attribute( "numMapUnitsPerScaleBarUnit", "1.0" ).toDouble();
357361
mPen.setWidthF( itemElem.attribute( "outlineWidth", "1.0" ).toDouble() );
358362
mUnitLabeling = itemElem.attribute( "unitLabel" );

src/core/composer/qgscomposerscalebar.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class CORE_EXPORT QgsComposerScaleBar: public QObject, public QgsComposerItem
5656
void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
5757

5858
QFont font() const;
59+
60+
/**Returns font that has size set in pixels. Used from QgsComposerScaleBarStyle*/
61+
QFont fontPixelSize() const;
62+
5963
void setFont( const QFont& font );
6064

6165
QPen pen() const {return mPen;}

src/core/composer/qgscomposition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int QgsComposition::pixelFontSize( double pointSize ) const
139139
{
140140
//in QgsComposition, one unit = one mm
141141
double sizeMM = pointSize * 0.3527;
142-
return sizeMM;
142+
return (sizeMM + 0.5); //round to nearest mm
143143
}
144144

145145
double QgsComposition::pointFontSize( int pixelSize ) const

src/core/composer/qgsscalebarstyle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void QgsScaleBarStyle::drawLabels( QPainter* p ) const
4343

4444
p->save();
4545

46-
p->setFont( mScaleBar->font() );
46+
p->setFont( mScaleBar->fontPixelSize() );
4747

48-
QFontMetricsF fontMetrics( mScaleBar->font() );
48+
QFontMetricsF fontMetrics( mScaleBar->fontPixelSize() );
4949
QString firstLabel = mScaleBar->firstLabelString();
5050
double xOffset = fontMetrics.width( firstLabel ) / 2;
5151

@@ -107,7 +107,7 @@ QRectF QgsScaleBarStyle::calculateBoxSize() const
107107
}
108108

109109

110-
QFontMetricsF fontMetrics( mScaleBar->font() );
110+
QFontMetricsF fontMetrics( mScaleBar->fontPixelSize() );
111111

112112
//consider centered first label
113113
double firstLabelLeft = fontMetrics.width( mScaleBar->firstLabelString() ) / 2;

src/gui/qgscomposerview.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
8686
t.translate( scenePoint.x(), scenePoint.y() );
8787
mRubberBandItem->setTransform( t );
8888
mRubberBandItem->setZValue( 100 );
89-
9089
scene()->addItem( mRubberBandItem );
9190
scene()->update();
9291
}

0 commit comments

Comments
 (0)