32 #include <QItemDelegate> 33 #include <QListWidgetItem> 34 #include <QMessageBox> 36 #include <QFileDialog> 37 #include <QRadioButton> 38 #include <QImageReader> 53 :
QDialog( parent, fl ), mServiceName( serviceName ), mServiceType( serviceType ), mBuildQueryButton( 0 ), mImageEncodingGroup( 0 )
58 mAddButton = buttonBox->addButton(
tr(
"&Add" ), QDialogButtonBox::ActionRole );
64 mBuildQueryButton = buttonBox->addButton(
tr(
"&Build query" ), QDialogButtonBox::ActionRole );
70 connect( btnNew, SIGNAL( clicked() ),
this, SLOT( addEntryToServerList() ) );
71 connect( btnEdit, SIGNAL( clicked() ),
this, SLOT( modifyEntryOfServerList() ) );
72 connect( btnDelete, SIGNAL( clicked() ),
this, SLOT( deleteEntryOfServerList() ) );
73 connect( btnConnect, SIGNAL( clicked() ),
this, SLOT( connectToServer() ) );
74 connect( btnChangeSpatialRefSys, SIGNAL( clicked() ),
this, SLOT( changeCRS() ) );
76 populateConnectionList();
84 cbxUseTitleLayerName->setChecked( settings.
value(
"/Windows/SourceSelectDialog/UseTitleLayerName",
false ).
toBool() );
94 gbImageEncoding->hide();
98 cbxFeatureCurrentViewExtent->hide();
115 settings.
setValue(
"/Windows/SourceSelectDialog/UseTitleLayerName", cbxUseTitleLayerName->isChecked() );
131 while (( item = gbImageEncoding->
layout()->
takeAt( 0 ) ) !=
nullptr )
138 foreach (
const QString& encoding, availableEncodings )
140 bool supported =
false;
141 foreach (
const QByteArray& fmt, supportedFormats )
143 if ( encoding.
startsWith( fmt, Qt::CaseInsensitive ) )
155 gbImageEncoding->layout()->addWidget( button );
166 void QgsSourceSelectDialog::populateConnectionList()
169 cmbConnections->clear();
170 foreach (
const QString& item, conns )
172 cmbConnections->addItem( item );
174 bool connectionsAvailable = !conns.
isEmpty();
175 btnConnect->setEnabled( connectionsAvailable );
176 btnEdit->setEnabled( connectionsAvailable );
177 btnDelete->setEnabled( connectionsAvailable );
178 btnSave->setEnabled( connectionsAvailable );
182 int index = cmbConnections->findText( selectedConnection );
185 cmbConnections->setCurrentIndex( index );
191 if ( crsSet.
size() < 1 )
203 ProjectCRS = projectRefSys.
authid();
221 void QgsSourceSelectDialog::addEntryToServerList()
229 populateConnectionList();
234 void QgsSourceSelectDialog::modifyEntryOfServerList()
241 populateConnectionList();
246 void QgsSourceSelectDialog::deleteEntryOfServerList()
248 QString msg =
tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
249 .
arg( cmbConnections->currentText() );
251 if ( result == QMessageBox::Ok )
254 cmbConnections->removeItem( cmbConnections->currentIndex() );
256 bool connectionsAvailable = cmbConnections->count() > 0;
257 btnConnect->setEnabled( connectionsAvailable );
258 btnEdit->setEnabled( connectionsAvailable );
259 btnDelete->setEnabled( connectionsAvailable );
260 btnSave->setEnabled( connectionsAvailable );
264 void QgsSourceSelectDialog::connectToServer()
266 bool haveLayers =
false;
267 btnConnect->setEnabled(
false );
282 for (
int i = 0; i < treeView->header()->count(); ++i )
284 treeView->resizeColumnToContents( i );
285 if ( i < 2 && treeView->columnWidth( i ) > 300 )
287 treeView->setColumnWidth( i, 300 );
290 treeView->selectionModel()->select(
mModel->
index( 0, 0 ), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
291 treeView->setFocus();
299 btnConnect->setEnabled(
true );
305 btnChangeSpatialRefSys->setEnabled( haveLayers );
308 void QgsSourceSelectDialog::addButtonClicked()
310 if ( treeView->selectionModel()->selectedRows().isEmpty() )
317 QString pCrsString( labelCoordRefSys->text() );
337 QModelIndexList list = treeView->selectionModel()->selectedRows();
338 for (
int i = 0; i < list.size(); i++ )
350 if ( cbxUseTitleLayerName->isChecked() && !layerTitle.
isEmpty() )
352 layerName = layerTitle;
357 layerExtent = extent;
359 QString uri =
getLayerURI( connection, layerTitle, layerName, pCrsString, filter, layerExtent );
361 QgsDebugMsg(
"Layer " + layerName +
", uri: " + uri );
367 void QgsSourceSelectDialog::changeCRS()
372 labelCoordRefSys->setText( crsString );
376 void QgsSourceSelectDialog::changeCRSFilter()
380 QModelIndex currentIndex = treeView->selectionModel()->currentIndex();
383 QString currentTypename = currentIndex.
sibling( currentIndex.
row(), 1 ).data().toString();
392 crsNames.
insert( crsName );
397 QString preferredCRS = getPreferredCrs( crsNames );
403 labelCoordRefSys->setText( preferredCRS );
410 void QgsSourceSelectDialog::on_cmbConnections_activated(
int index )
416 void QgsSourceSelectDialog::treeWidgetItemDoubleClicked(
const QModelIndex&
index )
423 void QgsSourceSelectDialog::treeWidgetCurrentRowChanged(
const QModelIndex & current,
const QModelIndex & previous )
426 QgsDebugMsg(
"treeWidget_currentRowChanged called" );
435 void QgsSourceSelectDialog::buildQueryButtonClicked()
439 buildQuery( connection, treeView->selectionModel()->currentIndex() );
442 void QgsSourceSelectDialog::filterChanged(
QString text )
444 QgsDebugMsg(
"FeatureType filter changed to :" + text );
445 QRegExp::PatternSyntax mySyntax = QRegExp::PatternSyntax( QRegExp::RegExp );
446 Qt::CaseSensitivity myCaseSensitivity = Qt::CaseInsensitive;
447 QRegExp myRegExp( text, myCaseSensitivity, mySyntax );
464 void QgsSourceSelectDialog::on_buttonBox_helpRequested()
const const char * className() const
QgsRectangle mCanvasExtent
QgsSourceSelectItemDelegate(QObject *parent=0)
Constructor.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QByteArray toByteArray() const
A rectangle specified with double values.
void setHeight(int height)
QgsSourceSelectDialog(const QString &serviceName, ServiceType serviceType, QWidget *parent, Qt::WindowFlags fl)
Constructor.
QgsCoordinateReferenceSystem crsByOgcWmsCrs(const QString &ogcCrs) const
Returns the CRS from a given OGC WMS-format Coordinate Reference System string.
virtual void sort(int column, Qt::SortOrder order)
void addLayer(QString uri, QString typeName)
Emitted when a layer is added from the dialog.
virtual void setSourceModel(QAbstractItemModel *sourceModel)
static QString selectedConnection(const QString &theService)
Retreives the selected connection for the specified service.
virtual bool connectToService(const QgsOWSConnection &connection)=0
To be implemented in the child class.
QStandardItemModel * mModel
A generic dialog to prompt the user for a Coordinate Reference System.
static QStringList connectionList(const QString &theService)
Returns the list of connections for the specified service.
virtual QLayout * layout()
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
const_iterator insert(const T &value)
QgsCoordinateReferenceSystem mCanvasCrs
QgsGenericProjectionSelector * mProjectionSelector
QString tr(const char *sourceText, const char *disambiguation, int n)
Qt::CheckState checkState() const
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
QgsCoordinateReferenceSystem crsBySrsId(long srsId) const
Returns the CRS from a specified QGIS SRS ID.
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
static void setSelectedConnection(const QString &theService, const QString &name)
Marks the specified connection for the specified service as selected.
void populateImageEncodings(const QStringList &availableEncodings)
Updates the UI for the list of available image encodings from the specified list. ...
static void run(const QString &context)
void setValue(const QString &key, const QVariant &value)
static void deleteConnection(const QString &theService, const QString &name)
Deletes the connection for the specified service with the specified name.
void connectionsChanged()
Emitted when the connections for the service were changed.
void setMessage(QString theMessage="")
If no parameter is passed, the message will be a generic 'define the CRS for this layer'...
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
QSortFilterProxyModel * mModelProxy
QButtonGroup * mImageEncodingGroup
ServiceType
Whether the dialog is for a map service or a feature service.
QString asWktCoordinates() const
returns string representation in Wkt form
QMap< QString, QStringList > mAvailableCRS
QStandardItem * item(int row, int column) const
~QgsSourceSelectDialog()
Destructor.
const_iterator constBegin() const
bool contains(const T &value) const
QVariant value(const QString &key, const QVariant &defaultValue) const
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
virtual QString getLayerURI(const QgsOWSConnection &connection, const QString &layerTitle, const QString &layerName, const QString &crs=QString(), const QString &filter=QString(), const QgsRectangle &bBox=QgsRectangle()) const =0
To be implemented in the child class.
void setSortCaseSensitivity(Qt::CaseSensitivity cs)
void setSelectedCrsId(long theID)
Qt::SortOrder sortOrder() const
QVariant data(int role) const
QModelIndex sibling(int row, int column) const
QPushButton * mBuildQueryButton
static QgsProject * instance()
Returns the QgsProject singleton instance.
Class for storing a coordinate reference system (CRS)
virtual int rowCount(const QModelIndex &parent) const
Custom exception class for Coordinate Reference System related exceptions.
void setRowCount(int rows)
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 void buildQuery(const QgsOWSConnection &, const QModelIndex &)
May be implemented in child classes for services which support customized queries.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
static QgsCRSCache * instance()
Returns a pointer to the QgsCRSCache singleton.
QString getSelectedImageEncoding() const
Returns the selected image encoding.
iterator find(const Key &key)
void setCurrentExtentAndCrs(const QgsRectangle &canvasExtent, const QgsCoordinateReferenceSystem &canvasCrs)
Sets the current extent and CRS.
QString authid() const
Returns the authority identifier for the CRS, which includes both the authority (eg EPSG) and the CRS...
virtual QLayoutItem * takeAt(int index)=0
void setFilterRegExp(const QRegExp ®Exp)
const T value(const Key &key) const
Item delegate with tweaked sizeHint.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setHorizontalHeaderItem(int column, QStandardItem *item)