Skip to content

Commit

Permalink
[FEATURE] Add new "View Settings" tab to project properties,
Browse files Browse the repository at this point in the history
and add option to manually set the full extent for a project

This extent will be used instead of the extent of all layers
when zooming to full map extent. It's useful when a project contains
web layers/national layers/global layers yet the actual area of
interest for the project is a smaller geographic area
  • Loading branch information
nyalldawson committed Nov 27, 2020
1 parent 442b9af commit d95820b
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 201 deletions.
3 changes: 2 additions & 1 deletion python/gui/auto_generated/qgsextentgroupbox.sip.in
Expand Up @@ -149,11 +149,12 @@ Returns the base part of title of the group box (will be appended with extent st
.. versionadded:: 2.12
%End

void setMapCanvas( QgsMapCanvas *canvas );
void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );
%Docstring
Sets the map canvas to enable dragging of extent on a canvas.

:param canvas: the map canvas
:param drawOnCanvasOption: set to false to disable to draw on canvas option

.. versionadded:: 3.0
%End
Expand Down
3 changes: 2 additions & 1 deletion python/gui/auto_generated/qgsextentwidget.sip.in
Expand Up @@ -135,11 +135,12 @@ Returns the current output CRS, used in the display.
Returns the currently selected state for the widget's extent.
%End

void setMapCanvas( QgsMapCanvas *canvas );
void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );
%Docstring
Sets the map canvas to enable dragging of extent on a canvas.

:param canvas: the map canvas
:param drawOnCanvasOption: set to false to disable to draw on canvas option
%End

QSize ratio() const;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -12352,6 +12352,7 @@ QMap< QString, QString > QgisApp::projectPropertiesPagesMap()
{
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "General" ), QStringLiteral( "mProjOptsGeneral" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Metadata" ), QStringLiteral( "mMetadataPage" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "View Settings" ), QStringLiteral( "mViewSettingsPage" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "CRS" ), QStringLiteral( "mProjOptsCRS" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Transformations" ), QStringLiteral( "mProjTransformations" ) );
sProjectPropertiesPagesMap.insert( QCoreApplication::translate( "QgsProjectPropertiesBase", "Default Styles" ), QStringLiteral( "mProjOptsSymbols" ) );
Expand Down
22 changes: 22 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -94,6 +94,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
{
setupUi( this );

mExtentGroupBox->setTitleBase( tr( "Set Project Full Extent" ) );
mExtentGroupBox->setMapCanvas( mapCanvas, false );

mMetadataWidget = new QgsMetadataWidget();
mMetadataPage->layout()->addWidget( mMetadataWidget );

Expand Down Expand Up @@ -396,6 +399,14 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa

grpProjectScales->setChecked( QgsProject::instance()->viewSettings()->useProjectScales() );

const QgsReferencedRectangle presetExtent = QgsProject::instance()->viewSettings()->presetFullExtent();
mExtentGroupBox->setOutputCrs( QgsProject::instance()->crs() );
if ( presetExtent.isNull() )
mExtentGroupBox->setOutputExtentFromUser( QgsProject::instance()->viewSettings()->fullExtent(), QgsProject::instance()->crs() );
else
mExtentGroupBox->setOutputExtentFromUser( presetExtent, presetExtent.crs() );
mExtentGroupBox->setChecked( !presetExtent.isNull() );

mLayerCapabilitiesModel = new QgsLayerCapabilitiesModel( QgsProject::instance(), this );
mLayerCapabilitiesModel->setLayerTreeModel( new QgsLayerTreeModel( QgsProject::instance()->layerTreeRoot(), mLayerCapabilitiesModel ) );
mLayerCapabilitiesTree->setModel( mLayerCapabilitiesModel );
Expand Down Expand Up @@ -1167,6 +1178,15 @@ void QgsProjectProperties::apply()
QgsProject::instance()->viewSettings()->setUseProjectScales( false );
}

if ( mExtentGroupBox->isChecked() )
{
QgsProject::instance()->viewSettings()->setPresetFullExtent( QgsReferencedRectangle( mExtentGroupBox->outputExtent(), mExtentGroupBox->outputCrs() ) );
}
else
{
QgsProject::instance()->viewSettings()->setPresetFullExtent( QgsReferencedRectangle() );
}

bool isDirty = false;
const QMap<QString, QgsMapLayer *> &mapLayers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
Expand Down Expand Up @@ -1783,6 +1803,8 @@ void QgsProjectProperties::crsChanged( const QgsCoordinateReferenceSystem &crs )
cmbEllipsoid->setCurrentIndex( 0 );
cmbEllipsoid->setEnabled( false );
}

mExtentGroupBox->setOutputCrs( crs );
}

void QgsProjectProperties::pbnWMSExtCanvas_clicked()
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsextentgroupbox.cpp
Expand Up @@ -186,9 +186,9 @@ QString QgsExtentGroupBox::titleBase() const
return mTitleBase;
}

void QgsExtentGroupBox::setMapCanvas( QgsMapCanvas *canvas )
void QgsExtentGroupBox::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
{
mWidget->setMapCanvas( canvas );
mWidget->setMapCanvas( canvas, drawOnCanvasOption );
}

QSize QgsExtentGroupBox::ratio() const
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsextentgroupbox.h
Expand Up @@ -155,9 +155,10 @@ class GUI_EXPORT QgsExtentGroupBox : public QgsCollapsibleGroupBox
/**
* Sets the map canvas to enable dragging of extent on a canvas.
* \param canvas the map canvas
* \param drawOnCanvasOption set to false to disable to draw on canvas option
* \since QGIS 3.0
*/
void setMapCanvas( QgsMapCanvas *canvas );
void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );

/**
* Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
Expand Down
7 changes: 4 additions & 3 deletions src/gui/qgsextentwidget.cpp
Expand Up @@ -420,16 +420,17 @@ QgsRectangle QgsExtentWidget::outputExtent() const
mXMaxLineEdit->text().toDouble(), mYMaxLineEdit->text().toDouble() );
}

void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas )
void QgsExtentWidget::setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption )
{
if ( canvas )
{
mCanvas = canvas;
mButtonDrawOnCanvas->setVisible( true );
mButtonDrawOnCanvas->setVisible( drawOnCanvasOption );
mCurrentExtentButton->setVisible( true );

mMenu->addAction( mUseCanvasExtentAction );
mMenu->addAction( mDrawOnCanvasAction );
if ( drawOnCanvasOption )
mMenu->addAction( mDrawOnCanvasAction );
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsextentwidget.h
Expand Up @@ -147,8 +147,9 @@ class GUI_EXPORT QgsExtentWidget : public QWidget, private Ui::QgsExtentGroupBox
/**
* Sets the map canvas to enable dragging of extent on a canvas.
* \param canvas the map canvas
* \param drawOnCanvasOption set to false to disable to draw on canvas option
*/
void setMapCanvas( QgsMapCanvas *canvas );
void setMapCanvas( QgsMapCanvas *canvas, bool drawOnCanvasOption = true );

/**
* Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
Expand Down
100 changes: 50 additions & 50 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -361,8 +361,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>743</height>
<width>675</width>
<height>1019</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
Expand Down Expand Up @@ -1133,8 +1133,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>940</height>
<width>586</width>
<height>1084</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
Expand Down Expand Up @@ -1672,8 +1672,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>340</width>
<height>442</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
Expand Down Expand Up @@ -1864,8 +1864,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>599</width>
<height>111</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_47">
Expand Down Expand Up @@ -1947,8 +1947,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>628</width>
<height>804</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
Expand Down Expand Up @@ -2356,8 +2356,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>844</height>
<width>713</width>
<height>1198</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_22">
Expand Down Expand Up @@ -3161,8 +3161,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>509</width>
<height>375</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
Expand Down Expand Up @@ -3606,8 +3606,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>614</width>
<height>709</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
Expand Down Expand Up @@ -4123,8 +4123,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>139</width>
<height>255</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_46">
Expand Down Expand Up @@ -4303,8 +4303,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>846</width>
<height>714</height>
<width>843</width>
<height>1024</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_31">
Expand Down Expand Up @@ -4977,8 +4977,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>474</width>
<height>556</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_39">
Expand Down Expand Up @@ -5258,8 +5258,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>861</width>
<height>691</height>
<width>447</width>
<height>431</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
Expand Down Expand Up @@ -5530,8 +5530,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>437</width>
<height>513</height>
<width>660</width>
<height>699</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">
Expand Down Expand Up @@ -6011,7 +6011,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.14286pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Fira Sans'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Noto Sans'; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
Expand Down Expand Up @@ -6122,23 +6122,6 @@ p, li { white-space: pre-wrap; }
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
Expand All @@ -6156,6 +6139,12 @@ p, li { white-space: pre-wrap; }
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorSchemeList</class>
<extends>QWidget</extends>
Expand All @@ -6168,6 +6157,23 @@ p, li { white-space: pre-wrap; }
<header location="global">qgsvariableeditorwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDatumTransformTableWidget</class>
<extends>QWidget</extends>
<header>qgsdatumtransformtablewidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScaleComboBox</class>
<extends>QComboBox</extends>
Expand All @@ -6185,12 +6191,6 @@ p, li { white-space: pre-wrap; }
<header>auth/qgsauthsettingswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDatumTransformTableWidget</class>
<extends>QWidget</extends>
<header>qgsdatumtransformtablewidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
Expand Down

0 comments on commit d95820b

Please sign in to comment.