remove index2category and use data

This commit is contained in:
Denis Rouzaud 2018-09-17 10:16:32 -04:00
parent 3e8e6ba9cd
commit 84d2376852
3 changed files with 9 additions and 12 deletions

View File

@ -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 );} );

View File

@ -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;

View File

@ -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;