[welcome] Factor out check for a filled requirements-model

This commit is contained in:
Adriaan de Groot 2022-04-14 21:48:55 +02:00
parent fc653adcc0
commit 11d7870d68
2 changed files with 32 additions and 7 deletions

View File

@ -217,11 +217,10 @@ ResultsListWidget::retranslate()
void
ResultsListWidget::requirementsChanged()
{
if ( m_config->requirementsModel()->count() < m_requirementsSeen )
if ( !isModelFilled() )
{
return;
}
m_requirementsSeen = m_config->requirementsModel()->count();
// Check that all are satisfied (gives warnings if not) and
// all *mandatory* entries are satisfied (gives errors if not).
@ -281,6 +280,18 @@ ResultsListWidget::requirementsChanged()
retranslate();
}
bool
ResultsListWidget::isModelFilled()
{
if ( m_config->requirementsModel()->count() < m_requirementsSeen )
{
return false;
}
m_requirementsSeen = m_config->requirementsModel()->count();
return true;
}
#include "utils/moc-warnings.h"
#include "ResultsListWidget.moc"

View File

@ -33,17 +33,31 @@ private:
void retranslate();
QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry
/** @brief The model can be reset and re-filled, is it full yet?
*
* We count how many requirements we have seen; since the model
* does not shrink, we can avoid reacting to model-is-cleared
* events because the size of the model is then (briefly) smaller
* than what we expect.
*
* Returns true if the model contains at least m_requirementsSeen
* elements, and updates m_requirementsSeen. (Which is why the
* method is not const)
*/
bool isModelFilled();
/** @brief A list of widgets, one per entry in the requirements model
*
* Unsatisfied entries have a non-null widget pointer, while requirements
* entries that **are** satisfied have no widget.
*/
QList< ResultWidget* > m_resultWidgets;
Config* m_config = nullptr;
// UI parts, which need updating when the model changes
QLabel* m_explanation = nullptr;
QBoxLayout* m_mainLayout = nullptr;
QBoxLayout* m_entriesLayout = nullptr;
// We count how many requirements we have seen; since the model
// does not shrink, we can avoid reacting to model-is-cleared
// events because the size of the model is then (briefly) smaller
// than what we expect.
int m_requirementsSeen = 0;
};