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 );
66 buttonBox->button( QDialogButtonBox::Help )->setEnabled(
false );
68 populateConnectionList();
71 void QgsVectorTileSourceSelect::btnNew_clicked()
73 QgsVectorTileConnectionDialog nc(
this );
76 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
77 populateConnectionList();
78 emit connectionsChanged();
82 void QgsVectorTileSourceSelect::newArcgisVectorTileServerConnection()
84 QgsArcgisVectorTileConnectionDialog nc(
this );
87 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
88 populateConnectionList();
89 emit connectionsChanged();
93 void QgsVectorTileSourceSelect::btnEdit_clicked()
95 const QgsVectorTileProviderConnection::Data connection = QgsVectorTileProviderConnection::connection( cmbConnections->currentText() );
96 QString uri = QgsVectorTileProviderConnection::encodedUri( connection );
98 switch ( connection.serviceType )
100 case QgsVectorTileProviderConnection::Generic:
102 QgsVectorTileConnectionDialog nc(
this );
103 nc.setConnection( cmbConnections->currentText(), uri );
106 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
107 populateConnectionList();
108 emit connectionsChanged();
113 case QgsVectorTileProviderConnection::ArcgisVectorTileService:
115 QgsArcgisVectorTileConnectionDialog nc(
this );
117 nc.setConnection( cmbConnections->currentText(), uri );
120 QgsVectorTileProviderConnection::addConnection( nc.connectionName(), QgsVectorTileProviderConnection::decodedUri( nc.connectionUri() ) );
121 populateConnectionList();
122 emit connectionsChanged();
129 void QgsVectorTileSourceSelect::btnDelete_clicked()
131 QString msg = tr(
"Are you sure you want to remove the %1 connection and all associated settings?" )
132 .arg( cmbConnections->currentText() );
133 if ( QMessageBox::Yes != QMessageBox::question(
this, tr(
"Confirm Delete" ), msg, QMessageBox::Yes | QMessageBox::No ) )
136 QgsVectorTileProviderConnection::deleteConnection( cmbConnections->currentText() );
138 populateConnectionList();
139 emit connectionsChanged();
142 void QgsVectorTileSourceSelect::btnSave_clicked()
148 void QgsVectorTileSourceSelect::btnLoad_clicked()
150 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Load Connections" ), QDir::homePath(),
151 tr(
"XML files (*.xml *.XML)" ) );
152 if ( fileName.isEmpty() )
159 populateConnectionList();
162 void QgsVectorTileSourceSelect::addButtonClicked()
164 QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
165 emit addVectorTileLayer( uri, cmbConnections->currentText() );
168 void QgsVectorTileSourceSelect::populateConnectionList()
170 cmbConnections->blockSignals(
true );
171 cmbConnections->clear();
172 cmbConnections->addItems( QgsVectorTileProviderConnection::connectionList() );
173 cmbConnections->blockSignals(
false );
175 btnEdit->setDisabled( cmbConnections->count() == 0 );
176 btnDelete->setDisabled( cmbConnections->count() == 0 );
177 btnSave->setDisabled( cmbConnections->count() == 0 );
178 cmbConnections->setDisabled( cmbConnections->count() == 0 );
180 setConnectionListPosition();
183 void QgsVectorTileSourceSelect::setConnectionListPosition()
185 QString toSelect = QgsVectorTileProviderConnection::selectedConnection();
187 cmbConnections->setCurrentIndex( cmbConnections->findText( toSelect ) );
189 if ( cmbConnections->currentIndex() < 0 )
191 if ( toSelect.isNull() )
192 cmbConnections->setCurrentIndex( 0 );
194 cmbConnections->setCurrentIndex( cmbConnections->count() - 1 );
197 emit enableButtons( !cmbConnections->currentText().isEmpty() );
200 void QgsVectorTileSourceSelect::cmbConnections_currentTextChanged(
const QString &text )
202 QgsVectorTileProviderConnection::setSelectedConnection( text );
203 emit enableButtons( !text.isEmpty() );
206 void QgsVectorTileSourceSelect::showHelp()
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...
WidgetMode
Different ways a source select dialog can be used.