[libcalamares] Allow resetting the requirements model

- When a requirements checker starts, it can reset the model
  to clear it of previous entries.
This commit is contained in:
Adriaan de Groot 2022-04-13 17:08:17 +02:00
parent 8f5c3fa302
commit a9e098b0b4
3 changed files with 29 additions and 11 deletions

View File

@ -32,6 +32,7 @@ RequirementsChecker::RequirementsChecker( QVector< Module* > modules, Requiremen
, m_progressTimer( nullptr )
, m_progressTimeouts( 0 )
{
m_model->clear();
m_watchers.reserve( m_modules.count() );
connect( this, &RequirementsChecker::requirementsProgress, model, &RequirementsModel::setProgressMessage );
}
@ -63,9 +64,9 @@ RequirementsChecker::finished()
static QMutex finishedMutex;
QMutexLocker lock( &finishedMutex );
if ( m_progressTimer && std::all_of( m_watchers.cbegin(), m_watchers.cend(), []( const Watcher* w ) {
return w && w->isFinished();
} ) )
if ( m_progressTimer
&& std::all_of(
m_watchers.cbegin(), m_watchers.cend(), []( const Watcher* w ) { return w && w->isFinished(); } ) )
{
cDebug() << "All requirements have been checked.";
if ( m_progressTimer )
@ -100,14 +101,17 @@ RequirementsChecker::reportProgress()
m_progressTimeouts++;
QStringList remainingNames;
auto remaining = std::count_if( m_watchers.cbegin(), m_watchers.cend(), [&]( const Watcher* w ) {
if ( w && !w->isFinished() )
{
remainingNames << w->objectName();
return true;
}
return false;
} );
auto remaining = std::count_if( m_watchers.cbegin(),
m_watchers.cend(),
[ & ]( const Watcher* w )
{
if ( w && !w->isFinished() )
{
remainingNames << w->objectName();
return true;
}
return false;
} );
if ( remaining > 0 )
{
cDebug() << "Remaining modules:" << remaining << Logger::DebugList( remainingNames );

View File

@ -15,6 +15,16 @@
namespace Calamares
{
void
RequirementsModel::clear()
{
QMutexLocker l( &m_addLock );
emit beginResetModel();
m_requirements.clear();
changeRequirementsList();
emit endResetModel();
}
void
RequirementsModel::addRequirementsList( const Calamares::RequirementsList& requirements )
{

View File

@ -77,6 +77,10 @@ signals:
protected:
QHash< int, QByteArray > roleNames() const override;
///@brief Clears the requirements; resets the model
void clear();
///@brief Append some requirements; resets the model
void addRequirementsList( const Calamares::RequirementsList& requirements );