Skip to content

Commit 05e1629

Browse files
committedSep 15, 2014
Remove colors from scheme list on delete/backspace press
1 parent ec39f08 commit 05e1629

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
 

‎python/gui/qgscolorschemelist.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,9 @@ class QgsColorSchemeList: QTreeView
170170
*/
171171
void copyColors();
172172

173+
protected:
174+
175+
void keyPressEvent( QKeyEvent* event );
176+
173177
};
174178

‎src/gui/qgscolorschemelist.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QColorDialog>
2222
#include <QMimeData>
2323
#include <QClipboard>
24+
#include <QKeyEvent>
2425

2526
//For model testing
2627
//#include "modeltest.h"
@@ -131,6 +132,31 @@ void QgsColorSchemeList::copyColors()
131132
QApplication::clipboard()->setMimeData( mimeData );
132133
}
133134

135+
void QgsColorSchemeList::keyPressEvent( QKeyEvent *event )
136+
{
137+
//listen out for delete/backspace presses and remove selected colors
138+
if (( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) )
139+
{
140+
QList<int> rows;
141+
foreach ( const QModelIndex &index, selectedIndexes() )
142+
{
143+
rows << index.row();
144+
}
145+
//remove duplicates
146+
QList<int> rowsToRemove = QList<int>::fromSet( rows.toSet() );
147+
148+
//remove rows in descending order
149+
qSort( rowsToRemove.begin(), rowsToRemove.end(), qGreater<int>() );
150+
foreach ( const int row, rowsToRemove )
151+
{
152+
mModel->removeRow( row );
153+
}
154+
return;
155+
}
156+
157+
QTreeView::keyPressEvent( event );
158+
}
159+
134160
bool QgsColorSchemeList::importColorsFromGpl( QFile &file )
135161
{
136162
QgsNamedColorList importedColors;

‎src/gui/qgscolorschemelist.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ class GUI_EXPORT QgsColorSchemeList: public QTreeView
211211
*/
212212
void copyColors();
213213

214+
protected:
215+
216+
void keyPressEvent( QKeyEvent* event );
217+
214218
private:
215219
QgsColorScheme* mScheme;
216220
QgsColorSchemeModel* mModel;

0 commit comments

Comments
 (0)
Please sign in to comment.