Skip to content

Commit

Permalink
fix displaying enabled/disable mesh dataset group
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Dec 2, 2020
1 parent feedc1e commit 761831e
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 10 deletions.
13 changes: 11 additions & 2 deletions python/core/auto_generated/mesh/qgsmeshdataset.sip.in
Expand Up @@ -883,9 +883,18 @@ Returns the count of children

int totalChildCount() const;
%Docstring
Returns the total count of children, that is included deeper children
Returns the total count of children, that is included deeper children and disabled items

:return:
:return: the total children's count
%End

QList<int> enabledDatasetGroupIndexes() const;
%Docstring
Returns a list of enabled dataset group indexes, included deeper children

:return: the list of dataset group indexes

.. versionadded:: 3.16.3
%End

QgsMeshDatasetGroupTreeItem *parentItem() const;
Expand Down
12 changes: 12 additions & 0 deletions python/core/auto_generated/mesh/qgsmeshlayer.sip.in
Expand Up @@ -271,6 +271,18 @@ Returns the list of indexes of dataset groups handled by the layer
In the layer scope, those indexes can be different from the data provider indexes.

.. versionadded:: 3.16
%End

QList<int> enabledDatasetGroupsIndexes() const;
%Docstring
Returns the list of indexes of enables dataset groups handled by the layer

.. note::

indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,...)
In the layer scope, those indexes can be different from the data provider indexes.

.. versionadded:: 3.16.3
%End

QgsMeshDatasetGroupMetadata datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const;
Expand Down
14 changes: 14 additions & 0 deletions src/core/mesh/qgsmeshdataset.cpp
Expand Up @@ -590,6 +590,20 @@ int QgsMeshDatasetGroupTreeItem::totalChildCount() const
return count;
}

QList<int> QgsMeshDatasetGroupTreeItem::enabledDatasetGroupIndexes() const
{
QList<int> indexesList;

for ( int i = 0; i < mChildren.count(); ++i )
{
if ( mChildren.at( i )->isEnabled() )
indexesList.append( mChildren.at( i )->datasetGroupIndex() );
indexesList.append( mChildren.at( i )->enabledDatasetGroupIndexes() );
}

return indexesList;
}

QgsMeshDatasetGroupTreeItem *QgsMeshDatasetGroupTreeItem::parentItem() const
{
return mParent;
Expand Down
14 changes: 11 additions & 3 deletions src/core/mesh/qgsmeshdataset.h
Expand Up @@ -866,11 +866,19 @@ class CORE_EXPORT QgsMeshDatasetGroupTreeItem
int childCount() const;

/**
* Returns the total count of children, that is included deeper children
* \return
*/
* Returns the total count of children, that is included deeper children and disabled items
* \return the total children's count
*/
int totalChildCount() const;

/**
* Returns a list of enabled dataset group indexes, included deeper children
* \return the list of dataset group indexes
*
* \since QGIS 3.16.3
*/
QList<int> enabledDatasetGroupIndexes() const;

/**
* Returns the parent item, nullptr if it is root item
* \return the parent item
Expand Down
5 changes: 5 additions & 0 deletions src/core/mesh/qgsmeshdatasetgroupstore.cpp
Expand Up @@ -27,6 +27,11 @@ QList<int> QgsMeshDatasetGroupStore::datasetGroupIndexes() const
return mRegistery.keys();
}

QList<int> QgsMeshDatasetGroupStore::enabledDatasetGroupIndexes() const
{
return mDatasetGroupTreeRootItem->enabledDatasetGroupIndexes();
}

int QgsMeshDatasetGroupStore::datasetGroupCount() const
{
return mRegistery.count();
Expand Down
7 changes: 7 additions & 0 deletions src/core/mesh/qgsmeshdatasetgroupstore.h
Expand Up @@ -156,6 +156,13 @@ class QgsMeshDatasetGroupStore: public QObject
//! Returns a list of all group indexes
QList<int> datasetGroupIndexes() const;

/**
* Returns a list of all group indexes that are enabled
*
* \since QGIS 3.16.3
*/
QList<int> enabledDatasetGroupIndexes() const;

//! Returns the count of dataset groups
int datasetGroupCount() const;

Expand Down
5 changes: 5 additions & 0 deletions src/core/mesh/qgsmeshlayer.cpp
Expand Up @@ -359,6 +359,11 @@ QList<int> QgsMeshLayer::datasetGroupsIndexes() const
return mDatasetGroupStore->datasetGroupIndexes();
}

QList<int> QgsMeshLayer::enabledDatasetGroupsIndexes() const
{
return mDatasetGroupStore->enabledDatasetGroupIndexes();
}

QgsMeshDatasetGroupMetadata QgsMeshLayer::datasetGroupMetadata( const QgsMeshDatasetIndex &index ) const
{
return mDatasetGroupStore->datasetGroupMetadata( index );
Expand Down
10 changes: 10 additions & 0 deletions src/core/mesh/qgsmeshlayer.h
Expand Up @@ -344,6 +344,16 @@ class CORE_EXPORT QgsMeshLayer : public QgsMapLayer
*/
QList<int> datasetGroupsIndexes() const;

/**
* Returns the list of indexes of enables dataset groups handled by the layer
*
* \note indexes are used to distinguish all the dataset groups handled by the layer (from dataprovider, extra dataset group,...)
* In the layer scope, those indexes can be different from the data provider indexes.
*
* \since QGIS 3.16.3
*/
QList<int> enabledDatasetGroupsIndexes() const;

/**
* Returns the dataset groups metadata
*
Expand Down
14 changes: 12 additions & 2 deletions src/gui/mesh/qgsmeshdatasetgrouptreeview.cpp
Expand Up @@ -494,17 +494,22 @@ void QgsMeshActiveDatasetGroupTreeView::setActiveGroup()
setActiveVectorGroup( vectorGroup );
}

QgsMeshDatasetGroupListModel::QgsMeshDatasetGroupListModel( QObject *parent ): QAbstractListModel( parent )
{}

void QgsMeshDatasetGroupListModel::syncToLayer( QgsMeshLayer *layer )
{
beginResetModel();
if ( layer )
mRootItem = layer->datasetGroupTreeRootItem();
endResetModel();
}

int QgsMeshDatasetGroupListModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent );
if ( mRootItem )
return mRootItem->totalChildCount();
return mRootItem->enabledDatasetGroupIndexes().count();
else
return 0;
}
Expand All @@ -517,7 +522,12 @@ QVariant QgsMeshDatasetGroupListModel::data( const QModelIndex &index, int role
if ( index.row() >= rowCount( QModelIndex() ) )
return QVariant();

QgsMeshDatasetGroupTreeItem *item = mRootItem->childFromDatasetGroupIndex( index.row() );
const QList<int> list = mRootItem->enabledDatasetGroupIndexes();
if ( index.row() >= list.count() )
return QVariant();

QgsMeshDatasetGroupTreeItem *item = mRootItem->childFromDatasetGroupIndex( list.at( index.row() ) );

if ( !item )
return QVariant();

Expand Down
3 changes: 1 addition & 2 deletions src/gui/mesh/qgsmeshdatasetgrouptreeview.h
Expand Up @@ -274,8 +274,7 @@ class GUI_EXPORT QgsMeshActiveDatasetGroupTreeView : public QTreeView
class GUI_EXPORT QgsMeshDatasetGroupListModel: public QAbstractListModel
{
public:
explicit QgsMeshDatasetGroupListModel( QObject *parent ): QAbstractListModel( parent )
{}
explicit QgsMeshDatasetGroupListModel( QObject *parent );

//! Add groups to the model from mesh layer
void syncToLayer( QgsMeshLayer *layer );
Expand Down
13 changes: 12 additions & 1 deletion src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -259,6 +259,7 @@ bool QgsMapToolIdentify::identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyRe
int activeScalarGroup = layer->rendererSettings().activeScalarDatasetGroup();
int activeVectorGroup = layer->rendererSettings().activeVectorDatasetGroup();

const QList<int> allGroup = layer->enabledDatasetGroupsIndexes();
if ( isTemporal ) //non active dataset group value are only accesible if temporal is active
{
const QgsDateTimeRange &time = identifyContext.temporalRange();
Expand All @@ -267,7 +268,6 @@ bool QgsMapToolIdentify::identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyRe
if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
datasetIndexList.append( layer->activeVectorDatasetAtTime( time ) );

const QList<int> allGroup = layer->datasetGroupsIndexes();
for ( int groupIndex : allGroup )
{
if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
Expand All @@ -276,10 +276,21 @@ bool QgsMapToolIdentify::identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyRe
}
else
{
// only active dataset group
if ( activeScalarGroup >= 0 )
datasetIndexList.append( layer->staticScalarDatasetIndex() );
if ( activeVectorGroup >= 0 && activeVectorGroup != activeScalarGroup )
datasetIndexList.append( layer->staticVectorDatasetIndex() );

// ...and static dataset group
for ( int groupIndex : allGroup )
{
if ( groupIndex != activeScalarGroup && groupIndex != activeVectorGroup )
{
if ( !layer->datasetGroupMetadata( groupIndex ).isTemporal() )
datasetIndexList.append( groupIndex );
}
}
}

//create results
Expand Down
9 changes: 9 additions & 0 deletions tests/src/core/testqgsmeshlayer.cpp
Expand Up @@ -1301,9 +1301,18 @@ void TestQgsMeshLayer::test_dataset_group_item_tree_item()
QCOMPARE( rootItem->childFromDatasetGroupIndex( i )->name(), names.at( i ) );

// Disable some items
QList<int> enabledList = rootItem->enabledDatasetGroupIndexes();
QCOMPARE( enabledList.count(), 22 );
QList<int> newList = enabledList;
newList.removeOne( 7 );
rootItem->childFromDatasetGroupIndex( 7 )->setIsEnabled( false );
QCOMPARE( newList, rootItem->enabledDatasetGroupIndexes() );
newList.removeOne( 10 );
rootItem->childFromDatasetGroupIndex( 10 )->setIsEnabled( false );
QCOMPARE( newList, rootItem->enabledDatasetGroupIndexes() );
newList.removeOne( 15 );
rootItem->childFromDatasetGroupIndex( 15 )->setIsEnabled( false );
QCOMPARE( newList, rootItem->enabledDatasetGroupIndexes() );

QDomDocument doc;
QgsReadWriteContext context;
Expand Down

0 comments on commit 761831e

Please sign in to comment.