Skip to content

Commit

Permalink
Scroll to newly added entries in paletted renderer widget
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent ad6c46f commit f5a0243
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/gui/raster/qgspalettedrendererwidget.cpp
Expand Up @@ -213,7 +213,9 @@ void QgsPalettedRendererWidget::addEntry()
{
color = ramp->color( 1.0 );
}
mModel->addEntry( color );
QModelIndex newEntry = mModel->addEntry( color );
mTreeView->scrollTo( newEntry );
mTreeView->selectionModel()->select( newEntry, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
connect( mModel, &QgsPalettedRendererModel::classesChanged, this, &QgsPalettedRendererWidget::widgetChanged );
emit widgetChanged();
}
Expand Down Expand Up @@ -785,10 +787,12 @@ bool QgsPalettedRendererModel::dropMimeData( const QMimeData *data, Qt::DropActi
return true;
}

void QgsPalettedRendererModel::addEntry( const QColor &color )
QModelIndex QgsPalettedRendererModel::addEntry( const QColor &color )
{
insertRow( rowCount() );
setData( index( mData.count() - 1, 1 ), color );
QModelIndex newRow = index( mData.count() - 1, 1 );
setData( newRow, color );
return newRow;
}

void QgsPalettedRendererModel::deleteAll()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/raster/qgspalettedrendererwidget.h
Expand Up @@ -160,7 +160,7 @@ class QgsPalettedRendererModel : public QAbstractItemModel
QMimeData *mimeData( const QModelIndexList &indexes ) const override;
bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) override;

void addEntry( const QColor &color );
QModelIndex addEntry( const QColor &color );

public slots:

Expand Down

0 comments on commit f5a0243

Please sign in to comment.