QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
18 #include <QFileDialog>
19 #include <QMessageBox>
20 
22 #include "qgsmeshlayer.h"
24 #include "qgsproject.h"
25 #include "qgsprojecttimesettings.h"
26 #include "qgsproviderregistry.h"
27 #include "qgssettings.h"
28 
29 
31  QWidget( parent )
32 {
33  setupUi( this );
34 
35  connect( mAddDatasetButton, &QToolButton::clicked, this, &QgsMeshDatasetGroupTreeWidget::addDataset );
36  connect( mCollapseButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::collapseAll );
37  connect( mExpandButton, &QToolButton::clicked, mDatasetGroupTreeView, &QTreeView::expandAll );
38  connect( mCheckAllButton, &QToolButton::clicked, mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::selectAllGroups );
39  connect( mUnCheckAllButton, &QToolButton::clicked, mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::deselectAllGroups );
40  connect( mResetDefaultButton, &QToolButton::clicked, this, [this]
41  {
42  this->mDatasetGroupTreeView->resetDefault( this->mMeshLayer );
43  } );
44 
45  connect( mDatasetGroupTreeView, &QgsMeshDatasetGroupTreeView::apply, this, &QgsMeshDatasetGroupTreeWidget::apply );
46 }
47 
49 {
50  mMeshLayer = meshLayer;
51  mDatasetGroupTreeView->syncToLayer( meshLayer );
52 }
53 
55 {
56  if ( mMeshLayer )
57  mMeshLayer->setDatasetGroupTreeRootItem( mDatasetGroupTreeView->datasetGroupTreeRootItem() );
58 }
59 
60 void QgsMeshDatasetGroupTreeWidget::addDataset()
61 {
62  if ( !mMeshLayer->dataProvider() )
63  return;
64 
65  QgsSettings settings;
66  const QString openFileDir = settings.value( QStringLiteral( "lastMeshDatasetDir" ), QDir::homePath(), QgsSettings::App ).toString();
67  const QString openFileString = QFileDialog::getOpenFileName( nullptr,
68  tr( "Load mesh datasets" ),
69  openFileDir,
70  QgsProviderRegistry::instance()->fileMeshDatasetFilters() );
71 
72  if ( openFileString.isEmpty() )
73  {
74  return; // canceled by the user
75  }
76 
77  const QFileInfo openFileInfo( openFileString );
78  settings.setValue( QStringLiteral( "lastMeshDatasetDir" ), openFileInfo.absolutePath(), QgsSettings::App );
79  const QFile datasetFile( openFileString );
80 
81  if ( mMeshLayer->addDatasets( openFileString, QgsProject::instance()->timeSettings()->temporalRange().begin() ) )
82  {
83  QMessageBox::information( this, tr( "Load mesh datasets" ), tr( "Datasets successfully added to the mesh layer" ) );
84  emit datasetGroupAdded();
85  }
86  else
87  {
88  QMessageBox::warning( this, tr( "Load mesh datasets" ), tr( "Could not read mesh dataset." ) );
89  }
90 }
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:161
QgsSettings::App
@ App
Definition: qgssettings.h:75
QgsMeshDatasetGroupTreeView::apply
void apply()
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:61
QgsProjectTimeSettings::temporalRange
QgsDateTimeRange temporalRange() const
Returns the project's temporal range, which indicates the earliest and latest datetime ranges associa...
Definition: qgsprojecttimesettings.cpp:34
QgsMeshDatasetGroupTreeWidget::syncToLayer
void syncToLayer(QgsMeshLayer *meshLayer)
Synchronizes widgets state with associated mesh layer.
Definition: qgsmeshdatasetgrouptreewidget.cpp:48
QgsProject::timeSettings
const QgsProjectTimeSettings * timeSettings() const
Returns the project's time settings, which contains the project's temporal range and other time based...
Definition: qgsproject.cpp:3511
qgsproviderregistry.h
QgsMeshLayer
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Definition: qgsmeshlayer.h:98
QgsMeshLayer::setDatasetGroupTreeRootItem
void setDatasetGroupTreeRootItem(QgsMeshDatasetGroupTreeItem *rootItem)
Sets the root items of the dataset group tree item.
Definition: qgsmeshlayer.cpp:759
QgsSettings::setValue
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Definition: qgssettings.cpp:279
QgsMeshDatasetGroupTreeWidget::datasetGroupAdded
void datasetGroupAdded()
qgsmeshlayer.h
qgsprojecttimesettings.h
QgsMeshLayer::addDatasets
bool addDatasets(const QString &path, const QDateTime &defaultReferenceTime=QDateTime())
Adds datasets to the mesh from file with path.
Definition: qgsmeshlayer.cpp:231
qgssettings.h
QgsMeshDatasetGroupTreeView::deselectAllGroups
void deselectAllGroups()
Definition: qgsmeshdatasetgrouptreeview.cpp:593
QgsMeshDatasetGroupTreeWidget::QgsMeshDatasetGroupTreeWidget
QgsMeshDatasetGroupTreeWidget(QWidget *parent=nullptr)
Constructor.
Definition: qgsmeshdatasetgrouptreewidget.cpp:30
QgsMeshDatasetGroupTreeWidget::apply
void apply()
Apply the dataset group tree item to the layer.
Definition: qgsmeshdatasetgrouptreewidget.cpp:54
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:73
qgsmeshdatasetgrouptreewidget.h
QgsMeshLayer::dataProvider
QgsMeshDataProvider * dataProvider() override
Returns the layer's data provider, it may be nullptr.
Definition: qgsmeshlayer.cpp:110
qgsproject.h
QgsMeshDatasetGroupTreeView::selectAllGroups
void selectAllGroups()
Definition: qgsmeshdatasetgrouptreeview.cpp:588
qgsmeshdatasetgrouptreeview.h
qgsmeshlayertemporalproperties.h