27 return mRegistery.keys();
32 return mRegistery.count();
37 return mExtraDatasets->datasetGroupCount();
48 removePersistentProvider();
49 mPersistentProvider = provider;
50 if ( !mPersistentProvider )
56 QgsMeshDatasetGroupStore::DatasetGroup QgsMeshDatasetGroupStore::datasetGroup(
int index )
const
58 if ( mRegistery.contains( index ) )
59 return mRegistery[index];
61 return DatasetGroup{
nullptr, -1};
66 if ( !mPersistentProvider )
68 return mPersistentProvider->
addDataset( path ) ;
73 if ( !mPersistentProvider || !mExtraDatasets )
95 int nativeIndex = mExtraDatasets->addDatasetGroup( group );
96 int groupIndex = registerDatasetGroup( DatasetGroup{mExtraDatasets.get(), nativeIndex} );
97 QList<int> groupIndexes;
98 groupIndexes.append( groupIndex );
99 createDatasetGroupTreeItems( groupIndexes );
100 syncItemToDatasetGroup( groupIndex );
112 for (
int groupIndex : groupIndexes )
113 syncItemToDatasetGroup( groupIndex );
118 return mDatasetGroupTreeRootItem.get();
124 mDatasetGroupTreeRootItem.reset( rootItem->
clone() );
126 mDatasetGroupTreeRootItem.reset();
128 unregisterGroupNotPresentInTree();
133 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
135 return group.first->datasetGroupMetadata( group.second );
142 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
144 return group.first->datasetCount( group.second );
151 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
160 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
169 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
178 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
187 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
196 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
207 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
214 group.first->datasetIndexAtTime( referenceTime, group.second, time, method ).dataset() );
219 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
220 if ( !group.first || group.second < 0 )
225 if ( group.first == mPersistentProvider )
227 else if ( group.first == mExtraDatasets.get() )
228 return mExtraDatasets->datasetRelativeTime( nativeIndex );
237 ( mExtraDatasets && mExtraDatasets->hasTemporalCapabilities() );
243 QDomElement storeElement = doc.createElement( QStringLiteral(
"mesh-dataset-groups-store" ) );
244 storeElement.appendChild( mDatasetGroupTreeRootItem->writeXml( doc, context ) );
246 QMap < int, DatasetGroup>::const_iterator it = mRegistery.begin();
247 while ( it != mRegistery.end() )
249 QDomElement elemDataset;
250 if ( it.value().first == mPersistentProvider )
252 elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
253 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
254 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"persitent-provider" ) );
255 elemDataset.setAttribute( QStringLiteral(
"source-index" ), it.value().second );
258 else if ( it.value().first == mExtraDatasets.get() )
263 elemDataset = mExtraDatasets->writeXml( it.value().second, doc, context );
264 if ( !elemDataset.isNull() )
265 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
269 if ( !elemDataset.isNull() )
270 storeElement.appendChild( elemDataset );
281 QDomElement datasetElem = storeElem.firstChildElement(
"mesh-dataset" );
282 QMap<int, QgsMeshDatasetGroup *> extraDatasetGroups;
283 while ( !datasetElem.isNull() )
285 int globalIndex = datasetElem.attribute( QStringLiteral(
"global-index" ) ).toInt();
288 if ( datasetElem.attribute( QStringLiteral(
"source-type" ) ) == QLatin1String(
"persitent-provider" ) )
290 source = mPersistentProvider;
291 sourceIndex = datasetElem.attribute( QStringLiteral(
"source-index" ) ).toInt();
293 else if ( datasetElem.attribute( QStringLiteral(
"source-type" ) ) == QLatin1String(
"virtual" ) )
295 source = mExtraDatasets.get();
296 QString name = datasetElem.attribute( QStringLiteral(
"name" ) );
297 QString formula = datasetElem.attribute( QStringLiteral(
"formula" ) );
298 qint64 startTime = datasetElem.attribute( QStringLiteral(
"start-time" ) ).toLongLong();
299 qint64 endTime = datasetElem.attribute( QStringLiteral(
"end-time" ) ).toLongLong();
302 extraDatasetGroups[globalIndex] = dsg;
303 sourceIndex = mExtraDatasets->addDatasetGroup( dsg );
307 mRegistery[globalIndex] = DatasetGroup{source, sourceIndex};
309 datasetElem = datasetElem.nextSiblingElement( QStringLiteral(
"mesh-dataset" ) );
312 QDomElement rootTreeItemElem = storeElem.firstChildElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
313 if ( !rootTreeItemElem.isNull() )
316 checkDatasetConsistency( mPersistentProvider );
317 removeUnregisteredItemFromTree();
320 for (
int groupIndex : extraDatasetGroups.keys() )
321 extraDatasetGroups.value( groupIndex )->initialize();
324 mExtraDatasets->updateTemporalCapabilities();
329 DatasetGroup group = datasetGroup( groupIndex );
332 if ( group.first && group.second >= 0 )
333 fail = mPersistentProvider->
persistDatasetGroup( filePath, driver, group.first, group.second );
337 eraseDatasetGroup( group );
338 group.first = mPersistentProvider;
340 mRegistery[groupIndex] = group;
342 if ( mDatasetGroupTreeRootItem )
353 void QgsMeshDatasetGroupStore::onPersistentDatasetAdded(
int count )
355 Q_ASSERT( mPersistentProvider );
359 QList<int> groupIndexes;
360 for (
int i = providerBeginIndex; i < providerTotalCount; ++i )
361 groupIndexes.append( registerDatasetGroup( DatasetGroup{mPersistentProvider, i} ) );
363 createDatasetGroupTreeItems( groupIndexes );
364 for (
int groupIndex : groupIndexes )
365 syncItemToDatasetGroup( groupIndex );
370 void QgsMeshDatasetGroupStore::removePersistentProvider()
372 if ( !mPersistentProvider )
377 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
378 while ( it != mRegistery.end() )
380 if ( it.value().first == mPersistentProvider )
381 it = mRegistery.erase( it );
386 mPersistentProvider =
nullptr;
389 int QgsMeshDatasetGroupStore::newIndex()
392 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
393 while ( it != mRegistery.end() )
395 if ( index <= it.key() )
396 index = it.key() + 1;
402 int QgsMeshDatasetGroupStore::registerDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
404 int groupIndex = newIndex();
405 mRegistery[newIndex()] = group;
409 void QgsMeshDatasetGroupStore::eraseDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
411 if ( group.first == mPersistentProvider )
413 else if ( group.first == mExtraDatasets.get() )
414 eraseExtraDataset( group.second );
417 void QgsMeshDatasetGroupStore::eraseExtraDataset(
int indexInExtraStore )
419 mExtraDatasets->removeDatasetGroup( indexInExtraStore );
422 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
423 while ( it != mRegistery.end() )
425 int localIndex = it.value().second;
426 if ( it.value().first == mExtraDatasets.get() && localIndex > indexInExtraStore )
427 it->second = localIndex - 1;
434 QMap < int, DatasetGroup>::const_iterator it = mRegistery.begin();
435 while ( it != mRegistery.end() )
437 if ( it.value() == DatasetGroup{source, nativeIndex} )
449 if ( nativeIndexToGroupIndex( source, i ) == -1 )
450 indexes.append( registerDatasetGroup( DatasetGroup{source, i} ) );
452 if ( !indexes.isEmpty() )
453 createDatasetGroupTreeItems( indexes );
454 for (
int index : indexes )
455 syncItemToDatasetGroup( index );
458 void QgsMeshDatasetGroupStore::removeUnregisteredItemFromTree()
460 QList<QgsMeshDatasetGroupTreeItem *> itemsToCheck;
461 QList<int> indexItemToRemove;
462 for (
int i = 0; i < mDatasetGroupTreeRootItem->childCount(); ++i )
463 itemsToCheck.append( mDatasetGroupTreeRootItem->child( i ) );
465 while ( !itemsToCheck.isEmpty() )
469 if ( !mRegistery.contains( globalIndex ) )
470 indexItemToRemove.append( globalIndex );
471 for (
int i = 0; i < item->
childCount(); ++i )
472 itemsToCheck.append( item->
child( i ) );
475 for (
int i : indexItemToRemove )
483 void QgsMeshDatasetGroupStore::unregisterGroupNotPresentInTree()
485 if ( !mDatasetGroupTreeRootItem )
491 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
492 while ( it != mRegistery.end() )
494 DatasetGroup datasetGroup = it.value();
495 int globalIndex = it.key();
496 if ( ! mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( globalIndex )
497 && datasetGroup.first != mPersistentProvider )
499 it = mRegistery.erase( it );
500 eraseDatasetGroup( datasetGroup );
507 void QgsMeshDatasetGroupStore::syncItemToDatasetGroup(
int groupIndex )
509 if ( !mDatasetGroupTreeRootItem )
511 DatasetGroup group = datasetGroup( groupIndex );
513 if ( group.first == mPersistentProvider && mPersistentProvider )
519 else if ( group.first == mExtraDatasets.get() )
526 void QgsMeshDatasetGroupStore::createDatasetGroupTreeItems(
const QList<int> &indexes )
528 QMap<QString, QgsMeshDatasetGroupTreeItem *> mNameToItem;
530 for (
int i = 0; i < indexes.count(); ++i )
532 int groupIndex = indexes.at( i );
534 const QString name = meta.
name();
535 const QStringList subdatasets = name.split(
'/' );
537 QString displayName = name;
540 if ( subdatasets.size() == 2 )
542 auto it = mNameToItem.find( subdatasets[0] );
543 if ( it == mNameToItem.end() )
544 QgsDebugMsg( QStringLiteral(
"Unable to find parent group for %1." ).arg( name ) );
547 displayName = subdatasets[1];
551 else if ( subdatasets.size() != 1 )
552 QgsDebugMsg( QStringLiteral(
"Ignoring too deep child group name %1." ).arg( name ) );
556 if ( mNameToItem.contains( name ) )
557 QgsDebugMsg( QStringLiteral(
"Group %1 is not unique" ).arg( displayName ) );
558 mNameToItem[name] = item;
564 int groupIndex = mGroups.size();
565 mGroups.push_back( std::unique_ptr<QgsMeshDatasetGroup>(
datasetGroup ) );
574 return mGroups.size() - 1;
580 mGroups.erase( mGroups.begin() + index );
598 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
599 return mGroups.at( groupIndex )->description();
606 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
607 return mGroups[groupIndex].get();
620 return QStringList();
625 return mGroups.size();
631 return mGroups.at( groupIndex )->datasetCount();
639 return mGroups.at( groupIndex )->groupMetadata();
646 int groupIndex = index.
group();
649 int datasetIndex = index.
dataset();
659 int groupIndex = index.
group();
663 int datasetIndex = index.
dataset();
673 int groupIndex = index.
group();
677 int datasetIndex = index.
dataset();
689 Q_UNUSED( faceIndex )
696 int groupIndex = index.
group();
700 int datasetIndex = index.
dataset();
710 int groupIndex = index.
group();
714 int datasetIndex = index.
dataset();
722 const QString &outputDriver,
724 const QVector<QgsMeshDataBlock> &datasetValues,
725 const QVector<QgsMeshDataBlock> &datasetActive,
726 const QVector<double> × )
728 Q_UNUSED( outputFilePath )
729 Q_UNUSED( outputDriver )
732 Q_UNUSED( datasetActive )
738 const QString &outputDriver,
740 int datasetGroupIndex )
742 Q_UNUSED( outputFilePath )
743 Q_UNUSED( outputDriver )
745 Q_UNUSED( datasetGroupIndex )
751 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) && mGroups[groupIndex] )
752 return mGroups[groupIndex]->writeXml( doc, context );
754 return QDomElement();
761 bool hasTemporal =
false;
762 for (
size_t g = 0; g < mGroups.size(); ++g )