[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:
parent
d2e11dd5d1
commit
3b7c2b2221
@ -39,7 +39,7 @@ SummaryModel::data( const QModelIndex& index, int role ) const
|
||||
return QVariant();
|
||||
}
|
||||
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
|
||||
@ -49,22 +49,22 @@ SummaryModel::rowCount( const QModelIndex& ) const
|
||||
}
|
||||
|
||||
void
|
||||
SummaryModel::setSummary( const Calamares::ViewStepList& steps )
|
||||
SummaryModel::setSummary( const Calamares::ViewStepList& steps, bool withWidgets )
|
||||
{
|
||||
m_summary.clear();
|
||||
Q_EMIT beginResetModel();
|
||||
m_summary.clear();
|
||||
|
||||
for ( Calamares::ViewStep* step : steps )
|
||||
{
|
||||
QString text = step->prettyStatus();
|
||||
QWidget* widget = step->createSummaryWidget();
|
||||
QWidget* widget = withWidgets ? step->createSummaryWidget() : nullptr;
|
||||
|
||||
if ( text.isEmpty() && !widget )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
m_summary << new StepSummary { step->prettyName(), text };
|
||||
m_summary << StepSummary { step->prettyName(), text, widget };
|
||||
}
|
||||
Q_EMIT endResetModel();
|
||||
}
|
||||
|
@ -18,10 +18,18 @@
|
||||
|
||||
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
|
||||
{
|
||||
QString title;
|
||||
QString message;
|
||||
QWidget* widget = nullptr;
|
||||
};
|
||||
|
||||
class SummaryModel : public QAbstractListModel
|
||||
@ -32,13 +40,13 @@ public:
|
||||
int rowCount( const QModelIndex& = QModelIndex() ) 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:
|
||||
QHash< int, QByteArray > roleNames() const override;
|
||||
|
||||
private:
|
||||
QVector< StepSummary* > m_summary;
|
||||
QVector< StepSummary > m_summary;
|
||||
};
|
||||
|
||||
class Config : public QObject, public QQmlParserStatus
|
||||
|
Loading…
Reference in New Issue
Block a user