Skip to content

Commit 84d2376

Browse files
committed
remove index2category and use data
1 parent 3e8e6ba commit 84d2376

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
328328
for ( int row = 0; row < model->rowCount(); ++row )
329329
{
330330
QModelIndex index = model->index( row, 0 );
331+
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
331332
QString name = model->data( index, Qt::DisplayRole ).toString();
332333
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
333334
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
334-
QgsMapLayer::StyleCategory category = model->index2category( index );
335335
QAction *copyAction = new QAction( icon, name, copyStyleMenu );
336336
copyAction->setToolTip( tooltip );
337337
connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} );
@@ -357,10 +357,10 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
357357
for ( int row = 0; row < model->rowCount(); ++row )
358358
{
359359
QModelIndex index = model->index( row, 0 );
360+
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
360361
QString name = model->data( index, Qt::DisplayRole ).toString();
361362
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
362363
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
363-
QgsMapLayer::StyleCategory category = model->index2category( index );
364364
QAction *copyAction = new QAction( icon, name, pasteStyleMenu );
365365
copyAction->setToolTip( tooltip );
366366
connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} );

src/app/qgsmaplayerstylecategoriesmodel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ void QgsMapLayerStyleCategoriesModel::setShowAllCategories( bool showAll )
4545
endResetModel();
4646
}
4747

48-
QgsMapLayer::StyleCategory QgsMapLayerStyleCategoriesModel::index2category( const QModelIndex &index ) const
49-
{
50-
return mCategoryList.at( index.row() );
51-
}
52-
5348
int QgsMapLayerStyleCategoriesModel::rowCount( const QModelIndex & ) const
5449
{
5550
int count = mCategoryList.count();
@@ -68,7 +63,12 @@ QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int ro
6863
if ( !index.isValid() || index.row() >= rowCount() )
6964
return QVariant();
7065

71-
QgsMapLayer::StyleCategory category = index2category( index );
66+
QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() );
67+
68+
if ( role == Qt::UserRole )
69+
{
70+
return category;
71+
}
7272

7373
switch ( category )
7474
{
@@ -226,7 +226,7 @@ bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const Q
226226

227227
if ( role == Qt::CheckStateRole )
228228
{
229-
QgsMapLayer::StyleCategory category = index2category( index );
229+
QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() );
230230
if ( value.value<Qt::CheckState>() == Qt::Checked )
231231
{
232232
mCategories |= category;

src/app/qgsmaplayerstylecategoriesmodel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ class QgsMapLayerStyleCategoriesModel : public QAbstractListModel
3434
//! defines if the model should list the AllStyleCategories entry
3535
void setShowAllCategories( bool showAll );
3636

37-
//! return the category for the given index
38-
QgsMapLayer::StyleCategory index2category( const QModelIndex &index ) const;
39-
4037
int rowCount( const QModelIndex & = QModelIndex() ) const override;
4138
int columnCount( const QModelIndex & = QModelIndex() ) const override;
4239
QVariant data( const QModelIndex &index, int role ) const override;

0 commit comments

Comments
 (0)