Skip to content

Commit 0296c27

Browse files
committed
[fix #19868] fix paste style
1 parent 84d2376 commit 0296c27

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
363363
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
364364
QAction *copyAction = new QAction( icon, name, pasteStyleMenu );
365365
copyAction->setToolTip( tooltip );
366-
connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} );
366+
connect( copyAction, &QAction::triggered, this, [ = ]() {app->pasteStyle( layer, category );} );
367367
pasteStyleMenu->addAction( copyAction );
368368
if ( category == QgsMapLayer::AllStyleCategories )
369369
pasteStyleMenu->addSeparator();

src/app/qgsmaplayerstylecategoriesmodel.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,16 @@ QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int ro
6363
if ( !index.isValid() || index.row() >= rowCount() )
6464
return QVariant();
6565

66-
QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() );
66+
QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() + ( mShowAllCategories ? 0 : 1 ) );
6767

6868
if ( role == Qt::UserRole )
6969
{
7070
return category;
7171
}
72+
if ( role == Qt::CheckStateRole )
73+
{
74+
return mCategories.testFlag( category ) ? Qt::Checked : Qt::Unchecked;
75+
}
7276

7377
switch ( category )
7478
{
@@ -226,7 +230,7 @@ bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const Q
226230

227231
if ( role == Qt::CheckStateRole )
228232
{
229-
QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() );
233+
QgsMapLayer::StyleCategory category = data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
230234
if ( value.value<Qt::CheckState>() == Qt::Checked )
231235
{
232236
mCategories |= category;
@@ -246,5 +250,5 @@ bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const Q
246250

247251
Qt::ItemFlags QgsMapLayerStyleCategoriesModel::flags( const QModelIndex & ) const
248252
{
249-
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
253+
return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
250254
}

0 commit comments

Comments
 (0)