changeset 400:32acd578fcba

* Basic implementation of add and remove point in data editor * Improve resilience of frame - real-time - frame round-trip conversions
author Chris Cannam
date Mon, 16 Jun 2008 14:48:42 +0000
parents 80c7dd3c8dce
children 96531861b2f3
files widgets/ModelDataTableDialog.cpp widgets/ModelDataTableDialog.h
diffstat 2 files changed, 33 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/ModelDataTableDialog.cpp	Fri Jun 13 21:09:43 2008 +0000
+++ b/widgets/ModelDataTableDialog.cpp	Mon Jun 16 14:48:42 2008 +0000
@@ -35,7 +35,8 @@
 #include <iostream>
 
 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) :
-    QMainWindow(parent)
+    QMainWindow(parent),
+    m_currentRow(0)
 {
     setWindowTitle(tr("Data Editor"));
 
@@ -52,7 +53,7 @@
     action = new QAction(il.load("datadelete"), tr("Delete Selected Items"), this);
     action->setShortcut(tr("Delete"));
     action->setStatusTip(tr("Delete the selected item or items"));
-    connect(action, SIGNAL(triggered()), this, SLOT(deleteRow()));
+    connect(action, SIGNAL(triggered()), this, SLOT(deleteRows()));
     toolbar->addAction(action);
 
     action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this);
@@ -99,8 +100,12 @@
             this, SLOT(viewClicked(const QModelIndex &)));
     connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
             this, SLOT(viewPressed(const QModelIndex &)));
-    connect(m_table, SIGNAL(executeCommand(Command *)),
-            this, SLOT(executeCommand(Command *)));
+    connect(m_tableView->selectionModel(),
+            SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+            this,
+            SLOT(currentChanged(const QModelIndex &, const QModelIndex &)));
+    connect(m_table, SIGNAL(addCommand(Command *)),
+            this, SLOT(addCommand(Command *)));
 
     QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
     connect(bb, SIGNAL(rejected()), this, SLOT(close()));
@@ -147,13 +152,30 @@
 }
 
 void
-ModelDataTableDialog::insertRow()
+ModelDataTableDialog::currentChanged(const QModelIndex &current,
+                                     const QModelIndex &previous)
 {
+    std::cerr << "ModelDataTableDialog::currentChanged: from "
+              << previous.row() << ", " << previous.column()
+              << " to " << current.row() << ", " << current.column() 
+              << std::endl;
+    m_currentRow = current.row();
 }
 
 void
-ModelDataTableDialog::deleteRow()
+ModelDataTableDialog::insertRow()
 {
+    m_table->insertRow(m_currentRow);
+}
+
+void
+ModelDataTableDialog::deleteRows()
+{
+    // not efficient
+    while (m_tableView->selectionModel()->hasSelection()) {
+        m_table->removeRow
+            (m_tableView->selectionModel()->selection().indexes().begin()->row());
+    }
 }
 
 void
@@ -162,9 +184,8 @@
 }
 
 void
-ModelDataTableDialog::executeCommand(Command *command)
+ModelDataTableDialog::addCommand(Command *command)
 {
-    std::cerr << "ModelDataTableDialog::executeCommand(" << command << ")" << std::endl;
     CommandHistory::getInstance()->addCommand(command, false, true);
 }
 
--- a/widgets/ModelDataTableDialog.h	Fri Jun 13 21:09:43 2008 +0000
+++ b/widgets/ModelDataTableDialog.h	Mon Jun 16 14:48:42 2008 +0000
@@ -37,19 +37,21 @@
 
 public slots:
     void scrollToFrameRequested(unsigned long frame);
-    void executeCommand(Command *);
+    void addCommand(Command *);
 
 protected slots:
     void viewClicked(const QModelIndex &);
     void viewPressed(const QModelIndex &);
+    void currentChanged(const QModelIndex &, const QModelIndex &);
     
     void insertRow();
-    void deleteRow();
+    void deleteRows();
     void editRow();
 
 protected:
     ModelDataTableModel *m_table;
     QTableView *m_tableView;
+    int m_currentRow;
 };
 
 #endif