Skip to content

Commit d1c3e8d

Browse files
committedApr 1, 2023
Add Source tab to vector tile layer properties
Match other layer types, and add a Source tab with: - layer name - CRS override - optional provider source widget, for providers which expose this functionality This matches the content of the Source tab for other layer types
1 parent 875be15 commit d1c3e8d

File tree

4 files changed

+215
-5
lines changed

4 files changed

+215
-5
lines changed
 

‎python/gui/auto_generated/vectortile/qgsvectortilelayerproperties.sip.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111

1212

13-
14-
1513
class QgsVectorTileLayerProperties : QgsOptionsDialogBase
1614
{
1715
%Docstring(signature="appended")

‎src/gui/vectortile/qgsvectortilelayerproperties.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgshelp.h"
2020
#include "qgsmaplayerstylemanager.h"
2121
#include "qgsmaplayerstyleguiutils.h"
22+
#include "qgsprovidersourcewidgetproviderregistry.h"
2223
#include "qgsvectortilebasicrendererwidget.h"
2324
#include "qgsvectortilebasiclabelingwidget.h"
2425
#include "qgsvectortilelayer.h"
@@ -28,6 +29,8 @@
2829
#include "qgsmetadatawidget.h"
2930
#include "qgsmaplayerloadstyledialog.h"
3031
#include "qgsmapboxglstyleconverter.h"
32+
#include "qgsprovidersourcewidget.h"
33+
#include "qgsdatumtransformdialog.h"
3134
#include <QFileDialog>
3235
#include <QMenu>
3336
#include <QMessageBox>
@@ -54,11 +57,15 @@ QgsVectorTileLayerProperties::QgsVectorTileLayerProperties( QgsVectorTileLayer *
5457
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsVectorTileLayerProperties::apply );
5558
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorTileLayerProperties::showHelp );
5659

60+
connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsVectorTileLayerProperties::crsChanged );
61+
5762
// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
5863
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
5964
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
6065
initOptionsBase( false );
6166

67+
mSourceGroupBox->hide();
68+
6269
#ifdef WITH_QTWEBKIT
6370
// Setup information tab
6471

@@ -127,6 +134,18 @@ QgsVectorTileLayerProperties::QgsVectorTileLayerProperties( QgsVectorTileLayer *
127134

128135
void QgsVectorTileLayerProperties::apply()
129136
{
137+
if ( mSourceWidget )
138+
{
139+
const QString newSource = mSourceWidget->sourceUri();
140+
if ( newSource != mLayer->source() )
141+
{
142+
mLayer->setDataSource( newSource, mLayer->name(), mLayer->providerType(), QgsDataProvider::ProviderOptions() );
143+
}
144+
}
145+
146+
mLayer->setName( mLayerOrigNameLineEd->text() );
147+
mLayer->setCrs( mCrsSelector->crs() );
148+
130149
mRendererWidget->apply();
131150
mLabelingWidget->apply();
132151
mMetadataWidget->acceptMetadata();
@@ -156,6 +175,37 @@ void QgsVectorTileLayerProperties::syncToLayer()
156175
const QString html { mLayer->htmlMetadata().replace( QLatin1String( "<head>" ), QStringLiteral( R"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
157176
mMetadataViewer->setHtml( html );
158177

178+
/*
179+
* Source
180+
*/
181+
182+
mLayerOrigNameLineEd->setText( mLayer->name() );
183+
mCrsSelector->setCrs( mLayer->crs() );
184+
185+
if ( !mSourceWidget )
186+
{
187+
mSourceWidget = QgsGui::sourceWidgetProviderRegistry()->createWidget( mLayer );
188+
if ( mSourceWidget )
189+
{
190+
QHBoxLayout *layout = new QHBoxLayout();
191+
layout->addWidget( mSourceWidget );
192+
mSourceGroupBox->setLayout( layout );
193+
mSourceGroupBox->show();
194+
195+
connect( mSourceWidget, &QgsProviderSourceWidget::validChanged, this, [ = ]( bool isValid )
196+
{
197+
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
198+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
199+
} );
200+
}
201+
}
202+
203+
if ( mSourceWidget )
204+
{
205+
mSourceWidget->setMapCanvas( mMapCanvas );
206+
mSourceWidget->setSourceUri( mLayer->source() );
207+
}
208+
159209
/*
160210
* Symbology Tab
161211
*/
@@ -411,6 +461,13 @@ void QgsVectorTileLayerProperties::urlClicked( const QUrl &url )
411461
QDesktopServices::openUrl( url );
412462
}
413463

464+
void QgsVectorTileLayerProperties::crsChanged( const QgsCoordinateReferenceSystem &crs )
465+
{
466+
QgsDatumTransformDialog::run( crs, QgsProject::instance()->crs(), this, mMapCanvas, tr( "Select Transformation" ) );
467+
mLayer->setCrs( crs );
468+
mMetadataWidget->crsChanged();
469+
}
470+
414471
void QgsVectorTileLayerProperties::optionsStackedWidget_CurrentChanged( int index )
415472
{
416473
QgsOptionsDialogBase::optionsStackedWidget_CurrentChanged( index );

‎src/gui/vectortile/qgsvectortilelayerproperties.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
#define QGSVECTORTILELAYERPROPERTIES_H
1818

1919
#include "qgsoptionsdialogbase.h"
20-
2120
#include "ui_qgsvectortilelayerpropertiesbase.h"
22-
23-
#include "qgsmaplayerstylemanager.h"
21+
#include "qgsmaplayerstyle.h"
2422

2523
class QgsMapLayer;
2624
class QgsMapCanvas;
@@ -29,6 +27,7 @@ class QgsVectorTileBasicLabelingWidget;
2927
class QgsVectorTileBasicRendererWidget;
3028
class QgsVectorTileLayer;
3129
class QgsMetadataWidget;
30+
class QgsProviderSourceWidget;
3231

3332

3433
/**
@@ -57,6 +56,7 @@ class GUI_EXPORT QgsVectorTileLayerProperties : public QgsOptionsDialogBase, pri
5756
void saveMetadataAs();
5857
void showHelp();
5958
void urlClicked( const QUrl &url );
59+
void crsChanged( const QgsCoordinateReferenceSystem &crs );
6060

6161
protected slots:
6262
void optionsStackedWidget_CurrentChanged( int index ) override SIP_SKIP ;
@@ -78,6 +78,8 @@ class GUI_EXPORT QgsVectorTileLayerProperties : public QgsOptionsDialogBase, pri
7878
QgsMapCanvas *mMapCanvas = nullptr;
7979
QgsMetadataWidget *mMetadataWidget = nullptr;
8080

81+
QgsProviderSourceWidget *mSourceWidget = nullptr;
82+
8183
/**
8284
* Previous layer style. Used to reset style to previous state if new style
8385
* was loaded but dialog is canceled.

‎src/ui/qgsvectortilelayerpropertiesbase.ui

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@
110110
<normaloff>:/images/themes/default/propertyicons/metadata.svg</normaloff>:/images/themes/default/propertyicons/metadata.svg</iconset>
111111
</property>
112112
</item>
113+
<item>
114+
<property name="text">
115+
<string>Source</string>
116+
</property>
117+
<property name="toolTip">
118+
<string>Source</string>
119+
</property>
120+
<property name="icon">
121+
<iconset resource="../../images/images.qrc">
122+
<normaloff>:/images/themes/default/propertyicons/system.svg</normaloff>:/images/themes/default/propertyicons/system.svg</iconset>
123+
</property>
124+
</item>
113125
<item>
114126
<property name="text">
115127
<string>Symbology</string>
@@ -209,6 +221,129 @@
209221
</item>
210222
</layout>
211223
</widget>
224+
<widget class="QWidget" name="mOptsPage_Source">
225+
<layout class="QVBoxLayout" name="verticalLayout_6">
226+
<property name="leftMargin">
227+
<number>0</number>
228+
</property>
229+
<property name="topMargin">
230+
<number>0</number>
231+
</property>
232+
<property name="rightMargin">
233+
<number>0</number>
234+
</property>
235+
<property name="bottomMargin">
236+
<number>0</number>
237+
</property>
238+
<item>
239+
<widget class="QgsScrollArea" name="scrollArea_3">
240+
<property name="frameShape">
241+
<enum>QFrame::NoFrame</enum>
242+
</property>
243+
<property name="widgetResizable">
244+
<bool>true</bool>
245+
</property>
246+
<widget class="QWidget" name="scrollAreaWidgetContents_3">
247+
<property name="geometry">
248+
<rect>
249+
<x>0</x>
250+
<y>0</y>
251+
<width>661</width>
252+
<height>507</height>
253+
</rect>
254+
</property>
255+
<layout class="QVBoxLayout" name="verticalLayout_7">
256+
<item>
257+
<layout class="QHBoxLayout" name="horizontalLayout_14">
258+
<item>
259+
<widget class="QLabel" name="label_8">
260+
<property name="text">
261+
<string>Layer name</string>
262+
</property>
263+
</widget>
264+
</item>
265+
<item>
266+
<widget class="QLineEdit" name="mLayerOrigNameLineEd"/>
267+
</item>
268+
</layout>
269+
</item>
270+
<item>
271+
<widget class="QgsCollapsibleGroupBox" name="mCrsGroupBox">
272+
<property name="focusPolicy">
273+
<enum>Qt::StrongFocus</enum>
274+
</property>
275+
<property name="title">
276+
<string>Assigned Coordinate Reference System (CRS)</string>
277+
</property>
278+
<property name="checkable">
279+
<bool>false</bool>
280+
</property>
281+
<property name="syncGroup" stdset="0">
282+
<string notr="true">vectorgeneral</string>
283+
</property>
284+
<layout class="QVBoxLayout" name="verticalLayout_28">
285+
<property name="spacing">
286+
<number>6</number>
287+
</property>
288+
<item>
289+
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
290+
<property name="focusPolicy">
291+
<enum>Qt::StrongFocus</enum>
292+
</property>
293+
</widget>
294+
</item>
295+
<item>
296+
<widget class="QLabel" name="label_17">
297+
<property name="text">
298+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Changing this option does not modify the original data source or perform any reprojection of the vector tile layer. Rather, it can be used to override the layer's CRS within this project if it could not be detected or has been incorrectly detected.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
299+
</property>
300+
<property name="textFormat">
301+
<enum>Qt::RichText</enum>
302+
</property>
303+
<property name="wordWrap">
304+
<bool>true</bool>
305+
</property>
306+
</widget>
307+
</item>
308+
<item>
309+
<widget class="Line" name="line_4">
310+
<property name="orientation">
311+
<enum>Qt::Vertical</enum>
312+
</property>
313+
</widget>
314+
</item>
315+
</layout>
316+
</widget>
317+
</item>
318+
<item>
319+
<widget class="QgsCollapsibleGroupBox" name="mSourceGroupBox">
320+
<property name="title">
321+
<string>Layer Source</string>
322+
</property>
323+
</widget>
324+
</item>
325+
<item>
326+
<spacer name="verticalSpacer_3">
327+
<property name="orientation">
328+
<enum>Qt::Vertical</enum>
329+
</property>
330+
<property name="sizeType">
331+
<enum>QSizePolicy::Expanding</enum>
332+
</property>
333+
<property name="sizeHint" stdset="0">
334+
<size>
335+
<width>17</width>
336+
<height>111</height>
337+
</size>
338+
</property>
339+
</spacer>
340+
</item>
341+
</layout>
342+
</widget>
343+
</widget>
344+
</item>
345+
</layout>
346+
</widget>
212347
<widget class="QWidget" name="mOptsPage_Style">
213348
<layout class="QVBoxLayout" name="verticalLayout_14">
214349
<property name="leftMargin">
@@ -303,11 +438,29 @@
303438
</layout>
304439
</widget>
305440
<customwidgets>
441+
<customwidget>
442+
<class>QgsCollapsibleGroupBox</class>
443+
<extends>QGroupBox</extends>
444+
<header>qgscollapsiblegroupbox.h</header>
445+
<container>1</container>
446+
</customwidget>
306447
<customwidget>
307448
<class>QgsFilterLineEdit</class>
308449
<extends>QLineEdit</extends>
309450
<header>qgsfilterlineedit.h</header>
310451
</customwidget>
452+
<customwidget>
453+
<class>QgsProjectionSelectionWidget</class>
454+
<extends>QWidget</extends>
455+
<header>qgsprojectionselectionwidget.h</header>
456+
<container>1</container>
457+
</customwidget>
458+
<customwidget>
459+
<class>QgsScrollArea</class>
460+
<extends>QScrollArea</extends>
461+
<header>qgsscrollarea.h</header>
462+
<container>1</container>
463+
</customwidget>
311464
<customwidget>
312465
<class>QgsWebView</class>
313466
<extends>QWidget</extends>

0 commit comments

Comments
 (0)
Please sign in to comment.