37#include <QDesktopServices>
46 mRendererWidget =
new QgsVectorTileBasicRendererWidget(
nullptr, canvas, messageBar,
this );
47 mOptsPage_Style->layout()->addWidget( mRendererWidget );
48 mOptsPage_Style->layout()->setContentsMargins( 0, 0, 0, 0 );
50 mLabelingWidget =
new QgsVectorTileBasicLabelingWidget(
nullptr, canvas, messageBar,
this );
51 mOptsPage_Labeling->layout()->addWidget( mLabelingWidget );
52 mOptsPage_Labeling->layout()->setContentsMargins( 0, 0, 0, 0 );
54 connect(
this, &QDialog::accepted,
this, &QgsVectorTileLayerProperties::apply );
56 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
this, &QgsVectorTileLayerProperties::apply );
57 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileLayerProperties::showHelp );
62 mScaleRangeWidget->setMapCanvas(
mCanvas );
69 mSourceGroupBox->hide();
74 const int horizontalDpi = logicalDpiX();
77 if ( horizontalDpi > 96 )
79 mMetadataViewer->setZoomFactor( mMetadataViewer->zoomFactor() * 0.9 );
81 mMetadataViewer->page()->setLinkDelegationPolicy( QWebPage::LinkDelegationPolicy::DelegateAllLinks );
83 mMetadataViewer->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled,
true );
84 mMetadataViewer->page()->settings()->setAttribute( QWebSettings::JavascriptEnabled,
true );
87 mOptsPage_Information->setContentsMargins( 0, 0, 0, 0 );
89 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
90 layout->setContentsMargins( 0, 0, 0, 0 );
91 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
93 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
95 layout->addWidget( mMetadataWidget );
96 metadataFrame->setLayout( layout );
97 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
107 if ( !settings.
contains( QStringLiteral(
"/Windows/VectorTileLayerProperties/tab" ) ) )
109 settings.
setValue( QStringLiteral(
"Windows/VectorTileLayerProperties/tab" ),
113 mBtnStyle =
new QPushButton( tr(
"Style" ) );
114 QMenu *menuStyle =
new QMenu(
this );
117 menuStyle->addSeparator();
120 mBtnStyle->setMenu( menuStyle );
121 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsVectorTileLayerProperties::aboutToShowStyleMenu );
123 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
125 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
126 QMenu *menuMetadata =
new QMenu(
this );
129 mBtnMetadata->setMenu( menuMetadata );
130 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
135void QgsVectorTileLayerProperties::apply()
139 const QString newSource = mSourceWidget->
sourceUri();
140 if ( newSource != mLayer->
source() )
146 mLayer->
setName( mLayerOrigNameLineEd->text() );
147 mLayer->
setCrs( mCrsSelector->crs() );
149 mRendererWidget->apply();
150 mLabelingWidget->apply();
170 mLayer->
setLegendUrl( mLayerLegendUrlLineEdit->text() );
174void QgsVectorTileLayerProperties::syncToLayer()
181 const QString html { mLayer->
htmlMetadata().replace( QLatin1String(
"<head>" ), QStringLiteral( R
"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
182 mMetadataViewer->setHtml( html );
188 mLayerOrigNameLineEd->setText( mLayer->
name() );
189 mCrsSelector->setCrs( mLayer->
crs() );
191 if ( !mSourceWidget )
196 QHBoxLayout *layout =
new QHBoxLayout();
197 layout->addWidget( mSourceWidget );
198 mSourceGroupBox->setLayout( layout );
200 mSourceGroupBox->setTitle( mSourceWidget->
groupTitle() );
201 mSourceGroupBox->show();
205 buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
206 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
220 mRendererWidget->syncToLayer( mLayer );
225 mLabelingWidget->setLayer( mLayer );
242 mLayerDataUrlFormatComboBox->setCurrentIndex(
243 mLayerDataUrlFormatComboBox->findText(
252 mLayerLegendUrlLineEdit->setText( mLayer->
legendUrl() );
253 mLayerLegendUrlFormatComboBox->setCurrentIndex(
254 mLayerLegendUrlFormatComboBox->findText(
276 if ( type.compare( QLatin1String(
"qml" ), Qt::CaseInsensitive ) == 0 )
279 bool defaultLoadedFlag =
false;
280 const QString filePath = dlg.
filePath();
281 message = mLayer->
loadNamedStyle( filePath, defaultLoadedFlag, categories );
284 if ( defaultLoadedFlag )
291 QMessageBox::warning(
this, tr(
"Load Style" ), message );
294 else if ( type.compare( QLatin1String(
"json" ), Qt::CaseInsensitive ) == 0 )
297 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
299 QMessageBox::warning(
this, tr(
"Load Style" ), tr(
"Could not read %1" ).arg( QDir::toNativeSeparators( dlg.
filePath() ) ) );
303 QTextStream in( &file );
304#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
305 in.setCodec(
"UTF-8" );
307 const QString content = in.readAll();
326 QMessageBox::warning(
this, tr(
"Load Style" ), converter.
errorMessage() );
351void QgsVectorTileLayerProperties::aboutToShowStyleMenu()
353 QMenu *m = qobject_cast<QMenu *>( sender() );
361void QgsVectorTileLayerProperties::showHelp()
363 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
365 if ( helpPage.isValid() )
371 QgsHelp::openHelp( QStringLiteral(
"working_with_vector_tiles/vector_tiles_properties.html" ) );
@ Millimeters
Millimeters.
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
@ WebBrowser
StyleSheet for embedded browsers (QtWebKit), supports full standard CSS.
This class represents a coordinate reference system (CRS).
static QgsProviderSourceWidgetProviderRegistry * sourceWidgetProviderRegistry()
Returns the registry of provider source widget providers.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
static QVariant parseJson(const std::string &jsonString)
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and ...
Base class for "layer properties" dialogs, containing common utilities for handling functionality in ...
void saveMetadataToFile()
Allows the user to save the layer's metadata as a file.
virtual void rollback()
Rolls back changes made to the layer.
void saveStyleAsDefault()
Saves the current layer style as the default for the layer.
void setMetadataWidget(QgsMetadataWidget *widget, QWidget *page)
Sets the metadata widget and page associated with the dialog.
void loadDefaultStyle()
Reloads the default style for the layer.
void saveStyleToFile()
Allows the user to save the layer's style to a file.
QgsMapCanvas * mCanvas
Associated map canvas.
QgsMapLayerStyle mOldStyle
Previous layer style.
void loadMetadataFromFile()
Allows the user to load layer metadata from a file.
void initialize()
Initialize the dialog.
void openUrl(const QUrl &url)
Handles opening a url from the dialog.
Context for a MapBox GL style conversion operation.
void setTargetUnit(Qgis::RenderUnit targetUnit)
Sets the target unit type.
void setPixelSizeConversionFactor(double sizeConversionFactor)
Sets the pixel size conversion factor, used to scale the original pixel sizes when converting styles.
Handles conversion of MapBox GL styles to QGIS vector tile renderers and labeling settings.
QgsVectorTileRenderer * renderer() const
Returns a new instance of a vector tile renderer representing the converted style,...
QgsVectorTileLabeling * labeling() const
Returns a new instance of a vector tile labeling representing the converted style,...
Result convert(const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context=nullptr)
Converts a JSON style map, and returns the resultant status of the conversion.
@ Success
Conversion was successful.
QString errorMessage() const
Returns a descriptive error message if an error was encountered during the style conversion,...
Map canvas is a class for displaying all GIS data types on a canvas.
A reusable dialog which allows users to select stored layer styles and categories to load for a map l...
QgsMapLayer::StyleCategories styleCategories() const
Returns the list of selected style categories the user has opted to load.
QString filePath() const
Returns the full path to the selected layer style source file.
QString fileExtension() const
Returns the file extension for the selected layer style source file.
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layerused by QGIS Server in GetCapabilities request.
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
void setAttributionUrl(const QString &url)
Sets the attribution url of the layer used by QGIS Server in GetCapabilities request.
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
void setShortName(const QString &name)
Sets the short name of the layer used by QGIS Server to identify the layer.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QString keywordList() const
Returns the keyword list of the layerused by QGIS Server in GetCapabilities request.
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
void setKeywordList(const QString &keywords)
Sets the keywords list of the layerused by QGIS Server in GetCapabilities request.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
QString abstract() const
Returns the abstract of the layerused by QGIS Server in GetCapabilities request.
void removesExtraMenuSeparators(QMenu *m)
removes extra separators from the menu
void addStyleManagerActions(QMenu *m, QgsMapLayer *layer)
adds actions to the menu in accordance to the layer
static QgsMapLayerStyleGuiUtils * instance()
returns a singleton instance of this class
QString currentStyle() const
Returns name of the current style.
QgsMapLayerStyle style(const QString &name) const
Returns data of a stored style - accessed by its unique name.
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
QString source() const
Returns the source for the layer.
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags=Qgis::LoadStyleFlags())
Loads a named style from file/local db/datasource db.
QgsCoordinateReferenceSystem crs
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QFlags< StyleCategory > StyleCategories
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
void setName(const QString &name)
Set the display name of the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
QString legendUrl() const
Returns the URL for the layer's legend.
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
double maximumScale() const
Returns the maximum map scale (i.e.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
A bar for displaying non-blocking messages to the user.
QStackedWidget * mOptStackedWidget
void initOptionsBase(bool restoreUi=true, const QString &title=QString())
Set up the base ui connections for vertical tabs.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class is a composition of two QSettings instances:
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Q_DECL_DEPRECATED void saveDefaultStyle() SIP_DEPRECATED
Saves the default style when appropriate button is pressed.
Q_DECL_DEPRECATED void saveStyleAs() SIP_DEPRECATED
Saves a style when appriate button is pressed.
void loadStyle()
Loads a saved style when appropriate button is pressed.
QgsVectorTileLayerProperties(QgsVectorTileLayer *lyr, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent=nullptr, Qt::WindowFlags=QgsGuiUtils::ModalDialogFlags)
Constructor.
Implements a map layer that is dedicated to rendering of vector tiles.
void setRenderer(QgsVectorTileRenderer *r)
Sets renderer for the map layer.
void setLabeling(QgsVectorTileLabeling *labeling)
Sets labeling for the map layer.
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
static void loadSprites(const QVariantMap &styleDefinition, QgsMapBoxGlStyleConversionContext &context, const QString &styleUrl=QString())
Downloads the sprite image and sets it to the conversion context.
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.