From ecefc446a6e07507335009b5b2091cf8dfb0d7b7 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Mon, 14 Jul 2025 20:50:02 -0400 Subject: [PATCH] homescreens/folio: Do not initialize shared_ptr with a QObject parent This MR ensures that delegates created with make_shared do not also get initialized with a QObject parent. Some of the classes used the same constructor parameter for HomeScreen and used it as a parent simultaneously. This was refactored so that they are separated. --- .../folio/applicationlistmodel.cpp | 4 +- containments/homescreens/folio/dragstate.cpp | 8 +-- .../homescreens/folio/favouritesmodel.cpp | 2 +- .../homescreens/folio/folioapplication.cpp | 6 +-- .../homescreens/folio/folioapplication.h | 4 +- .../folio/folioapplicationfolder.cpp | 12 ++--- .../folio/folioapplicationfolder.h | 2 +- .../homescreens/folio/foliodelegate.cpp | 54 +++++++++---------- .../homescreens/folio/foliodelegate.h | 22 ++++---- .../homescreens/folio/foliosettings.cpp | 4 +- .../homescreens/folio/foliowidget.cpp | 12 ++--- containments/homescreens/folio/foliowidget.h | 6 +-- 12 files changed, 68 insertions(+), 68 deletions(-) diff --git a/containments/homescreens/folio/applicationlistmodel.cpp b/containments/homescreens/folio/applicationlistmodel.cpp index 6fd392bf..ae299fd9 100644 --- a/containments/homescreens/folio/applicationlistmodel.cpp +++ b/containments/homescreens/folio/applicationlistmodel.cpp @@ -130,8 +130,8 @@ void ApplicationListModel::load() // Append new elements for (const KService::Ptr &service : toInsert) { - FolioApplication::Ptr app = std::make_shared(m_homeScreen, service); - FolioDelegate::Ptr delegate = std::make_shared(app, m_homeScreen); + FolioApplication::Ptr app = std::make_shared(service); + FolioDelegate::Ptr delegate = std::make_shared(app); beginInsertRows({}, m_delegates.size(), m_delegates.size()); m_delegates.append(delegate); diff --git a/containments/homescreens/folio/dragstate.cpp b/containments/homescreens/folio/dragstate.cpp index 6149663b..582122e7 100644 --- a/containments/homescreens/folio/dragstate.cpp +++ b/containments/homescreens/folio/dragstate.cpp @@ -505,8 +505,8 @@ void DragState::onDelegateDragFromAppDrawerStarted(QString storageId) { // fetch delegate at start position if (KService::Ptr service = KService::serviceByStorageId(storageId)) { - FolioApplication::Ptr app = std::make_shared(m_homeScreen, service); - setDropDelegate(std::make_shared(app, m_homeScreen)); + FolioApplication::Ptr app = std::make_shared(service); + setDropDelegate(std::make_shared(app)); } else { setDropDelegate(nullptr); } @@ -531,7 +531,7 @@ void DragState::onDelegateDragFromWidgetListStarted(QString appletPluginId) // default widget has dimensions of 1x1, and id of -1 m_createdAppletPluginId = appletPluginId; FolioWidget::Ptr widget = std::make_shared(m_homeScreen, -1, 1, 1); - setDropDelegate(std::make_shared(widget, m_homeScreen)); + setDropDelegate(std::make_shared(widget)); // set start location m_startPosition->setLocation(DelegateDragPosition::WidgetList); @@ -857,7 +857,7 @@ bool DragState::createDropPositionDelegate() FolioApplicationFolder::Ptr folder = std::make_shared(m_homeScreen, DEFAULT_FOLDER_NAME); folder->addDelegate(m_dropDelegate, 0); folder->addDelegate(existingDelegate, 0); - FolioDelegate::Ptr folderDelegate = std::make_shared(folder, m_homeScreen); + FolioDelegate::Ptr folderDelegate = std::make_shared(folder); m_homeScreen->favouritesModel()->removeEntry(m_candidateDropPosition->favouritesPosition()); m_homeScreen->favouritesModel()->addEntry(m_candidateDropPosition->favouritesPosition(), folderDelegate); diff --git a/containments/homescreens/folio/favouritesmodel.cpp b/containments/homescreens/folio/favouritesmodel.cpp index f160cb22..8df2a026 100644 --- a/containments/homescreens/folio/favouritesmodel.cpp +++ b/containments/homescreens/folio/favouritesmodel.cpp @@ -196,7 +196,7 @@ void FavouritesModel::setGhostEntry(int row) // if it doesn't, add a new empty delegate if (!found) { - FolioDelegate::Ptr ghost = std::make_shared(m_homeScreen); + FolioDelegate::Ptr ghost = std::make_shared(); addEntry(row, ghost); } } diff --git a/containments/homescreens/folio/folioapplication.cpp b/containments/homescreens/folio/folioapplication.cpp index 6a12d49f..f0d002ac 100644 --- a/containments/homescreens/folio/folioapplication.cpp +++ b/containments/homescreens/folio/folioapplication.cpp @@ -9,7 +9,7 @@ #include -FolioApplication::FolioApplication(HomeScreen *parent, KService::Ptr service) +FolioApplication::FolioApplication(KService::Ptr service, QObject *parent) : QObject{parent} , m_running{false} , m_name{service->name()} @@ -39,11 +39,11 @@ FolioApplication::FolioApplication(HomeScreen *parent, KService::Ptr service) }); } -FolioApplication::Ptr FolioApplication::fromJson(QJsonObject &obj, HomeScreen *parent) +FolioApplication::Ptr FolioApplication::fromJson(QJsonObject &obj) { QString storageId = obj[QStringLiteral("storageId")].toString(); if (KService::Ptr service = KService::serviceByStorageId(storageId)) { - return std::make_shared(parent, service); + return std::make_shared(service); } return nullptr; } diff --git a/containments/homescreens/folio/folioapplication.h b/containments/homescreens/folio/folioapplication.h index 4193c078..b7e759b9 100644 --- a/containments/homescreens/folio/folioapplication.h +++ b/containments/homescreens/folio/folioapplication.h @@ -34,9 +34,9 @@ class FolioApplication : public QObject, public std::enable_shared_from_this Ptr; - FolioApplication(HomeScreen *parent = nullptr, KService::Ptr service = QExplicitlySharedDataPointer{nullptr}); + FolioApplication(KService::Ptr service = QExplicitlySharedDataPointer{nullptr}, QObject *parent = nullptr); - static FolioApplication::Ptr fromJson(QJsonObject &obj, HomeScreen *parent); // may return nullptr + static FolioApplication::Ptr fromJson(QJsonObject &obj); // may return nullptr QJsonObject toJson() const; bool running() const; diff --git a/containments/homescreens/folio/folioapplicationfolder.cpp b/containments/homescreens/folio/folioapplicationfolder.cpp index fdbee04d..321ad2d0 100644 --- a/containments/homescreens/folio/folioapplicationfolder.cpp +++ b/containments/homescreens/folio/folioapplicationfolder.cpp @@ -7,25 +7,25 @@ #include #include -FolioApplicationFolder::FolioApplicationFolder(HomeScreen *parent, QString name) +FolioApplicationFolder::FolioApplicationFolder(HomeScreen *homeScreen, QString name, QObject *parent) : QObject{parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_name{name} , m_applicationFolderModel{new ApplicationFolderModel{this}} { } -FolioApplicationFolder::Ptr FolioApplicationFolder::fromJson(QJsonObject &obj, HomeScreen *parent) +FolioApplicationFolder::Ptr FolioApplicationFolder::fromJson(QJsonObject &obj, HomeScreen *homeScreen) { QString name = obj[QStringLiteral("name")].toString(); QList apps; for (auto storageId : obj[QStringLiteral("apps")].toArray()) { if (KService::Ptr service = KService::serviceByStorageId(storageId.toString())) { - apps.append(std::make_shared(parent, service)); + apps.append(std::make_shared(service)); } } - FolioApplicationFolder::Ptr folder = std::make_shared(parent, name); + FolioApplicationFolder::Ptr folder = std::make_shared(homeScreen, name); folder->setApplications(apps); return folder; } @@ -339,7 +339,7 @@ void ApplicationFolderModel::setGhostEntry(int index) } if (!ghost) { - ghost = std::make_shared(m_folder->m_homeScreen); + ghost = std::make_shared(); } // add empty delegate at new position diff --git a/containments/homescreens/folio/folioapplicationfolder.h b/containments/homescreens/folio/folioapplicationfolder.h index dd80b0b6..47b9697e 100644 --- a/containments/homescreens/folio/folioapplicationfolder.h +++ b/containments/homescreens/folio/folioapplicationfolder.h @@ -38,7 +38,7 @@ class FolioApplicationFolder : public QObject, public std::enable_shared_from_th public: typedef std::shared_ptr Ptr; - FolioApplicationFolder(HomeScreen *parent = nullptr, QString name = QString{}); + FolioApplicationFolder(HomeScreen *homeScreen = nullptr, QString name = QString{}, QObject *parent = nullptr); static std::shared_ptr fromJson(QJsonObject &obj, HomeScreen *parent); QJsonObject toJson() const; diff --git a/containments/homescreens/folio/foliodelegate.cpp b/containments/homescreens/folio/foliodelegate.cpp index 3b1d30d2..996fc541 100644 --- a/containments/homescreens/folio/foliodelegate.cpp +++ b/containments/homescreens/folio/foliodelegate.cpp @@ -4,7 +4,7 @@ #include "foliodelegate.h" #include "homescreenstate.h" -FolioDelegate::FolioDelegate(HomeScreen *parent) +FolioDelegate::FolioDelegate(QObject *parent) : QObject{parent} , m_type{FolioDelegate::None} , m_application{nullptr} @@ -13,7 +13,7 @@ FolioDelegate::FolioDelegate(HomeScreen *parent) { } -FolioDelegate::FolioDelegate(FolioApplication::Ptr application, HomeScreen *parent) +FolioDelegate::FolioDelegate(FolioApplication::Ptr application, QObject *parent) : QObject{parent} , m_type{FolioDelegate::Application} , m_application{application} @@ -22,7 +22,7 @@ FolioDelegate::FolioDelegate(FolioApplication::Ptr application, HomeScreen *pare { } -FolioDelegate::FolioDelegate(FolioApplicationFolder::Ptr folder, HomeScreen *parent) +FolioDelegate::FolioDelegate(FolioApplicationFolder::Ptr folder, QObject *parent) : QObject{parent} , m_type{FolioDelegate::Folder} , m_application{nullptr} @@ -31,7 +31,7 @@ FolioDelegate::FolioDelegate(FolioApplicationFolder::Ptr folder, HomeScreen *par { } -FolioDelegate::FolioDelegate(FolioWidget::Ptr widget, HomeScreen *parent) +FolioDelegate::FolioDelegate(FolioWidget::Ptr widget, QObject *parent) : QObject{parent} , m_type{FolioDelegate::Widget} , m_application{nullptr} @@ -40,34 +40,34 @@ FolioDelegate::FolioDelegate(FolioWidget::Ptr widget, HomeScreen *parent) { } -FolioDelegate::Ptr FolioDelegate::fromJson(QJsonObject &obj, HomeScreen *parent) +FolioDelegate::Ptr FolioDelegate::fromJson(QJsonObject &obj, HomeScreen *homeScreen) { const QString type = obj[QStringLiteral("type")].toString(); if (type == "application") { // read application - FolioApplication::Ptr app = FolioApplication::fromJson(obj, parent); + FolioApplication::Ptr app = FolioApplication::fromJson(obj); if (app) { - return std::make_shared(app, parent); + return std::make_shared(app); } } else if (type == "folder") { // read folder - FolioApplicationFolder::Ptr folder = FolioApplicationFolder::fromJson(obj, parent); + FolioApplicationFolder::Ptr folder = FolioApplicationFolder::fromJson(obj, homeScreen); if (folder) { - return std::make_shared(folder, parent); + return std::make_shared(folder); } } else if (type == "widget") { // read widget - FolioWidget::Ptr widget = FolioWidget::fromJson(obj, parent); + FolioWidget::Ptr widget = FolioWidget::fromJson(obj, homeScreen); if (widget) { - return std::make_shared(widget, parent); + return std::make_shared(widget); } } else if (type == "none") { - return std::make_shared(parent); + return std::make_shared(); } return nullptr; @@ -128,45 +128,45 @@ FolioWidget *FolioDelegate::widgetRaw() return m_widget.get(); } -FolioPageDelegate::FolioPageDelegate(int row, int column, HomeScreen *parent) +FolioPageDelegate::FolioPageDelegate(int row, int column, HomeScreen *homeScreen, QObject *parent) : FolioDelegate{parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_row{row} , m_column{column} { init(); } -FolioPageDelegate::FolioPageDelegate(int row, int column, FolioApplication::Ptr application, HomeScreen *parent) +FolioPageDelegate::FolioPageDelegate(int row, int column, FolioApplication::Ptr application, HomeScreen *homeScreen, QObject *parent) : FolioDelegate{application, parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_row{row} , m_column{column} { init(); } -FolioPageDelegate::FolioPageDelegate(int row, int column, FolioApplicationFolder::Ptr folder, HomeScreen *parent) +FolioPageDelegate::FolioPageDelegate(int row, int column, FolioApplicationFolder::Ptr folder, HomeScreen *homeScreen, QObject *parent) : FolioDelegate{folder, parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_row{row} , m_column{column} { init(); } -FolioPageDelegate::FolioPageDelegate(int row, int column, FolioWidget::Ptr widget, HomeScreen *parent) +FolioPageDelegate::FolioPageDelegate(int row, int column, FolioWidget::Ptr widget, HomeScreen *homeScreen, QObject *parent) : FolioDelegate{widget, parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_row{row} , m_column{column} { init(); } -FolioPageDelegate::FolioPageDelegate(int row, int column, FolioDelegate::Ptr delegate, HomeScreen *parent) +FolioPageDelegate::FolioPageDelegate(int row, int column, FolioDelegate::Ptr delegate, HomeScreen *homeScreen, QObject *parent) : FolioDelegate{parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_row{row} , m_column{column} { @@ -234,9 +234,9 @@ void FolioPageDelegate::init() }); } -FolioPageDelegate::Ptr FolioPageDelegate::fromJson(QJsonObject &obj, HomeScreen *parent) +FolioPageDelegate::Ptr FolioPageDelegate::fromJson(QJsonObject &obj, HomeScreen *homeScreen) { - FolioDelegate::Ptr fd = FolioDelegate::fromJson(obj, parent); + FolioDelegate::Ptr fd = FolioDelegate::fromJson(obj, homeScreen); if (!fd) { return nullptr; @@ -245,10 +245,10 @@ FolioPageDelegate::Ptr FolioPageDelegate::fromJson(QJsonObject &obj, HomeScreen int realRow = obj[QStringLiteral("row")].toInt(); int realColumn = obj[QStringLiteral("column")].toInt(); - int row = getTranslatedTopLeftRow(parent, realRow, realColumn, fd); - int column = getTranslatedTopLeftColumn(parent, realRow, realColumn, fd); + int row = getTranslatedTopLeftRow(homeScreen, realRow, realColumn, fd); + int column = getTranslatedTopLeftColumn(homeScreen, realRow, realColumn, fd); - FolioPageDelegate::Ptr delegate = std::make_shared(row, column, fd, parent); + FolioPageDelegate::Ptr delegate = std::make_shared(row, column, fd, homeScreen); fd->deleteLater(); return delegate; diff --git a/containments/homescreens/folio/foliodelegate.h b/containments/homescreens/folio/foliodelegate.h index 359a2de6..ad9e42f5 100644 --- a/containments/homescreens/folio/foliodelegate.h +++ b/containments/homescreens/folio/foliodelegate.h @@ -34,12 +34,12 @@ public: }; Q_ENUM(Type) - FolioDelegate(HomeScreen *parent); - FolioDelegate(std::shared_ptr application, HomeScreen *parent); - FolioDelegate(std::shared_ptr folder, HomeScreen *parent); - FolioDelegate(std::shared_ptr widget, HomeScreen *parent); + FolioDelegate(QObject *parent = nullptr); + FolioDelegate(std::shared_ptr application, QObject *parent = nullptr); + FolioDelegate(std::shared_ptr folder, QObject *parent = nullptr); + FolioDelegate(std::shared_ptr widget, QObject *parent = nullptr); - static std::shared_ptr fromJson(QJsonObject &obj, HomeScreen *parent); + static std::shared_ptr fromJson(QJsonObject &obj, HomeScreen *homeScreen); virtual QJsonObject toJson() const; @@ -71,13 +71,13 @@ class FolioPageDelegate : public FolioDelegate public: typedef std::shared_ptr Ptr; - FolioPageDelegate(int row = 0, int column = 0, HomeScreen *parent = nullptr); - FolioPageDelegate(int row, int column, std::shared_ptr application, HomeScreen *parent); - FolioPageDelegate(int row, int column, std::shared_ptr folder, HomeScreen *parent); - FolioPageDelegate(int row, int column, std::shared_ptr widget, HomeScreen *parent); - FolioPageDelegate(int row, int column, std::shared_ptr delegate, HomeScreen *parent); + FolioPageDelegate(int row = 0, int column = 0, HomeScreen *homeScreen = nullptr, QObject *parent = nullptr); + FolioPageDelegate(int row, int column, std::shared_ptr application, HomeScreen *homeScreen, QObject *parent = nullptr); + FolioPageDelegate(int row, int column, std::shared_ptr folder, HomeScreen *homeScreen, QObject *parent = nullptr); + FolioPageDelegate(int row, int column, std::shared_ptr widget, HomeScreen *homeScreen, QObject *parent = nullptr); + FolioPageDelegate(int row, int column, std::shared_ptr delegate, HomeScreen *homeScreen, QObject *parent = nullptr); - static std::shared_ptr fromJson(QJsonObject &obj, HomeScreen *parent); + static std::shared_ptr fromJson(QJsonObject &obj, HomeScreen *homeScreen); static int getTranslatedTopLeftRow(HomeScreen *homeScreen, int realRow, int realColumn, std::shared_ptr fd); static int getTranslatedTopLeftColumn(HomeScreen *homeScreen, int realRow, int realColumn, std::shared_ptr fd); static int getTranslatedRow(HomeScreen *homeScreen, int realRow, int realColumn); diff --git a/containments/homescreens/folio/foliosettings.cpp b/containments/homescreens/folio/foliosettings.cpp index 19735aad..da5fefaf 100644 --- a/containments/homescreens/folio/foliosettings.cpp +++ b/containments/homescreens/folio/foliosettings.cpp @@ -22,8 +22,8 @@ const QString CFG_KEY_SHOW_WALLPAPER_BLUR = QStringLiteral("wallpaperBlurEffect" const QString CFG_KEY_DOUBLE_TAP_TO_LOCK = QStringLiteral("doubleTapToLock"); FolioSettings::FolioSettings(HomeScreen *parent) -: QObject{parent} -, m_homeScreen{parent} + : QObject{parent} + , m_homeScreen{parent} { } diff --git a/containments/homescreens/folio/foliowidget.cpp b/containments/homescreens/folio/foliowidget.cpp index 16bd2c1a..7d909ebb 100644 --- a/containments/homescreens/folio/foliowidget.cpp +++ b/containments/homescreens/folio/foliowidget.cpp @@ -5,9 +5,9 @@ #include "homescreenstate.h" #include "widgetsmanager.h" -FolioWidget::FolioWidget(HomeScreen *parent, int id, int realGridWidth, int realGridHeight) +FolioWidget::FolioWidget(HomeScreen *homeScreen, int id, int realGridWidth, int realGridHeight, QObject *parent) : QObject{parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_id{id} , m_realGridWidth{realGridWidth} , m_realGridHeight{realGridHeight} @@ -21,9 +21,9 @@ FolioWidget::FolioWidget(HomeScreen *parent, int id, int realGridWidth, int real init(); } -FolioWidget::FolioWidget(HomeScreen *parent, Plasma::Applet *applet, int realGridWidth, int realGridHeight) +FolioWidget::FolioWidget(HomeScreen *homeScreen, Plasma::Applet *applet, int realGridWidth, int realGridHeight, QObject *parent) : QObject{parent} - , m_homeScreen{parent} + , m_homeScreen{homeScreen} , m_id{applet ? static_cast(applet->id()) : -1} , m_realGridWidth{realGridWidth} , m_realGridHeight{realGridHeight} @@ -51,12 +51,12 @@ void FolioWidget::init() }); } -FolioWidget::Ptr FolioWidget::fromJson(QJsonObject &obj, HomeScreen *parent) +FolioWidget::Ptr FolioWidget::fromJson(QJsonObject &obj, HomeScreen *homeScreen) { int id = obj[QStringLiteral("id")].toInt(); int gridWidth = obj[QStringLiteral("gridWidth")].toInt(); int gridHeight = obj[QStringLiteral("gridHeight")].toInt(); - return std::make_shared(parent, id, gridWidth, gridHeight); + return std::make_shared(homeScreen, id, gridWidth, gridHeight); } QJsonObject FolioWidget::toJson() const diff --git a/containments/homescreens/folio/foliowidget.h b/containments/homescreens/folio/foliowidget.h index 36b27c51..757376a4 100644 --- a/containments/homescreens/folio/foliowidget.h +++ b/containments/homescreens/folio/foliowidget.h @@ -34,10 +34,10 @@ class FolioWidget : public QObject, public std::enable_shared_from_this Ptr; - FolioWidget(HomeScreen *parent = nullptr, int id = -1, int gridWidth = 0, int gridHeight = 0); - FolioWidget(HomeScreen *parent, Plasma::Applet *applet, int gridWidth, int gridHeight); + FolioWidget(HomeScreen *homeScreen = nullptr, int id = -1, int gridWidth = 0, int gridHeight = 0, QObject *parent = nullptr); + FolioWidget(HomeScreen *homeScreen, Plasma::Applet *applet, int gridWidth, int gridHeight, QObject *parent = nullptr); - static std::shared_ptr fromJson(QJsonObject &obj, HomeScreen *parent); + static std::shared_ptr fromJson(QJsonObject &obj, HomeScreen *homeScreen); QJsonObject toJson() const; int id() const;