Skip to content
Permalink
Browse files

Handle image formats

  • Loading branch information
nyalldawson committed Dec 23, 2020
1 parent 7b17a0c commit 33a607b3d6908e3cd964b4c4b72471e08de57b44
@@ -188,27 +188,4 @@ void QgsAfsSourceSelect::buildQuery( const QgsOwsConnection &connection, const Q
}
}

QString QgsAfsSourceSelect::getLayerURI( const QgsOwsConnection &connection,
const QString &layerTitle, const QString & /*layerName*/,
const QString &crs,
const QString &filter,
const QgsRectangle &bBox, const QString & ) const
{
QgsDataSourceUri ds = connection.uri();
QString url = layerTitle;
ds.removeParam( QStringLiteral( "url" ) );
ds.setParam( QStringLiteral( "url" ), url );
ds.setParam( QStringLiteral( "filter" ), filter );
ds.setParam( QStringLiteral( "crs" ), crs );
if ( !bBox.isEmpty() )
{
ds.setParam( QStringLiteral( "bbox" ), QStringLiteral( "%1,%2,%3,%4" ).arg( bBox.xMinimum() ).arg( bBox.yMinimum() ).arg( bBox.xMaximum() ).arg( bBox.yMaximum() ) );
}
return ds.uri( false );
}


void QgsAfsSourceSelect::addServiceLayer( QString uri, QString typeName )
{
emit addVectorLayer( uri, typeName );
}
@@ -33,14 +33,7 @@ class QgsAfsSourceSelect: public QgsArcGisRestSourceSelect
protected:
bool connectToService( const QgsOwsConnection &connection ) override;
void buildQuery( const QgsOwsConnection &connection, const QModelIndex & ) override;
QString getLayerURI( const QgsOwsConnection &connection,
const QString &layerTitle, const QString &layerName,
const QString &crs = QString(),
const QString &filter = QString(),
const QgsRectangle &bBox = QgsRectangle(), const QString &layerId = QString() ) const override;
private:
//! A layer is added from the dialog
void addServiceLayer( QString uri, QString typeName ) override;


};

@@ -153,17 +153,3 @@ bool QgsAmsSourceSelect::connectToService( const QgsOwsConnection &connection )

return true;
}

QString QgsAmsSourceSelect::getLayerURI( const QgsOwsConnection &connection,
const QString &layerTitle, const QString & /*layerName*/,
const QString &crs,
const QString & /*filter*/,
const QgsRectangle & /*bBox*/, const QString &layerId ) const
{

}

void QgsAmsSourceSelect::addServiceLayer( QString uri, QString typeName )
{

}
@@ -32,15 +32,7 @@ class QgsAmsSourceSelect: public QgsArcGisRestSourceSelect

protected:
bool connectToService( const QgsOwsConnection &connection ) override;
QString getLayerURI( const QgsOwsConnection &connection,
const QString &layerTitle, const QString &layerName,
const QString &crs = QString(),
const QString &filter = QString(),
const QgsRectangle &bBox = QgsRectangle(),
const QString &layerId = QString() ) const override;
private:
//! A layer is added from the dialog
void addServiceLayer( QString uri, QString typeName ) override;

};

#endif // QGSAMSSOURCESELECT_H
@@ -67,19 +67,22 @@ void QgsArcGisRestRootItem::onConnectionsChanged()

///////////////////////////////////////////////////////////////////////////////

void addFolderItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceData, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers, QgsDataItem *parent )
void addFolderItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceData, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers, QgsDataItem *parent,
const QString &supportedFormats )
{
QgsArcGisRestQueryUtils::visitFolderItems( [parent, &baseUrl, &items, headers, authcfg]( const QString & name, const QString & url )
QgsArcGisRestQueryUtils::visitFolderItems( [parent, &baseUrl, &items, headers, authcfg, supportedFormats]( const QString & name, const QString & url )
{
std::unique_ptr< QgsArcGisRestFolderItem > folderItem = qgis::make_unique< QgsArcGisRestFolderItem >( parent, name, url, baseUrl, authcfg, headers );
folderItem->setSupportedFormats( supportedFormats );
items.append( folderItem.release() );
}, serviceData, baseUrl );
}

void addServiceItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceData, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers, QgsDataItem *parent )
void addServiceItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceData, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers, QgsDataItem *parent,
const QString &supportedFormats )
{
QgsArcGisRestQueryUtils::visitServiceItems(
[&items, parent, authcfg, headers]( const QString & name, const QString & url, QgsArcGisRestQueryUtils::ServiceTypeFilter serviceType )
[&items, parent, authcfg, headers, supportedFormats]( const QString & name, const QString & url, QgsArcGisRestQueryUtils::ServiceTypeFilter serviceType )
{
switch ( serviceType )
{
@@ -93,6 +96,7 @@ void addServiceItems( QVector< QgsDataItem * > &items, const QVariantMap &servic
case QgsArcGisRestQueryUtils::Vector:
{
std::unique_ptr< QgsArcGisFeatureServiceItem > serviceItem = qgis::make_unique< QgsArcGisFeatureServiceItem >( parent, name, url, url, authcfg, headers );
serviceItem->setSupportedFormats( supportedFormats );
items.append( serviceItem.release() );
break;
}
@@ -103,12 +107,13 @@ void addServiceItems( QVector< QgsDataItem * > &items, const QVariantMap &servic
}, serviceData, baseUrl, QgsArcGisRestQueryUtils::AllTypes );
}

void addLayerItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceData, const QString &parentUrl, const QString &authcfg, const QgsStringMap &headers, QgsDataItem *parent, QgsArcGisRestQueryUtils::ServiceTypeFilter serviceTypeFilter )
void addLayerItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceData, const QString &parentUrl, const QString &authcfg, const QgsStringMap &headers, QgsDataItem *parent, QgsArcGisRestQueryUtils::ServiceTypeFilter serviceTypeFilter,
const QString &supportedFormats )
{
QMultiMap< QString, QgsDataItem * > layerItems;
QMap< QString, QString > parents;

QgsArcGisRestQueryUtils::addLayerItems( [parent, &layerItems, &parents, authcfg, headers, serviceTypeFilter]( const QString & parentLayerId, QgsArcGisRestQueryUtils::ServiceTypeFilter serviceType, QgsWkbTypes::GeometryType geometryType, const QString & id, const QString & name, const QString & description, const QString & url, bool isParent, const QString & authid, const QString & format )
QgsArcGisRestQueryUtils::addLayerItems( [parent, &layerItems, &parents, authcfg, headers, serviceTypeFilter, supportedFormats]( const QString & parentLayerId, QgsArcGisRestQueryUtils::ServiceTypeFilter serviceType, QgsWkbTypes::GeometryType geometryType, const QString & id, const QString & name, const QString & description, const QString & url, bool isParent, const QString & authid, const QString & format )
{
Q_UNUSED( description )

@@ -136,6 +141,7 @@ void addLayerItems( QVector< QgsDataItem * > &items, const QVariantMap &serviceD

case QgsArcGisRestQueryUtils::Raster:
layerItem = qgis::make_unique< QgsArcGisMapServiceLayerItem >( parent, name, url, id, name, authid, format, authcfg, headers );
static_cast< QgsArcGisMapServiceLayerItem * >( layerItem.get() )->setSupportedFormats( supportedFormats );
break;

case QgsArcGisRestQueryUtils::AllTypes:
@@ -206,9 +212,9 @@ QVector<QgsDataItem *> QgsArcGisRestConnectionItem::createChildren()
return items;
}

addFolderItems( items, serviceData, url, authcfg, headers, this );
addServiceItems( items, serviceData, url, authcfg, headers, this );
addLayerItems( items, serviceData, url, authcfg, headers, this, QgsArcGisRestQueryUtils::AllTypes );
addFolderItems( items, serviceData, url, authcfg, headers, this, QString() );
addServiceItems( items, serviceData, url, authcfg, headers, this, QString() );
addLayerItems( items, serviceData, url, authcfg, headers, this, QgsArcGisRestQueryUtils::AllTypes, QString() );
}

return items;
@@ -379,9 +385,9 @@ QVector<QgsDataItem *> QgsArcGisRestServicesItem::createChildren()
return items;
}

addFolderItems( items, serviceData, mUrl, mAuthCfg, mHeaders, this );
addServiceItems( items, serviceData, mUrl, mAuthCfg, mHeaders, this );
addLayerItems( items, serviceData, mUrl, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::AllTypes );
addFolderItems( items, serviceData, mUrl, mAuthCfg, mHeaders, this, QString() );
addServiceItems( items, serviceData, mUrl, mAuthCfg, mHeaders, this, QString() );
addLayerItems( items, serviceData, mUrl, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::AllTypes, QString() );
return items;
}

@@ -407,6 +413,11 @@ QgsArcGisRestFolderItem::QgsArcGisRestFolderItem( QgsDataItem *parent, const QSt
setToolTip( path );
}

void QgsArcGisRestFolderItem::setSupportedFormats( const QString &formats )
{
mSupportedFormats = formats;
}


QVector<QgsDataItem *> QgsArcGisRestFolderItem::createChildren()
{
@@ -427,9 +438,9 @@ QVector<QgsDataItem *> QgsArcGisRestFolderItem::createChildren()
return items;
}

addFolderItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this );
addServiceItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this );
addLayerItems( items, serviceData, mPath, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::Vector );
addFolderItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this, mSupportedFormats );
addServiceItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this, mSupportedFormats );
addLayerItems( items, serviceData, mPath, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::Vector, mSupportedFormats );
return items;
}

@@ -450,6 +461,11 @@ QgsArcGisFeatureServiceItem::QgsArcGisFeatureServiceItem( QgsDataItem *parent, c
setToolTip( path );
}

void QgsArcGisFeatureServiceItem::setSupportedFormats( const QString &formats )
{
mSupportedFormats = formats;
}

QVector<QgsDataItem *> QgsArcGisFeatureServiceItem::createChildren()
{
const QString url = mPath;
@@ -469,9 +485,9 @@ QVector<QgsDataItem *> QgsArcGisFeatureServiceItem::createChildren()
return items;
}

addFolderItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this );
addServiceItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this );
addLayerItems( items, serviceData, mPath, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::Vector );
addFolderItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this, mSupportedFormats );
addServiceItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this, mSupportedFormats );
addLayerItems( items, serviceData, mPath, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::Vector, mSupportedFormats );
return items;
}

@@ -516,9 +532,11 @@ QVector<QgsDataItem *> QgsArcGisMapServiceItem::createChildren()
return items;
}

addFolderItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this );
addServiceItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this );
addLayerItems( items, serviceData, mPath, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::AllTypes );
const QString supportedFormats = serviceData.value( QStringLiteral( "supportedImageFormatTypes" ) ).toString();

addFolderItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this, supportedFormats );
addServiceItems( items, serviceData, mBaseUrl, mAuthCfg, mHeaders, this, supportedFormats );
addLayerItems( items, serviceData, mPath, mAuthCfg, mHeaders, this, QgsArcGisRestQueryUtils::AllTypes, supportedFormats );
return items;
}

@@ -143,6 +143,8 @@ class QgsArcGisRestFolderItem : public QgsDataCollectionItem
Q_OBJECT
public:
QgsArcGisRestFolderItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers );
void setSupportedFormats( const QString &formats );

QVector<QgsDataItem *> createChildren() override;
bool equal( const QgsDataItem *other ) override;

@@ -151,6 +153,7 @@ class QgsArcGisRestFolderItem : public QgsDataCollectionItem
QString mBaseUrl;
QString mAuthCfg;
QgsStringMap mHeaders;
QString mSupportedFormats;
};


@@ -165,6 +168,7 @@ class QgsArcGisFeatureServiceItem : public QgsDataCollectionItem
Q_OBJECT
public:
QgsArcGisFeatureServiceItem( QgsDataItem *parent, const QString &name, const QString &path, const QString &baseUrl, const QString &authcfg, const QgsStringMap &headers );
void setSupportedFormats( const QString &formats );
QVector<QgsDataItem *> createChildren() override;
bool equal( const QgsDataItem *other ) override;

@@ -173,6 +177,7 @@ class QgsArcGisFeatureServiceItem : public QgsDataCollectionItem
QString mBaseUrl;
QString mAuthCfg;
QgsStringMap mHeaders;
QString mSupportedFormats;
};

/**
@@ -238,6 +243,12 @@ class QgsArcGisMapServiceLayerItem : public QgsLayerItem

public:
QgsArcGisMapServiceLayerItem( QgsDataItem *parent, const QString &name, const QString &url, const QString &id, const QString &title, const QString &authid, const QString &format, const QString &authcfg, const QgsStringMap &headers );
void setSupportedFormats( const QString &formats ) { mSupportedFormats = formats; }
QString supportedFormats() const { return mSupportedFormats; }

private:

QString mSupportedFormats;
};


@@ -118,15 +118,18 @@ QgsArcGisRestSourceSelect::~QgsArcGisRestSourceSelect()
{
}

void QgsArcGisRestSourceSelect::populateImageEncodings( const QStringList &availableEncodings )
void QgsArcGisRestSourceSelect::populateImageEncodings( const QString &formats )
{
const QStringList availableEncodings = formats.split( ',' );

const QString prevFormat = getSelectedImageEncoding();

QLayoutItem *item = nullptr;
while ( ( item = gbImageEncoding->layout()->takeAt( 0 ) ) )
{
delete item->widget();
delete item;
}
bool first = true;
const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
for ( const QString &encoding : availableEncodings )
{
@@ -144,11 +147,13 @@ void QgsArcGisRestSourceSelect::populateImageEncodings( const QStringList &avail
}

QRadioButton *button = new QRadioButton( encoding, this );
button->setChecked( first );
if ( encoding == prevFormat )
button->setChecked( true );
gbImageEncoding->layout()->addWidget( button );
mImageEncodingGroup->addButton( button );
first = false;
}
if ( !mImageEncodingGroup->checkedButton() && !mImageEncodingGroup->buttons().empty() )
mImageEncodingGroup->buttons().value( 0 )->setChecked( true );
}

QString QgsArcGisRestSourceSelect::getSelectedImageEncoding() const
@@ -372,6 +377,7 @@ void QgsArcGisRestSourceSelect::addButtonClicked()
}
else if ( qobject_cast< QgsArcGisMapServiceLayerItem *>( layerItem ) )
{
uri.removeParam( QStringLiteral( "format" ) );
uri.setParam( QStringLiteral( "format" ), getSelectedImageEncoding() );
emit addRasterLayer( uri.uri( false ), layerName, QStringLiteral( "arcgismapserver" ) );
}
@@ -382,7 +388,6 @@ void QgsArcGisRestSourceSelect::addButtonClicked()

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() )
@@ -406,6 +411,25 @@ void QgsArcGisRestSourceSelect::updateCrsLabel()
}
}

void QgsArcGisRestSourceSelect::updateImageEncodings()
{
//evaluate currently selected typename and set the CRS filter in mProjectionSelector
QModelIndex currentIndex = mBrowserView->selectionModel()->currentIndex();
if ( currentIndex.isValid() )
{
const QModelIndex sourceIndex = mProxyModel->mapToSource( currentIndex );
if ( !sourceIndex.isValid() )
{
return;
}

if ( QgsArcGisMapServiceLayerItem *layerItem = qobject_cast< QgsArcGisMapServiceLayerItem * >( mBrowserModel->dataItem( sourceIndex ) ) )
{
populateImageEncodings( layerItem->supportedFormats() );
}
}
}

void QgsArcGisRestSourceSelect::cmbConnections_activated( int index )
{
Q_UNUSED( index )
@@ -424,6 +448,8 @@ void QgsArcGisRestSourceSelect::treeWidgetCurrentRowChanged( const QModelIndex &
Q_UNUSED( previous )
QgsDebugMsg( QStringLiteral( "treeWidget_currentRowChanged called" ) );
updateCrsLabel();
updateImageEncodings();

if ( mServiceType == FeatureService )
{
mBuildQueryButton->setEnabled( current.isValid() );
@@ -91,25 +91,16 @@ class QgsArcGisRestSourceSelect : public QgsAbstractDataSourceWidget, protected
//! May be implemented in child classes for services which support customized queries.
virtual void buildQuery( const QgsOwsConnection &, const QModelIndex & ) {}
//! To be implemented in the child class. Constructs an URI for the specified service layer.
virtual QString getLayerURI( const QgsOwsConnection &connection,
const QString &layerTitle,
const QString &layerName,
const QString &crs = QString(),
const QString &filter = QString(),
const QgsRectangle &bBox = QgsRectangle(),
const QString &layerId = QString() ) const = 0;

//! Updates the UI for the list of available image encodings from the specified list.
void populateImageEncodings( const QStringList &availableEncodings );
void populateImageEncodings( const QString &supportedFormats );
//! Returns the selected image encoding.
QString getSelectedImageEncoding() const;
void showEvent( QShowEvent *event ) override;

private:
void populateConnectionList();

//! A layer is added from the dialog
virtual void addServiceLayer( QString uri, QString typeName ) = 0;

public slots:

//! Triggered when the provider's connections need to be refreshed
@@ -122,6 +113,7 @@ class QgsArcGisRestSourceSelect : public QgsAbstractDataSourceWidget, protected
void addButtonClicked() override;
void buildQueryButtonClicked();
void updateCrsLabel();
void updateImageEncodings();
void connectToServer();
void disconnectFromServer();
void filterChanged( const QString &text );

0 comments on commit 33a607b

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