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.
This commit is contained in:
Devin Lin 2025-07-14 20:50:02 -04:00
parent 0fe7879afa
commit ecefc446a6
12 changed files with 68 additions and 68 deletions

View file

@ -130,8 +130,8 @@ void ApplicationListModel::load()
// Append new elements
for (const KService::Ptr &service : toInsert) {
FolioApplication::Ptr app = std::make_shared<FolioApplication>(m_homeScreen, service);
FolioDelegate::Ptr delegate = std::make_shared<FolioDelegate>(app, m_homeScreen);
FolioApplication::Ptr app = std::make_shared<FolioApplication>(service);
FolioDelegate::Ptr delegate = std::make_shared<FolioDelegate>(app);
beginInsertRows({}, m_delegates.size(), m_delegates.size());
m_delegates.append(delegate);

View file

@ -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<FolioApplication>(m_homeScreen, service);
setDropDelegate(std::make_shared<FolioDelegate>(app, m_homeScreen));
FolioApplication::Ptr app = std::make_shared<FolioApplication>(service);
setDropDelegate(std::make_shared<FolioDelegate>(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<FolioWidget>(m_homeScreen, -1, 1, 1);
setDropDelegate(std::make_shared<FolioDelegate>(widget, m_homeScreen));
setDropDelegate(std::make_shared<FolioDelegate>(widget));
// set start location
m_startPosition->setLocation(DelegateDragPosition::WidgetList);
@ -857,7 +857,7 @@ bool DragState::createDropPositionDelegate()
FolioApplicationFolder::Ptr folder = std::make_shared<FolioApplicationFolder>(m_homeScreen, DEFAULT_FOLDER_NAME);
folder->addDelegate(m_dropDelegate, 0);
folder->addDelegate(existingDelegate, 0);
FolioDelegate::Ptr folderDelegate = std::make_shared<FolioDelegate>(folder, m_homeScreen);
FolioDelegate::Ptr folderDelegate = std::make_shared<FolioDelegate>(folder);
m_homeScreen->favouritesModel()->removeEntry(m_candidateDropPosition->favouritesPosition());
m_homeScreen->favouritesModel()->addEntry(m_candidateDropPosition->favouritesPosition(), folderDelegate);

View file

@ -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<FolioDelegate>(m_homeScreen);
FolioDelegate::Ptr ghost = std::make_shared<FolioDelegate>();
addEntry(row, ghost);
}
}

View file

@ -9,7 +9,7 @@
#include <KNotificationJobUiDelegate>
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<FolioApplication>(parent, service);
return std::make_shared<FolioApplication>(service);
}
return nullptr;
}

View file

@ -34,9 +34,9 @@ class FolioApplication : public QObject, public std::enable_shared_from_this<Fol
public:
typedef std::shared_ptr<FolioApplication> Ptr;
FolioApplication(HomeScreen *parent = nullptr, KService::Ptr service = QExplicitlySharedDataPointer<KService>{nullptr});
FolioApplication(KService::Ptr service = QExplicitlySharedDataPointer<KService>{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;

View file

@ -7,25 +7,25 @@
#include <QJsonArray>
#include <algorithm>
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<FolioApplication::Ptr> apps;
for (auto storageId : obj[QStringLiteral("apps")].toArray()) {
if (KService::Ptr service = KService::serviceByStorageId(storageId.toString())) {
apps.append(std::make_shared<FolioApplication>(parent, service));
apps.append(std::make_shared<FolioApplication>(service));
}
}
FolioApplicationFolder::Ptr folder = std::make_shared<FolioApplicationFolder>(parent, name);
FolioApplicationFolder::Ptr folder = std::make_shared<FolioApplicationFolder>(homeScreen, name);
folder->setApplications(apps);
return folder;
}
@ -339,7 +339,7 @@ void ApplicationFolderModel::setGhostEntry(int index)
}
if (!ghost) {
ghost = std::make_shared<FolioDelegate>(m_folder->m_homeScreen);
ghost = std::make_shared<FolioDelegate>();
}
// add empty delegate at new position

View file

@ -38,7 +38,7 @@ class FolioApplicationFolder : public QObject, public std::enable_shared_from_th
public:
typedef std::shared_ptr<FolioApplicationFolder> Ptr;
FolioApplicationFolder(HomeScreen *parent = nullptr, QString name = QString{});
FolioApplicationFolder(HomeScreen *homeScreen = nullptr, QString name = QString{}, QObject *parent = nullptr);
static std::shared_ptr<FolioApplicationFolder> fromJson(QJsonObject &obj, HomeScreen *parent);
QJsonObject toJson() const;

View file

@ -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<FolioDelegate>(app, parent);
return std::make_shared<FolioDelegate>(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<FolioDelegate>(folder, parent);
return std::make_shared<FolioDelegate>(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<FolioDelegate>(widget, parent);
return std::make_shared<FolioDelegate>(widget);
}
} else if (type == "none") {
return std::make_shared<FolioDelegate>(parent);
return std::make_shared<FolioDelegate>();
}
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<FolioPageDelegate>(row, column, fd, parent);
FolioPageDelegate::Ptr delegate = std::make_shared<FolioPageDelegate>(row, column, fd, homeScreen);
fd->deleteLater();
return delegate;

View file

@ -34,12 +34,12 @@ public:
};
Q_ENUM(Type)
FolioDelegate(HomeScreen *parent);
FolioDelegate(std::shared_ptr<FolioApplication> application, HomeScreen *parent);
FolioDelegate(std::shared_ptr<FolioApplicationFolder> folder, HomeScreen *parent);
FolioDelegate(std::shared_ptr<FolioWidget> widget, HomeScreen *parent);
FolioDelegate(QObject *parent = nullptr);
FolioDelegate(std::shared_ptr<FolioApplication> application, QObject *parent = nullptr);
FolioDelegate(std::shared_ptr<FolioApplicationFolder> folder, QObject *parent = nullptr);
FolioDelegate(std::shared_ptr<FolioWidget> widget, QObject *parent = nullptr);
static std::shared_ptr<FolioDelegate> fromJson(QJsonObject &obj, HomeScreen *parent);
static std::shared_ptr<FolioDelegate> fromJson(QJsonObject &obj, HomeScreen *homeScreen);
virtual QJsonObject toJson() const;
@ -71,13 +71,13 @@ class FolioPageDelegate : public FolioDelegate
public:
typedef std::shared_ptr<FolioPageDelegate> Ptr;
FolioPageDelegate(int row = 0, int column = 0, HomeScreen *parent = nullptr);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioApplication> application, HomeScreen *parent);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioApplicationFolder> folder, HomeScreen *parent);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioWidget> widget, HomeScreen *parent);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioDelegate> delegate, HomeScreen *parent);
FolioPageDelegate(int row = 0, int column = 0, HomeScreen *homeScreen = nullptr, QObject *parent = nullptr);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioApplication> application, HomeScreen *homeScreen, QObject *parent = nullptr);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioApplicationFolder> folder, HomeScreen *homeScreen, QObject *parent = nullptr);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioWidget> widget, HomeScreen *homeScreen, QObject *parent = nullptr);
FolioPageDelegate(int row, int column, std::shared_ptr<FolioDelegate> delegate, HomeScreen *homeScreen, QObject *parent = nullptr);
static std::shared_ptr<FolioPageDelegate> fromJson(QJsonObject &obj, HomeScreen *parent);
static std::shared_ptr<FolioPageDelegate> fromJson(QJsonObject &obj, HomeScreen *homeScreen);
static int getTranslatedTopLeftRow(HomeScreen *homeScreen, int realRow, int realColumn, std::shared_ptr<FolioDelegate> fd);
static int getTranslatedTopLeftColumn(HomeScreen *homeScreen, int realRow, int realColumn, std::shared_ptr<FolioDelegate> fd);
static int getTranslatedRow(HomeScreen *homeScreen, int realRow, int realColumn);

View file

@ -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}
{
}

View file

@ -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<int>(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<FolioWidget>(parent, id, gridWidth, gridHeight);
return std::make_shared<FolioWidget>(homeScreen, id, gridWidth, gridHeight);
}
QJsonObject FolioWidget::toJson() const

View file

@ -34,10 +34,10 @@ class FolioWidget : public QObject, public std::enable_shared_from_this<FolioWid
public:
typedef std::shared_ptr<FolioWidget> 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<FolioWidget> fromJson(QJsonObject &obj, HomeScreen *parent);
static std::shared_ptr<FolioWidget> fromJson(QJsonObject &obj, HomeScreen *homeScreen);
QJsonObject toJson() const;
int id() const;