diff --git a/src/modules/summary/CMakeLists.txt b/src/modules/summary/CMakeLists.txt index 16f98ebb4..671cf569d 100644 --- a/src/modules/summary/CMakeLists.txt +++ b/src/modules/summary/CMakeLists.txt @@ -9,6 +9,7 @@ calamares_add_plugin(summary EXPORT_MACRO PLUGINDLLEXPORT_PRO SOURCES Config.cpp + SummaryModel.cpp SummaryPage.cpp SummaryViewStep.cpp UI diff --git a/src/modules/summary/Config.cpp b/src/modules/summary/Config.cpp index 75fed6817..be0d8cb0c 100644 --- a/src/modules/summary/Config.cpp +++ b/src/modules/summary/Config.cpp @@ -10,6 +10,8 @@ #include "Config.h" +#include "SummaryModel.h" + #include "Branding.h" #include "Settings.h" #include "ViewManager.h" @@ -18,67 +20,6 @@ #include "utils/Retranslator.h" #include "viewpages/ExecutionViewStep.h" -SummaryModel::SummaryModel( QObject* parent ) - : QAbstractListModel( parent ) -{ -} - -QHash< int, QByteArray > -SummaryModel::roleNames() const -{ - // Not including WidgetRole here because that wouldn't make sense - // in a QML context which is where the roleNames are important. - return { { TitleRole, "title" }, { MessageRole, "message" } }; -} - -QVariant -SummaryModel::data( const QModelIndex& index, int role ) const -{ - if ( !index.isValid() ) - { - return QVariant(); - } - auto& item = m_summary.at( index.row() ); - switch ( role ) - { - case TitleRole: - return item.title; - case MessageRole: - return item.message; - case WidgetRole: - return item.widget ? QVariant::fromValue( item.widget ) : QVariant(); - default: - return QVariant(); - } -} - -int -SummaryModel::rowCount( const QModelIndex& ) const -{ - return m_summary.count(); -} - -void -SummaryModel::setSummaryList( const Calamares::ViewStepList& steps, bool withWidgets ) -{ - beginResetModel(); - m_summary.clear(); - - for ( Calamares::ViewStep* step : steps ) - { - QString text = step->prettyStatus(); - QWidget* widget = withWidgets ? step->createSummaryWidget() : nullptr; - - if ( text.isEmpty() && !widget ) - { - continue; - } - - m_summary << StepSummary { step->prettyName(), text, widget }; - } - endResetModel(); -} - Config::Config( QObject* parent ) : QObject( parent ) , m_summary( new SummaryModel( this ) ) diff --git a/src/modules/summary/Config.h b/src/modules/summary/Config.h index f0732f448..25381b126 100644 --- a/src/modules/summary/Config.h +++ b/src/modules/summary/Config.h @@ -11,60 +11,10 @@ #ifndef SUMMARY_CONFIG_H #define SUMMARY_CONFIG_H +#include "SummaryModel.h" + #include "viewpages/ViewStep.h" -#include -#include -#include - -class Config; - -/** @brief Data for one step - * - * A step generally has a text description, but **may** have a - * QWidget. There is no ownership of the QWidget, that is assumed - * to be handed off to some owning parent-widget. - */ -struct StepSummary -{ - QString title; - QString message; - QWidget* widget = nullptr; -}; - -class SummaryModel : public QAbstractListModel -{ - Q_OBJECT - friend class Config; - -public: - enum Roles : int - { - TitleRole = Qt::DisplayRole, // Name of the step - MessageRole = Qt::UserRole, // String saying what it will do - WidgetRole, // Pointer to widget - }; - - explicit SummaryModel( QObject* parent = nullptr ); - int rowCount( const QModelIndex& = QModelIndex() ) const override; - QVariant data( const QModelIndex& index, int role ) const override; - -protected: - QHash< int, QByteArray > roleNames() const override; - -private: - /** @brief Sets the model data from @p steps - * - * Replaces the list of summaries with summaries given by - * the jobs and ViewSteps objects in @p steps. If @p withWidgets - * is @c true, then also queries for widget summaries alongside - * the text summaries for each step. - */ - void setSummaryList( const Calamares::ViewStepList& steps, bool withWidgets = false ); - - QVector< StepSummary > m_summary; -}; - class Config : public QObject { Q_OBJECT diff --git a/src/modules/summary/SummaryModel.cpp b/src/modules/summary/SummaryModel.cpp new file mode 100644 index 000000000..be8b062e0 --- /dev/null +++ b/src/modules/summary/SummaryModel.cpp @@ -0,0 +1,74 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2020, Camilo Higuita + * SPDX-FileCopyrightText: 2021 Anke Boersma + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#include "SummaryModel.h" + +#include + +SummaryModel::SummaryModel( QObject* parent ) + : QAbstractListModel( parent ) +{ +} + +QHash< int, QByteArray > +SummaryModel::roleNames() const +{ + // Not including WidgetRole here because that wouldn't make sense + // in a QML context which is where the roleNames are important. + return { { TitleRole, "title" }, { MessageRole, "message" } }; +} + +QVariant +SummaryModel::data( const QModelIndex& index, int role ) const +{ + if ( !index.isValid() ) + { + return QVariant(); + } + auto& item = m_summary.at( index.row() ); + switch ( role ) + { + case TitleRole: + return item.title; + case MessageRole: + return item.message; + case WidgetRole: + return item.widget ? QVariant::fromValue( item.widget ) : QVariant(); + default: + return QVariant(); + } +} + +int +SummaryModel::rowCount( const QModelIndex& ) const +{ + return m_summary.count(); +} + +void +SummaryModel::setSummaryList( const Calamares::ViewStepList& steps, bool withWidgets ) +{ + beginResetModel(); + m_summary.clear(); + + for ( Calamares::ViewStep* step : steps ) + { + QString text = step->prettyStatus(); + QWidget* widget = withWidgets ? step->createSummaryWidget() : nullptr; + + if ( text.isEmpty() && !widget ) + { + continue; + } + + m_summary << StepSummary { step->prettyName(), text, widget }; + } + endResetModel(); +} diff --git a/src/modules/summary/SummaryModel.h b/src/modules/summary/SummaryModel.h new file mode 100644 index 000000000..919b5d585 --- /dev/null +++ b/src/modules/summary/SummaryModel.h @@ -0,0 +1,67 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2019-2020, Adriaan de Groot + * SPDX-FileCopyrightText: 2020, Camilo Higuita + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#ifndef SUMMARY_SUMMARYMODEL_H +#define SUMMARY_SUMMARYMODEL_H + +#include "viewpages/ViewStep.h" + +#include +#include + +class Config; + +/** @brief Data for one step + * + * A step generally has a text description, but **may** have a + * QWidget. There is no ownership of the QWidget, that is assumed + * to be handed off to some owning parent-widget. + */ +struct StepSummary +{ + QString title; + QString message; + QWidget* widget = nullptr; +}; + +class SummaryModel : public QAbstractListModel +{ + Q_OBJECT + friend class Config; + +public: + enum Roles : int + { + TitleRole = Qt::DisplayRole, // Name of the step + MessageRole = Qt::UserRole, // String saying what it will do + WidgetRole, // Pointer to widget + }; + + explicit SummaryModel( QObject* parent = nullptr ); + int rowCount( const QModelIndex& = QModelIndex() ) const override; + QVariant data( const QModelIndex& index, int role ) const override; + +protected: + QHash< int, QByteArray > roleNames() const override; + +private: + /** @brief Sets the model data from @p steps + * + * Replaces the list of summaries with summaries given by + * the jobs and ViewSteps objects in @p steps. If @p withWidgets + * is @c true, then also queries for widget summaries alongside + * the text summaries for each step. + */ + void setSummaryList( const Calamares::ViewStepList& steps, bool withWidgets = false ); + + QVector< StepSummary > m_summary; +}; + +#endif diff --git a/src/modules/summaryq/CMakeLists.txt b/src/modules/summaryq/CMakeLists.txt index e63640597..75dd68aea 100644 --- a/src/modules/summaryq/CMakeLists.txt +++ b/src/modules/summaryq/CMakeLists.txt @@ -17,6 +17,7 @@ calamares_add_plugin(summaryq SOURCES SummaryQmlViewStep.cpp ${_summary}/Config.cpp + ${_summary}/SummaryModel.cpp UI RESOURCES summaryq${QT_VERSION_SUFFIX}.qrc