26 #include <QFileDialog>
27 #include <QMessageBox>
28 #include <QPushButton>
39 setWindowTitle( tr(
"Add Vector Tile Layer" ) );
40 mConnectionsGroupBox->setTitle( tr(
"Vector Tile Connections" ) );
44 btnNew->setPopupMode( QToolButton::InstantPopup );
45 QMenu *newMenu =
new QMenu( btnNew );
47 QAction *actionNew =
new QAction( tr(
"New Generic Connection…" ),
this );
48 connect( actionNew, &QAction::triggered,
this, &QgsVectorTileSourceSelect::btnNew_clicked );
49 newMenu->addAction( actionNew );
51 QAction *actionNewArcGISConnection =
new QAction( tr(
"New ArcGIS Vector Tile Service Connection…" ),
this );
52 connect( actionNewArcGISConnection, &QAction::triggered,
this, &QgsVectorTileSourceSelect::newArcgisVectorTileServerConnection );
53 newMenu->addAction( actionNewArcGISConnection );
55 btnNew->setMenu( newMenu );
57 connect( btnEdit, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnEdit_clicked );
58 connect( btnDelete, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnDelete_clicked );
59 connect( btnSave, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnSave_clicked );
60 connect( btnLoad, &QToolButton::clicked,
this, &QgsVectorTileSourceSelect::btnLoad_clicked );
61 connect( cmbConnections, &QComboBox::currentTextChanged,
this, &QgsVectorTileSourceSelect::cmbConnections_currentTextChanged );
62 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileSourceSelect::showHelp );
63 setupButtons( buttonBox );
65 populateConnectionList();
68 void QgsVectorTileSourceSelect::btnNew_clicked()
70 QgsVectorTileConnectionDialog nc(
this );
73 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
74 populateConnectionList();
75 emit connectionsChanged();
79 void QgsVectorTileSourceSelect::newArcgisVectorTileServerConnection()
81 QgsArcgisVectorTileConnectionDialog nc(
this );
84 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
85 populateConnectionList();
86 emit connectionsChanged();
90 void QgsVectorTileSourceSelect::btnEdit_clicked()
92 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( cmbConnections->currentText() );
93 const QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
95 switch ( connection.serviceType )
97 case QgsVectorTileProviderConnection::Generic:
99 QgsVectorTileConnectionDialog nc(
this );
100 nc.setConnection( cmbConnections->currentText(), uri );
103 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
104 populateConnectionList();
105 emit connectionsChanged();
110 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
112 QgsArcgisVectorTileConnectionDialog nc(
this );
114 nc.setConnection( cmbConnections->currentText(), uri );
117 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
118 populateConnectionList();
119 emit connectionsChanged();
126 void QgsVectorTileSourceSelect::btnDelete_clicked()
128 const QString msg = tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
129 .arg( cmbConnections->currentText() );
130 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Confirm Delete" ), msg, QMessageBox::Yes | QMessageBox::No ) )
133 QgsVectorTileProviderConnection::deleteConnection( cmbConnections->currentText() );
135 populateConnectionList();
136 emit connectionsChanged();
139 void QgsVectorTileSourceSelect::btnSave_clicked()
145 void QgsVectorTileSourceSelect::btnLoad_clicked()
147 const QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Load Connections" ), QDir::homePath(),
148 tr(
"XML files (*.xml *.XML)" ) );
149 if ( fileName.isEmpty() )
156 populateConnectionList();
159 void QgsVectorTileSourceSelect::addButtonClicked()
161 const QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
162 emit addVectorTileLayer( uri, cmbConnections->currentText() );
165 void QgsVectorTileSourceSelect::populateConnectionList()
167 cmbConnections->blockSignals(
true );
168 cmbConnections->clear();
169 cmbConnections->addItems( QgsVectorTileProviderConnection::connectionList() );
170 cmbConnections->blockSignals(
false );
172 btnEdit->setDisabled( cmbConnections->count() == 0 );
173 btnDelete->setDisabled( cmbConnections->count() == 0 );
174 btnSave->setDisabled( cmbConnections->count() == 0 );
175 cmbConnections->setDisabled( cmbConnections->count() == 0 );
177 setConnectionListPosition();
180 void QgsVectorTileSourceSelect::setConnectionListPosition()
182 const QString toSelect = QgsVectorTileProviderConnection::selectedConnection();
184 cmbConnections->setCurrentIndex( cmbConnections->findText( toSelect ) );
186 if ( cmbConnections->currentIndex() < 0 )
188 if ( toSelect.isNull() )
189 cmbConnections->setCurrentIndex( 0 );
191 cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
194 emit enableButtons( !cmbConnections->currentText().isEmpty() );
197 void QgsVectorTileSourceSelect::cmbConnections_currentTextChanged(
const QString &text )
199 QgsVectorTileProviderConnection::setSelectedConnection( text );
200 emit enableButtons( !text.isEmpty() );
203 void QgsVectorTileSourceSelect::showHelp()
205 QgsHelp::openHelp( QStringLiteral(
"managing_data_source/opening_data.html#using-vector-tiles-services" ) );
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
WidgetMode
Different ways a source select dialog can be used.