34
34
#include < QPicture>
35
35
#include < QSettings>
36
36
#include < QButtonGroup>
37
+ #include < QMap>
38
+ #include < QImageReader>
37
39
38
40
#include < iostream>
39
41
@@ -52,19 +54,40 @@ QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, Qt
52
54
// Qt Designer 4.1 doesn't let us use a QButtonGroup, so it has to
53
55
// be done manually... Unless I'm missing something, it's a whole
54
56
// lot harder to do groups of radio buttons in Qt4 than Qt3.
55
- m_imageFormatBtns = new QButtonGroup;
56
- // Populate it with a couple of buttons
57
- QRadioButton* btn1 = new QRadioButton (tr (" PNG" ));
58
- QRadioButton* btn2 = new QRadioButton (tr (" JPEG" ));
59
- m_imageFormatBtns->addButton (btn1, 1 );
60
- m_imageFormatBtns->addButton (btn2, 2 );
61
- btn1->setChecked (true );
62
- // And lay then out horizontally
63
- QHBoxLayout *hbox = new QHBoxLayout;
64
- hbox->addWidget (btn1);
65
- hbox->addWidget (btn2);
66
- hbox->addStretch ();
67
- btnGrpImageEncoding->setLayout (hbox);
57
+ m_imageFormatGroup = new QButtonGroup;
58
+ m_imageFormatLayout = new QHBoxLayout;
59
+ // Populate it with buttons for all of the formats that we can support. The
60
+ // value is the user visible name, and a unique integer, and the key is the
61
+ // mime type.
62
+ QMap<QString, QPair<QString, int > > formats;
63
+ // Note - the "PNG", etc text should match the Qt format strings as given by
64
+ // a called QImageReader::supportedImageFormats(), but case doesn't matter
65
+ m_PotentialFormats.insert (" image/png" , qMakePair (QString (" PNG" ), 1 ));
66
+ m_PotentialFormats.insert (" image/jpeg" , qMakePair (QString (" JPEG" ), 2 ));
67
+ m_PotentialFormats.insert (" image/gif" , qMakePair (QString (" GIF" ), 4 ));
68
+ // Desipte the Qt docs saying that it supports bmp, it practise it doesn't work...
69
+ // m_PotentialFormats.insert("image/wbmp", qMakePair(QString("BMP"), 5));
70
+ // Some wms servers will support tiff, but by default Qt doesn't, but leave
71
+ // this in for those versions of Qt that might support tiff
72
+ m_PotentialFormats.insert (" image/tiff" , qMakePair (QString (" TIFF" ), 6 ));
73
+
74
+ QMap<QString, QPair<QString, int > >::const_iterator iter = m_PotentialFormats.constBegin ();
75
+ int i = 1 ;
76
+ while (iter != m_PotentialFormats.end ())
77
+ {
78
+ QRadioButton* btn = new QRadioButton (iter.value ().first );
79
+ m_imageFormatGroup->addButton (btn, iter.value ().second );
80
+ m_imageFormatLayout->addWidget (btn);
81
+ if (i ==1 )
82
+ {
83
+ btn->setChecked (true );
84
+ }
85
+ iter++;
86
+ i++;
87
+ }
88
+
89
+ m_imageFormatLayout->addStretch ();
90
+ btnGrpImageEncoding->setLayout (m_imageFormatLayout);
68
91
69
92
// set up the WMS connections we already know about
70
93
populateConnectionList ();
@@ -225,61 +248,59 @@ void QgsServerSourceSelect::populateImageEncodingGroup(QgsWmsProvider* wmsProvid
225
248
//
226
249
// Remove old group of buttons
227
250
//
228
- QList<QAbstractButton*> btns = m_imageFormatBtns->buttons ();
229
- QList<QAbstractButton*>::const_iterator iter = btns.begin ();
230
- for (; iter != btns.end (); ++iter)
251
+ QList<QAbstractButton*> btns = m_imageFormatGroup->buttons ();
252
+ for (int i = 0 ; i < btns.count (); ++i)
231
253
{
232
- m_imageFormatBtns->removeButton (*iter);
233
- // Should the buttons be deleted too?
254
+ btns.at (i)->hide ();
234
255
}
235
256
236
- m_MimeTypeForButtonId.clear ();
237
-
238
257
//
239
258
// Collect capabilities reported by Qt itself
240
259
//
241
- QStringList qtImageFormats = QPicture::inputFormatList ();
260
+ QList<QByteArray> qtImageFormats = QImageReader::supportedImageFormats ();
242
261
243
- QStringList::Iterator it = qtImageFormats.begin ();
262
+ QList<QByteArray>::const_iterator it = qtImageFormats.begin ();
244
263
while ( it != qtImageFormats.end () )
245
264
{
246
- std::cout << " QgsServerSourceSelect::populateImageEncodingGroup: can support input of '" << (*it).toLocal8Bit ().data () << " '." << std::endl;
265
+ #ifdef QGISDEBUG
266
+ std::cout << " QgsServerSourceSelect::populateImageEncodingGroup: can support input of '" << (*it).data () << " '." << std::endl;
267
+ #endif
247
268
++it;
248
269
}
249
270
271
+
250
272
//
251
273
// Add new group of buttons
252
274
//
253
275
254
- int i = 1 ;
276
+ bool first = true ;
255
277
for (QStringList::Iterator format = formats.begin ();
256
278
format != formats.end ();
257
279
++format)
258
280
{
259
-
260
281
#ifdef QGISDEBUG
261
- std::cout << " QgsServerSourceSelect::populateImageEncodingGroup: got image format " << (*format).toLocal8Bit ().data () << " ." << std::endl;
282
+ std::cout << " QgsServerSourceSelect::populateImageEncodingGroup: got image format " << (*format).toLocal8Bit ().data () << " ." << std::endl;
262
283
#endif
263
284
264
- QRadioButton* radioButton = new QRadioButton;
265
- m_imageFormatBtns-> addButton (radioButton, i );
285
+ QMap<QString, QPair<QString, int > >::const_iterator iter =
286
+ m_PotentialFormats. find (*format );
266
287
267
- if ((*format) == " image/png" )
288
+ // The formats in qtImageFormats are lowercase, so force ours to lowercase too.
289
+ if (iter != m_PotentialFormats.end () &&
290
+ qtImageFormats.contains (iter.value ().first .toLower ().toLocal8Bit ()))
268
291
{
269
- radioButton->setText (tr (" PNG" ));
292
+ m_imageFormatGroup->button (iter.value ().second )->show ();
293
+ if (first)
294
+ {
295
+ first = false ;
296
+ m_imageFormatGroup->button (iter.value ().second )->setChecked (true );
297
+ }
270
298
}
271
- else if ((*format) == " image/jpeg " )
299
+ else
272
300
{
273
- radioButton-> setText ( tr ( " JPEG " )) ;
301
+ std::cerr<< " Unsupported type of " << format-> toLocal8Bit (). data () << ' \n ' ;
274
302
}
275
-
276
- m_imageFormatBtns->addButton (radioButton);
277
-
278
- m_MimeTypeForButtonId[i] = (*format);
279
-
280
- i++;
281
303
}
282
-
283
304
}
284
305
285
306
@@ -390,6 +411,7 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
390
411
{
391
412
showError (mWmsProvider );
392
413
}
414
+ populateImageEncodingGroup (mWmsProvider );
393
415
}
394
416
else
395
417
{
@@ -570,15 +592,14 @@ QString QgsServerSourceSelect::selectedImageEncoding()
570
592
{
571
593
// TODO: Match this hard coded list to the list of formats Qt reports it can actually handle.
572
594
573
- QAbstractButton* checked = m_imageFormatBtns->checkedButton ();
595
+ int id = m_imageFormatGroup->checkedId ();
596
+ QString label = m_imageFormatGroup->button (id)->text ();
574
597
575
- if (checked->text () == tr (" PNG" ))
576
- return " image/png" ;
577
- else if (checked->text () == tr (" JPEG" ))
578
- return " image/jpeg" ;
579
- else // Worst-case scenario - fall back to PNG
580
- return " image/png" ;
598
+ // The way that we construct the buttons, this call to key() will never have
599
+ // a value that isn't in the map, hence we don't need to check for the value
600
+ // not being found.
581
601
602
+ return m_PotentialFormats.key (qMakePair (label, id));
582
603
}
583
604
584
605
0 commit comments