[summary] Improve naming, shuffle parameters

- the page doesn't need to remember what step it belongs to,
  if the step tells it when creating widgets.
- detach naming from the viewstep API that calls it.
This commit is contained in:
Adriaan de Groot 2021-10-04 12:23:17 +02:00
parent 87af923638
commit 763f29e2b8
3 changed files with 15 additions and 21 deletions

View File

@ -27,18 +27,15 @@
#include <QLabel> #include <QLabel>
#include <QScrollArea> #include <QScrollArea>
SummaryPage::SummaryPage( Config* config, const SummaryViewStep* thisViewStep, QWidget* parent ) SummaryPage::SummaryPage( Config* config, QWidget* parent )
: QWidget() : QWidget()
, m_thisViewStep( thisViewStep )
, m_contentWidget( nullptr ) , m_contentWidget( nullptr )
, m_scrollArea( new QScrollArea( this ) ) , m_scrollArea( new QScrollArea( this ) )
{ {
Q_UNUSED( parent ) Q_UNUSED( parent )
this->setObjectName( "summaryStep" ); this->setObjectName( "summaryStep" );
Q_ASSERT( m_thisViewStep );
QVBoxLayout* layout = new QVBoxLayout( this ); QVBoxLayout* layout = new QVBoxLayout( this );
layout->setContentsMargins( 0, 0, 0, 0 ); layout->setContentsMargins( 0, 0, 0, 0 );
@ -85,7 +82,7 @@ createBodyLabel( const QString& text, const QPalette& bodyPalette )
// Adds a widget for those ViewSteps that want a summary; // Adds a widget for those ViewSteps that want a summary;
// see SummaryPage documentation and also ViewStep docs. // see SummaryPage documentation and also ViewStep docs.
void void
SummaryPage::onActivate() SummaryPage::buildWidgets( Config* config, SummaryViewStep* viewstep )
{ {
const int SECTION_SPACING = 12; const int SECTION_SPACING = 12;
@ -102,7 +99,7 @@ SummaryPage::onActivate()
bodyPalette.setColor( WindowBackground, palette().window().color().lighter( 108 ) ); bodyPalette.setColor( WindowBackground, palette().window().color().lighter( 108 ) );
bool first = true; bool first = true;
const Calamares::ViewStepList steps = stepsForSummary( Calamares::ViewManager::instance()->viewSteps() ); const Calamares::ViewStepList steps = stepsForSummary( Calamares::ViewManager::instance()->viewSteps(), viewstep );
for ( Calamares::ViewStep* step : steps ) for ( Calamares::ViewStep* step : steps )
{ {
@ -151,12 +148,12 @@ SummaryPage::onActivate()
cDebug() << "Summary widget is larger than viewport, enlarge by" << enlarge << "to" << widgetSize; cDebug() << "Summary widget is larger than viewport, enlarge by" << enlarge << "to" << widgetSize;
emit m_thisViewStep->ensureSize( widgetSize ); // Only expand height emit viewstep->ensureSize( widgetSize ); // Only expand height
} }
} }
Calamares::ViewStepList Calamares::ViewStepList
SummaryPage::stepsForSummary( const Calamares::ViewStepList& allSteps ) const SummaryPage::stepsForSummary( const Calamares::ViewStepList& allSteps, SummaryViewStep* viewstep ) const
{ {
Calamares::ViewStepList steps; Calamares::ViewStepList steps;
for ( Calamares::ViewStep* step : allSteps ) for ( Calamares::ViewStep* step : allSteps )
@ -173,7 +170,7 @@ SummaryPage::stepsForSummary( const Calamares::ViewStepList& allSteps ) const
// If we reach the parent step of this page, we're done collecting the list of // If we reach the parent step of this page, we're done collecting the list of
// steps to summarize. // steps to summarize.
if ( m_thisViewStep == step ) if ( viewstep == step )
{ {
break; break;
} }
@ -185,7 +182,7 @@ SummaryPage::stepsForSummary( const Calamares::ViewStepList& allSteps ) const
} }
void void
SummaryPage::onLeave() SummaryPage::cleanup()
{ {
delete m_contentWidget; delete m_contentWidget;
m_contentWidget = nullptr; m_contentWidget = nullptr;

View File

@ -45,22 +45,19 @@ class SummaryPage : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SummaryPage( Config* config, const SummaryViewStep* thisViewStep, QWidget* parent = nullptr ); explicit SummaryPage( Config* config, QWidget* parent = nullptr );
/// @brief Create contents showing all of the summary /// @brief Create contents showing all of the summary
void onActivate(); void buildWidgets( Config* config, SummaryViewStep* viewstep );
/// @brief Clean up the widgets /// @brief Clean up the widgets
void onLeave(); void cleanup();
private: private:
Calamares::ViewStepList stepsForSummary( const Calamares::ViewStepList& allSteps ) const; Calamares::ViewStepList stepsForSummary( const Calamares::ViewStepList& allSteps, SummaryViewStep* viewstep ) const;
const SummaryViewStep* m_thisViewStep;
QVBoxLayout* m_layout = nullptr; QVBoxLayout* m_layout = nullptr;
QWidget* m_contentWidget = nullptr; QWidget* m_contentWidget = nullptr;
QScrollArea* m_scrollArea = nullptr;
QScrollArea* m_scrollArea;
}; };
#endif // SUMMARYPAGE_H #endif // SUMMARYPAGE_H

View File

@ -16,7 +16,7 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( SummaryViewStepFactory, registerPlugin< Sum
SummaryViewStep::SummaryViewStep( QObject* parent ) SummaryViewStep::SummaryViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_config( new Config( this ) ) , m_config( new Config( this ) )
, m_widget( new SummaryPage( m_config, this ) ) , m_widget( new SummaryPage( m_config ) )
{ {
emit nextStatusChanged( true ); emit nextStatusChanged( true );
} }
@ -85,7 +85,7 @@ void
SummaryViewStep::onActivate() SummaryViewStep::onActivate()
{ {
m_config->collectSummaries( this, Config::Widgets::Enabled ); m_config->collectSummaries( this, Config::Widgets::Enabled );
m_widget->onActivate(); m_widget->buildWidgets( m_config, this );
} }
@ -93,5 +93,5 @@ void
SummaryViewStep::onLeave() SummaryViewStep::onLeave()
{ {
m_config->clearSummaries(); m_config->clearSummaries();
m_widget->onLeave(); m_widget->cleanup();
} }