Merge "QConcatenateTablesProxyModel: skip dataChanged in hidden columns"

This commit is contained in:
David Faure 2021-02-26 22:47:41 +01:00 committed by Qt CI Bot
commit 1d567eb63d
2 changed files with 17 additions and 1 deletions

View File

@ -622,9 +622,14 @@ void QConcatenateTablesProxyModelPrivate::_q_slotDataChanged(const QModelIndex &
Q_Q(QConcatenateTablesProxyModel); Q_Q(QConcatenateTablesProxyModel);
Q_ASSERT(from.isValid()); Q_ASSERT(from.isValid());
Q_ASSERT(to.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); const QModelIndex myFrom = q->mapFromSource(from);
Q_ASSERT(q->checkIndex(myFrom, QAbstractItemModel::CheckIndexOption::IndexIsValid)); 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)); Q_ASSERT(q->checkIndex(myTo, QAbstractItemModel::CheckIndexOption::IndexIsValid));
emit q->dataChanged(myFrom, myTo, roles); emit q->dataChanged(myFrom, myTo, roles);
} }

View File

@ -453,6 +453,17 @@ void tst_QConcatenateTablesProxyModel::shouldUseSmallestColumnCount()
const QModelIndex indexD = pm.mapFromSource(mod2.index(0, 0)); const QModelIndex indexD = pm.mapFromSource(mod2.index(0, 0));
QVERIFY(indexD.isValid()); QVERIFY(indexD.isValid());
QCOMPARE(indexD, pm.index(1, 0)); 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() void tst_QConcatenateTablesProxyModel::shouldIncreaseColumnCountWhenRemovingFirstModel()