Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global index #4

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core/mesh/qgsmeshdatasetgroupstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ void QgsMeshDatasetGroupStore::readXml( const QDomElement &storeElem, const QgsR
setDatasetGroupTreeItem( new QgsMeshDatasetGroupTreeItem( rootTreeItemElem, context ) );
}

int QgsMeshDatasetGroupStore::globalDatasetGroupIndexInSource( QgsMeshDatasetSourceInterface *source, int nativeGroupIndex ) const
{
for ( QMap<int, DatasetGroup>::const_iterator it = mRegistery.cbegin(); it != mRegistery.cend(); ++it )
{
if ( it.value().first == source && it.value().second == nativeGroupIndex )
return it.key();
}

return -1;
}

bool QgsMeshDatasetGroupStore::saveDatasetGroup( QString filePath, int groupIndex, QString driver )
{
Expand Down
8 changes: 8 additions & 0 deletions src/core/mesh/qgsmeshdatasetgroupstore.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ class QgsMeshDatasetGroupStore: public QObject
//! Reads the store's information from a DOM document
void readXml( const QDomElement &storeElem, const QgsReadWriteContext &context );

/**
* Returns the global dataset group index of the dataset group with native index \a globalGroupIndex in the \a source
* Returns -1 if the group or the source is not registered
*
* Since QGIS 3.22
*/
int globalDatasetGroupIndexInSource( QgsMeshDatasetSourceInterface *source, int nativeGroupIndex ) const;

signals:
//! Emitted after dataset groups are added
void datasetGroupsAdded( QList<int> indexes );
Expand Down
28 changes: 14 additions & 14 deletions src/core/mesh/qgsmeshlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,13 @@ bool QgsMeshLayer::supportsEditing() const

QString QgsMeshLayer::loadDefaultStyle( bool &resultFlag )
{
if ( mDataProvider )
{
for ( int i = 0; i < mDataProvider->datasetGroupCount(); ++i )
assignDefaultStyleToDatasetGroup( i );
const QList<int> groupsList = datasetGroupsIndexes();

for ( const int index : groupsList )
assignDefaultStyleToDatasetGroup( index );

if ( !groupsList.isEmpty() )
{
emit rendererChanged();
emitStyleChanged();
}
Expand Down Expand Up @@ -1713,10 +1715,7 @@ bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvid

mDataProvider->setTemporalUnit( mTemporalUnit );

// temporarily disconnect from datasetGroupsAdded -- we don't want to reset the style for reconnected dataset groups
disconnect( mDatasetGroupStore.get(), &QgsMeshDatasetGroupStore::datasetGroupsAdded, this, &QgsMeshLayer::onDatasetGroupsAdded );
mDatasetGroupStore->setPersistentProvider( mDataProvider, mExtraDatasetUri );
connect( mDatasetGroupStore.get(), &QgsMeshDatasetGroupStore::datasetGroupsAdded, this, &QgsMeshLayer::onDatasetGroupsAdded );

setCrs( mDataProvider->crs() );

Expand All @@ -1726,16 +1725,17 @@ bool QgsMeshLayer::setDataProvider( QString const &provider, const QgsDataProvid
mDataSource = mDataSource + QStringLiteral( "&uid=%1" ).arg( QUuid::createUuid().toString() );
}

if ( flags & QgsDataProvider::FlagLoadDefaultStyle )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to check FlagLoadDefaultStyle -- if it's true we should always reset the style

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, ignore me

// set default style if required by flags or if the dataset group does not has a style yet
for ( int i = 0; i < mDataProvider->datasetGroupCount(); ++i )
{
for ( int i = 0; i < mDataProvider->datasetGroupCount(); ++i )
assignDefaultStyleToDatasetGroup( i );

emit rendererChanged();
emitStyleChanged();
int globalIndex = mDatasetGroupStore->globalDatasetGroupIndexInSource( mDataProvider, i );
if ( globalIndex != -1 &&
( !mRendererSettings.hasSettings( globalIndex ) || ( flags & QgsDataProvider::FlagLoadDefaultStyle ) ) )
assignDefaultStyleToDatasetGroup( globalIndex );
}

temporalProperties()->setIsActive( mDatasetGroupStore->hasTemporalCapabilities() );
emit rendererChanged();
emitStyleChanged();

connect( mDataProvider, &QgsMeshDataProvider::dataChanged, this, &QgsMeshLayer::dataChanged );

Expand Down
4 changes: 4 additions & 0 deletions src/core/mesh/qgsmeshrenderersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,7 @@ void QgsMeshRendererVectorTracesSettings::setParticlesCount( int value )
mParticlesCount = value;
}

bool QgsMeshRendererSettings::hasSettings( int datasetGroupIndex ) const
{
return mRendererScalarSettings.contains( datasetGroupIndex ) || mRendererVectorSettings.contains( datasetGroupIndex );
}
7 changes: 7 additions & 0 deletions src/core/mesh/qgsmeshrenderersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ class CORE_EXPORT QgsMeshRendererSettings
*/
void setActiveVectorDatasetGroup( int activeVectorDatasetGroup );

/**
* Returns whether the group with \a index has render settings (scalar or vector)
*
* \since QGIS 3.22
*/
bool hasSettings( int datasetGroupIndex ) const;

private:
QgsMeshRendererMeshSettings mRendererNativeMeshSettings;
QgsMeshRendererMeshSettings mRendererTriangularMeshSettings;
Expand Down