Skip to content
Permalink
Browse files

Remove useless projection selector -- arcgis rest layers are only ava…

…ilable in a single crs
  • Loading branch information
nyalldawson committed Dec 23, 2020
1 parent b45280e commit 7b17a0c8dd7c5d0a47ffbcd9764f947799f55e2f
@@ -160,18 +160,10 @@ QString QgsAmsSourceSelect::getLayerURI( const QgsOwsConnection &connection,
const QString & /*filter*/,
const QgsRectangle & /*bBox*/, const QString &layerId ) const
{
QgsDataSourceUri ds = connection.uri();
QString url = layerTitle;
QString trimmedUrl = layerId.isEmpty() ? url : url.left( url.length() - 1 - layerId.length() ); // trim '/0' from end of url -- AMS provider requires this omitted
ds.removeParam( QStringLiteral( "url" ) );
ds.setParam( QStringLiteral( "url" ), trimmedUrl );
ds.setParam( QStringLiteral( "layer" ), layerId );
ds.setParam( QStringLiteral( "crs" ), crs );
ds.setParam( QStringLiteral( "format" ), getSelectedImageEncoding() );
return ds.uri( false );

}

void QgsAmsSourceSelect::addServiceLayer( QString uri, QString typeName )
{
emit addRasterLayer( uri, typeName, QStringLiteral( "arcgismapserver" ) );

}
@@ -103,11 +103,8 @@ QgsArcGisRestSourceSelect::QgsArcGisRestSourceSelect( const QString &serviceName
connect( btnConnect, &QAbstractButton::clicked, this, &QgsArcGisRestSourceSelect::connectToServer );
connect( btnSave, &QPushButton::clicked, this, &QgsArcGisRestSourceSelect::btnSave_clicked );
connect( btnLoad, &QPushButton::clicked, this, &QgsArcGisRestSourceSelect::btnLoad_clicked );
connect( btnChangeSpatialRefSys, &QAbstractButton::clicked, this, &QgsArcGisRestSourceSelect::changeCrs );
connect( lineFilter, &QLineEdit::textChanged, this, &QgsArcGisRestSourceSelect::filterChanged );
populateConnectionList();
mProjectionSelector = new QgsProjectionSelectionDialog( this );
mProjectionSelector->setMessage( QString() );

lineFilter->setShowClearButton( true );
lineFilter->setShowSearchIcon( true );
@@ -220,37 +217,6 @@ void QgsArcGisRestSourceSelect::populateConnectionList()
}
}

QString QgsArcGisRestSourceSelect::getPreferredCrs( const QSet<QString> &crsSet ) const
{
if ( crsSet.size() < 1 )
{
return QString();
}

//first: project CRS
QgsCoordinateReferenceSystem projectRefSys = QgsProject::instance()->crs();
//convert to EPSG
QString ProjectCRS;
if ( projectRefSys.isValid() )
{
ProjectCRS = projectRefSys.authid();
}

if ( !ProjectCRS.isEmpty() && crsSet.contains( ProjectCRS ) )
{
return ProjectCRS;
}

//second: WGS84
if ( crsSet.contains( geoEpsgCrsAuthId() ) )
{
return geoEpsgCrsAuthId();
}

//third: first entry in set
return *( crsSet.constBegin() );
}

void QgsArcGisRestSourceSelect::refresh()
{
populateConnectionList();
@@ -318,16 +284,14 @@ void QgsArcGisRestSourceSelect::connectToServer()
onRefresh();
}

mAvailableCRS.clear();

setCursor( Qt::WaitCursor );
connectToService( connection );
unsetCursor();

btnConnect->setEnabled( true );
emit enableButtons( haveLayers );
mBuildQueryButton->setEnabled( haveLayers );
btnChangeSpatialRefSys->setEnabled( haveLayers );
updateCrsLabel();
}

void QgsArcGisRestSourceSelect::disconnectFromServer()
@@ -416,46 +380,28 @@ void QgsArcGisRestSourceSelect::addButtonClicked()
accept();
}

void QgsArcGisRestSourceSelect::changeCrs()
{
if ( mProjectionSelector->exec() )
{
QString crsString = mProjectionSelector->crs().authid();
labelCoordRefSys->setText( crsString );
}
}

void QgsArcGisRestSourceSelect::changeCrsFilter()
void QgsArcGisRestSourceSelect::updateCrsLabel()
{
QgsDebugMsg( QStringLiteral( "changeCRSFilter called" ) );
//evaluate currently selected typename and set the CRS filter in mProjectionSelector
QModelIndex currentIndex = mBrowserView->selectionModel()->currentIndex();
if ( currentIndex.isValid() )
{
QString currentTypename = currentIndex.sibling( currentIndex.row(), 1 ).data().toString();
QgsDebugMsg( QStringLiteral( "the current typename is: %1" ).arg( currentTypename ) );

QMap<QString, QStringList>::const_iterator crsIterator = mAvailableCRS.constFind( currentTypename );
if ( crsIterator != mAvailableCRS.constEnd() )
const QModelIndex sourceIndex = mProxyModel->mapToSource( currentIndex );
if ( !sourceIndex.isValid() )
{
QSet<QString> crsNames;
const QStringList crsNamesList = crsIterator.value();
for ( const QString &crsName : crsNamesList )
{
crsNames.insert( crsName );
}
if ( mProjectionSelector )
{
mProjectionSelector->setOgcWmsCrsFilter( crsNames );
QString preferredCRS = getPreferredCrs( crsNames ); //get preferred EPSG system
if ( !preferredCRS.isEmpty() )
{
QgsCoordinateReferenceSystem refSys = QgsCoordinateReferenceSystem::fromOgcWmsCrs( preferredCRS );
mProjectionSelector->setCrs( refSys );
labelCoordRefSys->clear();
return;
}

labelCoordRefSys->setText( preferredCRS );
}
}
if ( QgsLayerItem *layerItem = qobject_cast< QgsLayerItem * >( mBrowserModel->dataItem( sourceIndex ) ) )
{
QgsDataSourceUri uri( layerItem->uri() );
labelCoordRefSys->setText( uri.param( QStringLiteral( "crs" ) ) );
}
else
{
labelCoordRefSys->clear();
}
}
}
@@ -477,7 +423,7 @@ void QgsArcGisRestSourceSelect::treeWidgetCurrentRowChanged( const QModelIndex &
{
Q_UNUSED( previous )
QgsDebugMsg( QStringLiteral( "treeWidget_currentRowChanged called" ) );
changeCrsFilter();
updateCrsLabel();
if ( mServiceType == FeatureService )
{
mBuildQueryButton->setEnabled( current.isValid() );
@@ -37,13 +37,13 @@ class QgsMapCanvas;

class QgsArcGisRestBrowserProxyModel : public QgsBrowserProxyModel
{
Q_OBJECT
Q_OBJECT

public:
public:

explicit QgsArcGisRestBrowserProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );

void setConnectionName(const QString &name);
void setConnectionName( const QString &name );
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;

private:
@@ -79,9 +79,6 @@ class QgsArcGisRestSourceSelect : public QgsAbstractDataSourceWidget, protected
protected:
QString mServiceName;
ServiceType mServiceType;
QgsProjectionSelectionDialog *mProjectionSelector = nullptr;
// Available CRS for a server connection, key=typename, value=list("EPSG:XXXX")
QMap<QString, QStringList> mAvailableCRS;

QgsBrowserGuiModel *mBrowserModel = nullptr;
QgsArcGisRestBrowserProxyModel *mProxyModel = nullptr;
@@ -113,15 +110,6 @@ class QgsArcGisRestSourceSelect : public QgsAbstractDataSourceWidget, protected
//! A layer is added from the dialog
virtual void addServiceLayer( QString uri, QString typeName ) = 0;

/**
* Returns the best suited CRS from a set of authority ids
* 1. project CRS if contained in the set
* 2. WGS84 if contained in the set
* 3. the first entry in the set else
* \returns the authority id of the crs or an empty string in case of error
*/
QString getPreferredCrs( const QSet<QString> &crsSet ) const;

public slots:

//! Triggered when the provider's connections need to be refreshed
@@ -133,8 +121,7 @@ class QgsArcGisRestSourceSelect : public QgsAbstractDataSourceWidget, protected
void modifyEntryOfServerList();
void addButtonClicked() override;
void buildQueryButtonClicked();
void changeCrs();
void changeCrsFilter();
void updateCrsLabel();
void connectToServer();
void disconnectFromServer();
void filterChanged( const QString &text );
@@ -148,7 +135,7 @@ class QgsArcGisRestSourceSelect : public QgsAbstractDataSourceWidget, protected

void refreshModel( const QModelIndex &index );

private:
private:

QString mConnectedService;
};
@@ -214,32 +214,6 @@
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>441</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnChangeSpatialRefSys">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Change…</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -277,7 +251,6 @@
<tabstop>lineFilter</tabstop>
<tabstop>mBrowserView</tabstop>
<tabstop>cbxFeatureCurrentViewExtent</tabstop>
<tabstop>btnChangeSpatialRefSys</tabstop>
</tabstops>
<resources/>
<connections/>

0 comments on commit 7b17a0c

Please sign in to comment.
You can’t perform that action at this time.