@@ -120,57 +120,111 @@ QgsOWSSourceSelect::~QgsOWSSourceSelect()
120
120
settings.setValue ( " /Windows/WMSSourceSelect/geometry" , saveGeometry () );
121
121
}
122
122
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
+
123
132
void QgsOWSSourceSelect::populateFormats ()
124
133
{
125
134
QgsDebugMsg ( " entered" );
126
- if ( mProviderFormats .size () == 0 )
127
- {
128
- QHBoxLayout *layout = new QHBoxLayout;
129
135
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
131
139
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 ();
136
141
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;
144
146
mImageFormatsGroupBox ->setLayout ( layout );
147
+ layout->addStretch ();
145
148
}
146
149
147
- // Show supported by server only
148
- foreach ( QAbstractButton *b, mImageFormatGroup ->buttons () )
150
+ if ( mProviderFormats .size () == 0 )
149
151
{
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
+ }
151
158
}
152
159
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 );
156
178
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 )
159
190
{
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
162
194
}
195
+ btn->setVisible ( true );
163
196
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 ) )
171
198
{
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" );
173
219
}
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 );
174
228
}
175
229
176
230
mImageFormatsGroupBox ->setEnabled ( true );
@@ -300,6 +354,10 @@ void QgsOWSSourceSelect::populateLayerList( )
300
354
void QgsOWSSourceSelect::on_mConnectButton_clicked ()
301
355
{
302
356
QgsDebugMsg ( " entered" );
357
+
358
+ mLayersTreeWidget ->clear ();
359
+ clearFormats ();
360
+
303
361
mConnName = mConnectionsComboBox ->currentText ();
304
362
305
363
QgsOWSConnection connection ( mService , mConnectionsComboBox ->currentText () );
@@ -455,7 +513,7 @@ QString QgsOWSSourceSelect::selectedFormat()
455
513
{
456
514
// TODO: do format in subclass (WMS)
457
515
// return QUrl::toPercentEncoding( mProviderFormats[ id ].format );
458
- return mProviderFormats [ id ]. format ;
516
+ return selectedLayersFormats (). value ( id ) ;
459
517
}
460
518
}
461
519
0 commit comments