mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Port elevation canvas away from QDesktopWidget
This commit is contained in:
parent
56f05b0943
commit
c306fa0a21
@ -9,6 +9,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
class QgsCompoundColorWidget : QgsPanelWidget
|
||||
{
|
||||
%Docstring(signature="appended")
|
||||
|
@ -42,6 +42,13 @@ Returns the window handle for the window the parent widget is associated with, o
|
||||
Returns the current screen DPI for the screen that the parent widget appears on.
|
||||
|
||||
.. seealso:: :py:func:`screenDpiChanged`
|
||||
%End
|
||||
|
||||
double logicalDpi() const;
|
||||
%Docstring
|
||||
Returns the current logical DPI for the screen that the parent widget appears on.
|
||||
|
||||
.. seealso:: :py:func:`logicalDpiChanged`
|
||||
%End
|
||||
|
||||
QRect availableGeometry() const;
|
||||
@ -60,6 +67,13 @@ The available geometry is the geometry excluding window manager reserved areas s
|
||||
Emitted whenever the screen ``dpi`` associated with the widget is changed.
|
||||
|
||||
.. seealso:: :py:func:`screenDpi`
|
||||
%End
|
||||
|
||||
void logicalDpiChanged( double dpi );
|
||||
%Docstring
|
||||
Emitted whenever the logical ``dpi`` associated with the widget is changed.
|
||||
|
||||
.. seealso:: :py:func:`logicalDpi`
|
||||
%End
|
||||
|
||||
void availableGeometryChanged( const QRect &geometry );
|
||||
|
@ -35,10 +35,10 @@
|
||||
#include "qgsprofilesnapping.h"
|
||||
#include "qgsmaplayerelevationproperties.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsscreenhelper.h"
|
||||
|
||||
#include <QWheelEvent>
|
||||
#include <QTimer>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
///@cond PRIVATE
|
||||
class QgsElevationProfilePlotItem : public Qgs2DPlot, public QgsPlotCanvasItem
|
||||
@ -323,6 +323,8 @@ class QgsElevationProfileCrossHairsItem : public QgsPlotCanvasItem
|
||||
QgsElevationProfileCanvas::QgsElevationProfileCanvas( QWidget *parent )
|
||||
: QgsPlotCanvas( parent )
|
||||
{
|
||||
mScreenHelper = new QgsScreenHelper( this );
|
||||
|
||||
mPlotItem = new QgsElevationProfilePlotItem( this );
|
||||
mCrossHairsItem = new QgsElevationProfileCrossHairsItem( this, mPlotItem );
|
||||
mCrossHairsItem->setZValue( 100 );
|
||||
@ -681,7 +683,7 @@ void QgsElevationProfileCanvas::refresh()
|
||||
connect( mCurrentJob, &QgsProfilePlotRenderer::generationFinished, this, &QgsElevationProfileCanvas::generationFinished );
|
||||
|
||||
QgsProfileGenerationContext generationContext;
|
||||
generationContext.setDpi( QgsApplication::desktop()->logicalDpiX() );
|
||||
generationContext.setDpi( mScreenHelper->logicalDpi() );
|
||||
generationContext.setMaximumErrorMapUnits( MAX_ERROR_PIXELS * ( mProfileCurve->length() ) / mPlotItem->plotArea().width() );
|
||||
generationContext.setMapUnitsPerDistancePixel( mProfileCurve->length() / mPlotItem->plotArea().width() );
|
||||
mCurrentJob->setContext( generationContext );
|
||||
@ -824,7 +826,7 @@ void QgsElevationProfileCanvas::refineResults()
|
||||
if ( mCurrentJob )
|
||||
{
|
||||
QgsProfileGenerationContext context;
|
||||
context.setDpi( QgsApplication::desktop()->logicalDpiX() );
|
||||
context.setDpi( mScreenHelper->logicalDpi() );
|
||||
const double plotDistanceRange = mPlotItem->xMaximum() - mPlotItem->xMinimum();
|
||||
const double plotElevationRange = mPlotItem->yMaximum() - mPlotItem->yMinimum();
|
||||
const double plotDistanceUnitsPerPixel = plotDistanceRange / mPlotItem->plotArea().width();
|
||||
|
@ -35,6 +35,7 @@ class Qgs2DPlot;
|
||||
class QgsProfileSnapContext;
|
||||
class QgsProfileIdentifyContext;
|
||||
class QgsProfileIdentifyResults;
|
||||
class QgsScreenHelper;
|
||||
|
||||
/**
|
||||
* \ingroup gui
|
||||
@ -273,6 +274,8 @@ class GUI_EXPORT QgsElevationProfileCanvas : public QgsPlotCanvas
|
||||
|
||||
void setupLayerConnections( QgsMapLayer *layer, bool isDisconnect );
|
||||
|
||||
QgsScreenHelper *mScreenHelper = nullptr;
|
||||
|
||||
QgsCoordinateReferenceSystem mCrs;
|
||||
QgsProject *mProject = nullptr;
|
||||
|
||||
|
@ -55,6 +55,7 @@ bool QgsScreenHelper::eventFilter( QObject *watched, QEvent *event )
|
||||
case QEvent::Show:
|
||||
{
|
||||
updateDevicePixelFromScreen();
|
||||
updateLogicalDpiFromScreen();
|
||||
updateAvailableGeometryFromScreen();
|
||||
|
||||
// keep device pixel ratio up to date on screen or resolution change
|
||||
@ -63,6 +64,7 @@ bool QgsScreenHelper::eventFilter( QObject *watched, QEvent *event )
|
||||
connect( handle, &QWindow::screenChanged, this, [ = ]( QScreen * )
|
||||
{
|
||||
disconnect( mScreenDpiChangedConnection );
|
||||
disconnect( mLogicalDpiChangedConnection );
|
||||
disconnect( mAvailableGeometryChangedConnection );
|
||||
|
||||
if ( QWindow *windowHandleInLambda = windowHandle() )
|
||||
@ -70,12 +72,16 @@ bool QgsScreenHelper::eventFilter( QObject *watched, QEvent *event )
|
||||
mScreenDpiChangedConnection = connect( windowHandleInLambda->screen(), &QScreen::physicalDotsPerInchChanged, this, &QgsScreenHelper::updateDevicePixelFromScreen );
|
||||
updateDevicePixelFromScreen();
|
||||
|
||||
mLogicalDpiChangedConnection = connect( windowHandleInLambda->screen(), &QScreen::logicalDotsPerInchChanged, this, &QgsScreenHelper::updateLogicalDpiFromScreen );
|
||||
updateLogicalDpiFromScreen();
|
||||
|
||||
mAvailableGeometryChangedConnection = connect( windowHandleInLambda->screen(), &QScreen::availableGeometryChanged, this, &QgsScreenHelper::updateAvailableGeometryFromScreen );
|
||||
updateAvailableGeometryFromScreen();
|
||||
}
|
||||
} );
|
||||
|
||||
mScreenDpiChangedConnection = connect( handle->screen(), &QScreen::physicalDotsPerInchChanged, this, &QgsScreenHelper::updateDevicePixelFromScreen );
|
||||
mLogicalDpiChangedConnection = connect( handle->screen(), &QScreen::logicalDotsPerInchChanged, this, &QgsScreenHelper::updateLogicalDpiFromScreen );
|
||||
mAvailableGeometryChangedConnection = connect( handle->screen(), &QScreen::availableGeometryChanged, this, &QgsScreenHelper::updateAvailableGeometryFromScreen );
|
||||
}
|
||||
}
|
||||
@ -100,6 +106,19 @@ void QgsScreenHelper::updateDevicePixelFromScreen()
|
||||
}
|
||||
}
|
||||
|
||||
void QgsScreenHelper::updateLogicalDpiFromScreen()
|
||||
{
|
||||
if ( QScreen *screen = QgsScreenHelper::screen() )
|
||||
{
|
||||
const double newDpi = screen->logicalDotsPerInch();
|
||||
if ( !qgsDoubleNear( newDpi, mLogicalDpi ) )
|
||||
{
|
||||
mLogicalDpi = newDpi;
|
||||
emit logicalDpiChanged( mLogicalDpi );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsScreenHelper::updateAvailableGeometryFromScreen()
|
||||
{
|
||||
if ( QScreen *screen = QgsScreenHelper::screen() )
|
||||
|
@ -60,6 +60,13 @@ class GUI_EXPORT QgsScreenHelper : public QObject
|
||||
*/
|
||||
double screenDpi() const { return mScreenDpi; }
|
||||
|
||||
/**
|
||||
* Returns the current logical DPI for the screen that the parent widget appears on.
|
||||
*
|
||||
* \see logicalDpiChanged()
|
||||
*/
|
||||
double logicalDpi() const { return mLogicalDpi; }
|
||||
|
||||
/**
|
||||
* Returns the current screen available geometry in pixels.
|
||||
*
|
||||
@ -78,6 +85,13 @@ class GUI_EXPORT QgsScreenHelper : public QObject
|
||||
*/
|
||||
void screenDpiChanged( double dpi );
|
||||
|
||||
/**
|
||||
* Emitted whenever the logical \a dpi associated with the widget is changed.
|
||||
*
|
||||
* \see logicalDpi()
|
||||
*/
|
||||
void logicalDpiChanged( double dpi );
|
||||
|
||||
/**
|
||||
* Emitted whenever the available geometry of the screen associated with the widget is changed.
|
||||
*
|
||||
@ -91,6 +105,7 @@ class GUI_EXPORT QgsScreenHelper : public QObject
|
||||
private slots:
|
||||
|
||||
void updateDevicePixelFromScreen();
|
||||
void updateLogicalDpiFromScreen();
|
||||
void updateAvailableGeometryFromScreen();
|
||||
|
||||
private:
|
||||
@ -100,6 +115,9 @@ class GUI_EXPORT QgsScreenHelper : public QObject
|
||||
double mScreenDpi = 96.0;
|
||||
QMetaObject::Connection mScreenDpiChangedConnection;
|
||||
|
||||
double mLogicalDpi = 96.0;
|
||||
QMetaObject::Connection mLogicalDpiChangedConnection;
|
||||
|
||||
QRect mAvailableGeometry;
|
||||
QMetaObject::Connection mAvailableGeometryChangedConnection;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user