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 mAddButton = mDialogButtonBox->button( QDialogButtonBox::Apply );
73 mAddButton->setToolTip(
tr(
"Add selected layers to map" ) );
78 mTileWidthLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
79 mTileHeightLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
80 mFeatureCountLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
82 mCacheComboBox->addItem(
tr(
"Always cache" ), QNetworkRequest::AlwaysCache );
83 mCacheComboBox->addItem(
tr(
"Prefer cache" ), QNetworkRequest::PreferCache );
84 mCacheComboBox->addItem(
tr(
"Prefer network" ), QNetworkRequest::PreferNetwork );
85 mCacheComboBox->addItem(
tr(
"Always network" ), QNetworkRequest::AlwaysNetwork );
92 if ( currentCRS != -1 )
104 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
105 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
107 mFormatWidget->hide();
110 mCacheWidget->hide();
118 restoreGeometry( settings.value(
"/Windows/WMSSourceSelect/geometry" ).toByteArray() );
125 settings.setValue(
"/Windows/WMSSourceSelect/geometry", saveGeometry() );
130 mFormatComboBox->clear();
131 mFormatComboBox->setEnabled(
false );
164 QMap<QString, QString> formatsMap;
165 formatsMap.insert(
"geotiff",
"tiff" );
166 formatsMap.insert(
"gtiff",
"tiff" );
167 formatsMap.insert(
"tiff",
"tiff" );
168 formatsMap.insert(
"tif",
"tiff" );
169 formatsMap.insert(
"gif",
"gif" );
170 formatsMap.insert(
"jpeg",
"jpeg" );
171 formatsMap.insert(
"jpg",
"jpeg" );
172 formatsMap.insert(
"png",
"png" );
176 for (
int i = 0; i < layersFormats.size(); i++ )
178 QString format = layersFormats.value( i );
180 QString simpleFormat = format.toLower().replace(
"image/",
"" ).replace( QRegExp(
"_.*" ),
"" );
181 QgsDebugMsg(
"server simpleFormat = " + simpleFormat );
182 QString mimeFormat =
"image/" + formatsMap.value( simpleFormat );
183 QgsDebugMsg(
"server mimeFormat = " + mimeFormat );
185 QString label = format;
195 if ( simpleFormat.contains(
"tif" ) )
197 if ( preferred < 0 || simpleFormat.startsWith(
"g" ) )
207 QgsDebugMsg( QString(
"format %1 unknown" ).arg( format ) );
210 mFormatComboBox->insertItem( i, label );
214 preferred = preferred >= 0 ? preferred : 0;
215 mFormatComboBox->setCurrentIndex( preferred );
217 mFormatComboBox->setEnabled(
true );
223 mTimeComboBox->clear();
230 mTimeComboBox->clear();
231 mTimeComboBox->setEnabled(
false );
236 mConnectionsComboBox->clear();
241 if ( mConnectionsComboBox->count() == 0 )
244 mConnectButton->setEnabled(
false );
245 mEditButton->setEnabled(
false );
246 mDeleteButton->setEnabled(
false );
251 mConnectButton->setEnabled(
true );
252 mEditButton->setEnabled(
true );
253 mDeleteButton->setEnabled(
true );
284 QString msg =
tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
285 .arg( mConnectionsComboBox->currentText() );
286 QMessageBox::StandardButton result = QMessageBox::information(
this,
tr(
"Confirm Delete" ), msg, QMessageBox::Ok | QMessageBox::Cancel );
287 if ( result == QMessageBox::Ok )
290 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
304 QString fileName = QFileDialog::getOpenFileName(
this,
tr(
"Load connections" ),
".",
305 tr(
"XML files (*.xml *XML)" ) );
306 if ( fileName.isEmpty() )
319 const QStringList &names,
320 QMap<int, QgsNumericSortTreeWidgetItem *> &items,
321 int &layerAndStyleCount,
322 const QMap<int, int> &layerParents,
323 const QMap<int, QStringList> &layerParentNames )
325 QgsDebugMsg( QString(
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg(
id ).arg( layerAndStyleCount ).arg( names.join(
"," ) ) );
326 if ( items.contains(
id ) )
331 if ( layerParents.contains(
id ) )
334 int parent = layerParents[ id ];
340 item->setText( 0, QString::number( ++layerAndStyleCount ) );
341 item->setText( 1, names[0].simplified() );
342 item->setText( 2, names[1].simplified() );
343 item->setText( 3, names[2].simplified() );
344 item->setToolTip( 3,
"<font color=black>" + names[2].simplified() +
"</font>" );
359 mLayersTreeWidget->clear();
364 mConnName = mConnectionsComboBox->currentText();
371 QApplication::setOverrideCursor( Qt::WaitCursor );
376 QApplication::restoreOverrideCursor();
391 foreach ( QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
393 QString layer = item->data( 0, Qt::UserRole + 0 ).toString();
394 if ( !layer.isEmpty() )
409 if ( !mySelector->exec() )
417 for (
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
434 mCRSLabel->setText(
tr(
"Coordinate Reference System (%n available)",
"crs count",
mSelectedLayersCRSs.count() ) +
":" );
446 if ( it->compare(
mSelectedCRS, Qt::CaseInsensitive ) == 0 )
464 mChangeCRSButton->setEnabled(
true );
471 mCRSLabel->setText(
tr(
"Coordinate Reference System" ) +
":" );
473 mSelectedCRSLabel->setText(
"" );
474 mChangeCRSButton->setEnabled(
false );
481 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
484 mTilesetsTableWidget->blockSignals(
true );
485 mTilesetsTableWidget->clearSelection();
488 QgsDebugMsg( QString(
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
489 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
496 mTilesetsTableWidget->blockSignals(
false );
520 int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
521 return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
531 return mTimeComboBox->currentText();
538 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
540 if ( mConnectionsComboBox->currentIndex() < 0 )
542 if ( toSelect.isNull() )
543 mConnectionsComboBox->setCurrentIndex( 0 );
545 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
552 mStatusLabel->setText( theMessage );
562 mv->setWindowTitle( theTitle );
564 if ( theFormat ==
"text/html" )
599 QMap<QString, QString> exampleServers;
600 exampleServers[
"DM Solutions GMap"] =
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
601 exampleServers[
"Lizardtech server"] =
"http://wms.lizardtech.com/lizardtech/iserv/ows";
606 settings.beginGroup(
"/Qgis/connections-" +
mService.toLower() );
607 QMap<QString, QString>::const_iterator i = exampleServers.constBegin();
608 for ( ; i != exampleServers.constEnd(); ++i )
611 QStringList keys = settings.childGroups();
612 if ( !keys.contains( i.key() ) )
614 QString path = i.key();
615 settings.setValue( path +
"/url", i.value() );
621 QMessageBox::information(
this,
tr(
"WMS proxies" ),
"<p>" +
tr(
"Several WMS servers have "
622 "been added to the server list. Note that if "
623 "you access the internet via a web proxy, you will "
624 "need to set the proxy settings in the QGIS options dialog." ) +
"</p>" );
629 QDomElement title = item.firstChildElement(
"title" );
631 QDomElement description = item.firstChildElement(
"description" );
633 QDomElement link = item.firstChildElement(
"link" );
641 QTableWidgetItem* tableItem =
new QTableWidgetItem( el.text() );
643 tableItem->setToolTip( el.text() );
644 mSearchTableWidget->setItem( row, column, tableItem );
651 mSearchTableWidget->clearContents();
652 mSearchTableWidget->setRowCount( 0 );
655 mSearchAddButton->setEnabled(
false );
657 QApplication::setOverrideCursor( Qt::WaitCursor );
661 QString mySearchUrl = settings.value(
"/qgis/WMSSearchUrl",
"http://geopole.org/wms/search?search=%1&type=rss" ).toString();
662 QUrl url( mySearchUrl.arg( mSearchTermLineEdit->text() ) );
671 QApplication::restoreOverrideCursor();
673 QNetworkReply *r = qobject_cast<QNetworkReply *>( sender() );
677 if ( r->error() == QNetworkReply::NoError )
680 QDomDocument doc(
"RSS" );
681 QByteArray res = r->readAll();
684 if ( doc.setContent( res, &error, &line, &column ) )
686 QDomNodeList list = doc.elementsByTagName(
"item" );
687 mSearchTableWidget->setRowCount( list.size() );
688 for (
int i = 0; i < list.size(); i++ )
690 if ( list.item( i ).isElement() )
692 QDomElement item = list.item( i ).toElement();
697 mSearchTableWidget->resizeColumnsToContents();
702 showStatusMessage(
tr(
"parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
715 mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
720 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
721 if ( selectionList.size() < 1 )
725 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
726 if ( selectedIndex < 1 )
731 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
732 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
733 mLayerOrderTreeWidget->clearSelection();
734 selectedItem->setSelected(
true );
739 QList<QTreeWidgetItem *> selectionList = mLayerOrderTreeWidget->selectedItems();
740 if ( selectionList.size() < 1 )
744 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
745 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
750 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
751 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
752 mLayerOrderTreeWidget->clearSelection();
753 selectedItem->setSelected(
true );
758 return QList<SupportedFormat>();
763 return QStringList();
768 return QStringList();
773 return QStringList();