23 const QString &formulaString,
25 qint64 relativeStartTime,
26 qint64 relativeEndTime ):
28 , mFormula( formulaString )
30 , mStartTime( relativeStartTime )
31 , mEndTime( relativeEndTime )
38 mCalcNode.reset( QgsMeshCalcNode::parseMeshCalcString( mFormula, errMessage ) );
40 if ( !mCalcNode || !mLayer )
43 mDatasetGroupNameUsed = mCalcNode->usedDatasetGroupNames();
44 setDataType( QgsMeshCalcUtils::determineResultDataType( mLayer, mDatasetGroupNameUsed ) );
47 QMap<QString, int> usedDatasetGroupindexes;
49 for (
int i : indexes )
52 if ( mDatasetGroupNameUsed.contains( usedName ) )
53 usedDatasetGroupindexes[usedName] = i;
57 if ( !mCalcNode->isNonTemporal() )
60 const QList<int> &usedIndexes = usedDatasetGroupindexes.values();
61 for (
int groupIndex : usedIndexes )
69 for (
int i = 0; i < dsCount; i++ )
78 if ( times.isEmpty() )
81 mDatasetTimes = qgis::setToList( times );
82 std::sort( mDatasetTimes.begin(), mDatasetTimes.end() );
84 mDatasetMetaData = QVector<QgsMeshDatasetMetadata>( mDatasetTimes.count() );
88 while ( i < mDatasetTimes.count() )
90 mCurrentDatasetIndex = i;
91 if ( calculateDataset() )
94 mDatasetTimes.removeAt( i );
102 return mDatasetTimes.count();
107 if ( index < 0 || index >= mDatasetTimes.count() )
110 if ( index != mCurrentDatasetIndex )
112 mCurrentDatasetIndex = index;
116 return mCacheDataset.get();
121 if ( datasetIndex < 0 && datasetIndex >= mDatasetMetaData.count() )
124 return mDatasetMetaData.at( datasetIndex );
129 return mDatasetGroupNameUsed;
135 QDomElement elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
136 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"virtual" ) );
137 elemDataset.setAttribute( QStringLiteral(
"name" ),
name() );
138 elemDataset.setAttribute( QStringLiteral(
"formula" ), mFormula );
139 elemDataset.setAttribute( QStringLiteral(
"start-time" ), mStartTime );
140 elemDataset.setAttribute( QStringLiteral(
"end-time" ), mEndTime );
150 bool QgsMeshVirtualDatasetGroup::calculateDataset()
const
155 QgsMeshCalcUtils dsu( mLayer, mDatasetGroupNameUsed,
QgsInterval( mDatasetTimes[mCurrentDatasetIndex] / 1000.0 ) );
157 if ( !dsu.isValid() )
161 std::unique_ptr<QgsMeshMemoryDatasetGroup> outputGroup = std::make_unique<QgsMeshMemoryDatasetGroup> ( QString(), dsu.outputType() );
162 mCalcNode->calculate( dsu, *outputGroup );
164 if ( outputGroup->memoryDatasets.isEmpty() )
167 mCacheDataset = outputGroup->memoryDatasets[0];
168 if ( !mDatasetMetaData[mCurrentDatasetIndex].isValid() )
170 mCacheDataset->calculateMinMax();
171 mCacheDataset->time = mDatasetTimes[mCurrentDatasetIndex] / 3600.0 / 1000.0;
172 mDatasetMetaData[mCurrentDatasetIndex] = mCacheDataset->metadata();
A representation of the interval between two datetime values.
Abstract class that represents a dataset group.
void setDataType(const QgsMeshDatasetGroupMetadata::DataType &dataType)
Sets the data type of the dataset group.
QString name() const
Returns the name of the dataset group.
void calculateStatistic()
Calculates the statistics (minimum and maximum)
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
Abstract class that represents a dataset.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
int datasetCount(const QgsMeshDatasetIndex &index) const
Returns the dataset count in the dataset groups.
QList< int > datasetGroupsIndexes() const
Returns the list of indexes of dataset groups handled by the layer.
qint64 datasetRelativeTimeInMilliseconds(const QgsMeshDatasetIndex &index)
Returns the relative time (in milliseconds) of the dataset from the reference time of its group.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the dataset groups metadata.
QgsMeshVirtualDatasetGroup(const QString &name, const QString &formulaString, QgsMeshLayer *layer, qint64 relativeStartTime, qint64 relativeEndTime)
Constructor.
QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const override
Returns the metadata of the dataset with index datasetIndex.
QStringList datasetGroupNamesDependentOn() const override
Returns the dataset group variable name which this dataset group depends on.
void initialize() override
Initialize the dataset group.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const override
Write dataset group information in a DOM element.
int datasetCount() const override
Returns the count of datasets in the group.
QgsMeshDataset * dataset(int index) const override
Returns the dataset with index.
QString description() const override
Returns some information about the dataset group.
The class is used as a container of context for various read/write operations on other objects.
#define INVALID_MESHLAYER_TIME