PDA

View Full Version : questions about datachanged() in model/view programming



calmspeaker
8th September 2008, 09:46
When I use tableview to make a table control ,something about singnal dataChanged() really confused me!

If the parameters "const QModelIndex & topLeft, const QModelIndex & bottomRight" are the same index, the view only will update exactly the cell which is pointed by the index.But if topLeft!=bottomRight, the entire tableview will be refreshed no matter whereever the topLeft or bottomRight is.

I looked up the src file of qt, in qabstractitemview.cpp

connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
this, SLOT(dataChanged(QModelIndex,QModelIndex)));

void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
// Single item changed
Q_D(QAbstractItemView);
if (topLeft == bottomRight && topLeft.isValid()) {
if (d->hasEditor(topLeft)) {
QAbstractItemDelegate *delegate = d->delegateForIndex(topLeft);
if (delegate) {
delegate->setEditorData(d->editorForIndex(topLeft), topLeft);
}
}
if (isVisible() && !d->delayedLayout.isActive()) {
// otherwise the items will be update later anyway
d->viewport->update(visualRect(topLeft));
}
return;
}
d->updateEditorData(topLeft, bottomRight);
if (!isVisible() || d->delayedLayout.isActive())
return; // no need to update
/* ---> */ d->viewport->update(); /* <--- */
}


I guess the red code means the entire tableview will be updated! Am I right?:(

jacek
8th September 2008, 23:48
The code invokes update() on the viewport. That's the visible part of the view.