summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/componentmodel.cpp
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2022-03-25 15:38:50 +0200
committerKatja Marttila <katja.marttila@qt.io>2022-04-28 15:18:34 +0300
commita28cf55b5a5007c0dd952b3012c076d9da329f0f (patch)
treeaba86d92da394969acfcf2eb6d7b7578c9432c36 /src/libs/installer/componentmodel.cpp
parent23ec1e91f4e0c567f5953de149b2ab3496490e87 (diff)
Speed up component selection in component selection pages
If a lot of components are installed, maintenancetool was slow to select/unselect a single component. This was caused because the whole tree's components were recalculated. Fixed so that only the selected/unselected components and their dependencies and autodependencies are recalculated instead of whole tree. This change speeds up clicking tree item from zero to 90 percent, depending on how much components are already installed. The more components are installed as autodependency, the slower it gets to select the items. Task-number: QTIFW-2522 Change-Id: I5e824aed8787fd7ecdce72b15a1b13848f0a3923 Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'src/libs/installer/componentmodel.cpp')
-rw-r--r--src/libs/installer/componentmodel.cpp41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/libs/installer/componentmodel.cpp b/src/libs/installer/componentmodel.cpp
index 88e502164..3bb9bc72e 100644
--- a/src/libs/installer/componentmodel.cpp
+++ b/src/libs/installer/componentmodel.cpp
@@ -58,14 +58,14 @@ namespace QInstaller {
*/
/*!
- \fn void QInstaller::ComponentModel::checkStateChanged(const QModelIndex &index)
+ \fn void QInstaller::ComponentModel::componentsCheckStateChanged(const QList<QModelIndex> &indexes)
- This signal is emitted whenever the checked state of a component is changed. The \a index value
- indicates the QModelIndex representation of the component as seen from the model.
+ This signal is emitted whenever the checked state of components are changed. The \a indexes value
+ indicates the QModelIndexes representation of the components as seen from the model.
*/
/*!
- \fn void QInstaller::ComponentModel::checkStateChanged(QInstaller::ComponentModel::ModelState state)
+ \fn void QInstaller::ComponentModel::modelCheckStateChanged(QInstaller::ComponentModel::ModelState state)
This signal is emitted whenever the checked state of a model is changed after all state
calculations have taken place. The \a state is a combination of \c ModelStateFlag values
@@ -238,7 +238,7 @@ QVariant ComponentModel::data(const QModelIndex &index, int role) const
/*!
Sets the \a role data for the item at \a index to \a value. Returns true if successful;
otherwise returns false. The dataChanged() signal is emitted if the data was successfully set.
- The checkStateChanged() signals are emitted in addition if the checked state of the item is set.
+ The componentsCheckStateChanged() signal is emitted in addition if the checked state of the item is set.
*/
bool ComponentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
@@ -260,12 +260,13 @@ bool ComponentModel::setData(const QModelIndex &index, const QVariant &value, in
const Qt::CheckState oldValue = component->checkState();
newValue = (oldValue == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
}
- QSet<QModelIndex> changed = updateCheckedState(nodes << component, newValue);
+ const QList<QModelIndex> changed = updateCheckedState(nodes << component, newValue);
foreach (const QModelIndex &changedIndex, changed) {
emit dataChanged(changedIndex, changedIndex);
- emit checkStateChanged(changedIndex);
}
- updateAndEmitModelState(); // update the internal state
+ updateModelState();
+ if (changed.count() > 0)
+ emit componentsCheckStateChanged(changed);
} else {
component->setData(value, role);
emit dataChanged(index, index);
@@ -425,12 +426,12 @@ void ComponentModel::reset(QList<Component *> rootComponents)
Sets the checked state of every component in the model to be \a state.
The ComponentModel::PartiallyChecked flag is ignored by this function. Note that components
- are not changed if they are not checkable. The dataChanged() and checkStateChanged() signals
+ are not changed if they are not checkable. The dataChanged() and componentsCheckStateChanged() signals
are emitted.
*/
void ComponentModel::setCheckedState(QInstaller::ComponentModel::ModelStateFlag state)
{
- QSet<QModelIndex> changed;
+ QList<QModelIndex> changed;
switch (state) {
case AllChecked:
changed = updateCheckedState(m_currentCheckedState[Qt::Unchecked], Qt::Checked);
@@ -453,9 +454,9 @@ void ComponentModel::setCheckedState(QInstaller::ComponentModel::ModelStateFlag
// notify about changes done to the model
foreach (const QModelIndex &index, changed) {
emit dataChanged(index, index);
- emit checkStateChanged(index);
}
- updateAndEmitModelState(); // update the internal state
+ updateModelState();
+ emit modelCheckStateChanged(m_modelState);
}
@@ -493,10 +494,11 @@ void ComponentModel::postModelReset()
}
m_currentCheckedState = m_initialCheckedState;
- updateAndEmitModelState(); // update the internal state
+ updateModelState(); // update the internal state
+ emit modelCheckStateChanged(m_modelState);
}
-void ComponentModel::updateAndEmitModelState()
+void ComponentModel::updateModelState()
{
m_modelState = ComponentModel::DefaultChecked;
if (m_initialCheckedState != m_currentCheckedState)
@@ -511,8 +513,6 @@ void ComponentModel::updateAndEmitModelState()
m_modelState |= ComponentModel::AllChecked;
m_modelState &= ~ComponentModel::PartiallyChecked;
}
-
- emit checkStateChanged(m_modelState);
}
void ComponentModel::collectComponents(Component *const component, const QModelIndex &parent) const
@@ -556,7 +556,7 @@ static Qt::CheckState verifyPartiallyChecked(Component *component)
} // namespace ComponentModelPrivate
-QSet<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &components, Qt::CheckState state)
+QList<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &components, const Qt::CheckState state)
{
// get all parent nodes for the components we're going to update
QMultiMap<QString, Component *> sortedNodesMap;
@@ -567,7 +567,7 @@ QSet<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &compone
}
}
- QSet<QModelIndex> changed;
+ QList<QModelIndex> changed;
const ComponentList sortedNodes = sortedNodesMap.values();
// we can start in descending order to check node and tri-state nodes properly
for (int i = sortedNodes.count(); i > 0; i--) {
@@ -589,7 +589,10 @@ QSet<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &compone
continue;
node->setCheckState(newState);
- changed.insert(indexFromComponentName(node->treeName()));
+ QModelIndex index = indexFromComponentName(node->treeName());
+ //Prepend to the list so that install order is correct (parent first)
+ if (!changed.contains(index))
+ changed.prepend(indexFromComponentName(node->treeName()));
m_currentCheckedState[Qt::Checked].remove(node);
m_currentCheckedState[Qt::Unchecked].remove(node);