39#include <QDesktopServices>
45 , mMapCanvas( canvas )
49 mRendererWidget =
new QgsVectorTileBasicRendererWidget(
nullptr, canvas, messageBar,
this );
50 mOptsPage_Style->layout()->addWidget( mRendererWidget );
51 mOptsPage_Style->layout()->setContentsMargins( 0, 0, 0, 0 );
53 mLabelingWidget =
new QgsVectorTileBasicLabelingWidget(
nullptr, canvas, messageBar,
this );
54 mOptsPage_Labeling->layout()->addWidget( mLabelingWidget );
55 mOptsPage_Labeling->layout()->setContentsMargins( 0, 0, 0, 0 );
57 connect(
this, &QDialog::accepted,
this, &QgsVectorTileLayerProperties::apply );
58 connect(
this, &QDialog::rejected,
this, &QgsVectorTileLayerProperties::onCancel );
59 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
this, &QgsVectorTileLayerProperties::apply );
60 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileLayerProperties::showHelp );
65 mScaleRangeWidget->setMapCanvas( mMapCanvas );
72 mSourceGroupBox->hide();
77 const int horizontalDpi = logicalDpiX();
80 if ( horizontalDpi > 96 )
82 mMetadataViewer->setZoomFactor( mMetadataViewer->zoomFactor() * 0.9 );
84 mMetadataViewer->page()->setLinkDelegationPolicy( QWebPage::LinkDelegationPolicy::DelegateAllLinks );
85 connect( mMetadataViewer->page(), &QWebPage::linkClicked,
this, &QgsVectorTileLayerProperties::urlClicked );
86 mMetadataViewer->page()->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled,
true );
87 mMetadataViewer->page()->settings()->setAttribute( QWebSettings::JavascriptEnabled,
true );
90 mOptsPage_Information->setContentsMargins( 0, 0, 0, 0 );
92 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
93 layout->setContentsMargins( 0, 0, 0, 0 );
94 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
96 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
98 layout->addWidget( mMetadataWidget );
99 metadataFrame->setLayout( layout );
100 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
108 if ( !settings.
contains( QStringLiteral(
"/Windows/VectorTileLayerProperties/tab" ) ) )
110 settings.
setValue( QStringLiteral(
"Windows/VectorTileLayerProperties/tab" ),
114 QString title = tr(
"Layer Properties - %1" ).arg( mLayer->
name() );
116 mBtnStyle =
new QPushButton( tr(
"Style" ) );
117 QMenu *menuStyle =
new QMenu(
this );
120 menuStyle->addSeparator();
123 mBtnStyle->setMenu( menuStyle );
124 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsVectorTileLayerProperties::aboutToShowStyleMenu );
126 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
128 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
129 QMenu *menuMetadata =
new QMenu(
this );
130 mActionLoadMetadata = menuMetadata->addAction( tr(
"Load Metadata…" ),
this, &QgsVectorTileLayerProperties::loadMetadata );
131 mActionSaveMetadataAs = menuMetadata->addAction( tr(
"Save Metadata…" ),
this, &QgsVectorTileLayerProperties::saveMetadataAs );
132 mBtnMetadata->setMenu( menuMetadata );
133 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
140void QgsVectorTileLayerProperties::apply()
144 const QString newSource = mSourceWidget->
sourceUri();
145 if ( newSource != mLayer->
source() )
151 mLayer->
setName( mLayerOrigNameLineEd->text() );
152 mLayer->
setCrs( mCrsSelector->crs() );
154 mRendererWidget->apply();
155 mLabelingWidget->apply();
163void QgsVectorTileLayerProperties::onCancel()
169 QDomDocument doc( QStringLiteral(
"qgis" ) );
170 int errorLine, errorColumn;
171 doc.setContent( mOldStyle.
xmlData(),
false, &myMessage, &errorLine, &errorColumn );
177void QgsVectorTileLayerProperties::syncToLayer()
184 const QString html { mLayer->
htmlMetadata().replace( QLatin1String(
"<head>" ), QStringLiteral( R
"raw(<head><style type="text/css">%1</style>)raw" ) ).arg( myStyle ) };
185 mMetadataViewer->setHtml( html );
191 mLayerOrigNameLineEd->setText( mLayer->
name() );
192 mCrsSelector->setCrs( mLayer->
crs() );
194 if ( !mSourceWidget )
199 QHBoxLayout *layout =
new QHBoxLayout();
200 layout->addWidget( mSourceWidget );
201 mSourceGroupBox->setLayout( layout );
202 mSourceGroupBox->show();
206 buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
207 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
221 mRendererWidget->syncToLayer( mLayer );
226 mLabelingWidget->setLayer( mLayer );
238 bool defaultLoadedFlag =
false;
241 if ( defaultLoadedFlag )
248 QMessageBox::information(
this,
249 tr(
"Default Style" ),
260 bool defaultSavedFlag =
false;
268 if ( !defaultSavedFlag )
271 QMessageBox::information(
this,
272 tr(
"Default Style" ),
289 if ( type.compare( QLatin1String(
"qml" ), Qt::CaseInsensitive ) == 0 )
292 bool defaultLoadedFlag =
false;
293 const QString filePath = dlg.
filePath();
294 message = mLayer->
loadNamedStyle( filePath, defaultLoadedFlag, categories );
297 if ( defaultLoadedFlag )
304 QMessageBox::warning(
this, tr(
"Load Style" ), message );
307 else if ( type.compare( QLatin1String(
"json" ), Qt::CaseInsensitive ) == 0 )
310 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
312 QMessageBox::warning(
this, tr(
"Load Style" ), tr(
"Could not read %1" ).arg( QDir::toNativeSeparators( dlg.
filePath() ) ) );
316 QTextStream in( &file );
317#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
318 in.setCodec(
"UTF-8" );
320 const QString content = in.readAll();
339 QMessageBox::warning(
this, tr(
"Load Style" ), converter.
errorMessage() );
343 if ( dlg.
styleCategories().testFlag( QgsMapLayer::StyleCategory::Symbology ) )
347 if ( dlg.
styleCategories().testFlag( QgsMapLayer::StyleCategory::Labeling ) )
362 const QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
364 QString outputFileName = QFileDialog::getSaveFileName(
366 tr(
"Save layer properties as style file" ),
368 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
369 if ( outputFileName.isEmpty() )
378 bool defaultLoadedFlag =
false;
380 message = mLayer->
saveNamedStyle( outputFileName, defaultLoadedFlag );
382 if ( defaultLoadedFlag )
384 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( outputFileName ).absolutePath() );
387 QMessageBox::information(
this, tr(
"Save Style" ), message );
390void QgsVectorTileLayerProperties::aboutToShowStyleMenu()
392 QMenu *m = qobject_cast<QMenu *>( sender() );
400void QgsVectorTileLayerProperties::loadMetadata()
403 const QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
405 const QString myFileName = QFileDialog::getOpenFileName(
this, tr(
"Load layer metadata from metadata file" ), myLastUsedDir,
406 tr(
"QGIS Layer Metadata File" ) +
" (*.qmd)" );
407 if ( myFileName.isNull() )
413 bool defaultLoadedFlag =
false;
417 if ( defaultLoadedFlag )
424 QMessageBox::warning(
this, tr(
"Load Metadata" ), myMessage );
427 const QFileInfo myFI( myFileName );
428 const QString myPath = myFI.path();
429 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
434void QgsVectorTileLayerProperties::saveMetadataAs()
437 const QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
439 QString myOutputFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Layer Metadata as QMD" ),
440 myLastUsedDir, tr(
"QMD File" ) +
" (*.qmd)" );
441 if ( myOutputFileName.isNull() )
454 bool defaultLoadedFlag =
false;
455 const QString message = mLayer->
saveNamedMetadata( myOutputFileName, defaultLoadedFlag );
456 if ( defaultLoadedFlag )
457 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( myOutputFileName ).absolutePath() );
459 QMessageBox::information(
this, tr(
"Save Metadata" ), message );
462void QgsVectorTileLayerProperties::showHelp()
464 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
466 if ( helpPage.isValid() )
472 QgsHelp::openHelp( QStringLiteral(
"working_with_vector_tiles/vector_tiles_properties.html" ) );
476void QgsVectorTileLayerProperties::urlClicked(
const QUrl &url )
478 const QFileInfo file( url.toLocalFile() );
479 if ( file.exists() && !file.isDir() )
482 QDesktopServices::openUrl( url );
496 const bool isMetadataPanel = ( index ==
mOptStackedWidget->indexOf( mOptsPage_Metadata ) );
497 mBtnStyle->setVisible( ! isMetadataPanel );
498 mBtnMetadata->setVisible( isMetadataPanel );
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
This class represents a coordinate reference system (CRS).
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
static QgsProviderSourceWidgetProviderRegistry * sourceWidgetProviderRegistry()
Returns the registry of provider source widget providers.
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
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 ...
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 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.
static bool isDefault(const QString &styleName)
Returns true if this is the default style.
QgsMapLayerStyle style(const QString &name) const
Returns data of a stored style - accessed by its unique name.
QString xmlData() const
Returns XML content of the style.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
QString source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
QgsCoordinateReferenceSystem crs
virtual QString loadNamedMetadata(const QString &uri, bool &resultFlag)
Retrieve a named metadata for this layer if one exists (either as a .qmd file on disk or as a record ...
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QgsLayerMetadata metadata
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.
virtual QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
void setName(const QString &name)
Set the display name of the layer.
QString saveNamedMetadata(const QString &uri, bool &resultFlag)
Save the current metadata of this layer as a named metadata (either as a .qmd file on disk or as a re...
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
virtual QString saveNamedStyle(const QString &uri, bool &resultFlag, StyleCategories categories=AllStyleCategories)
Save the properties of this layer as a named style (either as a .qml file on disk or as a record in t...
virtual QString saveDefaultStyle(bool &resultFlag, StyleCategories categories)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
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.
A base dialog for options and properties dialogs that offers vertical tabs.
virtual void optionsStackedWidget_CurrentChanged(int index)
Select relevant tab on current page change.
void restoreOptionsBaseUi(const QString &title=QString())
Restore the base ui.
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:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.
void saveDefaultStyle()
Saves the default style when appropriate button is pressed.
void optionsStackedWidget_CurrentChanged(int index) override
void saveStyleAs()
Saves a style when appriate button is pressed.
void loadDefaultStyle()
Loads the default style when appropriate 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 loadDefaultStyle(bool &resultFlag) override
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
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.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.