Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nyalldawson committed Apr 1, 2023
1 parent 875be15 commit d1c3e8d
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 5 deletions.
Expand Up @@ -10,8 +10,6 @@





class QgsVectorTileLayerProperties : QgsOptionsDialogBase
{
%Docstring(signature="appended")
Expand Down
57 changes: 57 additions & 0 deletions src/gui/vectortile/qgsvectortilelayerproperties.cpp
Expand Up @@ -19,6 +19,7 @@
#include "qgshelp.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsprovidersourcewidgetproviderregistry.h"
#include "qgsvectortilebasicrendererwidget.h"
#include "qgsvectortilebasiclabelingwidget.h"
#include "qgsvectortilelayer.h"
Expand All @@ -28,6 +29,8 @@
#include "qgsmetadatawidget.h"
#include "qgsmaplayerloadstyledialog.h"
#include "qgsmapboxglstyleconverter.h"
#include "qgsprovidersourcewidget.h"
#include "qgsdatumtransformdialog.h"
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
Expand All @@ -54,11 +57,15 @@ QgsVectorTileLayerProperties::QgsVectorTileLayerProperties( QgsVectorTileLayer *
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsVectorTileLayerProperties::apply );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsVectorTileLayerProperties::showHelp );

connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsVectorTileLayerProperties::crsChanged );

// QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
// switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( false );

mSourceGroupBox->hide();

#ifdef WITH_QTWEBKIT
// Setup information tab

Expand Down Expand Up @@ -127,6 +134,18 @@ QgsVectorTileLayerProperties::QgsVectorTileLayerProperties( QgsVectorTileLayer *

void QgsVectorTileLayerProperties::apply()
{
if ( mSourceWidget )
{
const QString newSource = mSourceWidget->sourceUri();
if ( newSource != mLayer->source() )
{
mLayer->setDataSource( newSource, mLayer->name(), mLayer->providerType(), QgsDataProvider::ProviderOptions() );
}
}

mLayer->setName( mLayerOrigNameLineEd->text() );
mLayer->setCrs( mCrsSelector->crs() );

mRendererWidget->apply();
mLabelingWidget->apply();
mMetadataWidget->acceptMetadata();
Expand Down Expand Up @@ -156,6 +175,37 @@ void QgsVectorTileLayerProperties::syncToLayer()
const QString html { mLayer->htmlMetadata().replace( QLatin1String( "<head>" ), QStringLiteral( R"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
mMetadataViewer->setHtml( html );

/*
* Source
*/

mLayerOrigNameLineEd->setText( mLayer->name() );
mCrsSelector->setCrs( mLayer->crs() );

if ( !mSourceWidget )
{
mSourceWidget = QgsGui::sourceWidgetProviderRegistry()->createWidget( mLayer );
if ( mSourceWidget )
{
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget( mSourceWidget );
mSourceGroupBox->setLayout( layout );
mSourceGroupBox->show();

connect( mSourceWidget, &QgsProviderSourceWidget::validChanged, this, [ = ]( bool isValid )
{
buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
} );
}
}

if ( mSourceWidget )
{
mSourceWidget->setMapCanvas( mMapCanvas );
mSourceWidget->setSourceUri( mLayer->source() );
}

/*
* Symbology Tab
*/
Expand Down Expand Up @@ -411,6 +461,13 @@ void QgsVectorTileLayerProperties::urlClicked( const QUrl &url )
QDesktopServices::openUrl( url );
}

void QgsVectorTileLayerProperties::crsChanged( const QgsCoordinateReferenceSystem &crs )
{
QgsDatumTransformDialog::run( crs, QgsProject::instance()->crs(), this, mMapCanvas, tr( "Select Transformation" ) );
mLayer->setCrs( crs );
mMetadataWidget->crsChanged();
}

void QgsVectorTileLayerProperties::optionsStackedWidget_CurrentChanged( int index )
{
QgsOptionsDialogBase::optionsStackedWidget_CurrentChanged( index );
Expand Down
8 changes: 5 additions & 3 deletions src/gui/vectortile/qgsvectortilelayerproperties.h
Expand Up @@ -17,10 +17,8 @@
#define QGSVECTORTILELAYERPROPERTIES_H

#include "qgsoptionsdialogbase.h"

#include "ui_qgsvectortilelayerpropertiesbase.h"

#include "qgsmaplayerstylemanager.h"
#include "qgsmaplayerstyle.h"

class QgsMapLayer;
class QgsMapCanvas;
Expand All @@ -29,6 +27,7 @@ class QgsVectorTileBasicLabelingWidget;
class QgsVectorTileBasicRendererWidget;
class QgsVectorTileLayer;
class QgsMetadataWidget;
class QgsProviderSourceWidget;


/**
Expand Down Expand Up @@ -57,6 +56,7 @@ class GUI_EXPORT QgsVectorTileLayerProperties : public QgsOptionsDialogBase, pri
void saveMetadataAs();
void showHelp();
void urlClicked( const QUrl &url );
void crsChanged( const QgsCoordinateReferenceSystem &crs );

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

QgsProviderSourceWidget *mSourceWidget = nullptr;

/**
* Previous layer style. Used to reset style to previous state if new style
* was loaded but dialog is canceled.
Expand Down
153 changes: 153 additions & 0 deletions src/ui/qgsvectortilelayerpropertiesbase.ui
Expand Up @@ -110,6 +110,18 @@
<normaloff>:/images/themes/default/propertyicons/metadata.svg</normaloff>:/images/themes/default/propertyicons/metadata.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Source</string>
</property>
<property name="toolTip">
<string>Source</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/system.svg</normaloff>:/images/themes/default/propertyicons/system.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Symbology</string>
Expand Down Expand Up @@ -209,6 +221,129 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="mOptsPage_Source">
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QgsScrollArea" name="scrollArea_3">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>661</width>
<height>507</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Layer name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mLayerOrigNameLineEd"/>
</item>
</layout>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mCrsGroupBox">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="title">
<string>Assigned Coordinate Reference System (CRS)</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="syncGroup" stdset="0">
<string notr="true">vectorgeneral</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
<property name="spacing">
<number>6</number>
</property>
<item>
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_17">
<property name="text">
<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>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mSourceGroupBox">
<property name="title">
<string>Layer Source</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>111</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mOptsPage_Style">
<layout class="QVBoxLayout" name="verticalLayout_14">
<property name="leftMargin">
Expand Down Expand Up @@ -303,11 +438,29 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsWebView</class>
<extends>QWidget</extends>
Expand Down

0 comments on commit d1c3e8d

Please sign in to comment.