Skip to content

Commit

Permalink
remove CRS picker and allow only layer CRS or provider CRS in metadat…
Browse files Browse the repository at this point in the history
…a editor (#5915)
  • Loading branch information
Gustry authored and timlinux committed Dec 20, 2017
1 parent 3c7f745 commit 9a5435f
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 26 deletions.
13 changes: 13 additions & 0 deletions python/core/metadata/qgslayermetadata.sip
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ using QgsNativeMetadataValidator.
QgsCoordinateReferenceSystem extentCrs;
%Docstring
Coordinate reference system for spatial extent.
The CRS should match the CRS defined in the QgsLayerMetadata CRS property.

.. seealso:: :py:func:`QgsLayerMetadata.crs()`

.. seealso:: :py:func:`spatial`
%End
Expand Down Expand Up @@ -505,6 +508,11 @@ CRS which is actually used to display and manipulate the layer within QGIS.
This may be the case when a layer has an incorrect CRS within its metadata
and a user has manually overridden the layer's CRS within QGIS.

The CRS described here should either match the CRS from the layer QgsMapLayer.crs()
or the CRS from the data provider.

This property should also match the CRS property used in the spatial extent.

.. seealso:: :py:func:`setCrs()`
%End

Expand All @@ -523,6 +531,11 @@ CRS which is actually used to display and manipulate the layer within QGIS.
This may be the case when a layer has an incorrect CRS within its metadata
and a user has manually overridden the layer's CRS within QGIS.

The CRS described here should either match the CRS from the layer QgsMapLayer.crs()
or the CRS from the data provider.

This property should also match the CRS property used in the spatial extent.

.. seealso:: :py:func:`crs()`
%End

Expand Down
5 changes: 5 additions & 0 deletions python/gui/qgsmetadatawidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Save all fields in a QgsLayerMetadata object.
bool checkMetadata() const;
%Docstring
Check if values in the wizard are correct.
%End

void crsChanged() const;
%Docstring
If the CRS is updated.
%End

void acceptMetadata();
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ void QgsRasterLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateRefer
{
QgisApp::instance()->askUserForDatumTransform( crs, QgsProject::instance()->crs() );
mRasterLayer->setCrs( crs );
mMetadataWidget->crsChanged();
}

void QgsRasterLayerProperties::pbnDefaultValues_clicked()
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ void QgsVectorLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateRefer
QgisApp::instance()->askUserForDatumTransform( crs, QgsProject::instance()->crs() );
mLayer->setCrs( crs );
mMetadataFilled = false;
mMetadataWidget->crsChanged();
}

void QgsVectorLayerProperties::loadDefaultStyle_clicked()
Expand Down
14 changes: 14 additions & 0 deletions src/core/metadata/qgslayermetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class CORE_EXPORT QgsLayerMetadata

/**
* Coordinate reference system for spatial extent.
* The CRS should match the CRS defined in the QgsLayerMetadata CRS property.
* \see QgsLayerMetadata::crs()
* \see spatial
*/
QgsCoordinateReferenceSystem extentCrs;
Expand Down Expand Up @@ -535,6 +537,12 @@ class CORE_EXPORT QgsLayerMetadata
* CRS which is actually used to display and manipulate the layer within QGIS.
* This may be the case when a layer has an incorrect CRS within its metadata
* and a user has manually overridden the layer's CRS within QGIS.
*
* The CRS described here should either match the CRS from the layer QgsMapLayer::crs()
* or the CRS from the data provider.
*
* This property should also match the CRS property used in the spatial extent.
*
* \see setCrs()
*/
QgsCoordinateReferenceSystem crs() const;
Expand All @@ -552,6 +560,12 @@ class CORE_EXPORT QgsLayerMetadata
* CRS which is actually used to display and manipulate the layer within QGIS.
* This may be the case when a layer has an incorrect CRS within its metadata
* and a user has manually overridden the layer's CRS within QGIS.
*
* The CRS described here should either match the CRS from the layer QgsMapLayer::crs()
* or the CRS from the data provider.
*
* This property should also match the CRS property used in the spatial extent.
*
* \see crs()
*/
void setCrs( const QgsCoordinateReferenceSystem &crs );
Expand Down
63 changes: 48 additions & 15 deletions src/gui/qgsmetadatawidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
tabConstraints->setItemDelegate( new ConstraintItemDelegate( this ) );

// Extent
selectionCrs->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
dateTimeFrom->setAllowNull( true );
dateTimeTo->setAllowNull( true );

Expand Down Expand Up @@ -94,8 +93,8 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
connect( btnRemoveLicence, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedLicence );
connect( btnAddConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::addConstraint );
connect( btnRemoveConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedConstraint );
connect( btnAutoCrs, &QPushButton::clicked, this, &QgsMetadataWidget::fillCrsFromLayer );
connect( selectionCrs, &QgsProjectionSelectionWidget::crsChanged, this, &QgsMetadataWidget::toggleExtentSelector );
connect( btnSetCrsFromLayer, &QPushButton::clicked, this, &QgsMetadataWidget::fillCrsFromLayer );
connect( btnSetCrsFromProvider, &QPushButton::clicked, this, &QgsMetadataWidget::fillCrsFromProvider );
connect( btnAddAddress, &QPushButton::clicked, this, &QgsMetadataWidget::addAddress );
connect( btnRemoveAddress, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedAddress );
connect( btnAddLink, &QPushButton::clicked, this, &QgsMetadataWidget::addLink );
Expand Down Expand Up @@ -200,10 +199,37 @@ void QgsMetadataWidget::removeSelectedConstraint() const
mConstraintsModel->removeRow( selectedRows[0].row() );
}

void QgsMetadataWidget::toggleExtentSelector() const
void QgsMetadataWidget::crsChanged() const
{
spatialExtentSelector->setEnabled( selectionCrs->crs().isValid() );
spatialExtentSelector->setOutputCrs( selectionCrs->crs() );
if ( mCrs.isValid() )
{
lblCurrentCrs->setText( tr( "CRS: %1 - %2" ).arg( mCrs.authid(), mCrs.description() ) );
spatialExtentSelector->setEnabled( true );
spatialExtentSelector->setOutputCrs( mCrs );

if ( mCrs == mLayer->crs() && mCrs == mLayer->dataProvider()->crs() )
{
lblCurrentCrsStatus->setText( tr( "Same as layer properties and provider." ) );
}
else if ( mCrs == mLayer->crs() && mCrs != mLayer->dataProvider()->crs() )
{
lblCurrentCrsStatus->setText( tr( "Same as layer properties but different than the provider." ) );
}
else if ( mCrs != mLayer->crs() && mCrs == mLayer->dataProvider()->crs() )
{
lblCurrentCrsStatus->setText( tr( "Same as the provider but different than the layer properties." ) );
}
else
{
lblCurrentCrsStatus->setText( tr( "Does not match either layer properties or the provider." ) );
}
}
else
{
lblCurrentCrs->setText( tr( "CRS: Not set." ) );
lblCurrentCrsStatus->setText( QString() );
spatialExtentSelector->setEnabled( false );
}
}

void QgsMetadataWidget::addAddress() const
Expand Down Expand Up @@ -242,9 +268,16 @@ void QgsMetadataWidget::removeSelectedAddress() const
}
}

void QgsMetadataWidget::fillCrsFromLayer() const
void QgsMetadataWidget::fillCrsFromLayer()
{
selectionCrs->setCrs( mLayer->crs() );
mCrs = mLayer->crs();
crsChanged();
}

void QgsMetadataWidget::fillCrsFromProvider()
{
mCrs = mLayer->dataProvider()->crs();
crsChanged();
}

void QgsMetadataWidget::addLink() const
Expand Down Expand Up @@ -322,7 +355,7 @@ void QgsMetadataWidget::fillComboBox() const
}
}

void QgsMetadataWidget::setPropertiesFromLayer() const
void QgsMetadataWidget::setPropertiesFromLayer()
{
// Parent ID
lineEditParentId->setText( mMetadata.parentIdentifier() );
Expand Down Expand Up @@ -409,11 +442,8 @@ void QgsMetadataWidget::setPropertiesFromLayer() const
}

// CRS
if ( mMetadata.crs().isValid() )
{
selectionCrs->setCrs( mMetadata.crs() );
}
toggleExtentSelector();
mCrs = mMetadata.crs();
crsChanged();

// Spatial extent
const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = mMetadata.extent().spatialExtents();
Expand Down Expand Up @@ -534,7 +564,10 @@ void QgsMetadataWidget::saveMetadata( QgsLayerMetadata &layerMetadata ) const
layerMetadata.setConstraints( constraints );

// CRS
layerMetadata.setCrs( selectionCrs->crs() );
if ( mCrs.isValid() )
{
layerMetadata.setCrs( mCrs );
}

// Extent
struct QgsLayerMetadata::SpatialExtent spatialExtent = QgsLayerMetadata::SpatialExtent();
Expand Down
14 changes: 11 additions & 3 deletions src/gui/qgsmetadatawidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "QStyledItemDelegate"

#include "qgis_gui.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsdataprovider.h"
#include "qgsmaplayer.h"
#include "qgslayermetadata.h"
#include "ui_qgsmetadatawidget.h"
Expand Down Expand Up @@ -54,6 +56,11 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
*/
bool checkMetadata() const;

/**
* If the CRS is updated.
*/
void crsChanged() const;

/**
* Saves the metadata to the layer.
*/
Expand Down Expand Up @@ -89,7 +96,8 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
private:
void updatePanel() const;
void fillSourceFromLayer() const;
void fillCrsFromLayer() const;
void fillCrsFromLayer();
void fillCrsFromProvider();
void addDefaultCategory() const;
void addNewCategory();
void removeSelectedCategory() const;
Expand All @@ -101,18 +109,18 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
void removeSelectedRight() const;
void addConstraint() const;
void removeSelectedConstraint() const;
void toggleExtentSelector() const;
void addAddress() const;
void removeSelectedAddress() const;
void addLink() const;
void removeSelectedLink() const;
void addHistory();
void removeSelectedHistory() const;
void fillComboBox() const;
void setPropertiesFromLayer() const;
void setPropertiesFromLayer();
void syncFromCategoriesTabToKeywordsTab() const;
QStringList mDefaultCategories;
QgsMapLayer *mLayer = nullptr;
QgsCoordinateReferenceSystem mCrs;
QgsLayerMetadata mMetadata;
QStandardItemModel *mConstraintsModel = nullptr;
QStandardItemModel *mLinksModel = nullptr;
Expand Down
34 changes: 26 additions & 8 deletions src/ui/qgsmetadatawidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,14 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QgsProjectionSelectionWidget" name="selectionCrs" native="true"/>
<widget class="QLabel" name="lblCurrentCrs">
<property name="text">
<string notr="true">CRS label set in cpp code</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnAutoCrs">
<widget class="QPushButton" name="btnSetCrsFromLayer">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
Expand All @@ -833,8 +837,28 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnSetCrsFromProvider">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Set CRS from provider</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="lblCurrentCrsStatus">
<property name="text">
<string notr="true">CRS status set in cpp code</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -1370,12 +1394,6 @@
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsExtentGroupBox</class>
<extends>QGroupBox</extends>
Expand Down

0 comments on commit 9a5435f

Please sign in to comment.