]> khamidou — GitHub mirrors - tt.git/commitdiff
added a delete function
authorkhamidou <khamidou@gmail.com>
Sat, 23 Jul 2011 07:38:39 +0000 (09:38 +0200)
committerkhamidou <khamidou@gmail.com>
Sat, 23 Jul 2011 07:38:39 +0000 (09:38 +0200)
mainwindow.cpp
mainwindow.h

index 489d213a91ab34bdc9e85897d3c919f9a5e318be..8d30932eb2358bad8b93a08fd0a6caf31c384c13 100644 (file)
@@ -42,18 +42,24 @@ void MainWindow::createActions()
 {
     newEntry = new QAction(QIcon("./icons/new.png"), tr("&New"), this);
     newEntry->setShortcuts(QKeySequence::New);
-
+    newEntry->setStatusTip(tr("Create a new entry"));
     connect(newEntry, SIGNAL(triggered()), this, SLOT(insertRow()));
+
+    deleteEntry = new QAction(QIcon("./icons/delete.png"), tr("&Delete"), this);
+    newEntry->setShortcuts(QKeySequence::Delete);
+    connect(deleteEntry, SIGNAL(triggered()), this, SLOT(deleteRows()));
 }
 
 void MainWindow::createToolbar()
 {
     toolBar = addToolBar(tr("New"));
     toolBar->addAction(newEntry);
+    toolBar->addAction(deleteEntry);
 }
 
 void MainWindow::insertRow()
 {
+    qDebug() << "paf";
     QSqlQuery query;
 
     /* FIXME : don't hardcode field numbers */
@@ -61,6 +67,23 @@ void MainWindow::insertRow()
     model->select();
 }
 
+void MainWindow::deleteRows() {
+
+    QItemSelectionModel *selectionModel = tableView->selectionModel();
+    QModelIndexList indexes = selectionModel->selectedIndexes();
+
+    QModelIndex index;
+
+    foreach(index, indexes)   // loop through and remove them
+    {
+            int row = index.row();
+           model->removeRows(row, 1, QModelIndex());
+    }
+
+    model->select();
+    qDebug() << "ho";
+}
+
 MainWindow::~MainWindow()
 {
     closeDb();
index cb6bda2637e70f625347dd32f0cb59fa3e00942b..d1dd511d42f401a1c3f347314592ccbad61394dd 100644 (file)
@@ -17,6 +17,7 @@ public:
 
 public slots:
     void insertRow();
+    void deleteRows();
 
 private:
     void setUpTableView();
@@ -26,7 +27,8 @@ private:
     QTabWidget *tabWidget;
     QTableView *tableView;
     QSqlRelationalTableModel *model;
-    QAction *newEntry;    
+    QAction *newEntry;
+    QAction *deleteEntry;
     QToolBar *toolBar;
 };