comparison demos/browser/edittableview.d @ 73:7bfd46c330dc

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