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> 60 , mManagerMode( managerMode )
61 , mEmbeddedMode( embeddedMode )
62 , mCurrentTileset( nullptr )
68 mDialogButtonBox->button( QDialogButtonBox::Close )->hide();
73 mAddButton = mDialogButtonBox->button( QDialogButtonBox::Apply );
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 );
90 mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
97 if ( currentCRS != -1 )
103 mSelectedCRS = currentRefSys.
authid();
109 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
110 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
112 mFormatWidget->hide();
115 mCacheWidget->hide();
135 mFormatComboBox->clear();
136 mFormatComboBox->setEnabled(
false );
149 if ( mProviderFormats.isEmpty() )
152 for (
int i = 0; i < mProviderFormats.size(); i++ )
155 mMimeLabelMap.
insert( mProviderFormats[i].format, mProviderFormats[i].label );
170 formatsMap.
insert(
"geotiff",
"tiff" );
171 formatsMap.
insert(
"gtiff",
"tiff" );
172 formatsMap.
insert(
"tiff",
"tiff" );
173 formatsMap.
insert(
"tif",
"tiff" );
174 formatsMap.
insert(
"gif",
"gif" );
175 formatsMap.
insert(
"jpeg",
"jpeg" );
176 formatsMap.
insert(
"jpg",
"jpeg" );
177 formatsMap.
insert(
"png",
"png" );
181 for (
int i = 0; i < layersFormats.
size(); i++ )
186 QgsDebugMsg(
"server simpleFormat = " + simpleFormat );
187 QString mimeFormat =
"image/" + formatsMap.
value( simpleFormat );
188 QgsDebugMsg(
"server mimeFormat = " + mimeFormat );
192 if ( mMimeLabelMap.
contains( mimeFormat ) )
194 if ( format != mMimeLabelMap.
value( mimeFormat ) )
197 label +=
" / " + mMimeLabelMap.
value( mimeFormat );
200 if ( simpleFormat.
contains(
"tif" ) )
202 if ( preferred < 0 || simpleFormat.
startsWith(
'g' ) )
215 mFormatComboBox->insertItem( i, label );
219 preferred = preferred >= 0 ? preferred : 0;
220 mFormatComboBox->setCurrentIndex( preferred );
222 mFormatComboBox->setEnabled(
true );
228 mTimeComboBox->clear();
235 mTimeComboBox->clear();
236 mTimeComboBox->setEnabled(
false );
241 mConnectionsComboBox->clear();
274 QString msg =
tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
275 .
arg( mConnectionsComboBox->currentText() );
277 if ( result == QMessageBox::Ok )
280 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
295 tr(
"XML files (*.xml *XML)" ) );
311 int &layerAndStyleCount,
315 QgsDebugMsg(
QString(
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg(
id ).arg( layerAndStyleCount ).arg( names.
join(
"," ) ) );
324 int parent = layerParents[ id ];
331 item->
setText( 1, names[0].simplified() );
332 item->
setText( 2, names[1].simplified() );
333 item->
setText( 3, names[2].simplified() );
334 item->
setToolTip( 3,
"<font color=black>" + names[2].simplified() +
"</font>" );
349 mLayersTreeWidget->clear();
354 mConnName = mConnectionsComboBox->currentText();
379 Q_FOREACH (
QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
397 if ( !mySelector->
exec() )
405 for (
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
422 mCRSLabel->setText(
tr(
"Coordinate Reference System (%n available)",
"crs count", mSelectedLayersCRSs.
count() ) +
':' );
424 mChangeCRSButton->setDisabled( mSelectedLayersCRSs.
isEmpty() );
426 if ( !mSelectedLayersCRSs.
isEmpty() )
432 for ( ; it != mSelectedLayersCRSs.
constEnd(); ++it )
434 if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
438 if ( it == mSelectedLayersCRSs.
begin() )
446 if ( it == mSelectedLayersCRSs.
end() )
449 mSelectedCRS = defaultCRS;
452 mChangeCRSButton->setEnabled(
true );
459 mCRSLabel->setText(
tr(
"Coordinate Reference System" ) +
':' );
461 mSelectedCRSLabel->setText(
"" );
462 mChangeCRSButton->setEnabled(
false );
465 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked(
QTableWidgetItem *item )
469 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
472 mTilesetsTableWidget->blockSignals(
true );
473 mTilesetsTableWidget->clearSelection();
476 QgsDebugMsg(
QString(
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
477 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
484 mTilesetsTableWidget->blockSignals(
false );
508 int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
509 return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
519 return mTimeComboBox->currentText();
526 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
528 if ( mConnectionsComboBox->currentIndex() < 0 )
531 mConnectionsComboBox->setCurrentIndex( 0 );
533 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
536 if ( mConnectionsComboBox->count() == 0 )
539 mConnectButton->setEnabled(
false );
540 mEditButton->setEnabled(
false );
541 mDeleteButton->setEnabled(
false );
542 mSaveButton->setEnabled(
false );
547 mConnectButton->setEnabled(
true );
548 mEditButton->setEnabled(
true );
549 mDeleteButton->setEnabled(
true );
550 mSaveButton->setEnabled(
true );
558 mStatusLabel->setText( theMessage );
570 if ( theFormat ==
"text/html" )
606 exampleServers[
"DM Solutions GMap"] =
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
607 exampleServers[
"Lizardtech server"] =
"http://wms.lizardtech.com/lizardtech/iserv/ows";
614 for ( ; i != exampleServers.
constEnd(); ++i )
628 "been added to the server list. Note that if " 629 "you access the internet via a web proxy, you will " 630 "need to set the proxy settings in the QGIS options dialog." ) +
"</p>" );
650 mSearchTableWidget->setItem( row, column, tableItem );
654 void QgsOWSSourceSelect::on_mSearchButton_clicked()
657 mSearchTableWidget->clearContents();
658 mSearchTableWidget->setRowCount( 0 );
661 mSearchAddButton->setEnabled(
false );
667 QString mySearchUrl = settings.
value(
"/qgis/WMSSearchUrl",
"http://geopole.org/wms/search?search=%1&type=rss" ).
toString();
668 QUrl url( mySearchUrl.
arg( mSearchTermLineEdit->text() ) );
683 if ( r->
error() == QNetworkReply::NoError )
690 if ( doc.
setContent( res, &error, &line, &column ) )
693 mSearchTableWidget->setRowCount( list.
size() );
694 for (
int i = 0; i < list.
size(); i++ )
703 mSearchTableWidget->resizeColumnsToContents();
708 showStatusMessage(
tr(
"parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
719 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
721 mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
724 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
727 if ( selectionList.
size() < 1 )
731 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
732 if ( selectedIndex < 1 )
737 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
738 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
739 mLayerOrderTreeWidget->clearSelection();
743 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
746 if ( selectionList.
size() < 1 )
750 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
751 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
756 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
757 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
758 mLayerOrderTreeWidget->clearSelection();
782 void QgsOWSSourceSelect::updateButtons()
void on_mNewButton_clicked()
Opens the create connection dialog to build a new connection.
QByteArray toByteArray() const
QDomNode item(int index) const
bool contains(const Key &key) const
QgsOWSSourceSelect(const QString &service, QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags, bool managerMode=false, bool embeddedMode=false)
Constructor.
QMap< QString, QString > mCrsNames
virtual void populateLayerList()
Populate the layer list.
void clearTimes()
Clear times.
QString selectedCRS()
Returns currently selected Crs.
QString connectionInfo()
Connection info (uri)
static QString selectedConnection(const QString &theService)
long srsid() const
Returns the SrsId, if available.
const_iterator constBegin() const
~QgsOWSSourceSelect()
Destructor.
A generic dialog to prompt the user for a Coordinate Reference System.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
static QStringList connectionList(const QString &theService)
bool mManagerMode
Connections manager mode.
QString selectedFormat()
Returns currently selected format.
void on_mChangeCRSButton_clicked()
Opens the Spatial Reference System dialog.
QString descriptionForAuthId(const QString &authId)
Returns a textual description for the authority id.
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
QString join(const QString &separator) const
QString & remove(int position, int n)
virtual QStringList selectedLayersFormats()
List of formats supported for currently selected layer item(s)
QString toString(QFlags< QUrl::FormattingOption > options) const
QString tr(const char *sourceText, const char *disambiguation, int n)
void populateCRS()
Set supported CRSs.
QNetworkRequest::CacheLoadControl selectedCacheLoadControl()
Returns currently selected cache load control.
void on_mConnectionsComboBox_activated(int)
Stores the selected datasource whenerver it is changed.
static void setSelectedConnection(const QString &theService, const QString &name)
void finished(int result)
QDomElement toElement() const
void setMessageAsHtml(const QString &msg)
void setValue(const QString &key, const QVariant &value)
bool createFromOgcWmsCrs(QString theCrs)
Set up this CRS from the given OGC CRS.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
void populateConnectionList()
Populate the connection list combo box.
QString number(int n, int base)
bool mEmbeddedMode
Embedded mode, without 'Close'.
static void deleteConnection(const QString &theService, const QString &name)
virtual void enableLayersForCrs(QTreeWidgetItem *item)
void addDefaultServers()
Add a few example servers to the list.
void on_mConnectButton_clicked()
Connects to the database using the stored connection parameters.
QDomNodeList elementsByTagName(const QString &tagname) const
void setMessage(QString theMessage="")
If no parameter is passed, the message will be a generic 'define the CRS for this layer'...
const_iterator constEnd() const
void on_mEditButton_clicked()
Opens a dialog to edit an existing connection.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QStringList childGroups() const
void setOverrideCursor(const QCursor &cursor)
void setMessageAsPlainText(const QString &msg)
void restoreOverrideCursor()
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
const_iterator constEnd() const
void populateFormats()
Populate supported formats.
QgsDataSourceURI mUri
URI for selected connection.
virtual QStringList selectedLayersTimes()
List of times (temporalDomain timePosition/timePeriod for currently selected layer item(s) ...
virtual void showMessage(bool blocking=true) override
display the message to the user and deletes itself
void on_mLoadButton_clicked()
Loads connections from the file.
QgsNumericSortTreeWidgetItem * createItem(int id, const QStringList &names, QMap< int, QgsNumericSortTreeWidgetItem * > &items, int &layerAndStyleCount, const QMap< int, int > &layerParents, const QMap< int, QStringList > &layerParentNames)
create an item including possible parents
void on_mAddDefaultButton_clicked()
Add some default wms servers to the list.
void addWMSListRow(const QDomElement &item, int row)
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
bool contains(QChar ch, Qt::CaseSensitivity cs) const
virtual void on_mLayersTreeWidget_itemSelectionChanged()
Signaled when a layer selection is changed.
void on_mDeleteButton_clicked()
Deletes the selected connection.
const_iterator constBegin() const
const Key key(const T &value) const
virtual void addClicked()
Determines the layers the user selected.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QVariant value(const QString &key, const QVariant &defaultValue) const
void connectionsChanged()
QString connName()
Connection name.
void setSelectedCrsId(long theID)
void addWMSListItem(const QDomElement &el, int row, int column)
QString mConnectionInfo
Connection info for selected connection.
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
static QgsProject * instance()
access to canonical QgsProject instance
QDomElement firstChildElement(const QString &tagName) const
Class for storing a coordinate reference system (CRS)
void setText(int column, const QString &text)
A generic message view for displaying QGIS messages.
virtual QList< SupportedFormat > providerFormats()
List of image formats (encodings) supported by provider.
QString authid() const
Returns the authority identifier for the CRS, which includes both the authority (eg EPSG) and the CRS...
void showStatusMessage(const QString &theMessage)
Set status message to theMessage.
void on_mSaveButton_clicked()
Saves connections to the file.
void setText(const QString &text)
QString selectedTime()
Returns currently selected time.
NetworkError error() const
void clearFormats()
Clear previously set formats.
iterator insert(const Key &key, const T &value)
QString mService
Service name.
void showError(const QString &theTitle, const QString &theFormat, const QString &theError)
show whatever error is exposed.
QString description() const
Returns the descriptive name of the CRS, eg "WGS 84" or "GDA 94 / Vicgrid94".
QNetworkReply * get(const QNetworkRequest &request)
QTableWidgetItem * mCurrentTileset
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
Dialog to allow the user to configure and save connection information for an HTTP Server for WMS...
virtual QStringList selectedLayersCRSs()
Server CRS supported for currently selected layer item(s)
QString uri(bool expandAuthConfig=true) const
return complete uri
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setConnectionListPosition()
Set the server connection combo box to that stored in the config file.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void populateTimes()
Populate times.
void beginGroup(const QString &prefix)
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
const T value(const Key &key) const
QString mConnName
Name for selected connection.
void clearCRS()
Clear CRSs.