diff options
author | Katja Marttila <katja.marttila@qt.io> | 2022-12-13 09:04:55 +0200 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2022-12-13 09:08:15 +0200 |
commit | c02d33db5723b7605dc953de078c26d54f284d5e (patch) | |
tree | 2aa841ad0ac416bf9baed474e90c75abd6fc67f9 /src/libs/installer/componentmodel.cpp | |
parent | 662110e1594788ddc54ec379d61776e1bdd82670 (diff) | |
parent | b7929635dcdbd01135c04e0a7ffc8fa29d647d4d (diff) |
Merge remote-tracking branch 'origin/4.5' into master
Change-Id: Id8121e6b4cdda23c8c44cf779e35dce8d9a28090
Diffstat (limited to 'src/libs/installer/componentmodel.cpp')
-rw-r--r-- | src/libs/installer/componentmodel.cpp | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/src/libs/installer/componentmodel.cpp b/src/libs/installer/componentmodel.cpp index 8407e5f2d..873175937 100644 --- a/src/libs/installer/componentmodel.cpp +++ b/src/libs/installer/componentmodel.cpp @@ -60,14 +60,7 @@ namespace QInstaller { */ /*! - \fn void QInstaller::ComponentModel::componentsCheckStateChanged(const QList<QModelIndex> &indexes) - - 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::modelCheckStateChanged(QInstaller::ComponentModel::ModelState state) + \fn void QInstaller::ComponentModel::checkStateChanged(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 @@ -240,7 +233,6 @@ 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 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) { @@ -262,13 +254,10 @@ bool ComponentModel::setData(const QModelIndex &index, const QVariant &value, in const Qt::CheckState oldValue = component->checkState(); newValue = (oldValue == Qt::Checked) ? Qt::Unchecked : Qt::Checked; } - const QList<QModelIndex> changed = updateCheckedState(nodes << component, newValue); - foreach (const QModelIndex &changedIndex, changed) { + const QSet<QModelIndex> changed = updateCheckedState(nodes << component, newValue); + foreach (const QModelIndex &changedIndex, changed) emit dataChanged(changedIndex, changedIndex); - } - updateModelState(); - if (changed.count() > 0) - emit componentsCheckStateChanged(changed); + updateAndEmitModelState(); // update the internal state } else { component->setData(value, role); emit dataChanged(index, index); @@ -448,8 +437,7 @@ void ComponentModel::setCheckedState(QInstaller::ComponentModel::ModelStateFlag default: break; } - updateModelState(); - emit modelCheckStateChanged(m_modelState); + updateAndEmitModelState(); // update the internal state } @@ -487,11 +475,10 @@ void ComponentModel::postModelReset() } m_currentCheckedState = m_initialCheckedState; - updateModelState(); // update the internal state - emit modelCheckStateChanged(m_modelState); + updateAndEmitModelState(); // update the internal state } -void ComponentModel::updateModelState() +void ComponentModel::updateAndEmitModelState() { if (m_rootComponentList.isEmpty()) { m_modelState = ComponentModel::Empty; @@ -510,6 +497,8 @@ void ComponentModel::updateModelState() m_modelState |= ComponentModel::AllChecked; m_modelState &= ~ComponentModel::PartiallyChecked; } + + emit checkStateChanged(m_modelState); } void ComponentModel::collectComponents(Component *const component, const QModelIndex &parent) const @@ -553,7 +542,7 @@ static Qt::CheckState verifyPartiallyChecked(Component *component) } // namespace ComponentModelPrivate -QList<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &components, const Qt::CheckState state) +QSet<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; @@ -564,7 +553,7 @@ QList<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &compon } } - QList<QModelIndex> changed; + QSet<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--) { @@ -586,10 +575,7 @@ QList<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &compon continue; node->setCheckState(newState); - 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())); + changed.insert(indexFromComponentName(node->treeName())); m_currentCheckedState[Qt::Checked].remove(node); m_currentCheckedState[Qt::Unchecked].remove(node); |