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();