Mercurial > hg > svgui
comparison widgets/ModelDataTableDialog.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
399:80c7dd3c8dce | 400:32acd578fcba |
---|---|
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, QString title, QWidget *parent) : |
38 QMainWindow(parent) | 38 QMainWindow(parent), |
39 m_currentRow(0) | |
39 { | 40 { |
40 setWindowTitle(tr("Data Editor")); | 41 setWindowTitle(tr("Data Editor")); |
41 | 42 |
42 QToolBar *toolbar = addToolBar(tr("Toolbar")); | 43 QToolBar *toolbar = addToolBar(tr("Toolbar")); |
43 | 44 |
50 toolbar->addAction(action); | 51 toolbar->addAction(action); |
51 | 52 |
52 action = new QAction(il.load("datadelete"), tr("Delete Selected Items"), this); | 53 action = new QAction(il.load("datadelete"), tr("Delete Selected Items"), this); |
53 action->setShortcut(tr("Delete")); | 54 action->setShortcut(tr("Delete")); |
54 action->setStatusTip(tr("Delete the selected item or items")); | 55 action->setStatusTip(tr("Delete the selected item or items")); |
55 connect(action, SIGNAL(triggered()), this, SLOT(deleteRow())); | 56 connect(action, SIGNAL(triggered()), this, SLOT(deleteRows())); |
56 toolbar->addAction(action); | 57 toolbar->addAction(action); |
57 | 58 |
58 action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this); | 59 action = new QAction(il.load("dataedit"), tr("Edit Selected Item"), this); |
59 action->setShortcut(tr("Edit")); | 60 action->setShortcut(tr("Edit")); |
60 action->setStatusTip(tr("Edit the selected item")); | 61 action->setStatusTip(tr("Edit the selected item")); |
97 | 98 |
98 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)), | 99 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)), |
99 this, SLOT(viewClicked(const QModelIndex &))); | 100 this, SLOT(viewClicked(const QModelIndex &))); |
100 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)), | 101 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)), |
101 this, SLOT(viewPressed(const QModelIndex &))); | 102 this, SLOT(viewPressed(const QModelIndex &))); |
102 connect(m_table, SIGNAL(executeCommand(Command *)), | 103 connect(m_tableView->selectionModel(), |
103 this, SLOT(executeCommand(Command *))); | 104 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), |
105 this, | |
106 SLOT(currentChanged(const QModelIndex &, const QModelIndex &))); | |
107 connect(m_table, SIGNAL(addCommand(Command *)), | |
108 this, SLOT(addCommand(Command *))); | |
104 | 109 |
105 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); | 110 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); |
106 connect(bb, SIGNAL(rejected()), this, SLOT(close())); | 111 connect(bb, SIGNAL(rejected()), this, SLOT(close())); |
107 grid->addWidget(bb, 2, 0); | 112 grid->addWidget(bb, 2, 0); |
108 grid->setRowStretch(2, 0); | 113 grid->setRowStretch(2, 0); |
145 { | 150 { |
146 std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl; | 151 std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl; |
147 } | 152 } |
148 | 153 |
149 void | 154 void |
150 ModelDataTableDialog::insertRow() | 155 ModelDataTableDialog::currentChanged(const QModelIndex ¤t, |
156 const QModelIndex &previous) | |
151 { | 157 { |
158 std::cerr << "ModelDataTableDialog::currentChanged: from " | |
159 << previous.row() << ", " << previous.column() | |
160 << " to " << current.row() << ", " << current.column() | |
161 << std::endl; | |
162 m_currentRow = current.row(); | |
152 } | 163 } |
153 | 164 |
154 void | 165 void |
155 ModelDataTableDialog::deleteRow() | 166 ModelDataTableDialog::insertRow() |
156 { | 167 { |
168 m_table->insertRow(m_currentRow); | |
169 } | |
170 | |
171 void | |
172 ModelDataTableDialog::deleteRows() | |
173 { | |
174 // not efficient | |
175 while (m_tableView->selectionModel()->hasSelection()) { | |
176 m_table->removeRow | |
177 (m_tableView->selectionModel()->selection().indexes().begin()->row()); | |
178 } | |
157 } | 179 } |
158 | 180 |
159 void | 181 void |
160 ModelDataTableDialog::editRow() | 182 ModelDataTableDialog::editRow() |
161 { | 183 { |
162 } | 184 } |
163 | 185 |
164 void | 186 void |
165 ModelDataTableDialog::executeCommand(Command *command) | 187 ModelDataTableDialog::addCommand(Command *command) |
166 { | 188 { |
167 std::cerr << "ModelDataTableDialog::executeCommand(" << command << ")" << std::endl; | |
168 CommandHistory::getInstance()->addCommand(command, false, true); | 189 CommandHistory::getInstance()->addCommand(command, false, true); |
169 } | 190 } |
170 | 191 |