40 #include <QButtonGroup>
41 #include <QFileDialog>
42 #include <QRadioButton>
43 #include <QDomDocument>
44 #include <QHeaderView>
45 #include <QImageReader>
46 #include <QInputDialog>
48 #include <QMessageBox>
54 #include <QNetworkRequest>
55 #include <QNetworkReply>
58 : QDialog( parent, fl )
60 , mManagerMode( managerMode )
61 , mEmbeddedMode( embeddedMode )
62 , mCurrentTileset( 0 )
68 mDialogButtonBox->button( QDialogButtonBox::Close )->hide();
71 setWindowTitle(
tr(
"Add Layer(s) from a %1 Server" ).arg( service ) );
73 mAddButton = mDialogButtonBox->button( QDialogButtonBox::Apply );
75 mAddButton->setToolTip(
tr(
"Add selected layers to map" ) );
80 mTileWidthLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
81 mTileHeightLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
82 mFeatureCountLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
84 mCacheComboBox->addItem(
tr(
"Always cache" ), QNetworkRequest::AlwaysCache );
85 mCacheComboBox->addItem(
tr(
"Prefer cache" ), QNetworkRequest::PreferCache );
86 mCacheComboBox->addItem(
tr(
"Prefer network" ), QNetworkRequest::PreferNetwork );
87 mCacheComboBox->addItem(
tr(
"Always network" ), QNetworkRequest::AlwaysNetwork );
94 if ( currentCRS != -1 )
106 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
107 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
109 mFormatWidget->hide();
112 mCacheWidget->hide();
120 restoreGeometry( settings.value(
"/Windows/WMSSourceSelect/geometry" ).toByteArray() );
127 settings.setValue(
"/Windows/WMSSourceSelect/geometry", saveGeometry() );
132 mFormatComboBox->clear();
133 mFormatComboBox->setEnabled(
false );
166 QMap<QString, QString> formatsMap;
167 formatsMap.insert(
"geotiff",
"tiff" );
168 formatsMap.insert(
"gtiff",
"tiff" );
169 formatsMap.insert(
"tiff",
"tiff" );
170 formatsMap.insert(
"tif",
"tiff" );
171 formatsMap.insert(
"gif",
"gif" );
172 formatsMap.insert(
"jpeg",
"jpeg" );
173 formatsMap.insert(
"jpg",
"jpeg" );
174 formatsMap.insert(
"png",
"png" );
178 for (
int i = 0; i < layersFormats.size(); i++ )
180 QString format = layersFormats.value( i );
182 QString simpleFormat = format.toLower().replace(
"image/",
"" ).replace( QRegExp(
"_.*" ),
"" );
183 QgsDebugMsg(
"server simpleFormat = " + simpleFormat );
184 QString mimeFormat =
"image/" + formatsMap.value( simpleFormat );
185 QgsDebugMsg(
"server mimeFormat = " + mimeFormat );
187 QString label = format;
197 if ( simpleFormat.contains(
"tif" ) )
199 if ( preferred < 0 || simpleFormat.startsWith(
"g" ) )
209 QgsDebugMsg( QString(
"format %1 unknown" ).arg( format ) );
212 mFormatComboBox->insertItem( i, label );
216 preferred = preferred >= 0 ? preferred : 0;
217 mFormatComboBox->setCurrentIndex( preferred );
219 mFormatComboBox->setEnabled(
true );
225 mTimeComboBox->clear();
232 mTimeComboBox->clear();
233 mTimeComboBox->setEnabled(
false );
238 mConnectionsComboBox->clear();
271 QString msg =
tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
272 .arg( mConnectionsComboBox->currentText() );
273 QMessageBox::StandardButton result = QMessageBox::information(
this,
tr(
"Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
274 if ( result == QMessageBox::Ok )
277 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
291 QString fileName = QFileDialog::getOpenFileName(
this,
tr(
"Load connections" ),
".",
292 tr(
"XML files (*.xml *XML)" ) );
293 if ( fileName.isEmpty() )
306 const QStringList &names,
307 QMap<int, QgsNumericSortTreeWidgetItem *> &items,
308 int &layerAndStyleCount,
309 const QMap<int, int> &layerParents,
310 const QMap<int, QStringList> &layerParentNames )
312 QgsDebugMsg( QString(
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg(
id ).arg( layerAndStyleCount ).arg( names.join(
"," ) ) );
313 if ( items.contains(
id ) )
318 if ( layerParents.contains(
id ) )
321 int parent = layerParents[ id ];
327 item->setText( 0, QString::number( ++layerAndStyleCount ) );
328 item->setText( 1, names[0].simplified() );
329 item->setText( 2, names[1].simplified() );
330 item->setText( 3, names[2].simplified() );
331 item->setToolTip( 3,
"<font color=black>" + names[2].simplified() +
"</font>" );
346 mLayersTreeWidget->clear();
351 mConnName = mConnectionsComboBox->currentText();
358 QApplication::setOverrideCursor( Qt::WaitCursor );
363 QApplication::restoreOverrideCursor();
378 foreach ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
380 QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
381 if ( !layer.isEmpty() )
396 if ( !mySelector->exec() )
404 for (
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
421 mCRSLabel->setText(
tr(
"Coordinate Reference System (%n available)",
"crs count",
mSelectedLayersCRSs.count() ) +
":" );
433 if ( it->compare(
mSelectedCRS, Qt::CaseInsensitive ) == 0 )
451 mChangeCRSButton->setEnabled(
true );
458 mCRSLabel->setText(
tr(
"Coordinate Reference System" ) +
":" );
460 mSelectedCRSLabel->setText(
"" );
461 mChangeCRSButton->setEnabled(
false );
468 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
471 mTilesetsTableWidget->blockSignals(
true );
472 mTilesetsTableWidget->clearSelection();
475 QgsDebugMsg( QString(
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
476 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
483 mTilesetsTableWidget->blockSignals(
false );
507 int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
508 return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
518 return mTimeComboBox->currentText();
525 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
527 if ( mConnectionsComboBox->currentIndex() < 0 )
529 if ( toSelect.isNull() )
530 mConnectionsComboBox->setCurrentIndex( 0 );
532 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
535 if ( mConnectionsComboBox->count() == 0 )
538 mConnectButton->setEnabled(
false );
539 mEditButton->setEnabled(
false );
540 mDeleteButton->setEnabled(
false );
541 mSaveButton->setEnabled(
false );
546 mConnectButton->setEnabled(
true );
547 mEditButton->setEnabled(
true );
548 mDeleteButton->setEnabled(
true );
549 mSaveButton->setEnabled(
true );
557 mStatusLabel->setText( theMessage );
567 mv->setWindowTitle( theTitle );
569 if ( theFormat ==
"text/html" )
604 QMap<QString, QString> exampleServers;
605 exampleServers[
"DM Solutions GMap"] =
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
606 exampleServers[
"Lizardtech server"] =
"http://wms.lizardtech.com/lizardtech/iserv/ows";
611 settings.beginGroup(
"/Qgis/connections-" +
mService.toLower() );
612 QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
613 for ( ; i != exampleServers.constEnd(); ++i )
616 QStringList keys = settings.childGroups();
617 if ( !keys.contains( i.key() ) )
619 QString path = i.key();
620 settings.setValue( path +
"/url", i.value() );
626 QMessageBox::information(
this,
tr(
"WMS proxies" ),
"<p>" +
tr(
"Several WMS servers have "
627 "been added to the server list. Note that if "
628 "you access the internet via a web proxy, you will "
629 "need to set the proxy settings in the QGIS options dialog." ) +
"</p>" );
634 QDomElement title = item.firstChildElement(
"title" );
636 QDomElement description = item.firstChildElement(
"description" );
638 QDomElement link = item.firstChildElement(
"link" );
646 QTableWidgetItem* tableItem =
new QTableWidgetItem( el.text() );
648 tableItem->setToolTip( el.text() );
649 mSearchTableWidget->setItem( row, column, tableItem );
656 mSearchTableWidget->clearContents();
657 mSearchTableWidget->setRowCount( 0 );
660 mSearchAddButton->setEnabled(
false );
662 QApplication::setOverrideCursor( Qt::WaitCursor );
666 QString mySearchUrl = settings.value(
"/qgis/WMSSearchUrl",
"http://geopole.org/wms/search?search=%1&type=rss" ).toString();
667 QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
676 QApplication::restoreOverrideCursor();
678 QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
682 if ( r->error() == QNetworkReply::NoError )
685 QDomDocument doc(
"RSS" );
686 QByteArray res = r->readAll();
689 if ( doc.setContent( res, &error, &line, &column ) )
691 QDomNodeList list = doc.elementsByTagName(
"item" );
692 mSearchTableWidget->setRowCount( list.size() );
693 for (
int i = 0; i < list.size(); i++ )
695 if ( list.item( i ).isElement() )
697 QDomElement item = list.item( i ).toElement();
702 mSearchTableWidget->resizeColumnsToContents();
707 showStatusMessage(
tr(
"parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
720 mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
725 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
726 if ( selectionList.size() < 1 )
730 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
731 if ( selectedIndex < 1 )
736 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
737 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
738 mLayerOrderTreeWidget->clearSelection();
739 selectedItem->setSelected(
true );
744 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
745 if ( selectionList.size() < 1 )
749 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
750 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
755 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
756 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
757 mLayerOrderTreeWidget->clearSelection();
758 selectedItem->setSelected(
true );
763 return QList<SupportedFormat>();
768 return QStringList();
773 return QStringList();
778 return QStringList();