Skip to content

Commit 692d7a7

Browse files
committedApr 2, 2023
[feature] Expose option to load vector tile sources from files
in Data Source Manager The Vector Tile tab now includes choices for selecting from a "Service" (the existing, connection based approach for adding vector tiles from online sources) or "File" (the new option which allows directly adding VTPK or MBTiles vector tile files)
1 parent e4a84d6 commit 692d7a7

File tree

2 files changed

+284
-97
lines changed

2 files changed

+284
-97
lines changed
 

‎src/gui/vectortile/qgsvectortilesourceselect.cpp

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "qgsvectortileconnection.h"
2323
#include "qgsvectortileconnectiondialog.h"
2424
#include "qgsarcgisvectortileconnectiondialog.h"
25+
#include "qgsprovidermetadata.h"
26+
#include "qgsproviderutils.h"
2527

2628
#include <QFileDialog>
2729
#include <QMessageBox>
@@ -36,10 +38,25 @@ QgsVectorTileSourceSelect::QgsVectorTileSourceSelect( QWidget *parent, Qt::Windo
3638
{
3739
setupUi( this );
3840

41+
QgsGui::enableAutoGeometryRestore( this );
42+
3943
setWindowTitle( tr( "Add Vector Tile Layer" ) );
40-
mConnectionsGroupBox->setTitle( tr( "Vector Tile Connections" ) );
4144

42-
QgsGui::enableAutoGeometryRestore( this );
45+
mRadioSourceService->setChecked( true );
46+
mStackedWidget->setCurrentIndex( 1 );
47+
48+
connect( mRadioSourceFile, &QRadioButton::toggled, this, [this]
49+
{
50+
mStackedWidget->setCurrentIndex( 0 );
51+
52+
emit enableButtons( !mFileWidget->filePath().isEmpty() );
53+
} );
54+
connect( mRadioSourceService, &QRadioButton::toggled, this, [this]
55+
{
56+
mStackedWidget->setCurrentIndex( 1 );
57+
58+
emit enableButtons( !cmbConnections->currentText().isEmpty() );
59+
} );
4360

4461
btnNew->setPopupMode( QToolButton::InstantPopup );
4562
QMenu *newMenu = new QMenu( btnNew );
@@ -63,6 +80,15 @@ QgsVectorTileSourceSelect::QgsVectorTileSourceSelect( QWidget *parent, Qt::Windo
6380
setupButtons( buttonBox );
6481

6582
populateConnectionList();
83+
84+
mFileWidget->setDialogTitle( tr( "Open Vector Tile Dataset" ) );
85+
mFileWidget->setFilter( QgsProviderRegistry::instance()->fileVectorTileFilters() );
86+
mFileWidget->setStorageMode( QgsFileWidget::GetFile );
87+
mFileWidget->setOptions( QFileDialog::HideNameFilterDetails );
88+
connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
89+
{
90+
emit enableButtons( ! path.isEmpty() );
91+
} );
6692
}
6793

6894
void QgsVectorTileSourceSelect::btnNew_clicked()
@@ -158,8 +184,31 @@ void QgsVectorTileSourceSelect::btnLoad_clicked()
158184

159185
void QgsVectorTileSourceSelect::addButtonClicked()
160186
{
161-
const QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
162-
emit addVectorTileLayer( uri, cmbConnections->currentText() );
187+
if ( mRadioSourceService->isChecked() )
188+
{
189+
190+
const QString uri = QgsVectorTileProviderConnection::encodedUri( QgsVectorTileProviderConnection::connection( cmbConnections->currentText() ) );
191+
emit addVectorTileLayer( uri, cmbConnections->currentText() );
192+
}
193+
else if ( mRadioSourceFile->isChecked() )
194+
{
195+
const QString filePath = mFileWidget->filePath();
196+
const QList< QgsProviderRegistry::ProviderCandidateDetails > providers = QgsProviderRegistry::instance()->preferredProvidersForUri( filePath );
197+
QString providerKey;
198+
for ( const QgsProviderRegistry::ProviderCandidateDetails &details : providers )
199+
{
200+
if ( details.layerTypes().contains( Qgis::LayerType::VectorTile ) )
201+
{
202+
providerKey = details.metadata()->key();
203+
}
204+
}
205+
206+
QVariantMap parts;
207+
parts.insert( QStringLiteral( "path" ), filePath );
208+
const QString uri = QgsProviderRegistry::instance()->encodeUri( providerKey, parts );
209+
210+
emit addVectorTileLayer( uri, QgsProviderUtils::suggestLayerNameFromFilePath( filePath ) );
211+
}
163212
}
164213

165214
void QgsVectorTileSourceSelect::populateConnectionList()

‎src/ui/qgsvectortilesourceselectbase.ui

Lines changed: 231 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,120 +6,258 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>558</width>
10-
<height>259</height>
9+
<width>553</width>
10+
<height>383</height>
1111
</rect>
1212
</property>
13-
<layout class="QGridLayout" name="gridLayout">
14-
<item row="2" column="0">
15-
<widget class="QDialogButtonBox" name="buttonBox">
16-
<property name="orientation">
17-
<enum>Qt::Horizontal</enum>
18-
</property>
19-
<property name="standardButtons">
20-
<set>QDialogButtonBox::Help</set>
13+
<layout class="QVBoxLayout" name="verticalLayout_3">
14+
<property name="leftMargin">
15+
<number>0</number>
16+
</property>
17+
<property name="topMargin">
18+
<number>0</number>
19+
</property>
20+
<property name="rightMargin">
21+
<number>0</number>
22+
</property>
23+
<property name="bottomMargin">
24+
<number>0</number>
25+
</property>
26+
<item>
27+
<widget class="QGroupBox" name="srcGroupBox">
28+
<property name="sizePolicy">
29+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
30+
<horstretch>0</horstretch>
31+
<verstretch>0</verstretch>
32+
</sizepolicy>
2133
</property>
22-
</widget>
23-
</item>
24-
<item row="1" column="0">
25-
<spacer name="verticalSpacer">
26-
<property name="orientation">
27-
<enum>Qt::Vertical</enum>
28-
</property>
29-
<property name="sizeHint" stdset="0">
30-
<size>
31-
<width>20</width>
32-
<height>40</height>
33-
</size>
34-
</property>
35-
</spacer>
36-
</item>
37-
<item row="0" column="0">
38-
<widget class="QGroupBox" name="mConnectionsGroupBox">
3934
<property name="title">
40-
<string>Connections</string>
35+
<string>Source Type</string>
4136
</property>
42-
<layout class="QGridLayout" name="gridLayout_2">
43-
<item row="1" column="4">
44-
<spacer>
45-
<property name="orientation">
46-
<enum>Qt::Horizontal</enum>
47-
</property>
48-
<property name="sizeType">
49-
<enum>QSizePolicy::Expanding</enum>
50-
</property>
51-
<property name="sizeHint" stdset="0">
52-
<size>
53-
<width>171</width>
54-
<height>30</height>
55-
</size>
56-
</property>
57-
</spacer>
58-
</item>
59-
<item row="0" column="0" colspan="7">
60-
<widget class="QComboBox" name="cmbConnections"/>
61-
</item>
62-
<item row="1" column="2">
63-
<widget class="QToolButton" name="btnEdit">
64-
<property name="enabled">
65-
<bool>false</bool>
66-
</property>
67-
<property name="toolTip">
68-
<string>Edit selected service connection</string>
69-
</property>
37+
<layout class="QHBoxLayout" name="horizontalLayout1">
38+
<item>
39+
<widget class="QRadioButton" name="mRadioSourceFile">
7040
<property name="text">
71-
<string>Edit</string>
41+
<string>F&amp;ile</string>
7242
</property>
7343
</widget>
7444
</item>
75-
<item row="1" column="3">
76-
<widget class="QToolButton" name="btnDelete">
77-
<property name="enabled">
78-
<bool>false</bool>
79-
</property>
80-
<property name="toolTip">
81-
<string>Remove connection to selected service</string>
82-
</property>
45+
<item>
46+
<widget class="QRadioButton" name="mRadioSourceService">
8347
<property name="text">
84-
<string>Remove</string>
48+
<string>Service</string>
8549
</property>
8650
</widget>
8751
</item>
88-
<item row="1" column="5">
89-
<widget class="QToolButton" name="btnLoad">
90-
<property name="toolTip">
91-
<string>Load connections from file</string>
92-
</property>
93-
<property name="text">
94-
<string>Load</string>
95-
</property>
96-
</widget>
97-
</item>
98-
<item row="1" column="6">
99-
<widget class="QToolButton" name="btnSave">
100-
<property name="toolTip">
101-
<string>Save connections to file</string>
102-
</property>
103-
<property name="text">
104-
<string>Save</string>
105-
</property>
106-
</widget>
107-
</item>
108-
<item row="1" column="0" colspan="2">
109-
<widget class="QToolButton" name="btnNew">
110-
<property name="toolTip">
111-
<string>Create a new service connection</string>
52+
<item>
53+
<spacer name="horizontalSpacer">
54+
<property name="orientation">
55+
<enum>Qt::Horizontal</enum>
11256
</property>
113-
<property name="text">
114-
<string>&amp;New</string>
57+
<property name="sizeHint" stdset="0">
58+
<size>
59+
<width>20</width>
60+
<height>40</height>
61+
</size>
11562
</property>
116-
</widget>
63+
</spacer>
11764
</item>
11865
</layout>
11966
</widget>
12067
</item>
68+
<item>
69+
<widget class="QStackedWidget" name="mStackedWidget">
70+
<property name="currentIndex">
71+
<number>1</number>
72+
</property>
73+
<widget class="QWidget" name="page">
74+
<layout class="QVBoxLayout" name="verticalLayout_2">
75+
<property name="leftMargin">
76+
<number>0</number>
77+
</property>
78+
<property name="topMargin">
79+
<number>0</number>
80+
</property>
81+
<property name="rightMargin">
82+
<number>0</number>
83+
</property>
84+
<property name="bottomMargin">
85+
<number>0</number>
86+
</property>
87+
<item>
88+
<widget class="QGroupBox" name="fileGroupBox">
89+
<property name="sizePolicy">
90+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
91+
<horstretch>0</horstretch>
92+
<verstretch>0</verstretch>
93+
</sizepolicy>
94+
</property>
95+
<property name="title">
96+
<string>Source</string>
97+
</property>
98+
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,2">
99+
<item>
100+
<widget class="QLabel" name="label">
101+
<property name="text">
102+
<string>Vector tile dataset</string>
103+
</property>
104+
</widget>
105+
</item>
106+
<item>
107+
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
108+
</item>
109+
</layout>
110+
</widget>
111+
</item>
112+
<item>
113+
<spacer name="verticalSpacer_2">
114+
<property name="orientation">
115+
<enum>Qt::Vertical</enum>
116+
</property>
117+
<property name="sizeHint" stdset="0">
118+
<size>
119+
<width>20</width>
120+
<height>40</height>
121+
</size>
122+
</property>
123+
</spacer>
124+
</item>
125+
</layout>
126+
</widget>
127+
<widget class="QWidget" name="page_2">
128+
<layout class="QVBoxLayout" name="verticalLayout">
129+
<property name="leftMargin">
130+
<number>0</number>
131+
</property>
132+
<property name="topMargin">
133+
<number>0</number>
134+
</property>
135+
<property name="rightMargin">
136+
<number>0</number>
137+
</property>
138+
<property name="bottomMargin">
139+
<number>0</number>
140+
</property>
141+
<item>
142+
<widget class="QGroupBox" name="mConnectionsGroupBox">
143+
<property name="title">
144+
<string>Connections</string>
145+
</property>
146+
<layout class="QGridLayout" name="gridLayout_2">
147+
<item row="0" column="0" colspan="7">
148+
<widget class="QComboBox" name="cmbConnections"/>
149+
</item>
150+
<item row="1" column="5">
151+
<widget class="QToolButton" name="btnLoad">
152+
<property name="toolTip">
153+
<string>Load connections from file</string>
154+
</property>
155+
<property name="text">
156+
<string>Load</string>
157+
</property>
158+
</widget>
159+
</item>
160+
<item row="1" column="4">
161+
<spacer>
162+
<property name="orientation">
163+
<enum>Qt::Horizontal</enum>
164+
</property>
165+
<property name="sizeType">
166+
<enum>QSizePolicy::Expanding</enum>
167+
</property>
168+
<property name="sizeHint" stdset="0">
169+
<size>
170+
<width>171</width>
171+
<height>30</height>
172+
</size>
173+
</property>
174+
</spacer>
175+
</item>
176+
<item row="1" column="2">
177+
<widget class="QToolButton" name="btnEdit">
178+
<property name="enabled">
179+
<bool>false</bool>
180+
</property>
181+
<property name="toolTip">
182+
<string>Edit selected service connection</string>
183+
</property>
184+
<property name="text">
185+
<string>Edit</string>
186+
</property>
187+
</widget>
188+
</item>
189+
<item row="1" column="3">
190+
<widget class="QToolButton" name="btnDelete">
191+
<property name="enabled">
192+
<bool>false</bool>
193+
</property>
194+
<property name="toolTip">
195+
<string>Remove connection to selected service</string>
196+
</property>
197+
<property name="text">
198+
<string>Remove</string>
199+
</property>
200+
</widget>
201+
</item>
202+
<item row="1" column="0" colspan="2">
203+
<widget class="QToolButton" name="btnNew">
204+
<property name="toolTip">
205+
<string>Create a new service connection</string>
206+
</property>
207+
<property name="text">
208+
<string>&amp;New</string>
209+
</property>
210+
</widget>
211+
</item>
212+
<item row="1" column="6">
213+
<widget class="QToolButton" name="btnSave">
214+
<property name="toolTip">
215+
<string>Save connections to file</string>
216+
</property>
217+
<property name="text">
218+
<string>Save</string>
219+
</property>
220+
</widget>
221+
</item>
222+
<item row="2" column="3">
223+
<spacer name="verticalSpacer">
224+
<property name="orientation">
225+
<enum>Qt::Vertical</enum>
226+
</property>
227+
<property name="sizeHint" stdset="0">
228+
<size>
229+
<width>20</width>
230+
<height>40</height>
231+
</size>
232+
</property>
233+
</spacer>
234+
</item>
235+
</layout>
236+
</widget>
237+
</item>
238+
</layout>
239+
</widget>
240+
</widget>
241+
</item>
242+
<item>
243+
<widget class="QDialogButtonBox" name="buttonBox">
244+
<property name="orientation">
245+
<enum>Qt::Horizontal</enum>
246+
</property>
247+
<property name="standardButtons">
248+
<set>QDialogButtonBox::Help</set>
249+
</property>
250+
</widget>
251+
</item>
121252
</layout>
122253
</widget>
254+
<customwidgets>
255+
<customwidget>
256+
<class>QgsFileWidget</class>
257+
<extends>QWidget</extends>
258+
<header>qgsfilewidget.h</header>
259+
</customwidget>
260+
</customwidgets>
123261
<tabstops>
124262
<tabstop>cmbConnections</tabstop>
125263
<tabstop>btnNew</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.