remove CRS picker and allow only layer CRS or provider CRS in metadata editor (#5915)

This commit is contained in:
Etienne Trimaille 2017-12-20 09:35:49 +01:00 committed by Tim Sutton
parent 3c7f745424
commit 9a5435ff1e
8 changed files with 119 additions and 26 deletions

View File

@ -50,6 +50,9 @@ using QgsNativeMetadataValidator.
QgsCoordinateReferenceSystem extentCrs; QgsCoordinateReferenceSystem extentCrs;
%Docstring %Docstring
Coordinate reference system for spatial extent. 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` .. seealso:: :py:func:`spatial`
%End %End
@ -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 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. 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()` .. seealso:: :py:func:`setCrs()`
%End %End
@ -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 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. 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()` .. seealso:: :py:func:`crs()`
%End %End

View File

@ -36,6 +36,11 @@ Save all fields in a QgsLayerMetadata object.
bool checkMetadata() const; bool checkMetadata() const;
%Docstring %Docstring
Check if values in the wizard are correct. Check if values in the wizard are correct.
%End
void crsChanged() const;
%Docstring
If the CRS is updated.
%End %End
void acceptMetadata(); void acceptMetadata();

View File

@ -1223,6 +1223,7 @@ void QgsRasterLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateRefer
{ {
QgisApp::instance()->askUserForDatumTransform( crs, QgsProject::instance()->crs() ); QgisApp::instance()->askUserForDatumTransform( crs, QgsProject::instance()->crs() );
mRasterLayer->setCrs( crs ); mRasterLayer->setCrs( crs );
mMetadataWidget->crsChanged();
} }
void QgsRasterLayerProperties::pbnDefaultValues_clicked() void QgsRasterLayerProperties::pbnDefaultValues_clicked()

View File

@ -834,6 +834,7 @@ void QgsVectorLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateRefer
QgisApp::instance()->askUserForDatumTransform( crs, QgsProject::instance()->crs() ); QgisApp::instance()->askUserForDatumTransform( crs, QgsProject::instance()->crs() );
mLayer->setCrs( crs ); mLayer->setCrs( crs );
mMetadataFilled = false; mMetadataFilled = false;
mMetadataWidget->crsChanged();
} }
void QgsVectorLayerProperties::loadDefaultStyle_clicked() void QgsVectorLayerProperties::loadDefaultStyle_clicked()

View File

@ -69,6 +69,8 @@ class CORE_EXPORT QgsLayerMetadata
/** /**
* Coordinate reference system for spatial extent. * Coordinate reference system for spatial extent.
* The CRS should match the CRS defined in the QgsLayerMetadata CRS property.
* \see QgsLayerMetadata::crs()
* \see spatial * \see spatial
*/ */
QgsCoordinateReferenceSystem extentCrs; QgsCoordinateReferenceSystem extentCrs;
@ -535,6 +537,12 @@ class CORE_EXPORT QgsLayerMetadata
* CRS which is actually used to display and manipulate the layer within QGIS. * 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 * 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. * 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() * \see setCrs()
*/ */
QgsCoordinateReferenceSystem crs() const; QgsCoordinateReferenceSystem crs() const;
@ -552,6 +560,12 @@ class CORE_EXPORT QgsLayerMetadata
* CRS which is actually used to display and manipulate the layer within QGIS. * 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 * 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. * 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() * \see crs()
*/ */
void setCrs( const QgsCoordinateReferenceSystem &crs ); void setCrs( const QgsCoordinateReferenceSystem &crs );

View File

@ -66,7 +66,6 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
tabConstraints->setItemDelegate( new ConstraintItemDelegate( this ) ); tabConstraints->setItemDelegate( new ConstraintItemDelegate( this ) );
// Extent // Extent
selectionCrs->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
dateTimeFrom->setAllowNull( true ); dateTimeFrom->setAllowNull( true );
dateTimeTo->setAllowNull( true ); dateTimeTo->setAllowNull( true );
@ -94,8 +93,8 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
connect( btnRemoveLicence, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedLicence ); connect( btnRemoveLicence, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedLicence );
connect( btnAddConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::addConstraint ); connect( btnAddConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::addConstraint );
connect( btnRemoveConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedConstraint ); connect( btnRemoveConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedConstraint );
connect( btnAutoCrs, &QPushButton::clicked, this, &QgsMetadataWidget::fillCrsFromLayer ); connect( btnSetCrsFromLayer, &QPushButton::clicked, this, &QgsMetadataWidget::fillCrsFromLayer );
connect( selectionCrs, &QgsProjectionSelectionWidget::crsChanged, this, &QgsMetadataWidget::toggleExtentSelector ); connect( btnSetCrsFromProvider, &QPushButton::clicked, this, &QgsMetadataWidget::fillCrsFromProvider );
connect( btnAddAddress, &QPushButton::clicked, this, &QgsMetadataWidget::addAddress ); connect( btnAddAddress, &QPushButton::clicked, this, &QgsMetadataWidget::addAddress );
connect( btnRemoveAddress, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedAddress ); connect( btnRemoveAddress, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedAddress );
connect( btnAddLink, &QPushButton::clicked, this, &QgsMetadataWidget::addLink ); connect( btnAddLink, &QPushButton::clicked, this, &QgsMetadataWidget::addLink );
@ -200,10 +199,37 @@ void QgsMetadataWidget::removeSelectedConstraint() const
mConstraintsModel->removeRow( selectedRows[0].row() ); mConstraintsModel->removeRow( selectedRows[0].row() );
} }
void QgsMetadataWidget::toggleExtentSelector() const void QgsMetadataWidget::crsChanged() const
{ {
spatialExtentSelector->setEnabled( selectionCrs->crs().isValid() ); if ( mCrs.isValid() )
spatialExtentSelector->setOutputCrs( selectionCrs->crs() ); {
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 void QgsMetadataWidget::addAddress() const
@ -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 void QgsMetadataWidget::addLink() const
@ -322,7 +355,7 @@ void QgsMetadataWidget::fillComboBox() const
} }
} }
void QgsMetadataWidget::setPropertiesFromLayer() const void QgsMetadataWidget::setPropertiesFromLayer()
{ {
// Parent ID // Parent ID
lineEditParentId->setText( mMetadata.parentIdentifier() ); lineEditParentId->setText( mMetadata.parentIdentifier() );
@ -409,11 +442,8 @@ void QgsMetadataWidget::setPropertiesFromLayer() const
} }
// CRS // CRS
if ( mMetadata.crs().isValid() ) mCrs = mMetadata.crs();
{ crsChanged();
selectionCrs->setCrs( mMetadata.crs() );
}
toggleExtentSelector();
// Spatial extent // Spatial extent
const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = mMetadata.extent().spatialExtents(); const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = mMetadata.extent().spatialExtents();
@ -534,7 +564,10 @@ void QgsMetadataWidget::saveMetadata( QgsLayerMetadata &layerMetadata ) const
layerMetadata.setConstraints( constraints ); layerMetadata.setConstraints( constraints );
// CRS // CRS
layerMetadata.setCrs( selectionCrs->crs() ); if ( mCrs.isValid() )
{
layerMetadata.setCrs( mCrs );
}
// Extent // Extent
struct QgsLayerMetadata::SpatialExtent spatialExtent = QgsLayerMetadata::SpatialExtent(); struct QgsLayerMetadata::SpatialExtent spatialExtent = QgsLayerMetadata::SpatialExtent();

View File

@ -21,6 +21,8 @@
#include "QStyledItemDelegate" #include "QStyledItemDelegate"
#include "qgis_gui.h" #include "qgis_gui.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsdataprovider.h"
#include "qgsmaplayer.h" #include "qgsmaplayer.h"
#include "qgslayermetadata.h" #include "qgslayermetadata.h"
#include "ui_qgsmetadatawidget.h" #include "ui_qgsmetadatawidget.h"
@ -54,6 +56,11 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
*/ */
bool checkMetadata() const; bool checkMetadata() const;
/**
* If the CRS is updated.
*/
void crsChanged() const;
/** /**
* Saves the metadata to the layer. * Saves the metadata to the layer.
*/ */
@ -89,7 +96,8 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
private: private:
void updatePanel() const; void updatePanel() const;
void fillSourceFromLayer() const; void fillSourceFromLayer() const;
void fillCrsFromLayer() const; void fillCrsFromLayer();
void fillCrsFromProvider();
void addDefaultCategory() const; void addDefaultCategory() const;
void addNewCategory(); void addNewCategory();
void removeSelectedCategory() const; void removeSelectedCategory() const;
@ -101,7 +109,6 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
void removeSelectedRight() const; void removeSelectedRight() const;
void addConstraint() const; void addConstraint() const;
void removeSelectedConstraint() const; void removeSelectedConstraint() const;
void toggleExtentSelector() const;
void addAddress() const; void addAddress() const;
void removeSelectedAddress() const; void removeSelectedAddress() const;
void addLink() const; void addLink() const;
@ -109,10 +116,11 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
void addHistory(); void addHistory();
void removeSelectedHistory() const; void removeSelectedHistory() const;
void fillComboBox() const; void fillComboBox() const;
void setPropertiesFromLayer() const; void setPropertiesFromLayer();
void syncFromCategoriesTabToKeywordsTab() const; void syncFromCategoriesTabToKeywordsTab() const;
QStringList mDefaultCategories; QStringList mDefaultCategories;
QgsMapLayer *mLayer = nullptr; QgsMapLayer *mLayer = nullptr;
QgsCoordinateReferenceSystem mCrs;
QgsLayerMetadata mMetadata; QgsLayerMetadata mMetadata;
QStandardItemModel *mConstraintsModel = nullptr; QStandardItemModel *mConstraintsModel = nullptr;
QStandardItemModel *mLinksModel = nullptr; QStandardItemModel *mLinksModel = nullptr;

View File

@ -818,10 +818,14 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_7"> <layout class="QHBoxLayout" name="horizontalLayout_7">
<item> <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>
<item> <item>
<widget class="QPushButton" name="btnAutoCrs"> <widget class="QPushButton" name="btnSetCrsFromLayer">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed"> <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -833,8 +837,28 @@
</property> </property>
</widget> </widget>
</item> </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> </layout>
</item> </item>
<item>
<widget class="QLabel" name="lblCurrentCrsStatus">
<property name="text">
<string notr="true">CRS status set in cpp code</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -1370,12 +1394,6 @@
<header>qgscollapsiblegroupbox.h</header> <header>qgscollapsiblegroupbox.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget> <customwidget>
<class>QgsExtentGroupBox</class> <class>QgsExtentGroupBox</class>
<extends>QGroupBox</extends> <extends>QGroupBox</extends>