Skip to content

Commit 45cf9dd

Browse files
author
g_j_m
committedMay 20, 2006
Provide the user with as many wms image formats as Qt and the WMS server
support in common. Sort of resolves ticket #118 git-svn-id: http://svn.osgeo.org/qgis/trunk@5478 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent fa510af commit 45cf9dd

File tree

3 files changed

+72
-50
lines changed

3 files changed

+72
-50
lines changed
 

‎src/gui/qgsserversourceselect.cpp

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include <QPicture>
3535
#include <QSettings>
3636
#include <QButtonGroup>
37+
#include <QMap>
38+
#include <QImageReader>
3739

3840
#include <iostream>
3941

@@ -52,19 +54,40 @@ QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, Qt
5254
// Qt Designer 4.1 doesn't let us use a QButtonGroup, so it has to
5355
// be done manually... Unless I'm missing something, it's a whole
5456
// 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);
6891

6992
// set up the WMS connections we already know about
7093
populateConnectionList();
@@ -225,61 +248,59 @@ void QgsServerSourceSelect::populateImageEncodingGroup(QgsWmsProvider* wmsProvid
225248
//
226249
// Remove old group of buttons
227250
//
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)
231253
{
232-
m_imageFormatBtns->removeButton(*iter);
233-
// Should the buttons be deleted too?
254+
btns.at(i)->hide();
234255
}
235256

236-
m_MimeTypeForButtonId.clear();
237-
238257
//
239258
// Collect capabilities reported by Qt itself
240259
//
241-
QStringList qtImageFormats = QPicture::inputFormatList();
260+
QList<QByteArray> qtImageFormats = QImageReader::supportedImageFormats();
242261

243-
QStringList::Iterator it = qtImageFormats.begin();
262+
QList<QByteArray>::const_iterator it = qtImageFormats.begin();
244263
while( it != qtImageFormats.end() )
245264
{
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
247268
++it;
248269
}
249270

271+
250272
//
251273
// Add new group of buttons
252274
//
253275

254-
int i = 1;
276+
bool first = true;
255277
for (QStringList::Iterator format = formats.begin();
256278
format != formats.end();
257279
++format)
258280
{
259-
260281
#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;
262283
#endif
263284

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);
266287

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()))
268291
{
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+
}
270298
}
271-
else if ((*format) == "image/jpeg")
299+
else
272300
{
273-
radioButton->setText(tr("JPEG"));
301+
std::cerr<<"Unsupported type of " << format->toLocal8Bit().data() << '\n';
274302
}
275-
276-
m_imageFormatBtns->addButton(radioButton);
277-
278-
m_MimeTypeForButtonId[i] = (*format);
279-
280-
i++;
281303
}
282-
283304
}
284305

285306

@@ -390,6 +411,7 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
390411
{
391412
showError(mWmsProvider);
392413
}
414+
populateImageEncodingGroup(mWmsProvider);
393415
}
394416
else
395417
{
@@ -570,15 +592,14 @@ QString QgsServerSourceSelect::selectedImageEncoding()
570592
{
571593
// TODO: Match this hard coded list to the list of formats Qt reports it can actually handle.
572594

573-
QAbstractButton* checked = m_imageFormatBtns->checkedButton();
595+
int id = m_imageFormatGroup->checkedId();
596+
QString label = m_imageFormatGroup->button(id)->text();
574597

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.
581601

602+
return m_PotentialFormats.key(qMakePair(label, id));
582603
}
583604

584605

‎src/gui/qgsserversourceselect.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ public slots:
135135

136136
std::map<QString, QString> m_selectedStyleIdForLayer;
137137

138-
//! What MIME type corresponds to the Button ID in btnGrpImageEncoding?
139-
std::vector<QString> m_MimeTypeForButtonId;
138+
//! The mime type, the text to use in the button and a unique number
139+
QMap<QString, QPair<QString, int> > m_PotentialFormats;
140140

141141
//! Pointer to the qgis application mainwindow
142142
QgisApp *qgisApp;
143143

144144
//! The widget that controls the image format radio buttons
145-
QButtonGroup* m_imageFormatBtns;
145+
QButtonGroup* m_imageFormatGroup;
146+
QHBoxLayout* m_imageFormatLayout;
146147

147148
//! The WMS provider that retreives information for this dialog
148149
QgsWmsProvider * mWmsProvider;

‎src/ui/qgsserversourceselectbase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<property name="minimumSize" >
9090
<size>
9191
<width>16</width>
92-
<height>30</height>
92+
<height>60</height>
9393
</size>
9494
</property>
9595
<property name="title" >

0 commit comments

Comments
 (0)