comparison widgets/ModelDataTableDialog.cpp @ 401:96531861b2f3

* a bit of progress on retaining current row when sorting changes &c
author Chris Cannam
date Tue, 17 Jun 2008 16:07:56 +0000
parents 32acd578fcba
children 66e01a6c9554
comparison
equal deleted inserted replaced
400:32acd578fcba 401:96531861b2f3
34 34
35 #include <iostream> 35 #include <iostream>
36 36
37 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) : 37 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QString title, QWidget *parent) :
38 QMainWindow(parent), 38 QMainWindow(parent),
39 m_currentRow(0) 39 m_currentRow(0),
40 m_trackPlayback(false)
40 { 41 {
41 setWindowTitle(tr("Data Editor")); 42 setWindowTitle(tr("Data Editor"));
42 43
43 QToolBar *toolbar = addToolBar(tr("Toolbar")); 44 QToolBar *toolbar = addToolBar(tr("Toolbar"));
44 45
104 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), 105 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
105 this, 106 this,
106 SLOT(currentChanged(const QModelIndex &, const QModelIndex &))); 107 SLOT(currentChanged(const QModelIndex &, const QModelIndex &)));
107 connect(m_table, SIGNAL(addCommand(Command *)), 108 connect(m_table, SIGNAL(addCommand(Command *)),
108 this, SLOT(addCommand(Command *))); 109 this, SLOT(addCommand(Command *)));
110 connect(m_table, SIGNAL(currentChanged(const QModelIndex &)),
111 this, SLOT(currentChangedThroughResort(const QModelIndex &)));
109 112
110 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); 113 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
111 connect(bb, SIGNAL(rejected()), this, SLOT(close())); 114 connect(bb, SIGNAL(rejected()), this, SLOT(close()));
112 grid->addWidget(bb, 2, 0); 115 grid->addWidget(bb, 2, 0);
113 grid->setRowStretch(2, 0); 116 grid->setRowStretch(2, 0);
131 { 134 {
132 delete m_table; 135 delete m_table;
133 } 136 }
134 137
135 void 138 void
136 ModelDataTableDialog::scrollToFrameRequested(unsigned long frame) 139 ModelDataTableDialog::userScrolledToFrame(unsigned long frame)
137 { 140 {
138 m_tableView->scrollTo(m_table->getModelIndexForFrame(frame)); 141 QModelIndex index = m_table->getModelIndexForFrame(frame);
142 makeCurrent(index.row());
143 }
144
145 void
146 ModelDataTableDialog::playbackScrolledToFrame(unsigned long frame)
147 {
148 if (m_trackPlayback) {
149 QModelIndex index = m_table->getModelIndexForFrame(frame);
150 makeCurrent(index.row());
151 }
152 }
153
154 void
155 ModelDataTableDialog::makeCurrent(int row)
156 {
157 int rh = m_tableView->height() / m_tableView->rowHeight(0);
158 int topRow = row - rh/2;
159 if (topRow < 0) topRow = 0;
160 m_tableView->scrollTo
161 (m_table->getModelIndexForRow(topRow));
162 m_tableView->selectionModel()->setCurrentIndex
163 (m_table->getModelIndexForRow(row), QItemSelectionModel::Select);
139 } 164 }
140 165
141 void 166 void
142 ModelDataTableDialog::viewClicked(const QModelIndex &index) 167 ModelDataTableDialog::viewClicked(const QModelIndex &index)
143 { 168 {
158 std::cerr << "ModelDataTableDialog::currentChanged: from " 183 std::cerr << "ModelDataTableDialog::currentChanged: from "
159 << previous.row() << ", " << previous.column() 184 << previous.row() << ", " << previous.column()
160 << " to " << current.row() << ", " << current.column() 185 << " to " << current.row() << ", " << current.column()
161 << std::endl; 186 << std::endl;
162 m_currentRow = current.row(); 187 m_currentRow = current.row();
188 m_table->setCurrentRow(m_currentRow);
163 } 189 }
164 190
165 void 191 void
166 ModelDataTableDialog::insertRow() 192 ModelDataTableDialog::insertRow()
167 { 193 {
187 ModelDataTableDialog::addCommand(Command *command) 213 ModelDataTableDialog::addCommand(Command *command)
188 { 214 {
189 CommandHistory::getInstance()->addCommand(command, false, true); 215 CommandHistory::getInstance()->addCommand(command, false, true);
190 } 216 }
191 217
218 void
219 ModelDataTableDialog::currentChangedThroughResort(const QModelIndex &index)
220 {
221 std::cerr << "ModelDataTableDialog::currentChangedThroughResort: row = " << index.row() << std::endl;
222 // m_tableView->scrollTo(index);
223 makeCurrent(index.row());
224 }
225
226
227