Skip to content
Permalink
Browse files

remove index2category and use data

  • Loading branch information
3nids committed Sep 17, 2018
1 parent 3e8e6ba commit 84d2376852348f6d9b5de044cd7d06a7fbd46909
@@ -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;

0 comments on commit 84d2376

Please sign in to comment.
You can’t perform that action at this time.