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
This commit is contained in:
mhugent 2008-09-01 17:14:59 +00:00
parent 0ecb47fc31
commit d21134dc27
9 changed files with 32 additions and 11 deletions

View File

@ -1422,6 +1422,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerLabel( newLabel );
mComposition->addItem( newLabel );
mComposition->update();
mComposition->clearSelection();
newLabel->setSelected(true);
showItemOptions(newLabel);
}
//composer maps
@ -1434,6 +1437,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerMap( newMap );
mComposition->addItem( newMap );
mComposition->update();
mComposition->clearSelection();
newMap->setSelected(true);
showItemOptions(newMap);
}
//composer scalebars
@ -1446,6 +1452,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerScaleBar( newScaleBar );
mComposition->addItem( newScaleBar );
mComposition->update();
mComposition->clearSelection();
newScaleBar->setSelected(true);
showItemOptions(newScaleBar);
}
//composer legends
@ -1458,6 +1467,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerLegend( newLegend );
mComposition->addItem( newLegend );
mComposition->update();
mComposition->clearSelection();
newLegend->setSelected(true);
showItemOptions(newLegend);
}
//composer pictures
@ -1470,6 +1482,9 @@ void QgsComposer::readXML( const QDomDocument& doc )
addComposerPicture( newPicture );
mComposition->addItem( newPicture );
mComposition->update();
mComposition->clearSelection();
newPicture->setSelected(true);
showItemOptions(newPicture);
}
mComposition->sortZList();

View File

@ -64,7 +64,6 @@ void QgsComposerLabelWidget::on_mMarginDoubleSpinBox_valueChanged( double d )
if ( mComposerLabel )
{
mComposerLabel->setMargin( d );
mComposerLabel->adjustSizeToText();
mComposerLabel->update();
}
}

View File

@ -51,8 +51,8 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
//support multiline labels
double penWidth = pen().widthF();
QRectF painterRect( penWidth, penWidth, rect().width() - 2 * penWidth,
rect().height() - 2 * penWidth );
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin,
rect().height() - 2 * penWidth - 2 * mMargin);
painter->drawText( painterRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, mText );

View File

@ -226,5 +226,5 @@ bool QgsComposerPicture::readXML( const QDomElement& itemElem, const QDomDocumen
mRotation = itemElem.attribute( "rotation" ).toDouble();
return false; //soon...
return true;
}

View File

@ -268,7 +268,6 @@ QString QgsComposerScaleBar::firstLabelString() const
QFont QgsComposerScaleBar::font() const
{
#if 0 //needed by scale bar style, therefore don't convert back to points
if ( mComposition ) //make pixel to point conversion to show correct point value in dialogs
{
double pointSize = mComposition->pointFontSize( mFont.pixelSize() );
@ -276,7 +275,10 @@ QFont QgsComposerScaleBar::font() const
returnFont.setPointSize( pointSize );
return returnFont;
}
#endif //0
}
QFont QgsComposerScaleBar::fontPixelSize() const
{
return mFont;
}
@ -311,6 +313,7 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc )
composerScaleBarElem.setAttribute( "numSegments", mNumSegments );
composerScaleBarElem.setAttribute( "numSegmentsLeft", mNumSegmentsLeft );
composerScaleBarElem.setAttribute( "numUnitsPerSegment", mNumUnitsPerSegment );
composerScaleBarElem.setAttribute( "segmentMM", mSegmentMM );
composerScaleBarElem.setAttribute( "numMapUnitsPerScaleBarUnit", mNumMapUnitsPerScaleBarUnit );
composerScaleBarElem.setAttribute( "font", mFont.toString() );
composerScaleBarElem.setAttribute( "outlineWidth", mPen.widthF() );
@ -353,6 +356,7 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume
mNumSegments = itemElem.attribute( "numSegments", "2" ).toInt();
mNumSegmentsLeft = itemElem.attribute( "numSegmentsLeft", "0" ).toInt();
mNumUnitsPerSegment = itemElem.attribute( "numUnitsPerSegment", "1.0" ).toDouble();
mSegmentMM = itemElem.attribute("segmentMM", "0.0").toDouble();
mNumMapUnitsPerScaleBarUnit = itemElem.attribute( "numMapUnitsPerScaleBarUnit", "1.0" ).toDouble();
mPen.setWidthF( itemElem.attribute( "outlineWidth", "1.0" ).toDouble() );
mUnitLabeling = itemElem.attribute( "unitLabel" );

View File

@ -56,6 +56,10 @@ class CORE_EXPORT QgsComposerScaleBar: public QObject, public QgsComposerItem
void setUnitLabeling( const QString& label ) {mUnitLabeling = label;}
QFont font() const;
/**Returns font that has size set in pixels. Used from QgsComposerScaleBarStyle*/
QFont fontPixelSize() const;
void setFont( const QFont& font );
QPen pen() const {return mPen;}

View File

@ -139,7 +139,7 @@ int QgsComposition::pixelFontSize( double pointSize ) const
{
//in QgsComposition, one unit = one mm
double sizeMM = pointSize * 0.3527;
return sizeMM;
return (sizeMM + 0.5); //round to nearest mm
}
double QgsComposition::pointFontSize( int pixelSize ) const

View File

@ -43,9 +43,9 @@ void QgsScaleBarStyle::drawLabels( QPainter* p ) const
p->save();
p->setFont( mScaleBar->font() );
p->setFont( mScaleBar->fontPixelSize() );
QFontMetricsF fontMetrics( mScaleBar->font() );
QFontMetricsF fontMetrics( mScaleBar->fontPixelSize() );
QString firstLabel = mScaleBar->firstLabelString();
double xOffset = fontMetrics.width( firstLabel ) / 2;
@ -107,7 +107,7 @@ QRectF QgsScaleBarStyle::calculateBoxSize() const
}
QFontMetricsF fontMetrics( mScaleBar->font() );
QFontMetricsF fontMetrics( mScaleBar->fontPixelSize() );
//consider centered first label
double firstLabelLeft = fontMetrics.width( mScaleBar->firstLabelString() ) / 2;

View File

@ -86,7 +86,6 @@ void QgsComposerView::mousePressEvent( QMouseEvent* e )
t.translate( scenePoint.x(), scenePoint.y() );
mRubberBandItem->setTransform( t );
mRubberBandItem->setZValue( 100 );
scene()->addItem( mRubberBandItem );
scene()->update();
}