QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsmeshdatasetgrouptreewidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmeshdatasetgrouptreewidget.cpp
3 -------------------------------
4 begin : May 2020
5 copyright : (C) 2020 by Vincent Cloarec
6 email : vcloarec at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsmeshdatasetgrouptreewidget.cpp"
18
19#include <QFileDialog>
20#include <QMessageBox>
21
23#include "qgsmeshlayer.h"
25#include "qgsproject.h"
27#include "qgsproviderregistry.h"
28#include "qgssettings.h"
29
30
32 QWidget( parent )
33{
34 setupUi( this );
35
36 connect( mAddDatasetButton, &QToolButton::clicked, this, &QgsMeshDatasetGroupTreeWidget::addDataset );
37 connect( mCollapseButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::collapseAll );
38 connect( mExpandButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::expandAll );
39 connect( mCheckAllButton, &QToolButton::clicked, mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::selectAllGroups );
40 connect( mUnCheckAllButton, &QToolButton::clicked, mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::deselectAllGroups );
41 connect( mResetDefaultButton, &QToolButton::clicked, this, [this]
42 {
43 this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer );
44 } );
45
46 connect( mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::apply, this, &QgsMeshDatasetGroupTreeWidget::apply );
47}
48
50{
51 mMeshLayer = meshLayer;
52 mDatasetGroupTreeView->syncToLayer( meshLayer );
53}
54
56{
57 if ( mMeshLayer )
58 mMeshLayer->setDatasetGroupTreeRootItem( mDatasetGroupTreeView->datasetGroupTreeRootItem() );
59}
60
61void QgsMeshDatasetGroupTreeWidget::addDataset()
62{
63 if ( !mMeshLayer->dataProvider() )
64 return;
65
66 QgsSettings settings;
67 const QString openFileDir = settings.value( QStringLiteral( "lastMeshDatasetDir" ), QDir::homePath(), QgsSettings::App ).toString();
68 const QString openFileString = QFileDialog::getOpenFileName( nullptr,
69 tr( "Load mesh datasets" ),
70 openFileDir,
71 QgsProviderRegistry::instance()->fileMeshDatasetFilters() );
72
73 if ( openFileString.isEmpty() )
74 {
75 return; // canceled by the user
76 }
77
78 const QFileInfo openFileInfo( openFileString );
79 settings.setValue( QStringLiteral( "lastMeshDatasetDir" ), openFileInfo.absolutePath(), QgsSettings::App );
80 const QFile datasetFile( openFileString );
81
82 if ( mMeshLayer->addDatasets( openFileString, QgsProject::instance()->timeSettings()->temporalRange().begin() ) )
83 {
84 QMessageBox::information( this, tr( "Load mesh datasets" ), tr( "Datasets successfully added to the mesh layer" ) );
85 emit datasetGroupAdded();
86 }
87 else
88 {
89 QMessageBox::warning( this, tr( "Load mesh datasets" ), tr( "Could not read mesh dataset." ) );
90 }
91}
void apply()
Apply the dataset group tree item to the layer.
QgsMeshDatasetGroupTreeWidget(QWidget *parent=nullptr)
Constructor.
void syncToLayer(QgsMeshLayer *meshLayer)
Synchronizes widgets state with associated mesh layer.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
bool addDatasets(const QString &path, const QDateTime &defaultReferenceTime=QDateTime())
Adds datasets to the mesh from file with path.
void setDatasetGroupTreeRootItem(QgsMeshDatasetGroupTreeItem *rootItem)
Sets the root items of the dataset group tree item.
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
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.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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.
Definition qgsrange.h:444