42 #include "qgsnative.h"
45 #include <QDesktopServices>
46 #include <QFileDialog>
47 #include <QMessageBox>
54 Q_ASSERT( mMeshLayer );
58 mConfigWidgets << mRendererMeshPropertiesWidget;
59 mOptsPage_StyleContent->layout()->addWidget( mRendererMeshPropertiesWidget );
61 mSimplifyReductionFactorSpinBox->setClearValue( 10.0 );
62 mSimplifyMeshResolutionSpinBox->setClearValue( 5 );
64 mStaticDatasetWidget->setLayer( mMeshLayer );
82 connect(
this, &QDialog::accepted,
this, &QgsMeshLayerProperties::apply );
83 connect(
this, &QDialog::rejected,
this, &QgsMeshLayerProperties::onCancel );
84 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked,
this, &QgsMeshLayerProperties::apply );
87 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsMeshLayerProperties::showHelp );
89 connect( mTemporalReloadButton, &QPushButton::clicked,
this, &QgsMeshLayerProperties::reloadTemporalProperties );
90 connect( mTemporalDateTimeReference, &QDateTimeEdit::dateTimeChanged,
this, &QgsMeshLayerProperties::onTimeReferenceChange );
94 mComboBoxTemporalDatasetMatchingMethod->addItem( tr(
"Find Closest Dataset Before Requested Time" ),
96 mComboBoxTemporalDatasetMatchingMethod->addItem( tr(
"Find Closest Dataset From Requested Time (After or Before)" ),
99 QVBoxLayout *layout =
new QVBoxLayout( metadataFrame );
100 layout->setContentsMargins( 0, 0, 0, 0 );
101 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
103 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
105 layout->addWidget( mMetadataWidget );
106 metadataFrame->setLayout( layout );
107 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
108 mBackupCrs = mMeshLayer->
crs();
110 mTemporalDateTimeStart->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
111 mTemporalDateTimeEnd->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
112 mTemporalDateTimeReference->setDisplayFormat(
"yyyy-MM-dd HH:mm:ss" );
120 if ( !settings.
contains( QStringLiteral(
"/Windows/MeshLayerProperties/tab" ) ) )
122 settings.
setValue( QStringLiteral(
"Windows/MeshLayerProperties/tab" ),
127 mOptsPage_Information->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#information-properties" ) );
128 mOptsPage_Source->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#source-properties" ) );
129 mOptsPage_Style->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#symbology-properties" ) );
130 mOptsPage_Rendering->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#rendering-properties" ) );
132 mBtnStyle =
new QPushButton( tr(
"Style" ) );
133 QMenu *menuStyle =
new QMenu(
this );
134 menuStyle->addAction( tr(
"Load Style…" ),
this, &QgsMeshLayerProperties::loadStyle );
135 menuStyle->addAction( tr(
"Save Style…" ),
this, &QgsMeshLayerProperties::saveStyleAs );
136 menuStyle->addSeparator();
137 menuStyle->addAction( tr(
"Save as Default" ),
this, &QgsMeshLayerProperties::saveDefaultStyle );
138 menuStyle->addAction( tr(
"Restore Default" ),
this, &QgsMeshLayerProperties::loadDefaultStyle );
139 mBtnStyle->setMenu( menuStyle );
140 connect( menuStyle, &QMenu::aboutToShow,
this, &QgsMeshLayerProperties::aboutToShowStyleMenu );
142 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
144 mBtnMetadata =
new QPushButton( tr(
"Metadata" ),
this );
145 QMenu *menuMetadata =
new QMenu(
this );
146 mActionLoadMetadata = menuMetadata->addAction( tr(
"Load Metadata…" ),
this, &QgsMeshLayerProperties::loadMetadata );
147 mActionSaveMetadataAs = menuMetadata->addAction( tr(
"Save Metadata…" ),
this, &QgsMeshLayerProperties::saveMetadataAs );
148 mBtnMetadata->setMenu( menuMetadata );
149 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
151 QString title = tr(
"Layer Properties — %1" ).arg( lyr->
name() );
166 mConfigWidgets << page;
168 page->setProperty(
"helpPage", QStringLiteral(
"working_with_mesh/mesh_properties.html#d-view-properties" ) );
171 if ( beforePage.isEmpty() )
184 bool isMetadataPanel = ( index ==
mOptStackedWidget->indexOf( mOptsPage_Metadata ) );
185 mBtnStyle->setVisible( ! isMetadataPanel );
186 mBtnMetadata->setVisible( isMetadataPanel );
189 void QgsMeshLayerProperties::syncToLayer()
191 Q_ASSERT( mRendererMeshPropertiesWidget );
193 QgsDebugMsgLevel( QStringLiteral(
"populate general information tab" ), 4 );
198 myStyle.append( QStringLiteral(
"body { margin: 10px; }\n " ) );
199 mInformationTextBrowser->clear();
200 mInformationTextBrowser->document()->setDefaultStyleSheet( myStyle );
201 mInformationTextBrowser->setHtml( mMeshLayer->
htmlMetadata() );
202 mInformationTextBrowser->setOpenLinks(
false );
203 connect( mInformationTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsMeshLayerProperties::urlClicked );
209 mLayerOrigNameLineEd->setText( mMeshLayer->
name() );
213 mDatasetGroupTreeWidget->syncToLayer( mMeshLayer );
217 w->syncToLayer( mMeshLayer );
221 mSimplifyMeshGroupBox->setEnabled(
false );
224 mSimplifyMeshGroupBox->setChecked( simplifySettings.
isEnabled() );
225 mSimplifyReductionFactorSpinBox->setValue( simplifySettings.
reductionFactor() );
226 mSimplifyMeshResolutionSpinBox->setValue( simplifySettings.
meshResolution() );
231 const QgsDateTimeRange timeRange = temporalProperties->
timeExtent();
232 mTemporalDateTimeStart->setDateTime( timeRange.begin() );
233 mTemporalDateTimeEnd->setDateTime( timeRange.end() );
236 mTemporalProviderTimeUnitComboBox->setCurrentIndex(
239 mComboBoxTemporalDatasetMatchingMethod->setCurrentIndex(
240 mComboBoxTemporalDatasetMatchingMethod->findData( temporalProperties->
matchingMethod() ) );
242 mStaticDatasetWidget->syncToLayer();
246 void QgsMeshLayerProperties::loadDefaultStyle()
248 bool defaultLoadedFlag =
false;
251 if ( defaultLoadedFlag )
258 QMessageBox::information(
this,
259 tr(
"Default Style" ),
265 void QgsMeshLayerProperties::saveDefaultStyle()
270 bool defaultSavedFlag =
false;
274 if ( !defaultSavedFlag )
277 QMessageBox::information(
this,
278 tr(
"Default Style" ),
284 void QgsMeshLayerProperties::loadStyle()
287 QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
289 QString fileName = QFileDialog::getOpenFileName(
291 tr(
"Load rendering setting from style file" ),
293 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
294 if ( fileName.isEmpty() )
298 if ( !fileName.endsWith( QLatin1String(
".qml" ), Qt::CaseInsensitive ) )
299 fileName += QLatin1String(
".qml" );
303 bool defaultLoadedFlag =
false;
304 QString message = mMeshLayer->
loadNamedStyle( fileName, defaultLoadedFlag );
305 if ( defaultLoadedFlag )
307 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( fileName ).absolutePath() );
312 QMessageBox::information(
this, tr(
"Load Style" ), message );
316 void QgsMeshLayerProperties::saveStyleAs()
319 QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
321 QString outputFileName = QFileDialog::getSaveFileName(
323 tr(
"Save layer properties as style file" ),
325 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
326 if ( outputFileName.isEmpty() )
335 bool defaultLoadedFlag =
false;
337 message = mMeshLayer->
saveNamedStyle( outputFileName, defaultLoadedFlag );
339 if ( defaultLoadedFlag )
341 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( outputFileName ).absolutePath() );
344 QMessageBox::information(
this, tr(
"Save Style" ), message );
347 void QgsMeshLayerProperties::apply()
349 Q_ASSERT( mRendererMeshPropertiesWidget );
355 mMeshLayer->
setName( mLayerOrigNameLineEd->text() );
361 mDatasetGroupTreeWidget->apply();
373 simplifySettings.
setEnabled( mSimplifyMeshGroupBox->isChecked() );
391 mStaticDatasetWidget->apply();
395 mComboBoxTemporalDatasetMatchingMethod->currentData().toInt() ) );
399 mBackupCrs = mMeshLayer->
crs();
401 if ( needMeshUpdating )
404 if ( needEmitRendererChanged )
414 mStaticDatasetWidget->syncToLayer();
416 w->syncToLayer( mMeshLayer );
425 void QgsMeshLayerProperties::syncAndRepaint()
431 void QgsMeshLayerProperties::showHelp()
433 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
435 if ( helpPage.isValid() )
445 void QgsMeshLayerProperties::aboutToShowStyleMenu()
447 QMenu *m = qobject_cast<QMenu *>( sender() );
455 void QgsMeshLayerProperties::reloadTemporalProperties()
460 QgsDateTimeRange timeExtent;
461 QDateTime referenceTime = temporalCapabalities->
referenceTime();
462 if ( referenceTime.isValid() )
464 timeExtent = temporalCapabalities->
timeExtent();
465 whileBlocking( mTemporalDateTimeReference )->setDateTime( referenceTime );
469 timeExtent = temporalCapabalities->
timeExtent( mTemporalDateTimeReference->dateTime() );
471 mTemporalDateTimeStart->setDateTime( timeExtent.begin() );
472 mTemporalDateTimeEnd->setDateTime( timeExtent.end() );
475 void QgsMeshLayerProperties::onTimeReferenceChange()
480 mTemporalDateTimeStart->setDateTime( timeExtent.begin() );
481 mTemporalDateTimeEnd->setDateTime( timeExtent.end() );
484 void QgsMeshLayerProperties::urlClicked(
const QUrl &url )
486 QFileInfo file( url.toLocalFile() );
487 if ( file.exists() && !file.isDir() )
490 QDesktopServices::openUrl( url );
493 void QgsMeshLayerProperties::loadMetadata()
496 QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
498 QString myFileName = QFileDialog::getOpenFileName(
this, tr(
"Load layer metadata from metadata file" ), myLastUsedDir,
499 tr(
"QGIS Layer Metadata File" ) +
" (*.qmd)" );
500 if ( myFileName.isNull() )
506 bool defaultLoadedFlag =
false;
510 if ( defaultLoadedFlag )
517 QMessageBox::warning(
this, tr(
"Load Metadata" ), myMessage );
520 QFileInfo myFI( myFileName );
521 QString myPath = myFI.path();
522 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
527 void QgsMeshLayerProperties::saveMetadataAs()
530 QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
532 QString myOutputFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Layer Metadata as QMD" ),
533 myLastUsedDir, tr(
"QMD File" ) +
" (*.qmd)" );
534 if ( myOutputFileName.isNull() )
547 bool defaultLoadedFlag =
false;
548 QString message = mMeshLayer->
saveNamedMetadata( myOutputFileName, defaultLoadedFlag );
549 if ( defaultLoadedFlag )
550 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( myOutputFileName ).absolutePath() );
552 QMessageBox::information(
this, tr(
"Save Metadata" ), message );
555 void QgsMeshLayerProperties::onCancel()
557 if ( mBackupCrs != mMeshLayer->
crs() )
558 mMeshLayer->
setCrs( mBackupCrs );
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 QgsGui * instance()
Returns a pointer to the singleton instance.
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.
bool isDefault(const QString &styleName) const
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.
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.
QgsLayerMetadata metadata
virtual QString saveDefaultStyle(bool &resultFlag)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
void rendererChanged()
Signal emitted when renderer is changed.
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...
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...
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.
QgsUnitTypes::TemporalUnit temporalUnit() const
Returns the temporal unit used to read data by the data provider.
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...
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.
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
void setTemporalUnit(QgsUnitTypes::TemporalUnit unit)
Sets the temporal unit of the provider and reload data if it changes.
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.
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...
TemporalUnit
Temporal units.
@ TemporalSeconds
Seconds.
@ TemporalMinutes
Minutes.
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