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();
79QgsMeshDatasetGroupStore::DatasetGroup QgsMeshDatasetGroupStore::datasetGroup(
int index )
const
81 return mRegistery.value( index, DatasetGroup{
nullptr, -1} );
86 if ( !mPersistentProvider )
88 return mPersistentProvider->
addDataset( path ) ;
93 if ( !mExtraDatasets && !mLayer )
115 int nativeIndex = mExtraDatasets->addDatasetGroup( group );
116 int groupIndex = registerDatasetGroup( DatasetGroup{mExtraDatasets.get(), nativeIndex} );
118 if ( groupIndex == -1 )
121 QList<int> groupIndexes;
122 groupIndexes.append( groupIndex );
123 createDatasetGroupTreeItems( groupIndexes );
124 syncItemToDatasetGroup( groupIndex );
136 for (
int groupIndex : groupIndexes )
137 syncItemToDatasetGroup( groupIndex );
142 return mDatasetGroupTreeRootItem.get();
148 mDatasetGroupTreeRootItem.reset( rootItem->
clone() );
150 mDatasetGroupTreeRootItem.reset();
152 unregisterGroupNotPresentInTree();
157 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
159 return group.first->datasetGroupMetadata( group.second );
166 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
168 return group.first->datasetCount( group.second );
175 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
184 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
193 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
202 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
211 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
220 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
231 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
238 group.first->datasetIndexAtTime( referenceTime, group.second, time, method ).dataset() );
244 int groupIndex )
const
246 const QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
248 return QList<QgsMeshDatasetIndex>();
252 const QList<QgsMeshDatasetIndex> datasetIndexes = group.first->datasetIndexInTimeInterval( referenceTime, group.second, time1, time2 );
254 QList<QgsMeshDatasetIndex> ret;
255 ret.reserve( datasetIndexes.count() );
265 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
266 if ( !group.first || group.second < 0 )
271 if ( group.first == mPersistentProvider )
273 else if ( group.first == mExtraDatasets.get() )
274 return mExtraDatasets->datasetRelativeTime( nativeIndex );
283 ( mExtraDatasets && mExtraDatasets->hasTemporalCapabilities() );
289 QDomElement storeElement = doc.createElement( QStringLiteral(
"mesh-dataset-groups-store" ) );
290 storeElement.appendChild( mDatasetGroupTreeRootItem->writeXml( doc, context ) );
292 QMap < int, DatasetGroup>::const_iterator it = mRegistery.constBegin();
293 while ( it != mRegistery.constEnd() )
295 QDomElement elemDataset;
296 if ( it.value().first == mPersistentProvider )
298 elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
299 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
300 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"persitent-provider" ) );
301 elemDataset.setAttribute( QStringLiteral(
"source-index" ), it.value().second );
303 else if ( it.value().first == mExtraDatasets.get() )
308 elemDataset = mExtraDatasets->writeXml( it.value().second, doc, context );
309 if ( !elemDataset.isNull() )
310 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
314 if ( !elemDataset.isNull() )
315 storeElement.appendChild( elemDataset );
319 for (
auto it = mGroupNameToGlobalIndex.constBegin(); it != mGroupNameToGlobalIndex.constEnd(); ++it )
321 QDomElement elemNameToIndex = doc.createElement( QStringLiteral(
"name-to-global-index" ) );
322 elemNameToIndex.setAttribute( QStringLiteral(
"name" ), it.key() );
323 elemNameToIndex.setAttribute( QStringLiteral(
"global-index" ), it.value() );
325 storeElement.appendChild( elemNameToIndex );
335 QDomElement datasetElem = storeElem.firstChildElement(
"mesh-dataset" );
336 QMap<int, QgsMeshDatasetGroup *> extraDatasetGroups;
337 while ( !datasetElem.isNull() )
339 int globalIndex = datasetElem.attribute( QStringLiteral(
"global-index" ) ).toInt();
341 const QString sourceType = datasetElem.attribute( QStringLiteral(
"source-type" ) );
342 if ( sourceType == QLatin1String(
"persitent-provider" ) )
344 mPersistentExtraDatasetGroupIndexes.append( globalIndex );
346 else if ( sourceType == QLatin1String(
"virtual" ) )
349 QString name = datasetElem.attribute( QStringLiteral(
"name" ) );
350 QString formula = datasetElem.attribute( QStringLiteral(
"formula" ) );
351 qint64 startTime = datasetElem.attribute( QStringLiteral(
"start-time" ) ).toLongLong();
352 qint64 endTime = datasetElem.attribute( QStringLiteral(
"end-time" ) ).toLongLong();
355 extraDatasetGroups[globalIndex] = dsg;
356 int sourceIndex = mExtraDatasets->addDatasetGroup( dsg );
358 mRegistery[globalIndex] = DatasetGroup{source, sourceIndex};
362 QgsDebugMsg( QStringLiteral(
"Unhandled source-type: %1." ).arg( sourceType ) );
365 datasetElem = datasetElem.nextSiblingElement( QStringLiteral(
"mesh-dataset" ) );
368 QDomElement nameToIndexElem = storeElem.firstChildElement(
"name-to-global-index" );
369 mGroupNameToGlobalIndex.clear();
370 while ( !nameToIndexElem.isNull() )
372 QString name = nameToIndexElem.attribute( QStringLiteral(
"name" ) );
373 int globalIndex = nameToIndexElem.attribute( QStringLiteral(
"global-index" ) ).toInt();
375 mGroupNameToGlobalIndex.insert( name, globalIndex );
377 nameToIndexElem = nameToIndexElem.nextSiblingElement( QStringLiteral(
"name-to-global-index" ) );
380 QDomElement rootTreeItemElem = storeElem.firstChildElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
381 if ( !rootTreeItemElem.isNull() )
390 for ( QMap<int, DatasetGroup>::const_iterator it = mRegistery.cbegin(); it != mRegistery.cend(); ++it )
392 if ( it.value().first == source && it.value().second == nativeGroupIndex )
401 DatasetGroup group = datasetGroup( groupIndex );
404 if ( group.first && group.second >= 0 )
405 fail = mPersistentProvider->
persistDatasetGroup( filePath, driver, group.first, group.second );
409 eraseDatasetGroup( group );
410 group.first = mPersistentProvider;
412 mRegistery[groupIndex] = group;
414 if ( mDatasetGroupTreeRootItem )
425void QgsMeshDatasetGroupStore::onPersistentDatasetAdded(
int count )
427 Q_ASSERT( mPersistentProvider );
431 QList<int> newGroupIndexes;
432 for (
int i = providerBeginIndex; i < providerTotalCount; ++i )
435 if ( mGroupNameToGlobalIndex.empty() && i < mPersistentExtraDatasetGroupIndexes.count() )
438 mRegistery[mPersistentExtraDatasetGroupIndexes.at( i )] = DatasetGroup( mPersistentProvider, i );
440 else if ( mGroupNameToGlobalIndex.contains( groupName ) )
443 registerDatasetGroup( DatasetGroup{mPersistentProvider, i} );
447 int newGroupIndex = registerDatasetGroup( DatasetGroup{mPersistentProvider, i} );
448 if ( newGroupIndex != -1 )
449 newGroupIndexes.append( newGroupIndex );
453 if ( !newGroupIndexes.isEmpty() )
455 createDatasetGroupTreeItems( newGroupIndexes );
456 mPersistentExtraDatasetGroupIndexes.append( newGroupIndexes );
458 for (
int groupIndex : std::as_const( newGroupIndexes ) )
459 syncItemToDatasetGroup( groupIndex );
465void QgsMeshDatasetGroupStore::removePersistentProvider()
467 if ( !mPersistentProvider )
472 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
473 while ( it != mRegistery.end() )
475 if ( it.value().first == mPersistentProvider )
476 it = mRegistery.erase( it );
481 mPersistentProvider =
nullptr;
484int QgsMeshDatasetGroupStore::newIndex()
486 QSet usedIndex = qgis::listToSet( mRegistery.keys() );
487 usedIndex.unite( qgis::listToSet( mGroupNameToGlobalIndex.values() ) );
490 while ( usedIndex.contains( index ) )
496int QgsMeshDatasetGroupStore::registerDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
498 const QString &name = group.first->datasetGroupMetadata( group.second ).name();
499 auto it = mGroupNameToGlobalIndex.find( name );
502 if ( it != mGroupNameToGlobalIndex.end() )
504 groupIndex = it.value();
506 if ( mRegistery.contains( groupIndex ) )
508 QgsDebugMsg( QStringLiteral(
"Dupplicate group name for %1." ).arg( name ) );
514 groupIndex = newIndex();
515 mGroupNameToGlobalIndex.insert( name, groupIndex );
518 mRegistery[groupIndex] = group;
522void QgsMeshDatasetGroupStore::eraseDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
524 if ( group.first == mPersistentProvider )
526 else if ( group.first == mExtraDatasets.get() )
527 eraseExtraDataset( group.second );
530void QgsMeshDatasetGroupStore::eraseExtraDataset(
int indexInExtraStore )
532 mExtraDatasets->removeDatasetGroup( indexInExtraStore );
535 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
536 while ( it != mRegistery.end() )
538 int localIndex = it.value().second;
539 if ( it.value().first == mExtraDatasets.get() && localIndex > indexInExtraStore )
540 it->second = localIndex - 1;
552 if ( globalIndex == -1 )
553 globalIndex = registerDatasetGroup( DatasetGroup{source, i} );
555 if ( globalIndex != - 1 )
556 indexes.append( globalIndex );
559 if ( !indexes.isEmpty() )
560 createDatasetGroupTreeItems( indexes );
562 const QList<int> globalIndexes = mRegistery.keys();
563 for (
int globalIndex : globalIndexes )
565 if ( mRegistery.value( globalIndex ).first == source )
566 syncItemToDatasetGroup( globalIndex );
570void QgsMeshDatasetGroupStore::removeUnregisteredItemFromTree()
572 QList<QgsMeshDatasetGroupTreeItem *> itemsToCheck;
573 QList<int> indexItemToRemove;
574 for (
int i = 0; i < mDatasetGroupTreeRootItem->childCount(); ++i )
575 itemsToCheck.append( mDatasetGroupTreeRootItem->child( i ) );
577 while ( !itemsToCheck.isEmpty() )
581 if ( !mRegistery.contains( globalIndex ) )
582 indexItemToRemove.append( globalIndex );
583 for (
int i = 0; i < item->
childCount(); ++i )
584 itemsToCheck.append( item->
child( i ) );
587 for (
int i : indexItemToRemove )
595void QgsMeshDatasetGroupStore::unregisterGroupNotPresentInTree()
597 if ( !mDatasetGroupTreeRootItem )
603 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
604 while ( it != mRegistery.end() )
606 DatasetGroup datasetGroup = it.value();
607 int globalIndex = it.key();
608 if ( ! mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( globalIndex )
609 && datasetGroup.first != mPersistentProvider )
611 it = mRegistery.erase( it );
612 eraseDatasetGroup( datasetGroup );
619void QgsMeshDatasetGroupStore::syncItemToDatasetGroup(
int groupIndex )
621 if ( !mDatasetGroupTreeRootItem )
623 const DatasetGroup group = datasetGroup( groupIndex );
625 if ( group.first == mPersistentProvider && mPersistentProvider )
631 else if ( group.first == mExtraDatasets.get() )
638void QgsMeshDatasetGroupStore::createDatasetGroupTreeItems(
const QList<int> &indexes )
640 QMap<QString, QgsMeshDatasetGroupTreeItem *> mNameToItem;
642 for (
int i = 0; i < indexes.count(); ++i )
644 int groupIndex = indexes.at( i );
645 if ( mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( groupIndex ) )
648 const QString name = meta.
name();
649 const QStringList subdatasets = name.split(
'/' );
651 QString displayName = name;
654 if ( subdatasets.size() == 2 )
656 auto it = mNameToItem.find( subdatasets[0] );
657 if ( it == mNameToItem.end() )
658 QgsDebugMsg( QStringLiteral(
"Unable to find parent group for %1." ).arg( name ) );
661 displayName = subdatasets[1];
665 else if ( subdatasets.size() != 1 )
666 QgsDebugMsg( QStringLiteral(
"Ignoring too deep child group name %1." ).arg( name ) );
670 if ( mNameToItem.contains( name ) )
671 QgsDebugMsg( QStringLiteral(
"Group %1 is not unique" ).arg( displayName ) );
672 mNameToItem[name] = item;
678 int groupIndex = mGroups.size();
679 mGroups.push_back( std::unique_ptr<QgsMeshDatasetGroup>(
datasetGroup ) );
688 return mGroups.size() - 1;
694 mGroups.erase( mGroups.begin() + index );
712 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
713 return mGroups.at( groupIndex )->description();
720 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
721 return mGroups[groupIndex].get();
734 return QStringList();
739 return mGroups.size();
745 return mGroups.at( groupIndex )->datasetCount();
753 return mGroups.at( groupIndex )->groupMetadata();
760 int groupIndex = index.
group();
763 int datasetIndex = index.
dataset();
773 int groupIndex = index.
group();
777 int datasetIndex = index.
dataset();
787 int groupIndex = index.
group();
791 int datasetIndex = index.
dataset();
803 Q_UNUSED( faceIndex )
810 int groupIndex = index.
group();
814 int datasetIndex = index.
dataset();
824 int groupIndex = index.
group();
828 int datasetIndex = index.
dataset();
836 const QString &outputDriver,
838 const QVector<QgsMeshDataBlock> &datasetValues,
839 const QVector<QgsMeshDataBlock> &datasetActive,
840 const QVector<double> × )
842 Q_UNUSED( outputFilePath )
843 Q_UNUSED( outputDriver )
846 Q_UNUSED( datasetActive )
852 const QString &outputDriver,
854 int datasetGroupIndex )
856 Q_UNUSED( outputFilePath )
857 Q_UNUSED( outputDriver )
859 Q_UNUSED( datasetGroupIndex )
865 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) && mGroups[groupIndex] )
866 return mGroups[groupIndex]->writeXml( doc, context );
868 return QDomElement();
875 bool hasTemporal =
false;
876 for (
size_t g = 0; g < mGroups.size(); ++g )
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.
QgsMesh3dDataBlock is a block of 3d stacked mesh data related N faces defined on base mesh frame.
QgsMeshDataBlock is a block of integers/doubles that can be used to retrieve: active flags (e....
QDateTime referenceTime() const
Returns the reference time.
MatchingTemporalDatasetMethod
Method for selection of temporal mesh dataset from a range time.
qint64 datasetTime(const QgsMeshDatasetIndex &index) const
Returns the relative time in milliseconds of the dataset.
Base class for providing data for QgsMeshLayer.
void datasetGroupsAdded(int count)
Emitted when some new dataset groups have been added.
QgsMeshDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
QgsMeshDatasetGroupTreeItem * datasetGroupTreeItem() const
Returns a pointer to the root of the dataset groups tree item.
QgsMeshDatasetMetadata datasetMetadata(const QgsMeshDatasetIndex &index) const
Returns the metadata of the dataset with global index.
void setDatasetGroupTreeItem(const QgsMeshDatasetGroupTreeItem *rootItem)
Sets the root of the dataset groups tree item.
QList< int > enabledDatasetGroupIndexes() const
Returns a list of all group indexes that are enabled.
bool addPersistentDatasets(const QString &path)
Adds persistent datasets from a file with path.
QgsMeshDatasetGroupMetadata datasetGroupMetadata(const QgsMeshDatasetIndex &index) const
Returns the metadata of the dataset group with global index.
bool isFaceActive(const QgsMeshDatasetIndex &index, int faceIndex) const
Returns whether face is active for particular dataset.
QList< int > datasetGroupIndexes() const
Returns a list of all group indexes.
bool hasTemporalCapabilities() const
Returns whether at lea&st one of stored dataset group is temporal.
void resetDatasetGroupTreeItem()
Resets to default state the dataset groups tree item.
QgsMeshDataBlock datasetValues(const QgsMeshDatasetIndex &index, int valueIndex, int count) const
Returns count values of the dataset with global index and from valueIndex.
QgsMesh3dDataBlock dataset3dValues(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns count 3D values of the dataset with global index and from valueIndex.
QgsMeshDatasetIndex datasetIndexAtTime(qint64 time, int groupIndex, QgsMeshDataProviderTemporalCapabilities::MatchingTemporalDatasetMethod method) const
Returns the global dataset index of the dataset int the dataset group with groupIndex,...
bool saveDatasetGroup(QString filePath, int groupIndex, QString driver)
Saves on a file with filePath the dataset groups index with groupIndex with the specified driver.
QList< QgsMeshDatasetIndex > datasetIndexInTimeInterval(qint64 time1, qint64 time2, int groupIndex) const
Returns the global dataset index of the dataset int the dataset group with groupIndex,...
bool addDatasetGroup(QgsMeshDatasetGroup *group)
Adds a extra dataset group, take ownership, returns True if the group is effectivly added.
QgsMeshDatasetValue datasetValue(const QgsMeshDatasetIndex &index, int valueIndex) const
Returns the value of the dataset with global index and valueIndex.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context)
Writes the store's information in a DOM document.
int extraDatasetGroupCount() const
Returns the count of extra dataset groups.
int datasetGroupCount() const
Returns the count of dataset groups.
QgsMeshDatasetGroupStore(QgsMeshLayer *layer)
Constructor.
QgsMeshDataBlock areFacesActive(const QgsMeshDatasetIndex &index, int faceIndex, int count) const
Returns whether faces are active for particular dataset.
void setPersistentProvider(QgsMeshDataProvider *provider, const QStringList &extraDatasetUri)
Sets the persistent mesh data provider with the path of its extra dataset to be loaded by the provide...
qint64 datasetRelativeTime(const QgsMeshDatasetIndex &index) const
Returns the relative time of the dataset from the persistent provider reference time.
int datasetCount(int groupIndex) const
Returns the total count of dataset group in the store.
void readXml(const QDomElement &storeElem, const QgsReadWriteContext &context)
Reads the store's information from a DOM document.
int globalDatasetGroupIndexInSource(QgsMeshDatasetSourceInterface *source, int nativeGroupIndex) const
Returns the global dataset group index of the dataset group with native index nativeGroupIndex in the...
void datasetGroupsAdded(QList< int > indexes)
Emitted after dataset groups are added.
Tree item for display of the mesh dataset groups.
QgsMeshDatasetGroupTreeItem * clone() const
Clones the item.
void setPersistentDatasetGroup(const QString &uri)
Set parameters of the item in accordance with the persistent dataset group with uri.
int childCount() const
Returns the count of children.
int datasetGroupIndex() const
QgsMeshDatasetGroupTreeItem * parentItem() const
Returns the parent item, nullptr if it is root item.
void removeChild(QgsMeshDatasetGroupTreeItem *item)
Removes a item child if exists.
void setDatasetGroup(QgsMeshDatasetGroup *datasetGroup)
Set parameters of the item in accordance with the dataset group.
void appendChild(QgsMeshDatasetGroupTreeItem *item)
Appends a child item.
QgsMeshDatasetGroupTreeItem * child(int row) const
Returns a child.
Abstract class that represents a dataset group.
bool isScalar() const
Returns whether the group contain scalar values.
bool checkValueCountPerDataset(int count) const
Returns whether all the datasets contain count values.
virtual QgsMeshDatasetMetadata datasetMetadata(int datasetIndex) const =0
Returns the metadata of the dataset with index datasetIndex.
QgsMeshDatasetGroupMetadata::DataType dataType() const
Returns the data type of the dataset group.
virtual int datasetCount() const =0
Returns the count of datasets in the group.
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
QgsMeshDatasetIndex is index that identifies the dataset group (e.g.
bool isValid() const
Returns whether index is valid, ie at least groups is set.
int group() const
Returns a group index.
int dataset() const
Returns a dataset index within group()
Interface for mesh datasets and dataset groups.
virtual Q_DECL_DEPRECATED bool persistDatasetGroup(const QString &path, const QgsMeshDatasetGroupMetadata &meta, const QVector< QgsMeshDataBlock > &datasetValues, const QVector< QgsMeshDataBlock > &datasetActive, const QVector< double > ×)
Creates a new dataset group from a data and persists it into a destination path.
virtual QgsMeshDatasetGroupMetadata datasetGroupMetadata(int groupIndex) const =0
Returns dataset group metadata.
virtual int datasetGroupCount() const =0
Returns number of datasets groups loaded.
std::unique_ptr< QgsMeshDataProviderTemporalCapabilities > mTemporalCapabilities
virtual bool addDataset(const QString &uri)=0
Associate dataset with the mesh.
QgsMeshDatasetValue represents single dataset value.
virtual QgsMeshDataBlock datasetValues(bool isScalar, int valueIndex, int count) const =0
Returns count values from valueIndex.
virtual bool isActive(int faceIndex) const =0
Returns whether the face is active.
virtual QgsMeshDataBlock areFacesActive(int faceIndex, int count) const =0
Returns whether faces are active.
virtual QgsMeshDatasetValue datasetValue(int valueIndex) const =0
Returns the value with index valueIndex.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
int meshFaceCount() const
Returns the faces count of the mesh frame.
int meshEdgeCount() const
Returns the edges count of the mesh frame.
int meshVertexCount() const
Returns the vertices count of the mesh frame.
Represents a dataset group calculated from a formula string.
The class is used as a container of context for various read/write operations on other objects.
#define INVALID_MESHLAYER_TIME