calamares/src/modules/summaryq/Config.h
Adriaan de Groot 3b7c2b2221 [summaryq] Remove memory leak
Don't use a vector of pointers, it is too easy (like when calling clear())
to leak memory.
2021-07-13 11:02:24 +02:00

82 lines
2.1 KiB
C++

/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2019-2020, Adriaan de Groot <groot@kde.org>
* SPDX-FileCopyrightText: 2020, Camilo Higuita <milo.h@aol.com>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#ifndef SUMMARY_CONFIG_H
#define SUMMARY_CONFIG_H
#include "viewpages/ViewStep.h"
#include <QAbstractListModel>
#include <QObject>
#include <QQmlParserStatus>
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
{
Q_OBJECT
public:
explicit SummaryModel( QObject* parent = nullptr );
int rowCount( const QModelIndex& = QModelIndex() ) const override;
QVariant data( const QModelIndex& index, int role ) const override;
void setSummary( const Calamares::ViewStepList& steps, bool withWidgets = false );
protected:
QHash< int, QByteArray > roleNames() const override;
private:
QVector< StepSummary > m_summary;
};
class Config : public QObject, public QQmlParserStatus
{
Q_OBJECT
Q_PROPERTY( QString message MEMBER m_message NOTIFY messageChanged CONSTANT )
Q_PROPERTY( QString title MEMBER m_title NOTIFY titleChanged CONSTANT )
Q_PROPERTY( SummaryModel* summaryModel READ summaryModel CONSTANT FINAL )
public:
explicit Config( QObject* parent = nullptr );
virtual void componentComplete() override;
virtual void classBegin() override {}
void refresh();
void init();
SummaryModel* summaryModel() const { return m_summary; }
private:
Calamares::ViewStepList stepsForSummary( const Calamares::ViewStepList& allSteps ) const;
const SummaryQmlViewStep* m_thisViewStep;
SummaryModel* m_summary;
QString m_message;
QString m_title;
signals:
void messageChanged();
void titleChanged();
};
#endif