diff options
author | jkobus <jaroslaw.kobus@theqtcompany.com> | 2014-12-18 14:59:52 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@theqtcompany.com> | 2015-01-19 16:27:58 +0100 |
commit | 668e053c62d4a2dae5f38e454fac00df74eeeb03 (patch) | |
tree | 6d7f8acffc163c44db404979d0db2d8f624536b5 /src/libs/installer/componentmodel.cpp | |
parent | 46b8eb8d6713e0e592c94b090baece0613b2503a (diff) |
Introduce InstallAction property for component
Fixes calculation of component size inside
maintenance tool. Don't manipulate check state
of components while calculating dependencies.
Prepare feature: live preview of dependencies.
Change-Id: I0485df8383bc9149a996456e09878fc5676bb27b
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/componentmodel.cpp')
-rw-r--r-- | src/libs/installer/componentmodel.cpp | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/libs/installer/componentmodel.cpp b/src/libs/installer/componentmodel.cpp index 9ff43a598..d2537dea0 100644 --- a/src/libs/installer/componentmodel.cpp +++ b/src/libs/installer/componentmodel.cpp @@ -36,6 +36,7 @@ #include "component.h" #include "packagemanagercore.h" +#include <QIcon> namespace QInstaller { @@ -71,6 +72,20 @@ namespace QInstaller { or unchecked, or some individual component's checked state has changed. */ +class IconCache +{ +public: + IconCache() { + } + + QIcon icon(ComponentModelHelper::InstallAction action) const { + return m_icons.value(action); + } +private: + QMap<ComponentModelHelper::InstallAction, QIcon> m_icons; +}; + +Q_GLOBAL_STATIC(IconCache, iconCache) /*! Constructs an component model with the given number of \a columns and \a core as parent. @@ -179,6 +194,25 @@ QVariant ComponentModel::data(const QModelIndex &index, int role) const if (index.column() > 0) { if (role == Qt::CheckStateRole) return QVariant(); + if (index.column() == ComponentModelHelper::ActionColumn) { + if (role == Qt::DecorationRole) + return iconCache->icon(component->installAction()); + if (role == Qt::ToolTipRole) { + switch (component->installAction()) { + case ComponentModelHelper::Install: + return tr("Component is marked for installation."); + case ComponentModelHelper::Uninstall: + return tr("Component is marked for uninstallation."); + case ComponentModelHelper::KeepInstalled: + return tr("Component is installed."); + case ComponentModelHelper::KeepUninstalled: + return tr("Component is not installed."); + default: + return QString(); + } + } + return QVariant(); + } if (role == Qt::EditRole || role == Qt::DisplayRole || role == Qt::ToolTipRole) return component->data(Qt::UserRole + index.column()); } @@ -202,6 +236,8 @@ bool ComponentModel::setData(const QModelIndex &index, const QVariant &value, in return false; if (role == Qt::CheckStateRole) { + if (index.column() != 0) + return false; ComponentSet nodes = component->childItems().toSet(); Qt::CheckState newValue = Qt::CheckState(value.toInt()); if (newValue == Qt::PartiallyChecked) { @@ -459,6 +495,15 @@ void ComponentModel::updateAndEmitModelState() } emit checkStateChanged(m_modelState); + + foreach (const Component *component, m_rootComponentList) { + emit dataChanged(indexFromComponentName(component->name()), + indexFromComponentName(component->name())); + QList<Component *> children = component->childItems(); + foreach (const Component *child, children) + emit dataChanged(indexFromComponentName(child->name()), + indexFromComponentName(child->name())); + } } void ComponentModel::collectComponents(Component *const component, const QModelIndex &parent) const @@ -547,10 +592,6 @@ QSet<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &compone break; } } - - // update all nodes uncompressed size - foreach (Component *const node, m_rootComponentList) - node->updateUncompressedSize(); // this is a recursive call return changed; } |