Skip to content

Commit 988a7da

Browse files
committed
Better formats in QgsOWSSourceSelect
1 parent 678147c commit 988a7da

File tree

3 files changed

+106
-48
lines changed

3 files changed

+106
-48
lines changed

src/gui/qgsowssourceselect.cpp

+92-34
Original file line numberDiff line numberDiff line change
@@ -120,57 +120,111 @@ QgsOWSSourceSelect::~QgsOWSSourceSelect()
120120
settings.setValue( "/Windows/WMSSourceSelect/geometry", saveGeometry() );
121121
}
122122

123+
void QgsOWSSourceSelect::clearFormats()
124+
{
125+
int i = 0;
126+
while ( QRadioButton *btn = dynamic_cast<QRadioButton*>( mImageFormatGroup->button( i++ ) ) )
127+
{
128+
btn->setVisible( false );
129+
}
130+
}
131+
123132
void QgsOWSSourceSelect::populateFormats()
124133
{
125134
QgsDebugMsg( "entered" );
126-
if ( mProviderFormats.size() == 0 )
127-
{
128-
QHBoxLayout *layout = new QHBoxLayout;
129135

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

132-
// add buttons for available formats
133-
for ( int i = 0; i < mProviderFormats.size(); i++ )
134-
{
135-
mMimeMap.insert( mProviderFormats[i].format, i );
140+
clearFormats();
136141

137-
QRadioButton *btn = new QRadioButton( mProviderFormats[i].label );
138-
btn->setToolTip( mProviderFormats[i].format );
139-
mImageFormatGroup->addButton( btn, i );
140-
layout->addWidget( btn );
141-
}
142-
143-
layout->addStretch();
142+
QHBoxLayout *layout = dynamic_cast<QHBoxLayout*>( mImageFormatsGroupBox->layout() );
143+
if ( !layout )
144+
{
145+
layout = new QHBoxLayout;
144146
mImageFormatsGroupBox->setLayout( layout );
147+
layout->addStretch();
145148
}
146149

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

153-
int firstVisible = -1;
154-
foreach( QString format, selectedLayersFormats() )
155-
{
160+
// selectedLayersFormats may come in various forms:
161+
// image/tiff, GTiff, GeoTIFF, TIFF, PNG, GTOPO30, ARCGRID, IMAGEMOSAIC ...
162+
QMap<QString, QString> formatsMap;
163+
formatsMap.insert( "geotiff", "tiff" );
164+
formatsMap.insert( "gtiff", "tiff" );
165+
formatsMap.insert( "tiff", "tiff" );
166+
formatsMap.insert( "tif", "tiff" );
167+
formatsMap.insert( "gif", "gif" );
168+
formatsMap.insert( "jpeg", "jpeg" );
169+
formatsMap.insert( "jpg", "jpeg" );
170+
formatsMap.insert( "png", "png" );
171+
172+
int prefered = -1;
173+
int firstEnabled = -1;
174+
QStringList layersFormats = selectedLayersFormats();
175+
for ( int i = 0; i < layersFormats.size(); i++ )
176+
{
177+
QString format = layersFormats.value( i );
156178
QgsDebugMsg( "server format = " + format );
157-
int id = mMimeMap.value( format, -1 );
158-
if ( id < 0 )
179+
QString simpleFormat = format.toLower().replace( "image/", "" );
180+
QgsDebugMsg( "server simpleFormat = " + simpleFormat );
181+
QString mimeFormat = "image/" + formatsMap.value( simpleFormat );
182+
QgsDebugMsg( "server mimeFormat = " + mimeFormat );
183+
184+
QString label = format;
185+
QString tip = tr( "Server format" ) + " " + format;
186+
187+
QRadioButton *btn;
188+
btn = dynamic_cast<QRadioButton*>( mImageFormatGroup->button( i ) );
189+
if ( !btn )
159190
{
160-
QgsDebugMsg( QString( "format %1 not supported." ).arg( format ) );
161-
continue;
191+
btn = new QRadioButton( label );
192+
mImageFormatGroup->addButton( btn, i );
193+
layout->insertWidget( layout->count() - 1, btn ); // before stretch
162194
}
195+
btn->setVisible( true );
163196

164-
mImageFormatGroup->button( id )->setVisible( true );
165-
if ( firstVisible == -1 ) firstVisible = id;
166-
}
167-
// Set first if no one visible is checked
168-
if ( mImageFormatGroup->checkedId() < 0 || !mImageFormatGroup->button( mImageFormatGroup->checkedId() )->isVisible() )
169-
{
170-
if ( firstVisible > -1 )
197+
if ( mMimeLabelMap.contains( mimeFormat ) )
171198
{
172-
mImageFormatGroup->button( firstVisible )->setChecked( true );
199+
btn->setEnabled( true );
200+
if ( format != mMimeLabelMap.value( mimeFormat ) )
201+
{
202+
label += " / " + mMimeLabelMap.value( mimeFormat );
203+
}
204+
tip += " " + tr( "is supported by GDAL %1 driver." ).arg( mMimeLabelMap.value( mimeFormat ) );
205+
if ( firstEnabled < 0 ) { firstEnabled = i; }
206+
if ( simpleFormat.contains( "tif" ) ) // prefer *tif*
207+
{
208+
if ( prefered < 0 || simpleFormat.startsWith( "g" ) ) // prefere geotiff
209+
{
210+
prefered = i;
211+
}
212+
}
213+
}
214+
else
215+
{
216+
QgsDebugMsg( QString( "format %1 not supported." ).arg( format ) );
217+
btn->setEnabled( false );
218+
tip += " " + tr( "is not supported by GDAL" );
173219
}
220+
btn->setText( label );
221+
btn->setToolTip( tip );
222+
}
223+
// Set prefered
224+
prefered = prefered >= 0 ? prefered : firstEnabled;
225+
if ( prefered >= 0 )
226+
{
227+
mImageFormatGroup->button( prefered )->setChecked( true );
174228
}
175229

176230
mImageFormatsGroupBox->setEnabled( true );
@@ -300,6 +354,10 @@ void QgsOWSSourceSelect::populateLayerList( )
300354
void QgsOWSSourceSelect::on_mConnectButton_clicked()
301355
{
302356
QgsDebugMsg( "entered" );
357+
358+
mLayersTreeWidget->clear();
359+
clearFormats();
360+
303361
mConnName = mConnectionsComboBox->currentText();
304362

305363
QgsOWSConnection connection( mService, mConnectionsComboBox->currentText() );
@@ -455,7 +513,7 @@ QString QgsOWSSourceSelect::selectedFormat()
455513
{
456514
// TODO: do format in subclass (WMS)
457515
//return QUrl::toPercentEncoding( mProviderFormats[ id ].format );
458-
return mProviderFormats[ id ].format;
516+
return selectedLayersFormats().value( id );
459517
}
460518
}
461519

src/gui/qgsowssourceselect.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au
66
wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG
77
generalized : (C) 2012 Radim Blazek, based on qgsowsconnection.h
8-
8+
99
***************************************************************************/
1010

1111
/***************************************************************************
@@ -115,7 +115,7 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
115115
/**
116116
* List of image formats (encodings) supported by provider
117117
* @return list of format/label pairs
118-
*/
118+
*/
119119
virtual QList<QgsOWSSupportedFormat> providerFormats();
120120

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

135-
//! Set supported CRSs
135+
//! Clear previously set formats
136+
void clearFormats();
137+
138+
//! Set supported CRSs
136139
void populateCRS();
137140

138141
//! Connection name
@@ -160,7 +163,7 @@ class QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSelectBase
160163
/**
161164
* \brief Populate the layer list.
162165
*
163-
* \retval false if the layers could not be retrieved or parsed
166+
* \retval false if the layers could not be retrieved or parsed
164167
*/
165168
virtual void populateLayerList( );
166169

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

221-
//! Map mime types to supported formats
222-
QMap<QString, int> mMimeMap;
224+
//! Map mime type labels to supported formats
225+
QMap<QString, QString> mMimeLabelMap;
223226

224227
private slots:
225228
void on_mSearchButton_clicked();

src/providers/gdal/qgswcscapabilities.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,8 @@ bool QgsWcsCapabilities::parseDescribeCoverageDom( QByteArray const &xml, QgsWcs
645645

646646
if ( tagName == "formats" )
647647
{
648-
// TODO: map other formats to GDAL mime types
649-
QString format = el.text().toLower();
650-
if ( format == "geotiff" || format == "gtiff" || format == "tiff" || format == "tif" )
651-
{
652-
coverage->supportedFormat << "image/tiff";
653-
}
648+
// may be GTiff, GeoTIFF, TIFF, GIF, ....
649+
coverage->supportedFormat << el.text();
654650
}
655651
}
656652
n1 = n1.nextSibling();
@@ -724,6 +720,7 @@ void QgsWcsCapabilities::parseCoverageSummary( QDomElement const & e, QgsWcsCove
724720

725721
if ( tagName == "SupportedFormat" )
726722
{
723+
// image/tiff, ...
727724
coverageSummary.supportedFormat << el.text();
728725
}
729726
else if ( tagName == "SupportedCRS" )
@@ -848,7 +845,7 @@ void QgsWcsCapabilities::showMessageBox( const QString& title, const QString& te
848845

849846
QgsWcsCoverageSummary* QgsWcsCapabilities::coverageSummary( QString const & theIdentifier, QgsWcsCoverageSummary* parent )
850847
{
851-
QgsDebugMsg( "theIdentifier = " + theIdentifier );
848+
//QgsDebugMsg( "theIdentifier = " + theIdentifier );
852849
if ( !parent )
853850
{
854851
parent = &( mCapabilities.contents );
@@ -857,7 +854,7 @@ QgsWcsCoverageSummary* QgsWcsCapabilities::coverageSummary( QString const & theI
857854
//foreach( const QgsWcsCoverageSummary &c, parent->coverageSummary )
858855
for ( QVector<QgsWcsCoverageSummary>::iterator c = parent->coverageSummary.begin(); c != parent->coverageSummary.end(); ++c )
859856
{
860-
QgsDebugMsg( "c->identifier = " + c->identifier );
857+
//QgsDebugMsg( "c->identifier = " + c->identifier );
861858
if ( c->identifier == theIdentifier )
862859
{
863860
return c;

0 commit comments

Comments
 (0)