diff --git a/applets/appmenu/plugin/appmenumodel.h b/applets/appmenu/plugin/appmenumodel.h index c5d530dcd..dc609d9d8 100644 --- a/applets/appmenu/plugin/appmenumodel.h +++ b/applets/appmenu/plugin/appmenumodel.h @@ -79,7 +79,7 @@ private: //! window that its menu initialization may be delayed WId m_delayedMenuWindowId = 0; - QScopedPointer m_searchMenu; + std::unique_ptr m_searchMenu; QPointer m_menu; QPointer m_searchAction; QList m_currentSearchActions; diff --git a/applets/icon/iconapplet.cpp b/applets/icon/iconapplet.cpp index 55a6fd4d4..22073a68a 100644 --- a/applets/icon/iconapplet.cpp +++ b/applets/icon/iconapplet.cpp @@ -370,7 +370,7 @@ QList IconApplet::contextualActions() m_openWithMenu.reset(new QMenu()); } m_openWithMenu->clear(); - m_fileItemActions->insertOpenWithActionsTo(nullptr, m_openWithMenu.data(), QStringList()); + m_fileItemActions->insertOpenWithActionsTo(nullptr, m_openWithMenu.get(), QStringList()); m_openWithActions = m_openWithMenu->actions(); } diff --git a/applets/icon/iconapplet.h b/applets/icon/iconapplet.h index 3bc32f8cf..217318f97 100644 --- a/applets/icon/iconapplet.h +++ b/applets/icon/iconapplet.h @@ -87,7 +87,7 @@ private: QAction *m_openContainingFolderAction = nullptr; KFileItemActions *m_fileItemActions = nullptr; - QScopedPointer m_openWithMenu; + std::unique_ptr m_openWithMenu; QPointer m_configDialog; diff --git a/appmenu/appmenu.cpp b/appmenu/appmenu.cpp index 8b56e2ee7..bd240be82 100644 --- a/appmenu/appmenu.cpp +++ b/appmenu/appmenu.cpp @@ -7,6 +7,7 @@ */ #include "appmenu.h" +#include "../c_ptr.h" #include "appmenu_dbus.h" #include "appmenu_debug.h" #include "appmenuadaptor.h" @@ -134,8 +135,8 @@ void AppMenuModule::slotWindowRegistered(WId id, const QString &serviceName, con auto setWindowProperty = [c](WId id, xcb_atom_t &atom, const QByteArray &name, const QByteArray &value) { if (atom == XCB_ATOM_NONE) { const xcb_intern_atom_cookie_t cookie = xcb_intern_atom(c, false, name.length(), name.constData()); - QScopedPointer reply(xcb_intern_atom_reply(c, cookie, nullptr)); - if (reply.isNull()) { + UniqueCPointer reply{xcb_intern_atom_reply(c, cookie, nullptr)}; + if (!reply) { return; } atom = reply->atom; diff --git a/c_ptr.h b/c_ptr.h new file mode 100644 index 000000000..0e263ee46 --- /dev/null +++ b/c_ptr.h @@ -0,0 +1,20 @@ +/* + SPDX-FileCopyrightText: 2022 Xaver Hugl + + SPDX-License-Identifier: LGPL-2.1-or-later +*/ +#pragma once +#include + +struct CDeleter { + template + void operator()(T *ptr) + { + if (ptr) { + free(ptr); + } + } +}; + +template +using UniqueCPointer = std::unique_ptr; diff --git a/components/shellprivate/widgetexplorer/widgetexplorer.cpp b/components/shellprivate/widgetexplorer/widgetexplorer.cpp index bd7db9518..c20bd5906 100644 --- a/components/shellprivate/widgetexplorer/widgetexplorer.cpp +++ b/components/shellprivate/widgetexplorer/widgetexplorer.cpp @@ -58,7 +58,7 @@ public: , filterModel(w) , activitiesConsumer(new KActivities::Consumer()) { - QObject::connect(activitiesConsumer.data(), &Consumer::currentActivityChanged, q, [this] { + QObject::connect(activitiesConsumer.get(), &Consumer::currentActivityChanged, q, [this] { initRunningApplets(); }); } @@ -98,7 +98,7 @@ public: DefaultItemFilterProxyModel filterItemModel; static QPointer newStuffDialog; - QScopedPointer activitiesConsumer; + std::unique_ptr activitiesConsumer; }; QPointer WidgetExplorerPrivate::newStuffDialog; diff --git a/gmenu-dbusmenu-proxy/menuproxy.cpp b/gmenu-dbusmenu-proxy/menuproxy.cpp index df64bca00..d78db0c43 100644 --- a/gmenu-dbusmenu-proxy/menuproxy.cpp +++ b/gmenu-dbusmenu-proxy/menuproxy.cpp @@ -31,6 +31,7 @@ #endif #include +#include "../c_ptr.h" #include "window.h" #include @@ -340,14 +341,14 @@ QByteArray MenuProxy::getWindowPropertyString(WId id, const QByteArray &name) static const long MAX_PROP_SIZE = 10000; auto propertyCookie = xcb_get_property(m_xConnection, false, id, atom, utf8StringAtom, 0, MAX_PROP_SIZE); - QScopedPointer propertyReply(xcb_get_property_reply(m_xConnection, propertyCookie, nullptr)); - if (propertyReply.isNull()) { + UniqueCPointer propertyReply(xcb_get_property_reply(m_xConnection, propertyCookie, nullptr)); + if (!propertyReply) { qCWarning(DBUSMENUPROXY) << "XCB property reply for atom" << name << "on" << id << "was null"; return value; } if (propertyReply->type == utf8StringAtom && propertyReply->format == 8 && propertyReply->value_len > 0) { - const char *data = (const char *)xcb_get_property_value(propertyReply.data()); + const char *data = (const char *)xcb_get_property_value(propertyReply.get()); int len = propertyReply->value_len; if (data) { value = QByteArray(data, data[len - 1] ? len : len - 1); @@ -378,8 +379,8 @@ xcb_atom_t MenuProxy::getAtom(const QByteArray &name) auto atom = s_atoms.value(name, XCB_ATOM_NONE); if (atom == XCB_ATOM_NONE) { const xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom(m_xConnection, false, name.length(), name.constData()); - QScopedPointer atomReply(xcb_intern_atom_reply(m_xConnection, atomCookie, nullptr)); - if (!atomReply.isNull()) { + UniqueCPointer atomReply(xcb_intern_atom_reply(m_xConnection, atomCookie, nullptr)); + if (atomReply) { atom = atomReply->atom; if (atom != XCB_ATOM_NONE) { s_atoms.insert(name, atom); diff --git a/kcms/colors/colors.h b/kcms/colors/colors.h index 4e9f3f7a5..907fb0711 100644 --- a/kcms/colors/colors.h +++ b/kcms/colors/colors.h @@ -12,7 +12,6 @@ #include #include #include -#include #include @@ -120,6 +119,6 @@ private: KSharedConfigPtr m_config; KConfigWatcher::Ptr m_configWatcher; - QScopedPointer m_tempInstallFile; + std::unique_ptr m_tempInstallFile; QPointer m_tempCopyJob; }; diff --git a/kcms/cursortheme/kcmcursortheme.h b/kcms/cursortheme/kcmcursortheme.h index 1409d90f7..94b419787 100644 --- a/kcms/cursortheme/kcmcursortheme.h +++ b/kcms/cursortheme/kcmcursortheme.h @@ -9,7 +9,6 @@ #include #include -#include #include "cursorthemesettings.h" @@ -121,6 +120,6 @@ private: bool m_canResize; bool m_canConfigure; - QScopedPointer m_tempInstallFile; + std::unique_ptr m_tempInstallFile; QPointer m_tempCopyJob; }; diff --git a/kcms/desktoptheme/kcm.h b/kcms/desktoptheme/kcm.h index 8988da83b..d57f7d468 100644 --- a/kcms/desktoptheme/kcm.h +++ b/kcms/desktoptheme/kcm.h @@ -84,7 +84,7 @@ private: QHash m_themes; bool m_haveThemeExplorerInstalled; - QScopedPointer m_tempInstallFile; + std::unique_ptr m_tempInstallFile; QPointer m_tempCopyJob; }; diff --git a/kcms/icons/main.cpp b/kcms/icons/main.cpp index 65da0d570..f71894ae0 100644 --- a/kcms/icons/main.cpp +++ b/kcms/icons/main.cpp @@ -313,7 +313,7 @@ QVariantList IconModule::previewIcons(const QString &themeName, int size, qreal {QStringLiteral("folder-video"), QStringLiteral("folder-videos")}}; // created on-demand as it is quite expensive to do and we don't want to do it every loop iteration either - QScopedPointer theme; + std::unique_ptr theme; QVariantList pixmaps; @@ -327,7 +327,7 @@ QVariantList IconModule::previewIcons(const QString &themeName, int size, qreal theme.reset(new KIconTheme(themeName)); } - pix = getBestIcon(*theme.data(), iconNames, size, dpr); + pix = getBestIcon(*theme.get(), iconNames, size, dpr); // Inserting a pixmap even if null so we know whether we searched for it already QPixmapCache::insert(cacheKey, pix); diff --git a/kcms/icons/main.h b/kcms/icons/main.h index 29ea83dc6..7bb0e5b38 100644 --- a/kcms/icons/main.h +++ b/kcms/icons/main.h @@ -16,7 +16,6 @@ #include #include -#include class KIconTheme; class IconsSettings; @@ -103,6 +102,6 @@ private: mutable QCache m_kiconThemeCache; - QScopedPointer m_tempInstallFile; + std::unique_ptr m_tempInstallFile; QPointer m_tempCopyJob; }; diff --git a/kcms/lookandfeel/kcm.cpp b/kcms/lookandfeel/kcm.cpp index 1230e0dd4..9ae286d39 100644 --- a/kcms/lookandfeel/kcm.cpp +++ b/kcms/lookandfeel/kcm.cpp @@ -358,9 +358,9 @@ void KCMLookandFeel::save() // Test if style can be installed before updating the config. KSharedConfigPtr conf = KSharedConfig::openConfig(package.filePath("defaults")); KConfigGroup cg(conf, "kdeglobals"); - QScopedPointer newStyle(QStyleFactory::create(cg.readEntry("widgetStyle", QString()))); - applyFlags.setFlag(LookAndFeelManager::WidgetStyle, (!newStyle.isNull() && - m_model->data(m_model->index(index, 0), HasWidgetStyleRole).toBool())); //Widget Style isn't in + std::unique_ptr newStyle(QStyleFactory::create(cg.readEntry("widgetStyle", QString()))); + applyFlags.setFlag(LookAndFeelManager::WidgetStyle, + (newStyle != nullptr && m_model->data(m_model->index(index, 0), HasWidgetStyleRole).toBool())); // Widget Style isn't in // the loop above since it has all of this extra checking too for it } m_lnf->setAppearanceToApply(applyFlags); diff --git a/kcms/style/kcmstyle.cpp b/kcms/style/kcmstyle.cpp index 778bdc1b2..c22ef5e2a 100644 --- a/kcms/style/kcmstyle.cpp +++ b/kcms/style/kcmstyle.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -272,7 +271,7 @@ void KCMStyle::save() // Otherwise apps will use the default style despite something else having been written to the config bool newStyleLoaded = false; if (styleSettings()->widgetStyle() != m_previousStyle) { - QScopedPointer newStyle(QStyleFactory::create(styleSettings()->widgetStyle())); + std::unique_ptr newStyle(QStyleFactory::create(styleSettings()->widgetStyle())); if (newStyle) { newStyleLoaded = true; m_previousStyle = styleSettings()->widgetStyle(); diff --git a/kcms/style/previewitem.cpp b/kcms/style/previewitem.cpp index 266abfd83..d1b7e1d91 100644 --- a/kcms/style/previewitem.cpp +++ b/kcms/style/previewitem.cpp @@ -44,7 +44,7 @@ void PreviewItem::componentComplete() bool PreviewItem::eventFilter(QObject *watched, QEvent *event) { - if (watched == m_widget.data()) { + if (watched == m_widget.get()) { switch (event->type()) { case QEvent::Show: case QEvent::UpdateRequest: @@ -118,7 +118,7 @@ void PreviewItem::reload() // Do not wait for this widget to close before the app closes m_widget->setAttribute(Qt::WA_QuitOnClose, false); - m_ui.setupUi(m_widget.data()); + m_ui.setupUi(m_widget.get()); // Prevent Qt from wrongly caching radio button images QPixmapCache::clear(); @@ -136,7 +136,7 @@ void PreviewItem::reload() palette.setColor(QPalette::Inactive, role, palette.color(QPalette::Active, role)); } - setStyleRecursively(m_widget.data(), m_style.data(), palette); + setStyleRecursively(m_widget.get(), m_style.get(), palette); m_widget->ensurePolished(); @@ -183,13 +183,13 @@ void PreviewItem::sendHoverEvent(QHoverEvent *event) QPointF pos = event->pos(); QWidget *child = m_widget->childAt(pos.toPoint()); - QWidget *receiver = child ? child : m_widget.data(); + QWidget *receiver = child ? child : m_widget.get(); dispatchEnterLeave(receiver, m_lastWidgetUnderMouse, mapToGlobal(event->pos())); m_lastWidgetUnderMouse = receiver; - pos = receiver->mapFrom(m_widget.data(), pos.toPoint()); + pos = receiver->mapFrom(m_widget.get(), pos.toPoint()); QMouseEvent mouseEvent(QEvent::MouseMove, pos, diff --git a/kcms/style/previewitem.h b/kcms/style/previewitem.h index 9d4c67336..95056eb41 100644 --- a/kcms/style/previewitem.h +++ b/kcms/style/previewitem.h @@ -9,7 +9,6 @@ #include #include -#include #include "ui_stylepreview.h" @@ -61,8 +60,8 @@ private: Ui::StylePreview m_ui; - QScopedPointer m_widget; + std::unique_ptr m_widget; QPointer m_lastWidgetUnderMouse; - QScopedPointer m_style; + std::unique_ptr m_style; }; diff --git a/kioslave/desktop/tests/kio_desktop_test.cpp b/kioslave/desktop/tests/kio_desktop_test.cpp index 7b5665c17..7dbc9e082 100644 --- a/kioslave/desktop/tests/kio_desktop_test.cpp +++ b/kioslave/desktop/tests/kio_desktop_test.cpp @@ -125,11 +125,11 @@ private Q_SLOTS: QFETCH(QUrl, srcUrl); QFETCH(QUrl, destUrl); - QScopedPointer lister(nullptr); + std::unique_ptr lister; if (withDirListerCache) { lister.reset(new KDirLister); lister->openUrl(QUrl(QStringLiteral("desktop:/"))); - QSignalSpy spyCompleted(lister.data(), static_cast(&KDirLister::completed)); + QSignalSpy spyCompleted(lister.get(), static_cast(&KDirLister::completed)); spyCompleted.wait(); } diff --git a/klipper/autotests/historymodeltest.cpp b/klipper/autotests/historymodeltest.cpp index 2c802572d..ea7464d09 100644 --- a/klipper/autotests/historymodeltest.cpp +++ b/klipper/autotests/historymodeltest.cpp @@ -26,8 +26,8 @@ private Q_SLOTS: void HistoryModelTest::testSetMaxSize() { - QScopedPointer history(new HistoryModel(nullptr)); - QScopedPointer modelTest(new QAbstractItemModelTester(history.data())); + std::unique_ptr history(new HistoryModel(nullptr)); + std::unique_ptr modelTest(new QAbstractItemModelTester(history.get())); QCOMPARE(history->rowCount(), 0); QCOMPARE(history->maxSize(), 0); @@ -64,8 +64,8 @@ void HistoryModelTest::testSetMaxSize() void HistoryModelTest::testInsertRemove() { - QScopedPointer history(new HistoryModel(nullptr)); - QScopedPointer modelTest(new QAbstractItemModelTester(history.data())); + std::unique_ptr history(new HistoryModel(nullptr)); + std::unique_ptr modelTest(new QAbstractItemModelTester(history.get())); history->setMaxSize(10); QCOMPARE(history->rowCount(), 0); @@ -165,8 +165,8 @@ void HistoryModelTest::testInsertRemove() void HistoryModelTest::testClear() { - QScopedPointer history(new HistoryModel(nullptr)); - QScopedPointer modelTest(new QAbstractItemModelTester(history.data())); + std::unique_ptr history(new HistoryModel(nullptr)); + std::unique_ptr modelTest(new QAbstractItemModelTester(history.get())); history->setMaxSize(10); QCOMPARE(history->rowCount(), 0); @@ -187,8 +187,8 @@ void HistoryModelTest::testClear() void HistoryModelTest::testIndexOf() { - QScopedPointer history(new HistoryModel(nullptr)); - QScopedPointer modelTest(new QAbstractItemModelTester(history.data())); + std::unique_ptr history(new HistoryModel(nullptr)); + std::unique_ptr modelTest(new QAbstractItemModelTester(history.get())); history->setMaxSize(10); QCOMPARE(history->rowCount(), 0); QVERIFY(!history->indexOf(QByteArrayLiteral("whatever")).isValid()); @@ -221,8 +221,8 @@ void HistoryModelTest::testType_data() void HistoryModelTest::testType() { - QScopedPointer history(new HistoryModel(nullptr)); - QScopedPointer modelTest(new QAbstractItemModelTester(history.data())); + std::unique_ptr history(new HistoryModel(nullptr)); + std::unique_ptr modelTest(new QAbstractItemModelTester(history.get())); history->setMaxSize(10); QCOMPARE(history->rowCount(), 0); diff --git a/klipper/autotests/historytest.cpp b/klipper/autotests/historytest.cpp index 217c080c5..bb01453f8 100644 --- a/klipper/autotests/historytest.cpp +++ b/klipper/autotests/historytest.cpp @@ -24,9 +24,9 @@ private Q_SLOTS: void HistoryTest::testSetMaxSize() { - QScopedPointer history(new History(nullptr)); - QSignalSpy changedSpy(history.data(), &History::changed); - QSignalSpy topSpy(history.data(), &History::topChanged); + std::unique_ptr history(new History(nullptr)); + QSignalSpy changedSpy(history.get(), &History::changed); + QSignalSpy topSpy(history.get(), &History::topChanged); QVERIFY(history->empty()); QCOMPARE(history->maxSize(), 0u); QVERIFY(changedSpy.isEmpty()); @@ -73,9 +73,9 @@ void HistoryTest::testSetMaxSize() void HistoryTest::testInsertRemove() { - QScopedPointer history(new History(nullptr)); - QSignalSpy topSpy(history.data(), &History::topChanged); - QSignalSpy topUserSelectedSpy(history.data(), &History::topIsUserSelectedSet); + std::unique_ptr history(new History(nullptr)); + QSignalSpy topSpy(history.get(), &History::topChanged); + QSignalSpy topUserSelectedSpy(history.get(), &History::topIsUserSelectedSet); history->setMaxSize(10); QVERIFY(history->empty()); @@ -198,7 +198,7 @@ void HistoryTest::testInsertRemove() void HistoryTest::testClear() { - QScopedPointer history(new History(nullptr)); + std::unique_ptr history(new History(nullptr)); history->setMaxSize(10); QVERIFY(history->empty()); QVERIFY(!history->topIsUserSelected()); @@ -216,7 +216,7 @@ void HistoryTest::testClear() QVERIFY(history->first()); // and clear - QSignalSpy topSpy(history.data(), &History::topChanged); + QSignalSpy topSpy(history.get(), &History::topChanged); QVERIFY(topSpy.isEmpty()); history->slotClear(); QVERIFY(history->empty()); @@ -227,7 +227,7 @@ void HistoryTest::testClear() void HistoryTest::testFind() { - QScopedPointer history(new History(nullptr)); + std::unique_ptr history(new History(nullptr)); history->setMaxSize(10); QVERIFY(history->empty()); QVERIFY(!history->find(QByteArrayLiteral("whatever"))); @@ -246,8 +246,8 @@ void HistoryTest::testFind() void HistoryTest::testCycle() { - QScopedPointer history(new History(nullptr)); - QSignalSpy topSpy(history.data(), &History::topChanged); + std::unique_ptr history(new History(nullptr)); + QSignalSpy topSpy(history.get(), &History::topChanged); history->setMaxSize(10); QVERIFY(!history->nextInCycle()); QVERIFY(!history->prevInCycle()); diff --git a/klipper/klipper.cpp b/klipper/klipper.cpp index 28df33aa8..4e633f0d4 100644 --- a/klipper/klipper.cpp +++ b/klipper/klipper.cpp @@ -38,6 +38,7 @@ #include #include +#include "../c_ptr.h" #include "configdialog.h" #include "history.h" #include "historyitem.h" @@ -721,8 +722,8 @@ bool Klipper::blockFetchingNewData() } xcb_connection_t *c = QX11Info::connection(); const xcb_query_pointer_cookie_t cookie = xcb_query_pointer_unchecked(c, QX11Info::appRootWindow()); - QScopedPointer queryPointer(xcb_query_pointer_reply(c, cookie, nullptr)); - if (queryPointer.isNull()) { + UniqueCPointer queryPointer(xcb_query_pointer_reply(c, cookie, nullptr)); + if (!queryPointer) { return false; } if (((queryPointer->mask & (XCB_KEY_BUT_MASK_SHIFT | XCB_KEY_BUT_MASK_BUTTON_1)) == XCB_KEY_BUT_MASK_SHIFT) // BUG: 85198 @@ -989,7 +990,7 @@ protected: } private: - QScopedPointer m_barcode; + std::unique_ptr m_barcode; }; void Klipper::showBarcode(const QSharedPointer &item) diff --git a/libnotificationmanager/notification_p.h b/libnotificationmanager/notification_p.h index f2f474b29..de550c3ca 100644 --- a/libnotificationmanager/notification_p.h +++ b/libnotificationmanager/notification_p.h @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/libnotificationmanager/server_p.cpp b/libnotificationmanager/server_p.cpp index 5eceb3cd5..059757b83 100644 --- a/libnotificationmanager/server_p.cpp +++ b/libnotificationmanager/server_p.cpp @@ -67,7 +67,7 @@ ServerInfo *ServerPrivate::currentOwner() const m_currentOwner.reset(new ServerInfo()); } - return m_currentOwner.data(); + return m_currentOwner.get(); } bool ServerPrivate::init() diff --git a/libnotificationmanager/server_p.h b/libnotificationmanager/server_p.h index 36e825992..9aa8f349a 100644 --- a/libnotificationmanager/server_p.h +++ b/libnotificationmanager/server_p.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "notification.h" @@ -115,7 +116,7 @@ private: bool m_dbusObjectValid = false; - mutable QScopedPointer m_currentOwner; + mutable std::unique_ptr m_currentOwner; QDBusServiceWatcher *m_inhibitionWatcher = nullptr; QDBusServiceWatcher *m_notificationWatchers = nullptr; diff --git a/libtaskmanager/declarative/pipewiresourceitem.cpp b/libtaskmanager/declarative/pipewiresourceitem.cpp index b666a9383..a8b26c1a9 100644 --- a/libtaskmanager/declarative/pipewiresourceitem.cpp +++ b/libtaskmanager/declarative/pipewiresourceitem.cpp @@ -93,7 +93,7 @@ void PipeWireSourceItem::itemChange(QQuickItem::ItemChange change, const QQuickI void PipeWireSourceItem::releaseResources() { if (window()) { - window()->scheduleRenderJob(new DiscardEglPixmapRunnable(m_image, m_texture.take()), QQuickWindow::NoStage); + window()->scheduleRenderJob(new DiscardEglPixmapRunnable(m_image, m_texture.release()), QQuickWindow::NoStage); m_image = EGL_NO_IMAGE_KHR; } } @@ -121,8 +121,8 @@ void PipeWireSourceItem::setNodeId(uint nodeId) } m_stream->setActive(isVisible() && isComponentComplete()); - connect(m_stream.data(), &PipeWireSourceStream::dmabufTextureReceived, this, &PipeWireSourceItem::updateTextureDmaBuf); - connect(m_stream.data(), &PipeWireSourceStream::imageTextureReceived, this, &PipeWireSourceItem::updateTextureImage); + connect(m_stream.get(), &PipeWireSourceStream::dmabufTextureReceived, this, &PipeWireSourceItem::updateTextureDmaBuf); + connect(m_stream.get(), &PipeWireSourceStream::imageTextureReceived, this, &PipeWireSourceItem::updateTextureImage); } Q_EMIT nodeIdChanged(nodeId); diff --git a/libtaskmanager/declarative/pipewiresourceitem.h b/libtaskmanager/declarative/pipewiresourceitem.h index 20fedc12b..a6814276e 100644 --- a/libtaskmanager/declarative/pipewiresourceitem.h +++ b/libtaskmanager/declarative/pipewiresourceitem.h @@ -52,8 +52,8 @@ private: uint m_nodeId = 0; std::function m_createNextTexture; - QScopedPointer m_stream; - QScopedPointer m_texture; + std::unique_ptr m_stream; + std::unique_ptr m_texture; EGLImage m_image = nullptr; bool m_needsRecreateTexture = false; diff --git a/libtaskmanager/declarative/screencasting.h b/libtaskmanager/declarative/screencasting.h index 1e24cd651..c75765805 100644 --- a/libtaskmanager/declarative/screencasting.h +++ b/libtaskmanager/declarative/screencasting.h @@ -42,7 +42,7 @@ Q_SIGNALS: private: friend class Screencasting; - QScopedPointer d; + std::unique_ptr d; }; class Screencasting : public QObject @@ -73,5 +73,5 @@ Q_SIGNALS: void sourcesChanged(); private: - QScopedPointer d; + std::unique_ptr d; }; diff --git a/runners/bookmarks/autotests/chrome/testchromebookmarks.cpp b/runners/bookmarks/autotests/chrome/testchromebookmarks.cpp index c1929b30b..5ece8d4a1 100644 --- a/runners/bookmarks/autotests/chrome/testchromebookmarks.cpp +++ b/runners/bookmarks/autotests/chrome/testchromebookmarks.cpp @@ -41,7 +41,7 @@ void TestChromeBookmarks::bookmarkFinderShouldReportNoProfilesOnErrors() void TestChromeBookmarks::itShouldFindNothingWhenPrepareIsNotCalled() { - Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); + Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.get(), this); QCOMPARE(chrome->match("any", true).size(), 0); } @@ -61,7 +61,7 @@ void verifyMatch(BookmarkMatch &match, const QString &title, const QString &url) void TestChromeBookmarks::itShouldFindAllBookmarks() { - Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); + Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.get(), this); chrome->prepare(); QList matches = chrome->match("any", true); QCOMPARE(matches.size(), 3); @@ -72,7 +72,7 @@ void TestChromeBookmarks::itShouldFindAllBookmarks() void TestChromeBookmarks::itShouldFindOnlyMatches() { - Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); + Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.get(), this); chrome->prepare(); QList matches = chrome->match("other", false); QCOMPARE(matches.size(), 1); @@ -81,7 +81,7 @@ void TestChromeBookmarks::itShouldFindOnlyMatches() void TestChromeBookmarks::itShouldClearResultAfterCallingTeardown() { - Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.data(), this); + Chrome *chrome = new Chrome(m_findBookmarksInCurrentDirectory.get(), this); chrome->prepare(); QCOMPARE(chrome->match("any", true).size(), 3); chrome->teardown(); diff --git a/runners/bookmarks/autotests/chrome/testchromebookmarks.h b/runners/bookmarks/autotests/chrome/testchromebookmarks.h index 91c0f9c0f..b067b5fe8 100644 --- a/runners/bookmarks/autotests/chrome/testchromebookmarks.h +++ b/runners/bookmarks/autotests/chrome/testchromebookmarks.h @@ -10,6 +10,7 @@ #include "browsers/findprofile.h" #include +#include class FakeFindProfile : public FindProfile { @@ -47,6 +48,6 @@ private Q_SLOTS: void itShouldFindBookmarksFromAllProfiles(); private: - QScopedPointer m_findBookmarksInCurrentDirectory; + std::unique_ptr m_findBookmarksInCurrentDirectory; QString m_configHome; }; diff --git a/shell/panelview.cpp b/shell/panelview.cpp index a0af15be8..9f3f1d713 100644 --- a/shell/panelview.cpp +++ b/shell/panelview.cpp @@ -6,6 +6,7 @@ #include +#include "../c_ptr.h" #include "debug.h" #include "panelconfigview.h" #include "panelshadows_p.h" @@ -777,7 +778,7 @@ void PanelView::setAutoHideEnabled(bool enabled) const QByteArray effectName = QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"); xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c, false, effectName.length(), effectName.constData()); - QScopedPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); + UniqueCPointer atom(xcb_intern_atom_reply(c, atomCookie, nullptr)); if (!atom) { return; diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp index 10eb0e94e..b767ee745 100644 --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -1681,9 +1681,9 @@ void ShellCorona::checkAddPanelAction() } else if (!panelContainmentPlugins.isEmpty()) { m_addPanelAction = new QAction(this); m_addPanelsMenu.reset(new QMenu); - m_addPanelAction->setMenu(m_addPanelsMenu.data()); - connect(m_addPanelsMenu.data(), &QMenu::aboutToShow, this, &ShellCorona::populateAddPanelsMenu); - connect(m_addPanelsMenu.data(), &QMenu::triggered, this, qOverload(&ShellCorona::addPanel)); + m_addPanelAction->setMenu(m_addPanelsMenu.get()); + connect(m_addPanelsMenu.get(), &QMenu::aboutToShow, this, &ShellCorona::populateAddPanelsMenu); + connect(m_addPanelsMenu.get(), &QMenu::triggered, this, qOverload(&ShellCorona::addPanel)); } if (m_addPanelAction) { diff --git a/shell/shellcorona.h b/shell/shellcorona.h index 3f8a200ed..bfad05026 100644 --- a/shell/shellcorona.h +++ b/shell/shellcorona.h @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -261,7 +260,7 @@ private: QList m_waitingPanels; QHash m_activityContainmentPlugins; QAction *m_addPanelAction; - QScopedPointer m_addPanelsMenu; + std::unique_ptr m_addPanelsMenu; KPackage::Package m_lookAndFeelPackage; QTimer m_waitingPanelsTimer; diff --git a/startkde/plasma-session/startup.h b/startkde/plasma-session/startup.h index da3ab8421..3cf35ad28 100644 --- a/startkde/plasma-session/startup.h +++ b/startkde/plasma-session/startup.h @@ -41,7 +41,7 @@ private: void autoStart(int phase); QVector m_processes; - QScopedPointer m_lock; + std::unique_ptr m_lock; static Startup *s_self; }; diff --git a/startkde/startplasma-x11.cpp b/startkde/startplasma-x11.cpp index 817de3511..3194cdc09 100644 --- a/startkde/startplasma-x11.cpp +++ b/startkde/startplasma-x11.cpp @@ -58,7 +58,7 @@ int main(int argc, char **argv) } setupCursor(false); - QScopedPointer ksplash(setupKSplash()); + std::unique_ptr ksplash(setupKSplash()); runEnvironmentScripts(); diff --git a/startkde/startplasma.cpp b/startkde/startplasma.cpp index bc5e278fa..826ff620e 100644 --- a/startkde/startplasma.cpp +++ b/startkde/startplasma.cpp @@ -656,7 +656,7 @@ bool startPlasmaSession(bool wayland) // Create .desktop files for the scripts in .config/autostart-scripts migrateUserScriptsAutostart(); - QScopedPointer startPlasmaSession; + std::unique_ptr startPlasmaSession; if (!useSystemdBoot()) { startPlasmaSession.reset(new QProcess); qCDebug(PLASMA_STARTUP) << "Using classic boot"; @@ -671,7 +671,7 @@ bool startPlasmaSession(bool wayland) } startPlasmaSession->setProcessChannelMode(QProcess::ForwardedChannels); - QObject::connect(startPlasmaSession.data(), &QProcess::finished, &e, [&rc](int exitCode, QProcess::ExitStatus) { + QObject::connect(startPlasmaSession.get(), &QProcess::finished, &e, [&rc](int exitCode, QProcess::ExitStatus) { if (exitCode == 255) { // Startup error messageBox(QStringLiteral("startkde: Could not start plasma_session. Check your installation.\n")); diff --git a/startkde/startplasma.h b/startkde/startplasma.h index 79b3b402c..49de492c5 100644 --- a/startkde/startplasma.h +++ b/startkde/startplasma.h @@ -41,7 +41,7 @@ void playStartupSound(QObject *parent); void gentleTermination(QProcess *process); struct KillBeforeDeleter { - static inline void cleanup(QProcess *pointer) + void operator()(QProcess *pointer) { if (pointer) { gentleTermination(pointer); diff --git a/xembed-sni-proxy/fdoselectionmanager.cpp b/xembed-sni-proxy/fdoselectionmanager.cpp index effcccc22..f51e721be 100644 --- a/xembed-sni-proxy/fdoselectionmanager.cpp +++ b/xembed-sni-proxy/fdoselectionmanager.cpp @@ -24,6 +24,7 @@ #include #include +#include "../c_ptr.h" #include "sniproxy.h" #include "xcbutils.h" @@ -82,10 +83,10 @@ bool FdoSelectionManager::addDamageWatch(xcb_window_t client) xcb_damage_create(c, damageId, client, XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY); xcb_generic_error_t *error = nullptr; - QScopedPointer attr(xcb_get_window_attributes_reply(c, attribsCookie, &error)); - QScopedPointer getAttrError(error); + UniqueCPointer attr(xcb_get_window_attributes_reply(c, attribsCookie, &error)); + UniqueCPointer getAttrError(error); uint32_t events = XCB_EVENT_MASK_STRUCTURE_NOTIFY; - if (!attr.isNull()) { + if (attr) { events = events | attr->your_event_mask; } // if window is already gone, there is no need to handle it. @@ -95,7 +96,7 @@ bool FdoSelectionManager::addDamageWatch(xcb_window_t client) // the event mask will not be removed again. We cannot track whether another component also needs STRUCTURE_NOTIFY (e.g. KWindowSystem). // if we would remove the event mask again, other areas will break. const auto changeAttrCookie = xcb_change_window_attributes_checked(c, client, XCB_CW_EVENT_MASK, &events); - QScopedPointer changeAttrError(xcb_request_check(c, changeAttrCookie)); + UniqueCPointer changeAttrError(xcb_request_check(c, changeAttrCookie)); // if window is gone by this point, it will be caught by eventFilter, so no need to check later errors. if (changeAttrError && changeAttrError->error_code == XCB_WINDOW) { return false; diff --git a/xembed-sni-proxy/sniproxy.cpp b/xembed-sni-proxy/sniproxy.cpp index ff15fef54..994addda6 100644 --- a/xembed-sni-proxy/sniproxy.cpp +++ b/xembed-sni-proxy/sniproxy.cpp @@ -32,6 +32,7 @@ #include "statusnotifieritemadaptor.h" #include "statusnotifierwatcher_interface.h" +#include "../c_ptr.h" #include "xtestsender.h" //#define VISUAL_DEBUG @@ -169,7 +170,7 @@ SNIProxy::SNIProxy(xcb_window_t wid, QObject *parent) // we query if the client selected button presses in the event mask // if the client does supports that we send directly, otherwise we'll use xtest auto waCookie = xcb_get_window_attributes(c, wid); - QScopedPointer windowAttributes(xcb_get_window_attributes_reply(c, waCookie, nullptr)); + UniqueCPointer windowAttributes(xcb_get_window_attributes_reply(c, waCookie, nullptr)); if (windowAttributes && !(windowAttributes->all_event_masks & XCB_EVENT_MASK_BUTTON_PRESS)) { m_injectMode = XTest; } @@ -234,7 +235,7 @@ QSize SNIProxy::calculateClientWindowSize() const auto c = QX11Info::connection(); auto cookie = xcb_get_geometry(c, m_windowId); - QScopedPointer clientGeom(xcb_get_geometry_reply(c, cookie, nullptr)); + UniqueCPointer clientGeom(xcb_get_geometry_reply(c, cookie, nullptr)); QSize clientWindowSize; if (clientGeom) { @@ -391,8 +392,8 @@ QPoint SNIProxy::calculateClickPoint() const // at the same time make the request for rectangles (even if this request isn't needed) xcb_shape_get_rectangles_cookie_t rectaglesCookie = xcb_shape_get_rectangles(c, m_windowId, XCB_SHAPE_SK_BOUNDING); - QScopedPointer extentsReply(xcb_shape_query_extents_reply(c, extentsCookie, nullptr)); - QScopedPointer rectanglesReply(xcb_shape_get_rectangles_reply(c, rectaglesCookie, nullptr)); + UniqueCPointer extentsReply(xcb_shape_query_extents_reply(c, extentsCookie, nullptr)); + UniqueCPointer rectanglesReply(xcb_shape_get_rectangles_reply(c, rectaglesCookie, nullptr)); if (!extentsReply || !rectanglesReply || !extentsReply->bounding_shaped) { return clickPoint; @@ -512,14 +513,14 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y) auto c = QX11Info::connection(); auto cookieSize = xcb_get_geometry(c, m_windowId); - QScopedPointer clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr)); + UniqueCPointer clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr)); if (!clientGeom) { return; } auto cookie = xcb_query_pointer(c, m_windowId); - QScopedPointer pointer(xcb_query_pointer_reply(c, cookie, nullptr)); + UniqueCPointer pointer(xcb_query_pointer_reply(c, cookie, nullptr)); /*qCDebug(SNIPROXY) << "samescreen" << pointer->same_screen << endl << "root x*y" << pointer->root_x << pointer->root_y << endl << "win x*y" << pointer->win_x << pointer->win_y;*/ diff --git a/xembed-sni-proxy/xcbutils.h b/xembed-sni-proxy/xcbutils.h index 4df797d27..c44e39e93 100644 --- a/xembed-sni-proxy/xcbutils.h +++ b/xembed-sni-proxy/xcbutils.h @@ -15,7 +15,6 @@ #include #include -#include #include #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include @@ -23,6 +22,8 @@ #include #endif +#include "../c_ptr.h" + /** XEMBED messages */ #define XEMBED_EMBEDDED_NOTIFY 0 #define XEMBED_WINDOW_ACTIVATE 1 @@ -37,9 +38,6 @@ namespace Xcb { typedef xcb_window_t WindowId; -template -using ScopedCPointer = QScopedPointer; - class Atom { public: @@ -88,8 +86,8 @@ private: if (m_retrieved || !m_cookie.sequence) { return; } - ScopedCPointer reply(xcb_intern_atom_reply(m_connection, m_cookie, nullptr)); - if (!reply.isNull()) { + UniqueCPointer reply(xcb_intern_atom_reply(m_connection, m_cookie, nullptr)); + if (reply) { m_atom = reply->atom; } m_retrieved = true;