feat(LeftJoinModel): Use QAbstractItemModel::match for searching key idx in right model
It creates a possibility to transparently improve performance of id lookup in right model by implementing fast search on given role in the righ model itself by reimplementing QAbstractItemModel::match. Closes: #12574
This commit is contained in:
parent
7847cb3b11
commit
04b6fb54c3
|
@ -129,7 +129,7 @@ QVariant LeftJoinModel::data(const QModelIndex& index, int role) const
|
||||||
if (m_rightModelDestroyed)
|
if (m_rightModelDestroyed)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
QVariant joinRoleLeftValue = m_leftModel->data(idx, m_leftModelJoinRole);
|
auto joinRoleLeftValue = m_leftModel->data(idx, m_leftModelJoinRole);
|
||||||
|
|
||||||
if (m_lastUsedRightModelIndex.isValid()
|
if (m_lastUsedRightModelIndex.isValid()
|
||||||
&& m_rightModel->data(m_lastUsedRightModelIndex,
|
&& m_rightModel->data(m_lastUsedRightModelIndex,
|
||||||
|
@ -139,22 +139,15 @@ QVariant LeftJoinModel::data(const QModelIndex& index, int role) const
|
||||||
role - m_rightModelRolesOffset);
|
role - m_rightModelRolesOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rightModelCount = m_rightModel->rowCount();
|
QModelIndexList match = m_rightModel->match(
|
||||||
|
m_rightModel->index(0, 0), m_rightModelJoinRole,
|
||||||
|
joinRoleLeftValue, 1, Qt::MatchExactly);
|
||||||
|
|
||||||
for (int i = 0; i < rightModelCount; i++) {
|
if (match.empty())
|
||||||
auto rightModelIdx = m_rightModel->index(i, 0);
|
return {};
|
||||||
auto rightJointRoleValue = m_rightModel->data(rightModelIdx,
|
|
||||||
m_rightModelJoinRole);
|
|
||||||
|
|
||||||
if (joinRoleLeftValue == rightJointRoleValue) {
|
m_lastUsedRightModelIndex = match.first();
|
||||||
m_lastUsedRightModelIndex = rightModelIdx;
|
return match.first().data(role - m_rightModelRolesOffset);
|
||||||
|
|
||||||
return m_rightModel->data(rightModelIdx,
|
|
||||||
role - m_rightModelRolesOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LeftJoinModel::setLeftModel(QAbstractItemModel* model)
|
void LeftJoinModel::setLeftModel(QAbstractItemModel* model)
|
||||||
|
|
Loading…
Reference in New Issue