41#include <QDesktopServices>
50 Q_ASSERT( mMeshLayer );
54 mConfigWidgets << mRendererMeshPropertiesWidget;
55 mOptsPage_StyleContent->layout()->addWidget( mRendererMeshPropertiesWidget );
57 mSimplifyReductionFactorSpinBox->setClearValue( 10.0 );
58 mSimplifyMeshResolutionSpinBox->setClearValue( 5 );
60 mStaticDatasetWidget->setLayer( mMeshLayer );
63 mTemporalProviderTimeUnitComboBox->addItem( tr(
"Seconds" ),
static_cast< int >( Qgis::TemporalUnit::Seconds ) );
64 mTemporalProviderTimeUnitComboBox->addItem( tr(
"Minutes" ),
static_cast< int >( Qgis::TemporalUnit::Minutes ) );
65 mTemporalProviderTimeUnitComboBox->addItem( tr(
"Hours" ),
static_cast< int >( Qgis::TemporalUnit::Hours ) );
66 mTemporalProviderTimeUnitComboBox->addItem( tr(
"Days" ),
static_cast< int >( Qgis::TemporalUnit::Days ) );
78 connect(
this, &QDialog::accepted,
this, &QgsMeshLayerProperties::apply );
79 connect(
this, &QDialog::rejected,
this, &QgsMeshLayerProperties::onCancel );
80 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
this, &QgsMeshLayerProperties::apply );
83 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsMeshLayerProperties::showHelp );
85 connect( mTemporalReloadButton, &QPushButton::clicked,
this, &QgsMeshLayerProperties::reloadTemporalProperties );
86 connect( mTemporalDateTimeReference, &QDateTimeEdit::dateTimeChanged,
this, &QgsMeshLayerProperties::onTimeReferenceChange );
90 mScaleRangeWidget->setMapCanvas( mCanvas );
94 connect( mAlwaysTimeFromSourceCheckBox, &QCheckBox::stateChanged,
this, [
this]
96 mTemporalDateTimeReference->setEnabled( !mAlwaysTimeFromSourceCheckBox->isChecked() );
97 if ( mAlwaysTimeFromSourceCheckBox->isChecked() )
98 reloadTemporalProperties();
101 mComboBoxTemporalDatasetMatchingMethod->addItem( tr(
"Find Closest Dataset Before Requested Time" ),
103 mComboBoxTemporalDatasetMatchingMethod->addItem( tr(
"Find Closest Dataset From Requested Time (After or Before)" ),
106 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
107 layout->setContentsMargins( 0, 0, 0, 0 );
108 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
110 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
112 layout->addWidget( mMetadataWidget );
113 metadataFrame->setLayout( layout );
114 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
115 mBackupCrs = mMeshLayer->
crs();
117 mTemporalDateTimeStart->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
118 mTemporalDateTimeEnd->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
119 mTemporalDateTimeReference->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
127 if ( !settings.
contains( QStringLiteral(
"/Windows/MeshLayerProperties/tab" ) ) )
129 settings.
setValue( QStringLiteral(
"Windows/MeshLayerProperties/tab" ),
134 mOptsPage_Information->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#information-properties" ) );
135 mOptsPage_Source->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#source-properties" ) );
136 mOptsPage_Style->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#symbology-properties" ) );
137 mOptsPage_Rendering->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#rendering-properties" ) );
138 mOptsPage_Temporal->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#temporal-properties" ) );
139 mOptsPage_Metadata->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#metadata-properties" ) );
141 mBtnStyle =
new QPushButton( tr(
"Style" ) );
142 QMenu *menuStyle =
new QMenu(
this );
143 menuStyle->addAction( tr(
"Load Style…" ),
this, &QgsMeshLayerProperties::loadStyle );
144 menuStyle->addAction( tr(
"Save Style…" ),
this, &QgsMeshLayerProperties::saveStyleAs );
145 menuStyle->addSeparator();
146 menuStyle->addAction( tr(
"Save as Default" ),
this, &QgsMeshLayerProperties::saveDefaultStyle );
147 menuStyle->addAction( tr(
"Restore Default" ),
this, &QgsMeshLayerProperties::loadDefaultStyle );
148 mBtnStyle->setMenu( menuStyle );
149 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsMeshLayerProperties::aboutToShowStyleMenu );
151 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
153 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
154 QMenu *menuMetadata =
new QMenu(
this );
155 mActionLoadMetadata = menuMetadata->addAction( tr(
"Load Metadata…" ),
this, &QgsMeshLayerProperties::loadMetadata );
156 mActionSaveMetadataAs = menuMetadata->addAction( tr(
"Save Metadata…" ),
this, &QgsMeshLayerProperties::saveMetadataAs );
157 mBtnMetadata->setMenu( menuMetadata );
158 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
160 QString title = tr(
"Layer Properties — %1" ).arg( lyr->
name() );
175 mConfigWidgets << page;
178 if ( beforePage.isEmpty() )
191 bool isMetadataPanel = ( index ==
mOptStackedWidget->indexOf( mOptsPage_Metadata ) );
192 mBtnStyle->setVisible( ! isMetadataPanel );
193 mBtnMetadata->setVisible( isMetadataPanel );
196void QgsMeshLayerProperties::syncToLayer()
198 Q_ASSERT( mRendererMeshPropertiesWidget );
200 QgsDebugMsgLevel( QStringLiteral(
"populate general information tab" ), 4 );
205 myStyle.append( QStringLiteral(
"body { margin: 10px; }\n " ) );
206 mInformationTextBrowser->clear();
207 mInformationTextBrowser->document()->setDefaultStyleSheet( myStyle );
208 mInformationTextBrowser->setHtml( mMeshLayer->
htmlMetadata() );
209 mInformationTextBrowser->setOpenLinks(
false );
210 connect( mInformationTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsMeshLayerProperties::urlClicked );
216 mLayerOrigNameLineEd->setText( mMeshLayer->
name() );
220 mDatasetGroupTreeWidget->syncToLayer( mMeshLayer );
224 w->syncToLayer( mMeshLayer );
228 mSimplifyMeshGroupBox->setEnabled(
false );
231 mSimplifyMeshGroupBox->setChecked( simplifySettings.
isEnabled() );
232 mSimplifyReductionFactorSpinBox->setValue( simplifySettings.
reductionFactor() );
233 mSimplifyMeshResolutionSpinBox->setValue( simplifySettings.
meshResolution() );
238 const QgsDateTimeRange timeRange = temporalProperties->
timeExtent();
239 mTemporalDateTimeStart->setDateTime( timeRange.begin() );
240 mTemporalDateTimeEnd->setDateTime( timeRange.end() );
243 mTemporalProviderTimeUnitComboBox->setCurrentIndex(
247 mComboBoxTemporalDatasetMatchingMethod->setCurrentIndex(
248 mComboBoxTemporalDatasetMatchingMethod->findData( temporalProperties->
matchingMethod() ) );
250 mStaticDatasetWidget->syncToLayer();
254void QgsMeshLayerProperties::loadDefaultStyle()
256 bool defaultLoadedFlag =
false;
259 if ( defaultLoadedFlag )
266 QMessageBox::information(
this,
267 tr(
"Default Style" ),
273void QgsMeshLayerProperties::saveDefaultStyle()
278 bool defaultSavedFlag =
false;
286 if ( !defaultSavedFlag )
289 QMessageBox::information(
this,
290 tr(
"Default Style" ),
296void QgsMeshLayerProperties::loadStyle()
299 QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
301 QString fileName = QFileDialog::getOpenFileName(
303 tr(
"Load rendering setting from style file" ),
305 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
306 if ( fileName.isEmpty() )
310 if ( !fileName.endsWith( QLatin1String(
".qml" ), Qt::CaseInsensitive ) )
311 fileName += QLatin1String(
".qml" );
315 bool defaultLoadedFlag =
false;
316 QString message = mMeshLayer->
loadNamedStyle( fileName, defaultLoadedFlag );
317 if ( defaultLoadedFlag )
319 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( fileName ).absolutePath() );
324 QMessageBox::information(
this, tr(
"Load Style" ), message );
328void QgsMeshLayerProperties::saveStyleAs()
331 QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
333 QString outputFileName = QFileDialog::getSaveFileName(
335 tr(
"Save layer properties as style file" ),
337 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
338 if ( outputFileName.isEmpty() )
347 bool defaultLoadedFlag =
false;
349 message = mMeshLayer->
saveNamedStyle( outputFileName, defaultLoadedFlag );
351 if ( defaultLoadedFlag )
353 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( outputFileName ).absolutePath() );
356 QMessageBox::information(
this, tr(
"Save Style" ), message );
359void QgsMeshLayerProperties::apply()
361 Q_ASSERT( mRendererMeshPropertiesWidget );
367 mMeshLayer->
setName( mLayerOrigNameLineEd->text() );
373 mDatasetGroupTreeWidget->apply();
385 simplifySettings.
setEnabled( mSimplifyMeshGroupBox->isChecked() );
405 static_cast<Qgis::TemporalUnit>( mTemporalProviderTimeUnitComboBox->currentData().toInt() ) );
407 mStaticDatasetWidget->apply();
411 mComboBoxTemporalDatasetMatchingMethod->currentData().toInt() ) );
413 mMeshLayer->
temporalProperties() )->setAlwaysLoadReferenceTimeFromSource( mAlwaysTimeFromSourceCheckBox->isChecked() );
417 mBackupCrs = mMeshLayer->
crs();
419 if ( needMeshUpdating )
422 if ( needEmitRendererChanged )
432 mStaticDatasetWidget->syncToLayer();
434 w->syncToLayer( mMeshLayer );
443void QgsMeshLayerProperties::syncAndRepaint()
449void QgsMeshLayerProperties::showHelp()
451 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
453 if ( helpPage.isValid() )
463void QgsMeshLayerProperties::aboutToShowStyleMenu()
465 QMenu *m = qobject_cast<QMenu *>( sender() );
473void QgsMeshLayerProperties::reloadTemporalProperties()
478 QgsDateTimeRange timeExtent;
479 QDateTime referenceTime = temporalCapabalities->
referenceTime();
480 if ( referenceTime.isValid() )
482 timeExtent = temporalCapabalities->
timeExtent();
483 whileBlocking( mTemporalDateTimeReference )->setDateTime( referenceTime );
487 timeExtent = temporalCapabalities->
timeExtent( mTemporalDateTimeReference->dateTime() );
489 mTemporalDateTimeStart->setDateTime( timeExtent.begin() );
490 mTemporalDateTimeEnd->setDateTime( timeExtent.end() );
493void QgsMeshLayerProperties::onTimeReferenceChange()
498 mTemporalDateTimeStart->setDateTime( timeExtent.begin() );
499 mTemporalDateTimeEnd->setDateTime( timeExtent.end() );
502void QgsMeshLayerProperties::urlClicked(
const QUrl &url )
504 QFileInfo file( url.toLocalFile() );
505 if ( file.exists() && !file.isDir() )
508 QDesktopServices::openUrl( url );
511void QgsMeshLayerProperties::loadMetadata()
514 QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
516 QString myFileName = QFileDialog::getOpenFileName(
this, tr(
"Load layer metadata from metadata file" ), myLastUsedDir,
517 tr(
"QGIS Layer Metadata File" ) +
" (*.qmd)" );
518 if ( myFileName.isNull() )
524 bool defaultLoadedFlag =
false;
528 if ( defaultLoadedFlag )
535 QMessageBox::warning(
this, tr(
"Load Metadata" ), myMessage );
538 QFileInfo myFI( myFileName );
539 QString myPath = myFI.path();
540 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
545void QgsMeshLayerProperties::saveMetadataAs()
548 QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
550 QString myOutputFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Layer Metadata as QMD" ),
551 myLastUsedDir, tr(
"QMD File" ) +
" (*.qmd)" );
552 if ( myOutputFileName.isNull() )
565 bool defaultLoadedFlag =
false;
566 QString message = mMeshLayer->
saveNamedMetadata( myOutputFileName, defaultLoadedFlag );
567 if ( defaultLoadedFlag )
568 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( myOutputFileName ).absolutePath() );
570 QMessageBox::information(
this, tr(
"Save Metadata" ), message );
573void QgsMeshLayerProperties::onCancel()
575 if ( mBackupCrs != mMeshLayer->
crs() )
576 mMeshLayer->
setCrs( mBackupCrs );
TemporalUnit
Temporal units.
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 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.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
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.
void currentStyleChanged(const QString ¤tName)
Emitted when the current style has been changed.
Base class for all map layer types.
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 triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QgsLayerMetadata metadata
void rendererChanged()
Signal emitted when renderer is changed.
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 ...
void dataChanged()
Data of layer changed.
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...
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.
Class for handling properties relating to a mesh data provider's temporal capabilities.
QDateTime referenceTime() const
Returns the reference time.
QgsDateTimeRange timeExtent() const
Returns the time extent using the internal reference time and the first and last times available from...
Qgis::TemporalUnit temporalUnit() const
Returns the temporal unit used to read data by the data provider.
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
@ FindClosestDatasetBeforeStartRangeTime
@ FindClosestDatasetFromStartRangeTime
Finds the closest dataset which have its time before the requested start range time.
void setTemporalUnit(Qgis::TemporalUnit unit)
Sets the temporal unit of the provider and reload data if it changes.
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
void optionsStackedWidget_CurrentChanged(int index) override
QgsMeshLayerProperties(QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent=nullptr, Qt::WindowFlags=QgsGuiUtils::ModalDialogFlags)
Constructor.
void addPropertiesPageFactory(const QgsMapLayerConfigWidgetFactory *factory)
Adds properties page from a factory.
Implementation of map layer temporal properties for mesh layers.
QDateTime referenceTime() const
Returns the reference time.
QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod matchingMethod() const
Returns the method used to match dataset from temporal capabilities.
bool alwaysLoadReferenceTimeFromSource() const
Returns whether the time proporties are automatically reloaded from provider when project is opened o...
QgsDateTimeRange timeExtent() const
Returns the time extent.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
void setMeshSimplificationSettings(const QgsMeshSimplificationSettings &meshSimplificationSettings)
Sets mesh simplification settings.
void activeScalarDatasetGroupChanged(int index)
Emitted when active scalar group dataset is changed.
void activeVectorDatasetGroupChanged(int index)
Emitted when active vector group dataset is changed.
void reload() override
Synchronises with changes in the datasource.
QString loadDefaultStyle(bool &resultFlag) FINAL
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.
QgsMeshSimplificationSettings meshSimplificationSettings() const
Returns mesh simplification settings.
bool isEditable() const override
Returns true if the layer can be edited.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
void setReferenceTime(const QDateTime &referenceTime)
Sets the reference time of the layer.
void setTemporalMatchingMethod(const QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod &matchingMethod)
Sets the method used to match the temporal dataset from a requested time, see activeVectorDatasetAtTi...
Represents an overview renderer settings.
void setMeshResolution(int meshResolution)
Sets the mesh resolution i.e., the minimum size (average) of triangles in pixels This value is used d...
void setEnabled(bool isEnabled)
Sets if the overview is active.
double reductionFactor() const
Returns the reduction factor used to build simplified mesh.
bool isEnabled() const
Returns if the overview is active.
int meshResolution() const
Returns the mesh resolution i.e., the minimum size (average) of triangles in pixels.
void setReductionFactor(double value)
Sets the reduction factor used to build simplified mesh.
A base dialog for options and properties dialogs that offers vertical tabs.
void addPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QStringList &path=QStringList())
Adds a new page to the dialog pages.
virtual void optionsStackedWidget_CurrentChanged(int index)
Select relevant tab on current page change.
void insertPage(const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QString &before, const QStringList &path=QStringList())
Inserts a new page into the dialog pages.
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.
void setDirty(bool b=true)
Flag the project as dirty (modified).
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.
bool isActive() const
Returns true if the temporal property is active.
void setIsActive(bool active)
Sets whether the temporal property is active.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
#define QgsDebugMsgLevel(str, level)
const QgsCoordinateReferenceSystem & crs