Mercurial > projects > qtd
comparison demos/browser/edittreeview.d @ 73:7bfd46c330dc
more porting
author | mandel |
---|---|
date | Fri, 22 May 2009 10:59:00 +0000 |
parents | 71b382c10ef6 |
children | 37caa90ce503 |
comparison
equal
deleted
inserted
replaced
72:b149ef2cb18b | 73:7bfd46c330dc |
---|---|
40 ****************************************************************************/ | 40 ****************************************************************************/ |
41 | 41 |
42 module edittreeview; | 42 module edittreeview; |
43 | 43 |
44 | 44 |
45 import QtGui.QTreeView; | 45 import qt.gui.QTreeView; |
46 import QtGui.QKeyEvent; | 46 import qt.gui.QKeyEvent; |
47 | |
47 | 48 |
48 class EditTreeView : public QTreeView | 49 class EditTreeView : public QTreeView |
49 { | 50 { |
50 Q_OBJECT | 51 public: |
52 | |
53 this(QWidget parent = null) | |
54 { | |
55 super(parent); | |
56 } | |
57 | |
58 void keyPressEvent(QKeyEvent event) | |
59 { | |
60 if ((event.key() == Qt.Key_Delete || event.key() == Qt.Key_Backspace) && model()) { | |
61 removeOne(); | |
62 } else { | |
63 QAbstractItemView::keyPressEvent(event); | |
64 } | |
65 } | |
51 | 66 |
52 public: | 67 public: |
53 this(QWidget *parent = null) | 68 |
54 { | 69 void removeOne() |
55 super(parent); | 70 { |
71 if (!model()) | |
72 return; | |
73 QModelIndex ci = currentIndex(); | |
74 int row = ci.row(); | |
75 model().removeRow(row, ci.parent()); | |
76 } | |
77 | |
78 void removeAll() | |
79 { | |
80 if (!model()) | |
81 return; | |
82 model().removeRows(0, model().rowCount(rootIndex()), rootIndex()); | |
83 } | |
56 } | 84 } |
57 void keyPressEvent(QKeyEvent *event) | |
58 { | |
59 if ((event.key() == Qt::Key_Delete | |
60 || event.key() == Qt::Key_Backspace) | |
61 && model()) { | |
62 removeOne(); | |
63 } else { | |
64 QAbstractItemView::keyPressEvent(event); | |
65 } | |
66 } | |
67 | |
68 public slots: | |
69 void removeOne() | |
70 { | |
71 if (!model()) | |
72 return; | |
73 QModelIndex ci = currentIndex(); | |
74 int row = ci.row(); | |
75 model().removeRow(row, ci.parent()); | |
76 } | |
77 | |
78 void removeAll() | |
79 { | |
80 if (!model()) | |
81 return; | |
82 model().removeRows(0, model().rowCount(rootIndex()), rootIndex()); | |
83 } | |
84 } |