Compare commits

...

9 Commits

Author SHA1 Message Date
Till Frankenbach
a8a3fd8395
Merge 4c7ae43e466d89e8962d24241eaec484e90e62ca into 74549aad26c3358101e88477d9dfa1caae013d72 2025-07-01 11:18:12 +02:00
Till Frankenbach
4c7ae43e46 Fix mExtentWidget not defined in .h 2025-06-21 19:01:36 +02:00
Till Frankenbach
56e5fa40cc Add QgsExtentWidget programatically and set to expanded style 2025-06-21 17:22:11 +02:00
Till Frankenbach
4a01df3c39 Rename method setMainCanvasOpensAtProjectExtent to setRestoreProjectExtentOnProjectLoad for clarity 2025-06-21 16:50:12 +02:00
Till Frankenbach
6aa165ade6 Rename mLoadProjectExtent to mRestoreProjectExtentOnProjectLoad 2025-06-21 13:46:20 +02:00
Till Frankenbach
161de03c78 Fix typos
Co-authored-by: Mathieu Pellerin <nirvn.asia@gmail.com>
2025-06-21 13:46:20 +02:00
Till Frankenbach
58e6943ec4 Adapt UI description 2025-06-21 13:46:20 +02:00
Till Frankenbach
b484c77e35 Rename canvasUseProjectExtent methods to mainCanvasOpensAtProjectExtent for clarity 2025-06-21 13:46:19 +02:00
Till Frankenbach
df7ad50b17 Add option to load project extent when project is loaded 2025-06-21 13:46:19 +02:00
8 changed files with 107 additions and 28 deletions

View File

@ -95,6 +95,22 @@ should be calculated based on the layers in the project.
.. seealso:: :py:func:`fullExtent` .. seealso:: :py:func:`fullExtent`
.. versionadded:: 3.18 .. versionadded:: 3.18
%End
void setRestoreProjectExtentOnProjectLoad( bool state );
%Docstring
Sets whether the project's preset full extent should be restored when
the project is loaded.
.. versionadded:: 3.44
%End
bool mainCanvasOpensAtProjectExtent();
%Docstring
Returns whether the project's preset full extent should be restored when
the project is loaded.
.. versionadded:: 3.44
%End %End
QgsReferencedRectangle fullExtent() const; QgsReferencedRectangle fullExtent() const;

View File

@ -95,6 +95,22 @@ should be calculated based on the layers in the project.
.. seealso:: :py:func:`fullExtent` .. seealso:: :py:func:`fullExtent`
.. versionadded:: 3.18 .. versionadded:: 3.18
%End
void setRestoreProjectExtentOnProjectLoad( bool state );
%Docstring
Sets whether the project's preset full extent should be restored when
the project is loaded.
.. versionadded:: 3.44
%End
bool mainCanvasOpensAtProjectExtent();
%Docstring
Returns whether the project's preset full extent should be restored when
the project is loaded.
.. versionadded:: 3.44
%End %End
QgsReferencedRectangle fullExtent() const; QgsReferencedRectangle fullExtent() const;

View File

@ -98,8 +98,17 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
setupUi( this ); setupUi( this );
mExtentGroupBox->setTitleBase( tr( "Set Project Full Extent" ) ); mExtentGroupBox->setObjectName( "mExtentGroupBox" );
mExtentGroupBox->setMapCanvas( mapCanvas, false ); mExtentGroupBox->setCheckable( true );
mExtentWidget = new QgsExtentWidget( parent, QgsExtentWidget::ExpandedStyle );
QVBoxLayout *mExtentGroupBoxLayout = qobject_cast<QVBoxLayout *>( mExtentGroupBox->layout() );
mExtentGroupBoxLayout->insertWidget( 0, mExtentWidget );
mExtentWidget->setMapCanvas( mapCanvas, false );
mCheckBoxLoadProjectExtent->setObjectName( "mCheckBoxLoadProjectExtent" );
mAdvertisedExtentServer->setOutputCrs( QgsProject::instance()->crs() ); mAdvertisedExtentServer->setOutputCrs( QgsProject::instance()->crs() );
mAdvertisedExtentServer->setMapCanvas( mapCanvas, false ); mAdvertisedExtentServer->setMapCanvas( mapCanvas, false );
@ -476,12 +485,13 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
grpProjectScales->setChecked( QgsProject::instance()->viewSettings()->useProjectScales() ); grpProjectScales->setChecked( QgsProject::instance()->viewSettings()->useProjectScales() );
const QgsReferencedRectangle presetExtent = QgsProject::instance()->viewSettings()->presetFullExtent(); const QgsReferencedRectangle presetExtent = QgsProject::instance()->viewSettings()->presetFullExtent();
mExtentGroupBox->setOutputCrs( QgsProject::instance()->crs() ); mExtentWidget->setOutputCrs( QgsProject::instance()->crs() );
if ( presetExtent.isNull() ) if ( presetExtent.isNull() )
mExtentGroupBox->setOutputExtentFromUser( QgsProject::instance()->viewSettings()->fullExtent(), QgsProject::instance()->crs() ); mExtentWidget->setOutputExtentFromUser( QgsProject::instance()->viewSettings()->fullExtent(), QgsProject::instance()->crs() );
else else
mExtentGroupBox->setOutputExtentFromUser( presetExtent, presetExtent.crs() ); mExtentWidget->setOutputExtentFromUser( presetExtent, presetExtent.crs() );
mExtentGroupBox->setChecked( !presetExtent.isNull() ); mExtentGroupBox->setChecked( !presetExtent.isNull() );
mCheckBoxLoadProjectExtent->setChecked( QgsProject::instance()->viewSettings()->mainCanvasOpensAtProjectExtent() );
mLayerCapabilitiesModel = new QgsLayerCapabilitiesModel( QgsProject::instance(), this ); mLayerCapabilitiesModel = new QgsLayerCapabilitiesModel( QgsProject::instance(), this );
mLayerCapabilitiesModel->setLayerTreeModel( new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot(), mLayerCapabilitiesModel ) ); mLayerCapabilitiesModel->setLayerTreeModel( new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot(), mLayerCapabilitiesModel ) );
@ -1209,6 +1219,7 @@ void QgsProjectProperties::apply()
} }
} }
mMapCanvas->enableMapTileRendering( mMapTileRenderingCheckBox->isChecked() ); mMapCanvas->enableMapTileRendering( mMapTileRenderingCheckBox->isChecked() );
QgsProject::instance()->writeEntry( QStringLiteral( "RenderMapTile" ), QStringLiteral( "/" ), mMapTileRenderingCheckBox->isChecked() ); QgsProject::instance()->writeEntry( QStringLiteral( "RenderMapTile" ), QStringLiteral( "/" ), mMapTileRenderingCheckBox->isChecked() );
@ -1350,13 +1361,15 @@ void QgsProjectProperties::apply()
if ( mExtentGroupBox->isChecked() ) if ( mExtentGroupBox->isChecked() )
{ {
QgsProject::instance()->viewSettings()->setPresetFullExtent( QgsReferencedRectangle( mExtentGroupBox->outputExtent(), mExtentGroupBox->outputCrs() ) ); QgsProject::instance()->viewSettings()->setPresetFullExtent( QgsReferencedRectangle( mExtentWidget->outputExtent(), mExtentWidget->outputCrs() ) );
} }
else else
{ {
QgsProject::instance()->viewSettings()->setPresetFullExtent( QgsReferencedRectangle() ); QgsProject::instance()->viewSettings()->setPresetFullExtent( QgsReferencedRectangle() );
} }
QgsProject::instance()->viewSettings()->setRestoreProjectExtentOnProjectLoad( mCheckBoxLoadProjectExtent->isChecked() );
bool isDirty = false; bool isDirty = false;
const QMap<QString, QgsMapLayer *> &mapLayers = QgsProject::instance()->mapLayers(); const QMap<QString, QgsMapLayer *> &mapLayers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it ) for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
@ -2043,7 +2056,7 @@ void QgsProjectProperties::crsChanged( const QgsCoordinateReferenceSystem &crs )
cmbEllipsoid->setEnabled( false ); cmbEllipsoid->setEnabled( false );
} }
mExtentGroupBox->setOutputCrs( crs ); mExtentWidget->setOutputCrs( crs );
mAdvertisedExtentServer->setOutputCrs( crs ); mAdvertisedExtentServer->setOutputCrs( crs );
} }

View File

@ -250,6 +250,8 @@ class APP_EXPORT QgsProjectProperties : public QgsOptionsDialogBase, private Ui:
QDoubleSpinBox *mWMSDefaultMapUnitsPerMm = nullptr; QDoubleSpinBox *mWMSDefaultMapUnitsPerMm = nullptr;
QgsScaleWidget *mWMSDefaultMapUnitScale = nullptr; QgsScaleWidget *mWMSDefaultMapUnitScale = nullptr;
QgsExtentWidget *mExtentWidget;
QgsCoordinateReferenceSystem mCrs; QgsCoordinateReferenceSystem mCrs;

View File

@ -20,10 +20,13 @@
#include "qgsmaplayerutils.h" #include "qgsmaplayerutils.h"
#include "qgscoordinatetransform.h" #include "qgscoordinatetransform.h"
#include <QDomElement> #include <QDomElement>
#include "qgsmessagelog.h"
QgsProjectViewSettings::QgsProjectViewSettings( QgsProject *project ) QgsProjectViewSettings::QgsProjectViewSettings( QgsProject *project )
: QObject( project ) : QObject( project )
, mProject( project ) , mProject( project )
, mRestoreProjectExtentOnProjectLoad( false )
{ {
} }
@ -71,6 +74,17 @@ void QgsProjectViewSettings::setPresetFullExtent( const QgsReferencedRectangle &
emit presetFullExtentChanged(); emit presetFullExtentChanged();
} }
void QgsProjectViewSettings::setRestoreProjectExtentOnProjectLoad( bool projectExtentCheckboxState )
{
mRestoreProjectExtentOnProjectLoad = projectExtentCheckboxState;
}
bool QgsProjectViewSettings::mainCanvasOpensAtProjectExtent( )
{
return mRestoreProjectExtentOnProjectLoad;
}
QgsReferencedRectangle QgsProjectViewSettings::fullExtent() const QgsReferencedRectangle QgsProjectViewSettings::fullExtent() const
{ {
if ( !mProject ) if ( !mProject )
@ -198,6 +212,7 @@ bool QgsProjectViewSettings::readXml( const QDomElement &element, const QgsReadW
} }
mDefaultRotation = element.attribute( QStringLiteral( "rotation" ), QStringLiteral( "0" ) ).toDouble(); mDefaultRotation = element.attribute( QStringLiteral( "rotation" ), QStringLiteral( "0" ) ).toDouble();
mRestoreProjectExtentOnProjectLoad = element.attribute( QStringLiteral( "LoadProjectExtent" ), QStringLiteral( "0" ) ).toInt();
return true; return true;
} }
@ -207,6 +222,8 @@ QDomElement QgsProjectViewSettings::writeXml( QDomDocument &doc, const QgsReadWr
QDomElement element = doc.createElement( QStringLiteral( "ProjectViewSettings" ) ); QDomElement element = doc.createElement( QStringLiteral( "ProjectViewSettings" ) );
element.setAttribute( QStringLiteral( "UseProjectScales" ), mUseProjectScales ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); element.setAttribute( QStringLiteral( "UseProjectScales" ), mUseProjectScales ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
element.setAttribute( QStringLiteral( "LoadProjectExtent" ), mRestoreProjectExtentOnProjectLoad ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
element.setAttribute( QStringLiteral( "rotation" ), qgsDoubleToString( mDefaultRotation ) ); element.setAttribute( QStringLiteral( "rotation" ), qgsDoubleToString( mDefaultRotation ) );
QDomElement scales = doc.createElement( QStringLiteral( "Scales" ) ); QDomElement scales = doc.createElement( QStringLiteral( "Scales" ) );

View File

@ -104,6 +104,20 @@ class CORE_EXPORT QgsProjectViewSettings : public QObject
*/ */
void setPresetFullExtent( const QgsReferencedRectangle &extent ); void setPresetFullExtent( const QgsReferencedRectangle &extent );
/**
* Sets whether the project's preset full extent should be restored when the project is loaded.
*
* \since QGIS 3.44
*/
void setRestoreProjectExtentOnProjectLoad( bool state );
/**
* Returns whether the project's preset full extent should be restored when the project is loaded.
*
* \since QGIS 3.44
*/
bool mainCanvasOpensAtProjectExtent();
/** /**
* Returns the full extent of the project, which represents the maximal limits of the project. * Returns the full extent of the project, which represents the maximal limits of the project.
* *
@ -228,6 +242,7 @@ class CORE_EXPORT QgsProjectViewSettings : public QObject
bool mUseProjectScales = false; bool mUseProjectScales = false;
QgsReferencedRectangle mDefaultViewExtent; QgsReferencedRectangle mDefaultViewExtent;
QgsReferencedRectangle mPresetFullExtent; QgsReferencedRectangle mPresetFullExtent;
bool mRestoreProjectExtentOnProjectLoad;
double mDefaultRotation = 0; double mDefaultRotation = 0;
}; };

View File

@ -3271,7 +3271,14 @@ void QgsMapCanvas::readProject( const QDomDocument &doc )
// never manually set the crs for the main canvas - this is instead connected to the project CRS // never manually set the crs for the main canvas - this is instead connected to the project CRS
setDestinationCrs( tmpSettings.destinationCrs() ); setDestinationCrs( tmpSettings.destinationCrs() );
} }
setExtent( tmpSettings.extent() ); if ( QgsProject::instance()->viewSettings()->mainCanvasOpensAtProjectExtent() && objectName() == QLatin1String( "theMapCanvas" ) )
{
zoomToProjectExtent();
}
else
{
setExtent( tmpSettings.extent() );
}
setRotation( tmpSettings.rotation() ); setRotation( tmpSettings.rotation() );
enableMapTileRendering( tmpSettings.testFlag( Qgis::MapSettingsFlag::RenderMapTile ) ); enableMapTileRendering( tmpSettings.testFlag( Qgis::MapSettingsFlag::RenderMapTile ) );

View File

@ -1010,19 +1010,19 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QgsExtentGroupBox" name="mExtentGroupBox"> <widget class="QgsCollapsibleGroupBox" name="mExtentGroupBox">
<property name="toolTip">
<string>If checked the preset extent will be used as the full extent of the project. If unchecked, the project's full extent will be calculated using the full extent of all layers in the project.</string>
</property>
<property name="title"> <property name="title">
<string>Extent (current: none)</string> <string>Set Project Full Extent</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_30">
<item>
<widget class="QCheckBox" name="mCheckBoxLoadProjectExtent">
<property name="text">
<string>Use as extent for the main canvas when opening the project</string>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
@ -1132,8 +1132,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>528</width> <width>685</width>
<height>85</height> <height>791</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
@ -3601,12 +3601,6 @@
<extends>QDateTimeEdit</extends> <extends>QDateTimeEdit</extends>
<header>qgsdatetimeedit.h</header> <header>qgsdatetimeedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>QgsExtentGroupBox</class>
<extends>QgsCollapsibleGroupBox</extends>
<header>qgsextentgroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget> <customwidget>
<class>QgsFontButton</class> <class>QgsFontButton</class>
<extends>QToolButton</extends> <extends>QToolButton</extends>
@ -3699,7 +3693,6 @@
<tabstop>pbnRemoveScale</tabstop> <tabstop>pbnRemoveScale</tabstop>
<tabstop>pbnImportScales</tabstop> <tabstop>pbnImportScales</tabstop>
<tabstop>pbnExportScales</tabstop> <tabstop>pbnExportScales</tabstop>
<tabstop>mExtentGroupBox</tabstop>
<tabstop>scrollArea</tabstop> <tabstop>scrollArea</tabstop>
<tabstop>scrollArea_3</tabstop> <tabstop>scrollArea_3</tabstop>
<tabstop>mShowDatumTransformDialogCheckBox</tabstop> <tabstop>mShowDatumTransformDialogCheckBox</tabstop>