Skip to content

Commit

Permalink
Migrate from Qt3 widgets to Qt4 widgets.
Browse files Browse the repository at this point in the history
Had to implement some UI stuff manually as Qt4 does less for the 
programmer that Qt3 (for button groups).


git-svn-id: http://svn.osgeo.org/qgis/trunk@4683 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Jan 14, 2006
1 parent 51c488b commit cce957c
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 284 deletions.
47 changes: 32 additions & 15 deletions src/gui/qgsserversourceselect.cpp
Expand Up @@ -23,10 +23,10 @@
#include "qgsproviderregistry.h"
#include "../providers/wms/qgswmsprovider.h"

#include <Q3ListView>
#include <QMessageBox>
#include <QPicture>
#include <QSettings>
#include <QButtonGroup>

#include <iostream>

Expand All @@ -37,6 +37,23 @@ QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, co
setupUi(this);
connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));

// Qt Designer 4.1 doesn't let us use a QButtonGroup, so it has to
// be done manually... Unless I'm missing something, it's a whole
// lot harder to do groups of radio buttons in Qt4 than Qt3.
m_imageFormatBtns = new QButtonGroup;
// Populate it with a couple of buttons
QRadioButton* btn1 = new QRadioButton(tr("PNG"));
QRadioButton* btn2 = new QRadioButton(tr("JPEG"));
m_imageFormatBtns->addButton(btn1, 1);
m_imageFormatBtns->addButton(btn2, 2);
btn1->setChecked(true);
// And lay then out horizontally
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addWidget(btn1);
hbox->addWidget(btn2);
hbox->addStretch();
btnGrpImageEncoding->setLayout(hbox);

btnAdd->setEnabled(false);
populateConnectionList();
// connect the double-click signal to the addSingleLayer slot in the parent
Expand Down Expand Up @@ -170,9 +187,12 @@ void QgsServerSourceSelect::populateImageEncodingGroup(QgsWmsProvider* wmsProvid
//
// Remove old group of buttons
//
for (int i = 1; i <= btnGrpImageEncoding->count(); i++)
QList<QAbstractButton*> btns = m_imageFormatBtns->buttons();
QList<QAbstractButton*>::const_iterator iter = btns.begin();
for (; iter != btns.end(); ++iter)
{
btnGrpImageEncoding->remove( btnGrpImageEncoding->find(i) );
m_imageFormatBtns->removeButton(*iter);
// Should the buttons be deleted too?
}

m_MimeTypeForButtonId.clear();
Expand Down Expand Up @@ -203,7 +223,8 @@ void QgsServerSourceSelect::populateImageEncodingGroup(QgsWmsProvider* wmsProvid
std::cout << "QgsServerSourceSelect::populateImageEncodingGroup: got image format " << (*format).toLocal8Bit().data() << "." << std::endl;
#endif

QRadioButton* radioButton = new QRadioButton(btnGrpImageEncoding);
QRadioButton* radioButton = new QRadioButton;
m_imageFormatBtns->addButton(radioButton, i);

if ((*format) == "image/png")
{
Expand All @@ -214,9 +235,7 @@ void QgsServerSourceSelect::populateImageEncodingGroup(QgsWmsProvider* wmsProvid
radioButton->setText(tr("JPEG"));
}

/* Qt4 in Qt3 compat mode seems to clobber custom layout variable names */
// layoutImageEncoding->addWidget(radioButton);
hboxLayout3->addWidget(radioButton);
m_imageFormatBtns->addButton(radioButton);

m_MimeTypeForButtonId[i] = (*format);

Expand Down Expand Up @@ -381,16 +400,14 @@ QString QgsServerSourceSelect::selectedImageEncoding()
{
// TODO: Match this hard coded list to the list of formats Qt reports it can actually handle.

if (btnGrpImageEncoding->selected() == (QRadioButton *) radioButtonPng)
{
QAbstractButton* checked = m_imageFormatBtns->checkedButton();

if (checked->text() == tr("PNG"))
return "image/png";
}
else if (btnGrpImageEncoding->selected() == (QRadioButton *) radioButtonJpeg)
{
else if (checked->text() == tr("JPEG"))
return "image/jpeg";
}
else // Worst-case scenario - fall back to PNG
return "image/png";

// Worst-case scenario - fall back to PNG
return "image/png";
}

6 changes: 4 additions & 2 deletions src/gui/qgsserversourceselect.h
Expand Up @@ -19,14 +19,13 @@
#ifndef QGSSERVERSOURCESELECT_H
#define QGSSERVERSOURCESELECT_H
#include "ui_qgsserversourceselectbase.h"
#include <QDialog>

#include <vector>
#include <map>

class QgisApp;
class QgsWmsProvider;

class QButtonGroup;
/*!
* \brief Dialog to create connections and add layers from WMS, etc.
*
Expand Down Expand Up @@ -102,6 +101,9 @@ public slots:

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

//! The widget that controls the image format radio buttons
QButtonGroup* m_imageFormatBtns;
};


Expand Down

0 comments on commit cce957c

Please sign in to comment.