mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Getter/setter for linking a map canvas with its QgsProject; link app canvases to QgsProject::instance(); rationale: using the QgsProject singleton is discouraged
This commit is contained in:
parent
45125979b2
commit
f3d473cb27
@ -337,6 +337,21 @@ You don't have to call it manually, QgsMapTool takes care of it.
|
||||
QgsMapTool *mapTool();
|
||||
%Docstring
|
||||
Returns the currently active tool
|
||||
%End
|
||||
|
||||
void setProject( QgsProject *project );
|
||||
%Docstring
|
||||
Sets the ``project`` linked to this canvas.
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
QgsProject *project();
|
||||
%Docstring
|
||||
Returns the project linked to this canvas.
|
||||
The returned value may be ``None``.
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
void setCanvasColor( const QColor &_newVal );
|
||||
|
@ -940,6 +940,9 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
|
||||
int myGreen = settings.value( QStringLiteral( "qgis/default_canvas_color_green" ), 255 ).toInt();
|
||||
int myBlue = settings.value( QStringLiteral( "qgis/default_canvas_color_blue" ), 255 ).toInt();
|
||||
mMapCanvas->setCanvasColor( QColor( myRed, myGreen, myBlue ) );
|
||||
|
||||
// set project linked to main canvas
|
||||
mMapCanvas->setProject( QgsProject::instance() );
|
||||
endProfile();
|
||||
|
||||
// what type of project to auto-open
|
||||
@ -4481,6 +4484,7 @@ QgsMapCanvasDockWidget *QgisApp::createNewMapCanvasDock( const QString &name )
|
||||
QgsMapCanvas *mapCanvas = mapCanvasWidget->mapCanvas();
|
||||
mapCanvas->freeze( true );
|
||||
mapCanvas->setObjectName( name );
|
||||
mapCanvas->setProject( QgsProject::instance() );
|
||||
connect( mapCanvas, &QgsMapCanvas::messageEmitted, this, &QgisApp::displayMessage );
|
||||
connect( mLayerTreeCanvasBridge, &QgsLayerTreeMapCanvasBridge::canvasLayersChanged, mapCanvas, &QgsMapCanvas::setLayers );
|
||||
|
||||
|
@ -2030,6 +2030,11 @@ void QgsMapCanvas::unsetMapTool( QgsMapTool *tool )
|
||||
}
|
||||
}
|
||||
|
||||
void QgsMapCanvas::setProject( QgsProject *project )
|
||||
{
|
||||
mProject = project;
|
||||
}
|
||||
|
||||
void QgsMapCanvas::setCanvasColor( const QColor &color )
|
||||
{
|
||||
if ( canvasColor() == color )
|
||||
@ -2247,6 +2252,11 @@ QgsMapTool *QgsMapCanvas::mapTool()
|
||||
return mMapTool;
|
||||
}
|
||||
|
||||
QgsProject *QgsMapCanvas::project()
|
||||
{
|
||||
return mProject;
|
||||
}
|
||||
|
||||
void QgsMapCanvas::panActionEnd( QPoint releasePoint )
|
||||
{
|
||||
// move map image and other items to standard position
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "qgscustomdrophandler.h"
|
||||
#include "qgstemporalrangeobject.h"
|
||||
#include "qgsmapcanvasinteractionblocker.h"
|
||||
#include "qgsproject.h"
|
||||
|
||||
#include <QDomDocument>
|
||||
#include <QGraphicsView>
|
||||
@ -355,6 +356,21 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
||||
//! Returns the currently active tool
|
||||
QgsMapTool *mapTool();
|
||||
|
||||
/**
|
||||
* Sets the \a project linked to this canvas.
|
||||
*
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
void setProject( QgsProject *project );
|
||||
|
||||
/**
|
||||
* Returns the project linked to this canvas.
|
||||
* The returned value may be NULLPTR.
|
||||
*
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
QgsProject *project();
|
||||
|
||||
//! Write property of QColor bgColor.
|
||||
void setCanvasColor( const QColor &_newVal );
|
||||
//! Read property of QColor bgColor.
|
||||
@ -1112,6 +1128,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
|
||||
//! previous tool if current is for zooming/panning
|
||||
QgsMapTool *mLastNonZoomMapTool = nullptr;
|
||||
|
||||
//! Pointer to project linked to this canvas
|
||||
QgsProject *mProject = nullptr;
|
||||
|
||||
//! Context menu
|
||||
QMenu *mMenu = nullptr;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user