mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
remove index2category and use data
This commit is contained in:
parent
3e8e6ba9cd
commit
84d2376852
@ -328,10 +328,10 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
||||
for ( int row = 0; row < model->rowCount(); ++row )
|
||||
{
|
||||
QModelIndex index = model->index( row, 0 );
|
||||
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
|
||||
QString name = model->data( index, Qt::DisplayRole ).toString();
|
||||
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
|
||||
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
|
||||
QgsMapLayer::StyleCategory category = model->index2category( index );
|
||||
QAction *copyAction = new QAction( icon, name, copyStyleMenu );
|
||||
copyAction->setToolTip( tooltip );
|
||||
connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} );
|
||||
@ -357,10 +357,10 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
||||
for ( int row = 0; row < model->rowCount(); ++row )
|
||||
{
|
||||
QModelIndex index = model->index( row, 0 );
|
||||
QgsMapLayer::StyleCategory category = model->data( index, Qt::UserRole ).value<QgsMapLayer::StyleCategory>();
|
||||
QString name = model->data( index, Qt::DisplayRole ).toString();
|
||||
QString tooltip = model->data( index, Qt::ToolTipRole ).toString();
|
||||
QIcon icon = model->data( index, Qt::DecorationRole ).value<QIcon>();
|
||||
QgsMapLayer::StyleCategory category = model->index2category( index );
|
||||
QAction *copyAction = new QAction( icon, name, pasteStyleMenu );
|
||||
copyAction->setToolTip( tooltip );
|
||||
connect( copyAction, &QAction::triggered, this, [ = ]() {app->copyStyle( layer, category );} );
|
||||
|
@ -45,11 +45,6 @@ void QgsMapLayerStyleCategoriesModel::setShowAllCategories( bool showAll )
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QgsMapLayer::StyleCategory QgsMapLayerStyleCategoriesModel::index2category( const QModelIndex &index ) const
|
||||
{
|
||||
return mCategoryList.at( index.row() );
|
||||
}
|
||||
|
||||
int QgsMapLayerStyleCategoriesModel::rowCount( const QModelIndex & ) const
|
||||
{
|
||||
int count = mCategoryList.count();
|
||||
@ -68,7 +63,12 @@ QVariant QgsMapLayerStyleCategoriesModel::data( const QModelIndex &index, int ro
|
||||
if ( !index.isValid() || index.row() >= rowCount() )
|
||||
return QVariant();
|
||||
|
||||
QgsMapLayer::StyleCategory category = index2category( index );
|
||||
QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() );
|
||||
|
||||
if ( role == Qt::UserRole )
|
||||
{
|
||||
return category;
|
||||
}
|
||||
|
||||
switch ( category )
|
||||
{
|
||||
@ -226,7 +226,7 @@ bool QgsMapLayerStyleCategoriesModel::setData( const QModelIndex &index, const Q
|
||||
|
||||
if ( role == Qt::CheckStateRole )
|
||||
{
|
||||
QgsMapLayer::StyleCategory category = index2category( index );
|
||||
QgsMapLayer::StyleCategory category = mCategoryList.at( index.row() );
|
||||
if ( value.value<Qt::CheckState>() == Qt::Checked )
|
||||
{
|
||||
mCategories |= category;
|
||||
|
@ -34,9 +34,6 @@ class QgsMapLayerStyleCategoriesModel : public QAbstractListModel
|
||||
//! defines if the model should list the AllStyleCategories entry
|
||||
void setShowAllCategories( bool showAll );
|
||||
|
||||
//! return the category for the given index
|
||||
QgsMapLayer::StyleCategory index2category( const QModelIndex &index ) const;
|
||||
|
||||
int rowCount( const QModelIndex & = QModelIndex() ) const override;
|
||||
int columnCount( const QModelIndex & = QModelIndex() ) const override;
|
||||
QVariant data( const QModelIndex &index, int role ) const override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user