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() )
176 page->syncToLayer( mMeshLayer );
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;
278 if ( !defaultSavedFlag )
281 QMessageBox::information(
this,
282 tr(
"Default Style" ),
288 void QgsMeshLayerProperties::loadStyle()
291 QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
293 QString fileName = QFileDialog::getOpenFileName(
295 tr(
"Load rendering setting from style file" ),
297 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
298 if ( fileName.isEmpty() )
302 if ( !fileName.endsWith( QLatin1String(
".qml" ), Qt::CaseInsensitive ) )
303 fileName += QLatin1String(
".qml" );
307 bool defaultLoadedFlag =
false;
308 QString message = mMeshLayer->
loadNamedStyle( fileName, defaultLoadedFlag );
309 if ( defaultLoadedFlag )
311 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( fileName ).absolutePath() );
316 QMessageBox::information(
this, tr(
"Load Style" ), message );
320 void QgsMeshLayerProperties::saveStyleAs()
323 QString lastUsedDir = settings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
325 QString outputFileName = QFileDialog::getSaveFileName(
327 tr(
"Save layer properties as style file" ),
329 tr(
"QGIS Layer Style File" ) +
" (*.qml)" );
330 if ( outputFileName.isEmpty() )
339 bool defaultLoadedFlag =
false;
341 message = mMeshLayer->
saveNamedStyle( outputFileName, defaultLoadedFlag );
343 if ( defaultLoadedFlag )
345 settings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( outputFileName ).absolutePath() );
348 QMessageBox::information(
this, tr(
"Save Style" ), message );
351 void QgsMeshLayerProperties::apply()
353 Q_ASSERT( mRendererMeshPropertiesWidget );
359 mMeshLayer->
setName( mLayerOrigNameLineEd->text() );
365 mDatasetGroupTreeWidget->apply();
377 simplifySettings.
setEnabled( mSimplifyMeshGroupBox->isChecked() );
395 mStaticDatasetWidget->apply();
399 mComboBoxTemporalDatasetMatchingMethod->currentData().toInt() ) );
403 mBackupCrs = mMeshLayer->
crs();
405 if ( needMeshUpdating )
408 if ( needEmitRendererChanged )
418 mStaticDatasetWidget->syncToLayer();
420 w->syncToLayer( mMeshLayer );
429 void QgsMeshLayerProperties::syncAndRepaint()
435 void QgsMeshLayerProperties::showHelp()
437 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property(
"helpPage" );
439 if ( helpPage.isValid() )
449 void QgsMeshLayerProperties::aboutToShowStyleMenu()
451 QMenu *m = qobject_cast<QMenu *>( sender() );
459 void QgsMeshLayerProperties::reloadTemporalProperties()
464 QgsDateTimeRange timeExtent;
465 QDateTime referenceTime = temporalCapabalities->
referenceTime();
466 if ( referenceTime.isValid() )
468 timeExtent = temporalCapabalities->
timeExtent();
469 whileBlocking( mTemporalDateTimeReference )->setDateTime( referenceTime );
473 timeExtent = temporalCapabalities->
timeExtent( mTemporalDateTimeReference->dateTime() );
475 mTemporalDateTimeStart->setDateTime( timeExtent.begin() );
476 mTemporalDateTimeEnd->setDateTime( timeExtent.end() );
479 void QgsMeshLayerProperties::onTimeReferenceChange()
484 mTemporalDateTimeStart->setDateTime( timeExtent.begin() );
485 mTemporalDateTimeEnd->setDateTime( timeExtent.end() );
488 void QgsMeshLayerProperties::urlClicked(
const QUrl &url )
490 QFileInfo file( url.toLocalFile() );
491 if ( file.exists() && !file.isDir() )
494 QDesktopServices::openUrl( url );
497 void QgsMeshLayerProperties::loadMetadata()
500 QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
502 QString myFileName = QFileDialog::getOpenFileName(
this, tr(
"Load layer metadata from metadata file" ), myLastUsedDir,
503 tr(
"QGIS Layer Metadata File" ) +
" (*.qmd)" );
504 if ( myFileName.isNull() )
510 bool defaultLoadedFlag =
false;
514 if ( defaultLoadedFlag )
521 QMessageBox::warning(
this, tr(
"Load Metadata" ), myMessage );
524 QFileInfo myFI( myFileName );
525 QString myPath = myFI.path();
526 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), myPath );
531 void QgsMeshLayerProperties::saveMetadataAs()
534 QString myLastUsedDir = myQSettings.
value( QStringLiteral(
"style/lastStyleDir" ), QDir::homePath() ).toString();
536 QString myOutputFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Layer Metadata as QMD" ),
537 myLastUsedDir, tr(
"QMD File" ) +
" (*.qmd)" );
538 if ( myOutputFileName.isNull() )
551 bool defaultLoadedFlag =
false;
552 QString message = mMeshLayer->
saveNamedMetadata( myOutputFileName, defaultLoadedFlag );
553 if ( defaultLoadedFlag )
554 myQSettings.
setValue( QStringLiteral(
"style/lastStyleDir" ), QFileInfo( myOutputFileName ).absolutePath() );
556 QMessageBox::information(
this, tr(
"Save Metadata" ), message );
559 void QgsMeshLayerProperties::onCancel()
561 if ( mBackupCrs != mMeshLayer->
crs() )
562 mMeshLayer->
setCrs( mBackupCrs );