30#include "moc_qgsmeshdatasetgrouptreewidget.cpp"
32using namespace Qt::StringLiterals;
39 connect( mAddDatasetButton, &QToolButton::clicked,
this, &QgsMeshDatasetGroupTreeWidget::addDataset );
40 connect( mRemoveDatasetButton, &QToolButton::clicked,
this, &QgsMeshDatasetGroupTreeWidget::removeDataset );
41 connect( mCollapseButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::collapseAll );
42 connect( mExpandButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::expandAll );
45 connect( mResetDefaultButton, &QToolButton::clicked,
this, [
this] { this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer ); } );
47 connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, [
this]() {
48 const QModelIndex index = mDatasetGroupTreeView->currentIndex();
49 const QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->childFromDatasetGroupIndex( index.row() );
52 if ( mMeshLayer->dataProvider()->dataSourceUri().contains( meshGroupItem->description() ) )
54 mRemoveDatasetButton->setEnabled( false );
58 mRemoveDatasetButton->setEnabled( true );
68 mMeshLayer = meshLayer;
69 mDatasetGroupTreeView->syncToLayer( meshLayer );
78void QgsMeshDatasetGroupTreeWidget::removeDataset()
80 const QModelIndex index = mDatasetGroupTreeView->currentIndex();
82 const QString datasetGroupName = meshGroupItem->
defaultName();
85 QMessageBox::warning(
this, tr(
"Remove mesh datasets" ), tr(
"Dataset Group removed from mesh." ) );
90 QMessageBox::warning(
this, tr(
"Remove mesh datasets" ), tr(
"Could not remove mesh dataset group." ) );
93 mDatasetGroupTreeView->resetDefault( mMeshLayer );
96void QgsMeshDatasetGroupTreeWidget::addDataset()
98 if ( !mMeshLayer->dataProvider() )
101 QgsSettings settings;
102 const QString openFileDir = settings.
value( u
"lastMeshDatasetDir"_s, QDir::homePath(),
QgsSettings::App ).toString();
103 const QString openFileString = QFileDialog::getOpenFileName(
nullptr, tr(
"Load mesh datasets" ), openFileDir,
QgsProviderRegistry::instance()->fileMeshDatasetFilters() );
105 if ( openFileString.isEmpty() )
110 if ( !mMeshLayer->datasetsPathUnique( openFileString ) )
112 QMessageBox::warning(
this, tr(
"Load mesh datasets" ), tr(
"Could not add dataset from path that is already added to the mesh." ) );
116 const QFileInfo openFileInfo( openFileString );
118 const QFile datasetFile( openFileString );
122 QMessageBox::information(
this, tr(
"Load mesh datasets" ), tr(
"Datasets successfully added to the mesh layer" ) );
127 QMessageBox::warning(
this, tr(
"Load mesh datasets" ), tr(
"Could not read mesh dataset." ) );
Tree item for display of the mesh dataset groups.
QString defaultName() const
Returns the default name.
QgsMeshDatasetGroupTreeItem * child(int row) const
Returns a child.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
void setDatasetGroupTreeRootItem(QgsMeshDatasetGroupTreeItem *rootItem)
Sets the root items of the dataset group tree item.
bool removeDatasets(const QString &name)
Removes datasets from the mesh with given name.
QgsDateTimeRange temporalRange() const
Returns the project's temporal range, which indicates the earliest and latest datetime ranges associa...
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsProjectTimeSettings * timeSettings() const
Returns the project's time settings, which contains the project's temporal range and other time based...
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
T begin() const
Returns the beginning of the range.