diff options
Diffstat (limited to 'src/libs/installer/componentselectionpage_p.cpp')
-rw-r--r-- | src/libs/installer/componentselectionpage_p.cpp | 391 |
1 files changed, 244 insertions, 147 deletions
diff --git a/src/libs/installer/componentselectionpage_p.cpp b/src/libs/installer/componentselectionpage_p.cpp index 5e44d153c..b68eebf06 100644 --- a/src/libs/installer/componentselectionpage_p.cpp +++ b/src/libs/installer/componentselectionpage_p.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2022 The Qt Company Ltd. +** Copyright (C) 2024 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -28,12 +28,14 @@ #include "componentselectionpage_p.h" +#include "globals.h" #include "packagemanagergui.h" #include "componentmodel.h" #include "settings.h" #include "component.h" #include "fileutils.h" #include "messageboxhandler.h" +#include "customcombobox.h" #include <QTreeView> #include <QLabel> @@ -44,13 +46,13 @@ #include <QVBoxLayout> #include <QHBoxLayout> #include <QCheckBox> -#include <QHeaderView> #include <QStandardPaths> #include <QFileDialog> #include <QStackedLayout> #include <QStackedWidget> -#include <QToolBox> #include <QLineEdit> +#include <QStandardItemModel> +#include <QStyledItemDelegate> namespace QInstaller { @@ -60,23 +62,29 @@ namespace QInstaller { \internal */ +constexpr int scNoCheckSelectionIndex = -1; +constexpr int scCheckDefaultIndex = 0; +constexpr int scCheckAllIndex = 1; +constexpr int scUncheckAllIndex = 2; + ComponentSelectionPagePrivate::ComponentSelectionPagePrivate(ComponentSelectionPage *qq, PackageManagerCore *core) : q(qq) , m_core(core) , m_treeView(new QTreeView(q)) - , m_allModel(m_core->defaultComponentModel()) - , m_updaterModel(m_core->updaterComponentModel()) - , m_currentModel(m_allModel) - , m_allowCompressedRepositoryInstall(false) - , m_toolBox(nullptr) + , m_tabWidget(nullptr) , m_descriptionBaseWidget(nullptr) , m_categoryWidget(Q_NULLPTR) + , m_allowCreateOfflineInstaller(false) , m_categoryLayoutVisible(false) - , m_proxyModel(new ComponentSortFilterProxyModel(q)) + , m_allModel(m_core->defaultComponentModel()) + , m_updaterModel(m_core->updaterComponentModel()) + , m_currentModel(m_allModel) + , m_proxyModel(m_core->componentSortFilterProxyModel()) + , m_componentsResolved(false) + , m_headerStretchLastSection(false) { m_treeView->setObjectName(QLatin1String("ComponentsTreeView")); - m_proxyModel->setRecursiveFilteringEnabled(true); - m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_treeView->setUniformRowHeights(true); m_descriptionBaseWidget = new QWidget(q); m_descriptionBaseWidget->setObjectName(QLatin1String("DescriptionBaseWidget")); @@ -85,8 +93,12 @@ ComponentSelectionPagePrivate::ComponentSelectionPagePrivate(ComponentSelectionP descriptionVLayout->setObjectName(QLatin1String("DescriptionLayout")); descriptionVLayout->setContentsMargins(0, 0, 0, 0); - m_toolBox = new QToolBox(q); - m_toolBox->setObjectName(QLatin1String("ToolBox")); + m_tabWidget = new QTabWidget(q); + m_tabWidget->setObjectName(QLatin1String("ComponentSelectionTabWidget")); + m_tabWidget->tabBar()->setObjectName(QLatin1String("ComponentSelectionTabBar")); + m_tabWidget->hide(); + + m_rightSideVLayout = new QVBoxLayout; QScrollArea *descriptionScrollArea = new QScrollArea(q); descriptionScrollArea->setWidgetResizable(true); @@ -107,46 +119,67 @@ ComponentSelectionPagePrivate::ComponentSelectionPagePrivate(ComponentSelectionP m_sizeLabel->setObjectName(QLatin1String("ComponentSizeLabel")); descriptionVLayout->addWidget(m_sizeLabel); - QHBoxLayout *buttonHLayout = new QHBoxLayout; - m_checkDefault = new QPushButton; - connect(m_checkDefault, &QAbstractButton::clicked, - this, &ComponentSelectionPagePrivate::selectDefault); + m_createOfflinePushButton = new QPushButton(q); + m_createOfflinePushButton->setVisible(false); + m_createOfflinePushButton->setText(ComponentSelectionPage::tr("Create Offline Installer")); + m_createOfflinePushButton->setToolTip( + ComponentSelectionPage::tr("Create offline installer from selected components, instead " + "of installing now.")); + + connect(m_createOfflinePushButton, &QPushButton::clicked, + this, &ComponentSelectionPagePrivate::createOfflineButtonClicked); + connect(q, &ComponentSelectionPage::completeChanged, + this, [&]() { m_createOfflinePushButton->setEnabled(q->isComplete()); }); + + m_qbspPushButton = new QPushButton(q); + m_qbspPushButton->setVisible(false); + m_qbspPushButton->setText(ComponentSelectionPage::tr("Browse &QBSP files")); + m_qbspPushButton->setToolTip( + ComponentSelectionPage::tr("Select a Qt Board Support Package file to install " + "additional content that is not directly available from the online repositories.")); + + connect(m_qbspPushButton, &QPushButton::clicked, + this, &ComponentSelectionPagePrivate::qbspButtonClicked); + + m_rightSideVLayout->addWidget(m_descriptionBaseWidget); + m_rightSideVLayout->addWidget(m_createOfflinePushButton); + m_rightSideVLayout->addWidget(m_qbspPushButton); + + QHBoxLayout *topHLayout = new QHBoxLayout; + + // Using custom combobox to workaround QTBUG-90595 + m_checkStateComboBox = new CustomComboBox(q); +#ifdef Q_OS_MACOS + QStyledItemDelegate *delegate = new QStyledItemDelegate(this); + m_checkStateComboBox->setItemDelegate(delegate); +#endif + m_checkStateComboBox->setObjectName(QLatin1String("CheckStateComboBox")); + topHLayout->addWidget(m_checkStateComboBox); + + connect(m_checkStateComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), + this, &ComponentSelectionPagePrivate::updateAllCheckStates); + + // Workaround invisible placeholder text + QPalette palette = m_checkStateComboBox->palette(); + palette.setColor(QPalette::PlaceholderText, palette.color(QPalette::Text)); + m_checkStateComboBox->setPalette(palette); + + m_checkStateComboBox->setPlaceholderText(ComponentSelectionPage::tr("Select")); if (m_core->isInstaller()) { - m_checkDefault->setObjectName(QLatin1String("SelectDefaultComponentsButton")); - m_checkDefault->setShortcut(QKeySequence(ComponentSelectionPage::tr("Alt+A", - "Select default components"))); - m_checkDefault->setText(ComponentSelectionPage::tr("Def&ault")); - m_checkDefault->setToolTip(ComponentSelectionPage::tr("Select default components in the tree view.")); + m_checkStateComboBox->insertItem(scCheckDefaultIndex, ComponentSelectionPage::tr("Default")); + m_checkStateComboBox->setItemData(scCheckDefaultIndex, + ComponentSelectionPage::tr("Select default components in the tree view."), Qt::ToolTipRole); } else { - m_checkDefault->setEnabled(false); - m_checkDefault->setObjectName(QLatin1String("ResetComponentsButton")); - m_checkDefault->setShortcut(QKeySequence(ComponentSelectionPage::tr("Alt+R", - "Reset to already installed components"))); - m_checkDefault->setText(ComponentSelectionPage::tr("&Reset")); - m_checkDefault->setToolTip( - ComponentSelectionPage::tr("Reset all components to their original selection state in the tree view.")); + m_checkStateComboBox->insertItem(scCheckDefaultIndex, ComponentSelectionPage::tr("Reset")); + m_checkStateComboBox->setItemData(scCheckDefaultIndex, + ComponentSelectionPage::tr("Reset all components to their original selection state in the tree view."), Qt::ToolTipRole); } - buttonHLayout->addWidget(m_checkDefault); - - m_checkAll = new QPushButton; - connect(m_checkAll, &QAbstractButton::clicked, - this, &ComponentSelectionPagePrivate::selectAll); - m_checkAll->setObjectName(QLatin1String("SelectAllComponentsButton")); - m_checkAll->setShortcut(QKeySequence(ComponentSelectionPage::tr("Alt+S", - "Select all components"))); - m_checkAll->setText(ComponentSelectionPage::tr("&Select All")); - m_checkAll->setToolTip(ComponentSelectionPage::tr("Select all components in the tree view.")); - buttonHLayout->addWidget(m_checkAll); - - m_uncheckAll = new QPushButton; - connect(m_uncheckAll, &QAbstractButton::clicked, - this, &ComponentSelectionPagePrivate::deselectAll); - m_uncheckAll->setObjectName(QLatin1String("DeselectAllComponentsButton")); - m_uncheckAll->setShortcut(QKeySequence(ComponentSelectionPage::tr("Alt+D", - "Deselect all components"))); - m_uncheckAll->setText(ComponentSelectionPage::tr("&Deselect All")); - m_uncheckAll->setToolTip(ComponentSelectionPage::tr("Deselect all components in the tree view.")); - buttonHLayout->addWidget(m_uncheckAll); + m_checkStateComboBox->insertItem(scCheckAllIndex, ComponentSelectionPage::tr("Select All")); + m_checkStateComboBox->setItemData(scCheckAllIndex, + ComponentSelectionPage::tr("Select all components in the tree view."), Qt::ToolTipRole); + m_checkStateComboBox->insertItem(scUncheckAllIndex, ComponentSelectionPage::tr("Deselect All")); + m_checkStateComboBox->setItemData(scUncheckAllIndex, + ComponentSelectionPage::tr("Deselect all components in the tree view."), Qt::ToolTipRole); QWidget *progressStackedWidget = new QWidget(); QVBoxLayout *metaLayout = new QVBoxLayout(progressStackedWidget); @@ -166,17 +199,24 @@ ComponentSelectionPagePrivate::ComponentSelectionPagePrivate(ComponentSelectionP connect(m_searchLineEdit, &QLineEdit::textChanged, this, &ComponentSelectionPagePrivate::setSearchPattern); connect(q, &ComponentSelectionPage::entered, m_searchLineEdit, &QLineEdit::clear); + topHLayout->addWidget(m_searchLineEdit); QVBoxLayout *treeViewVLayout = new QVBoxLayout; treeViewVLayout->setObjectName(QLatin1String("TreeviewLayout")); treeViewVLayout->addWidget(m_treeView, 3); - treeViewVLayout->addWidget(m_searchLineEdit); QWidget *mainStackedWidget = new QWidget(); m_mainGLayout = new QGridLayout(mainStackedWidget); - m_mainGLayout->addLayout(buttonHLayout, 0, 0); + { + int left = 0; + int top = 0; + int bottom = 0; + m_mainGLayout->getContentsMargins(&left, &top, nullptr, &bottom); + m_mainGLayout->setContentsMargins(left, top, 0, bottom); + } + m_mainGLayout->addLayout(topHLayout, 0, 0); m_mainGLayout->addLayout(treeViewVLayout, 1, 0); - m_mainGLayout->addWidget(m_descriptionBaseWidget, 1, 1); + m_mainGLayout->addLayout(m_rightSideVLayout, 0, 1, 0, -1); m_mainGLayout->setColumnStretch(0, 3); m_mainGLayout->setColumnStretch(1, 2); @@ -185,25 +225,15 @@ ComponentSelectionPagePrivate::ComponentSelectionPagePrivate(ComponentSelectionP m_stackedLayout->addWidget(progressStackedWidget); m_stackedLayout->setCurrentIndex(0); - connect(m_allModel, &ComponentModel::modelCheckStateChanged, - this, &ComponentSelectionPagePrivate::onModelStateChanged); - connect(m_updaterModel, &ComponentModel::modelCheckStateChanged, - this, &ComponentSelectionPagePrivate::onModelStateChanged); - - connect(m_allModel, &ComponentModel::componentsCheckStateChanged, this, - [=]() { onModelStateChanged(m_allModel->checkedState());}); - - connect(m_updaterModel, &ComponentModel::componentsCheckStateChanged, this, - [=]() { onModelStateChanged(m_allModel->checkedState());}); + connect(m_allModel, &ComponentModel::checkStateChanged, + this, &ComponentSelectionPagePrivate::onModelStateChanged); + connect(m_updaterModel, &ComponentModel::checkStateChanged, + this, &ComponentSelectionPagePrivate::onModelStateChanged); connect(m_core, SIGNAL(metaJobProgress(int)), this, SLOT(onProgressChanged(int))); connect(m_core, SIGNAL(metaJobInfoMessage(QString)), this, SLOT(setMessage(QString))); connect(m_core, &PackageManagerCore::metaJobTotalProgress, this, &ComponentSelectionPagePrivate::setTotalProgress); - -#ifdef INSTALLCOMPRESSED - allowCompressedRepositoryInstall(); -#endif } ComponentSelectionPagePrivate::~ComponentSelectionPagePrivate() @@ -211,36 +241,28 @@ ComponentSelectionPagePrivate::~ComponentSelectionPagePrivate() } -void ComponentSelectionPagePrivate::allowCompressedRepositoryInstall() +void ComponentSelectionPagePrivate::setAllowCreateOfflineInstaller(bool allow) { - m_allowCompressedRepositoryInstall = true; + m_allowCreateOfflineInstaller = allow; } void ComponentSelectionPagePrivate::showCompressedRepositoryButton() { - QWizard *wizard = qobject_cast<QWizard*>(m_core->guiObject()); - if (wizard && !(wizard->options() & QWizard::HaveCustomButton2) && m_allowCompressedRepositoryInstall) { - wizard->setOption(QWizard::HaveCustomButton2, true); - wizard->setButtonText(QWizard::CustomButton2, - ComponentSelectionPage::tr("&Browse QBSP files")); - wizard->button(QWizard::CustomButton2)->setToolTip( - ComponentSelectionPage::tr("Select a Qt Board Support Package file to install " - "additional content that is not directly available from the online repositories.")); - connect(wizard, &QWizard::customButtonClicked, - this, &ComponentSelectionPagePrivate::customButtonClicked); - q->gui()->updateButtonLayout(); - } + if (m_core->allowCompressedRepositoryInstall()) + m_qbspPushButton->setVisible(true); } void ComponentSelectionPagePrivate::hideCompressedRepositoryButton() { - QWizard *wizard = qobject_cast<QWizard*>(m_core->guiObject()); - if (wizard && (wizard->options() & QWizard::HaveCustomButton2)) { - wizard->setOption(QWizard::HaveCustomButton2, false); - disconnect(wizard, &QWizard::customButtonClicked, - this, &ComponentSelectionPagePrivate::customButtonClicked); - q->gui()->updateButtonLayout(); - } + m_qbspPushButton->setVisible(false); +} + +void ComponentSelectionPagePrivate::showCreateOfflineInstallerButton(bool show) +{ + if (show && m_allowCreateOfflineInstaller) + m_createOfflinePushButton->setVisible(m_core->isInstaller() && !m_core->isOfflineOnly()); + else + m_createOfflinePushButton->setVisible(false); } void ComponentSelectionPagePrivate::setupCategoryLayout() @@ -274,7 +296,7 @@ void ComponentSelectionPagePrivate::setupCategoryLayout() vLayout->addWidget(m_categoryGroupBox); vLayout->addStretch(); - m_toolBox->insertItem(1, m_categoryWidget, m_core->settings().repositoryCategoryDisplayName()); + m_tabWidget->insertTab(1, m_categoryWidget, m_core->settings().repositoryCategoryDisplayName()); } void ComponentSelectionPagePrivate::showCategoryLayout(bool show) @@ -287,27 +309,27 @@ void ComponentSelectionPagePrivate::showCategoryLayout(bool show) setupCategoryLayout(); if (show) { - m_mainGLayout->removeWidget(m_descriptionBaseWidget); - m_toolBox->insertItem(0, m_descriptionBaseWidget, tr("Component Information")); - m_mainGLayout->addWidget(m_toolBox, 1, 1); + m_rightSideVLayout->removeWidget(m_descriptionBaseWidget); + m_tabWidget->insertTab(0, m_descriptionBaseWidget, tr("Information")); + m_rightSideVLayout->insertWidget(0, m_tabWidget); } else { - m_toolBox->removeItem(0); - m_mainGLayout->removeWidget(m_toolBox); - m_mainGLayout->addWidget(m_descriptionBaseWidget, 1, 1); + m_tabWidget->removeTab(0); + m_rightSideVLayout->removeWidget(m_tabWidget); + m_rightSideVLayout->insertWidget(0, m_descriptionBaseWidget); + m_descriptionBaseWidget->setVisible(true); } - m_toolBox->setVisible(show); + m_tabWidget->setVisible(show); m_categoryLayoutVisible = show; } void ComponentSelectionPagePrivate::updateTreeView() { - m_checkDefault->setVisible(m_core->isInstaller() || m_core->isPackageManager()); + setComboBoxItemEnabled(scCheckDefaultIndex, m_core->isInstaller() || m_core->isPackageManager()); if (m_treeView->selectionModel()) { disconnect(m_treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ComponentSelectionPagePrivate::currentSelectedChanged); } - m_searchLineEdit->setVisible(!m_core->isUpdater()); m_currentModel = m_core->isUpdater() ? m_updaterModel : m_allModel; m_proxyModel->setSourceModel(m_currentModel); m_treeView->setModel(m_proxyModel); @@ -375,6 +397,9 @@ void ComponentSelectionPagePrivate::expandDefault() */ void ComponentSelectionPagePrivate::expandSearchResults() { + // Avoid resizing the sections after each expand of a node + storeHeaderResizeModes(); + // Expand parents of root indexes accepted by filter const QVector<QModelIndex> acceptedIndexes = m_proxyModel->directlyAcceptedIndexes(); for (auto proxyModelIndex : acceptedIndexes) { @@ -390,6 +415,16 @@ void ComponentSelectionPagePrivate::expandSearchResults() index = index.parent(); } } + restoreHeaderResizeModes(); +} + +/*! + Returns \c true if the components to install and uninstall are calculated + successfully, \c false otherwise. +*/ +bool ComponentSelectionPagePrivate::componentsResolved() const +{ + return m_componentsResolved; } void ComponentSelectionPagePrivate::currentSelectedChanged(const QModelIndex ¤t) @@ -415,6 +450,32 @@ void ComponentSelectionPagePrivate::currentSelectedChanged(const QModelIndex &cu } } +/*! + Updates the checkstate of the components based on the value of \c which. +*/ +void ComponentSelectionPagePrivate::updateAllCheckStates(int which) +{ + switch (which) { + case scNoCheckSelectionIndex: + // A 'helper' text index, no selection + return; + case scCheckDefaultIndex: + selectDefault(); + break; + case scCheckAllIndex: + selectAll(); + break; + case scUncheckAllIndex: + deselectAll(); + break; + default: + qCWarning(lcInstallerInstallLog) << "Invalid index for check state selection!"; + break; + } + // Reset back to 'helper' text index + m_checkStateComboBox->setCurrentIndex(scNoCheckSelectionIndex); +} + void ComponentSelectionPagePrivate::selectAll() { m_currentModel->setCheckedState(ComponentModel::AllChecked); @@ -425,27 +486,6 @@ void ComponentSelectionPagePrivate::deselectAll() m_currentModel->setCheckedState(ComponentModel::AllUnchecked); } -void ComponentSelectionPagePrivate::enableRepositoryCategory(const QString &repositoryName, bool enable) -{ - QMap<QString, RepositoryCategory> organizedRepositoryCategories = m_core->settings().organizedRepositoryCategories(); - - QMap<QString, RepositoryCategory>::iterator i = organizedRepositoryCategories.find(repositoryName); - RepositoryCategory repoCategory; - while (i != organizedRepositoryCategories.end() && i.key() == repositoryName) { - repoCategory = i.value(); - i++; - } - - RepositoryCategory replacement = repoCategory; - replacement.setEnabled(enable); - QSet<RepositoryCategory> tmpRepoCategories = m_core->settings().repositoryCategories(); - if (tmpRepoCategories.contains(repoCategory)) { - tmpRepoCategories.remove(repoCategory); - tmpRepoCategories.insert(replacement); - m_core->settings().addRepositoryCategories(tmpRepoCategories); - } -} - void ComponentSelectionPagePrivate::updateWidgetVisibility(bool show) { if (show) @@ -453,8 +493,12 @@ void ComponentSelectionPagePrivate::updateWidgetVisibility(bool show) else m_stackedLayout->setCurrentIndex(0); - if (QAbstractButton *bspButton = q->gui()->button(QWizard::CustomButton2)) - bspButton->setEnabled(!show); + m_qbspPushButton->setEnabled(!show); + + if (show) { + q->gui()->button(QWizard::NextButton)->setEnabled(false); + q->gui()->button(QWizard::BackButton)->setEnabled(false); + } // In macOS 10.12 the widgets are not hidden if those are not updated immediately #ifdef Q_OS_MACOS @@ -469,7 +513,7 @@ void ComponentSelectionPagePrivate::fetchRepositoryCategories() QList<QCheckBox*> checkboxes = m_categoryGroupBox->findChildren<QCheckBox *>(); for (int i = 0; i < checkboxes.count(); i++) { QCheckBox *checkbox = checkboxes.at(i); - enableRepositoryCategory(checkbox->objectName(), checkbox->isChecked()); + m_core->enableRepositoryCategory(checkbox->objectName(), checkbox->isChecked()); } if (!m_core->fetchRemotePackagesTree()) { @@ -480,31 +524,28 @@ void ComponentSelectionPagePrivate::fetchRepositoryCategories() m_searchLineEdit->text().isEmpty() ? expandDefault() : expandSearchResults(); } -void ComponentSelectionPagePrivate::customButtonClicked(int which) +void ComponentSelectionPagePrivate::createOfflineButtonClicked() { - if (QWizard::WizardButton(which) == QWizard::CustomButton2) { - QString defaultDownloadDirectory = - QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, - ComponentSelectionPage::tr("Open File"),defaultDownloadDirectory, - QLatin1String("QBSP or 7z Files (*.qbsp *.7z)")); - - QSet<Repository> set; - foreach (QString fileName, fileNames) { - Repository repository = Repository::fromUserInput(fileName, true); - repository.setEnabled(true); - set.insert(repository); - } - if (set.count() > 0) { - updateWidgetVisibility(true); - m_core->settings().addTemporaryRepositories(set, false); - if (!m_core->fetchCompressedPackagesTree()) { - MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), - QLatin1String("FailToFetchPackages"), tr("Error"), m_core->error()); - } + m_core->setOfflineGenerator(); + q->gui()->button(QWizard::NextButton)->click(); +} + +void ComponentSelectionPagePrivate::qbspButtonClicked() +{ + QString defaultDownloadDirectory = + QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + QStringList fileNames = QFileDialog::getOpenFileNames(nullptr, + ComponentSelectionPage::tr("Open File"),defaultDownloadDirectory, + QLatin1String("QBSP or 7z Files (*.qbsp *.7z)")); + + if (m_core->addQBspRepositories(fileNames)) { + updateWidgetVisibility(true); + if (!m_core->fetchCompressedPackagesTree()) { + MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), + QLatin1String("FailToFetchPackages"), tr("Error"), m_core->error()); } - updateWidgetVisibility(false); } + updateWidgetVisibility(false); } /*! @@ -538,6 +579,21 @@ void ComponentSelectionPagePrivate::selectDefault() void ComponentSelectionPagePrivate::onModelStateChanged(QInstaller::ComponentModel::ModelState state) { + if (state.testFlag(ComponentModel::Empty)) { + setComboBoxItemEnabled(scCheckAllIndex, false); + setComboBoxItemEnabled(scUncheckAllIndex, false); + setComboBoxItemEnabled(scCheckDefaultIndex, false); + return; + } + + m_componentsResolved = m_core->recalculateAllComponents(); + if (!m_componentsResolved) { + const QString error = !m_core->componentsToInstallError().isEmpty() + ? m_core->componentsToInstallError() : m_core->componentsToUninstallError(); + MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), + QLatin1String("CalculateComponentsError"), tr("Error"), error); + } + q->setModified(state.testFlag(ComponentModel::DefaultChecked) == false); // If all components in the checked list are only checkable when run without forced // installation, set ComponentModel::AllUnchecked as well, as we cannot uncheck anything. @@ -547,9 +603,9 @@ void ComponentSelectionPagePrivate::onModelStateChanged(QInstaller::ComponentMod state |= ComponentModel::AllUnchecked; } // enable the button if the corresponding flag is not set - m_checkAll->setEnabled(state.testFlag(ComponentModel::AllChecked) == false); - m_uncheckAll->setEnabled(state.testFlag(ComponentModel::AllUnchecked) == false); - m_checkDefault->setEnabled(state.testFlag(ComponentModel::DefaultChecked) == false); + setComboBoxItemEnabled(scCheckAllIndex, state.testFlag(ComponentModel::AllChecked) == false); + setComboBoxItemEnabled(scUncheckAllIndex, state.testFlag(ComponentModel::AllUnchecked) == false); + setComboBoxItemEnabled(scCheckDefaultIndex, state.testFlag(ComponentModel::DefaultChecked) == false); // update the current selected node (important to reflect possible sub-node changes) if (m_treeView->selectionModel()) @@ -578,4 +634,45 @@ void ComponentSelectionPagePrivate::setSearchPattern(const QString &text) } } +/*! + Stores the current resize modes of the tree view header's columns, and sets + the new resize modes to \c QHeaderView::Fixed. +*/ +void ComponentSelectionPagePrivate::storeHeaderResizeModes() +{ + m_headerStretchLastSection = m_treeView->header()->stretchLastSection(); + for (int i = 0; i < ComponentModelHelper::LastColumn; ++i) + m_headerResizeModes.insert(i, m_treeView->header()->sectionResizeMode(i)); + + m_treeView->header()->setStretchLastSection(false); + m_treeView->header()->setSectionResizeMode(QHeaderView::Fixed); +} + +/*! + Restores the resize modes of the tree view header's columns, that were + stored when calling \l storeHeaderResizeModes(). +*/ +void ComponentSelectionPagePrivate::restoreHeaderResizeModes() +{ + m_treeView->header()->setStretchLastSection(m_headerStretchLastSection); + for (int i = 0; i < ComponentModelHelper::LastColumn; ++i) + m_treeView->header()->setSectionResizeMode(i, m_headerResizeModes.value(i)); +} + +/*! + Sets the enabled state of the combo box item in \a index to \a enabled. +*/ +void ComponentSelectionPagePrivate::setComboBoxItemEnabled(int index, bool enabled) +{ + auto *model = qobject_cast<QStandardItemModel *>(m_checkStateComboBox->model()); + if (!model) + return; + + QStandardItem *item = model->item(index); + if (!item) + return; + + item->setEnabled(enabled); +} + } // namespace QInstaller |