diff options
-rw-r--r-- | src/libs/installer/component.cpp | 4 | ||||
-rw-r--r-- | src/libs/installer/component_p.cpp | 10 | ||||
-rw-r--r-- | src/libs/installer/component_p.h | 19 | ||||
-rw-r--r-- | src/libs/installer/componentmodel.cpp | 49 | ||||
-rw-r--r-- | src/libs/installer/installercalculator.cpp | 3 | ||||
-rw-r--r-- | src/libs/installer/packagemanagercore.cpp | 87 | ||||
-rw-r--r-- | src/libs/installer/packagemanagercore.h | 1 | ||||
-rw-r--r-- | src/libs/installer/packagemanagercore_p.cpp | 4 | ||||
-rw-r--r-- | src/libs/installer/packagemanagergui.cpp | 20 | ||||
-rw-r--r-- | src/libs/installer/uninstallercalculator.cpp | 6 |
10 files changed, 161 insertions, 42 deletions
diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index f73aefbfb..494e61dbd 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -342,8 +342,10 @@ quint64 Component::updateUncompressedSize() { quint64 size = 0; - if (isSelected()) + if (installAction() == ComponentModelHelper::Install + || installAction() == ComponentModelHelper::KeepInstalled) { size = d->m_vars.value(scUncompressedSize).toLongLong(); + } foreach (Component* comp, d->m_allChildComponents) size += comp->updateUncompressedSize(); diff --git a/src/libs/installer/component_p.cpp b/src/libs/installer/component_p.cpp index 4bcfbf5dc..18ba4b7b5 100644 --- a/src/libs/installer/component_p.cpp +++ b/src/libs/installer/component_p.cpp @@ -204,6 +204,16 @@ void ComponentModelHelper::setSelectable(bool selectable) changeFlags(selectable, Qt::ItemIsSelectable); } +ComponentModelHelper::InstallAction ComponentModelHelper::installAction() const +{ + return data(ComponentModelHelper::Action).value<ComponentModelHelper::InstallAction>(); +} + +void ComponentModelHelper::setInstallAction(ComponentModelHelper::InstallAction action) +{ + setData(QVariant::fromValue<ComponentModelHelper::InstallAction>(action), ComponentModelHelper::Action); +} + /*! Returns the item flags for the component. The item flags determine how the user can interact with the component. diff --git a/src/libs/installer/component_p.h b/src/libs/installer/component_p.h index 15834d1f2..87e067ba4 100644 --- a/src/libs/installer/component_p.h +++ b/src/libs/installer/component_p.h @@ -93,18 +93,28 @@ class INSTALLER_EXPORT ComponentModelHelper { public: enum Roles { - LocalDisplayVersion = Qt::UserRole + 1, + Action = Qt::UserRole + 1, + LocalDisplayVersion, RemoteDisplayVersion, ReleaseDate, UncompressedSize }; + enum InstallAction { + Install, + Uninstall, + KeepInstalled, + KeepUninstalled + }; + enum Column { NameColumn = 0, + ActionColumn, InstalledVersionColumn, NewVersionColumn, ReleaseDateColumn, - UncompressedSizeColumn + UncompressedSizeColumn, + LastColumn }; explicit ComponentModelHelper(); @@ -125,6 +135,9 @@ public: bool isSelectable() const; void setSelectable(bool selectable); + InstallAction installAction() const; + void setInstallAction(InstallAction action); + Qt::ItemFlags flags() const; void setFlags(Qt::ItemFlags flags); @@ -148,4 +161,6 @@ private: } // namespace QInstaller +Q_DECLARE_METATYPE(QInstaller::ComponentModelHelper::InstallAction) + #endif // COMPONENT_P_H 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; } diff --git a/src/libs/installer/installercalculator.cpp b/src/libs/installer/installercalculator.cpp index e4773460d..10f7327db 100644 --- a/src/libs/installer/installercalculator.cpp +++ b/src/libs/installer/installercalculator.cpp @@ -101,9 +101,6 @@ QString InstallerCalculator::componentsToInstallError() const void InstallerCalculator::realAppendToInstallComponents(Component *component) { if (!component->isInstalled() || component->updateRequested()) { - // remove the checkState method if we don't use selected in scripts - component->setCheckState(Qt::Checked); - m_orderedComponentsToInstall.append(component); m_toInstallComponentIds.insert(component->name()); } diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 4190efd18..8600dc114 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -424,7 +424,37 @@ void PackageManagerCore::cancelMetaInfoJob() */ void PackageManagerCore::componentsToInstallNeedsRecalculation() { - d->m_componentsToInstallCalculated = false; + d->clearInstallerCalculator(); + d->clearUninstallerCalculator(); + QList<Component*> selectedComponentsToInstall = componentsMarkedForInstallation(); + + d->m_componentsToInstallCalculated = + d->installerCalculator()->appendComponentsToInstall(selectedComponentsToInstall); + + QList<Component *> componentsToInstall = d->installerCalculator()->orderedComponentsToInstall(); + + QList<Component *> selectedComponentsToUninstall; + foreach (Component *component, components(ComponentType::All)) { + if (component->uninstallationRequested() && !selectedComponentsToInstall.contains(component)) + selectedComponentsToUninstall.append(component); + } + + d->uninstallerCalculator()->appendComponentsToUninstall(selectedComponentsToUninstall); + + QSet<Component *> componentsToUninstall = d->uninstallerCalculator()->componentsToUninstall(); + + foreach (Component *component, components(ComponentType::Root | ComponentType::Descendants)) + component->setInstallAction(component->isInstalled() + ? ComponentModelHelper::KeepInstalled + : ComponentModelHelper::KeepUninstalled); + foreach (Component *component, componentsToUninstall) + component->setInstallAction(ComponentModelHelper::Uninstall); + foreach (Component *component, componentsToInstall) + component->setInstallAction(ComponentModelHelper::Install); + + // update all nodes uncompressed size + foreach (Component *const component, components(ComponentType::Root)) + component->updateUncompressedSize(); // this is a recursive call } /*! @@ -468,9 +498,9 @@ void PackageManagerCore::setMessageBoxAutomaticAnswer(const QString &identifier, quint64 size(QInstaller::Component *component, const QString &value) { - if (!component->isSelected() || component->isInstalled()) - return quint64(0); - return component->value(value).toLongLong(); + if (component->installAction() == ComponentModelHelper::Install) + return component->value(value).toLongLong(); + return quint64(0); } /*! @@ -1235,6 +1265,30 @@ Component *PackageManagerCore::componentByName(const QString &name, const QList< return 0; } +QList<Component *> PackageManagerCore::componentsMarkedForInstallation() const +{ + QList<Component*> markedForInstallation; + const QList<Component*> relevant = components(ComponentType::Root | ComponentType::Descendants); + if (isUpdater()) { + foreach (Component *component, relevant) { + if (component->updateRequested()) + markedForInstallation.append(component); + } + } else { + // relevant means all components which are not replaced + foreach (Component *component, relevant) { + // ask for all components which will be installed to get all dependencies + // even dependencies which are changed without an increased version + if (component->installationRequested() + || (component->isInstalled() + && !component->uninstallationRequested())) { + markedForInstallation.append(component); + } + } + } + return markedForInstallation; +} + /*! \qmlmethod boolean installer::calculateComponentsToInstall() @@ -1248,28 +1302,11 @@ bool PackageManagerCore::calculateComponentsToInstall() const emit aboutCalculateComponentsToInstall(); if (!d->m_componentsToInstallCalculated) { d->clearInstallerCalculator(); - QList<Component*> componentsToInstall; - const QList<Component*> relevant = components(ComponentType::Root | ComponentType::Descendants); - if (isUpdater()) { - foreach (Component *component, relevant) { - if (component->updateRequested()) - componentsToInstall.append(component); - } - } else if (!isUpdater()) { - // relevant means all components which are not replaced - foreach (Component *component, relevant) { - // ask for all components which will be installed to get all dependencies - // even dependencies which are changed without an increased version - if (component->installationRequested() || (component->isInstalled() - && !component->uninstallationRequested())) { - componentsToInstall.append(component); - } - } - } + QList<Component*> selectedComponentsToInstall = componentsMarkedForInstallation(); d->storeCheckState(); d->m_componentsToInstallCalculated = - d->installerCalculator()->appendComponentsToInstall(componentsToInstall); + d->installerCalculator()->appendComponentsToInstall(selectedComponentsToInstall); } emit finishedCalculateComponentsToInstall(); return d->m_componentsToInstallCalculated; @@ -2441,11 +2478,13 @@ QString PackageManagerCore::findDisplayVersion(const QString &componentName, ComponentModel *PackageManagerCore::componentModel(PackageManagerCore *core, const QString &objectName) const { - ComponentModel *model = new ComponentModel(5, core); + ComponentModel *model = new ComponentModel(ComponentModelHelper::LastColumn, core); model->setObjectName(objectName); model->setHeaderData(ComponentModelHelper::NameColumn, Qt::Horizontal, ComponentModel::tr("Component Name")); + model->setHeaderData(ComponentModelHelper::ActionColumn, Qt::Horizontal, + ComponentModel::tr("Action")); model->setHeaderData(ComponentModelHelper::InstalledVersionColumn, Qt::Horizontal, ComponentModel::tr("Installed Version")); model->setHeaderData(ComponentModelHelper::NewVersionColumn, Qt::Horizontal, diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h index df7ac5557..fb16cc29c 100644 --- a/src/libs/installer/packagemanagercore.h +++ b/src/libs/installer/packagemanagercore.h @@ -329,6 +329,7 @@ private: QString findDisplayVersion(const QString &componentName, const QHash<QString, QInstaller::Component*> &components, const QString& versionKey, QHash<QString, bool> &visited); ComponentModel *componentModel(PackageManagerCore *core, const QString &objectName) const; + QList<Component *> componentsMarkedForInstallation() const; private: PackageManagerCorePrivate *const d; diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index ba28c6871..467bf5408 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -1638,7 +1638,9 @@ bool PackageManagerCorePrivate::runPackageUpdater() } else if (isPackageManager()) { // We found the component, the component is still checked and the dependency solver did not // add the component as install dependency, keep it. - if (component && component->isSelected() && !componentsToInstall.contains(component)) { + if (component + && component->installAction() == ComponentModelHelper::KeepInstalled + && !componentsToInstall.contains(component)) { nonRevertedOperations.append(operation); continue; } diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp index ac258fe29..eed7bd066 100644 --- a/src/libs/installer/packagemanagergui.cpp +++ b/src/libs/installer/packagemanagergui.cpp @@ -1462,12 +1462,30 @@ public: m_treeView->setModel(m_currentModel); m_treeView->setExpanded(m_currentModel->index(0, 0), true); + const bool installActionColumnVisible = false; + if (!installActionColumnVisible) + m_treeView->hideColumn(ComponentModelHelper::ActionColumn); + if (m_core->isInstaller()) { m_treeView->setHeaderHidden(true); - for (int i = 1; i < m_currentModel->columnCount(); ++i) + for (int i = ComponentModelHelper::InstalledVersionColumn; i < m_currentModel->columnCount(); ++i) m_treeView->hideColumn(i); + + if (installActionColumnVisible) { + m_treeView->header()->setStretchLastSection(false); + m_treeView->header()->setSectionResizeMode( + ComponentModelHelper::NameColumn, QHeaderView::Stretch); + m_treeView->header()->setSectionResizeMode( + ComponentModelHelper::ActionColumn, QHeaderView::ResizeToContents); + } } else { m_treeView->header()->setStretchLastSection(true); + if (installActionColumnVisible) { + m_treeView->header()->setSectionResizeMode( + ComponentModelHelper::NameColumn, QHeaderView::Interactive); + m_treeView->header()->setSectionResizeMode( + ComponentModelHelper::ActionColumn, QHeaderView::Interactive); + } for (int i = 0; i < m_currentModel->columnCount(); ++i) m_treeView->resizeColumnToContents(i); } diff --git a/src/libs/installer/uninstallercalculator.cpp b/src/libs/installer/uninstallercalculator.cpp index 1b59fd42f..726ee735b 100644 --- a/src/libs/installer/uninstallercalculator.cpp +++ b/src/libs/installer/uninstallercalculator.cpp @@ -68,17 +68,11 @@ void UninstallerCalculator::appendComponentToUninstall(Component *component) foreach (Component *dependee, dependees) appendComponentToUninstall(dependee); - component->setCheckState(Qt::Unchecked); m_componentsToUninstall.insert(component); } void UninstallerCalculator::appendComponentsToUninstall(const QList<Component*> &components) { - if (components.isEmpty()) { - qDebug() << "components list is empty in" << Q_FUNC_INFO; - return; - } - foreach (Component *component, components) appendComponentToUninstall(component); |