Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wcs select dialog cleanup
  • Loading branch information
blazek committed Oct 4, 2012
1 parent a07845d commit b9960ad
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 137 deletions.
104 changes: 38 additions & 66 deletions src/gui/qgsowssourceselect.cpp
Expand Up @@ -73,6 +73,8 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( QString service, QWidget * parent, Qt::W
mAddButton->setToolTip( tr( "Add selected layers to map" ) );
mAddButton->setEnabled( false );

clearCRS();

mTileWidthLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
mTileHeightLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
mFeatureCountLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
Expand All @@ -82,8 +84,6 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( QString service, QWidget * parent, Qt::W
mCacheComboBox->addItem( tr( "Prefer network" ), QNetworkRequest::PreferNetwork );
mCacheComboBox->addItem( tr( "Always network" ), QNetworkRequest::AlwaysNetwork );

mImageFormatGroup = new QButtonGroup;

if ( !mManagerMode )
{
connect( mAddButton, SIGNAL( clicked() ), this, SLOT( addClicked() ) );
Expand All @@ -103,11 +103,11 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( QString service, QWidget * parent, Qt::W
{
mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
mImageFormatsGroupBox->hide();
mLayersTab->layout()->removeWidget( mImageFormatsGroupBox );
mCRSGroupBox->hide();
mLayersTab->layout()->removeWidget( mCRSGroupBox );
mTimeWidget->hide();
mFormatWidget->hide();
mCRSWidget->hide();
mAddButton->hide();
mCacheWidget->hide();
}

// set up the WMS connections we already know about
Expand All @@ -127,11 +127,8 @@ QgsOWSSourceSelect::~QgsOWSSourceSelect()

void QgsOWSSourceSelect::clearFormats()
{
int i = 0;
while ( QRadioButton *btn = dynamic_cast<QRadioButton*>( mImageFormatGroup->button( i++ ) ) )
{
btn->setVisible( false );
}
mFormatComboBox->clear();
mFormatComboBox->setEnabled( false );
}

void QgsOWSSourceSelect::populateFormats()
Expand All @@ -144,14 +141,6 @@ void QgsOWSSourceSelect::populateFormats()

clearFormats();

QHBoxLayout *layout = dynamic_cast<QHBoxLayout*>( mImageFormatsGroupBox->layout() );
if ( !layout )
{
layout = new QHBoxLayout;
mImageFormatsGroupBox->setLayout( layout );
layout->addStretch();
}

if ( mProviderFormats.size() == 0 )
{
mProviderFormats = providerFormats();
Expand Down Expand Up @@ -183,7 +172,6 @@ void QgsOWSSourceSelect::populateFormats()
formatsMap.insert( "png", "png" );

int preferred = -1;
int firstEnabled = -1;
QStringList layersFormats = selectedLayersFormats();
for ( int i = 0; i < layersFormats.size(); i++ )
{
Expand All @@ -195,27 +183,15 @@ void QgsOWSSourceSelect::populateFormats()
QgsDebugMsg( "server mimeFormat = " + mimeFormat );

QString label = format;
QString tip = tr( "Server format" ) + " " + format;

QRadioButton *btn;
btn = dynamic_cast<QRadioButton*>( mImageFormatGroup->button( i ) );
if ( !btn )
{
btn = new QRadioButton( label );
mImageFormatGroup->addButton( btn, i );
layout->insertWidget( layout->count() - 1, btn ); // before stretch
}
btn->setVisible( true );

if ( mMimeLabelMap.contains( mimeFormat ) )
{
btn->setEnabled( true );
if ( format != mMimeLabelMap.value( mimeFormat ) )
{
// Append name of GDAL driver
label += " / " + mMimeLabelMap.value( mimeFormat );
}
tip += " " + tr( "is supported by GDAL %1 driver." ).arg( mMimeLabelMap.value( mimeFormat ) );
if ( firstEnabled < 0 ) { firstEnabled = i; }

if ( simpleFormat.contains( "tif" ) ) // prefer *tif*
{
if ( preferred < 0 || simpleFormat.startsWith( "g" ) ) // prefer geotiff
Expand All @@ -226,24 +202,19 @@ void QgsOWSSourceSelect::populateFormats()
}
else
{
QgsDebugMsg( QString( "format %1 not supported." ).arg( format ) );
//btn->setEnabled( false );
btn->setEnabled( true );
if ( firstEnabled < 0 ) { firstEnabled = i; }
tip += " " + tr( "is not supported by GDAL" );
// We cannot always say that the format is not supported by GDAL because
// server can use strange names, but format itself is supported
QgsDebugMsg( QString( "format %1 unknown" ).arg( format ) );
}
btn->setText( label );
btn->setToolTip( tip );

mFormatComboBox->insertItem( i, label );
}
// Set preferred
// TODO: all enabled for now, see above
preferred = preferred >= 0 ? preferred : firstEnabled;
if ( preferred >= 0 )
{
mImageFormatGroup->button( preferred )->setChecked( true );
}
preferred = preferred >= 0 ? preferred : 0;
mFormatComboBox->setCurrentIndex( preferred );

mImageFormatsGroupBox->setEnabled( true );
mFormatComboBox->setEnabled( true );
}

void QgsOWSSourceSelect::populateTimes()
Expand All @@ -254,6 +225,12 @@ void QgsOWSSourceSelect::populateTimes()
mTimeComboBox->setEnabled( !selectedLayersTimes().isEmpty() );
}

void QgsOWSSourceSelect::clearTimes()
{
mTimeComboBox->clear();
mTimeComboBox->setEnabled( false );
}

void QgsOWSSourceSelect::populateConnectionList()
{
mConnectionsComboBox->clear();
Expand Down Expand Up @@ -381,6 +358,8 @@ void QgsOWSSourceSelect::on_mConnectButton_clicked()

mLayersTreeWidget->clear();
clearFormats();
clearTimes();
clearCRS();

mConnName = mConnectionsComboBox->currentText();

Expand Down Expand Up @@ -450,8 +429,9 @@ void QgsOWSSourceSelect::on_mLayersTreeWidget_itemSelectionChanged()
void QgsOWSSourceSelect::populateCRS()
{
QgsDebugMsg( "Entered" );
clearCRS();
mSelectedLayersCRSs = selectedLayersCRSs().toSet();
mCRSGroupBox->setTitle( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) );
mCRSLabel->setText( tr( "Coordinate Reference System (%n available)", "crs count", mSelectedLayersCRSs.count() ) + ":" );

mChangeCRSButton->setDisabled( mSelectedLayersCRSs.isEmpty() );

Expand Down Expand Up @@ -481,14 +461,17 @@ void QgsOWSSourceSelect::populateCRS()
mSelectedCRS = defaultCRS;
}
mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
}
else
{
mSelectedCRS = "";
mSelectedCRSLabel->setText( "" );
mChangeCRSButton->setEnabled( true );
}
QgsDebugMsg( "mSelectedCRS = " + mSelectedCRS );
mChangeCRSButton->setEnabled( !mSelectedLayersCRSs.isEmpty() );
}

void QgsOWSSourceSelect::clearCRS()
{
mCRSLabel->setText( tr( "Coordinate Reference System" ) + ":" );
mSelectedCRS = "";
mSelectedCRSLabel->setText( "" );
mChangeCRSButton->setEnabled( false );
}

void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked( QTableWidgetItem *item )
Expand Down Expand Up @@ -529,18 +512,7 @@ QString QgsOWSSourceSelect::connectionInfo()

QString QgsOWSSourceSelect::selectedFormat()
{
// TODO: Match this hard coded list to the list of formats Qt reports it can actually handle.
int id = mImageFormatGroup->checkedId();
if ( id < 0 )
{
return "";
}
else
{
// TODO: do format in subclass (WMS)
//return QUrl::toPercentEncoding( mProviderFormats[ id ].format );
return selectedLayersFormats().value( id );
}
return selectedLayersFormats().value( mFormatComboBox->currentIndex() );
}

QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
Expand Down
9 changes: 6 additions & 3 deletions src/gui/qgsowssourceselect.h
Expand Up @@ -143,9 +143,15 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSel
//! Set supported CRSs
void populateCRS();

//! Clear CRSs
void clearCRS();

//! Populate times
void populateTimes();

//! Clear times
void clearTimes();

//! Connection name
QString connName();

Expand Down Expand Up @@ -190,9 +196,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSel
//! layer name derived from latest layer selection (updated as long it's not edited manually)
QString mLastLayerName;

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

QPushButton *mAddButton;

QMap<QString, QString> mCrsNames;
Expand Down

0 comments on commit b9960ad

Please sign in to comment.