QConcatenateTablesProxyModel: implement roleNames()
Change-Id: Id74b45f58678df15285c8b9631db1c59a5d62a2a Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> (cherry picked from commit 5ffb9d7ae6d60fb370b79f8222dab7d7e628fa4f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
18b56bbae2
commit
3af7624967
@ -540,6 +540,23 @@ void QConcatenateTablesProxyModel::removeSourceModel(QAbstractItemModel *sourceM
|
||||
d->updateColumnCount();
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 6.9.0
|
||||
\reimp
|
||||
Returns the union of the roleNames() of the underlying models.
|
||||
|
||||
In case source models associate different names to the same role,
|
||||
the name used in last source model overrides the name used in earlier models.
|
||||
*/
|
||||
QHash<int, QByteArray> QConcatenateTablesProxyModel::roleNames() const
|
||||
{
|
||||
Q_D(const QConcatenateTablesProxyModel);
|
||||
QHash<int, QByteArray> ret = QAbstractItemModel::roleNames();
|
||||
for (const auto &[model, _] : d->m_models)
|
||||
ret.insert(model->roleNames());
|
||||
return ret;
|
||||
}
|
||||
|
||||
void QConcatenateTablesProxyModelPrivate::slotRowsAboutToBeInserted(const QModelIndex &parent,
|
||||
int start, int end)
|
||||
{
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
||||
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||
QSize span(const QModelIndex &index) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE(QConcatenateTablesProxyModel)
|
||||
|
@ -2251,7 +2251,7 @@ void QStandardItemModel::setItemRoleNames(const QHash<int,QByteArray> &roleNames
|
||||
}
|
||||
|
||||
/*!
|
||||
reimp
|
||||
\reimp
|
||||
*/
|
||||
QHash<int, QByteArray> QStandardItemModel::roleNames() const
|
||||
{
|
||||
|
@ -86,6 +86,8 @@ private Q_SLOTS:
|
||||
void qtbug91788();
|
||||
void qtbug91878();
|
||||
void createPersistentOnLayoutAboutToBeChanged();
|
||||
void shouldMergeRoleNames();
|
||||
|
||||
private:
|
||||
QStandardItemModel mod;
|
||||
QStandardItemModel mod2;
|
||||
@ -99,11 +101,13 @@ void tst_QConcatenateTablesProxyModel::init()
|
||||
mod.appendRow({ new QStandardItem(QStringLiteral("A")), new QStandardItem(QStringLiteral("B")), new QStandardItem(QStringLiteral("C")) });
|
||||
mod.setHorizontalHeaderLabels(QStringList() << QStringLiteral("H1") << QStringLiteral("H2") << QStringLiteral("H3"));
|
||||
mod.setVerticalHeaderLabels(QStringList() << QStringLiteral("One"));
|
||||
mod.setItemRoleNames({ { Qt::UserRole, "user" } });
|
||||
|
||||
mod2.clear();
|
||||
mod2.appendRow({ new QStandardItem(QStringLiteral("D")), new QStandardItem(QStringLiteral("E")), new QStandardItem(QStringLiteral("F")) });
|
||||
mod2.setHorizontalHeaderLabels(QStringList() << QStringLiteral("H1") << QStringLiteral("H2") << QStringLiteral("H3"));
|
||||
mod2.setVerticalHeaderLabels(QStringList() << QStringLiteral("Two"));
|
||||
mod2.setItemRoleNames({ { Qt::UserRole + 1, "user+1" } });
|
||||
|
||||
mod3.clear();
|
||||
mod3.appendRow({ new QStandardItem(QStringLiteral("1")), new QStandardItem(QStringLiteral("2")), new QStandardItem(QStringLiteral("3")) });
|
||||
@ -927,6 +931,23 @@ void tst_QConcatenateTablesProxyModel::createPersistentOnLayoutAboutToBeChanged(
|
||||
QCOMPARE(layoutChangedSpy.size(), 1);
|
||||
}
|
||||
|
||||
void tst_QConcatenateTablesProxyModel::shouldMergeRoleNames()
|
||||
{
|
||||
// Given a combining proxy
|
||||
QConcatenateTablesProxyModel pm;
|
||||
|
||||
// When adding three source models
|
||||
pm.addSourceModel(&mod);
|
||||
pm.addSourceModel(&mod2);
|
||||
pm.addSourceModel(&mod3);
|
||||
|
||||
// Then the role names should be merged
|
||||
const auto roleNames = pm.roleNames();
|
||||
QCOMPARE(roleNames[Qt::DisplayRole], "display");
|
||||
QCOMPARE(roleNames[Qt::UserRole], "user");
|
||||
QCOMPARE(roleNames[Qt::UserRole + 1], "user+1");
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(tst_QConcatenateTablesProxyModel)
|
||||
|
||||
#include "tst_qconcatenatetablesproxymodel.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user