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->notAggregatedUsedDatasetGroupNames();
44 mDatasetGroupNameUsedForAggregate = mCalcNode->aggregatedUsedDatasetGroupNames();
45 setDataType( QgsMeshCalcUtils::determineResultDataType( mLayer,
46 mDatasetGroupNameUsed + mDatasetGroupNameUsedForAggregate ) );
49 QMap<QString, int> usedDatasetGroupindexes;
51 for (
const int i : indexes )
54 if ( mDatasetGroupNameUsed.contains( usedName ) )
55 usedDatasetGroupindexes[usedName] = i;
59 if ( !mCalcNode->isNonTemporal() )
62 const QList<int> &usedIndexes = usedDatasetGroupindexes.values();
63 for (
const int groupIndex : usedIndexes )
71 for (
int i = 0; i < dsCount; i++ )
80 if ( times.isEmpty() )
83 mDatasetTimes = qgis::setToList( times );
84 std::sort( mDatasetTimes.begin(), mDatasetTimes.end() );
86 mDatasetMetaData = QVector<QgsMeshDatasetMetadata>( mDatasetTimes.count() );
90 while ( i < mDatasetTimes.count() )
92 mCurrentDatasetIndex = i;
93 if ( calculateDataset() )
96 mDatasetTimes.removeAt( i );
104 return mDatasetTimes.count();
109 if ( index < 0 || index >= mDatasetTimes.count() )
112 if ( index != mCurrentDatasetIndex )
114 mCurrentDatasetIndex = index;
118 return mCacheDataset.get();
123 if ( datasetIndex < 0 && datasetIndex >= mDatasetMetaData.count() )
126 return mDatasetMetaData.at( datasetIndex );
131 return mDatasetGroupNameUsed;
137 QDomElement elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
138 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"virtual" ) );
139 elemDataset.setAttribute( QStringLiteral(
"name" ),
name() );
140 elemDataset.setAttribute( QStringLiteral(
"formula" ), mFormula );
141 elemDataset.setAttribute( QStringLiteral(
"start-time" ), mStartTime );
142 elemDataset.setAttribute( QStringLiteral(
"end-time" ), mEndTime );
152 bool QgsMeshVirtualDatasetGroup::calculateDataset()
const
157 const QgsMeshCalcUtils dsu( mLayer,
158 mDatasetGroupNameUsed,
159 mDatasetGroupNameUsedForAggregate,
160 QgsInterval( mDatasetTimes[mCurrentDatasetIndex] / 1000.0 ),
164 if ( !dsu.isValid() )
168 std::unique_ptr<QgsMeshMemoryDatasetGroup> outputGroup = std::make_unique<QgsMeshMemoryDatasetGroup> ( QString(), dsu.outputType() );
169 mCalcNode->calculate( dsu, *outputGroup );
171 if ( outputGroup->memoryDatasets.isEmpty() )
174 mCacheDataset = outputGroup->memoryDatasets[0];
175 if ( !mDatasetMetaData[mCurrentDatasetIndex].isValid() )
177 mCacheDataset->calculateMinMax();
178 mCacheDataset->time = mDatasetTimes[mCurrentDatasetIndex] / 3600.0 / 1000.0;
179 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