summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qpainterstateguard.cpp
blob: 9f88a6e75d6204477f8192acb4585ea103f4fc6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2024 Christian Ehrlicher <ch.ehrlicher@gmx.de>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qpainterstateguard.h"

QT_BEGIN_NAMESPACE

/*!
    \class QPainterStateGuard
    \brief The QPainterStateGuard is a RAII convenience class for balanced
    QPainter::save() and QPainter::restore() calls.
    \since 6.9

    \inmodule QtGui
    \ingroup painting

    \reentrant

    \sa QPainter

    QPainterStateGuard should be used everywhere as a replacement for QPainter::save()
    to make sure that the corresponding QPainter::restore() is called upon finishing
    of the painting routine to avoid unbalanced calls between those two functions.

    Example with QPainter::save()/QPainter::restore():
    \snippet code/src_gui_painting_qpainterstateguard.cpp 0

    Example with QPainterStateGuard:
    \snippet code/src_gui_painting_qpainterstateguard.cpp 1
*/

/*!
    \fn QPainterStateGuard::QPainterStateGuard(QPainter *painter, InitialState state = InitialState::Save)
    Constructs a QPainterStateGuard and calls save() on \a painter if \a state
    is \c InitialState::Save (which is the default). When QPainterStateGuard is
    destroyed, restore() is called as often as save() was called to restore the
    QPainter's state.
*/

/*!
    \fn QPainterStateGuard::QPainterStateGuard(QPainterStateGuard &&other)

    Move-constructs a painter state guard from \a other.
*/

/*!
    \fn QPainterStateGuard &QPainterStateGuard::operator=(QPainterStateGuard &&other)

    Move-assigns \a other to this painter state guard.
*/

/*!
    \fn void QPainterStateGuard::swap(QPainterStateGuard &other)

    Swaps the \a other with this painter state guard. This operation is very
    fast and never fails.
*/

/*!
    \fn QPainterStateGuard::~QPainterStateGuard()
    Destroys the QPainterStateGuard instance and calls restore() as often as save()
    was called to restore the QPainter's state.
*/

/*!
    \fn void QPainterStateGuard::save()
    Calls QPainter::save() and increases the internal save/restore counter by one.
*/

/*!
    \fn void QPainterStateGuard::restore()
    Calls QPainter::restore() if the internal save/restore counter is greater than zero.

    \note This function asserts in debug builds if the counter has already reached zero.
*/

QT_END_NAMESPACE