Skip to content

Commit

Permalink
Remove colors from scheme list on delete/backspace press
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 15, 2014
1 parent ec39f08 commit 05e1629
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgscolorschemelist.sip
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,9 @@ class QgsColorSchemeList: QTreeView
*/
void copyColors();

protected:

void keyPressEvent( QKeyEvent* event );

};

26 changes: 26 additions & 0 deletions src/gui/qgscolorschemelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QColorDialog>
#include <QMimeData>
#include <QClipboard>
#include <QKeyEvent>

//For model testing
//#include "modeltest.h"
Expand Down Expand Up @@ -131,6 +132,31 @@ void QgsColorSchemeList::copyColors()
QApplication::clipboard()->setMimeData( mimeData );
}

void QgsColorSchemeList::keyPressEvent( QKeyEvent *event )
{
//listen out for delete/backspace presses and remove selected colors
if (( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) )
{
QList<int> rows;
foreach ( const QModelIndex &index, selectedIndexes() )
{
rows << index.row();
}
//remove duplicates
QList<int> rowsToRemove = QList<int>::fromSet( rows.toSet() );

//remove rows in descending order
qSort( rowsToRemove.begin(), rowsToRemove.end(), qGreater<int>() );
foreach ( const int row, rowsToRemove )
{
mModel->removeRow( row );
}
return;
}

QTreeView::keyPressEvent( event );
}

bool QgsColorSchemeList::importColorsFromGpl( QFile &file )
{
QgsNamedColorList importedColors;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgscolorschemelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ class GUI_EXPORT QgsColorSchemeList: public QTreeView
*/
void copyColors();

protected:

void keyPressEvent( QKeyEvent* event );

private:
QgsColorScheme* mScheme;
QgsColorSchemeModel* mModel;
Expand Down

0 comments on commit 05e1629

Please sign in to comment.