Skip to content
Permalink
Browse files

Remove colors from scheme list on delete/backspace press

  • Loading branch information
nyalldawson committed Sep 15, 2014
1 parent ec39f08 commit 05e16291eaa38b9c00792eeae2cacb99b30940b2
Showing with 34 additions and 0 deletions.
  1. +4 −0 python/gui/qgscolorschemelist.sip
  2. +26 −0 src/gui/qgscolorschemelist.cpp
  3. +4 −0 src/gui/qgscolorschemelist.h
@@ -170,5 +170,9 @@ class QgsColorSchemeList: QTreeView
*/
void copyColors();

protected:

void keyPressEvent( QKeyEvent* event );

};

@@ -21,6 +21,7 @@
#include <QColorDialog>
#include <QMimeData>
#include <QClipboard>
#include <QKeyEvent>

//For model testing
//#include "modeltest.h"
@@ -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;
@@ -211,6 +211,10 @@ class GUI_EXPORT QgsColorSchemeList: public QTreeView
*/
void copyColors();

protected:

void keyPressEvent( QKeyEvent* event );

private:
QgsColorScheme* mScheme;
QgsColorSchemeModel* mModel;

0 comments on commit 05e1629

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