Skip to content

Commit

Permalink
QConcatenateTablesProxyModel: skip dataChanged in hidden columns
Browse files Browse the repository at this point in the history
When the source models don't have the same number of columns, the proxy
keeps only the smallest number of columns across all source models.
Afterwards, if a source model emits dataChanged in a column past
that number (a "hidden" column), the proxy needs to ignore it rather than
assert.
But also, if the source model emits a dataChanged signal across both
visible and hidden columns, then the last column number needs to be
adjusted so that the signal is correctly processed and forwarded.

Task-number: QTBUG-91253
Pick-to: 6.1 6.0 5.15
Change-Id: I939e8ec0faf41370472f86785851292e4372f72c
Reviewed-by: Giuseppe D'Angelo <[email protected]>
  • Loading branch information
dfaure-kdab committed Mar 9, 2021
1 parent 09d3615 commit f6efbd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/corelib/itemmodels/qconcatenatetablesproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,14 @@ void QConcatenateTablesProxyModelPrivate::_q_slotDataChanged(const QModelIndex &
Q_Q(QConcatenateTablesProxyModel);
Q_ASSERT(from.isValid());
Q_ASSERT(to.isValid());
if (from.column() >= m_columnCount)
return;
QModelIndex adjustedTo = to;
if (to.column() >= m_columnCount)
adjustedTo = to.siblingAtColumn(m_columnCount - 1);
const QModelIndex myFrom = q->mapFromSource(from);
Q_ASSERT(q->checkIndex(myFrom, QAbstractItemModel::CheckIndexOption::IndexIsValid));
const QModelIndex myTo = q->mapFromSource(to);
const QModelIndex myTo = q->mapFromSource(adjustedTo);
Q_ASSERT(q->checkIndex(myTo, QAbstractItemModel::CheckIndexOption::IndexIsValid));
emit q->dataChanged(myFrom, myTo, roles);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,17 @@ void tst_QConcatenateTablesProxyModel::shouldUseSmallestColumnCount()
const QModelIndex indexD = pm.mapFromSource(mod2.index(0, 0));
QVERIFY(indexD.isValid());
QCOMPARE(indexD, pm.index(1, 0));

// Test setData in an ignored column (QTBUG-91253)
QSignalSpy dataChangedSpy(&pm, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
mod.setData(mod.index(0, 1), "b");
QCOMPARE(dataChangedSpy.count(), 0);

// Test dataChanged across all columns, some visible, some ignored
mod.dataChanged(mod.index(0, 0), mod.index(0, 2));
QCOMPARE(dataChangedSpy.count(), 1);
QCOMPARE(dataChangedSpy.at(0).at(0).toModelIndex(), pm.index(0, 0));
QCOMPARE(dataChangedSpy.at(0).at(1).toModelIndex(), pm.index(0, 0));
}

void tst_QConcatenateTablesProxyModel::shouldIncreaseColumnCountWhenRemovingFirstModel()
Expand Down

0 comments on commit f6efbd2

Please sign in to comment.