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

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtbase/src/gui/util/qlayoutpolicy.cpp