QGIS API Documentation 4.1.0-Master (d6fb7a379fb)
Loading...
Searching...
No Matches
qgsscopedconnection.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsscopedconnection.h
3 ----------------------
4 begin : May 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSSCOPEDCONNECTION_H
19#define QGSSCOPEDCONNECTION_H
20
21#include <QMetaObject>
22#include <QObject>
23
24#define SIP_NO_FILE
25
33{
34 public:
39
43 explicit QgsScopedConnection( QMetaObject::Connection connection )
44 : mConnection( std::move( connection ) )
45 {}
46
53
54 // No copies permitted
57
60 : mConnection( std::move( other.mConnection ) )
61 {
62 other.mConnection = QMetaObject::Connection();
63 }
64
66 {
67 if ( this != &other )
68 {
69 disconnect();
70 mConnection = std::move( other.mConnection );
71 other.mConnection = QMetaObject::Connection();
72 }
73 return *this;
74 }
75
76 QgsScopedConnection &operator=( QMetaObject::Connection connection )
77 {
78 disconnect();
79 mConnection = std::move( connection );
80 return *this;
81 }
82
87 {
88 if ( mConnection )
89 {
90 QObject::disconnect( mConnection );
91 mConnection = QMetaObject::Connection();
92 }
93 }
94
95 private:
96 QMetaObject::Connection mConnection;
97};
98
99#endif // QGSSCOPEDCONNECTION_H
void disconnect()
Manually disconnects the managed connection.
QgsScopedConnection()=default
Default constructor (holds an invalid connection).
QgsScopedConnection & operator=(QgsScopedConnection &&other) noexcept
QgsScopedConnection & operator=(const QgsScopedConnection &)=delete
QgsScopedConnection & operator=(QMetaObject::Connection connection)
QgsScopedConnection(QgsScopedConnection &&other) noexcept
Move constructor.
QgsScopedConnection(const QgsScopedConnection &)=delete
QgsScopedConnection(QMetaObject::Connection connection)
Constructor for QgsScopedConnection, managing the specified connection.
~QgsScopedConnection()
Destructor for QgsScopedConnection.