Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qbsptree.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
9 | ** Commercial License Usage | - | ||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
16 | ** | - | ||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "qbsptree_p.h" | - | ||||||
35 | - | |||||||
36 | QT_BEGIN_NAMESPACE | - | ||||||
37 | - | |||||||
38 | QBspTree::QBspTree() : depth(6), visited(0) {} never executed: end of block | 0 | ||||||
39 | - | |||||||
40 | void QBspTree::create(int n, int d) | - | ||||||
41 | { | - | ||||||
42 | // simple heuristics to find the best tree depth | - | ||||||
43 | if (d == -1) {
| 0 | ||||||
44 | int c; | - | ||||||
45 | for (c = 0; n; ++c)
| 0 | ||||||
46 | n = n / 10; never executed: n = n / 10; | 0 | ||||||
47 | depth = c << 1; | - | ||||||
48 | } else { never executed: end of block | 0 | ||||||
49 | depth = d; | - | ||||||
50 | } never executed: end of block | 0 | ||||||
51 | depth = qMax(depth, uint(1)); | - | ||||||
52 | - | |||||||
53 | nodes.resize((1 << depth) - 1); // resize to number of nodes | - | ||||||
54 | leaves.resize(1 << depth); // resize to number of leaves | - | ||||||
55 | } never executed: end of block | 0 | ||||||
56 | - | |||||||
57 | void QBspTree::destroy() | - | ||||||
58 | { | - | ||||||
59 | leaves.clear(); | - | ||||||
60 | nodes.clear(); | - | ||||||
61 | } never executed: end of block | 0 | ||||||
62 | - | |||||||
63 | void QBspTree::climbTree(const QRect &rect, callback *function, QBspTreeData data) | - | ||||||
64 | { | - | ||||||
65 | if (nodes.isEmpty())
| 0 | ||||||
66 | return; never executed: return; | 0 | ||||||
67 | ++visited; | - | ||||||
68 | climbTree(rect, function, data, 0); | - | ||||||
69 | } never executed: end of block | 0 | ||||||
70 | - | |||||||
71 | void QBspTree::climbTree(const QRect &area, callback *function, QBspTreeData data, int index) | - | ||||||
72 | { | - | ||||||
73 | if (index >= nodes.count()) { // the index points to a leaf
| 0 | ||||||
74 | Q_ASSERT(!nodes.isEmpty()); | - | ||||||
75 | function(leaf(index - nodes.count()), area, visited, data); | - | ||||||
76 | return; never executed: return; | 0 | ||||||
77 | } | - | ||||||
78 | - | |||||||
79 | Node::Type t = (Node::Type) nodes.at(index).type; | - | ||||||
80 | - | |||||||
81 | int pos = nodes.at(index).pos; | - | ||||||
82 | int idx = firstChildIndex(index); | - | ||||||
83 | if (t == Node::VerticalPlane) {
| 0 | ||||||
84 | if (area.left() < pos)
| 0 | ||||||
85 | climbTree(area, function, data, idx); // back never executed: climbTree(area, function, data, idx); | 0 | ||||||
86 | if (area.right() >= pos)
| 0 | ||||||
87 | climbTree(area, function, data, idx + 1); // front never executed: climbTree(area, function, data, idx + 1); | 0 | ||||||
88 | } else { never executed: end of block | 0 | ||||||
89 | if (area.top() < pos)
| 0 | ||||||
90 | climbTree(area, function, data, idx); // back never executed: climbTree(area, function, data, idx); | 0 | ||||||
91 | if (area.bottom() >= pos)
| 0 | ||||||
92 | climbTree(area, function, data, idx + 1); // front never executed: climbTree(area, function, data, idx + 1); | 0 | ||||||
93 | } never executed: end of block | 0 | ||||||
94 | } | - | ||||||
95 | - | |||||||
96 | void QBspTree::init(const QRect &area, int depth, NodeType type, int index) | - | ||||||
97 | { | - | ||||||
98 | Node::Type t = Node::None; // t should never have this value | - | ||||||
99 | if (type == Node::Both) // if both planes are specified, use 2d bsp
| 0 | ||||||
100 | t = (depth & 1) ? Node::HorizontalPlane : Node::VerticalPlane; never executed: t = (depth & 1) ? Node::HorizontalPlane : Node::VerticalPlane;
| 0 | ||||||
101 | else | - | ||||||
102 | t = type; never executed: t = type; | 0 | ||||||
103 | QPoint center = area.center(); | - | ||||||
104 | nodes[index].pos = (t == Node::VerticalPlane ? center.x() : center.y());
| 0 | ||||||
105 | nodes[index].type = t; | - | ||||||
106 | - | |||||||
107 | QRect front = area; | - | ||||||
108 | QRect back = area; | - | ||||||
109 | - | |||||||
110 | if (t == Node::VerticalPlane) {
| 0 | ||||||
111 | front.setLeft(center.x()); | - | ||||||
112 | back.setRight(center.x() - 1); // front includes the center | - | ||||||
113 | } else { // t == Node::HorizontalPlane never executed: end of block | 0 | ||||||
114 | front.setTop(center.y()); | - | ||||||
115 | back.setBottom(center.y() - 1); | - | ||||||
116 | } never executed: end of block | 0 | ||||||
117 | - | |||||||
118 | int idx = firstChildIndex(index); | - | ||||||
119 | if (--depth) {
| 0 | ||||||
120 | init(back, depth, type, idx); | - | ||||||
121 | init(front, depth, type, idx + 1); | - | ||||||
122 | } never executed: end of block | 0 | ||||||
123 | } never executed: end of block | 0 | ||||||
124 | - | |||||||
125 | void QBspTree::insert(QVector<int> &leaf, const QRect &, uint, QBspTreeData data) | - | ||||||
126 | { | - | ||||||
127 | leaf.append(data.i); | - | ||||||
128 | } never executed: end of block | 0 | ||||||
129 | - | |||||||
130 | void QBspTree::remove(QVector<int> &leaf, const QRect &, uint, QBspTreeData data) | - | ||||||
131 | { | - | ||||||
132 | int i = leaf.indexOf(data.i); | - | ||||||
133 | if (i != -1)
| 0 | ||||||
134 | leaf.remove(i); never executed: leaf.remove(i); | 0 | ||||||
135 | } never executed: end of block | 0 | ||||||
136 | - | |||||||
137 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |