Skip to content

Commit

Permalink
Better formats in QgsOWSSourceSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed May 2, 2012
1 parent 678147c commit 988a7da
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 48 deletions.
126 changes: 92 additions & 34 deletions src/gui/qgsowssourceselect.cpp
Expand Up @@ -120,57 +120,111 @@ QgsOWSSourceSelect::~QgsOWSSourceSelect()
settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() ); settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() );
} }


void QgsOWSSourceSelect::clearFormats()
{
int i = 0;
while ( QRadioButton *btn = dynamic_cast<QRadioButton*>( mImageFormatGroup->button( i++ ) ) )
{
btn->setVisible( false );
}
}

void QgsOWSSourceSelect::populateFormats() void QgsOWSSourceSelect::populateFormats()
{ {
QgsDebugMsg( "entered" ); QgsDebugMsg( "entered" );
if ( mProviderFormats.size() == 0 )
{
QHBoxLayout *layout = new QHBoxLayout;


mProviderFormats = providerFormats(); // A server may offer more similar formats, which are mapped
// to the same GDAL format, e.g. GeoTIFF and TIFF
// -> recreate always buttons for all available formats, enable supported


// add buttons for available formats clearFormats();
for ( int i = 0; i < mProviderFormats.size(); i++ )
{
mMimeMap.insert( mProviderFormats[i].format, i );


QRadioButton *btn = new QRadioButton( mProviderFormats[i].label ); QHBoxLayout *layout = dynamic_cast<QHBoxLayout*>( mImageFormatsGroupBox->layout() );
btn->setToolTip( mProviderFormats[i].format ); if ( !layout )
mImageFormatGroup->addButton( btn, i ); {
layout->addWidget( btn ); layout = new QHBoxLayout;
}

layout->addStretch();
mImageFormatsGroupBox->setLayout( layout ); mImageFormatsGroupBox->setLayout( layout );
layout->addStretch();
} }


// Show supported by server only if ( mProviderFormats.size() == 0 )
foreach( QAbstractButton *b, mImageFormatGroup->buttons() )
{ {
b->setHidden( true ); mProviderFormats = providerFormats();
for ( int i = 0; i < mProviderFormats.size(); i++ )
{
// GDAL mime types may be image/tiff, image/png, ...
mMimeLabelMap.insert( mProviderFormats[i].format, mProviderFormats[i].label );
}
} }


int firstVisible = -1; // selectedLayersFormats may come in various forms:
foreach( QString format, selectedLayersFormats() ) // image/tiff, GTiff, GeoTIFF, TIFF, PNG, GTOPO30, ARCGRID, IMAGEMOSAIC ...
{ QMap<QString, QString> formatsMap;
formatsMap.insert( "geotiff", "tiff" );
formatsMap.insert( "gtiff", "tiff" );
formatsMap.insert( "tiff", "tiff" );
formatsMap.insert( "tif", "tiff" );
formatsMap.insert( "gif", "gif" );
formatsMap.insert( "jpeg", "jpeg" );
formatsMap.insert( "jpg", "jpeg" );
formatsMap.insert( "png", "png" );

int prefered = -1;
int firstEnabled = -1;
QStringList layersFormats = selectedLayersFormats();
for ( int i = 0; i < layersFormats.size(); i++ )
{
QString format = layersFormats.value( i );
QgsDebugMsg( "server format = " + format ); QgsDebugMsg( "server format = " + format );
int id = mMimeMap.value( format, -1 ); QString simpleFormat = format.toLower().replace( "image/", "" );
if ( id < 0 ) QgsDebugMsg( "server simpleFormat = " + simpleFormat );
QString mimeFormat = "image/" + formatsMap.value( simpleFormat );
QgsDebugMsg( "server mimeFormat = " + mimeFormat );

QString label = format;
QString tip = tr( "Server format" ) + " " + format;

QRadioButton *btn;
btn = dynamic_cast<QRadioButton*>( mImageFormatGroup->button( i ) );
if ( !btn )
{ {
QgsDebugMsg( QString( "format %1 not supported." ).arg( format ) ); btn = new QRadioButton( label );
continue; mImageFormatGroup->addButton( btn, i );
layout->insertWidget( layout->count() - 1, btn ); // before stretch
} }
btn->setVisible( true );


mImageFormatGroup->button( id )->setVisible( true ); if ( mMimeLabelMap.contains( mimeFormat ) )
if ( firstVisible == -1 ) firstVisible = id;
}
// Set first if no one visible is checked
if ( mImageFormatGroup->checkedId() < 0 || !mImageFormatGroup->button( mImageFormatGroup->checkedId() )->isVisible() )
{
if ( firstVisible > -1 )
{ {
mImageFormatGroup->button( firstVisible )->setChecked( true ); btn->setEnabled( true );
if ( format != mMimeLabelMap.value( mimeFormat ) )
{
label += " / " + mMimeLabelMap.value( mimeFormat );
}
tip += " " + tr( "is supported by GDAL %1 driver." ).arg( mMimeLabelMap.value( mimeFormat ) );
if ( firstEnabled < 0 ) { firstEnabled = i; }
if ( simpleFormat.contains( "tif" ) ) // prefer *tif*
{
if ( prefered < 0 || simpleFormat.startsWith( "g" ) ) // prefere geotiff
{
prefered = i;
}
}
}
else
{
QgsDebugMsg( QString( "format %1 not supported." ).arg( format ) );
btn->setEnabled( false );
tip += " " + tr( "is not supported by GDAL" );
} }
btn->setText( label );
btn->setToolTip( tip );
}
// Set prefered
prefered = prefered >= 0 ? prefered : firstEnabled;
if ( prefered >= 0 )
{
mImageFormatGroup->button( prefered )->setChecked( true );
} }


mImageFormatsGroupBox->setEnabled( true ); mImageFormatsGroupBox->setEnabled( true );
Expand Down Expand Up @@ -300,6 +354,10 @@ void QgsOWSSourceSelect::populateLayerList( )
void QgsOWSSourceSelect::on_mConnectButton_clicked() void QgsOWSSourceSelect::on_mConnectButton_clicked()
{ {
QgsDebugMsg( "entered" ); QgsDebugMsg( "entered" );

mLayersTreeWidget->clear();
clearFormats();

mConnName = mConnectionsComboBox->currentText(); mConnName = mConnectionsComboBox->currentText();


QgsOWSConnection connection( mService, mConnectionsComboBox->currentText() ); QgsOWSConnection connection( mService, mConnectionsComboBox->currentText() );
Expand Down Expand Up @@ -455,7 +513,7 @@ QString QgsOWSSourceSelect::selectedFormat()
{ {
// TODO: do format in subclass (WMS) // TODO: do format in subclass (WMS)
//return QUrl::toPercentEncoding( mProviderFormats[ id ].format ); //return QUrl::toPercentEncoding( mProviderFormats[ id ].format );
return mProviderFormats[ id ].format; return selectedLayersFormats().value( id );
} }
} }


Expand Down
15 changes: 9 additions & 6 deletions src/gui/qgsowssourceselect.h
Expand Up @@ -5,7 +5,7 @@
original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au
wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG
generalized : (C) 2012 Radim Blazek, based on qgsowsconnection.h generalized : (C) 2012 Radim Blazek, based on qgsowsconnection.h
***************************************************************************/ ***************************************************************************/


/*************************************************************************** /***************************************************************************
Expand Down Expand Up @@ -115,7 +115,7 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
/** /**
* List of image formats (encodings) supported by provider * List of image formats (encodings) supported by provider
* @return list of format/label pairs * @return list of format/label pairs
*/ */
virtual QList<QgsOWSSupportedFormat> providerFormats(); virtual QList<QgsOWSSupportedFormat> providerFormats();


//! List of formats supported for currently selected layer item(s) //! List of formats supported for currently selected layer item(s)
Expand All @@ -132,7 +132,10 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
//! Populate supported formats //! Populate supported formats
void populateFormats(); void populateFormats();


//! Set supported CRSs //! Clear previously set formats
void clearFormats();

//! Set supported CRSs
void populateCRS(); void populateCRS();


//! Connection name //! Connection name
Expand Down Expand Up @@ -160,7 +163,7 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
/** /**
* \brief Populate the layer list. * \brief Populate the layer list.
* *
* \retval false if the layers could not be retrieved or parsed * \retval false if the layers could not be retrieved or parsed
*/ */
virtual void populateLayerList( ); virtual void populateLayerList( );


Expand Down Expand Up @@ -218,8 +221,8 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
//! Supported formats //! Supported formats
QList<QgsOWSSupportedFormat> mProviderFormats; QList<QgsOWSSupportedFormat> mProviderFormats;


//! Map mime types to supported formats //! Map mime type labels to supported formats
QMap<QString, int> mMimeMap; QMap<QString, QString> mMimeLabelMap;


private slots: private slots:
void on_mSearchButton_clicked(); void on_mSearchButton_clicked();
Expand Down
13 changes: 5 additions & 8 deletions src/providers/gdal/qgswcscapabilities.cpp
Expand Up @@ -645,12 +645,8 @@ bool QgsWcsCapabilities::parseDescribeCoverageDom( QByteArray const &xml, QgsWcs


if ( tagName == "formats" ) if ( tagName == "formats" )
{ {
// TODO: map other formats to GDAL mime types // may be GTiff, GeoTIFF, TIFF, GIF, ....
QString format = el.text().toLower(); coverage->supportedFormat << el.text();
if ( format == "geotiff" || format == "gtiff" || format == "tiff" || format == "tif" )
{
coverage->supportedFormat << "image/tiff";
}
} }
} }
n1 = n1.nextSibling(); n1 = n1.nextSibling();
Expand Down Expand Up @@ -724,6 +720,7 @@ void QgsWcsCapabilities::parseCoverageSummary( QDomElement const & e, QgsWcsCove


if ( tagName == "SupportedFormat" ) if ( tagName == "SupportedFormat" )
{ {
// image/tiff, ...
coverageSummary.supportedFormat << el.text(); coverageSummary.supportedFormat << el.text();
} }
else if ( tagName == "SupportedCRS" ) else if ( tagName == "SupportedCRS" )
Expand Down Expand Up @@ -848,7 +845,7 @@ void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& te


QgsWcsCoverageSummary* QgsWcsCapabilities::coverageSummary( QString const & theIdentifier, QgsWcsCoverageSummary* parent ) QgsWcsCoverageSummary* QgsWcsCapabilities::coverageSummary( QString const & theIdentifier, QgsWcsCoverageSummary* parent )
{ {
QgsDebugMsg( "theIdentifier = " + theIdentifier ); //QgsDebugMsg( "theIdentifier = " + theIdentifier );
if ( !parent ) if ( !parent )
{ {
parent = &( mCapabilities.contents ); parent = &( mCapabilities.contents );
Expand All @@ -857,7 +854,7 @@ QgsWcsCoverageSummary* QgsWcsCapabilities::coverageSummary( QString const & theI
//foreach( const QgsWcsCoverageSummary &c, parent->coverageSummary ) //foreach( const QgsWcsCoverageSummary &c, parent->coverageSummary )
for ( QVector<QgsWcsCoverageSummary>::iterator c = parent->coverageSummary.begin(); c != parent->coverageSummary.end(); ++c ) for ( QVector<QgsWcsCoverageSummary>::iterator c = parent->coverageSummary.begin(); c != parent->coverageSummary.end(); ++c )
{ {
QgsDebugMsg( "c->identifier = " + c->identifier ); //QgsDebugMsg( "c->identifier = " + c->identifier );
if ( c->identifier == theIdentifier ) if ( c->identifier == theIdentifier )
{ {
return c; return c;
Expand Down

0 comments on commit 988a7da

Please sign in to comment.