[QGIS Commit] r14430 - in trunk/qgis: python/core src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Oct 23 05:50:23 EDT 2010
Author: mhugent
Date: 2010-10-23 02:50:23 -0700 (Sat, 23 Oct 2010)
New Revision: 14430
Modified:
trunk/qgis/python/core/qgsmaptopixel.sip
trunk/qgis/src/core/qgsmaptopixel.cpp
trunk/qgis/src/core/qgsmaptopixel.h
trunk/qgis/src/core/qgspallabeling.cpp
trunk/qgis/src/core/qgspallabeling.h
Log:
Add method to convert double precision device coordinates to map coords (important for print composer). Change pallabeling to use FontMetricsF and toMapCoordinatesF. Fixes bug #3065
Modified: trunk/qgis/python/core/qgsmaptopixel.sip
===================================================================
--- trunk/qgis/python/core/qgsmaptopixel.sip 2010-10-23 09:41:46 UTC (rev 14429)
+++ trunk/qgis/python/core/qgsmaptopixel.sip 2010-10-23 09:50:23 UTC (rev 14430)
@@ -53,6 +53,11 @@
// std::vector<double>& y);
QgsPoint toMapCoordinates(int x, int y);
+
+ /*! Transform device coordinates to map (world) coordinates
+ @note: this method was added in version 1.6*/
+ QgsPoint toMapCoordinatesF( double x, double y ) const;
+
/*! Tranform device coordinates to map (world) coordinates
* @param p Point to be converted to map cooordinates
* @return QgsPoint in map coorndiates
Modified: trunk/qgis/src/core/qgsmaptopixel.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaptopixel.cpp 2010-10-23 09:41:46 UTC (rev 14429)
+++ trunk/qgis/src/core/qgsmaptopixel.cpp 2010-10-23 09:50:23 UTC (rev 14430)
@@ -36,7 +36,7 @@
{
}
-QgsPoint QgsMapToPixel::toMapPoint( int x, int y ) const
+QgsPoint QgsMapToPixel::toMapPoint( double x, double y ) const
{
double mx = x * mMapUnitsPerPixel + xMin;
double my = -1 * (( y - yMax ) * mMapUnitsPerPixel - yMin );
@@ -54,6 +54,11 @@
return toMapPoint( x, y );
}
+QgsPoint QgsMapToPixel::toMapCoordinatesF( double x, double y ) const
+{
+ return toMapPoint( x, y );
+}
+
void QgsMapToPixel::setMapUnitsPerPixel( double mapUnitsPerPixel )
{
mMapUnitsPerPixel = mapUnitsPerPixel;
Modified: trunk/qgis/src/core/qgsmaptopixel.h
===================================================================
--- trunk/qgis/src/core/qgsmaptopixel.h 2010-10-23 09:41:46 UTC (rev 14429)
+++ trunk/qgis/src/core/qgsmaptopixel.h 2010-10-23 09:50:23 UTC (rev 14430)
@@ -75,13 +75,18 @@
std::vector<double>& y ) const;
QgsPoint toMapCoordinates( int x, int y ) const;
+
+ /*! Transform device coordinates to map (world) coordinates
+ @note: this method was added in version 1.6*/
+ QgsPoint toMapCoordinatesF( double x, double y ) const;
+
/*! Tranform device coordinates to map (world) coordinates
* @param p Point to be converted to map cooordinates
* @return QgsPoint in map coorndiates
*/
QgsPoint toMapCoordinates( QPoint p ) const;
- QgsPoint toMapPoint( int x, int y ) const;
+ QgsPoint toMapPoint( double x, double y ) const;
/*! Set map units per pixel
* @param mapUnitsPerPixel Map units per pixel
*/
Modified: trunk/qgis/src/core/qgspallabeling.cpp
===================================================================
--- trunk/qgis/src/core/qgspallabeling.cpp 2010-10-23 09:41:46 UTC (rev 14429)
+++ trunk/qgis/src/core/qgspallabeling.cpp 2010-10-23 09:50:23 UTC (rev 14430)
@@ -78,19 +78,19 @@
const char* strId() { return mStrId.data(); }
QString text() { return mText; }
- pal::LabelInfo* info( QFontMetrics* fm, const QgsMapToPixel* xform, double fontScale )
+ pal::LabelInfo* info( QFontMetricsF* fm, const QgsMapToPixel* xform, double fontScale )
{
if ( mInfo ) return mInfo;
// create label info!
QgsPoint ptZero = xform->toMapCoordinates( 0, 0 );
- QgsPoint ptSize = xform->toMapCoordinates( 0, ( int )( -fm->height() / fontScale ) );
+ QgsPoint ptSize = xform->toMapCoordinatesF( 0.0, -fm->height() / fontScale );
mInfo = new pal::LabelInfo( mText.count(), ptSize.y() - ptZero.y() );
for ( int i = 0; i < mText.count(); i++ )
{
mInfo->char_info[i].chr = mText[i].unicode();
- ptSize = xform->toMapCoordinates(( int )( fm->width( mText[i] ) / fontScale ) , 0 );
+ ptSize = xform->toMapCoordinatesF( fm->width( mText[i] ) / fontScale , 0.0 );
mInfo->char_info[i].width = ptSize.x() - ptZero.x();
}
return mInfo;
@@ -365,7 +365,7 @@
return true; //should never be reached. Return true in this case to label such geometries anyway.
}
-void QgsPalLayerSettings::calculateLabelSize( const QFontMetrics* fm, QString text, double& labelX, double& labelY )
+void QgsPalLayerSettings::calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY )
{
if ( !fm )
{
@@ -426,7 +426,7 @@
}
labelFont.setPixelSize( sizeToPixel( sizeDouble, context ) );
}
- QFontMetrics labelFontMetrics( labelFont );
+ QFontMetricsF labelFontMetrics( labelFont );
calculateLabelSize( &labelFontMetrics, labelText, labelX, labelY );
}
else
@@ -704,7 +704,7 @@
// save the pal layer to our layer context (with some additional info)
lyr.palLayer = l;
lyr.fieldIndex = fldIndex;
- lyr.fontMetrics = new QFontMetrics( lyr.textFont );
+ lyr.fontMetrics = new QFontMetricsF( lyr.textFont );
lyr.xform = mMapRenderer->coordinateTransform();
if ( mMapRenderer->hasCrsTransformEnabled() )
Modified: trunk/qgis/src/core/qgspallabeling.h
===================================================================
--- trunk/qgis/src/core/qgspallabeling.h 2010-10-23 09:41:46 UTC (rev 14429)
+++ trunk/qgis/src/core/qgspallabeling.h 2010-10-23 09:50:23 UTC (rev 14430)
@@ -21,6 +21,7 @@
#ifndef QGSPALLABELING_H
#define QGSPALLABELING_H
+class QFontMetricsF;
class QPainter;
class QgsMapRenderer;
class QgsRectangle;
@@ -115,7 +116,7 @@
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
// called from register feature hook
- void calculateLabelSize( const QFontMetrics* fm, QString text, double& labelX, double& labelY );
+ void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY );
// implementation of register feature hook
void registerFeature( QgsFeature& f, const QgsRenderContext& context );
@@ -131,7 +132,7 @@
// temporary stuff: set when layer gets prepared
pal::Layer* palLayer;
int fieldIndex;
- QFontMetrics* fontMetrics;
+ QFontMetricsF* fontMetrics;
const QgsMapToPixel* xform;
const QgsCoordinateTransform* ct;
QgsPoint ptZero, ptOne;
More information about the QGIS-commit
mailing list