[summary] Split out classes to help lupdate
One QObject-based class per source file helps lupdate figure out what goes where, avoids warning about unknown class / namespace ::Config.
This commit is contained in:
parent
115f00f5cd
commit
0ac170c3de
@ -9,6 +9,7 @@ calamares_add_plugin(summary
|
||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
SOURCES
|
||||
Config.cpp
|
||||
SummaryModel.cpp
|
||||
SummaryPage.cpp
|
||||
SummaryViewStep.cpp
|
||||
UI
|
||||
|
@ -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 ) )
|
||||
|
@ -11,60 +11,10 @@
|
||||
#ifndef SUMMARY_CONFIG_H
|
||||
#define SUMMARY_CONFIG_H
|
||||
|
||||
#include "SummaryModel.h"
|
||||
|
||||
#include "viewpages/ViewStep.h"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QObject>
|
||||
#include <QQmlParserStatus>
|
||||
|
||||
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
|
||||
|
74
src/modules/summary/SummaryModel.cpp
Normal file
74
src/modules/summary/SummaryModel.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2020, Camilo Higuita <milo.h@aol.com>
|
||||
* SPDX-FileCopyrightText: 2021 Anke Boersma <demm@kaosx.us>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "SummaryModel.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
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();
|
||||
}
|
67
src/modules/summary/SummaryModel.h
Normal file
67
src/modules/summary/SummaryModel.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2019-2020, Adriaan de Groot <groot@kde.org>
|
||||
* SPDX-FileCopyrightText: 2020, Camilo Higuita <milo.h@aol.com>
|
||||
* 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 <QAbstractListModel>
|
||||
#include <QObject>
|
||||
|
||||
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
|
@ -17,6 +17,7 @@ calamares_add_plugin(summaryq
|
||||
SOURCES
|
||||
SummaryQmlViewStep.cpp
|
||||
${_summary}/Config.cpp
|
||||
${_summary}/SummaryModel.cpp
|
||||
UI
|
||||
RESOURCES
|
||||
summaryq${QT_VERSION_SUFFIX}.qrc
|
||||
|
Loading…
Reference in New Issue
Block a user