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
qlayoutpolicy.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:trivial-parsing-only
4
6#include <QtCore/qdebug.h>
7#include <QtCore/qdatastream.h>
8
10
12{
13 /*
14 The control type is a flag type, with values 0x1, 0x2, 0x4, 0x8, 0x10,
15 etc. In memory, we pack it onto the available bits (CTSize) in
16 setControlType(), and unpack it here.
17
18 Example:
19
20 0x00000001 maps to 0
21 0x00000002 maps to 1
22 0x00000004 maps to 2
23 0x00000008 maps to 3
24 etc.
25 */
26 bits.ctype = qCountTrailingZeroBits(quint32(type));
27}
28
30{
31 return QLayoutPolicy::ControlType(1 << bits.ctype);
32}
33
34#ifndef QT_NO_DATASTREAM
35
36/*!
37 \relates QLayoutPolicy
38
39 Writes the size \a policy to the data stream \a stream.
40
41 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
42*/
43QDataStream &operator<<(QDataStream &stream, const QLayoutPolicy &policy)
44{
45 // The order here is for historical reasons. (compatibility with Qt4)
46 quint32 data = (policy.bits.horPolicy | // [0, 3]
47 policy.bits.verPolicy << 4 | // [4, 7]
48 policy.bits.hfw << 8 | // [8]
49 policy.bits.ctype << 9 | // [9, 13]
50 policy.bits.wfh << 14 | // [14]
51 //policy.bits.padding << 15 | // [15]
52 policy.bits.verStretch << 16 | // [16, 23]
53 policy.bits.horStretch << 24); // [24, 31]
54 return stream << data;
55}
56
57#define VALUE_OF_BITS(data, bitstart, bitcount) ((data >> bitstart) & ((1 << bitcount) -1))
58
59/*!
60 \relates QLayoutPolicy
61
62 Reads the size \a policy from the data stream \a stream.
63
64 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
65*/
66QDataStream &operator>>(QDataStream &stream, QLayoutPolicy &policy)
67{
68 quint32 data;
69 stream >> data;
70 policy.bits.horPolicy = VALUE_OF_BITS(data, 0, 4);
71 policy.bits.verPolicy = VALUE_OF_BITS(data, 4, 4);
72 policy.bits.hfw = VALUE_OF_BITS(data, 8, 1);
73 policy.bits.ctype = VALUE_OF_BITS(data, 9, 5);
74 policy.bits.wfh = VALUE_OF_BITS(data, 14, 1);
75 policy.bits.padding = 0;
76 policy.bits.verStretch = VALUE_OF_BITS(data, 16, 8);
77 policy.bits.horStretch = VALUE_OF_BITS(data, 24, 8);
78 return stream;
79}
80#endif // QT_NO_DATASTREAM
81
82#ifndef QT_NO_DEBUG_STREAM
83QDebug operator<<(QDebug dbg, const QLayoutPolicy &p)
84{
85 QDebugStateSaver saver(dbg);
86 dbg.nospace() << "QLayoutPolicy(horizontalPolicy = " << p.horizontalPolicy()
87 << ", verticalPolicy = " << p.verticalPolicy() << ')';
88 return dbg;
89}
90#endif
91
92QT_END_NAMESPACE
93
94#include "moc_qlayoutpolicy_p.cpp"
friend QDataStream & operator>>(QDataStream &, QLayoutPolicy &)
Reads the size policy from the data stream stream.
friend QDataStream & operator<<(QDataStream &, const QLayoutPolicy &)
Writes the size policy to the data stream stream.
Q_GUI_EXPORT void setControlType(ControlType type)
QDebug operator<<(QDebug dbg, const QLayoutPolicy &p)
#define VALUE_OF_BITS(data, bitstart, bitcount)