QTableView: call model->submit() on row change
QTreeView already does this in the exact same way. It's necessary to call submit() so edit strategy OnRowChange in QSqlTableModel will work as expected. Change-Id: Ib430143e8a71f3b0bcd842fcc772cc7ee4525f0a Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
273508205c
commit
9e87104295
@ -1071,6 +1071,10 @@ void QTableView::setModel(QAbstractItemModel *model)
|
|||||||
disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
|
disconnect(d->model, SIGNAL(columnsRemoved(QModelIndex,int,int)),
|
||||||
this, SLOT(_q_updateSpanRemovedColumns(QModelIndex,int,int)));
|
this, SLOT(_q_updateSpanRemovedColumns(QModelIndex,int,int)));
|
||||||
}
|
}
|
||||||
|
if (d->selectionModel) { // support row editing
|
||||||
|
disconnect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
||||||
|
d->model, SLOT(submit()));
|
||||||
|
}
|
||||||
if (model) { //and connect to the new one
|
if (model) { //and connect to the new one
|
||||||
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
||||||
this, SLOT(_q_updateSpanInsertedRows(QModelIndex,int,int)));
|
this, SLOT(_q_updateSpanInsertedRows(QModelIndex,int,int)));
|
||||||
@ -1123,9 +1127,21 @@ void QTableView::setSelectionModel(QItemSelectionModel *selectionModel)
|
|||||||
{
|
{
|
||||||
Q_D(QTableView);
|
Q_D(QTableView);
|
||||||
Q_ASSERT(selectionModel);
|
Q_ASSERT(selectionModel);
|
||||||
|
if (d->selectionModel) {
|
||||||
|
// support row editing
|
||||||
|
disconnect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
||||||
|
d->model, SLOT(submit()));
|
||||||
|
}
|
||||||
|
|
||||||
d->verticalHeader->setSelectionModel(selectionModel);
|
d->verticalHeader->setSelectionModel(selectionModel);
|
||||||
d->horizontalHeader->setSelectionModel(selectionModel);
|
d->horizontalHeader->setSelectionModel(selectionModel);
|
||||||
QAbstractItemView::setSelectionModel(selectionModel);
|
QAbstractItemView::setSelectionModel(selectionModel);
|
||||||
|
|
||||||
|
if (d->selectionModel) {
|
||||||
|
// support row editing
|
||||||
|
connect(d->selectionModel, SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
||||||
|
d->model, SLOT(submit()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -175,6 +175,7 @@ private slots:
|
|||||||
void tabFocus();
|
void tabFocus();
|
||||||
void bigModel();
|
void bigModel();
|
||||||
void selectionSignal();
|
void selectionSignal();
|
||||||
|
void setCurrentIndex();
|
||||||
|
|
||||||
// task-specific tests:
|
// task-specific tests:
|
||||||
void task173773_updateVerticalHeader();
|
void task173773_updateVerticalHeader();
|
||||||
@ -254,11 +255,15 @@ class QtTestTableModel: public QAbstractTableModel
|
|||||||
signals:
|
signals:
|
||||||
void invalidIndexEncountered() const;
|
void invalidIndexEncountered() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
bool submit() { ++submit_count; return QAbstractTableModel::submit(); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
|
QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
|
||||||
: QAbstractTableModel(parent),
|
: QAbstractTableModel(parent),
|
||||||
row_count(rows),
|
row_count(rows),
|
||||||
column_count(columns),
|
column_count(columns),
|
||||||
|
submit_count(0),
|
||||||
can_fetch_more(false),
|
can_fetch_more(false),
|
||||||
fetch_more_count(0),
|
fetch_more_count(0),
|
||||||
disabled_rows(),
|
disabled_rows(),
|
||||||
@ -400,6 +405,7 @@ public:
|
|||||||
|
|
||||||
int row_count;
|
int row_count;
|
||||||
int column_count;
|
int column_count;
|
||||||
|
int submit_count;
|
||||||
bool can_fetch_more;
|
bool can_fetch_more;
|
||||||
int fetch_more_count;
|
int fetch_more_count;
|
||||||
QSet<int> disabled_rows;
|
QSet<int> disabled_rows;
|
||||||
@ -3480,6 +3486,27 @@ void tst_QTableView::selectionSignal()
|
|||||||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center());
|
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTableView::setCurrentIndex()
|
||||||
|
{
|
||||||
|
QtTestTableModel model(4, 4);
|
||||||
|
QtTestTableView view;
|
||||||
|
view.setModel(&model);
|
||||||
|
|
||||||
|
// submit() slot should be called in model when current row changes
|
||||||
|
view.setCurrentIndex(model.index(0,0));
|
||||||
|
QCOMPARE(model.submit_count, 1);
|
||||||
|
view.setCurrentIndex(model.index(0,2));
|
||||||
|
QCOMPARE(model.submit_count, 1);
|
||||||
|
view.setCurrentIndex(model.index(1,0));
|
||||||
|
QCOMPARE(model.submit_count, 2);
|
||||||
|
view.setCurrentIndex(model.index(3,3));
|
||||||
|
QCOMPARE(model.submit_count, 3);
|
||||||
|
view.setCurrentIndex(model.index(0,1));
|
||||||
|
QCOMPARE(model.submit_count, 4);
|
||||||
|
view.setCurrentIndex(model.index(0,0));
|
||||||
|
QCOMPARE(model.submit_count, 4);
|
||||||
|
}
|
||||||
|
|
||||||
class task173773_EventFilter : public QObject
|
class task173773_EventFilter : public QObject
|
||||||
{
|
{
|
||||||
int paintEventCount_;
|
int paintEventCount_;
|
||||||
|
Loading…
Reference in New Issue
Block a user