[netinstall] Various refactoring

- move ready-indication to Config
- don't check pointers that can't be null
- hand the whole Config to the page
main
Adriaan de Groot 6 years ago
parent 4cdfe1276a
commit 85551f0fdb

@ -66,6 +66,7 @@ void
Config::loadGroupList( const QVariantList& groupData ) Config::loadGroupList( const QVariantList& groupData )
{ {
m_model->setupModelData( groupData ); m_model->setupModelData( groupData );
emit statusReady();
} }
void void

@ -71,7 +71,8 @@ public:
PackageModel* model() const { return m_model; } PackageModel* model() const { return m_model; }
signals: signals:
void statusChanged( QString status ); void statusChanged( QString status ); ///< Something changed
void statusReady(); ///< Loading groups is complete
private slots: private slots:
void receivedGroupData(); ///< From async-loading group data void receivedGroupData(); ///< From async-loading group data

@ -34,11 +34,16 @@
#include <QHeaderView> #include <QHeaderView>
#include <QNetworkReply> #include <QNetworkReply>
NetInstallPage::NetInstallPage( QWidget* parent ) NetInstallPage::NetInstallPage( Config* c, QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, m_config( c )
, ui( new Ui::Page_NetInst ) , ui( new Ui::Page_NetInst )
{ {
ui->setupUi( this ); ui->setupUi( this );
ui->groupswidget->setModel( c->model() );
connect( c, &Config::statusChanged, this, &NetInstallPage::setStatus );
connect( c, &Config::statusReady, this, &NetInstallPage::expandGroups );
setPageTitle( nullptr ); setPageTitle( nullptr );
CALAMARES_RETRANSLATE_SLOT( &NetInstallPage::retranslate ); CALAMARES_RETRANSLATE_SLOT( &NetInstallPage::retranslate );
} }
@ -63,16 +68,17 @@ NetInstallPage::setPageTitle( CalamaresUtils::Locale::TranslatedString* t )
void void
NetInstallPage::retranslate() NetInstallPage::retranslate()
{ {
if ( ui && m_title ) if ( m_title )
{ {
ui->label->setText( m_title->get() ); // That's get() on the TranslatedString ui->label->setText( m_title->get() ); // That's get() on the TranslatedString
} }
ui->netinst_status->setText( m_config->status() );
} }
void void
NetInstallPage::setModel( QAbstractItemModel* model ) NetInstallPage::expandGroups()
{ {
ui->groupswidget->setModel( model ); auto* model = m_config->model();
// Go backwards because expanding a group may cause rows to appear below it // Go backwards because expanding a group may cause rows to appear below it
for ( int i = model->rowCount() - 1; i >= 0; --i ) for ( int i = model->rowCount() - 1; i >= 0; --i )
{ {
@ -84,6 +90,11 @@ NetInstallPage::setModel( QAbstractItemModel* model )
} }
} }
void
NetInstallPage::setStatus( QString s )
{
ui->netinst_status->setText( s );
}
void void
NetInstallPage::onActivate() NetInstallPage::onActivate()

@ -21,6 +21,7 @@
#ifndef NETINSTALLPAGE_H #ifndef NETINSTALLPAGE_H
#define NETINSTALLPAGE_H #define NETINSTALLPAGE_H
#include "Config.h"
#include "PackageModel.h" #include "PackageModel.h"
#include "PackageTreeItem.h" #include "PackageTreeItem.h"
@ -42,7 +43,7 @@ class NetInstallPage : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
NetInstallPage( QWidget* parent = nullptr ); NetInstallPage( Config* config, QWidget* parent = nullptr );
virtual ~NetInstallPage(); virtual ~NetInstallPage();
/** @brief Sets the page title /** @brief Sets the page title
@ -56,24 +57,21 @@ public:
*/ */
void setPageTitle( CalamaresUtils::Locale::TranslatedString* ); void setPageTitle( CalamaresUtils::Locale::TranslatedString* );
/** @brief Sets the model of packages to display
*
* While setting up the UI, expand entries that should be pre-expanded.
*
* Follows the *expanded* key / the startExpanded field in the
* group entries of the model. Call this after filling up the model.
*/
void setModel( QAbstractItemModel* );
void onActivate(); void onActivate();
public slots: public slots:
void retranslate(); void retranslate();
void setStatus( QString s );
signals: /** @brief Expand entries that should be pre-expanded.
void checkReady( bool ); *
* Follows the *expanded* key / the startExpanded field in the
* group entries of the model. Call this after filling up the model.
*/
void expandGroups();
private: private:
Config* m_config;
Ui::Page_NetInst* ui; Ui::Page_NetInst* ui;
std::unique_ptr< CalamaresUtils::Locale::TranslatedString > m_title; // Above the treeview std::unique_ptr< CalamaresUtils::Locale::TranslatedString > m_title; // Above the treeview

@ -32,12 +32,11 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( NetInstallViewStepFactory, registerPlugin<
NetInstallViewStep::NetInstallViewStep( QObject* parent ) NetInstallViewStep::NetInstallViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_widget( new NetInstallPage() ) , m_widget( new NetInstallPage( &m_config ) )
, m_sidebarLabel( nullptr ) , m_sidebarLabel( nullptr )
, m_nextEnabled( false ) , m_nextEnabled( false )
{ {
emit nextStatusChanged( true ); connect( &m_config, &Config::statusReady, this, &NetInstallViewStep::nextIsReady );
connect( m_widget, &NetInstallPage::checkReady, this, &NetInstallViewStep::nextIsReady );
} }
@ -86,7 +85,7 @@ NetInstallViewStep::widget()
bool bool
NetInstallViewStep::isNextEnabled() const NetInstallViewStep::isNextEnabled() const
{ {
return m_nextEnabled; return !m_config.required() || m_nextEnabled;
} }
@ -192,17 +191,16 @@ NetInstallViewStep::onLeave()
} }
void void
NetInstallViewStep::nextIsReady( bool b ) NetInstallViewStep::nextIsReady()
{ {
m_nextEnabled = b; m_nextEnabled = true;
emit nextStatusChanged( b ); emit nextStatusChanged( true );
} }
void void
NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap ) NetInstallViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{ {
m_config.setRequired( CalamaresUtils::getBool( configurationMap, "required", false ) ); m_config.setRequired( CalamaresUtils::getBool( configurationMap, "required", false ) );
m_widget->setModel( m_config.model() );
QString groupsUrl = CalamaresUtils::getString( configurationMap, "groupsUrl" ); QString groupsUrl = CalamaresUtils::getString( configurationMap, "groupsUrl" );
if ( !groupsUrl.isEmpty() ) if ( !groupsUrl.isEmpty() )

@ -59,14 +59,14 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override; void setConfigurationMap( const QVariantMap& configurationMap ) override;
public slots: public slots:
void nextIsReady( bool ); void nextIsReady();
private: private:
Config m_config; Config m_config;
NetInstallPage* m_widget; NetInstallPage* m_widget;
CalamaresUtils::Locale::TranslatedString* m_sidebarLabel; // As it appears in the sidebar CalamaresUtils::Locale::TranslatedString* m_sidebarLabel; // As it appears in the sidebar
bool m_nextEnabled; bool m_nextEnabled = false;
}; };
CALAMARES_PLUGIN_FACTORY_DECLARATION( NetInstallViewStepFactory ) CALAMARES_PLUGIN_FACTORY_DECLARATION( NetInstallViewStepFactory )

Loading…
Cancel
Save