changeset 404:4075bf03faef

* Add playback controls to data edit dialog * Make data edit dialog close properly when layer is removed from view * More fixes to playback tracking & selection model in data edit dialog * Remove edit button from data edit dialog for now
author Chris Cannam
date Wed, 18 Jun 2008 15:53:23 +0000
parents dc32f6e7839b
children 7920688d8e70
files widgets/ModelDataTableDialog.cpp widgets/ModelDataTableDialog.h
diffstat 2 files changed, 46 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/ModelDataTableDialog.cpp	Wed Jun 18 14:34:13 2008 +0000
+++ b/widgets/ModelDataTableDialog.cpp	Wed Jun 18 15:53:23 2008 +0000
@@ -34,24 +34,30 @@
 
 #include <iostream>
 
-ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) :
+ModelDataTableDialog::ModelDataTableDialog(TabularModel *model,
+                                           QString title, QWidget *parent) :
     QMainWindow(parent),
     m_currentRow(0),
-    m_trackPlayback(false)
+    m_trackPlayback(true)
 {
     setWindowTitle(tr("Data Editor"));
 
-    QToolBar *toolbar = addToolBar(tr("Toolbar"));
+    QToolBar *toolbar;
 
+    toolbar = addToolBar(tr("Playback Toolbar"));
+    m_playToolbar = toolbar;
+    toolbar = addToolBar(tr("Play Mode Toolbar"));
+    
     IconLoader il;
 
     QAction *action = new QAction(il.load("playfollow"), tr("Track Playback"), this);
     action->setStatusTip(tr("Toggle tracking of playback position"));
     action->setCheckable(true);
+    action->setChecked(m_trackPlayback);
     connect(action, SIGNAL(triggered()), this, SLOT(togglePlayTracking()));
     toolbar->addAction(action);
 
-    CommandHistory::getInstance()->registerToolbar(toolbar);
+    toolbar = addToolBar(tr("Edit Toolbar"));
 
     action = new QAction(il.load("datainsert"), tr("Insert New Item"), this);
     action->setShortcut(tr("Insert"));
@@ -65,11 +71,15 @@
     connect(action, SIGNAL(triggered()), this, SLOT(deleteRows()));
     toolbar->addAction(action);
 
+    CommandHistory::getInstance()->registerToolbar(toolbar);
+
+/*
     action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this);
     action->setShortcut(tr("Edit"));
     action->setStatusTip(tr("Edit the selected item"));
     connect(action, SIGNAL(triggered()), this, SLOT(editRow()));
     toolbar->addAction(action);
+*/
 
     QFrame *mainFrame = new QFrame;
     setCentralWidget(mainFrame);
@@ -161,18 +171,35 @@
 ModelDataTableDialog::makeCurrent(int row)
 {
     int rh = m_tableView->height() / m_tableView->rowHeight(0);
-    int topRow = row - rh/2;
+    int topRow = row - rh/4;
     if (topRow < 0) topRow = 0;
-    //!!! should not do any of this if an item in the given row is
-    //already current; should not scroll if the current row is already
-    //visible
+    
+    // should only scroll if the desired row is not currently visible
+
+    // should only select if no part of the desired row is currently selected
+
     std::cerr << "rh = " << rh << ", row = " << row << ", scrolling to "
               << topRow << std::endl;
-    m_tableView->scrollTo
-        (m_table->getModelIndexForRow(topRow));
-    m_tableView->selectionModel()->setCurrentIndex
-        (m_table->getModelIndexForRow(row),
-         QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+
+    int pos = m_tableView->rowViewportPosition(row);
+
+    if (pos < 0 || pos >= m_tableView->height() - rh) {
+        m_tableView->scrollTo(m_table->index(topRow, 0));
+    }
+
+    bool haveRowSelected = false;
+    for (int i = 0; i < m_table->columnCount(); ++i) {
+        if (m_tableView->selectionModel()->isSelected(m_table->index(row, i))) {
+            haveRowSelected = true;
+            break;
+        }
+    }
+
+    if (!haveRowSelected) {
+        m_tableView->selectionModel()->setCurrentIndex
+            (m_table->index(row, 0),
+             QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+    }
 }
 
 void
--- a/widgets/ModelDataTableDialog.h	Wed Jun 18 14:34:13 2008 +0000
+++ b/widgets/ModelDataTableDialog.h	Wed Jun 18 15:53:23 2008 +0000
@@ -23,15 +23,19 @@
 class QTableView;
 class QModelIndex;
 class Command;
+class QToolBar;
 
 class ModelDataTableDialog : public QMainWindow
 {
     Q_OBJECT
     
 public:
-    ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent =0);
+    ModelDataTableDialog(TabularModel *model,
+                         QString title, QWidget *parent =0);
     ~ModelDataTableDialog();
 
+    QToolBar *getPlayToolbar() { return m_playToolbar; }
+
 signals:
     void scrollToFrame(unsigned long frame);
 
@@ -54,6 +58,7 @@
 protected:
     void makeCurrent(int row);
     ModelDataTableModel *m_table;
+    QToolBar *m_playToolbar;
     QTableView *m_tableView;
     int m_currentRow;
     bool m_trackPlayback;