Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpainterstateguard.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 Christian Ehrlicher <ch.ehrlicher@gmx.de>
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
include
"qpainterstateguard.h"
5
6
QT_BEGIN_NAMESPACE
7
8
/*!
9
\class QPainterStateGuard
10
\brief The QPainterStateGuard is a RAII convenience class for balanced
11
QPainter::save() and QPainter::restore() calls.
12
\since 6.9
13
14
\inmodule QtGui
15
\ingroup painting
16
17
\reentrant
18
19
\sa QPainter
20
21
QPainterStateGuard should be used everywhere as a replacement for QPainter::save()
22
to make sure that the corresponding QPainter::restore() is called upon finishing
23
of the painting routine to avoid unbalanced calls between those two functions.
24
25
Example with QPainter::save()/QPainter::restore():
26
\snippet code/src_gui_painting_qpainterstateguard.cpp 0
27
28
Example with QPainterStateGuard:
29
\snippet code/src_gui_painting_qpainterstateguard.cpp 1
30
*/
31
32
/*!
33
\fn QPainterStateGuard::QPainterStateGuard(QPainter *painter, InitialState state = InitialState::Save)
34
Constructs a QPainterStateGuard and calls save() on \a painter if \a state
35
is \c InitialState::Save (which is the default). When QPainterStateGuard is
36
destroyed, restore() is called as often as save() was called to restore the
37
QPainter's state.
38
*/
39
40
/*!
41
\fn QPainterStateGuard::QPainterStateGuard(QPainterStateGuard &&other)
42
43
Move-constructs a painter state guard from \a other.
44
*/
45
46
/*!
47
\fn QPainterStateGuard &QPainterStateGuard::operator=(QPainterStateGuard &&other)
48
49
Move-assigns \a other to this painter state guard.
50
*/
51
52
/*!
53
\fn void QPainterStateGuard::swap(QPainterStateGuard &other)
54
55
Swaps the \a other with this painter state guard. This operation is very
56
fast and never fails.
57
*/
58
59
/*!
60
\fn QPainterStateGuard::~QPainterStateGuard()
61
Destroys the QPainterStateGuard instance and calls restore() as often as save()
62
was called to restore the QPainter's state.
63
*/
64
65
/*!
66
\fn void QPainterStateGuard::save()
67
Calls QPainter::save() and increases the internal save/restore counter by one.
68
*/
69
70
/*!
71
\fn void QPainterStateGuard::restore()
72
Calls QPainter::restore() if the internal save/restore counter is greater than zero.
73
74
\note This function asserts in debug builds if the counter has already reached zero.
75
*/
76
77
QT_END_NAMESPACE
QPlatformGraphicsBufferHelper
\inmodule QtGui
qtbase
src
gui
painting
qpainterstateguard.cpp
Generated on
for Qt by
1.14.0