27 return mRegistery.keys();
32 return mDatasetGroupTreeRootItem->enabledDatasetGroupIndexes();
37 return mRegistery.count();
42 return mExtraDatasets->datasetGroupCount();
53 removePersistentProvider();
54 mPersistentProvider = provider;
55 if ( !mPersistentProvider )
61 QgsMeshDatasetGroupStore::DatasetGroup QgsMeshDatasetGroupStore::datasetGroup(
int index )
const
63 if ( mRegistery.contains( index ) )
64 return mRegistery[index];
66 return DatasetGroup{
nullptr, -1};
71 if ( !mPersistentProvider )
73 return mPersistentProvider->
addDataset( path ) ;
78 if ( !mPersistentProvider || !mExtraDatasets )
100 int nativeIndex = mExtraDatasets->addDatasetGroup( group );
101 int groupIndex = registerDatasetGroup( DatasetGroup{mExtraDatasets.get(), nativeIndex} );
102 QList<int> groupIndexes;
103 groupIndexes.append( groupIndex );
104 createDatasetGroupTreeItems( groupIndexes );
105 syncItemToDatasetGroup( groupIndex );
117 for (
int groupIndex : groupIndexes )
118 syncItemToDatasetGroup( groupIndex );
123 return mDatasetGroupTreeRootItem.get();
129 mDatasetGroupTreeRootItem.reset( rootItem->
clone() );
131 mDatasetGroupTreeRootItem.reset();
133 unregisterGroupNotPresentInTree();
138 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
140 return group.first->datasetGroupMetadata( group.second );
147 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
149 return group.first->datasetCount( group.second );
156 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
165 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
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() );
212 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( groupIndex );
219 group.first->datasetIndexAtTime( referenceTime, group.second, time, method ).dataset() );
224 QgsMeshDatasetGroupStore::DatasetGroup group = datasetGroup( index.
group() );
225 if ( !group.first || group.second < 0 )
230 if ( group.first == mPersistentProvider )
232 else if ( group.first == mExtraDatasets.get() )
233 return mExtraDatasets->datasetRelativeTime( nativeIndex );
242 ( mExtraDatasets && mExtraDatasets->hasTemporalCapabilities() );
248 QDomElement storeElement = doc.createElement( QStringLiteral(
"mesh-dataset-groups-store" ) );
249 storeElement.appendChild( mDatasetGroupTreeRootItem->writeXml( doc, context ) );
251 QMap < int, DatasetGroup>::const_iterator it = mRegistery.begin();
252 while ( it != mRegistery.end() )
254 QDomElement elemDataset;
255 if ( it.value().first == mPersistentProvider )
257 elemDataset = doc.createElement( QStringLiteral(
"mesh-dataset" ) );
258 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
259 elemDataset.setAttribute( QStringLiteral(
"source-type" ), QStringLiteral(
"persitent-provider" ) );
260 elemDataset.setAttribute( QStringLiteral(
"source-index" ), it.value().second );
263 else if ( it.value().first == mExtraDatasets.get() )
268 elemDataset = mExtraDatasets->writeXml( it.value().second, doc, context );
269 if ( !elemDataset.isNull() )
270 elemDataset.setAttribute( QStringLiteral(
"global-index" ), it.key() );
274 if ( !elemDataset.isNull() )
275 storeElement.appendChild( elemDataset );
286 QDomElement datasetElem = storeElem.firstChildElement(
"mesh-dataset" );
287 QMap<int, QgsMeshDatasetGroup *> extraDatasetGroups;
288 while ( !datasetElem.isNull() )
290 int globalIndex = datasetElem.attribute( QStringLiteral(
"global-index" ) ).toInt();
293 if ( datasetElem.attribute( QStringLiteral(
"source-type" ) ) == QLatin1String(
"persitent-provider" ) )
295 source = mPersistentProvider;
296 sourceIndex = datasetElem.attribute( QStringLiteral(
"source-index" ) ).toInt();
298 else if ( datasetElem.attribute( QStringLiteral(
"source-type" ) ) == QLatin1String(
"virtual" ) )
300 source = mExtraDatasets.get();
301 QString name = datasetElem.attribute( QStringLiteral(
"name" ) );
302 QString formula = datasetElem.attribute( QStringLiteral(
"formula" ) );
303 qint64 startTime = datasetElem.attribute( QStringLiteral(
"start-time" ) ).toLongLong();
304 qint64 endTime = datasetElem.attribute( QStringLiteral(
"end-time" ) ).toLongLong();
307 extraDatasetGroups[globalIndex] = dsg;
308 sourceIndex = mExtraDatasets->addDatasetGroup( dsg );
312 mRegistery[globalIndex] = DatasetGroup{source, sourceIndex};
314 datasetElem = datasetElem.nextSiblingElement( QStringLiteral(
"mesh-dataset" ) );
317 QDomElement rootTreeItemElem = storeElem.firstChildElement( QStringLiteral(
"mesh-dataset-group-tree-item" ) );
318 if ( !rootTreeItemElem.isNull() )
321 checkDatasetConsistency( mPersistentProvider );
322 removeUnregisteredItemFromTree();
325 for (
int groupIndex : extraDatasetGroups.keys() )
326 extraDatasetGroups.value( groupIndex )->initialize();
329 mExtraDatasets->updateTemporalCapabilities();
334 DatasetGroup group = datasetGroup( groupIndex );
337 if ( group.first && group.second >= 0 )
338 fail = mPersistentProvider->
persistDatasetGroup( filePath, driver, group.first, group.second );
342 eraseDatasetGroup( group );
343 group.first = mPersistentProvider;
345 mRegistery[groupIndex] = group;
347 if ( mDatasetGroupTreeRootItem )
358 void QgsMeshDatasetGroupStore::onPersistentDatasetAdded(
int count )
360 Q_ASSERT( mPersistentProvider );
364 QList<int> groupIndexes;
365 for (
int i = providerBeginIndex; i < providerTotalCount; ++i )
366 groupIndexes.append( registerDatasetGroup( DatasetGroup{mPersistentProvider, i} ) );
368 createDatasetGroupTreeItems( groupIndexes );
369 for (
int groupIndex : groupIndexes )
370 syncItemToDatasetGroup( groupIndex );
375 void QgsMeshDatasetGroupStore::removePersistentProvider()
377 if ( !mPersistentProvider )
382 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
383 while ( it != mRegistery.end() )
385 if ( it.value().first == mPersistentProvider )
386 it = mRegistery.erase( it );
391 mPersistentProvider =
nullptr;
394 int QgsMeshDatasetGroupStore::newIndex()
397 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
398 while ( it != mRegistery.end() )
400 if ( index <= it.key() )
401 index = it.key() + 1;
407 int QgsMeshDatasetGroupStore::registerDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
409 int groupIndex = newIndex();
410 mRegistery[newIndex()] = group;
414 void QgsMeshDatasetGroupStore::eraseDatasetGroup(
const QgsMeshDatasetGroupStore::DatasetGroup &group )
416 if ( group.first == mPersistentProvider )
418 else if ( group.first == mExtraDatasets.get() )
419 eraseExtraDataset( group.second );
422 void QgsMeshDatasetGroupStore::eraseExtraDataset(
int indexInExtraStore )
424 mExtraDatasets->removeDatasetGroup( indexInExtraStore );
427 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
428 while ( it != mRegistery.end() )
430 int localIndex = it.value().second;
431 if ( it.value().first == mExtraDatasets.get() && localIndex > indexInExtraStore )
432 it->second = localIndex - 1;
439 QMap < int, DatasetGroup>::const_iterator it = mRegistery.begin();
440 while ( it != mRegistery.end() )
442 if ( it.value() == DatasetGroup{source, nativeIndex} )
454 if ( nativeIndexToGroupIndex( source, i ) == -1 )
455 indexes.append( registerDatasetGroup( DatasetGroup{source, i} ) );
457 if ( !indexes.isEmpty() )
458 createDatasetGroupTreeItems( indexes );
459 for (
int index : indexes )
460 syncItemToDatasetGroup( index );
463 void QgsMeshDatasetGroupStore::removeUnregisteredItemFromTree()
465 QList<QgsMeshDatasetGroupTreeItem *> itemsToCheck;
466 QList<int> indexItemToRemove;
467 for (
int i = 0; i < mDatasetGroupTreeRootItem->childCount(); ++i )
468 itemsToCheck.append( mDatasetGroupTreeRootItem->child( i ) );
470 while ( !itemsToCheck.isEmpty() )
474 if ( !mRegistery.contains( globalIndex ) )
475 indexItemToRemove.append( globalIndex );
476 for (
int i = 0; i < item->
childCount(); ++i )
477 itemsToCheck.append( item->
child( i ) );
480 for (
int i : indexItemToRemove )
488 void QgsMeshDatasetGroupStore::unregisterGroupNotPresentInTree()
490 if ( !mDatasetGroupTreeRootItem )
496 QMap < int, DatasetGroup>::iterator it = mRegistery.begin();
497 while ( it != mRegistery.end() )
499 DatasetGroup datasetGroup = it.value();
500 int globalIndex = it.key();
501 if ( ! mDatasetGroupTreeRootItem->childFromDatasetGroupIndex( globalIndex )
502 && datasetGroup.first != mPersistentProvider )
504 it = mRegistery.erase( it );
505 eraseDatasetGroup( datasetGroup );
512 void QgsMeshDatasetGroupStore::syncItemToDatasetGroup(
int groupIndex )
514 if ( !mDatasetGroupTreeRootItem )
516 DatasetGroup group = datasetGroup( groupIndex );
518 if ( group.first == mPersistentProvider && mPersistentProvider )
524 else if ( group.first == mExtraDatasets.get() )
531 void QgsMeshDatasetGroupStore::createDatasetGroupTreeItems(
const QList<int> &indexes )
533 QMap<QString, QgsMeshDatasetGroupTreeItem *> mNameToItem;
535 for (
int i = 0; i < indexes.count(); ++i )
537 int groupIndex = indexes.at( i );
539 const QString name = meta.
name();
540 const QStringList subdatasets = name.split(
'/' );
542 QString displayName = name;
545 if ( subdatasets.size() == 2 )
547 auto it = mNameToItem.find( subdatasets[0] );
548 if ( it == mNameToItem.end() )
549 QgsDebugMsg( QStringLiteral(
"Unable to find parent group for %1." ).arg( name ) );
552 displayName = subdatasets[1];
556 else if ( subdatasets.size() != 1 )
557 QgsDebugMsg( QStringLiteral(
"Ignoring too deep child group name %1." ).arg( name ) );
561 if ( mNameToItem.contains( name ) )
562 QgsDebugMsg( QStringLiteral(
"Group %1 is not unique" ).arg( displayName ) );
563 mNameToItem[name] = item;
569 int groupIndex = mGroups.size();
570 mGroups.push_back( std::unique_ptr<QgsMeshDatasetGroup>(
datasetGroup ) );
579 return mGroups.size() - 1;
585 mGroups.erase( mGroups.begin() + index );
603 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
604 return mGroups.at( groupIndex )->description();
611 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) )
612 return mGroups[groupIndex].get();
625 return QStringList();
630 return mGroups.size();
636 return mGroups.at( groupIndex )->datasetCount();
644 return mGroups.at( groupIndex )->groupMetadata();
651 int groupIndex = index.
group();
654 int datasetIndex = index.
dataset();
664 int groupIndex = index.
group();
668 int datasetIndex = index.
dataset();
678 int groupIndex = index.
group();
682 int datasetIndex = index.
dataset();
694 Q_UNUSED( faceIndex )
701 int groupIndex = index.
group();
705 int datasetIndex = index.
dataset();
715 int groupIndex = index.
group();
719 int datasetIndex = index.
dataset();
727 const QString &outputDriver,
729 const QVector<QgsMeshDataBlock> &datasetValues,
730 const QVector<QgsMeshDataBlock> &datasetActive,
731 const QVector<double> × )
733 Q_UNUSED( outputFilePath )
734 Q_UNUSED( outputDriver )
737 Q_UNUSED( datasetActive )
743 const QString &outputDriver,
745 int datasetGroupIndex )
747 Q_UNUSED( outputFilePath )
748 Q_UNUSED( outputDriver )
750 Q_UNUSED( datasetGroupIndex )
756 if ( groupIndex >= 0 && groupIndex <
int( mGroups.size() ) && mGroups[groupIndex] )
757 return mGroups[groupIndex]->writeXml( doc, context );
759 return QDomElement();
766 bool hasTemporal =
false;
767 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.
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 setPersistentProvider(QgsMeshDataProvider *provider)
Sets the persistent mesh data provider.
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 item child.
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