From 30710bad704cc9fa2ad7c4efd534c3cd7d3b5cd7 Mon Sep 17 00:00:00 2001 From: pvdk Date: Sun, 15 Dec 2013 15:13:49 +0100 Subject: [PATCH] Modified components widget so the checked items can be stored for all pages to access --- apps/wizard/CMakeLists.txt | 6 +++ apps/wizard/componentselectionpage.cpp | 12 +++++- apps/wizard/componentselectionpage.hpp | 1 + apps/wizard/installationpage.cpp | 6 ++- apps/wizard/mainwizard.cpp | 2 + apps/wizard/utils/componentlistwidget.cpp | 46 +++++++++++++++++++++++ apps/wizard/utils/componentlistwidget.hpp | 29 ++++++++++++++ files/ui/wizard/componentselectionpage.ui | 13 +++++-- 8 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 apps/wizard/utils/componentlistwidget.cpp create mode 100644 apps/wizard/utils/componentlistwidget.hpp diff --git a/apps/wizard/CMakeLists.txt b/apps/wizard/CMakeLists.txt index a62327d85..741f790b5 100644 --- a/apps/wizard/CMakeLists.txt +++ b/apps/wizard/CMakeLists.txt @@ -10,6 +10,8 @@ set(WIZARD main.cpp mainwizard.cpp methodselectionpage.cpp + + utils/componentlistwidget.cpp ) # if(NOT WIN32) # LIST(APPEND WIZARD unshieldthread.cpp) @@ -26,6 +28,8 @@ set(WIZARD_HEADER languageselectionpage.hpp mainwizard.hpp methodselectionpage.hpp + + utils/componentlistwidget.hpp ) # if(NOT WIN32) # LIST(APPEND WIZARD_HEADER unshieldthread.hpp) @@ -44,6 +48,8 @@ set(WIZARD_HEADER_MOC languageselectionpage.hpp mainwizard.hpp methodselectionpage.hpp + + utils/componentlistwidget.hpp ) # if(NOT WIN32) diff --git a/apps/wizard/componentselectionpage.cpp b/apps/wizard/componentselectionpage.cpp index b5618c677..50e6e8ef4 100644 --- a/apps/wizard/componentselectionpage.cpp +++ b/apps/wizard/componentselectionpage.cpp @@ -14,8 +14,16 @@ Wizard::ComponentSelectionPage::ComponentSelectionPage(MainWizard *wizard) : setCommitPage(true); setButtonText(QWizard::CommitButton, tr("&Install")); - connect(componentsList, SIGNAL(itemChanged(QListWidgetItem*)), - this, SLOT(updateButton(QListWidgetItem*))); + registerField("installation.components", componentsList); + + connect(componentsList, SIGNAL(itemChanged(QListWidgetItem *)), + this, SLOT(updateButton(QListWidgetItem *))); + +} + +void Wizard::ComponentSelectionPage::debugMe(QString &text) +{ + qDebug() << "Debug Me" << text; } void Wizard::ComponentSelectionPage::updateButton(QListWidgetItem *item) diff --git a/apps/wizard/componentselectionpage.hpp b/apps/wizard/componentselectionpage.hpp index 8b4c186d0..f5e955782 100644 --- a/apps/wizard/componentselectionpage.hpp +++ b/apps/wizard/componentselectionpage.hpp @@ -19,6 +19,7 @@ namespace Wizard private slots: void updateButton(QListWidgetItem *item); + void debugMe(QString &text); private: MainWizard *mWizard; diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index 1053c3240..632b9c6a6 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -14,9 +14,11 @@ Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : void Wizard::InstallationPage::initializePage() { QString path = field("installation.path").toString(); + QStringList components = field("installation.components").toStringList(); + + logTextEdit->append(QString("Installing to %1").arg(path)); + logTextEdit->append(QString("Installing %1.").arg(components.join(", "))); - qDebug() << "installing to: " << field("installation.path").toString(); - logTextEdit->setText(QString("Installing to %1").arg(field("installation.path").toString())); } int Wizard::InstallationPage::nextId() const diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index 58ef2e061..e752d0455 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -28,6 +28,8 @@ Wizard::MainWizard::MainWizard(QWidget *parent) : // Set the property for comboboxes to the text instead of index setDefaultProperty("QComboBox", "currentText", "currentIndexChanged"); + setDefaultProperty("ComponentListWidget", "mCheckedItems", "checkedItemsChanged"); + setupInstallations(); setupPages(); } diff --git a/apps/wizard/utils/componentlistwidget.cpp b/apps/wizard/utils/componentlistwidget.cpp new file mode 100644 index 000000000..c9a1c1940 --- /dev/null +++ b/apps/wizard/utils/componentlistwidget.cpp @@ -0,0 +1,46 @@ +#include "componentlistwidget.hpp" + +#include +#include + +ComponentListWidget::ComponentListWidget(QWidget *parent) : + QListWidget(parent) +{ + mCheckedItems = QStringList(); + + connect(this, SIGNAL(itemChanged(QListWidgetItem *)), + this, SLOT(updateCheckedItems(QListWidgetItem *))); +} + +void ComponentListWidget::addItem(QListWidgetItem *item) +{ + // The model does not emit a dataChanged signal when items are added + // So we need to update manually + QListWidget::insertItem(count(), item); + updateCheckedItems(item); + +} + +QStringList ComponentListWidget::checkedItems() +{ + mCheckedItems.removeDuplicates(); + return mCheckedItems; +} + +void ComponentListWidget::updateCheckedItems(QListWidgetItem *item) +{ + QString text = item->text(); + + if (item->checkState() == Qt::Checked) { + if (!mCheckedItems.contains(text)) + mCheckedItems.append(text); + } else { + if (mCheckedItems.contains(text)) + mCheckedItems.removeAll(text); + } + + mCheckedItems.removeDuplicates(); + + emit checkedItemsChanged(mCheckedItems); + +} diff --git a/apps/wizard/utils/componentlistwidget.hpp b/apps/wizard/utils/componentlistwidget.hpp new file mode 100644 index 000000000..c9c782d45 --- /dev/null +++ b/apps/wizard/utils/componentlistwidget.hpp @@ -0,0 +1,29 @@ +#ifndef COMPONENTLISTWIDGET_HPP +#define COMPONENTLISTWIDGET_HPP + +#include + +class ComponentListWidget : public QListWidget +{ + Q_OBJECT + + Q_PROPERTY(QStringList mCheckedItems READ checkedItems) + +public: + ComponentListWidget(QWidget *parent = 0); + + QStringList mCheckedItems; + QStringList checkedItems(); + + void addItem(QListWidgetItem *item); + +signals: + void checkedItemsChanged(const QStringList &items); + +private slots: + void updateCheckedItems(QListWidgetItem *item); +}; + + + +#endif // COMPONENTLISTWIDGET_HPP diff --git a/files/ui/wizard/componentselectionpage.ui b/files/ui/wizard/componentselectionpage.ui index c3333752a..026fcdff6 100644 --- a/files/ui/wizard/componentselectionpage.ui +++ b/files/ui/wizard/componentselectionpage.ui @@ -6,8 +6,8 @@ 0 0 - 454 - 393 + 448 + 387 @@ -38,7 +38,7 @@ - + @@ -55,6 +55,13 @@ + + + ComponentListWidget + QListWidget +
apps/wizard/utils/componentlistwidget.hpp
+
+