Mercurial > hg > svgui
comparison widgets/ModelDataTableDialog.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
403:dc32f6e7839b | 404:4075bf03faef |
---|---|
32 #include <QAction> | 32 #include <QAction> |
33 #include <QToolBar> | 33 #include <QToolBar> |
34 | 34 |
35 #include <iostream> | 35 #include <iostream> |
36 | 36 |
37 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) : | 37 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, |
38 QString title, QWidget *parent) : | |
38 QMainWindow(parent), | 39 QMainWindow(parent), |
39 m_currentRow(0), | 40 m_currentRow(0), |
40 m_trackPlayback(false) | 41 m_trackPlayback(true) |
41 { | 42 { |
42 setWindowTitle(tr("Data Editor")); | 43 setWindowTitle(tr("Data Editor")); |
43 | 44 |
44 QToolBar *toolbar = addToolBar(tr("Toolbar")); | 45 QToolBar *toolbar; |
45 | 46 |
47 toolbar = addToolBar(tr("Playback Toolbar")); | |
48 m_playToolbar = toolbar; | |
49 toolbar = addToolBar(tr("Play Mode Toolbar")); | |
50 | |
46 IconLoader il; | 51 IconLoader il; |
47 | 52 |
48 QAction *action = new QAction(il.load("playfollow"), tr("Track Playback"), this); | 53 QAction *action = new QAction(il.load("playfollow"), tr("Track Playback"), this); |
49 action->setStatusTip(tr("Toggle tracking of playback position")); | 54 action->setStatusTip(tr("Toggle tracking of playback position")); |
50 action->setCheckable(true); | 55 action->setCheckable(true); |
56 action->setChecked(m_trackPlayback); | |
51 connect(action, SIGNAL(triggered()), this, SLOT(togglePlayTracking())); | 57 connect(action, SIGNAL(triggered()), this, SLOT(togglePlayTracking())); |
52 toolbar->addAction(action); | 58 toolbar->addAction(action); |
53 | 59 |
54 CommandHistory::getInstance()->registerToolbar(toolbar); | 60 toolbar = addToolBar(tr("Edit Toolbar")); |
55 | 61 |
56 action = new QAction(il.load("datainsert"), tr("Insert New Item"), this); | 62 action = new QAction(il.load("datainsert"), tr("Insert New Item"), this); |
57 action->setShortcut(tr("Insert")); | 63 action->setShortcut(tr("Insert")); |
58 action->setStatusTip(tr("Insert a new item")); | 64 action->setStatusTip(tr("Insert a new item")); |
59 connect(action, SIGNAL(triggered()), this, SLOT(insertRow())); | 65 connect(action, SIGNAL(triggered()), this, SLOT(insertRow())); |
63 action->setShortcut(tr("Delete")); | 69 action->setShortcut(tr("Delete")); |
64 action->setStatusTip(tr("Delete the selected item or items")); | 70 action->setStatusTip(tr("Delete the selected item or items")); |
65 connect(action, SIGNAL(triggered()), this, SLOT(deleteRows())); | 71 connect(action, SIGNAL(triggered()), this, SLOT(deleteRows())); |
66 toolbar->addAction(action); | 72 toolbar->addAction(action); |
67 | 73 |
74 CommandHistory::getInstance()->registerToolbar(toolbar); | |
75 | |
76 /* | |
68 action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this); | 77 action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this); |
69 action->setShortcut(tr("Edit")); | 78 action->setShortcut(tr("Edit")); |
70 action->setStatusTip(tr("Edit the selected item")); | 79 action->setStatusTip(tr("Edit the selected item")); |
71 connect(action, SIGNAL(triggered()), this, SLOT(editRow())); | 80 connect(action, SIGNAL(triggered()), this, SLOT(editRow())); |
72 toolbar->addAction(action); | 81 toolbar->addAction(action); |
82 */ | |
73 | 83 |
74 QFrame *mainFrame = new QFrame; | 84 QFrame *mainFrame = new QFrame; |
75 setCentralWidget(mainFrame); | 85 setCentralWidget(mainFrame); |
76 | 86 |
77 QGridLayout *grid = new QGridLayout; | 87 QGridLayout *grid = new QGridLayout; |
159 | 169 |
160 void | 170 void |
161 ModelDataTableDialog::makeCurrent(int row) | 171 ModelDataTableDialog::makeCurrent(int row) |
162 { | 172 { |
163 int rh = m_tableView->height() / m_tableView->rowHeight(0); | 173 int rh = m_tableView->height() / m_tableView->rowHeight(0); |
164 int topRow = row - rh/2; | 174 int topRow = row - rh/4; |
165 if (topRow < 0) topRow = 0; | 175 if (topRow < 0) topRow = 0; |
166 //!!! should not do any of this if an item in the given row is | 176 |
167 //already current; should not scroll if the current row is already | 177 // should only scroll if the desired row is not currently visible |
168 //visible | 178 |
179 // should only select if no part of the desired row is currently selected | |
180 | |
169 std::cerr << "rh = " << rh << ", row = " << row << ", scrolling to " | 181 std::cerr << "rh = " << rh << ", row = " << row << ", scrolling to " |
170 << topRow << std::endl; | 182 << topRow << std::endl; |
171 m_tableView->scrollTo | 183 |
172 (m_table->getModelIndexForRow(topRow)); | 184 int pos = m_tableView->rowViewportPosition(row); |
173 m_tableView->selectionModel()->setCurrentIndex | 185 |
174 (m_table->getModelIndexForRow(row), | 186 if (pos < 0 || pos >= m_tableView->height() - rh) { |
175 QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | 187 m_tableView->scrollTo(m_table->index(topRow, 0)); |
188 } | |
189 | |
190 bool haveRowSelected = false; | |
191 for (int i = 0; i < m_table->columnCount(); ++i) { | |
192 if (m_tableView->selectionModel()->isSelected(m_table->index(row, i))) { | |
193 haveRowSelected = true; | |
194 break; | |
195 } | |
196 } | |
197 | |
198 if (!haveRowSelected) { | |
199 m_tableView->selectionModel()->setCurrentIndex | |
200 (m_table->index(row, 0), | |
201 QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); | |
202 } | |
176 } | 203 } |
177 | 204 |
178 void | 205 void |
179 ModelDataTableDialog::viewClicked(const QModelIndex &index) | 206 ModelDataTableDialog::viewClicked(const QModelIndex &index) |
180 { | 207 { |