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 ( !mPersistentProvider || !mExtraDatasets )
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() );
242 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
243 if ( !group.first || group.second < 0 )
248 if ( group.first == mPersistentProvider )
250 else if ( group.first == mExtraDatasets.get() )
251 return mExtraDatasets->datasetRelativeTime( nativeIndex );
260 ( mExtraDatasets && mExtraDatasets->hasTemporalCapabilities() );
266 QDomElement storeElement = doc.createElement( QStringLiteral(
"mesh-dataset-groups-store" ) );
267 storeElement.appendChild( mDatasetGroupTreeRootItem->writeXml( doc, context ) );
269 QMap < int, DatasetGroup>::const_iterator it = mRegistery.constBegin();
270 while ( it != mRegistery.constEnd() )
272 QDomElement elemDataset;
273 if ( it.value().first == mPersistentProvider )
275 elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
276 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
277 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"persitent-provider" ) );
278 elemDataset.setAttribute( QStringLiteral(
"source-index" ), it.value().second );
280 else if ( it.value().first == mExtraDatasets.get() )
285 elemDataset = mExtraDatasets->writeXml( it.value().second, doc, context );
286 if ( !elemDataset.isNull() )
287 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
291 if ( !elemDataset.isNull() )
292 storeElement.appendChild( elemDataset );
303 QDomElement datasetElem = storeElem.firstChildElement(
"mesh-dataset" );
304 QMap<int, QgsMeshDatasetGroup *> extraDatasetGroups;
305 while ( !datasetElem.isNull() )
307 int globalIndex = datasetElem.attribute( QStringLiteral(
"global-index" ) ).toInt();
308 int sourceIndex = -1;
310 const QString sourceType = datasetElem.attribute( QStringLiteral(
"source-type" ) );
311 if ( sourceType == QLatin1String(
"persitent-provider" ) )
313 source = mPersistentProvider;
314 sourceIndex = datasetElem.attribute( QStringLiteral(
"source-index" ) ).toInt();
315 mPersistentExtraDatasetGroupIndexes.append( globalIndex );
317 else if ( sourceType == QLatin1String(
"virtual" ) )
319 source = mExtraDatasets.get();
320 QString name = datasetElem.attribute( QStringLiteral(
"name" ) );
321 QString formula = datasetElem.attribute( QStringLiteral(
"formula" ) );
322 qint64 startTime = datasetElem.attribute( QStringLiteral(
"start-time" ) ).toLongLong();
323 qint64 endTime = datasetElem.attribute( QStringLiteral(
"end-time" ) ).toLongLong();
326 extraDatasetGroups[globalIndex] = dsg;
327 sourceIndex = mExtraDatasets->addDatasetGroup( dsg );
331 QgsDebugMsg( QStringLiteral(
"Unhandled source-type: %1." ).arg( sourceType ) );
335 mRegistery[globalIndex] = DatasetGroup{source, sourceIndex};
338 datasetElem = datasetElem.nextSiblingElement( QStringLiteral(
"mesh-dataset" ) );
341 QDomElement rootTreeItemElem = storeElem.firstChildElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
342 if ( !rootTreeItemElem.isNull() )
349 DatasetGroup group = datasetGroup( groupIndex );
352 if ( group.first && group.second >= 0 )
353 fail = mPersistentProvider->
persistDatasetGroup( filePath, driver, group.first, group.second );
357 eraseDatasetGroup( group );
358 group.first = mPersistentProvider;
360 mRegistery[groupIndex] = group;
362 if ( mDatasetGroupTreeRootItem )
373 void QgsMeshDatasetGroupStore::onPersistentDatasetAdded(
int count )
375 Q_ASSERT( mPersistentProvider );
379 QList<int> newGroupIndexes;
380 for (
int i = providerBeginIndex; i < providerTotalCount; ++i )
382 if ( i < mPersistentExtraDatasetGroupIndexes.count() )
383 mRegistery[mPersistentExtraDatasetGroupIndexes.at( i )] = DatasetGroup( mPersistentProvider, i );
385 newGroupIndexes.append( registerDatasetGroup( DatasetGroup{mPersistentProvider, i} ) );
388 if ( !newGroupIndexes.isEmpty() )
390 createDatasetGroupTreeItems( newGroupIndexes );
391 mPersistentExtraDatasetGroupIndexes.append( newGroupIndexes );
393 for (
int groupIndex : std::as_const( newGroupIndexes ) )
394 syncItemToDatasetGroup( groupIndex );
400 void QgsMeshDatasetGroupStore::removePersistentProvider()
402 if ( !mPersistentProvider )
407 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
408 while ( it != mRegistery.end() )
410 if ( it.value().first == mPersistentProvider )
411 it = mRegistery.erase( it );
416 mPersistentProvider =
nullptr;
419 int QgsMeshDatasetGroupStore::newIndex()
422 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
423 while ( it != mRegistery.end() )
425 if ( index <= it.key() )
426 index = it.key() + 1;
432 int QgsMeshDatasetGroupStore::registerDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
434 int groupIndex = newIndex();
435 mRegistery[newIndex()] = group;
439 void QgsMeshDatasetGroupStore::eraseDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
441 if ( group.first == mPersistentProvider )
443 else if ( group.first == mExtraDatasets.get() )
444 eraseExtraDataset( group.second );
447 void QgsMeshDatasetGroupStore::eraseExtraDataset(
int indexInExtraStore )
449 mExtraDatasets->removeDatasetGroup( indexInExtraStore );
452 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
453 while ( it != mRegistery.end() )
455 int localIndex = it.value().second;
456 if ( it.value().first == mExtraDatasets.get() && localIndex > indexInExtraStore )
457 it->second = localIndex - 1;
464 QMap < int, DatasetGroup>::const_iterator it = mRegistery.constBegin();
465 while ( it != mRegistery.constEnd() )
467 if ( it.value() == DatasetGroup{source, nativeIndex} )
479 if ( nativeIndexToGroupIndex( source, i ) == -1 )
480 indexes.append( registerDatasetGroup( DatasetGroup{source, i} ) );
482 if ( !indexes.isEmpty() )
483 createDatasetGroupTreeItems( indexes );
485 for (
int globalIndex : mRegistery.keys() )
487 if ( mRegistery.value( globalIndex ).first == source )
488 syncItemToDatasetGroup( globalIndex );
492 void QgsMeshDatasetGroupStore::removeUnregisteredItemFromTree()
494 QList<QgsMeshDatasetGroupTreeItem *> itemsToCheck;
495 QList<int> indexItemToRemove;
496 for (
int i = 0; i < mDatasetGroupTreeRootItem->childCount(); ++i )
497 itemsToCheck.append( mDatasetGroupTreeRootItem->child( i ) );
499 while ( !itemsToCheck.isEmpty() )
503 if ( !mRegistery.contains( globalIndex ) )
504 indexItemToRemove.append( globalIndex );
505 for (
int i = 0; i < item->
childCount(); ++i )
506 itemsToCheck.append( item->
child( i ) );
509 for (
int i : indexItemToRemove )
517 void QgsMeshDatasetGroupStore::unregisterGroupNotPresentInTree()
519 if ( !mDatasetGroupTreeRootItem )
525 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
526 while ( it != mRegistery.end() )
528 DatasetGroup datasetGroup = it.value();
529 int globalIndex = it.key();
530 if ( ! mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( globalIndex )
531 && datasetGroup.first != mPersistentProvider )
533 it = mRegistery.erase( it );
534 eraseDatasetGroup( datasetGroup );
541 void QgsMeshDatasetGroupStore::syncItemToDatasetGroup(
int groupIndex )
543 if ( !mDatasetGroupTreeRootItem )
545 DatasetGroup group = datasetGroup( groupIndex );
547 if ( group.first == mPersistentProvider && mPersistentProvider )
553 else if ( group.first == mExtraDatasets.get() )
560 void QgsMeshDatasetGroupStore::createDatasetGroupTreeItems(
const QList<int> &indexes )
562 QMap<QString, QgsMeshDatasetGroupTreeItem *> mNameToItem;
564 for (
int i = 0; i < indexes.count(); ++i )
566 int groupIndex = indexes.at( i );
568 const QString name = meta.
name();
569 const QStringList subdatasets = name.split(
'/' );
571 QString displayName = name;
574 if ( subdatasets.size() == 2 )
576 auto it = mNameToItem.find( subdatasets[0] );
577 if ( it == mNameToItem.end() )
578 QgsDebugMsg( QStringLiteral(
"Unable to find parent group for %1." ).arg( name ) );
581 displayName = subdatasets[1];
585 else if ( subdatasets.size() != 1 )
586 QgsDebugMsg( QStringLiteral(
"Ignoring too deep child group name %1." ).arg( name ) );
590 if ( mNameToItem.contains( name ) )
591 QgsDebugMsg( QStringLiteral(
"Group %1 is not unique" ).arg( displayName ) );
592 mNameToItem[name] = item;
598 int groupIndex = mGroups.size();
599 mGroups.push_back( std::unique_ptr<QgsMeshDatasetGroup>(
datasetGroup ) );
608 return mGroups.size() - 1;
614 mGroups.erase( mGroups.begin() + index );
632 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
633 return mGroups.at( groupIndex )->description();
640 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
641 return mGroups[groupIndex].get();
654 return QStringList();
659 return mGroups.size();
665 return mGroups.at( groupIndex )->datasetCount();
673 return mGroups.at( groupIndex )->groupMetadata();
680 int groupIndex = index.
group();
683 int datasetIndex = index.
dataset();
693 int groupIndex = index.
group();
697 int datasetIndex = index.
dataset();
707 int groupIndex = index.
group();
711 int datasetIndex = index.
dataset();
723 Q_UNUSED( faceIndex )
730 int groupIndex = index.
group();
734 int datasetIndex = index.
dataset();
744 int groupIndex = index.
group();
748 int datasetIndex = index.
dataset();
756 const QString &outputDriver,
758 const QVector<QgsMeshDataBlock> &datasetValues,
759 const QVector<QgsMeshDataBlock> &datasetActive,
760 const QVector<double> × )
762 Q_UNUSED( outputFilePath )
763 Q_UNUSED( outputDriver )
766 Q_UNUSED( datasetActive )
772 const QString &outputDriver,
774 int datasetGroupIndex )
776 Q_UNUSED( outputFilePath )
777 Q_UNUSED( outputDriver )
779 Q_UNUSED( datasetGroupIndex )
785 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) && mGroups[groupIndex] )
786 return mGroups[groupIndex]->writeXml( doc, context );
788 return QDomElement();
795 bool hasTemporal =
false;
796 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.
virtual int vertexCount() const =0
Returns number of vertices in the native mesh.
virtual int edgeCount() const =0
Returns number of edges in the native mesh.
virtual int faceCount() const =0
Returns number of faces in the native mesh.
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.
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.
bool addDatasetGroup(QgsMeshDatasetGroup *group)
Adds a extra dataset group, take ownership.
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 setDatasetGroupTreeItem(QgsMeshDatasetGroupTreeItem *rootItem)
Sets the root of the dataset groups tree item, doesn't take onwnershib but clone the root item.
void setPersistentProvider(QgsMeshDataProvider *provider, const QStringList &extraDatasetUri)
Sets the persistent mesh data provider with the path of its extra dataset.
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.
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.
virtual QgsMeshDataset * dataset(int index) const =0
Returns the dataset with index.
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.
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.
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