Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
remove index2category and use data
  • Loading branch information
3nids committed Sep 17, 2018
1 parent 3e8e6ba commit 84d2376
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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 );} );
Expand All @@ -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 );} );
Expand Down
14 changes: 7 additions & 7 deletions src/app/qgsmaplayerstylecategoriesmodel.cpp
Expand Up @@ -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();
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/app/qgsmaplayerstylecategoriesmodel.h
Expand Up @@ -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;
Expand Down

0 comments on commit 84d2376

Please sign in to comment.