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] {
46 this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer );
49 connect( mDatasetGroupTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, [
this]() {
50 const QModelIndex index = mDatasetGroupTreeView->currentIndex();
51 const QgsMeshDatasetGroupTreeItem *meshGroupItem = mDatasetGroupTreeView->datasetGroupTreeRootItem()->childFromDatasetGroupIndex( index.row() );
54 if ( mMeshLayer->dataProvider()->dataSourceUri().contains( meshGroupItem->description() ) )
56 mRemoveDatasetButton->setEnabled( false );
60 mRemoveDatasetButton->setEnabled( true );
70 mMeshLayer = meshLayer;
71 mDatasetGroupTreeView->syncToLayer( meshLayer );
80void QgsMeshDatasetGroupTreeWidget::removeDataset()
82 const QModelIndex index = mDatasetGroupTreeView->currentIndex();
84 const QString datasetGroupName = meshGroupItem->
defaultName();
87 QMessageBox::warning(
this, tr(
"Remove mesh datasets" ), tr(
"Dataset Group removed from mesh." ) );
92 QMessageBox::warning(
this, tr(
"Remove mesh datasets" ), tr(
"Could not remove mesh dataset group." ) );
95 mDatasetGroupTreeView->resetDefault( mMeshLayer );
98void QgsMeshDatasetGroupTreeWidget::addDataset()
100 if ( !mMeshLayer->dataProvider() )
103 QgsSettings settings;
104 const QString openFileDir = settings.
value( u
"lastMeshDatasetDir"_s, QDir::homePath(),
QgsSettings::App ).toString();
105 const QString openFileString = QFileDialog::getOpenFileName(
nullptr, tr(
"Load mesh datasets" ), openFileDir,
QgsProviderRegistry::instance()->fileMeshDatasetFilters() );
107 if ( openFileString.isEmpty() )
112 if ( !mMeshLayer->datasetsPathUnique( openFileString ) )
114 QMessageBox::warning(
this, tr(
"Load mesh datasets" ), tr(
"Could not add dataset from path that is already added to the mesh." ) );
118 const QFileInfo openFileInfo( openFileString );
120 const QFile datasetFile( openFileString );
124 QMessageBox::information(
this, tr(
"Load mesh datasets" ), tr(
"Datasets successfully added to the mesh layer" ) );
129 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.