Permalink
Browse files

Better formats in QgsOWSSourceSelect

  • Loading branch information...
1 parent 678147c commit 988a7da13cb0a83a81242058c03e504023ec73ee @blazek blazek committed May 2, 2012
Showing with 106 additions and 48 deletions.
  1. +92 −34 src/gui/qgsowssourceselect.cpp
  2. +9 −6 src/gui/qgsowssourceselect.h
  3. +5 −8 src/providers/gdal/qgswcscapabilities.cpp
View
126 src/gui/qgsowssourceselect.cpp
@@ -120,57 +120,111 @@ QgsOWSSourceSelect::~QgsOWSSourceSelect()
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()
{
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
- for ( int i = 0; i < mProviderFormats.size(); i++ )
- {
- mMimeMap.insert( mProviderFormats[i].format, i );
+ clearFormats();
- QRadioButton *btn = new QRadioButton( mProviderFormats[i].label );
- btn->setToolTip( mProviderFormats[i].format );
- mImageFormatGroup->addButton( btn, i );
- layout->addWidget( btn );
- }
-
- layout->addStretch();
+ QHBoxLayout *layout = dynamic_cast<QHBoxLayout*>( mImageFormatsGroupBox->layout() );
+ if ( !layout )
+ {
+ layout = new QHBoxLayout;
mImageFormatsGroupBox->setLayout( layout );
+ layout->addStretch();
}
- // Show supported by server only
- foreach( QAbstractButton *b, mImageFormatGroup->buttons() )
+ if ( mProviderFormats.size() == 0 )
{
- 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;
- foreach( QString format, selectedLayersFormats() )
- {
+ // selectedLayersFormats may come in various forms:
+ // 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 );
- int id = mMimeMap.value( format, -1 );
- if ( id < 0 )
+ QString simpleFormat = format.toLower().replace( "image/", "" );
+ 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 ) );
- continue;
+ btn = new QRadioButton( label );
+ mImageFormatGroup->addButton( btn, i );
+ layout->insertWidget( layout->count() - 1, btn ); // before stretch
}
+ btn->setVisible( true );
- mImageFormatGroup->button( id )->setVisible( true );
- 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 )
+ if ( mMimeLabelMap.contains( mimeFormat ) )
{
- 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 );
@@ -300,6 +354,10 @@ void QgsOWSSourceSelect::populateLayerList( )
void QgsOWSSourceSelect::on_mConnectButton_clicked()
{
QgsDebugMsg( "entered" );
+
+ mLayersTreeWidget->clear();
+ clearFormats();
+
mConnName = mConnectionsComboBox->currentText();
QgsOWSConnection connection( mService, mConnectionsComboBox->currentText() );
@@ -455,7 +513,7 @@ QString QgsOWSSourceSelect::selectedFormat()
{
// TODO: do format in subclass (WMS)
//return QUrl::toPercentEncoding( mProviderFormats[ id ].format );
- return mProviderFormats[ id ].format;
+ return selectedLayersFormats().value( id );
}
}
View
15 src/gui/qgsowssourceselect.h
@@ -5,7 +5,7 @@
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
generalized : (C) 2012 Radim Blazek, based on qgsowsconnection.h
-
+
***************************************************************************/
/***************************************************************************
@@ -115,7 +115,7 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
/**
* List of image formats (encodings) supported by provider
* @return list of format/label pairs
- */
+ */
virtual QList<QgsOWSSupportedFormat> providerFormats();
//! List of formats supported for currently selected layer item(s)
@@ -132,7 +132,10 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
//! Populate supported formats
void populateFormats();
- //! Set supported CRSs
+ //! Clear previously set formats
+ void clearFormats();
+
+ //! Set supported CRSs
void populateCRS();
//! Connection name
@@ -160,7 +163,7 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
/**
* \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( );
@@ -218,8 +221,8 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
//! Supported formats
QList<QgsOWSSupportedFormat> mProviderFormats;
- //! Map mime types to supported formats
- QMap<QString, int> mMimeMap;
+ //! Map mime type labels to supported formats
+ QMap<QString, QString> mMimeLabelMap;
private slots:
void on_mSearchButton_clicked();
View
13 src/providers/gdal/qgswcscapabilities.cpp
@@ -645,12 +645,8 @@ bool QgsWcsCapabilities::parseDescribeCoverageDom( QByteArray const &xml, QgsWcs
if ( tagName == "formats" )
{
- // TODO: map other formats to GDAL mime types
- QString format = el.text().toLower();
- if ( format == "geotiff" || format == "gtiff" || format == "tiff" || format == "tif" )
- {
- coverage->supportedFormat << "image/tiff";
- }
+ // may be GTiff, GeoTIFF, TIFF, GIF, ....
+ coverage->supportedFormat << el.text();
}
}
n1 = n1.nextSibling();
@@ -724,6 +720,7 @@ void QgsWcsCapabilities::parseCoverageSummary( QDomElement const & e, QgsWcsCove
if ( tagName == "SupportedFormat" )
{
+ // image/tiff, ...
coverageSummary.supportedFormat << el.text();
}
else if ( tagName == "SupportedCRS" )
@@ -848,7 +845,7 @@ void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& te
QgsWcsCoverageSummary* QgsWcsCapabilities::coverageSummary( QString const & theIdentifier, QgsWcsCoverageSummary* parent )
{
- QgsDebugMsg( "theIdentifier = " + theIdentifier );
+ //QgsDebugMsg( "theIdentifier = " + theIdentifier );
if ( !parent )
{
parent = &( mCapabilities.contents );
@@ -857,7 +854,7 @@ QgsWcsCoverageSummary* QgsWcsCapabilities::coverageSummary( QString const & theI
//foreach( const QgsWcsCoverageSummary &c, parent->coverageSummary )
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 )
{
return c;

0 comments on commit 988a7da

Please sign in to comment.