Merge pull request #8406 from 3nids/fix20321

fix device size in decoration item
This commit is contained in:
Denis Rouzaud 2018-11-03 11:01:26 -08:00 committed by GitHub
commit 15b2352ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 49 additions and 28 deletions

View File

@ -27,17 +27,6 @@ SET(QGIS_APP_SRCS
qgscustomization.cpp
qgscustomprojectiondialog.cpp
qgsdatumtransformtablewidget.cpp
qgsdecorationitem.cpp
qgsdecorationcopyright.cpp
qgsdecorationcopyrightdialog.cpp
qgsdecorationlayoutextent.cpp
qgsdecorationlayoutextentdialog.cpp
qgsdecorationnortharrow.cpp
qgsdecorationnortharrowdialog.cpp
qgsdecorationscalebar.cpp
qgsdecorationscalebardialog.cpp
qgsdecorationgrid.cpp
qgsdecorationgriddialog.cpp
qgsdiscoverrelationsdlg.cpp
qgsdxfexportdialog.cpp
qgsformannotationdialog.cpp
@ -119,6 +108,18 @@ SET(QGIS_APP_SRCS
qgsmaptoolsvgannotation.cpp
qgsmaptooltextannotation.cpp
decorations/qgsdecorationitem.cpp
decorations/qgsdecorationcopyright.cpp
decorations/qgsdecorationcopyrightdialog.cpp
decorations/qgsdecorationlayoutextent.cpp
decorations/qgsdecorationlayoutextentdialog.cpp
decorations/qgsdecorationnortharrow.cpp
decorations/qgsdecorationnortharrowdialog.cpp
decorations/qgsdecorationscalebar.cpp
decorations/qgsdecorationscalebardialog.cpp
decorations/qgsdecorationgrid.cpp
decorations/qgsdecorationgriddialog.cpp
vertextool/qgsselectedfeature.cpp
vertextool/qgsvertexentry.cpp
vertextool/qgsvertexeditor.cpp
@ -258,17 +259,6 @@ SET (QGIS_APP_MOC_HDRS
qgscustomization.h
qgscustomprojectiondialog.h
qgsdatumtransformtablewidget.h
qgsdecorationitem.h
qgsdecorationcopyright.h
qgsdecorationcopyrightdialog.h
qgsdecorationlayoutextent.h
qgsdecorationlayoutextentdialog.h
qgsdecorationnortharrow.h
qgsdecorationnortharrowdialog.h
qgsdecorationscalebar.h
qgsdecorationscalebardialog.h
qgsdecorationgrid.h
qgsdecorationgriddialog.h
qgsdelattrdialog.h
qgsdiagramproperties.h
qgsdiscoverrelationsdlg.h
@ -370,6 +360,18 @@ SET (QGIS_APP_MOC_HDRS
qgsmaptoolregularpolygoncenterpoint.h
qgsmaptoolregularpolygoncentercorner.h
decorations/qgsdecorationitem.h
decorations/qgsdecorationcopyright.h
decorations/qgsdecorationcopyrightdialog.h
decorations/qgsdecorationlayoutextent.h
decorations/qgsdecorationlayoutextentdialog.h
decorations/qgsdecorationnortharrow.h
decorations/qgsdecorationnortharrowdialog.h
decorations/qgsdecorationscalebar.h
decorations/qgsdecorationscalebardialog.h
decorations/qgsdecorationgrid.h
decorations/qgsdecorationgriddialog.h
vertextool/qgsselectedfeature.h
vertextool/qgsvertexeditor.h
vertextool/qgsvertextool.h
@ -632,6 +634,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/external/nmea
${CMAKE_SOURCE_DIR}/src/app
${CMAKE_SOURCE_DIR}/src/app/decorations
${CMAKE_SOURCE_DIR}/src/app/layout
${CMAKE_SOURCE_DIR}/src/app/pluginmanager
${CMAKE_SOURCE_DIR}/src/app/gps

View File

@ -124,8 +124,14 @@ void QgsDecorationCopyright::render( const QgsMapSettings &mapSettings, QgsRende
double textWidth = QgsTextRenderer::textWidth( context, mTextFormat, displayStringList, &fm );
double textHeight = QgsTextRenderer::textHeight( context, mTextFormat, displayStringList, QgsTextRenderer::Point, &fm );
int deviceHeight = context.painter()->device()->height();
int deviceWidth = context.painter()->device()->width();
QPaintDevice *device = context.painter()->device();
#if QT_VERSION < 0x050600
int deviceHeight = device->height() / device->devicePixelRatio();
int deviceWidth = device->width() / device->devicePixelRatio();
#else
int deviceHeight = device->height() / device->devicePixelRatioF();
int deviceWidth = device->width() / device->devicePixelRatioF();
#endif
float xOffset( 0 ), yOffset( 0 );

View File

@ -168,8 +168,14 @@ void QgsDecorationNorthArrow::render( const QgsMapSettings &mapSettings, QgsRend
( centerYDouble * std::cos( radiansDouble ) )
) - centerYDouble );
// need width/height of paint device
int deviceHeight = context.painter()->device()->height();
int deviceWidth = context.painter()->device()->width();
QPaintDevice *device = context.painter()->device();
#if QT_VERSION < 0x050600
int deviceHeight = device->height() / device->devicePixelRatio();
int deviceWidth = device->width() / device->devicePixelRatio();
#else
int deviceHeight = device->height() / device->devicePixelRatioF();
int deviceWidth = device->width() / device->devicePixelRatioF();
#endif
// Set margin according to selected units
int xOffset = 0;

View File

@ -177,8 +177,14 @@ void QgsDecorationScaleBar::render( const QgsMapSettings &mapSettings, QgsRender
return;
//Get canvas dimensions
int deviceHeight = context.painter()->device()->height();
int deviceWidth = context.painter()->device()->width();
QPaintDevice *device = context.painter()->device();
#if QT_VERSION < 0x050600
int deviceHeight = device->height() / device->devicePixelRatio();
int deviceWidth = device->width() / device->devicePixelRatio();
#else
int deviceHeight = device->height() / device->devicePixelRatioF();
int deviceWidth = device->width() / device->devicePixelRatioF();
#endif
//Get map units per pixel. This can be negative at times (to do with
//projections) and that just confuses the rest of the code in this