37#include <QDesktopServices>
44#include "moc_qgsvectortilelayerproperties.cpp"
46using namespace Qt::StringLiterals;
54 mRendererWidget =
new QgsVectorTileBasicRendererWidget(
nullptr, canvas, messageBar,
this );
55 mOptsPage_Style->layout()->addWidget( mRendererWidget );
56 mOptsPage_Style->layout()->setContentsMargins( 0, 0, 0, 0 );
58 mLabelingWidget =
new QgsVectorTileBasicLabelingWidget(
nullptr, canvas, messageBar,
this );
59 mOptsPage_Labeling->layout()->addWidget( mLabelingWidget );
60 mOptsPage_Labeling->layout()->setContentsMargins( 0, 0, 0, 0 );
62 connect(
this, &QDialog::accepted,
this, &QgsVectorTileLayerProperties::apply );
64 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
this, &QgsVectorTileLayerProperties::apply );
65 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsVectorTileLayerProperties::showHelp );
70 mScaleRangeWidget->setMapCanvas(
mCanvas );
77 mSourceGroupBox->hide();
79 mOptsPage_Information->setContentsMargins( 0, 0, 0, 0 );
81 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
82 layout->setContentsMargins( 0, 0, 0, 0 );
83 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
85 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
86 mMetadataWidget->setMapCanvas(
mCanvas );
87 layout->addWidget( mMetadataWidget );
88 metadataFrame->setLayout( layout );
89 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
93 mMapLayerServerPropertiesWidget->setHasWfsTitle(
false );
103 if ( !settings.
contains( u
"/Windows/VectorTileLayerProperties/tab"_s ) )
108 mBtnStyle =
new QPushButton( tr(
"Style" ) );
109 QMenu *menuStyle =
new QMenu(
this );
112 menuStyle->addSeparator();
115 mBtnStyle->setMenu( menuStyle );
116 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsVectorTileLayerProperties::aboutToShowStyleMenu );
118 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
120 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
121 QMenu *menuMetadata =
new QMenu(
this );
124 mBtnMetadata->setMenu( menuMetadata );
125 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
134 const QString newSource = mSourceWidget->
sourceUri();
135 if ( newSource != mLayer->
source() )
141 mLayer->setName( mLayerOrigNameLineEd->text() );
142 mLayer->setCrs( mCrsSelector->crs() );
144 mRendererWidget->apply();
145 mLabelingWidget->apply();
146 mMetadataWidget->acceptMetadata();
148 mLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
149 mLayer->setMinimumScale( mScaleRangeWidget->minimumScale() );
150 mLayer->setMaximumScale( mScaleRangeWidget->maximumScale() );
152 mMapLayerServerPropertiesWidget->save();
164 myStyle.append( u
"body { margin: 10px; }\n "_s );
165 mMetadataViewer->clear();
166 mMetadataViewer->document()->setDefaultStyleSheet( myStyle );
167 mMetadataViewer->setHtml( mLayer->htmlMetadata() );
173 mLayerOrigNameLineEd->setText( mLayer->name() );
174 mCrsSelector->setCrs( mLayer->crs() );
176 if ( !mSourceWidget )
181 QHBoxLayout *layout =
new QHBoxLayout();
182 layout->addWidget( mSourceWidget );
183 mSourceGroupBox->setLayout( layout );
184 if ( !mSourceWidget->groupTitle().isEmpty() )
185 mSourceGroupBox->setTitle( mSourceWidget->groupTitle() );
186 mSourceGroupBox->show();
189 buttonBox->button( QDialogButtonBox::Apply )->setEnabled( isValid );
190 buttonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
197 mSourceWidget->setMapCanvas(
mCanvas );
198 mSourceWidget->setSourceUri( mLayer->source() );
204 mRendererWidget->syncToLayer( mLayer );
209 mLabelingWidget->setLayer( mLayer );
214 chkUseScaleDependentRendering->setChecked( mLayer->hasScaleBasedVisibility() );
215 mScaleRangeWidget->setScaleRange( mLayer->minimumScale(), mLayer->maximumScale() );
217 mMapLayerServerPropertiesWidget->setServerProperties( mLayer->serverProperties() );
233 mOldStyle = mLayer->styleManager()->style( mLayer->styleManager()->currentStyle() );
236 if ( type.compare(
"qml"_L1, Qt::CaseInsensitive ) == 0 )
239 bool defaultLoadedFlag =
false;
240 const QString filePath = dlg.
filePath();
241 message = mLayer->loadNamedStyle( filePath, defaultLoadedFlag, categories );
244 if ( defaultLoadedFlag )
251 QMessageBox::warning(
this, tr(
"Load Style" ), message );
254 else if ( type.compare(
"json"_L1, Qt::CaseInsensitive ) == 0 )
257 if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
259 QMessageBox::warning(
this, tr(
"Load Style" ), tr(
"Could not read %1" ).arg( QDir::toNativeSeparators( dlg.
filePath() ) ) );
263 QTextStream in( &file );
264 const QString content = in.readAll();
283 QMessageBox::warning(
this, tr(
"Load Style" ), converter.
errorMessage() );
289 mLayer->setRenderer( converter.
renderer().release() );
293 mLayer->setLabeling( converter.
labeling().release() );
308void QgsVectorTileLayerProperties::aboutToShowStyleMenu()
310 QMenu *m = qobject_cast<QMenu *>( sender() );
318void QgsVectorTileLayerProperties::showHelp()
320 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
322 if ( helpPage.isValid() )
328 QgsHelp::openHelp( u
"working_with_vector_tiles/vector_tiles_properties.html"_s );
335 mLayer->setCrs( crs );
336 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.
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.
std::unique_ptr< QgsVectorTileLabeling > labeling() const
Returns a new instance of a vector tile labeling representing the converted style,...
QString errorMessage() const
Returns a descriptive error message if an error was encountered during the style conversion,...
std::unique_ptr< QgsVectorTileRenderer > renderer() const
Returns a new instance of a vector tile renderer representing the converted style,...
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.