22 const QString &formulaString,
24 qint64 relativeStartTime,
25 qint64 relativeEndTime ):
27 , mFormula( formulaString )
29 , mStartTime( relativeStartTime )
30 , mEndTime( relativeEndTime )
37 mCalcNode.reset( QgsMeshCalcNode::parseMeshCalcString( mFormula, errMessage ) );
39 if ( !mCalcNode || !mLayer )
42 mDatasetGroupNameUsed = mCalcNode->notAggregatedUsedDatasetGroupNames();
43 mDatasetGroupNameUsedForAggregate = mCalcNode->aggregatedUsedDatasetGroupNames();
44 setDataType( QgsMeshCalcUtils::determineResultDataType( mLayer,
45 mDatasetGroupNameUsed + mDatasetGroupNameUsedForAggregate ) );
48 QMap<QString, int> usedDatasetGroupindexes;
50 for (
const int i : indexes )
53 if ( mDatasetGroupNameUsed.contains( usedName ) )
54 usedDatasetGroupindexes[usedName] = i;
58 if ( !mCalcNode->isNonTemporal() )
61 const QList<int> &usedIndexes = usedDatasetGroupindexes.values();
62 for (
const int groupIndex : usedIndexes )
70 for (
int i = 0; i < dsCount; i++ )
79 if ( times.isEmpty() )
82 mDatasetTimes = QList<qint64>( times.constBegin(), times.constEnd() );
83 std::sort( mDatasetTimes.begin(), mDatasetTimes.end() );
85 mDatasetMetaData = QVector<QgsMeshDatasetMetadata>( mDatasetTimes.count() );
89 while ( i < mDatasetTimes.count() )
91 mCurrentDatasetIndex = i;
92 if ( calculateDataset() )
95 mDatasetTimes.removeAt( i );
103 return mDatasetTimes.count();
108 if ( index < 0 || index >= mDatasetTimes.count() )
111 if ( index != mCurrentDatasetIndex )
113 mCurrentDatasetIndex = index;
117 return mCacheDataset.get();
122 if ( datasetIndex < 0 && datasetIndex >= mDatasetMetaData.count() )
125 return mDatasetMetaData.at( datasetIndex );
130 return mDatasetGroupNameUsed;
136 QDomElement elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
137 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"virtual" ) );
138 elemDataset.setAttribute( QStringLiteral(
"name" ),
name() );
139 elemDataset.setAttribute( QStringLiteral(
"formula" ), mFormula );
140 elemDataset.setAttribute( QStringLiteral(
"start-time" ), mStartTime );
141 elemDataset.setAttribute( QStringLiteral(
"end-time" ), mEndTime );
151bool QgsMeshVirtualDatasetGroup::calculateDataset()
const
156 const QgsMeshCalcUtils dsu( mLayer,
157 mDatasetGroupNameUsed,
158 mDatasetGroupNameUsedForAggregate,
159 QgsInterval( mDatasetTimes[mCurrentDatasetIndex] / 1000.0 ),
163 if ( !dsu.isValid() )
167 std::unique_ptr<QgsMeshMemoryDatasetGroup> outputGroup = std::make_unique<QgsMeshMemoryDatasetGroup> ( QString(), dsu.outputType() );
168 mCalcNode->calculate( dsu, *outputGroup );
170 if ( outputGroup->memoryDatasets.isEmpty() )
173 mCacheDataset = outputGroup->memoryDatasets[0];
174 if ( !mDatasetMetaData[mCurrentDatasetIndex].isValid() )
176 mCacheDataset->calculateMinMax();
177 mCacheDataset->time = mDatasetTimes[mCurrentDatasetIndex] / 3600.0 / 1000.0;
178 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() const
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