Skip to content

Commit

Permalink
set default style by global group index
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Oct 6, 2021
1 parent b48d7dc commit 3ee6a00
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/core/mesh/qgsmeshdatasetgroupstore.cpp
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
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
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 )
// 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
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
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

0 comments on commit 3ee6a00

Please sign in to comment.