41 #include <QButtonGroup> 42 #include <QFileDialog> 43 #include <QRadioButton> 44 #include <QDomDocument> 45 #include <QHeaderView> 46 #include <QImageReader> 47 #include <QInputDialog> 49 #include <QMessageBox> 55 #include <QNetworkRequest> 56 #include <QNetworkReply> 61 , mManagerMode( managerMode )
62 , mEmbeddedMode( embeddedMode )
63 , mCurrentTileset( nullptr )
69 mDialogButtonBox->button( QDialogButtonBox::Close )->hide();
74 mAddButton = mDialogButtonBox->button( QDialogButtonBox::Apply );
81 mTileWidthLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
82 mTileHeightLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
83 mFeatureCountLineEdit->setValidator(
new QIntValidator( 0, 9999,
this ) );
85 mCacheComboBox->addItem(
tr(
"Always cache" ), QNetworkRequest::AlwaysCache );
86 mCacheComboBox->addItem(
tr(
"Prefer cache" ), QNetworkRequest::PreferCache );
87 mCacheComboBox->addItem(
tr(
"Prefer network" ), QNetworkRequest::PreferNetwork );
88 mCacheComboBox->addItem(
tr(
"Always network" ), QNetworkRequest::AlwaysNetwork );
91 mCacheComboBox->setCurrentIndex( mCacheComboBox->findData( QNetworkRequest::PreferNetwork ) );
98 if ( currentCRS != -1 )
104 mSelectedCRS = currentRefSys.
authid();
110 mTabWidget->removeTab( mTabWidget->indexOf( mLayerOrderTab ) );
111 mTabWidget->removeTab( mTabWidget->indexOf( mTilesetsTab ) );
113 mFormatWidget->hide();
116 mCacheWidget->hide();
136 mFormatComboBox->clear();
137 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 );
227 mTimeComboBox->clear();
234 mTimeComboBox->clear();
235 mTimeComboBox->setEnabled(
false );
240 mConnectionsComboBox->clear();
273 QString msg =
tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
274 .
arg( mConnectionsComboBox->currentText() );
276 if ( result == QMessageBox::Ok )
279 mConnectionsComboBox->removeItem( mConnectionsComboBox->currentIndex() );
294 tr(
"XML files (*.xml *XML)" ) );
310 int &layerAndStyleCount,
314 QgsDebugMsg(
QString(
"id = %1 layerAndStyleCount = %2 names = %3 " ).arg(
id ).arg( layerAndStyleCount ).arg( names.
join(
"," ) ) );
323 int parent = layerParents[ id ];
330 item->
setText( 1, names[0].simplified() );
331 item->
setText( 2, names[1].simplified() );
332 item->
setText( 3, names[2].simplified() );
333 item->
setToolTip( 3,
"<font color=black>" + names[2].simplified() +
"</font>" );
347 mLayersTreeWidget->clear();
352 mConnName = mConnectionsComboBox->currentText();
376 Q_FOREACH (
QTreeWidgetItem *item, mLayersTreeWidget->selectedItems() )
394 if ( !mySelector->
exec() )
402 for (
int i = 0; i < mLayersTreeWidget->topLevelItemCount(); i++ )
418 mCRSLabel->setText(
tr(
"Coordinate Reference System (%n available)",
"crs count", mSelectedLayersCRSs.
count() ) +
':' );
420 mChangeCRSButton->setDisabled( mSelectedLayersCRSs.
isEmpty() );
422 if ( !mSelectedLayersCRSs.
isEmpty() )
428 for ( ; it != mSelectedLayersCRSs.
constEnd(); ++it )
430 if ( it->compare( mSelectedCRS, Qt::CaseInsensitive ) == 0 )
434 if ( it == mSelectedLayersCRSs.
begin() )
442 if ( it == mSelectedLayersCRSs.
end() )
445 mSelectedCRS = defaultCRS;
448 mChangeCRSButton->setEnabled(
true );
455 mCRSLabel->setText(
tr(
"Coordinate Reference System" ) +
':' );
457 mSelectedCRSLabel->setText(
"" );
458 mChangeCRSButton->setEnabled(
false );
461 void QgsOWSSourceSelect::on_mTilesetsTableWidget_itemClicked(
QTableWidgetItem *item )
465 QTableWidgetItem *rowItem = mTilesetsTableWidget->item( mTilesetsTableWidget->currentRow(), 0 );
468 mTilesetsTableWidget->blockSignals(
true );
469 mTilesetsTableWidget->clearSelection();
472 QgsDebugMsg(
QString(
"selecting current row %1" ).arg( mTilesetsTableWidget->currentRow() ) );
473 mTilesetsTableWidget->selectRow( mTilesetsTableWidget->currentRow() );
480 mTilesetsTableWidget->blockSignals(
false );
504 int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
505 return static_cast<QNetworkRequest::CacheLoadControl
>( cache );
515 return mTimeComboBox->currentText();
522 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->findText( toSelect ) );
524 if ( mConnectionsComboBox->currentIndex() < 0 )
527 mConnectionsComboBox->setCurrentIndex( 0 );
529 mConnectionsComboBox->setCurrentIndex( mConnectionsComboBox->count() - 1 );
532 if ( mConnectionsComboBox->count() == 0 )
535 mConnectButton->setEnabled(
false );
536 mEditButton->setEnabled(
false );
537 mDeleteButton->setEnabled(
false );
538 mSaveButton->setEnabled(
false );
543 mConnectButton->setEnabled(
true );
544 mEditButton->setEnabled(
true );
545 mDeleteButton->setEnabled(
true );
546 mSaveButton->setEnabled(
true );
554 mStatusLabel->setText( theMessage );
566 if ( theFormat ==
"text/html" )
601 exampleServers[
"DM Solutions GMap"] =
"http://www2.dmsolutions.ca/cgi-bin/mswms_gmap";
602 exampleServers[
"Lizardtech server"] =
"http://wms.lizardtech.com/lizardtech/iserv/ows";
609 for ( ; i != exampleServers.
constEnd(); ++i )
623 "been added to the server list. Note that if " 624 "you access the internet via a web proxy, you will " 625 "need to set the proxy settings in the QGIS options dialog." ) +
"</p>" );
645 mSearchTableWidget->setItem( row, column, tableItem );
649 void QgsOWSSourceSelect::on_mSearchButton_clicked()
652 mSearchTableWidget->clearContents();
653 mSearchTableWidget->setRowCount( 0 );
656 mSearchAddButton->setEnabled(
false );
662 QString mySearchUrl = settings.
value(
"/qgis/WMSSearchUrl",
"http://geopole.org/wms/search?search=%1&type=rss" ).
toString();
663 QUrl url( mySearchUrl.
arg( mSearchTermLineEdit->text() ) );
678 if ( r->
error() == QNetworkReply::NoError )
685 if ( doc.
setContent( res, &error, &line, &column ) )
688 mSearchTableWidget->setRowCount( list.
size() );
689 for (
int i = 0; i < list.
size(); i++ )
698 mSearchTableWidget->resizeColumnsToContents();
703 showStatusMessage(
tr(
"parse error at row %1, column %2: %3" ).arg( line ).arg( column ).arg( error ) );
714 void QgsOWSSourceSelect::on_mSearchTableWidget_itemSelectionChanged()
716 mSearchAddButton->setEnabled( mSearchTableWidget->currentRow() != -1 );
719 void QgsOWSSourceSelect::on_mLayerUpButton_clicked()
722 if ( selectionList.
size() < 1 )
726 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
727 if ( selectedIndex < 1 )
732 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
733 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex - 1, selectedItem );
734 mLayerOrderTreeWidget->clearSelection();
738 void QgsOWSSourceSelect::on_mLayerDownButton_clicked()
741 if ( selectionList.
size() < 1 )
745 int selectedIndex = mLayerOrderTreeWidget->indexOfTopLevelItem( selectionList[0] );
746 if ( selectedIndex < 0 || selectedIndex > mLayerOrderTreeWidget->topLevelItemCount() - 2 )
751 QTreeWidgetItem* selectedItem = mLayerOrderTreeWidget->takeTopLevelItem( selectedIndex );
752 mLayerOrderTreeWidget->insertTopLevelItem( selectedIndex + 1, selectedItem );
753 mLayerOrderTreeWidget->clearSelection();
777 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
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=nullptr) const
QgsCoordinateReferenceSystem crsByOgcWmsCrs(const QString &ogcCrs) const
Returns the CRS from a given OGC WMS-format Coordinate Reference System string.
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
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)
Retreives the selected connection for the specified service.
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)
Returns the list of connections for the specified service.
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.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
QNetworkRequest::CacheLoadControl selectedCacheLoadControl()
Returns currently selected cache load control.
QgsCoordinateReferenceSystem crsBySrsId(long srsId) const
Returns the CRS from a specified QGIS SRS ID.
void on_mConnectionsComboBox_activated(int)
Stores the selected datasource whenerver it is changed.
static void setSelectedConnection(const QString &theService, const QString &name)
Marks the specified connection for the specified service as selected.
void finished(int result)
QDomElement toElement() const
void setMessageAsHtml(const QString &msg)
void setValue(const QString &key, const QVariant &value)
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)
Deletes the connection for the specified service with the specified 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)
QString description() const
Returns the descriptive name of the CRS, eg "WGS 84" or "GDA 94 / Vicgrid94".
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.
QString uri(bool expandAuthConfig=true) const
return complete uri
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.
void on_mAddDefaultButton_clicked()
Add some default wms servers to the list.
void addWMSListRow(const QDomElement &item, int row)
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.
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()
Returns the QgsProject singleton 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.
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.
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)
long srsid() const
Returns the SrsId, if available.
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)
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.
static QgsCRSCache * instance()
Returns a pointer to the QgsCRSCache singleton.
QString authid() const
Returns the authority identifier for the CRS, which includes both the authority (eg EPSG) and the CRS...
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.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void clearCRS()
Clear CRSs.