[summaryq] Remove memory leak

Don't use a vector of pointers, it is too easy (like when calling clear())
to leak memory.
This commit is contained in:
Adriaan de Groot 2021-07-13 11:02:24 +02:00
parent d2e11dd5d1
commit 3b7c2b2221
2 changed files with 15 additions and 7 deletions

View File

@ -39,7 +39,7 @@ SummaryModel::data( const QModelIndex& index, int role ) const
return QVariant(); return QVariant();
} }
const auto item = m_summary.at( index.row() ); const auto item = m_summary.at( index.row() );
return role == Qt::DisplayRole ? item->title : item->message; return role == Qt::DisplayRole ? item.title : item.message;
} }
int int
@ -49,22 +49,22 @@ SummaryModel::rowCount( const QModelIndex& ) const
} }
void void
SummaryModel::setSummary( const Calamares::ViewStepList& steps ) SummaryModel::setSummary( const Calamares::ViewStepList& steps, bool withWidgets )
{ {
m_summary.clear();
Q_EMIT beginResetModel(); Q_EMIT beginResetModel();
m_summary.clear();
for ( Calamares::ViewStep* step : steps ) for ( Calamares::ViewStep* step : steps )
{ {
QString text = step->prettyStatus(); QString text = step->prettyStatus();
QWidget* widget = step->createSummaryWidget(); QWidget* widget = withWidgets ? step->createSummaryWidget() : nullptr;
if ( text.isEmpty() && !widget ) if ( text.isEmpty() && !widget )
{ {
continue; continue;
} }
m_summary << new StepSummary { step->prettyName(), text }; m_summary << StepSummary { step->prettyName(), text, widget };
} }
Q_EMIT endResetModel(); Q_EMIT endResetModel();
} }

View File

@ -18,10 +18,18 @@
class SummaryQmlViewStep; class SummaryQmlViewStep;
/** @brief Data for one step
*
* A step generally has a text description, but **may** have a
* QWidget. There is no ownership of the QWidget, that is assumed
* to be handed off to some owning parent-widget.
*/
struct StepSummary struct StepSummary
{ {
QString title; QString title;
QString message; QString message;
QWidget* widget = nullptr;
}; };
class SummaryModel : public QAbstractListModel class SummaryModel : public QAbstractListModel
@ -32,13 +40,13 @@ public:
int rowCount( const QModelIndex& = QModelIndex() ) const override; int rowCount( const QModelIndex& = QModelIndex() ) const override;
QVariant data( const QModelIndex& index, int role ) const override; QVariant data( const QModelIndex& index, int role ) const override;
void setSummary( const Calamares::ViewStepList& steps ); void setSummary( const Calamares::ViewStepList& steps, bool withWidgets = false );
protected: protected:
QHash< int, QByteArray > roleNames() const override; QHash< int, QByteArray > roleNames() const override;
private: private:
QVector< StepSummary* > m_summary; QVector< StepSummary > m_summary;
}; };
class Config : public QObject, public QQmlParserStatus class Config : public QObject, public QQmlParserStatus