I am trying to insert some data in a TableView from a model but I am doing something wrong because the data is not inserted. The table is updated with the columns and rows though.
So I have a GraphicsView where I am drawing some custom GraphicsItems. Each time a new Item is added to the scene the model is supposed to get updated and send a signal to my TableView to insert the data in it as well.
Here I update the model when the new item is added:
Clothoid *temp = new Clothoid();
temp->setStartPoint(p1);
temp->setEndPoint(p2);
clothoids.append(temp);
scene->addItem(temp);
model.setColumnCount(3);
model.setRowCount(clothoids.size());
model.setData(index, clothoids.last()->startCurvature);
index
= model.
index(clothoids.
size(),
2,
QModelIndex());
model.setData(index, clothoids.last()->endCurvature);
index
= model.
index(clothoids.
size(),
3,
QModelIndex());
model.setData(index, clothoids.last()->clothoidLength);
emit clothoidAdded(&model);
Clothoid *temp = new Clothoid();
temp->setStartPoint(p1);
temp->setEndPoint(p2);
clothoids.append(temp);
scene->addItem(temp);
model.setColumnCount(3);
model.setRowCount(clothoids.size());
QModelIndex index = model.index(clothoids.size(), 1, QModelIndex());
model.setData(index, clothoids.last()->startCurvature);
index = model.index(clothoids.size(), 2, QModelIndex());
model.setData(index, clothoids.last()->endCurvature);
index = model.index(clothoids.size(), 3, QModelIndex());
model.setData(index, clothoids.last()->clothoidLength);
emit clothoidAdded(&model);
To copy to clipboard, switch view to plain text mode
Clothoids being a list of my custom graphicsItems:
QList < Clothoid
*> clothoids;
QList < Clothoid *> clothoids;
To copy to clipboard, switch view to plain text mode
The signal is connected to the slot in my main window:
ui->setupUi(this);
SpinBoxDelegate delegate;
ui->clothoidTable->setItemDelegate(&delegate);
ui->setupUi(this);
SpinBoxDelegate delegate;
ui->clothoidTable->setItemDelegate(&delegate);
connect(ui->graphicsView, SIGNAL(clothoidAdded(QStandardItemModel*)), ui->clothoidTable, SLOT(onClothoidAdded(QStandardItemModel*)));
To copy to clipboard, switch view to plain text mode
where the slot is:
{
setModel(model);
}
void TableViewList::onClothoidAdded(QStandardItemModel *model)
{
setModel(model);
}
To copy to clipboard, switch view to plain text mode
What am I doing wrong?
Bookmarks