35#include <QDesktopServices>
42#include "moc_qgsvectortilelayerproperties.cpp"
44using namespace Qt::StringLiterals;
52 mRendererWidget =
new QgsVectorTileBasicRendererWidget(
nullptr, canvas, messageBar,
this );
53 mOptsPage_Style->layout()->addWidget( mRendererWidget );
54 mOptsPage_Style->layout()->setContentsMargins( 0, 0, 0, 0 );
56 mLabelingWidget =
new QgsVectorTileBasicLabelingWidget(
nullptr, canvas, messageBar,
this );
57 mOptsPage_Labeling->layout()->addWidget( mLabelingWidget );
58 mOptsPage_Labeling->layout()->setContentsMargins( 0, 0, 0, 0 );
60 connect(
this, &QDialog::accepted,
this, &QgsVectorTileLayerProperties::apply );
62 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
this, &QgsVectorTileLayerProperties::apply );
63 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileLayerProperties::showHelp );
68 mScaleRangeWidget->setMapCanvas(
mCanvas );
75 mSourceGroupBox->hide();
77 mOptsPage_Information->setContentsMargins( 0, 0, 0, 0 );
79 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
80 layout->setContentsMargins( 0, 0, 0, 0 );
81 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
83 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
84 mMetadataWidget->setMapCanvas(
mCanvas );
85 layout->addWidget( mMetadataWidget );
86 metadataFrame->setLayout( layout );
87 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
91 mMapLayerServerPropertiesWidget->setHasWfsTitle(
false );
101 if ( !settings.
contains( u
"/Windows/VectorTileLayerProperties/tab"_s ) )
106 mBtnStyle =
new QPushButton( tr(
"Style" ) );
107 QMenu *menuStyle =
new QMenu(
this );
110 menuStyle->addSeparator();
113 mBtnStyle->setMenu( menuStyle );
114 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsVectorTileLayerProperties::aboutToShowStyleMenu );
116 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
118 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
119 QMenu *menuMetadata =
new QMenu(
this );
122 mBtnMetadata->setMenu( menuMetadata );
123 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
132 const QString newSource = mSourceWidget->
sourceUri();
133 if ( newSource != mLayer->
source() )
139 mLayer->setName( mLayerOrigNameLineEd->text() );
140 mLayer->setCrs( mCrsSelector->crs() );
142 mRendererWidget->apply();
143 mLabelingWidget->apply();
144 mMetadataWidget->acceptMetadata();
146 mLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
147 mLayer->setMinimumScale( mScaleRangeWidget->minimumScale() );
148 mLayer->setMaximumScale( mScaleRangeWidget->maximumScale() );
150 mMapLayerServerPropertiesWidget->save();
162 myStyle.append( u
"body { margin: 10px; }\n "_s );
163 mMetadataViewer->clear();
164 mMetadataViewer->document()->setDefaultStyleSheet( myStyle );
165 mMetadataViewer->setHtml( mLayer->htmlMetadata() );
171 mLayerOrigNameLineEd->setText( mLayer->name() );
172 mCrsSelector->setCrs( mLayer->crs() );
174 if ( !mSourceWidget )
179 QHBoxLayout *layout =
new QHBoxLayout();
180 layout->addWidget( mSourceWidget );
181 mSourceGroupBox->setLayout( layout );
182 if ( !mSourceWidget->groupTitle().isEmpty() )
183 mSourceGroupBox->setTitle( mSourceWidget->groupTitle() );
184 mSourceGroupBox->show();
187 buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
188 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
195 mSourceWidget->setMapCanvas(
mCanvas );
196 mSourceWidget->setSourceUri( mLayer->source() );
202 mRendererWidget->syncToLayer( mLayer );
207 mLabelingWidget->setLayer( mLayer );
212 chkUseScaleDependentRendering->setChecked( mLayer->hasScaleBasedVisibility() );
213 mScaleRangeWidget->setScaleRange( mLayer->minimumScale(), mLayer->maximumScale() );
215 mMapLayerServerPropertiesWidget->setServerProperties( mLayer->serverProperties() );
231 mOldStyle = mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() );
234 if ( type.compare(
"qml"_L1, Qt::CaseInsensitive ) == 0 )
237 bool defaultLoadedFlag =
false;
238 const QString filePath = dlg.
filePath();
239 message = mLayer->loadNamedStyle( filePath, defaultLoadedFlag, categories );
242 if ( defaultLoadedFlag )
249 QMessageBox::warning(
this, tr(
"Load Style" ), message );
252 else if ( type.compare(
"json"_L1, Qt::CaseInsensitive ) == 0 )
255 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
257 QMessageBox::warning(
this, tr(
"Load Style" ), tr(
"Could not read %1" ).arg( QDir::toNativeSeparators( dlg.
filePath() ) ) );
261 QTextStream in( &file );
262 const QString content = in.readAll();
281 QMessageBox::warning(
this, tr(
"Load Style" ), converter.
errorMessage() );
287 mLayer->setRenderer( converter.
renderer() );
291 mLayer->setLabeling( converter.
labeling() );
306void QgsVectorTileLayerProperties::aboutToShowStyleMenu()
308 QMenu *m = qobject_cast<QMenu *>( sender() );
316void QgsVectorTileLayerProperties::showHelp()
318 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
320 if ( helpPage.isValid() )
326 QgsHelp::openHelp( u
"working_with_vector_tiles/vector_tiles_properties.html"_s );
333 mLayer->setCrs( crs );
334 mMetadataWidget->crsChanged();
@ 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...
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 ...
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.
virtual void apply()=0
Applies the dialog settings to the layer.
virtual void syncToLayer()=0
Resets the dialog to the current layer state.
void saveStyleToFile()
Allows the user to save the layer's style to a file.
QgsMapCanvas * mCanvas
Associated map canvas.
QgsLayerPropertiesDialog(QgsMapLayer *layer, QgsMapCanvas *canvas, const QString &settingsKey, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags(), QgsSettings *settings=nullptr)
Constructor for QgsLayerPropertiesDialog.
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 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 source() const
Returns the source for the layer.
QString providerType() const
Returns the provider type (provider key) for this layer.
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QFlags< StyleCategory > StyleCategories
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.
Stores settings for use within QGIS.
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.
static void loadSprites(const QVariantMap &styleDefinition, QgsMapBoxGlStyleConversionContext &context, const QString &styleUrl=QString())
Downloads the sprite image and sets it to the conversion context.
Setting options for creating vector data providers.