From d951a9d317ee30777a6a569ecca03ef9e33adf09 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 4 Oct 2021 12:59:50 +0200 Subject: [PATCH] [summary] Improve role names in SummaryModel --- src/modules/summary/Config.cpp | 18 +++++++++++++++--- src/modules/summary/Config.h | 7 +++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/modules/summary/Config.cpp b/src/modules/summary/Config.cpp index 98079cb6d..9038f786f 100644 --- a/src/modules/summary/Config.cpp +++ b/src/modules/summary/Config.cpp @@ -26,7 +26,9 @@ SummaryModel::SummaryModel( QObject* parent ) QHash< int, QByteArray > SummaryModel::roleNames() const { - return { { Qt::DisplayRole, "title" }, { Qt::UserRole, "message" } }; + // Not including WidgetRole here because that wouldn't make sense + // in a QML context which is where the roleNames are important. + return { { TitleRole, "title" }, { MessageRole, "message" } }; } QVariant @@ -36,8 +38,18 @@ 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; + auto& item = m_summary.at( index.row() ); + switch ( role ) + { + case TitleRole: + return item.title; + case MessageRole: + return item.message; + case WidgetRole: + return item.widget ? QVariant::fromValue( item.widget ) : QVariant(); + default: + return QVariant(); + } } int diff --git a/src/modules/summary/Config.h b/src/modules/summary/Config.h index cf819b503..f0732f448 100644 --- a/src/modules/summary/Config.h +++ b/src/modules/summary/Config.h @@ -38,6 +38,13 @@ class SummaryModel : public QAbstractListModel friend class Config; public: + enum Roles : int + { + TitleRole = Qt::DisplayRole, // Name of the step + MessageRole = Qt::UserRole, // String saying what it will do + WidgetRole, // Pointer to widget + }; + explicit SummaryModel( QObject* parent = nullptr ); int rowCount( const QModelIndex& = QModelIndex() ) const override; QVariant data( const QModelIndex& index, int role ) const override;