27 return mRegistery.keys();
32 return mDatasetGroupTreeRootItem->enabledDatasetGroupIndexes();
37 return mRegistery.count();
42 return mExtraDatasets->datasetGroupCount();
53 removePersistentProvider();
54 mPersistentProvider = provider;
55 if ( !mPersistentProvider )
57 for (
const QString &uri : extraDatasetUri )
62 checkDatasetConsistency( mPersistentProvider );
63 removeUnregisteredItemFromTree();
68 const int groupCount = mExtraDatasets->datasetGroupCount();
69 for (
int i = 0; i < groupCount; ++i )
70 if ( mExtraDatasets->datasetGroup( i ) )
71 mExtraDatasets->datasetGroup( i )->initialize();
74 mExtraDatasets->updateTemporalCapabilities();
79 QgsMeshDatasetGroupStore::DatasetGroup QgsMeshDatasetGroupStore::datasetGroup(
int index )
const
81 if ( mRegistery.contains( index ) )
82 return mRegistery[index];
84 return DatasetGroup{
nullptr, -1};
89 if ( !mPersistentProvider )
91 return mPersistentProvider->
addDataset( path ) ;
96 if ( !mExtraDatasets && !mLayer )
118 int nativeIndex = mExtraDatasets->addDatasetGroup( group );
119 int groupIndex = registerDatasetGroup( DatasetGroup{mExtraDatasets.get(), nativeIndex} );
120 QList<int> groupIndexes;
121 groupIndexes.append( groupIndex );
122 createDatasetGroupTreeItems( groupIndexes );
123 syncItemToDatasetGroup( groupIndex );
135 for (
int groupIndex : groupIndexes )
136 syncItemToDatasetGroup( groupIndex );
141 return mDatasetGroupTreeRootItem.get();
147 mDatasetGroupTreeRootItem.reset( rootItem->
clone() );
149 mDatasetGroupTreeRootItem.reset();
151 unregisterGroupNotPresentInTree();
156 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
158 return group.first->datasetGroupMetadata( group.second );
165 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
167 return group.first->datasetCount( group.second );
174 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
183 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
192 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
201 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
210 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
219 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
230 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
237 group.first->datasetIndexAtTime( referenceTime, group.second, time, method ).dataset() );
243 int groupIndex )
const
245 const QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
247 return QList<QgsMeshDatasetIndex>();
251 const QList<QgsMeshDatasetIndex> datasetIndexes = group.first->datasetIndexInTimeInterval( referenceTime, group.second, time1, time2 );
253 QList<QgsMeshDatasetIndex> ret;
254 ret.reserve( datasetIndexes.count() );
264 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
265 if ( !group.first || group.second < 0 )
270 if ( group.first == mPersistentProvider )
272 else if ( group.first == mExtraDatasets.get() )
273 return mExtraDatasets->datasetRelativeTime( nativeIndex );
282 ( mExtraDatasets && mExtraDatasets->hasTemporalCapabilities() );
288 QDomElement storeElement = doc.createElement( QStringLiteral(
"mesh-dataset-groups-store" ) );
289 storeElement.appendChild( mDatasetGroupTreeRootItem->writeXml( doc, context ) );
291 QMap < int, DatasetGroup>::const_iterator it = mRegistery.constBegin();
292 while ( it != mRegistery.constEnd() )
294 QDomElement elemDataset;
295 if ( it.value().first == mPersistentProvider )
297 elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
298 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
299 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"persitent-provider" ) );
300 elemDataset.setAttribute( QStringLiteral(
"source-index" ), it.value().second );
302 else if ( it.value().first == mExtraDatasets.get() )
307 elemDataset = mExtraDatasets->writeXml( it.value().second, doc, context );
308 if ( !elemDataset.isNull() )
309 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
313 if ( !elemDataset.isNull() )
314 storeElement.appendChild( elemDataset );
325 QDomElement datasetElem = storeElem.firstChildElement(
"mesh-dataset" );
326 QMap<int, QgsMeshDatasetGroup *> extraDatasetGroups;
327 while ( !datasetElem.isNull() )
329 int globalIndex = datasetElem.attribute( QStringLiteral(
"global-index" ) ).toInt();
330 int sourceIndex = -1;
332 const QString sourceType = datasetElem.attribute( QStringLiteral(
"source-type" ) );
333 if ( sourceType == QLatin1String(
"persitent-provider" ) )
335 source = mPersistentProvider;
336 sourceIndex = datasetElem.attribute( QStringLiteral(
"source-index" ) ).toInt();
337 mPersistentExtraDatasetGroupIndexes.append( globalIndex );
339 else if ( sourceType == QLatin1String(
"virtual" ) )
341 source = mExtraDatasets.get();
342 QString name = datasetElem.attribute( QStringLiteral(
"name" ) );
343 QString formula = datasetElem.attribute( QStringLiteral(
"formula" ) );
344 qint64 startTime = datasetElem.attribute( QStringLiteral(
"start-time" ) ).toLongLong();
345 qint64 endTime = datasetElem.attribute( QStringLiteral(
"end-time" ) ).toLongLong();
348 extraDatasetGroups[globalIndex] = dsg;
349 sourceIndex = mExtraDatasets->addDatasetGroup( dsg );
353 QgsDebugMsg( QStringLiteral(
"Unhandled source-type: %1." ).arg( sourceType ) );
357 mRegistery[globalIndex] = DatasetGroup{source, sourceIndex};
360 datasetElem = datasetElem.nextSiblingElement( QStringLiteral(
"mesh-dataset" ) );
363 QDomElement rootTreeItemElem = storeElem.firstChildElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
364 if ( !rootTreeItemElem.isNull() )
373 for ( QMap<int, DatasetGroup>::const_iterator it = mRegistery.cbegin(); it != mRegistery.cend(); ++it )
375 if ( it.value().first == source && it.value().second == nativeGroupIndex )
384 DatasetGroup group = datasetGroup( groupIndex );
387 if ( group.first && group.second >= 0 )
388 fail = mPersistentProvider->
persistDatasetGroup( filePath, driver, group.first, group.second );
392 eraseDatasetGroup( group );
393 group.first = mPersistentProvider;
395 mRegistery[groupIndex] = group;
397 if ( mDatasetGroupTreeRootItem )
408 void QgsMeshDatasetGroupStore::onPersistentDatasetAdded(
int count )
410 Q_ASSERT( mPersistentProvider );
414 QList<int> newGroupIndexes;
415 for (
int i = providerBeginIndex; i < providerTotalCount; ++i )
417 if ( i < mPersistentExtraDatasetGroupIndexes.count() )
418 mRegistery[mPersistentExtraDatasetGroupIndexes.at( i )] = DatasetGroup( mPersistentProvider, i );
420 newGroupIndexes.append( registerDatasetGroup( DatasetGroup{mPersistentProvider, i} ) );
423 if ( !newGroupIndexes.isEmpty() )
425 createDatasetGroupTreeItems( newGroupIndexes );
426 mPersistentExtraDatasetGroupIndexes.append( newGroupIndexes );
428 for (
int groupIndex : std::as_const( newGroupIndexes ) )
429 syncItemToDatasetGroup( groupIndex );
435 void QgsMeshDatasetGroupStore::removePersistentProvider()
437 if ( !mPersistentProvider )
442 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
443 while ( it != mRegistery.end() )
445 if ( it.value().first == mPersistentProvider )
446 it = mRegistery.erase( it );
451 mPersistentProvider =
nullptr;
454 int QgsMeshDatasetGroupStore::newIndex()
457 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
458 while ( it != mRegistery.end() )
460 if ( index <= it.key() )
461 index = it.key() + 1;
467 int QgsMeshDatasetGroupStore::registerDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
469 int groupIndex = newIndex();
470 mRegistery[newIndex()] = group;
474 void QgsMeshDatasetGroupStore::eraseDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
476 if ( group.first == mPersistentProvider )
478 else if ( group.first == mExtraDatasets.get() )
479 eraseExtraDataset( group.second );
482 void QgsMeshDatasetGroupStore::eraseExtraDataset(
int indexInExtraStore )
484 mExtraDatasets->removeDatasetGroup( indexInExtraStore );
487 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
488 while ( it != mRegistery.end() )
490 int localIndex = it.value().second;
491 if ( it.value().first == mExtraDatasets.get() && localIndex > indexInExtraStore )
492 it->second = localIndex - 1;
499 QMap < int, DatasetGroup>::const_iterator it = mRegistery.constBegin();
500 while ( it != mRegistery.constEnd() )
502 if ( it.value() == DatasetGroup{source, nativeIndex} )
514 if ( nativeIndexToGroupIndex( source, i ) == -1 )
515 indexes.append( registerDatasetGroup( DatasetGroup{source, i} ) );
517 if ( !indexes.isEmpty() )
518 createDatasetGroupTreeItems( indexes );
520 for (
int globalIndex : mRegistery.keys() )
522 if ( mRegistery.value( globalIndex ).first == source )
523 syncItemToDatasetGroup( globalIndex );
527 void QgsMeshDatasetGroupStore::removeUnregisteredItemFromTree()
529 QList<QgsMeshDatasetGroupTreeItem *> itemsToCheck;
530 QList<int> indexItemToRemove;
531 for (
int i = 0; i < mDatasetGroupTreeRootItem->childCount(); ++i )
532 itemsToCheck.append( mDatasetGroupTreeRootItem->child( i ) );
534 while ( !itemsToCheck.isEmpty() )
538 if ( !mRegistery.contains( globalIndex ) )
539 indexItemToRemove.append( globalIndex );
540 for (
int i = 0; i < item->
childCount(); ++i )
541 itemsToCheck.append( item->
child( i ) );
544 for (
int i : indexItemToRemove )
552 void QgsMeshDatasetGroupStore::unregisterGroupNotPresentInTree()
554 if ( !mDatasetGroupTreeRootItem )
560 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
561 while ( it != mRegistery.end() )
563 DatasetGroup datasetGroup = it.value();
564 int globalIndex = it.key();
565 if ( ! mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( globalIndex )
566 && datasetGroup.first != mPersistentProvider )
568 it = mRegistery.erase( it );
569 eraseDatasetGroup( datasetGroup );
576 void QgsMeshDatasetGroupStore::syncItemToDatasetGroup(
int groupIndex )
578 if ( !mDatasetGroupTreeRootItem )
580 DatasetGroup group = datasetGroup( groupIndex );
582 if ( group.first == mPersistentProvider && mPersistentProvider )
588 else if ( group.first == mExtraDatasets.get() )
595 void QgsMeshDatasetGroupStore::createDatasetGroupTreeItems(
const QList<int> &indexes )
597 QMap<QString, QgsMeshDatasetGroupTreeItem *> mNameToItem;
599 for (
int i = 0; i < indexes.count(); ++i )
601 int groupIndex = indexes.at( i );
603 const QString name = meta.
name();
604 const QStringList subdatasets = name.split(
'/' );
606 QString displayName = name;
609 if ( subdatasets.size() == 2 )
611 auto it = mNameToItem.find( subdatasets[0] );
612 if ( it == mNameToItem.end() )
613 QgsDebugMsg( QStringLiteral(
"Unable to find parent group for %1." ).arg( name ) );
616 displayName = subdatasets[1];
620 else if ( subdatasets.size() != 1 )
621 QgsDebugMsg( QStringLiteral(
"Ignoring too deep child group name %1." ).arg( name ) );
625 if ( mNameToItem.contains( name ) )
626 QgsDebugMsg( QStringLiteral(
"Group %1 is not unique" ).arg( displayName ) );
627 mNameToItem[name] = item;
633 int groupIndex = mGroups.size();
634 mGroups.push_back( std::unique_ptr<QgsMeshDatasetGroup>(
datasetGroup ) );
643 return mGroups.size() - 1;
649 mGroups.erase( mGroups.begin() + index );
667 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
668 return mGroups.at( groupIndex )->description();
675 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
676 return mGroups[groupIndex].get();
689 return QStringList();
694 return mGroups.size();
700 return mGroups.at( groupIndex )->datasetCount();
708 return mGroups.at( groupIndex )->groupMetadata();
715 int groupIndex = index.
group();
718 int datasetIndex = index.
dataset();
728 int groupIndex = index.
group();
732 int datasetIndex = index.
dataset();
742 int groupIndex = index.
group();
746 int datasetIndex = index.
dataset();
758 Q_UNUSED( faceIndex )
765 int groupIndex = index.
group();
769 int datasetIndex = index.
dataset();
779 int groupIndex = index.
group();
783 int datasetIndex = index.
dataset();
791 const QString &outputDriver,
793 const QVector<QgsMeshDataBlock> &datasetValues,
794 const QVector<QgsMeshDataBlock> &datasetActive,
795 const QVector<double> × )
797 Q_UNUSED( outputFilePath )
798 Q_UNUSED( outputDriver )
801 Q_UNUSED( datasetActive )
807 const QString &outputDriver,
809 int datasetGroupIndex )
811 Q_UNUSED( outputFilePath )
812 Q_UNUSED( outputDriver )
814 Q_UNUSED( datasetGroupIndex )
820 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) && mGroups[groupIndex] )
821 return mGroups[groupIndex]->writeXml( doc, context );
823 return QDomElement();
830 bool hasTemporal =
false;
831 for (
size_t g = 0; g < mGroups.size(); ++g )