diff --git a/src/calamares/VariantModel.cpp b/src/calamares/VariantModel.cpp index bdcf8f75c..fc11794bc 100644 --- a/src/calamares/VariantModel.cpp +++ b/src/calamares/VariantModel.cpp @@ -70,15 +70,21 @@ findNth( const VariantModel::IndexVector& skiplist, quintptr value, int n ) VariantModel::VariantModel( const QVariant* p ) : m_p( p ) { - int x = 0; - overallLength( *p, x, -1, nullptr ); - m_rows.reserve( x ); - x = 0; - overallLength( *p, x, -1, &m_rows ); + reload(); } VariantModel::~VariantModel() {} +void VariantModel::reload() +{ + int x = 0; + overallLength( *m_p, x, -1, nullptr ); + m_rows.clear(); // Start over + m_rows.reserve( x ); // We'll need this much + x = 0; + overallLength( *m_p, x, -1, &m_rows ); +} + int VariantModel::columnCount( const QModelIndex& index ) const { diff --git a/src/calamares/VariantModel.h b/src/calamares/VariantModel.h index 9ea6f6737..b0c93e91c 100644 --- a/src/calamares/VariantModel.h +++ b/src/calamares/VariantModel.h @@ -33,7 +33,9 @@ * VariantMap's data structure. * * Take care of object lifetimes and that the underlying - * QVariant does not change during use. + * QVariant does not change during use. If the QVariant + * **does** change, call reload() to re-build the internal + * representation of the tree. */ class VariantModel : public QAbstractItemModel { @@ -56,6 +58,13 @@ public: ~VariantModel() override; + /** @brief Re-build the internal tree + * + * Call this when the underlying variant is changed, which + * might impact how the tree is laid out. + */ + void reload(); + int columnCount( const QModelIndex& index ) const override; int rowCount( const QModelIndex& index ) const override;