From b18b35e2d2db771c754eee9fec7faada2b8fd303 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 13 Aug 2017 09:41:50 +0200 Subject: democompositor: Give up on having AppEntry with only const members When building gadgets that include instances of AppEntry that will expose these member variables a Q_PROPERTY we will end trying to do a std::move (even if the AppEntry is not movable). Remove the const from the member variables, leave the CONSTANT in the property to not generate a write function and let's keep the discipline to not assign to an existing AppEntry. Change-Id: I742a9d091e7e6eac6cc3cb84a48b7b8812a24247 Reviewed-by: Paul Olav Tvete --- wayland/democompositor/apps/appentry.h | 11 ++++++----- wayland/democompositor/apps/applistmodel.cpp | 25 +++++++++---------------- wayland/democompositor/apps/applistmodel.h | 8 +++----- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/wayland/democompositor/apps/appentry.h b/wayland/democompositor/apps/appentry.h index cb7a727..317b748 100644 --- a/wayland/democompositor/apps/appentry.h +++ b/wayland/democompositor/apps/appentry.h @@ -64,11 +64,12 @@ class AppEntry { Q_PROPERTY(QString executableName MEMBER executableName CONSTANT) Q_PROPERTY(QString executablePath MEMBER executablePath CONSTANT) public: - const QString iconName; - const QString appName; - const QString executableName; - const QString executablePath; - const QString sourceFileName; + + QString iconName; + QString appName; + QString executableName; + QString executablePath; + QString sourceFileName; static AppEntry empty(); }; diff --git a/wayland/democompositor/apps/applistmodel.cpp b/wayland/democompositor/apps/applistmodel.cpp index 8602588..0b4d620 100644 --- a/wayland/democompositor/apps/applistmodel.cpp +++ b/wayland/democompositor/apps/applistmodel.cpp @@ -69,11 +69,6 @@ static QHash modelRoles() QHash AppListModel::m_roles = modelRoles(); -AppListModel::~AppListModel() -{ - qDeleteAll(m_rows); -} - int AppListModel::rowCount(const QModelIndex& index) const { if (index.isValid()) @@ -90,17 +85,17 @@ QVariant AppListModel::data(const QModelIndex& index, int role) const switch (role) { case App: - return QVariant::fromValue(*entry); + return QVariant::fromValue(entry); case IconName: - return entry->iconName; + return entry.iconName; case ApplicationName: - return entry->appName; + return entry.appName; case ExeuctableName: - return entry->executableName; + return entry.executableName; case ExecutablePath: - return entry->executablePath; + return entry.executablePath; case SourceFileName: - return entry->sourceFileName; + return entry.sourceFileName; default: qCWarning(apps) << "Unhandled role" << role; return QVariant(); @@ -154,13 +149,11 @@ void AppListModel::doAddFile(const QString& fileName) return; for (int i = 0; i < m_rows.count(); ++i) { - auto oldEntry = m_rows[i]; - if (oldEntry->sourceFileName == fileName) { - m_rows[i] = new AppEntry(newEntry); - delete oldEntry; + if (m_rows[i].sourceFileName == fileName) { + m_rows[i] = newEntry; return; } } - m_rows.push_back(new AppEntry(newEntry)); + m_rows.push_back(newEntry); } diff --git a/wayland/democompositor/apps/applistmodel.h b/wayland/democompositor/apps/applistmodel.h index b177ece..9147f54 100644 --- a/wayland/democompositor/apps/applistmodel.h +++ b/wayland/democompositor/apps/applistmodel.h @@ -50,11 +50,11 @@ #pragma once +#include "appentry.h" + #include #include -class AppEntry; - /** * A model that holds all available applications and * exports them to a QML scene @@ -63,8 +63,6 @@ class AppListModel : public QAbstractListModel { Q_OBJECT public: - ~AppListModel(); - enum Roles { App = Qt::UserRole, IconName, @@ -87,6 +85,6 @@ public Q_SLOTS: private: void doAddFile(const QString& fileName); - QVector m_rows; + QVector m_rows; static QHash m_roles; }; -- cgit v1.2.3