[summaryq] Hide internals of building the summary model

This commit is contained in:
Adriaan de Groot 2021-07-13 22:04:01 +02:00
parent 792ba8c0af
commit 768760793a
2 changed files with 30 additions and 17 deletions

View file

@ -48,7 +48,7 @@ SummaryModel::rowCount( const QModelIndex& ) const
}
void
SummaryModel::setSummary( const Calamares::ViewStepList& steps, bool withWidgets )
SummaryModel::setSummaryList( const Calamares::ViewStepList& steps, bool withWidgets )
{
Q_EMIT beginResetModel();
m_summary.clear();
@ -105,28 +105,24 @@ Config::componentComplete()
void
Config::refresh()
{
m_summary->setSummary( stepsForSummary( Calamares::ViewManager::instance()->viewSteps() ) );
}
void
Config::init()
{
refresh();
}
Calamares::ViewStepList
Config::stepsForSummary( const Calamares::ViewStepList& allSteps ) const
{
Calamares::ViewStepList steps;
for ( Calamares::ViewStep* step : allSteps )
for ( Calamares::ViewStep* step : Calamares::ViewManager::instance()->viewSteps() )
{
// *Assume* that if there's an exec step in the sequence,
// we don't need a summary for steps before it. This works in
// practice if there's a summary step before each exec --
// and in practice, there's only one of each.
if ( qobject_cast< Calamares::ExecutionViewStep* >( step ) )
{
steps.clear();
continue;
}
// Having reached the parent view-step of the Config object,
// we know we're providing a summary of steps up until this
// view step, so we now have steps since the previous exec, up
// to this summary.
if ( m_thisViewStep == step )
{
break;
@ -135,5 +131,11 @@ Config::stepsForSummary( const Calamares::ViewStepList& allSteps ) const
steps.append( step );
}
return steps;
m_summary->setSummaryList( steps );
}
void
Config::init()
{
refresh();
}

View file

@ -17,6 +17,8 @@
#include <QObject>
#include <QQmlParserStatus>
class Config;
/** @brief Data for one step
*
* A step generally has a text description, but **may** have a
@ -33,17 +35,26 @@ struct StepSummary
class SummaryModel : public QAbstractListModel
{
Q_OBJECT
friend class Config;
public:
explicit SummaryModel( QObject* parent = nullptr );
int rowCount( const QModelIndex& = QModelIndex() ) const override;
QVariant data( const QModelIndex& index, int role ) const override;
void setSummary( const Calamares::ViewStepList& steps, bool withWidgets = false );
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;
};