Remove usage of QWeakPointer for QObject
This usage of QWeakPointer has been deprecated since Qt 5.0, since it leads to really confusing API - usually you must never dereference a QWeakPointer directly, but always go through QSharedPointer, except in this one case, where it's permissible. Use QPointer instead, which is clean. Only keep the QPointer where the object in question may get deleted, while in the API where it has to be valid, use a regular pointer. Initializing the pointer explicitly to nullptr makes no sense.
This commit is contained in:
parent
8f5b781a33
commit
9002f9b99e
2 changed files with 13 additions and 12 deletions
|
@ -96,7 +96,6 @@ UserActionsMenu::UserActionsMenu(QObject *parent)
|
|||
, m_closeOperation(NULL)
|
||||
, m_removeFromTabGroup(NULL)
|
||||
, m_closeTabGroup(NULL)
|
||||
, m_client(QWeakPointer<AbstractClient>())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -132,8 +131,9 @@ bool UserActionsMenu::isMenuClient(const AbstractClient *c) const
|
|||
return c == m_client.data();
|
||||
}
|
||||
|
||||
void UserActionsMenu::show(const QRect &pos, const QWeakPointer<AbstractClient> &cl)
|
||||
void UserActionsMenu::show(const QRect &pos, AbstractClient *client)
|
||||
{
|
||||
QPointer<AbstractClient> cl(client);
|
||||
if (!KAuthorized::authorizeAction(QStringLiteral("kwin_rmb")))
|
||||
return;
|
||||
if (cl.isNull())
|
||||
|
@ -189,7 +189,7 @@ void UserActionsMenu::grabInput()
|
|||
m_menu->windowHandle()->setKeyboardGrabEnabled(true);
|
||||
}
|
||||
|
||||
void UserActionsMenu::helperDialog(const QString& message, const QWeakPointer<AbstractClient> &c)
|
||||
void UserActionsMenu::helperDialog(const QString& message, AbstractClient* client)
|
||||
{
|
||||
QStringList args;
|
||||
QString type;
|
||||
|
@ -226,8 +226,8 @@ void UserActionsMenu::helperDialog(const QString& message, const QWeakPointer<Ab
|
|||
return;
|
||||
args << QStringLiteral("--dontagain") << QLatin1String("kwin_dialogsrc:") + type;
|
||||
}
|
||||
if (!c.isNull())
|
||||
args << QStringLiteral("--embed") << QString::number(c.data()->windowId());
|
||||
if (client)
|
||||
args << QStringLiteral("--embed") << QString::number(client->windowId());
|
||||
QtConcurrent::run([args]() {
|
||||
KProcess::startDetached(QStringLiteral("kdialog"), args);
|
||||
});
|
||||
|
@ -835,17 +835,17 @@ void UserActionsMenu::slotWindowOperation(QAction *action)
|
|||
return;
|
||||
|
||||
Options::WindowOperation op = static_cast< Options::WindowOperation >(action->data().toInt());
|
||||
QWeakPointer<AbstractClient> c = (!m_client.isNull()) ? m_client : QWeakPointer<AbstractClient>(Workspace::self()->activeClient());
|
||||
QPointer<AbstractClient> c = m_client ? m_client : QPointer<AbstractClient>(Workspace::self()->activeClient());
|
||||
if (c.isNull())
|
||||
return;
|
||||
QString type;
|
||||
switch(op) {
|
||||
case Options::FullScreenOp:
|
||||
if (!c.data()->isFullScreen() && c.data()->userCanSetFullScreen())
|
||||
if (!c->isFullScreen() && c->userCanSetFullScreen())
|
||||
type = QStringLiteral("fullscreenaltf3");
|
||||
break;
|
||||
case Options::NoBorderOp:
|
||||
if (!c.data()->noBorder() && c.data()->userCanSetNoBorder())
|
||||
if (!c->noBorder() && c->userCanSetNoBorder())
|
||||
type = QStringLiteral("noborderaltf3");
|
||||
break;
|
||||
default:
|
||||
|
@ -858,7 +858,7 @@ void UserActionsMenu::slotWindowOperation(QAction *action)
|
|||
qRegisterMetaType<Options::WindowOperation>();
|
||||
QMetaObject::invokeMethod(workspace(), "performWindowOperation",
|
||||
Qt::QueuedConnection,
|
||||
Q_ARG(KWin::AbstractClient*, c.data()),
|
||||
Q_ARG(KWin::AbstractClient*, c),
|
||||
Q_ARG(Options::WindowOperation, op));
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// Qt
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
|
||||
class QAction;
|
||||
class QRect;
|
||||
|
@ -98,7 +99,7 @@ public:
|
|||
* @param pos The position where the menu should be shown.
|
||||
* @param client The Client for which the Menu has to be shown.
|
||||
*/
|
||||
void show(const QRect &pos, const QWeakPointer<AbstractClient> &client);
|
||||
void show(const QRect &pos, AbstractClient *client);
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
|
@ -219,7 +220,7 @@ private:
|
|||
* @param message The message type to be shown
|
||||
* @param c The Client for which the dialog should be shown.
|
||||
*/
|
||||
void helperDialog(const QString &message, const QWeakPointer<AbstractClient> &c);
|
||||
void helperDialog(const QString &message, AbstractClient *c);
|
||||
/**
|
||||
* The actual main context menu which is show when the UserActionsMenu is invoked.
|
||||
*/
|
||||
|
@ -274,7 +275,7 @@ private:
|
|||
/**
|
||||
* The Client for which the menu is shown.
|
||||
*/
|
||||
QWeakPointer<AbstractClient> m_client;
|
||||
QPointer<AbstractClient> m_client;
|
||||
QAction *m_rulesOperation = nullptr;
|
||||
QAction *m_applicationRulesOperation = nullptr;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue