| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/util/qgridlayoutengine.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qglobal.h" | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | #include "qgridlayoutengine_p.h" | - | ||||||||||||||||||||||||
| 43 | #include "qvarlengtharray.h" | - | ||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | #include <QtDebug> | - | ||||||||||||||||||||||||
| 46 | #include <QtCore/qmath.h> | - | ||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||
| 48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||
| 50 | template <typename T> | - | ||||||||||||||||||||||||
| 51 | static void insertOrRemoveItems(QVector<T> &items, int index, int delta) | - | ||||||||||||||||||||||||
| 52 | { | - | ||||||||||||||||||||||||
| 53 | int count = items.count(); | - | ||||||||||||||||||||||||
| 54 | if (index < count) {
| 0 | ||||||||||||||||||||||||
| 55 | if (delta > 0) {
| 0 | ||||||||||||||||||||||||
| 56 | items.insert(index, delta, T()); | - | ||||||||||||||||||||||||
| 57 | } else if (delta < 0) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 58 | items.remove(index, qMin(-delta, count - index)); | - | ||||||||||||||||||||||||
| 59 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 60 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 61 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | static qreal growthFactorBelowPreferredSize(qreal desired, qreal sumAvailable, qreal sumDesired) | - | ||||||||||||||||||||||||
| 64 | { | - | ||||||||||||||||||||||||
| 65 | Q_ASSERT(sumDesired != 0.0); | - | ||||||||||||||||||||||||
| 66 | return desired * qPow(sumAvailable / sumDesired, desired / sumDesired); never executed: return desired * qPow(sumAvailable / sumDesired, desired / sumDesired); | 0 | ||||||||||||||||||||||||
| 67 | } | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | static qreal fixedDescent(qreal descent, qreal ascent, qreal targetSize) | - | ||||||||||||||||||||||||
| 70 | { | - | ||||||||||||||||||||||||
| 71 | if (descent < 0.0)
| 0 | ||||||||||||||||||||||||
| 72 | return -1.0; never executed: return -1.0; | 0 | ||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | Q_ASSERT(descent >= 0.0); | - | ||||||||||||||||||||||||
| 75 | Q_ASSERT(ascent >= 0.0); | - | ||||||||||||||||||||||||
| 76 | Q_ASSERT(targetSize >= ascent + descent); | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | qreal extra = targetSize - (ascent + descent); | - | ||||||||||||||||||||||||
| 79 | return descent + (extra / 2.0); never executed: return descent + (extra / 2.0); | 0 | ||||||||||||||||||||||||
| 80 | } | - | ||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||
| 82 | static qreal compare(const QGridLayoutBox &box1, const QGridLayoutBox &box2, int which) | - | ||||||||||||||||||||||||
| 83 | { | - | ||||||||||||||||||||||||
| 84 | qreal size1 = box1.q_sizes(which); | - | ||||||||||||||||||||||||
| 85 | qreal size2 = box2.q_sizes(which); | - | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | if (which == MaximumSize) {
| 0 | ||||||||||||||||||||||||
| 88 | return size2 - size1; never executed: return size2 - size1; | 0 | ||||||||||||||||||||||||
| 89 | } else { | - | ||||||||||||||||||||||||
| 90 | return size1 - size2; never executed: return size1 - size2; | 0 | ||||||||||||||||||||||||
| 91 | } | - | ||||||||||||||||||||||||
| 92 | } | - | ||||||||||||||||||||||||
| 93 | - | |||||||||||||||||||||||||
| 94 | void QGridLayoutBox::add(const QGridLayoutBox &other, int stretch, qreal spacing) | - | ||||||||||||||||||||||||
| 95 | { | - | ||||||||||||||||||||||||
| 96 | Q_ASSERT(q_minimumDescent < 0.0); | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | q_minimumSize += other.q_minimumSize + spacing; | - | ||||||||||||||||||||||||
| 99 | q_preferredSize += other.q_preferredSize + spacing; | - | ||||||||||||||||||||||||
| 100 | q_maximumSize += ((stretch == 0) ? other.q_preferredSize : other.q_maximumSize) + spacing;
| 0 | ||||||||||||||||||||||||
| 101 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||
| 103 | void QGridLayoutBox::combine(const QGridLayoutBox &other) | - | ||||||||||||||||||||||||
| 104 | { | - | ||||||||||||||||||||||||
| 105 | q_minimumDescent = qMax(q_minimumDescent, other.q_minimumDescent); | - | ||||||||||||||||||||||||
| 106 | q_minimumAscent = qMax(q_minimumAscent, other.q_minimumAscent); | - | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | q_minimumSize = qMax(q_minimumAscent + q_minimumDescent, | - | ||||||||||||||||||||||||
| 109 | qMax(q_minimumSize, other.q_minimumSize)); | - | ||||||||||||||||||||||||
| 110 | qreal maxMax; | - | ||||||||||||||||||||||||
| 111 | if (q_maximumSize == FLT_MAX && other.q_maximumSize != FLT_MAX)
| 0 | ||||||||||||||||||||||||
| 112 | maxMax = other.q_maximumSize; never executed: maxMax = other.q_maximumSize; | 0 | ||||||||||||||||||||||||
| 113 | else if (other.q_maximumSize == FLT_MAX && q_maximumSize != FLT_MAX)
| 0 | ||||||||||||||||||||||||
| 114 | maxMax = q_maximumSize; never executed: maxMax = q_maximumSize; | 0 | ||||||||||||||||||||||||
| 115 | else | - | ||||||||||||||||||||||||
| 116 | maxMax = qMax(q_maximumSize, other.q_maximumSize); never executed: maxMax = qMax(q_maximumSize, other.q_maximumSize); | 0 | ||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | q_maximumSize = qMax(q_minimumSize, maxMax); | - | ||||||||||||||||||||||||
| 119 | q_preferredSize = qBound(q_minimumSize, qMax(q_preferredSize, other.q_preferredSize), | - | ||||||||||||||||||||||||
| 120 | q_maximumSize); | - | ||||||||||||||||||||||||
| 121 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | void QGridLayoutBox::normalize() | - | ||||||||||||||||||||||||
| 124 | { | - | ||||||||||||||||||||||||
| 125 | q_maximumSize = qMax(qreal(0.0), q_maximumSize); | - | ||||||||||||||||||||||||
| 126 | q_minimumSize = qBound(qreal(0.0), q_minimumSize, q_maximumSize); | - | ||||||||||||||||||||||||
| 127 | q_preferredSize = qBound(q_minimumSize, q_preferredSize, q_maximumSize); | - | ||||||||||||||||||||||||
| 128 | q_minimumDescent = qMin(q_minimumDescent, q_minimumSize); | - | ||||||||||||||||||||||||
| 129 | - | |||||||||||||||||||||||||
| 130 | Q_ASSERT((q_minimumDescent < 0.0) == (q_minimumAscent < 0.0)); | - | ||||||||||||||||||||||||
| 131 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||||||||||||||
| 134 | void QGridLayoutBox::dump(int indent) const | - | ||||||||||||||||||||||||
| 135 | { | - | ||||||||||||||||||||||||
| 136 | qDebug("%*sBox (%g <= %g <= %g [%g/%g])", indent, "", q_minimumSize, q_preferredSize, | - | ||||||||||||||||||||||||
| 137 | q_maximumSize, q_minimumAscent, q_minimumDescent); | - | ||||||||||||||||||||||||
| 138 | } | - | ||||||||||||||||||||||||
| 139 | #endif | - | ||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||
| 141 | bool operator==(const QGridLayoutBox &box1, const QGridLayoutBox &box2) | - | ||||||||||||||||||||||||
| 142 | { | - | ||||||||||||||||||||||||
| 143 | for (int i = 0; i < NSizes; ++i) {
| 0 | ||||||||||||||||||||||||
| 144 | if (box1.q_sizes(i) != box2.q_sizes(i))
| 0 | ||||||||||||||||||||||||
| 145 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 147 | return box1.q_minimumDescent == box2.q_minimumDescent never executed: return box1.q_minimumDescent == box2.q_minimumDescent && box1.q_minimumAscent == box2.q_minimumAscent; | 0 | ||||||||||||||||||||||||
| 148 | && box1.q_minimumAscent == box2.q_minimumAscent; never executed: return box1.q_minimumDescent == box2.q_minimumDescent && box1.q_minimumAscent == box2.q_minimumAscent; | 0 | ||||||||||||||||||||||||
| 149 | } | - | ||||||||||||||||||||||||
| 150 | - | |||||||||||||||||||||||||
| 151 | void QGridLayoutRowData::reset(int count) | - | ||||||||||||||||||||||||
| 152 | { | - | ||||||||||||||||||||||||
| 153 | ignore.fill(false, count); | - | ||||||||||||||||||||||||
| 154 | boxes.fill(QGridLayoutBox(), count); | - | ||||||||||||||||||||||||
| 155 | multiCellMap.clear(); | - | ||||||||||||||||||||||||
| 156 | stretches.fill(0, count); | - | ||||||||||||||||||||||||
| 157 | spacings.fill(0.0, count); | - | ||||||||||||||||||||||||
| 158 | hasIgnoreFlag = false; | - | ||||||||||||||||||||||||
| 159 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 160 | - | |||||||||||||||||||||||||
| 161 | void QGridLayoutRowData::distributeMultiCells(const QGridLayoutRowInfo &rowInfo, bool snapToPixelGrid) | - | ||||||||||||||||||||||||
| 162 | { | - | ||||||||||||||||||||||||
| 163 | MultiCellMap::const_iterator i = multiCellMap.constBegin(); | - | ||||||||||||||||||||||||
| 164 | for (; i != multiCellMap.constEnd(); ++i) {
| 0 | ||||||||||||||||||||||||
| 165 | int start = i.key().first; | - | ||||||||||||||||||||||||
| 166 | int span = i.key().second; | - | ||||||||||||||||||||||||
| 167 | int end = start + span; | - | ||||||||||||||||||||||||
| 168 | const QGridLayoutBox &box = i.value().q_box; | - | ||||||||||||||||||||||||
| 169 | int stretch = i.value().q_stretch; | - | ||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||
| 171 | QGridLayoutBox totalBox = this->totalBox(start, end); | - | ||||||||||||||||||||||||
| 172 | QVarLengthArray<QGridLayoutBox> extras(span); | - | ||||||||||||||||||||||||
| 173 | QVarLengthArray<qreal> dummy(span); | - | ||||||||||||||||||||||||
| 174 | QVarLengthArray<qreal> newSizes(span); | - | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | for (int j = 0; j < NSizes; ++j) {
| 0 | ||||||||||||||||||||||||
| 177 | qreal extra = compare(box, totalBox, j); | - | ||||||||||||||||||||||||
| 178 | if (extra > 0.0) {
| 0 | ||||||||||||||||||||||||
| 179 | calculateGeometries(start, end, box.q_sizes(j), dummy.data(), newSizes.data(), | - | ||||||||||||||||||||||||
| 180 | 0, totalBox, rowInfo, snapToPixelGrid); | - | ||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||
| 182 | for (int k = 0; k < span; ++k)
| 0 | ||||||||||||||||||||||||
| 183 | extras[k].q_sizes(j) = newSizes[k]; never executed: extras[k].q_sizes(j) = newSizes[k]; | 0 | ||||||||||||||||||||||||
| 184 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 185 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | for (int k = 0; k < span; ++k) {
| 0 | ||||||||||||||||||||||||
| 188 | boxes[start + k].combine(extras[k]); | - | ||||||||||||||||||||||||
| 189 | if (stretch != 0)
| 0 | ||||||||||||||||||||||||
| 190 | stretches[start + k] = qMax(stretches[start + k], stretch); never executed: stretches[start + k] = qMax(stretches[start + k], stretch); | 0 | ||||||||||||||||||||||||
| 191 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 192 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 193 | multiCellMap.clear(); | - | ||||||||||||||||||||||||
| 194 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 195 | namespace { | - | ||||||||||||||||||||||||
| 196 | - | |||||||||||||||||||||||||
| 197 | // does not return int | - | ||||||||||||||||||||||||
| 198 | static inline qreal qround(qreal f) | - | ||||||||||||||||||||||||
| 199 | { | - | ||||||||||||||||||||||||
| 200 | return std::floor(f + qreal(0.5)); never executed: return std::floor(f + qreal(0.5)); | 0 | ||||||||||||||||||||||||
| 201 | } | - | ||||||||||||||||||||||||
| 202 | - | |||||||||||||||||||||||||
| 203 | } | - | ||||||||||||||||||||||||
| 204 | void QGridLayoutRowData::calculateGeometries(int start, int end, qreal targetSize, qreal *positions, | - | ||||||||||||||||||||||||
| 205 | qreal *sizes, qreal *descents, | - | ||||||||||||||||||||||||
| 206 | const QGridLayoutBox &totalBox, | - | ||||||||||||||||||||||||
| 207 | const QGridLayoutRowInfo &rowInfo, bool snapToPixelGrid) | - | ||||||||||||||||||||||||
| 208 | { | - | ||||||||||||||||||||||||
| 209 | Q_ASSERT(end > start); | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | targetSize = qMax(totalBox.q_minimumSize, targetSize); | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | int n = end - start; | - | ||||||||||||||||||||||||
| 214 | QVarLengthArray<qreal> newSizes(n); | - | ||||||||||||||||||||||||
| 215 | QVarLengthArray<qreal> factors(n); | - | ||||||||||||||||||||||||
| 216 | qreal sumFactors = 0.0; | - | ||||||||||||||||||||||||
| 217 | int sumStretches = 0; | - | ||||||||||||||||||||||||
| 218 | qreal sumAvailable; | - | ||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 221 | const int stretch = stretches.at(start + i); | - | ||||||||||||||||||||||||
| 222 | if (stretch > 0)
| 0 | ||||||||||||||||||||||||
| 223 | sumStretches += stretch; never executed: sumStretches += stretch; | 0 | ||||||||||||||||||||||||
| 224 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 225 | - | |||||||||||||||||||||||||
| 226 | if (targetSize < totalBox.q_preferredSize) {
| 0 | ||||||||||||||||||||||||
| 227 | stealBox(start, end, MinimumSize, positions, sizes); | - | ||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||
| 229 | sumAvailable = targetSize - totalBox.q_minimumSize; | - | ||||||||||||||||||||||||
| 230 | if (sumAvailable > 0.0) {
| 0 | ||||||||||||||||||||||||
| 231 | qreal sumDesired = totalBox.q_preferredSize - totalBox.q_minimumSize; | - | ||||||||||||||||||||||||
| 232 | - | |||||||||||||||||||||||||
| 233 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 234 | if (ignore.testBit(start + i)) {
| 0 | ||||||||||||||||||||||||
| 235 | factors[i] = 0.0; | - | ||||||||||||||||||||||||
| 236 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 237 | } | - | ||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | const QGridLayoutBox &box = boxes.at(start + i); | - | ||||||||||||||||||||||||
| 240 | qreal desired = box.q_preferredSize - box.q_minimumSize; | - | ||||||||||||||||||||||||
| 241 | factors[i] = growthFactorBelowPreferredSize(desired, sumAvailable, sumDesired); | - | ||||||||||||||||||||||||
| 242 | sumFactors += factors[i]; | - | ||||||||||||||||||||||||
| 243 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 246 | Q_ASSERT(sumFactors > 0.0); | - | ||||||||||||||||||||||||
| 247 | qreal delta = sumAvailable * factors[i] / sumFactors; | - | ||||||||||||||||||||||||
| 248 | newSizes[i] = sizes[i] + delta; | - | ||||||||||||||||||||||||
| 249 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 250 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 251 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 252 | bool isLargerThanMaximum = (targetSize > totalBox.q_maximumSize); | - | ||||||||||||||||||||||||
| 253 | if (isLargerThanMaximum) {
| 0 | ||||||||||||||||||||||||
| 254 | stealBox(start, end, MaximumSize, positions, sizes); | - | ||||||||||||||||||||||||
| 255 | sumAvailable = targetSize - totalBox.q_maximumSize; | - | ||||||||||||||||||||||||
| 256 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 257 | stealBox(start, end, PreferredSize, positions, sizes); | - | ||||||||||||||||||||||||
| 258 | sumAvailable = targetSize - totalBox.q_preferredSize; | - | ||||||||||||||||||||||||
| 259 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||
| 261 | if (sumAvailable > 0.0) {
| 0 | ||||||||||||||||||||||||
| 262 | qreal sumCurrentAvailable = sumAvailable; | - | ||||||||||||||||||||||||
| 263 | bool somethingHasAMaximumSize = false; | - | ||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||
| 265 | qreal sumSizes = 0.0; | - | ||||||||||||||||||||||||
| 266 | for (int i = 0; i < n; ++i)
| 0 | ||||||||||||||||||||||||
| 267 | sumSizes += sizes[i]; never executed: sumSizes += sizes[i]; | 0 | ||||||||||||||||||||||||
| 268 | - | |||||||||||||||||||||||||
| 269 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 270 | if (ignore.testBit(start + i)) {
| 0 | ||||||||||||||||||||||||
| 271 | newSizes[i] = 0.0; | - | ||||||||||||||||||||||||
| 272 | factors[i] = 0.0; | - | ||||||||||||||||||||||||
| 273 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 274 | } | - | ||||||||||||||||||||||||
| 275 | - | |||||||||||||||||||||||||
| 276 | const QGridLayoutBox &box = boxes.at(start + i); | - | ||||||||||||||||||||||||
| 277 | qreal boxSize; | - | ||||||||||||||||||||||||
| 278 | - | |||||||||||||||||||||||||
| 279 | qreal desired; | - | ||||||||||||||||||||||||
| 280 | if (isLargerThanMaximum) {
| 0 | ||||||||||||||||||||||||
| 281 | boxSize = box.q_maximumSize; | - | ||||||||||||||||||||||||
| 282 | desired = rowInfo.boxes.value(start + i).q_maximumSize - boxSize; | - | ||||||||||||||||||||||||
| 283 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 284 | boxSize = box.q_preferredSize; | - | ||||||||||||||||||||||||
| 285 | desired = box.q_maximumSize - boxSize; | - | ||||||||||||||||||||||||
| 286 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 287 | if (desired == 0.0) {
| 0 | ||||||||||||||||||||||||
| 288 | newSizes[i] = sizes[i]; | - | ||||||||||||||||||||||||
| 289 | factors[i] = 0.0; | - | ||||||||||||||||||||||||
| 290 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 291 | Q_ASSERT(desired > 0.0); | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | int stretch = stretches[start + i]; | - | ||||||||||||||||||||||||
| 294 | if (sumStretches == 0) {
| 0 | ||||||||||||||||||||||||
| 295 | if (hasIgnoreFlag || sizes[i] == 0.0) {
| 0 | ||||||||||||||||||||||||
| 296 | factors[i] = (stretch < 0) ? 1.0 : 0.0;
| 0 | ||||||||||||||||||||||||
| 297 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 298 | factors[i] = (stretch < 0) ? sizes[i] : 0.0;
| 0 | ||||||||||||||||||||||||
| 299 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 300 | } else if (stretch == sumStretches) {
| 0 | ||||||||||||||||||||||||
| 301 | factors[i] = 1.0; | - | ||||||||||||||||||||||||
| 302 | } else if (stretch <= 0) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 303 | factors[i] = 0.0; | - | ||||||||||||||||||||||||
| 304 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 305 | qreal ultimateSize; | - | ||||||||||||||||||||||||
| 306 | qreal ultimateSumSizes; | - | ||||||||||||||||||||||||
| 307 | qreal x = ((stretch * sumSizes) | - | ||||||||||||||||||||||||
| 308 | - (sumStretches * boxSize)) | - | ||||||||||||||||||||||||
| 309 | / (sumStretches - stretch); | - | ||||||||||||||||||||||||
| 310 | if (x >= 0.0) {
| 0 | ||||||||||||||||||||||||
| 311 | ultimateSize = boxSize + x; | - | ||||||||||||||||||||||||
| 312 | ultimateSumSizes = sumSizes + x; | - | ||||||||||||||||||||||||
| 313 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 314 | ultimateSize = boxSize; | - | ||||||||||||||||||||||||
| 315 | ultimateSumSizes = (sumStretches * boxSize) | - | ||||||||||||||||||||||||
| 316 | / stretch; | - | ||||||||||||||||||||||||
| 317 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||
| 319 | /* | - | ||||||||||||||||||||||||
| 320 | We multiply these by 1.5 to give some space for a smooth transition | - | ||||||||||||||||||||||||
| 321 | (at the expense of the stretch factors, which are not fully respected | - | ||||||||||||||||||||||||
| 322 | during the transition). | - | ||||||||||||||||||||||||
| 323 | */ | - | ||||||||||||||||||||||||
| 324 | ultimateSize = ultimateSize * 3 / 2; | - | ||||||||||||||||||||||||
| 325 | ultimateSumSizes = ultimateSumSizes * 3 / 2; | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | qreal beta = ultimateSumSizes - sumSizes; | - | ||||||||||||||||||||||||
| 328 | if (!beta) {
| 0 | ||||||||||||||||||||||||
| 329 | factors[i] = 1; | - | ||||||||||||||||||||||||
| 330 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 331 | qreal alpha = qMin(sumCurrentAvailable, beta); | - | ||||||||||||||||||||||||
| 332 | qreal ultimateFactor = (stretch * ultimateSumSizes / sumStretches) | - | ||||||||||||||||||||||||
| 333 | - (boxSize); | - | ||||||||||||||||||||||||
| 334 | qreal transitionalFactor = sumCurrentAvailable * (ultimateSize - boxSize) / beta; | - | ||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||
| 336 | factors[i] = ((alpha * ultimateFactor) | - | ||||||||||||||||||||||||
| 337 | + ((beta - alpha) * transitionalFactor)) / beta; | - | ||||||||||||||||||||||||
| 338 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 339 | - | |||||||||||||||||||||||||
| 340 | } | - | ||||||||||||||||||||||||
| 341 | sumFactors += factors[i]; | - | ||||||||||||||||||||||||
| 342 | if (desired < sumCurrentAvailable)
| 0 | ||||||||||||||||||||||||
| 343 | somethingHasAMaximumSize = true; never executed: somethingHasAMaximumSize = true; | 0 | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | newSizes[i] = -1.0; | - | ||||||||||||||||||||||||
| 346 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 347 | } | - | ||||||||||||||||||||||||
| 348 | - | |||||||||||||||||||||||||
| 349 | bool keepGoing = somethingHasAMaximumSize; | - | ||||||||||||||||||||||||
| 350 | while (keepGoing) {
| 0 | ||||||||||||||||||||||||
| 351 | //sumCurrentAvailable is so large that something *might* reach its maximum size | - | ||||||||||||||||||||||||
| 352 | keepGoing = false; | - | ||||||||||||||||||||||||
| 353 | - | |||||||||||||||||||||||||
| 354 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 355 | if (newSizes[i] >= 0.0)
| 0 | ||||||||||||||||||||||||
| 356 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||
| 358 | const QVector<QGridLayoutBox> &rBoxes = isLargerThanMaximum ? rowInfo.boxes : boxes;
| 0 | ||||||||||||||||||||||||
| 359 | const QGridLayoutBox &box = rBoxes.value(start + i); | - | ||||||||||||||||||||||||
| 360 | qreal maxBoxSize = box.q_maximumSize; | - | ||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||
| 362 | if (snapToPixelGrid)
| 0 | ||||||||||||||||||||||||
| 363 | maxBoxSize = qMax(box.q_minimumSize, std::floor(maxBoxSize)); never executed: maxBoxSize = qMax(box.q_minimumSize, std::floor(maxBoxSize)); | 0 | ||||||||||||||||||||||||
| 364 | - | |||||||||||||||||||||||||
| 365 | qreal avail = sumCurrentAvailable * factors[i] / sumFactors; | - | ||||||||||||||||||||||||
| 366 | if (sizes[i] + avail >= maxBoxSize) {
| 0 | ||||||||||||||||||||||||
| 367 | newSizes[i] = maxBoxSize; | - | ||||||||||||||||||||||||
| 368 | sumCurrentAvailable -= maxBoxSize - sizes[i]; | - | ||||||||||||||||||||||||
| 369 | sumFactors -= factors[i]; | - | ||||||||||||||||||||||||
| 370 | keepGoing = (sumCurrentAvailable > 0.0); | - | ||||||||||||||||||||||||
| 371 | if (!keepGoing)
| 0 | ||||||||||||||||||||||||
| 372 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 373 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 374 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 375 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 376 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 377 | if (newSizes[i] < 0.0) {
| 0 | ||||||||||||||||||||||||
| 378 | qreal delta = (sumFactors == 0.0) ? 0.0
| 0 | ||||||||||||||||||||||||
| 379 | : sumCurrentAvailable * factors[i] / sumFactors; | - | ||||||||||||||||||||||||
| 380 | newSizes[i] = sizes[i] + delta; | - | ||||||||||||||||||||||||
| 381 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 382 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 383 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 384 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 385 | - | |||||||||||||||||||||||||
| 386 | if (sumAvailable > 0) {
| 0 | ||||||||||||||||||||||||
| 387 | qreal offset = 0; | - | ||||||||||||||||||||||||
| 388 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 389 | qreal delta = newSizes[i] - sizes[i]; | - | ||||||||||||||||||||||||
| 390 | positions[i] += offset; | - | ||||||||||||||||||||||||
| 391 | sizes[i] += delta; | - | ||||||||||||||||||||||||
| 392 | offset += delta; | - | ||||||||||||||||||||||||
| 393 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 394 | - | |||||||||||||||||||||||||
| 395 | #if 0 // some "pixel allocation" | - | ||||||||||||||||||||||||
| 396 | int surplus = targetSize - (positions[n - 1] + sizes[n - 1]); | - | ||||||||||||||||||||||||
| 397 | Q_ASSERT(surplus >= 0 && surplus <= n); | - | ||||||||||||||||||||||||
| 398 | - | |||||||||||||||||||||||||
| 399 | int prevSurplus = -1; | - | ||||||||||||||||||||||||
| 400 | while (surplus > 0 && surplus != prevSurplus) { | - | ||||||||||||||||||||||||
| 401 | prevSurplus = surplus; | - | ||||||||||||||||||||||||
| 402 | - | |||||||||||||||||||||||||
| 403 | int offset = 0; | - | ||||||||||||||||||||||||
| 404 | for (int i = 0; i < n; ++i) { | - | ||||||||||||||||||||||||
| 405 | const QGridLayoutBox &box = boxes.at(start + i); | - | ||||||||||||||||||||||||
| 406 | int delta = (!ignore.testBit(start + i) && surplus > 0 | - | ||||||||||||||||||||||||
| 407 | && factors[i] > 0 && sizes[i] < box.q_maximumSize) | - | ||||||||||||||||||||||||
| 408 | ? 1 : 0; | - | ||||||||||||||||||||||||
| 409 | - | |||||||||||||||||||||||||
| 410 | positions[i] += offset; | - | ||||||||||||||||||||||||
| 411 | sizes[i] += delta; | - | ||||||||||||||||||||||||
| 412 | offset += delta; | - | ||||||||||||||||||||||||
| 413 | surplus -= delta; | - | ||||||||||||||||||||||||
| 414 | } | - | ||||||||||||||||||||||||
| 415 | } | - | ||||||||||||||||||||||||
| 416 | Q_ASSERT(surplus == 0); | - | ||||||||||||||||||||||||
| 417 | #endif | - | ||||||||||||||||||||||||
| 418 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 419 | if (snapToPixelGrid) {
| 0 | ||||||||||||||||||||||||
| 420 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 421 | const qreal oldpos = positions[i]; | - | ||||||||||||||||||||||||
| 422 | positions[i] = qround(oldpos); | - | ||||||||||||||||||||||||
| 423 | const qreal delta = positions[i] - oldpos; | - | ||||||||||||||||||||||||
| 424 | sizes[i] -= delta; | - | ||||||||||||||||||||||||
| 425 | if (i > 0)
| 0 | ||||||||||||||||||||||||
| 426 | sizes[i - 1] += delta; never executed: sizes[i - 1] += delta; | 0 | ||||||||||||||||||||||||
| 427 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||
| 429 | sizes[n - 1] = targetSize - positions[n - 1]; | - | ||||||||||||||||||||||||
| 430 | // This loop serves two purposes: | - | ||||||||||||||||||||||||
| 431 | // 1. round off the small epsilons produced by the above loop. | - | ||||||||||||||||||||||||
| 432 | // 2. avoid that the above loop didn't make the cell width smaller than its minimum constraint. | - | ||||||||||||||||||||||||
| 433 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 434 | const QGridLayoutBox &box = boxes.at(start + i); | - | ||||||||||||||||||||||||
| 435 | sizes[i] = qMax(box.q_minimumSize, qround(sizes[i])); | - | ||||||||||||||||||||||||
| 436 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 437 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 438 | - | |||||||||||||||||||||||||
| 439 | if (descents) {
| 0 | ||||||||||||||||||||||||
| 440 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
| 441 | if (ignore.testBit(start + i))
| 0 | ||||||||||||||||||||||||
| 442 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 443 | const QGridLayoutBox &box = boxes.at(start + i); | - | ||||||||||||||||||||||||
| 444 | descents[i] = fixedDescent(box.q_minimumDescent, box.q_minimumAscent, sizes[i]); | - | ||||||||||||||||||||||||
| 445 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 446 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 447 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | QGridLayoutBox QGridLayoutRowData::totalBox(int start, int end) const | - | ||||||||||||||||||||||||
| 450 | { | - | ||||||||||||||||||||||||
| 451 | QGridLayoutBox result; | - | ||||||||||||||||||||||||
| 452 | if (start < end) {
| 0 | ||||||||||||||||||||||||
| 453 | result.q_maximumSize = 0.0; | - | ||||||||||||||||||||||||
| 454 | qreal nextSpacing = 0.0; | - | ||||||||||||||||||||||||
| 455 | for (int i = start; i < end; ++i) {
| 0 | ||||||||||||||||||||||||
| 456 | if (ignore.testBit(i))
| 0 | ||||||||||||||||||||||||
| 457 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 458 | result.add(boxes.at(i), stretches.at(i), nextSpacing); | - | ||||||||||||||||||||||||
| 459 | nextSpacing = spacings.at(i); | - | ||||||||||||||||||||||||
| 460 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 462 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 463 | } | - | ||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||
| 465 | void QGridLayoutRowData::stealBox(int start, int end, int which, qreal *positions, qreal *sizes) | - | ||||||||||||||||||||||||
| 466 | { | - | ||||||||||||||||||||||||
| 467 | qreal offset = 0.0; | - | ||||||||||||||||||||||||
| 468 | qreal nextSpacing = 0.0; | - | ||||||||||||||||||||||||
| 469 | - | |||||||||||||||||||||||||
| 470 | for (int i = start; i < end; ++i) {
| 0 | ||||||||||||||||||||||||
| 471 | qreal avail = 0.0; | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | if (!ignore.testBit(i)) {
| 0 | ||||||||||||||||||||||||
| 474 | const QGridLayoutBox &box = boxes.at(i); | - | ||||||||||||||||||||||||
| 475 | avail = box.q_sizes(which); | - | ||||||||||||||||||||||||
| 476 | offset += nextSpacing; | - | ||||||||||||||||||||||||
| 477 | nextSpacing = spacings.at(i); | - | ||||||||||||||||||||||||
| 478 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||
| 480 | *positions++ = offset; | - | ||||||||||||||||||||||||
| 481 | *sizes++ = avail; | - | ||||||||||||||||||||||||
| 482 | offset += avail; | - | ||||||||||||||||||||||||
| 483 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 484 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 485 | - | |||||||||||||||||||||||||
| 486 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||||||||||||||
| 487 | void QGridLayoutRowData::dump(int indent) const | - | ||||||||||||||||||||||||
| 488 | { | - | ||||||||||||||||||||||||
| 489 | qDebug("%*sData", indent, ""); | - | ||||||||||||||||||||||||
| 490 | - | |||||||||||||||||||||||||
| 491 | for (int i = 0; i < ignore.count(); ++i) { | - | ||||||||||||||||||||||||
| 492 | qDebug("%*s Row %d (stretch %d, spacing %g)", indent, "", i, stretches.at(i), | - | ||||||||||||||||||||||||
| 493 | spacings.at(i)); | - | ||||||||||||||||||||||||
| 494 | if (ignore.testBit(i)) | - | ||||||||||||||||||||||||
| 495 | qDebug("%*s Ignored", indent, ""); | - | ||||||||||||||||||||||||
| 496 | boxes.at(i).dump(indent + 2); | - | ||||||||||||||||||||||||
| 497 | } | - | ||||||||||||||||||||||||
| 498 | - | |||||||||||||||||||||||||
| 499 | MultiCellMap::const_iterator it = multiCellMap.constBegin(); | - | ||||||||||||||||||||||||
| 500 | while (it != multiCellMap.constEnd()) { | - | ||||||||||||||||||||||||
| 501 | qDebug("%*s Multi-cell entry <%d, %d> (stretch %d)", indent, "", it.key().first, | - | ||||||||||||||||||||||||
| 502 | it.key().second, it.value().q_stretch); | - | ||||||||||||||||||||||||
| 503 | it.value().q_box.dump(indent + 2); | - | ||||||||||||||||||||||||
| 504 | } | - | ||||||||||||||||||||||||
| 505 | } | - | ||||||||||||||||||||||||
| 506 | #endif | - | ||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | QGridLayoutItem::QGridLayoutItem(int row, int column, int rowSpan, int columnSpan, | - | ||||||||||||||||||||||||
| 509 | Qt::Alignment alignment) | - | ||||||||||||||||||||||||
| 510 | : q_alignment(alignment) | - | ||||||||||||||||||||||||
| 511 | { | - | ||||||||||||||||||||||||
| 512 | q_firstRows[Hor] = column; | - | ||||||||||||||||||||||||
| 513 | q_firstRows[Ver] = row; | - | ||||||||||||||||||||||||
| 514 | q_rowSpans[Hor] = columnSpan; | - | ||||||||||||||||||||||||
| 515 | q_rowSpans[Ver] = rowSpan; | - | ||||||||||||||||||||||||
| 516 | q_stretches[Hor] = -1; | - | ||||||||||||||||||||||||
| 517 | q_stretches[Ver] = -1; | - | ||||||||||||||||||||||||
| 518 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 519 | - | |||||||||||||||||||||||||
| 520 | int QGridLayoutItem::firstRow(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 521 | { | - | ||||||||||||||||||||||||
| 522 | return q_firstRows[orientation == Qt::Vertical]; never executed: return q_firstRows[orientation == Qt::Vertical]; | 0 | ||||||||||||||||||||||||
| 523 | } | - | ||||||||||||||||||||||||
| 524 | - | |||||||||||||||||||||||||
| 525 | int QGridLayoutItem::firstColumn(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 526 | { | - | ||||||||||||||||||||||||
| 527 | return q_firstRows[orientation == Qt::Horizontal]; never executed: return q_firstRows[orientation == Qt::Horizontal]; | 0 | ||||||||||||||||||||||||
| 528 | } | - | ||||||||||||||||||||||||
| 529 | - | |||||||||||||||||||||||||
| 530 | int QGridLayoutItem::lastRow(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 531 | { | - | ||||||||||||||||||||||||
| 532 | return firstRow(orientation) + rowSpan(orientation) - 1; never executed: return firstRow(orientation) + rowSpan(orientation) - 1; | 0 | ||||||||||||||||||||||||
| 533 | } | - | ||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||
| 535 | int QGridLayoutItem::lastColumn(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 536 | { | - | ||||||||||||||||||||||||
| 537 | return firstColumn(orientation) + columnSpan(orientation) - 1; never executed: return firstColumn(orientation) + columnSpan(orientation) - 1; | 0 | ||||||||||||||||||||||||
| 538 | } | - | ||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||
| 540 | int QGridLayoutItem::rowSpan(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 541 | { | - | ||||||||||||||||||||||||
| 542 | return q_rowSpans[orientation == Qt::Vertical]; never executed: return q_rowSpans[orientation == Qt::Vertical]; | 0 | ||||||||||||||||||||||||
| 543 | } | - | ||||||||||||||||||||||||
| 544 | - | |||||||||||||||||||||||||
| 545 | int QGridLayoutItem::columnSpan(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 546 | { | - | ||||||||||||||||||||||||
| 547 | return q_rowSpans[orientation == Qt::Horizontal]; never executed: return q_rowSpans[orientation == Qt::Horizontal]; | 0 | ||||||||||||||||||||||||
| 548 | } | - | ||||||||||||||||||||||||
| 549 | - | |||||||||||||||||||||||||
| 550 | void QGridLayoutItem::setFirstRow(int row, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 551 | { | - | ||||||||||||||||||||||||
| 552 | q_firstRows[orientation == Qt::Vertical] = row; | - | ||||||||||||||||||||||||
| 553 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 554 | - | |||||||||||||||||||||||||
| 555 | void QGridLayoutItem::setRowSpan(int rowSpan, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 556 | { | - | ||||||||||||||||||||||||
| 557 | q_rowSpans[orientation == Qt::Vertical] = rowSpan; | - | ||||||||||||||||||||||||
| 558 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 559 | - | |||||||||||||||||||||||||
| 560 | int QGridLayoutItem::stretchFactor(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 561 | { | - | ||||||||||||||||||||||||
| 562 | int stretch = q_stretches[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 563 | if (stretch >= 0)
| 0 | ||||||||||||||||||||||||
| 564 | return stretch; never executed: return stretch; | 0 | ||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | QLayoutPolicy::Policy policy = sizePolicy(orientation); | - | ||||||||||||||||||||||||
| 567 | - | |||||||||||||||||||||||||
| 568 | if (policy & QLayoutPolicy::ExpandFlag) {
| 0 | ||||||||||||||||||||||||
| 569 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
| 570 | } else if (policy & QLayoutPolicy::GrowFlag) {
| 0 | ||||||||||||||||||||||||
| 571 | return -1; // because we max it up never executed: return -1; | 0 | ||||||||||||||||||||||||
| 572 | } else { | - | ||||||||||||||||||||||||
| 573 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 574 | } | - | ||||||||||||||||||||||||
| 575 | } | - | ||||||||||||||||||||||||
| 576 | - | |||||||||||||||||||||||||
| 577 | void QGridLayoutItem::setStretchFactor(int stretch, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 578 | { | - | ||||||||||||||||||||||||
| 579 | Q_ASSERT(stretch >= 0); // ### deal with too big stretches | - | ||||||||||||||||||||||||
| 580 | q_stretches[orientation == Qt::Vertical] = stretch; | - | ||||||||||||||||||||||||
| 581 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 582 | - | |||||||||||||||||||||||||
| 583 | QLayoutPolicy::ControlTypes QGridLayoutItem::controlTypes(LayoutSide /*side*/) const | - | ||||||||||||||||||||||||
| 584 | { | - | ||||||||||||||||||||||||
| 585 | return QLayoutPolicy::DefaultType; never executed: return QLayoutPolicy::DefaultType; | 0 | ||||||||||||||||||||||||
| 586 | } | - | ||||||||||||||||||||||||
| 587 | - | |||||||||||||||||||||||||
| 588 | QGridLayoutBox QGridLayoutItem::box(Qt::Orientation orientation, bool snapToPixelGrid, qreal constraint) const | - | ||||||||||||||||||||||||
| 589 | { | - | ||||||||||||||||||||||||
| 590 | QGridLayoutBox result; | - | ||||||||||||||||||||||||
| 591 | QLayoutPolicy::Policy policy = sizePolicy(orientation); | - | ||||||||||||||||||||||||
| 592 | - | |||||||||||||||||||||||||
| 593 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
| 594 | QSizeF constraintSize(-1.0, constraint); | - | ||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||
| 596 | result.q_preferredSize = sizeHint(Qt::PreferredSize, constraintSize).width(); | - | ||||||||||||||||||||||||
| 597 | - | |||||||||||||||||||||||||
| 598 | if (policy & QLayoutPolicy::ShrinkFlag) {
| 0 | ||||||||||||||||||||||||
| 599 | result.q_minimumSize = sizeHint(Qt::MinimumSize, constraintSize).width(); | - | ||||||||||||||||||||||||
| 600 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 601 | result.q_minimumSize = result.q_preferredSize; | - | ||||||||||||||||||||||||
| 602 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 603 | if (snapToPixelGrid)
| 0 | ||||||||||||||||||||||||
| 604 | result.q_minimumSize = qCeil(result.q_minimumSize); never executed: result.q_minimumSize = qCeil(result.q_minimumSize); | 0 | ||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||
| 606 | if (policy & (QLayoutPolicy::GrowFlag | QLayoutPolicy::ExpandFlag)) {
| 0 | ||||||||||||||||||||||||
| 607 | result.q_maximumSize = sizeHint(Qt::MaximumSize, constraintSize).width(); | - | ||||||||||||||||||||||||
| 608 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 609 | result.q_maximumSize = result.q_preferredSize; | - | ||||||||||||||||||||||||
| 610 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 611 | } else { | - | ||||||||||||||||||||||||
| 612 | QSizeF constraintSize(constraint, -1.0); | - | ||||||||||||||||||||||||
| 613 | - | |||||||||||||||||||||||||
| 614 | result.q_preferredSize = sizeHint(Qt::PreferredSize, constraintSize).height(); | - | ||||||||||||||||||||||||
| 615 | - | |||||||||||||||||||||||||
| 616 | if (policy & QLayoutPolicy::ShrinkFlag) {
| 0 | ||||||||||||||||||||||||
| 617 | result.q_minimumSize = sizeHint(Qt::MinimumSize, constraintSize).height(); | - | ||||||||||||||||||||||||
| 618 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 619 | result.q_minimumSize = result.q_preferredSize; | - | ||||||||||||||||||||||||
| 620 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 621 | if (snapToPixelGrid)
| 0 | ||||||||||||||||||||||||
| 622 | result.q_minimumSize = qCeil(result.q_minimumSize); never executed: result.q_minimumSize = qCeil(result.q_minimumSize); | 0 | ||||||||||||||||||||||||
| 623 | - | |||||||||||||||||||||||||
| 624 | if (policy & (QLayoutPolicy::GrowFlag | QLayoutPolicy::ExpandFlag)) {
| 0 | ||||||||||||||||||||||||
| 625 | result.q_maximumSize = sizeHint(Qt::MaximumSize, constraintSize).height(); | - | ||||||||||||||||||||||||
| 626 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 627 | result.q_maximumSize = result.q_preferredSize; | - | ||||||||||||||||||||||||
| 628 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 629 | - | |||||||||||||||||||||||||
| 630 | if (alignment() & Qt::AlignBaseline) {
| 0 | ||||||||||||||||||||||||
| 631 | result.q_minimumDescent = sizeHint(Qt::MinimumDescent, constraintSize).height(); | - | ||||||||||||||||||||||||
| 632 | if (result.q_minimumDescent != -1.0) {
| 0 | ||||||||||||||||||||||||
| 633 | const qreal minSizeHint = sizeHint(Qt::MinimumSize, constraintSize).height(); | - | ||||||||||||||||||||||||
| 634 | result.q_minimumDescent -= (minSizeHint - result.q_minimumSize); | - | ||||||||||||||||||||||||
| 635 | result.q_minimumAscent = result.q_minimumSize - result.q_minimumDescent; | - | ||||||||||||||||||||||||
| 636 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 637 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 638 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 639 | if (policy & QLayoutPolicy::IgnoreFlag)
| 0 | ||||||||||||||||||||||||
| 640 | result.q_preferredSize = result.q_minimumSize; never executed: result.q_preferredSize = result.q_minimumSize; | 0 | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 643 | } | - | ||||||||||||||||||||||||
| 644 | - | |||||||||||||||||||||||||
| 645 | QRectF QGridLayoutItem::geometryWithin(qreal x, qreal y, qreal width, qreal height, | - | ||||||||||||||||||||||||
| 646 | qreal rowDescent, Qt::Alignment align, bool snapToPixelGrid) const | - | ||||||||||||||||||||||||
| 647 | { | - | ||||||||||||||||||||||||
| 648 | const qreal cellWidth = width; | - | ||||||||||||||||||||||||
| 649 | const qreal cellHeight = height; | - | ||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||
| 651 | QSizeF size = effectiveMaxSize(QSizeF(-1,-1)); | - | ||||||||||||||||||||||||
| 652 | if (hasDynamicConstraint()) {
| 0 | ||||||||||||||||||||||||
| 653 | if (dynamicConstraintOrientation() == Qt::Vertical) {
| 0 | ||||||||||||||||||||||||
| 654 | if (size.width() > cellWidth)
| 0 | ||||||||||||||||||||||||
| 655 | size = effectiveMaxSize(QSizeF(cellWidth, -1)); never executed: size = effectiveMaxSize(QSizeF(cellWidth, -1)); | 0 | ||||||||||||||||||||||||
| 656 | } else if (size.height() > cellHeight) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 657 | size = effectiveMaxSize(QSizeF(-1, cellHeight)); | - | ||||||||||||||||||||||||
| 658 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 659 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 660 | size = size.boundedTo(QSizeF(cellWidth, cellHeight)); | - | ||||||||||||||||||||||||
| 661 | width = size.width(); | - | ||||||||||||||||||||||||
| 662 | height = size.height(); | - | ||||||||||||||||||||||||
| 663 | - | |||||||||||||||||||||||||
| 664 | switch (align & Qt::AlignHorizontal_Mask) { | - | ||||||||||||||||||||||||
| 665 | case Qt::AlignHCenter: never executed: case Qt::AlignHCenter: | 0 | ||||||||||||||||||||||||
| 666 | x += (cellWidth - width)/2; | - | ||||||||||||||||||||||||
| 667 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 668 | case Qt::AlignRight: never executed: case Qt::AlignRight: | 0 | ||||||||||||||||||||||||
| 669 | x += cellWidth - width; | - | ||||||||||||||||||||||||
| 670 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 671 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 672 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 673 | } | - | ||||||||||||||||||||||||
| 674 | - | |||||||||||||||||||||||||
| 675 | switch (align & Qt::AlignVertical_Mask) { | - | ||||||||||||||||||||||||
| 676 | case Qt::AlignVCenter: never executed: case Qt::AlignVCenter: | 0 | ||||||||||||||||||||||||
| 677 | y += (cellHeight - height)/2; | - | ||||||||||||||||||||||||
| 678 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 679 | case Qt::AlignBottom: never executed: case Qt::AlignBottom: | 0 | ||||||||||||||||||||||||
| 680 | y += cellHeight - height; | - | ||||||||||||||||||||||||
| 681 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 682 | case Qt::AlignBaseline: { never executed: case Qt::AlignBaseline: | 0 | ||||||||||||||||||||||||
| 683 | width = qMin(effectiveMaxSize(QSizeF(-1,-1)).width(), width); | - | ||||||||||||||||||||||||
| 684 | QGridLayoutBox vBox = box(Qt::Vertical, snapToPixelGrid); | - | ||||||||||||||||||||||||
| 685 | const qreal descent = vBox.q_minimumDescent; | - | ||||||||||||||||||||||||
| 686 | const qreal ascent = vBox.q_minimumSize - descent; | - | ||||||||||||||||||||||||
| 687 | y += (cellHeight - rowDescent - ascent); | - | ||||||||||||||||||||||||
| 688 | height = ascent + descent; | - | ||||||||||||||||||||||||
| 689 | break; } never executed: break; | 0 | ||||||||||||||||||||||||
| 690 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 691 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 692 | } | - | ||||||||||||||||||||||||
| 693 | return QRectF(x, y, width, height); never executed: return QRectF(x, y, width, height); | 0 | ||||||||||||||||||||||||
| 694 | } | - | ||||||||||||||||||||||||
| 695 | - | |||||||||||||||||||||||||
| 696 | void QGridLayoutItem::transpose() | - | ||||||||||||||||||||||||
| 697 | { | - | ||||||||||||||||||||||||
| 698 | qSwap(q_firstRows[Hor], q_firstRows[Ver]); | - | ||||||||||||||||||||||||
| 699 | qSwap(q_rowSpans[Hor], q_rowSpans[Ver]); | - | ||||||||||||||||||||||||
| 700 | qSwap(q_stretches[Hor], q_stretches[Ver]); | - | ||||||||||||||||||||||||
| 701 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||
| 703 | void QGridLayoutItem::insertOrRemoveRows(int row, int delta, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 704 | { | - | ||||||||||||||||||||||||
| 705 | int oldFirstRow = firstRow(orientation); | - | ||||||||||||||||||||||||
| 706 | if (oldFirstRow >= row) {
| 0 | ||||||||||||||||||||||||
| 707 | setFirstRow(oldFirstRow + delta, orientation); | - | ||||||||||||||||||||||||
| 708 | } else if (lastRow(orientation) >= row) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 709 | setRowSpan(rowSpan(orientation) + delta, orientation); | - | ||||||||||||||||||||||||
| 710 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 711 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 712 | /*! | - | ||||||||||||||||||||||||
| 713 | \internal | - | ||||||||||||||||||||||||
| 714 | returns the effective maximumSize, will take the sizepolicy into | - | ||||||||||||||||||||||||
| 715 | consideration. (i.e. if sizepolicy does not have QLayoutPolicy::Grow, then | - | ||||||||||||||||||||||||
| 716 | maxSizeHint will be the preferredSize) | - | ||||||||||||||||||||||||
| 717 | Note that effectiveSizeHint does not take sizePolicy into consideration, | - | ||||||||||||||||||||||||
| 718 | (since it only evaluates the hints, as the name implies) | - | ||||||||||||||||||||||||
| 719 | */ | - | ||||||||||||||||||||||||
| 720 | QSizeF QGridLayoutItem::effectiveMaxSize(const QSizeF &constraint) const | - | ||||||||||||||||||||||||
| 721 | { | - | ||||||||||||||||||||||||
| 722 | QSizeF size = constraint; | - | ||||||||||||||||||||||||
| 723 | bool vGrow = (sizePolicy(Qt::Vertical) & QLayoutPolicy::GrowFlag) == QLayoutPolicy::GrowFlag; | - | ||||||||||||||||||||||||
| 724 | bool hGrow = (sizePolicy(Qt::Horizontal) & QLayoutPolicy::GrowFlag) == QLayoutPolicy::GrowFlag; | - | ||||||||||||||||||||||||
| 725 | if (!vGrow || !hGrow) {
| 0 | ||||||||||||||||||||||||
| 726 | QSizeF pref = sizeHint(Qt::PreferredSize, constraint); | - | ||||||||||||||||||||||||
| 727 | if (!vGrow)
| 0 | ||||||||||||||||||||||||
| 728 | size.setHeight(pref.height()); never executed: size.setHeight(pref.height()); | 0 | ||||||||||||||||||||||||
| 729 | if (!hGrow)
| 0 | ||||||||||||||||||||||||
| 730 | size.setWidth(pref.width()); never executed: size.setWidth(pref.width()); | 0 | ||||||||||||||||||||||||
| 731 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | if (!size.isValid()) {
| 0 | ||||||||||||||||||||||||
| 734 | QSizeF maxSize = sizeHint(Qt::MaximumSize, size); | - | ||||||||||||||||||||||||
| 735 | if (size.width() == -1)
| 0 | ||||||||||||||||||||||||
| 736 | size.setWidth(maxSize.width()); never executed: size.setWidth(maxSize.width()); | 0 | ||||||||||||||||||||||||
| 737 | if (size.height() == -1)
| 0 | ||||||||||||||||||||||||
| 738 | size.setHeight(maxSize.height()); never executed: size.setHeight(maxSize.height()); | 0 | ||||||||||||||||||||||||
| 739 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 740 | return size; never executed: return size; | 0 | ||||||||||||||||||||||||
| 741 | } | - | ||||||||||||||||||||||||
| 742 | - | |||||||||||||||||||||||||
| 743 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||||||||||||||
| 744 | void QGridLayoutItem::dump(int indent) const | - | ||||||||||||||||||||||||
| 745 | { | - | ||||||||||||||||||||||||
| 746 | qDebug("%*s (%d, %d) %d x %d", indent, "", firstRow(), firstColumn(), //### | - | ||||||||||||||||||||||||
| 747 | rowSpan(), columnSpan()); | - | ||||||||||||||||||||||||
| 748 | - | |||||||||||||||||||||||||
| 749 | if (q_stretches[Hor] >= 0) | - | ||||||||||||||||||||||||
| 750 | qDebug("%*s Horizontal stretch: %d", indent, "", q_stretches[Hor]); | - | ||||||||||||||||||||||||
| 751 | if (q_stretches[Ver] >= 0) | - | ||||||||||||||||||||||||
| 752 | qDebug("%*s Vertical stretch: %d", indent, "", q_stretches[Ver]); | - | ||||||||||||||||||||||||
| 753 | if (q_alignment != 0) | - | ||||||||||||||||||||||||
| 754 | qDebug("%*s Alignment: %x", indent, "", uint(q_alignment)); | - | ||||||||||||||||||||||||
| 755 | qDebug("%*s Horizontal size policy: %x Vertical size policy: %x", | - | ||||||||||||||||||||||||
| 756 | indent, "", sizePolicy(Qt::Horizontal), sizePolicy(Qt::Vertical)); | - | ||||||||||||||||||||||||
| 757 | } | - | ||||||||||||||||||||||||
| 758 | #endif | - | ||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||
| 760 | void QGridLayoutRowInfo::insertOrRemoveRows(int row, int delta) | - | ||||||||||||||||||||||||
| 761 | { | - | ||||||||||||||||||||||||
| 762 | count += delta; | - | ||||||||||||||||||||||||
| 763 | - | |||||||||||||||||||||||||
| 764 | insertOrRemoveItems(stretches, row, delta); | - | ||||||||||||||||||||||||
| 765 | insertOrRemoveItems(spacings, row, delta); | - | ||||||||||||||||||||||||
| 766 | insertOrRemoveItems(alignments, row, delta); | - | ||||||||||||||||||||||||
| 767 | insertOrRemoveItems(boxes, row, delta); | - | ||||||||||||||||||||||||
| 768 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 769 | - | |||||||||||||||||||||||||
| 770 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||||||||||||||
| 771 | void QGridLayoutRowInfo::dump(int indent) const | - | ||||||||||||||||||||||||
| 772 | { | - | ||||||||||||||||||||||||
| 773 | qDebug("%*sInfo (count: %d)", indent, "", count); | - | ||||||||||||||||||||||||
| 774 | for (int i = 0; i < count; ++i) { | - | ||||||||||||||||||||||||
| 775 | QString message; | - | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | if (stretches.value(i).value() >= 0) | - | ||||||||||||||||||||||||
| 778 | message += QString::fromLatin1(" stretch %1").arg(stretches.value(i).value()); | - | ||||||||||||||||||||||||
| 779 | if (spacings.value(i).value() >= 0.0) | - | ||||||||||||||||||||||||
| 780 | message += QString::fromLatin1(" spacing %1").arg(spacings.value(i).value()); | - | ||||||||||||||||||||||||
| 781 | if (alignments.value(i) != 0) | - | ||||||||||||||||||||||||
| 782 | message += QString::fromLatin1(" alignment %1").arg(int(alignments.value(i)), 16); | - | ||||||||||||||||||||||||
| 783 | - | |||||||||||||||||||||||||
| 784 | if (!message.isEmpty() || boxes.value(i) != QGridLayoutBox()) { | - | ||||||||||||||||||||||||
| 785 | qDebug("%*s Row %d:%s", indent, "", i, qPrintable(message)); | - | ||||||||||||||||||||||||
| 786 | if (boxes.value(i) != QGridLayoutBox()) | - | ||||||||||||||||||||||||
| 787 | boxes.value(i).dump(indent + 1); | - | ||||||||||||||||||||||||
| 788 | } | - | ||||||||||||||||||||||||
| 789 | } | - | ||||||||||||||||||||||||
| 790 | } | - | ||||||||||||||||||||||||
| 791 | #endif | - | ||||||||||||||||||||||||
| 792 | - | |||||||||||||||||||||||||
| 793 | QGridLayoutEngine::QGridLayoutEngine(Qt::Alignment defaultAlignment, bool snapToPixelGrid) | - | ||||||||||||||||||||||||
| 794 | { | - | ||||||||||||||||||||||||
| 795 | m_visualDirection = Qt::LeftToRight; | - | ||||||||||||||||||||||||
| 796 | m_defaultAlignment = defaultAlignment; | - | ||||||||||||||||||||||||
| 797 | m_snapToPixelGrid = snapToPixelGrid; | - | ||||||||||||||||||||||||
| 798 | invalidate(); | - | ||||||||||||||||||||||||
| 799 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 800 | - | |||||||||||||||||||||||||
| 801 | int QGridLayoutEngine::rowCount(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 802 | { | - | ||||||||||||||||||||||||
| 803 | return q_infos[orientation == Qt::Vertical].count; never executed: return q_infos[orientation == Qt::Vertical].count; | 0 | ||||||||||||||||||||||||
| 804 | } | - | ||||||||||||||||||||||||
| 805 | - | |||||||||||||||||||||||||
| 806 | int QGridLayoutEngine::columnCount(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 807 | { | - | ||||||||||||||||||||||||
| 808 | return q_infos[orientation == Qt::Horizontal].count; never executed: return q_infos[orientation == Qt::Horizontal].count; | 0 | ||||||||||||||||||||||||
| 809 | } | - | ||||||||||||||||||||||||
| 810 | - | |||||||||||||||||||||||||
| 811 | int QGridLayoutEngine::itemCount() const | - | ||||||||||||||||||||||||
| 812 | { | - | ||||||||||||||||||||||||
| 813 | return q_items.count(); never executed: return q_items.count(); | 0 | ||||||||||||||||||||||||
| 814 | } | - | ||||||||||||||||||||||||
| 815 | - | |||||||||||||||||||||||||
| 816 | QGridLayoutItem *QGridLayoutEngine::itemAt(int index) const | - | ||||||||||||||||||||||||
| 817 | { | - | ||||||||||||||||||||||||
| 818 | Q_ASSERT(index >= 0 && index < itemCount()); | - | ||||||||||||||||||||||||
| 819 | return q_items.at(index); never executed: return q_items.at(index); | 0 | ||||||||||||||||||||||||
| 820 | } | - | ||||||||||||||||||||||||
| 821 | - | |||||||||||||||||||||||||
| 822 | int QGridLayoutEngine::effectiveFirstRow(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 823 | { | - | ||||||||||||||||||||||||
| 824 | ensureEffectiveFirstAndLastRows(); | - | ||||||||||||||||||||||||
| 825 | return q_cachedEffectiveFirstRows[orientation == Qt::Vertical]; never executed: return q_cachedEffectiveFirstRows[orientation == Qt::Vertical]; | 0 | ||||||||||||||||||||||||
| 826 | } | - | ||||||||||||||||||||||||
| 827 | - | |||||||||||||||||||||||||
| 828 | int QGridLayoutEngine::effectiveLastRow(Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 829 | { | - | ||||||||||||||||||||||||
| 830 | ensureEffectiveFirstAndLastRows(); | - | ||||||||||||||||||||||||
| 831 | return q_cachedEffectiveLastRows[orientation == Qt::Vertical]; never executed: return q_cachedEffectiveLastRows[orientation == Qt::Vertical]; | 0 | ||||||||||||||||||||||||
| 832 | } | - | ||||||||||||||||||||||||
| 833 | - | |||||||||||||||||||||||||
| 834 | void QGridLayoutEngine::setSpacing(qreal spacing, Qt::Orientations orientations) | - | ||||||||||||||||||||||||
| 835 | { | - | ||||||||||||||||||||||||
| 836 | if (orientations & Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
| 837 | q_defaultSpacings[Hor].setUserValue(spacing); never executed: q_defaultSpacings[Hor].setUserValue(spacing); | 0 | ||||||||||||||||||||||||
| 838 | if (orientations & Qt::Vertical)
| 0 | ||||||||||||||||||||||||
| 839 | q_defaultSpacings[Ver].setUserValue(spacing); never executed: q_defaultSpacings[Ver].setUserValue(spacing); | 0 | ||||||||||||||||||||||||
| 840 | - | |||||||||||||||||||||||||
| 841 | invalidate(); | - | ||||||||||||||||||||||||
| 842 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 843 | - | |||||||||||||||||||||||||
| 844 | qreal QGridLayoutEngine::spacing(Qt::Orientation orientation, const QAbstractLayoutStyleInfo *styleInfo) const | - | ||||||||||||||||||||||||
| 845 | { | - | ||||||||||||||||||||||||
| 846 | if (!q_defaultSpacings[orientation == Qt::Vertical].isUser()) {
| 0 | ||||||||||||||||||||||||
| 847 | qreal defaultSpacing = styleInfo->spacing(orientation); | - | ||||||||||||||||||||||||
| 848 | q_defaultSpacings[orientation == Qt::Vertical].setCachedValue(defaultSpacing); | - | ||||||||||||||||||||||||
| 849 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 850 | return q_defaultSpacings[orientation == Qt::Vertical].value(); never executed: return q_defaultSpacings[orientation == Qt::Vertical].value(); | 0 | ||||||||||||||||||||||||
| 851 | } | - | ||||||||||||||||||||||||
| 852 | - | |||||||||||||||||||||||||
| 853 | void QGridLayoutEngine::setRowSpacing(int row, qreal spacing, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 854 | { | - | ||||||||||||||||||||||||
| 855 | Q_ASSERT(row >= 0); | - | ||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||
| 857 | QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 858 | if (row >= rowInfo.spacings.count())
| 0 | ||||||||||||||||||||||||
| 859 | rowInfo.spacings.resize(row + 1); never executed: rowInfo.spacings.resize(row + 1); | 0 | ||||||||||||||||||||||||
| 860 | if (spacing >= 0)
| 0 | ||||||||||||||||||||||||
| 861 | rowInfo.spacings[row].setUserValue(spacing); never executed: rowInfo.spacings[row].setUserValue(spacing); | 0 | ||||||||||||||||||||||||
| 862 | else | - | ||||||||||||||||||||||||
| 863 | rowInfo.spacings[row] = QLayoutParameter<qreal>(); never executed: rowInfo.spacings[row] = QLayoutParameter<qreal>(); | 0 | ||||||||||||||||||||||||
| 864 | invalidate(); | - | ||||||||||||||||||||||||
| 865 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 866 | - | |||||||||||||||||||||||||
| 867 | qreal QGridLayoutEngine::rowSpacing(int row, Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 868 | { | - | ||||||||||||||||||||||||
| 869 | QLayoutParameter<qreal> spacing = q_infos[orientation == Qt::Vertical].spacings.value(row); | - | ||||||||||||||||||||||||
| 870 | if (!spacing.isDefault())
| 0 | ||||||||||||||||||||||||
| 871 | return spacing.value(); never executed: return spacing.value(); | 0 | ||||||||||||||||||||||||
| 872 | return q_defaultSpacings[orientation == Qt::Vertical].value(); never executed: return q_defaultSpacings[orientation == Qt::Vertical].value(); | 0 | ||||||||||||||||||||||||
| 873 | } | - | ||||||||||||||||||||||||
| 874 | - | |||||||||||||||||||||||||
| 875 | void QGridLayoutEngine::setRowStretchFactor(int row, int stretch, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 876 | { | - | ||||||||||||||||||||||||
| 877 | Q_ASSERT(row >= 0); | - | ||||||||||||||||||||||||
| 878 | Q_ASSERT(stretch >= 0); | - | ||||||||||||||||||||||||
| 879 | - | |||||||||||||||||||||||||
| 880 | maybeExpandGrid(row, -1, orientation); | - | ||||||||||||||||||||||||
| 881 | - | |||||||||||||||||||||||||
| 882 | QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 883 | if (row >= rowInfo.stretches.count())
| 0 | ||||||||||||||||||||||||
| 884 | rowInfo.stretches.resize(row + 1); never executed: rowInfo.stretches.resize(row + 1); | 0 | ||||||||||||||||||||||||
| 885 | rowInfo.stretches[row].setUserValue(stretch); | - | ||||||||||||||||||||||||
| 886 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||
| 888 | int QGridLayoutEngine::rowStretchFactor(int row, Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 889 | { | - | ||||||||||||||||||||||||
| 890 | QStretchParameter stretch = q_infos[orientation == Qt::Vertical].stretches.value(row); | - | ||||||||||||||||||||||||
| 891 | if (!stretch.isDefault())
| 0 | ||||||||||||||||||||||||
| 892 | return stretch.value(); never executed: return stretch.value(); | 0 | ||||||||||||||||||||||||
| 893 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 894 | } | - | ||||||||||||||||||||||||
| 895 | - | |||||||||||||||||||||||||
| 896 | void QGridLayoutEngine::setRowSizeHint(Qt::SizeHint which, int row, qreal size, | - | ||||||||||||||||||||||||
| 897 | Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 898 | { | - | ||||||||||||||||||||||||
| 899 | Q_ASSERT(row >= 0); | - | ||||||||||||||||||||||||
| 900 | Q_ASSERT(size >= 0.0); | - | ||||||||||||||||||||||||
| 901 | - | |||||||||||||||||||||||||
| 902 | maybeExpandGrid(row, -1, orientation); | - | ||||||||||||||||||||||||
| 903 | - | |||||||||||||||||||||||||
| 904 | QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 905 | if (row >= rowInfo.boxes.count())
| 0 | ||||||||||||||||||||||||
| 906 | rowInfo.boxes.resize(row + 1); never executed: rowInfo.boxes.resize(row + 1); | 0 | ||||||||||||||||||||||||
| 907 | rowInfo.boxes[row].q_sizes(which) = size; | - | ||||||||||||||||||||||||
| 908 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 909 | - | |||||||||||||||||||||||||
| 910 | qreal QGridLayoutEngine::rowSizeHint(Qt::SizeHint which, int row, Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 911 | { | - | ||||||||||||||||||||||||
| 912 | return q_infos[orientation == Qt::Vertical].boxes.value(row).q_sizes(which); never executed: return q_infos[orientation == Qt::Vertical].boxes.value(row).q_sizes(which); | 0 | ||||||||||||||||||||||||
| 913 | } | - | ||||||||||||||||||||||||
| 914 | - | |||||||||||||||||||||||||
| 915 | void QGridLayoutEngine::setRowAlignment(int row, Qt::Alignment alignment, | - | ||||||||||||||||||||||||
| 916 | Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 917 | { | - | ||||||||||||||||||||||||
| 918 | Q_ASSERT(row >= 0); | - | ||||||||||||||||||||||||
| 919 | - | |||||||||||||||||||||||||
| 920 | maybeExpandGrid(row, -1, orientation); | - | ||||||||||||||||||||||||
| 921 | - | |||||||||||||||||||||||||
| 922 | QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 923 | if (row >= rowInfo.alignments.count())
| 0 | ||||||||||||||||||||||||
| 924 | rowInfo.alignments.resize(row + 1); never executed: rowInfo.alignments.resize(row + 1); | 0 | ||||||||||||||||||||||||
| 925 | rowInfo.alignments[row] = alignment; | - | ||||||||||||||||||||||||
| 926 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 927 | - | |||||||||||||||||||||||||
| 928 | Qt::Alignment QGridLayoutEngine::rowAlignment(int row, Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 929 | { | - | ||||||||||||||||||||||||
| 930 | Q_ASSERT(row >= 0); | - | ||||||||||||||||||||||||
| 931 | return q_infos[orientation == Qt::Vertical].alignments.value(row); never executed: return q_infos[orientation == Qt::Vertical].alignments.value(row); | 0 | ||||||||||||||||||||||||
| 932 | } | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | Qt::Alignment QGridLayoutEngine::effectiveAlignment(const QGridLayoutItem *layoutItem) const | - | ||||||||||||||||||||||||
| 935 | { | - | ||||||||||||||||||||||||
| 936 | Qt::Alignment align = layoutItem->alignment(); | - | ||||||||||||||||||||||||
| 937 | if (!(align & Qt::AlignVertical_Mask)) {
| 0 | ||||||||||||||||||||||||
| 938 | // no vertical alignment, respect the row alignment | - | ||||||||||||||||||||||||
| 939 | int y = layoutItem->firstRow(); | - | ||||||||||||||||||||||||
| 940 | align |= (rowAlignment(y, Qt::Vertical) & Qt::AlignVertical_Mask); | - | ||||||||||||||||||||||||
| 941 | if (!(align & Qt::AlignVertical_Mask))
| 0 | ||||||||||||||||||||||||
| 942 | align |= (m_defaultAlignment & Qt::AlignVertical_Mask); never executed: align |= (m_defaultAlignment & Qt::AlignVertical_Mask); | 0 | ||||||||||||||||||||||||
| 943 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 944 | if (!(align & Qt::AlignHorizontal_Mask)) {
| 0 | ||||||||||||||||||||||||
| 945 | // no horizontal alignment, respect the column alignment | - | ||||||||||||||||||||||||
| 946 | int x = layoutItem->firstColumn(); | - | ||||||||||||||||||||||||
| 947 | align |= (rowAlignment(x, Qt::Horizontal) & Qt::AlignHorizontal_Mask); | - | ||||||||||||||||||||||||
| 948 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 949 | - | |||||||||||||||||||||||||
| 950 | return align; never executed: return align; | 0 | ||||||||||||||||||||||||
| 951 | } | - | ||||||||||||||||||||||||
| 952 | - | |||||||||||||||||||||||||
| 953 | /*! | - | ||||||||||||||||||||||||
| 954 | \internal | - | ||||||||||||||||||||||||
| 955 | The \a index is only used by QGraphicsLinearLayout to ensure that itemAt() reflects the order | - | ||||||||||||||||||||||||
| 956 | of visual arrangement. Strictly speaking it does not have to, but most people expect it to. | - | ||||||||||||||||||||||||
| 957 | (And if it didn't we would have to add itemArrangedAt(int index) or something..) | - | ||||||||||||||||||||||||
| 958 | */ | - | ||||||||||||||||||||||||
| 959 | void QGridLayoutEngine::insertItem(QGridLayoutItem *item, int index) | - | ||||||||||||||||||||||||
| 960 | { | - | ||||||||||||||||||||||||
| 961 | maybeExpandGrid(item->lastRow(), item->lastColumn()); | - | ||||||||||||||||||||||||
| 962 | - | |||||||||||||||||||||||||
| 963 | if (index == -1)
| 0 | ||||||||||||||||||||||||
| 964 | q_items.append(item); never executed: q_items.append(item); | 0 | ||||||||||||||||||||||||
| 965 | else | - | ||||||||||||||||||||||||
| 966 | q_items.insert(index, item); never executed: q_items.insert(index, item); | 0 | ||||||||||||||||||||||||
| 967 | - | |||||||||||||||||||||||||
| 968 | for (int i = item->firstRow(); i <= item->lastRow(); ++i) {
| 0 | ||||||||||||||||||||||||
| 969 | for (int j = item->firstColumn(); j <= item->lastColumn(); ++j) {
| 0 | ||||||||||||||||||||||||
| 970 | if (itemAt(i, j))
| 0 | ||||||||||||||||||||||||
| 971 | qWarning("QGridLayoutEngine::addItem: Cell (%d, %d) already taken", i, j); never executed: QMessageLogger(__FILE__, 971, __PRETTY_FUNCTION__).warning("QGridLayoutEngine::addItem: Cell (%d, %d) already taken", i, j); | 0 | ||||||||||||||||||||||||
| 972 | setItemAt(i, j, item); | - | ||||||||||||||||||||||||
| 973 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 974 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 975 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | void QGridLayoutEngine::addItem(QGridLayoutItem *item) | - | ||||||||||||||||||||||||
| 978 | { | - | ||||||||||||||||||||||||
| 979 | insertItem(item, -1); | - | ||||||||||||||||||||||||
| 980 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 981 | - | |||||||||||||||||||||||||
| 982 | void QGridLayoutEngine::removeItem(QGridLayoutItem *item) | - | ||||||||||||||||||||||||
| 983 | { | - | ||||||||||||||||||||||||
| 984 | Q_ASSERT(q_items.contains(item)); | - | ||||||||||||||||||||||||
| 985 | - | |||||||||||||||||||||||||
| 986 | invalidate(); | - | ||||||||||||||||||||||||
| 987 | - | |||||||||||||||||||||||||
| 988 | for (int i = item->firstRow(); i <= item->lastRow(); ++i) {
| 0 | ||||||||||||||||||||||||
| 989 | for (int j = item->firstColumn(); j <= item->lastColumn(); ++j) {
| 0 | ||||||||||||||||||||||||
| 990 | if (itemAt(i, j) == item)
| 0 | ||||||||||||||||||||||||
| 991 | setItemAt(i, j, 0); never executed: setItemAt(i, j, 0); | 0 | ||||||||||||||||||||||||
| 992 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 993 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 994 | - | |||||||||||||||||||||||||
| 995 | q_items.removeAll(item); | - | ||||||||||||||||||||||||
| 996 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 997 | - | |||||||||||||||||||||||||
| 998 | - | |||||||||||||||||||||||||
| 999 | QGridLayoutItem *QGridLayoutEngine::itemAt(int row, int column, Qt::Orientation orientation) const | - | ||||||||||||||||||||||||
| 1000 | { | - | ||||||||||||||||||||||||
| 1001 | if (orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
| 1002 | qSwap(row, column); never executed: qSwap(row, column); | 0 | ||||||||||||||||||||||||
| 1003 | if (uint(row) >= uint(rowCount()) || uint(column) >= uint(columnCount()))
| 0 | ||||||||||||||||||||||||
| 1004 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1005 | return q_grid.at((row * internalGridColumnCount()) + column); never executed: return q_grid.at((row * internalGridColumnCount()) + column); | 0 | ||||||||||||||||||||||||
| 1006 | } | - | ||||||||||||||||||||||||
| 1007 | - | |||||||||||||||||||||||||
| 1008 | void QGridLayoutEngine::invalidate() | - | ||||||||||||||||||||||||
| 1009 | { | - | ||||||||||||||||||||||||
| 1010 | q_cachedEffectiveFirstRows[Hor] = -1; | - | ||||||||||||||||||||||||
| 1011 | q_cachedEffectiveFirstRows[Ver] = -1; | - | ||||||||||||||||||||||||
| 1012 | q_cachedEffectiveLastRows[Hor] = -1; | - | ||||||||||||||||||||||||
| 1013 | q_cachedEffectiveLastRows[Ver] = -1; | - | ||||||||||||||||||||||||
| 1014 | - | |||||||||||||||||||||||||
| 1015 | q_totalBoxCachedConstraints[Hor] = NotCached; | - | ||||||||||||||||||||||||
| 1016 | q_totalBoxCachedConstraints[Ver] = NotCached; | - | ||||||||||||||||||||||||
| 1017 | - | |||||||||||||||||||||||||
| 1018 | q_cachedSize = QSizeF(); | - | ||||||||||||||||||||||||
| 1019 | q_cachedConstraintOrientation = UnknownConstraint; | - | ||||||||||||||||||||||||
| 1020 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1021 | - | |||||||||||||||||||||||||
| 1022 | static void visualRect(QRectF *geom, Qt::LayoutDirection dir, const QRectF &contentsRect) | - | ||||||||||||||||||||||||
| 1023 | { | - | ||||||||||||||||||||||||
| 1024 | if (dir == Qt::RightToLeft)
| 0 | ||||||||||||||||||||||||
| 1025 | geom->moveRight(contentsRect.right() - (geom->left() - contentsRect.left())); never executed: geom->moveRight(contentsRect.right() - (geom->left() - contentsRect.left())); | 0 | ||||||||||||||||||||||||
| 1026 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1027 | - | |||||||||||||||||||||||||
| 1028 | void QGridLayoutEngine::setGeometries(const QRectF &contentsGeometry, const QAbstractLayoutStyleInfo *styleInfo) | - | ||||||||||||||||||||||||
| 1029 | { | - | ||||||||||||||||||||||||
| 1030 | if (rowCount() < 1 || columnCount() < 1)
| 0 | ||||||||||||||||||||||||
| 1031 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1032 | - | |||||||||||||||||||||||||
| 1033 | ensureGeometries(contentsGeometry.size(), styleInfo); | - | ||||||||||||||||||||||||
| 1034 | - | |||||||||||||||||||||||||
| 1035 | for (int i = q_items.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
| 1036 | QGridLayoutItem *item = q_items.at(i); | - | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | qreal x = q_xx.at(item->firstColumn()); | - | ||||||||||||||||||||||||
| 1039 | qreal y = q_yy.at(item->firstRow()); | - | ||||||||||||||||||||||||
| 1040 | qreal width = q_widths.at(item->lastColumn()); | - | ||||||||||||||||||||||||
| 1041 | qreal height = q_heights.at(item->lastRow()); | - | ||||||||||||||||||||||||
| 1042 | - | |||||||||||||||||||||||||
| 1043 | if (item->columnSpan() != 1)
| 0 | ||||||||||||||||||||||||
| 1044 | width += q_xx.at(item->lastColumn()) - x; never executed: width += q_xx.at(item->lastColumn()) - x; | 0 | ||||||||||||||||||||||||
| 1045 | if (item->rowSpan() != 1)
| 0 | ||||||||||||||||||||||||
| 1046 | height += q_yy.at(item->lastRow()) - y; never executed: height += q_yy.at(item->lastRow()) - y; | 0 | ||||||||||||||||||||||||
| 1047 | - | |||||||||||||||||||||||||
| 1048 | const Qt::Alignment align = effectiveAlignment(item); | - | ||||||||||||||||||||||||
| 1049 | QRectF geom = item->geometryWithin(contentsGeometry.x() + x, contentsGeometry.y() + y, | - | ||||||||||||||||||||||||
| 1050 | width, height, q_descents.at(item->lastRow()), align, m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1051 | if (m_snapToPixelGrid) {
| 0 | ||||||||||||||||||||||||
| 1052 | // x and y should already be rounded, but the call to geometryWithin() above might | - | ||||||||||||||||||||||||
| 1053 | // result in a geom with x,y at half-pixels (due to centering within the cell) | - | ||||||||||||||||||||||||
| 1054 | geom.setX(qround(geom.x())); | - | ||||||||||||||||||||||||
| 1055 | // Do not snap baseline aligned items, since that might cause the baselines to not be aligned. | - | ||||||||||||||||||||||||
| 1056 | if (align != Qt::AlignBaseline)
| 0 | ||||||||||||||||||||||||
| 1057 | geom.setY(qround(geom.y())); never executed: geom.setY(qround(geom.y())); | 0 | ||||||||||||||||||||||||
| 1058 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1059 | visualRect(&geom, visualDirection(), contentsGeometry); | - | ||||||||||||||||||||||||
| 1060 | item->setGeometry(geom); | - | ||||||||||||||||||||||||
| 1061 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1062 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1063 | - | |||||||||||||||||||||||||
| 1064 | // ### candidate for deletion | - | ||||||||||||||||||||||||
| 1065 | QRectF QGridLayoutEngine::cellRect(const QRectF &contentsGeometry, int row, int column, int rowSpan, | - | ||||||||||||||||||||||||
| 1066 | int columnSpan, const QAbstractLayoutStyleInfo *styleInfo) const | - | ||||||||||||||||||||||||
| 1067 | { | - | ||||||||||||||||||||||||
| 1068 | if (uint(row) >= uint(rowCount()) || uint(column) >= uint(columnCount())
| 0 | ||||||||||||||||||||||||
| 1069 | || rowSpan < 1 || columnSpan < 1)
| 0 | ||||||||||||||||||||||||
| 1070 | return QRectF(); never executed: return QRectF(); | 0 | ||||||||||||||||||||||||
| 1071 | - | |||||||||||||||||||||||||
| 1072 | ensureGeometries(contentsGeometry.size(), styleInfo); | - | ||||||||||||||||||||||||
| 1073 | - | |||||||||||||||||||||||||
| 1074 | int lastColumn = qMax(column + columnSpan, columnCount()) - 1; | - | ||||||||||||||||||||||||
| 1075 | int lastRow = qMax(row + rowSpan, rowCount()) - 1; | - | ||||||||||||||||||||||||
| 1076 | - | |||||||||||||||||||||||||
| 1077 | qreal x = q_xx[column]; | - | ||||||||||||||||||||||||
| 1078 | qreal y = q_yy[row]; | - | ||||||||||||||||||||||||
| 1079 | qreal width = q_widths[lastColumn]; | - | ||||||||||||||||||||||||
| 1080 | qreal height = q_heights[lastRow]; | - | ||||||||||||||||||||||||
| 1081 | - | |||||||||||||||||||||||||
| 1082 | if (columnSpan != 1)
| 0 | ||||||||||||||||||||||||
| 1083 | width += q_xx[lastColumn] - x; never executed: width += q_xx[lastColumn] - x; | 0 | ||||||||||||||||||||||||
| 1084 | if (rowSpan != 1)
| 0 | ||||||||||||||||||||||||
| 1085 | height += q_yy[lastRow] - y; never executed: height += q_yy[lastRow] - y; | 0 | ||||||||||||||||||||||||
| 1086 | - | |||||||||||||||||||||||||
| 1087 | return QRectF(contentsGeometry.x() + x, contentsGeometry.y() + y, width, height); never executed: return QRectF(contentsGeometry.x() + x, contentsGeometry.y() + y, width, height); | 0 | ||||||||||||||||||||||||
| 1088 | } | - | ||||||||||||||||||||||||
| 1089 | - | |||||||||||||||||||||||||
| 1090 | QSizeF QGridLayoutEngine::sizeHint(Qt::SizeHint which, const QSizeF &constraint, | - | ||||||||||||||||||||||||
| 1091 | const QAbstractLayoutStyleInfo *styleInfo) const | - | ||||||||||||||||||||||||
| 1092 | { | - | ||||||||||||||||||||||||
| 1093 | - | |||||||||||||||||||||||||
| 1094 | - | |||||||||||||||||||||||||
| 1095 | if (hasDynamicConstraint() && rowCount() > 0 && columnCount() > 0) {
| 0 | ||||||||||||||||||||||||
| 1096 | QGridLayoutBox sizehint_totalBoxes[NOrientations]; | - | ||||||||||||||||||||||||
| 1097 | bool sizeHintCalculated = false; | - | ||||||||||||||||||||||||
| 1098 | if (constraintOrientation() == Qt::Vertical) {
| 0 | ||||||||||||||||||||||||
| 1099 | //We have items whose height depends on their width | - | ||||||||||||||||||||||||
| 1100 | if (constraint.width() >= 0) {
| 0 | ||||||||||||||||||||||||
| 1101 | ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], NULL, NULL, Qt::Horizontal, styleInfo); | - | ||||||||||||||||||||||||
| 1102 | QVector<qreal> sizehint_xx; | - | ||||||||||||||||||||||||
| 1103 | QVector<qreal> sizehint_widths; | - | ||||||||||||||||||||||||
| 1104 | - | |||||||||||||||||||||||||
| 1105 | sizehint_xx.resize(columnCount()); | - | ||||||||||||||||||||||||
| 1106 | sizehint_widths.resize(columnCount()); | - | ||||||||||||||||||||||||
| 1107 | qreal width = constraint.width(); | - | ||||||||||||||||||||||||
| 1108 | //Calculate column widths and positions, and put results in q_xx.data() and q_widths.data() so that we can use this information as | - | ||||||||||||||||||||||||
| 1109 | //constraints to find the row heights | - | ||||||||||||||||||||||||
| 1110 | q_columnData.calculateGeometries(0, columnCount(), width, sizehint_xx.data(), sizehint_widths.data(), | - | ||||||||||||||||||||||||
| 1111 | 0, sizehint_totalBoxes[Hor], q_infos[Hor], m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1112 | ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], sizehint_xx.data(), sizehint_widths.data(), Qt::Vertical, styleInfo); | - | ||||||||||||||||||||||||
| 1113 | sizeHintCalculated = true; | - | ||||||||||||||||||||||||
| 1114 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1115 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1116 | if (constraint.height() >= 0) {
| 0 | ||||||||||||||||||||||||
| 1117 | //We have items whose width depends on their height | - | ||||||||||||||||||||||||
| 1118 | ensureColumnAndRowData(&q_rowData, &sizehint_totalBoxes[Ver], NULL, NULL, Qt::Vertical, styleInfo); | - | ||||||||||||||||||||||||
| 1119 | QVector<qreal> sizehint_yy; | - | ||||||||||||||||||||||||
| 1120 | QVector<qreal> sizehint_heights; | - | ||||||||||||||||||||||||
| 1121 | - | |||||||||||||||||||||||||
| 1122 | sizehint_yy.resize(rowCount()); | - | ||||||||||||||||||||||||
| 1123 | sizehint_heights.resize(rowCount()); | - | ||||||||||||||||||||||||
| 1124 | qreal height = constraint.height(); | - | ||||||||||||||||||||||||
| 1125 | //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() so that we can use this information as | - | ||||||||||||||||||||||||
| 1126 | //constraints to find the column widths | - | ||||||||||||||||||||||||
| 1127 | q_rowData.calculateGeometries(0, rowCount(), height, sizehint_yy.data(), sizehint_heights.data(), | - | ||||||||||||||||||||||||
| 1128 | 0, sizehint_totalBoxes[Ver], q_infos[Ver], m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1129 | ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], sizehint_yy.data(), sizehint_heights.data(), Qt::Horizontal, styleInfo); | - | ||||||||||||||||||||||||
| 1130 | sizeHintCalculated = true; | - | ||||||||||||||||||||||||
| 1131 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1132 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1133 | if (sizeHintCalculated)
| 0 | ||||||||||||||||||||||||
| 1134 | return QSizeF(sizehint_totalBoxes[Hor].q_sizes(which), sizehint_totalBoxes[Ver].q_sizes(which)); never executed: return QSizeF(sizehint_totalBoxes[Hor].q_sizes(which), sizehint_totalBoxes[Ver].q_sizes(which)); | 0 | ||||||||||||||||||||||||
| 1135 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1136 | - | |||||||||||||||||||||||||
| 1137 | //No items with height for width, so it doesn't matter which order we do these in | - | ||||||||||||||||||||||||
| 1138 | ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], NULL, NULL, Qt::Horizontal, styleInfo); | - | ||||||||||||||||||||||||
| 1139 | ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], NULL, NULL, Qt::Vertical, styleInfo); | - | ||||||||||||||||||||||||
| 1140 | return QSizeF(q_totalBoxes[Hor].q_sizes(which), q_totalBoxes[Ver].q_sizes(which)); never executed: return QSizeF(q_totalBoxes[Hor].q_sizes(which), q_totalBoxes[Ver].q_sizes(which)); | 0 | ||||||||||||||||||||||||
| 1141 | } | - | ||||||||||||||||||||||||
| 1142 | - | |||||||||||||||||||||||||
| 1143 | QLayoutPolicy::ControlTypes QGridLayoutEngine::controlTypes(LayoutSide side) const | - | ||||||||||||||||||||||||
| 1144 | { | - | ||||||||||||||||||||||||
| 1145 | Qt::Orientation orientation = (side == Top || side == Bottom) ? Qt::Vertical : Qt::Horizontal;
| 0 | ||||||||||||||||||||||||
| 1146 | int row = (side == Top || side == Left) ? effectiveFirstRow(orientation)
| 0 | ||||||||||||||||||||||||
| 1147 | : effectiveLastRow(orientation); | - | ||||||||||||||||||||||||
| 1148 | QLayoutPolicy::ControlTypes result = 0; | - | ||||||||||||||||||||||||
| 1149 | - | |||||||||||||||||||||||||
| 1150 | for (int column = columnCount(orientation) - 1; column >= 0; --column) {
| 0 | ||||||||||||||||||||||||
| 1151 | if (QGridLayoutItem *item = itemAt(row, column, orientation))
| 0 | ||||||||||||||||||||||||
| 1152 | result |= item->controlTypes(side); never executed: result |= item->controlTypes(side); | 0 | ||||||||||||||||||||||||
| 1153 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1154 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 1155 | } | - | ||||||||||||||||||||||||
| 1156 | - | |||||||||||||||||||||||||
| 1157 | void QGridLayoutEngine::transpose() | - | ||||||||||||||||||||||||
| 1158 | { | - | ||||||||||||||||||||||||
| 1159 | invalidate(); | - | ||||||||||||||||||||||||
| 1160 | - | |||||||||||||||||||||||||
| 1161 | for (int i = q_items.count() - 1; i >= 0; --i)
| 0 | ||||||||||||||||||||||||
| 1162 | q_items.at(i)->transpose(); never executed: q_items.at(i)->transpose(); | 0 | ||||||||||||||||||||||||
| 1163 | - | |||||||||||||||||||||||||
| 1164 | qSwap(q_defaultSpacings[Hor], q_defaultSpacings[Ver]); | - | ||||||||||||||||||||||||
| 1165 | qSwap(q_infos[Hor], q_infos[Ver]); | - | ||||||||||||||||||||||||
| 1166 | - | |||||||||||||||||||||||||
| 1167 | regenerateGrid(); | - | ||||||||||||||||||||||||
| 1168 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1169 | - | |||||||||||||||||||||||||
| 1170 | void QGridLayoutEngine::setVisualDirection(Qt::LayoutDirection direction) | - | ||||||||||||||||||||||||
| 1171 | { | - | ||||||||||||||||||||||||
| 1172 | m_visualDirection = direction; | - | ||||||||||||||||||||||||
| 1173 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1174 | - | |||||||||||||||||||||||||
| 1175 | Qt::LayoutDirection QGridLayoutEngine::visualDirection() const | - | ||||||||||||||||||||||||
| 1176 | { | - | ||||||||||||||||||||||||
| 1177 | return m_visualDirection; never executed: return m_visualDirection; | 0 | ||||||||||||||||||||||||
| 1178 | } | - | ||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||
| 1180 | #ifdef QGRIDLAYOUTENGINE_DEBUG | - | ||||||||||||||||||||||||
| 1181 | void QGridLayoutEngine::dump(int indent) const | - | ||||||||||||||||||||||||
| 1182 | { | - | ||||||||||||||||||||||||
| 1183 | qDebug("%*sEngine", indent, ""); | - | ||||||||||||||||||||||||
| 1184 | - | |||||||||||||||||||||||||
| 1185 | qDebug("%*s Items (%d)", indent, "", q_items.count()); | - | ||||||||||||||||||||||||
| 1186 | int i; | - | ||||||||||||||||||||||||
| 1187 | for (i = 0; i < q_items.count(); ++i) | - | ||||||||||||||||||||||||
| 1188 | q_items.at(i)->dump(indent + 2); | - | ||||||||||||||||||||||||
| 1189 | - | |||||||||||||||||||||||||
| 1190 | qDebug("%*s Grid (%d x %d)", indent, "", internalGridRowCount(), | - | ||||||||||||||||||||||||
| 1191 | internalGridColumnCount()); | - | ||||||||||||||||||||||||
| 1192 | for (int row = 0; row < internalGridRowCount(); ++row) { | - | ||||||||||||||||||||||||
| 1193 | QString message = QLatin1String("[ "); | - | ||||||||||||||||||||||||
| 1194 | for (int column = 0; column < internalGridColumnCount(); ++column) { | - | ||||||||||||||||||||||||
| 1195 | message += QString::number(q_items.indexOf(itemAt(row, column))).rightJustified(3); | - | ||||||||||||||||||||||||
| 1196 | message += QLatin1Char(' '); | - | ||||||||||||||||||||||||
| 1197 | } | - | ||||||||||||||||||||||||
| 1198 | message += QLatin1Char(']'); | - | ||||||||||||||||||||||||
| 1199 | qDebug("%*s %s", indent, "", qPrintable(message)); | - | ||||||||||||||||||||||||
| 1200 | } | - | ||||||||||||||||||||||||
| 1201 | - | |||||||||||||||||||||||||
| 1202 | if (q_defaultSpacings[Hor].value() >= 0.0 || q_defaultSpacings[Ver].value() >= 0.0) | - | ||||||||||||||||||||||||
| 1203 | qDebug("%*s Default spacings: %g %g", indent, "", q_defaultSpacings[Hor].value(), | - | ||||||||||||||||||||||||
| 1204 | q_defaultSpacings[Ver].value()); | - | ||||||||||||||||||||||||
| 1205 | - | |||||||||||||||||||||||||
| 1206 | qDebug("%*s Column and row info", indent, ""); | - | ||||||||||||||||||||||||
| 1207 | q_infos[Hor].dump(indent + 2); | - | ||||||||||||||||||||||||
| 1208 | q_infos[Ver].dump(indent + 2); | - | ||||||||||||||||||||||||
| 1209 | - | |||||||||||||||||||||||||
| 1210 | qDebug("%*s Column and row data", indent, ""); | - | ||||||||||||||||||||||||
| 1211 | q_columnData.dump(indent + 2); | - | ||||||||||||||||||||||||
| 1212 | q_rowData.dump(indent + 2); | - | ||||||||||||||||||||||||
| 1213 | - | |||||||||||||||||||||||||
| 1214 | qDebug("%*s Geometries output", indent, ""); | - | ||||||||||||||||||||||||
| 1215 | QVector<qreal> *cellPos = &q_yy; | - | ||||||||||||||||||||||||
| 1216 | for (int pass = 0; pass < 2; ++pass) { | - | ||||||||||||||||||||||||
| 1217 | QString message; | - | ||||||||||||||||||||||||
| 1218 | for (i = 0; i < cellPos->count(); ++i) { | - | ||||||||||||||||||||||||
| 1219 | message += QLatin1String((message.isEmpty() ? "[" : ", ")); | - | ||||||||||||||||||||||||
| 1220 | message += QString::number(cellPos->at(i)); | - | ||||||||||||||||||||||||
| 1221 | } | - | ||||||||||||||||||||||||
| 1222 | message += QLatin1Char(']'); | - | ||||||||||||||||||||||||
| 1223 | qDebug("%*s %s %s", indent, "", (pass == 0 ? "rows:" : "columns:"), qPrintable(message)); | - | ||||||||||||||||||||||||
| 1224 | cellPos = &q_xx; | - | ||||||||||||||||||||||||
| 1225 | } | - | ||||||||||||||||||||||||
| 1226 | } | - | ||||||||||||||||||||||||
| 1227 | #endif | - | ||||||||||||||||||||||||
| 1228 | - | |||||||||||||||||||||||||
| 1229 | void QGridLayoutEngine::maybeExpandGrid(int row, int column, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 1230 | { | - | ||||||||||||||||||||||||
| 1231 | invalidate(); // ### move out of here? | - | ||||||||||||||||||||||||
| 1232 | - | |||||||||||||||||||||||||
| 1233 | if (orientation == Qt::Horizontal)
| 0 | ||||||||||||||||||||||||
| 1234 | qSwap(row, column); never executed: qSwap(row, column); | 0 | ||||||||||||||||||||||||
| 1235 | - | |||||||||||||||||||||||||
| 1236 | if (row < rowCount() && column < columnCount())
| 0 | ||||||||||||||||||||||||
| 1237 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1238 | - | |||||||||||||||||||||||||
| 1239 | int oldGridRowCount = internalGridRowCount(); | - | ||||||||||||||||||||||||
| 1240 | int oldGridColumnCount = internalGridColumnCount(); | - | ||||||||||||||||||||||||
| 1241 | - | |||||||||||||||||||||||||
| 1242 | q_infos[Ver].count = qMax(row + 1, rowCount()); | - | ||||||||||||||||||||||||
| 1243 | q_infos[Hor].count = qMax(column + 1, columnCount()); | - | ||||||||||||||||||||||||
| 1244 | - | |||||||||||||||||||||||||
| 1245 | int newGridRowCount = internalGridRowCount(); | - | ||||||||||||||||||||||||
| 1246 | int newGridColumnCount = internalGridColumnCount(); | - | ||||||||||||||||||||||||
| 1247 | - | |||||||||||||||||||||||||
| 1248 | int newGridSize = newGridRowCount * newGridColumnCount; | - | ||||||||||||||||||||||||
| 1249 | if (newGridSize != q_grid.count()) {
| 0 | ||||||||||||||||||||||||
| 1250 | q_grid.resize(newGridSize); | - | ||||||||||||||||||||||||
| 1251 | - | |||||||||||||||||||||||||
| 1252 | if (newGridColumnCount != oldGridColumnCount) {
| 0 | ||||||||||||||||||||||||
| 1253 | for (int i = oldGridRowCount - 1; i >= 1; --i) {
| 0 | ||||||||||||||||||||||||
| 1254 | for (int j = oldGridColumnCount - 1; j >= 0; --j) {
| 0 | ||||||||||||||||||||||||
| 1255 | int oldIndex = (i * oldGridColumnCount) + j; | - | ||||||||||||||||||||||||
| 1256 | int newIndex = (i * newGridColumnCount) + j; | - | ||||||||||||||||||||||||
| 1257 | - | |||||||||||||||||||||||||
| 1258 | Q_ASSERT(newIndex > oldIndex); | - | ||||||||||||||||||||||||
| 1259 | q_grid[newIndex] = q_grid[oldIndex]; | - | ||||||||||||||||||||||||
| 1260 | q_grid[oldIndex] = 0; | - | ||||||||||||||||||||||||
| 1261 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1262 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1263 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1264 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1265 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1266 | - | |||||||||||||||||||||||||
| 1267 | void QGridLayoutEngine::regenerateGrid() | - | ||||||||||||||||||||||||
| 1268 | { | - | ||||||||||||||||||||||||
| 1269 | q_grid.fill(0); | - | ||||||||||||||||||||||||
| 1270 | - | |||||||||||||||||||||||||
| 1271 | for (int i = q_items.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
| 1272 | QGridLayoutItem *item = q_items.at(i); | - | ||||||||||||||||||||||||
| 1273 | - | |||||||||||||||||||||||||
| 1274 | for (int j = item->firstRow(); j <= item->lastRow(); ++j) {
| 0 | ||||||||||||||||||||||||
| 1275 | for (int k = item->firstColumn(); k <= item->lastColumn(); ++k) {
| 0 | ||||||||||||||||||||||||
| 1276 | setItemAt(j, k, item); | - | ||||||||||||||||||||||||
| 1277 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1278 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1279 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1280 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1281 | - | |||||||||||||||||||||||||
| 1282 | void QGridLayoutEngine::setItemAt(int row, int column, QGridLayoutItem *item) | - | ||||||||||||||||||||||||
| 1283 | { | - | ||||||||||||||||||||||||
| 1284 | Q_ASSERT(row >= 0 && row < rowCount()); | - | ||||||||||||||||||||||||
| 1285 | Q_ASSERT(column >= 0 && column < columnCount()); | - | ||||||||||||||||||||||||
| 1286 | q_grid[(row * internalGridColumnCount()) + column] = item; | - | ||||||||||||||||||||||||
| 1287 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1288 | - | |||||||||||||||||||||||||
| 1289 | void QGridLayoutEngine::insertOrRemoveRows(int row, int delta, Qt::Orientation orientation) | - | ||||||||||||||||||||||||
| 1290 | { | - | ||||||||||||||||||||||||
| 1291 | int oldRowCount = rowCount(orientation); | - | ||||||||||||||||||||||||
| 1292 | Q_ASSERT(uint(row) <= uint(oldRowCount)); | - | ||||||||||||||||||||||||
| 1293 | - | |||||||||||||||||||||||||
| 1294 | invalidate(); | - | ||||||||||||||||||||||||
| 1295 | - | |||||||||||||||||||||||||
| 1296 | // appending rows (or columns) is easy | - | ||||||||||||||||||||||||
| 1297 | if (row == oldRowCount && delta > 0) {
| 0 | ||||||||||||||||||||||||
| 1298 | maybeExpandGrid(oldRowCount + delta - 1, -1, orientation); | - | ||||||||||||||||||||||||
| 1299 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1300 | } | - | ||||||||||||||||||||||||
| 1301 | - | |||||||||||||||||||||||||
| 1302 | q_infos[orientation == Qt::Vertical].insertOrRemoveRows(row, delta); | - | ||||||||||||||||||||||||
| 1303 | - | |||||||||||||||||||||||||
| 1304 | for (int i = q_items.count() - 1; i >= 0; --i)
| 0 | ||||||||||||||||||||||||
| 1305 | q_items.at(i)->insertOrRemoveRows(row, delta, orientation); never executed: q_items.at(i)->insertOrRemoveRows(row, delta, orientation); | 0 | ||||||||||||||||||||||||
| 1306 | - | |||||||||||||||||||||||||
| 1307 | q_grid.resize(internalGridRowCount() * internalGridColumnCount()); | - | ||||||||||||||||||||||||
| 1308 | regenerateGrid(); | - | ||||||||||||||||||||||||
| 1309 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1310 | - | |||||||||||||||||||||||||
| 1311 | void QGridLayoutEngine::fillRowData(QGridLayoutRowData *rowData, | - | ||||||||||||||||||||||||
| 1312 | const qreal *colPositions, const qreal *colSizes, | - | ||||||||||||||||||||||||
| 1313 | Qt::Orientation orientation, | - | ||||||||||||||||||||||||
| 1314 | const QAbstractLayoutStyleInfo *styleInfo) const | - | ||||||||||||||||||||||||
| 1315 | { | - | ||||||||||||||||||||||||
| 1316 | const int ButtonMask = QLayoutPolicy::ButtonBox | QLayoutPolicy::PushButton; | - | ||||||||||||||||||||||||
| 1317 | const QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 1318 | const QGridLayoutRowInfo &columnInfo = q_infos[orientation == Qt::Horizontal]; | - | ||||||||||||||||||||||||
| 1319 | LayoutSide top = (orientation == Qt::Vertical) ? Top : Left;
| 0 | ||||||||||||||||||||||||
| 1320 | LayoutSide bottom = (orientation == Qt::Vertical) ? Bottom : Right;
| 0 | ||||||||||||||||||||||||
| 1321 | - | |||||||||||||||||||||||||
| 1322 | const QLayoutParameter<qreal> &defaultSpacing = q_defaultSpacings[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 1323 | qreal innerSpacing = styleInfo->spacing(orientation); | - | ||||||||||||||||||||||||
| 1324 | if (innerSpacing >= 0.0)
| 0 | ||||||||||||||||||||||||
| 1325 | defaultSpacing.setCachedValue(innerSpacing); never executed: defaultSpacing.setCachedValue(innerSpacing); | 0 | ||||||||||||||||||||||||
| 1326 | - | |||||||||||||||||||||||||
| 1327 | for (int row = 0; row < rowInfo.count; ++row) {
| 0 | ||||||||||||||||||||||||
| 1328 | bool rowIsEmpty = true; | - | ||||||||||||||||||||||||
| 1329 | bool rowIsIdenticalToPrevious = (row > 0); | - | ||||||||||||||||||||||||
| 1330 | - | |||||||||||||||||||||||||
| 1331 | for (int column = 0; column < columnInfo.count; ++column) {
| 0 | ||||||||||||||||||||||||
| 1332 | QGridLayoutItem *item = itemAt(row, column, orientation); | - | ||||||||||||||||||||||||
| 1333 | - | |||||||||||||||||||||||||
| 1334 | if (rowIsIdenticalToPrevious && item != itemAt(row - 1, column, orientation))
| 0 | ||||||||||||||||||||||||
| 1335 | rowIsIdenticalToPrevious = false; never executed: rowIsIdenticalToPrevious = false; | 0 | ||||||||||||||||||||||||
| 1336 | - | |||||||||||||||||||||||||
| 1337 | if (item && !item->isIgnored())
| 0 | ||||||||||||||||||||||||
| 1338 | rowIsEmpty = false; never executed: rowIsEmpty = false; | 0 | ||||||||||||||||||||||||
| 1339 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1340 | - | |||||||||||||||||||||||||
| 1341 | if ((rowIsEmpty || rowIsIdenticalToPrevious)
| 0 | ||||||||||||||||||||||||
| 1342 | && rowInfo.spacings.value(row).isDefault()
| 0 | ||||||||||||||||||||||||
| 1343 | && rowInfo.stretches.value(row).isDefault()
| 0 | ||||||||||||||||||||||||
| 1344 | && rowInfo.boxes.value(row) == QGridLayoutBox())
| 0 | ||||||||||||||||||||||||
| 1345 | rowData->ignore.setBit(row, true); never executed: rowData->ignore.setBit(row, true); | 0 | ||||||||||||||||||||||||
| 1346 | - | |||||||||||||||||||||||||
| 1347 | if (rowInfo.spacings.value(row).isUser()) {
| 0 | ||||||||||||||||||||||||
| 1348 | rowData->spacings[row] = rowInfo.spacings.at(row).value(); | - | ||||||||||||||||||||||||
| 1349 | } else if (!defaultSpacing.isDefault()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1350 | rowData->spacings[row] = defaultSpacing.value(); | - | ||||||||||||||||||||||||
| 1351 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1352 | - | |||||||||||||||||||||||||
| 1353 | rowData->stretches[row] = rowInfo.stretches.value(row).value(); | - | ||||||||||||||||||||||||
| 1354 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1355 | - | |||||||||||||||||||||||||
| 1356 | struct RowAdHocData { | - | ||||||||||||||||||||||||
| 1357 | int q_row; | - | ||||||||||||||||||||||||
| 1358 | unsigned int q_hasButtons : 8; | - | ||||||||||||||||||||||||
| 1359 | unsigned int q_hasNonButtons : 8; | - | ||||||||||||||||||||||||
| 1360 | - | |||||||||||||||||||||||||
| 1361 | inline RowAdHocData() : q_row(-1), q_hasButtons(false), q_hasNonButtons(false) {} never executed: end of block | 0 | ||||||||||||||||||||||||
| 1362 | inline void init(int row) { | - | ||||||||||||||||||||||||
| 1363 | this->q_row = row; | - | ||||||||||||||||||||||||
| 1364 | q_hasButtons = false; | - | ||||||||||||||||||||||||
| 1365 | q_hasNonButtons = false; | - | ||||||||||||||||||||||||
| 1366 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1367 | inline bool hasOnlyButtons() const { return q_hasButtons && !q_hasNonButtons; } never executed: return q_hasButtons && !q_hasNonButtons; | 0 | ||||||||||||||||||||||||
| 1368 | inline bool hasOnlyNonButtons() const { return q_hasNonButtons && !q_hasButtons; } never executed: return q_hasNonButtons && !q_hasButtons; | 0 | ||||||||||||||||||||||||
| 1369 | }; | - | ||||||||||||||||||||||||
| 1370 | RowAdHocData lastRowAdHocData; | - | ||||||||||||||||||||||||
| 1371 | RowAdHocData nextToLastRowAdHocData; | - | ||||||||||||||||||||||||
| 1372 | RowAdHocData nextToNextToLastRowAdHocData; | - | ||||||||||||||||||||||||
| 1373 | - | |||||||||||||||||||||||||
| 1374 | rowData->hasIgnoreFlag = false; | - | ||||||||||||||||||||||||
| 1375 | for (int row = 0; row < rowInfo.count; ++row) {
| 0 | ||||||||||||||||||||||||
| 1376 | if (rowData->ignore.testBit(row))
| 0 | ||||||||||||||||||||||||
| 1377 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1378 | - | |||||||||||||||||||||||||
| 1379 | QGridLayoutBox &rowBox = rowData->boxes[row]; | - | ||||||||||||||||||||||||
| 1380 | if (styleInfo->isWindow()) {
| 0 | ||||||||||||||||||||||||
| 1381 | nextToNextToLastRowAdHocData = nextToLastRowAdHocData; | - | ||||||||||||||||||||||||
| 1382 | nextToLastRowAdHocData = lastRowAdHocData; | - | ||||||||||||||||||||||||
| 1383 | lastRowAdHocData.init(row); | - | ||||||||||||||||||||||||
| 1384 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1385 | - | |||||||||||||||||||||||||
| 1386 | bool userRowStretch = rowInfo.stretches.value(row).isUser(); | - | ||||||||||||||||||||||||
| 1387 | int &rowStretch = rowData->stretches[row]; | - | ||||||||||||||||||||||||
| 1388 | - | |||||||||||||||||||||||||
| 1389 | bool hasIgnoreFlag = true; | - | ||||||||||||||||||||||||
| 1390 | for (int column = 0; column < columnInfo.count; ++column) {
| 0 | ||||||||||||||||||||||||
| 1391 | QGridLayoutItem *item = itemAt(row, column, orientation); | - | ||||||||||||||||||||||||
| 1392 | if (item) {
| 0 | ||||||||||||||||||||||||
| 1393 | int itemRow = item->firstRow(orientation); | - | ||||||||||||||||||||||||
| 1394 | int itemColumn = item->firstColumn(orientation); | - | ||||||||||||||||||||||||
| 1395 | - | |||||||||||||||||||||||||
| 1396 | if (itemRow == row && itemColumn == column) {
| 0 | ||||||||||||||||||||||||
| 1397 | int itemStretch = item->stretchFactor(orientation); | - | ||||||||||||||||||||||||
| 1398 | if (!(item->sizePolicy(orientation) & QLayoutPolicy::IgnoreFlag))
| 0 | ||||||||||||||||||||||||
| 1399 | hasIgnoreFlag = false; never executed: hasIgnoreFlag = false; | 0 | ||||||||||||||||||||||||
| 1400 | int itemRowSpan = item->rowSpan(orientation); | - | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | int effectiveRowSpan = 1; | - | ||||||||||||||||||||||||
| 1403 | for (int i = 1; i < itemRowSpan; ++i) {
| 0 | ||||||||||||||||||||||||
| 1404 | if (!rowData->ignore.testBit(i + itemRow))
| 0 | ||||||||||||||||||||||||
| 1405 | ++effectiveRowSpan; never executed: ++effectiveRowSpan; | 0 | ||||||||||||||||||||||||
| 1406 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1407 | - | |||||||||||||||||||||||||
| 1408 | QGridLayoutBox *box; | - | ||||||||||||||||||||||||
| 1409 | if (effectiveRowSpan == 1) {
| 0 | ||||||||||||||||||||||||
| 1410 | box = &rowBox; | - | ||||||||||||||||||||||||
| 1411 | if (!userRowStretch && itemStretch != 0)
| 0 | ||||||||||||||||||||||||
| 1412 | rowStretch = qMax(rowStretch, itemStretch); never executed: rowStretch = qMax(rowStretch, itemStretch); | 0 | ||||||||||||||||||||||||
| 1413 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1414 | QGridLayoutMultiCellData &multiCell = | - | ||||||||||||||||||||||||
| 1415 | rowData->multiCellMap[qMakePair(row, itemRowSpan)]; | - | ||||||||||||||||||||||||
| 1416 | box = &multiCell.q_box; | - | ||||||||||||||||||||||||
| 1417 | multiCell.q_stretch = itemStretch; | - | ||||||||||||||||||||||||
| 1418 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1419 | // Items with constraints need to be passed the constraint | - | ||||||||||||||||||||||||
| 1420 | if (colSizes && colPositions && item->hasDynamicConstraint() && orientation == item->dynamicConstraintOrientation()) {
| 0 | ||||||||||||||||||||||||
| 1421 | /* Get the width of the item by summing up the widths of the columns that it spans. | - | ||||||||||||||||||||||||
| 1422 | * We need to have already calculated the widths of the columns by calling | - | ||||||||||||||||||||||||
| 1423 | * q_columns->calculateGeometries() before hand and passing the value in the colSizes | - | ||||||||||||||||||||||||
| 1424 | * and colPositions parameters. | - | ||||||||||||||||||||||||
| 1425 | * The variable name is still colSizes even when it actually has the row sizes | - | ||||||||||||||||||||||||
| 1426 | */ | - | ||||||||||||||||||||||||
| 1427 | qreal length = colSizes[item->lastColumn(orientation)]; | - | ||||||||||||||||||||||||
| 1428 | if (item->columnSpan(orientation) != 1)
| 0 | ||||||||||||||||||||||||
| 1429 | length += colPositions[item->lastColumn(orientation)] - colPositions[item->firstColumn(orientation)]; never executed: length += colPositions[item->lastColumn(orientation)] - colPositions[item->firstColumn(orientation)]; | 0 | ||||||||||||||||||||||||
| 1430 | box->combine(item->box(orientation, m_snapToPixelGrid, length)); | - | ||||||||||||||||||||||||
| 1431 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1432 | box->combine(item->box(orientation, m_snapToPixelGrid)); | - | ||||||||||||||||||||||||
| 1433 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1434 | - | |||||||||||||||||||||||||
| 1435 | if (effectiveRowSpan == 1) {
| 0 | ||||||||||||||||||||||||
| 1436 | QLayoutPolicy::ControlTypes controls = item->controlTypes(top); | - | ||||||||||||||||||||||||
| 1437 | if (controls & ButtonMask)
| 0 | ||||||||||||||||||||||||
| 1438 | lastRowAdHocData.q_hasButtons = true; never executed: lastRowAdHocData.q_hasButtons = true; | 0 | ||||||||||||||||||||||||
| 1439 | if (controls & ~ButtonMask)
| 0 | ||||||||||||||||||||||||
| 1440 | lastRowAdHocData.q_hasNonButtons = true; never executed: lastRowAdHocData.q_hasNonButtons = true; | 0 | ||||||||||||||||||||||||
| 1441 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1442 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1443 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1444 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1445 | if (row < rowInfo.boxes.count()) {
| 0 | ||||||||||||||||||||||||
| 1446 | QGridLayoutBox rowBoxInfo = rowInfo.boxes.at(row); | - | ||||||||||||||||||||||||
| 1447 | rowBoxInfo.normalize(); | - | ||||||||||||||||||||||||
| 1448 | rowBox.q_minimumSize = qMax(rowBox.q_minimumSize, rowBoxInfo.q_minimumSize); | - | ||||||||||||||||||||||||
| 1449 | rowBox.q_maximumSize = qMax(rowBox.q_minimumSize, | - | ||||||||||||||||||||||||
| 1450 | (rowBoxInfo.q_maximumSize != FLT_MAX ? | - | ||||||||||||||||||||||||
| 1451 | rowBoxInfo.q_maximumSize : rowBox.q_maximumSize)); | - | ||||||||||||||||||||||||
| 1452 | rowBox.q_preferredSize = qBound(rowBox.q_minimumSize, | - | ||||||||||||||||||||||||
| 1453 | qMax(rowBox.q_preferredSize, rowBoxInfo.q_preferredSize), | - | ||||||||||||||||||||||||
| 1454 | rowBox.q_maximumSize); | - | ||||||||||||||||||||||||
| 1455 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1456 | if (hasIgnoreFlag)
| 0 | ||||||||||||||||||||||||
| 1457 | rowData->hasIgnoreFlag = true; never executed: rowData->hasIgnoreFlag = true; | 0 | ||||||||||||||||||||||||
| 1458 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1459 | - | |||||||||||||||||||||||||
| 1460 | /* | - | ||||||||||||||||||||||||
| 1461 | Heuristic: Detect button boxes that don't use QLayoutPolicy::ButtonBox. | - | ||||||||||||||||||||||||
| 1462 | This is somewhat ad hoc but it usually does the trick. | - | ||||||||||||||||||||||||
| 1463 | */ | - | ||||||||||||||||||||||||
| 1464 | bool lastRowIsButtonBox = (lastRowAdHocData.hasOnlyButtons()
| 0 | ||||||||||||||||||||||||
| 1465 | && nextToLastRowAdHocData.hasOnlyNonButtons());
| 0 | ||||||||||||||||||||||||
| 1466 | bool lastTwoRowsIsButtonBox = (lastRowAdHocData.hasOnlyButtons()
| 0 | ||||||||||||||||||||||||
| 1467 | && nextToLastRowAdHocData.hasOnlyButtons()
| 0 | ||||||||||||||||||||||||
| 1468 | && nextToNextToLastRowAdHocData.hasOnlyNonButtons()
| 0 | ||||||||||||||||||||||||
| 1469 | && orientation == Qt::Vertical);
| 0 | ||||||||||||||||||||||||
| 1470 | - | |||||||||||||||||||||||||
| 1471 | if (defaultSpacing.isDefault()) {
| 0 | ||||||||||||||||||||||||
| 1472 | int prevRow = -1; | - | ||||||||||||||||||||||||
| 1473 | for (int row = 0; row < rowInfo.count; ++row) {
| 0 | ||||||||||||||||||||||||
| 1474 | if (rowData->ignore.testBit(row))
| 0 | ||||||||||||||||||||||||
| 1475 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1476 | - | |||||||||||||||||||||||||
| 1477 | if (prevRow != -1 && !rowInfo.spacings.value(prevRow).isUser()) {
| 0 | ||||||||||||||||||||||||
| 1478 | qreal &rowSpacing = rowData->spacings[prevRow]; | - | ||||||||||||||||||||||||
| 1479 | for (int column = 0; column < columnInfo.count; ++column) {
| 0 | ||||||||||||||||||||||||
| 1480 | QGridLayoutItem *item1 = itemAt(prevRow, column, orientation); | - | ||||||||||||||||||||||||
| 1481 | QGridLayoutItem *item2 = itemAt(row, column, orientation); | - | ||||||||||||||||||||||||
| 1482 | - | |||||||||||||||||||||||||
| 1483 | if (item1 && item2 && item1 != item2) {
| 0 | ||||||||||||||||||||||||
| 1484 | QLayoutPolicy::ControlTypes controls1 = item1->controlTypes(bottom); | - | ||||||||||||||||||||||||
| 1485 | QLayoutPolicy::ControlTypes controls2 = item2->controlTypes(top); | - | ||||||||||||||||||||||||
| 1486 | - | |||||||||||||||||||||||||
| 1487 | if (controls2 & QLayoutPolicy::PushButton) {
| 0 | ||||||||||||||||||||||||
| 1488 | if ((row == nextToLastRowAdHocData.q_row && lastTwoRowsIsButtonBox)
| 0 | ||||||||||||||||||||||||
| 1489 | || (row == lastRowAdHocData.q_row && lastRowIsButtonBox)) {
| 0 | ||||||||||||||||||||||||
| 1490 | controls2 &= ~QLayoutPolicy::PushButton; | - | ||||||||||||||||||||||||
| 1491 | controls2 |= QLayoutPolicy::ButtonBox; | - | ||||||||||||||||||||||||
| 1492 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1493 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1494 | - | |||||||||||||||||||||||||
| 1495 | qreal spacing = styleInfo->combinedLayoutSpacing(controls1, controls2, | - | ||||||||||||||||||||||||
| 1496 | orientation); | - | ||||||||||||||||||||||||
| 1497 | if (orientation == Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
| 1498 | qreal width1 = rowData->boxes.at(prevRow).q_minimumSize; | - | ||||||||||||||||||||||||
| 1499 | qreal width2 = rowData->boxes.at(row).q_minimumSize; | - | ||||||||||||||||||||||||
| 1500 | QRectF rect1 = item1->geometryWithin(0.0, 0.0, width1, FLT_MAX, -1.0, effectiveAlignment(item1), m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1501 | QRectF rect2 = item2->geometryWithin(0.0, 0.0, width2, FLT_MAX, -1.0, effectiveAlignment(item2), m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1502 | spacing -= (width1 - (rect1.x() + rect1.width())) + rect2.x(); | - | ||||||||||||||||||||||||
| 1503 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1504 | const QGridLayoutBox &box1 = rowData->boxes.at(prevRow); | - | ||||||||||||||||||||||||
| 1505 | const QGridLayoutBox &box2 = rowData->boxes.at(row); | - | ||||||||||||||||||||||||
| 1506 | qreal height1 = box1.q_minimumSize; | - | ||||||||||||||||||||||||
| 1507 | qreal height2 = box2.q_minimumSize; | - | ||||||||||||||||||||||||
| 1508 | qreal rowDescent1 = fixedDescent(box1.q_minimumDescent, | - | ||||||||||||||||||||||||
| 1509 | box1.q_minimumAscent, height1); | - | ||||||||||||||||||||||||
| 1510 | qreal rowDescent2 = fixedDescent(box2.q_minimumDescent, | - | ||||||||||||||||||||||||
| 1511 | box2.q_minimumAscent, height2); | - | ||||||||||||||||||||||||
| 1512 | QRectF rect1 = item1->geometryWithin(0.0, 0.0, FLT_MAX, height1, | - | ||||||||||||||||||||||||
| 1513 | rowDescent1, effectiveAlignment(item1), m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1514 | QRectF rect2 = item2->geometryWithin(0.0, 0.0, FLT_MAX, height2, | - | ||||||||||||||||||||||||
| 1515 | rowDescent2, effectiveAlignment(item2), m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1516 | spacing -= (height1 - (rect1.y() + rect1.height())) + rect2.y(); | - | ||||||||||||||||||||||||
| 1517 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1518 | rowSpacing = qMax(spacing, rowSpacing); | - | ||||||||||||||||||||||||
| 1519 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1520 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1521 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1522 | prevRow = row; | - | ||||||||||||||||||||||||
| 1523 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1524 | } else if (lastRowIsButtonBox || lastTwoRowsIsButtonBox) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1525 | /* | - | ||||||||||||||||||||||||
| 1526 | Even for styles that define a uniform spacing, we cheat a | - | ||||||||||||||||||||||||
| 1527 | bit and use the window margin as the spacing. This | - | ||||||||||||||||||||||||
| 1528 | significantly improves the look of dialogs. | - | ||||||||||||||||||||||||
| 1529 | */ | - | ||||||||||||||||||||||||
| 1530 | int prevRow = lastRowIsButtonBox ? nextToLastRowAdHocData.q_row
| 0 | ||||||||||||||||||||||||
| 1531 | : nextToNextToLastRowAdHocData.q_row; | - | ||||||||||||||||||||||||
| 1532 | if (!defaultSpacing.isUser() && !rowInfo.spacings.value(prevRow).isUser()) {
| 0 | ||||||||||||||||||||||||
| 1533 | qreal windowMargin = styleInfo->windowMargin(orientation); | - | ||||||||||||||||||||||||
| 1534 | qreal &rowSpacing = rowData->spacings[prevRow]; | - | ||||||||||||||||||||||||
| 1535 | rowSpacing = qMax(windowMargin, rowSpacing); | - | ||||||||||||||||||||||||
| 1536 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1537 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1538 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1539 | - | |||||||||||||||||||||||||
| 1540 | void QGridLayoutEngine::ensureEffectiveFirstAndLastRows() const | - | ||||||||||||||||||||||||
| 1541 | { | - | ||||||||||||||||||||||||
| 1542 | if (q_cachedEffectiveFirstRows[Hor] == -1 && !q_items.isEmpty()) {
| 0 | ||||||||||||||||||||||||
| 1543 | int rowCount = this->rowCount(); | - | ||||||||||||||||||||||||
| 1544 | int columnCount = this->columnCount(); | - | ||||||||||||||||||||||||
| 1545 | - | |||||||||||||||||||||||||
| 1546 | q_cachedEffectiveFirstRows[Ver] = rowCount; | - | ||||||||||||||||||||||||
| 1547 | q_cachedEffectiveFirstRows[Hor] = columnCount; | - | ||||||||||||||||||||||||
| 1548 | q_cachedEffectiveLastRows[Ver] = -1; | - | ||||||||||||||||||||||||
| 1549 | q_cachedEffectiveLastRows[Hor] = -1; | - | ||||||||||||||||||||||||
| 1550 | - | |||||||||||||||||||||||||
| 1551 | for (int i = q_items.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
| 1552 | const QGridLayoutItem *item = q_items.at(i); | - | ||||||||||||||||||||||||
| 1553 | - | |||||||||||||||||||||||||
| 1554 | for (int j = 0; j < NOrientations; ++j) {
| 0 | ||||||||||||||||||||||||
| 1555 | Qt::Orientation orientation = (j == Hor) ? Qt::Horizontal : Qt::Vertical;
| 0 | ||||||||||||||||||||||||
| 1556 | if (item->firstRow(orientation) < q_cachedEffectiveFirstRows[j])
| 0 | ||||||||||||||||||||||||
| 1557 | q_cachedEffectiveFirstRows[j] = item->firstRow(orientation); never executed: q_cachedEffectiveFirstRows[j] = item->firstRow(orientation); | 0 | ||||||||||||||||||||||||
| 1558 | if (item->lastRow(orientation) > q_cachedEffectiveLastRows[j])
| 0 | ||||||||||||||||||||||||
| 1559 | q_cachedEffectiveLastRows[j] = item->lastRow(orientation); never executed: q_cachedEffectiveLastRows[j] = item->lastRow(orientation); | 0 | ||||||||||||||||||||||||
| 1560 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1561 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1562 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1563 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1564 | - | |||||||||||||||||||||||||
| 1565 | void QGridLayoutEngine::ensureColumnAndRowData(QGridLayoutRowData *rowData, QGridLayoutBox *totalBox, | - | ||||||||||||||||||||||||
| 1566 | const qreal *colPositions, const qreal *colSizes, | - | ||||||||||||||||||||||||
| 1567 | Qt::Orientation orientation, | - | ||||||||||||||||||||||||
| 1568 | const QAbstractLayoutStyleInfo *styleInfo) const | - | ||||||||||||||||||||||||
| 1569 | { | - | ||||||||||||||||||||||||
| 1570 | const int o = (orientation == Qt::Vertical ? Ver : Hor);
| 0 | ||||||||||||||||||||||||
| 1571 | const int cc = columnCount(orientation); | - | ||||||||||||||||||||||||
| 1572 | - | |||||||||||||||||||||||||
| 1573 | const qreal constraint = (colPositions && colSizes && hasDynamicConstraint()) ? (colPositions[cc - 1] + colSizes[cc - 1]) : qreal(CachedWithNoConstraint);
| 0 | ||||||||||||||||||||||||
| 1574 | qreal &cachedConstraint = q_totalBoxCachedConstraints[o]; | - | ||||||||||||||||||||||||
| 1575 | if (cachedConstraint == constraint) {
| 0 | ||||||||||||||||||||||||
| 1576 | if (totalBox != &q_totalBoxes[o])
| 0 | ||||||||||||||||||||||||
| 1577 | *totalBox = q_totalBoxes[o]; never executed: *totalBox = q_totalBoxes[o]; | 0 | ||||||||||||||||||||||||
| 1578 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1579 | } | - | ||||||||||||||||||||||||
| 1580 | rowData->reset(rowCount(orientation)); | - | ||||||||||||||||||||||||
| 1581 | fillRowData(rowData, colPositions, colSizes, orientation, styleInfo); | - | ||||||||||||||||||||||||
| 1582 | const QGridLayoutRowInfo &rowInfo = q_infos[orientation == Qt::Vertical]; | - | ||||||||||||||||||||||||
| 1583 | rowData->distributeMultiCells(rowInfo, m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1584 | *totalBox = rowData->totalBox(0, rowCount(orientation)); | - | ||||||||||||||||||||||||
| 1585 | - | |||||||||||||||||||||||||
| 1586 | if (totalBox != &q_totalBoxes[o])
| 0 | ||||||||||||||||||||||||
| 1587 | q_totalBoxes[o] = *totalBox; never executed: q_totalBoxes[o] = *totalBox; | 0 | ||||||||||||||||||||||||
| 1588 | - | |||||||||||||||||||||||||
| 1589 | cachedConstraint = constraint; | - | ||||||||||||||||||||||||
| 1590 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1591 | - | |||||||||||||||||||||||||
| 1592 | /** | - | ||||||||||||||||||||||||
| 1593 | returns false if the layout has contradicting constraints (i.e. some items with a horizontal | - | ||||||||||||||||||||||||
| 1594 | constraint and other items with a vertical constraint) | - | ||||||||||||||||||||||||
| 1595 | */ | - | ||||||||||||||||||||||||
| 1596 | bool QGridLayoutEngine::ensureDynamicConstraint() const | - | ||||||||||||||||||||||||
| 1597 | { | - | ||||||||||||||||||||||||
| 1598 | if (q_cachedConstraintOrientation == UnknownConstraint) {
| 0 | ||||||||||||||||||||||||
| 1599 | for (int i = q_items.count() - 1; i >= 0; --i) {
| 0 | ||||||||||||||||||||||||
| 1600 | QGridLayoutItem *item = q_items.at(i); | - | ||||||||||||||||||||||||
| 1601 | if (item->hasDynamicConstraint()) {
| 0 | ||||||||||||||||||||||||
| 1602 | Qt::Orientation itemConstraintOrientation = item->dynamicConstraintOrientation(); | - | ||||||||||||||||||||||||
| 1603 | if (q_cachedConstraintOrientation == UnknownConstraint) {
| 0 | ||||||||||||||||||||||||
| 1604 | q_cachedConstraintOrientation = itemConstraintOrientation; | - | ||||||||||||||||||||||||
| 1605 | } else if (q_cachedConstraintOrientation != itemConstraintOrientation) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1606 | q_cachedConstraintOrientation = UnfeasibleConstraint; | - | ||||||||||||||||||||||||
| 1607 | qWarning("QGridLayoutEngine: Unfeasible, cannot mix horizontal and" | - | ||||||||||||||||||||||||
| 1608 | " vertical constraint in the same layout"); | - | ||||||||||||||||||||||||
| 1609 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1610 | } | - | ||||||||||||||||||||||||
| 1611 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1612 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1613 | if (q_cachedConstraintOrientation == UnknownConstraint)
| 0 | ||||||||||||||||||||||||
| 1614 | q_cachedConstraintOrientation = NoConstraint; never executed: q_cachedConstraintOrientation = NoConstraint; | 0 | ||||||||||||||||||||||||
| 1615 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1616 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1617 | } | - | ||||||||||||||||||||||||
| 1618 | - | |||||||||||||||||||||||||
| 1619 | bool QGridLayoutEngine::hasDynamicConstraint() const | - | ||||||||||||||||||||||||
| 1620 | { | - | ||||||||||||||||||||||||
| 1621 | if (!ensureDynamicConstraint())
| 0 | ||||||||||||||||||||||||
| 1622 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1623 | return q_cachedConstraintOrientation != NoConstraint; never executed: return q_cachedConstraintOrientation != NoConstraint; | 0 | ||||||||||||||||||||||||
| 1624 | } | - | ||||||||||||||||||||||||
| 1625 | - | |||||||||||||||||||||||||
| 1626 | /* | - | ||||||||||||||||||||||||
| 1627 | * return value is only valid if hasConstraint() returns \c true | - | ||||||||||||||||||||||||
| 1628 | */ | - | ||||||||||||||||||||||||
| 1629 | Qt::Orientation QGridLayoutEngine::constraintOrientation() const | - | ||||||||||||||||||||||||
| 1630 | { | - | ||||||||||||||||||||||||
| 1631 | (void)ensureDynamicConstraint(); | - | ||||||||||||||||||||||||
| 1632 | return (Qt::Orientation)q_cachedConstraintOrientation; never executed: return (Qt::Orientation)q_cachedConstraintOrientation; | 0 | ||||||||||||||||||||||||
| 1633 | } | - | ||||||||||||||||||||||||
| 1634 | - | |||||||||||||||||||||||||
| 1635 | void QGridLayoutEngine::ensureGeometries(const QSizeF &size, | - | ||||||||||||||||||||||||
| 1636 | const QAbstractLayoutStyleInfo *styleInfo) const | - | ||||||||||||||||||||||||
| 1637 | { | - | ||||||||||||||||||||||||
| 1638 | if (q_cachedSize == size)
| 0 | ||||||||||||||||||||||||
| 1639 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1640 | - | |||||||||||||||||||||||||
| 1641 | q_cachedSize = size; | - | ||||||||||||||||||||||||
| 1642 | - | |||||||||||||||||||||||||
| 1643 | q_xx.resize(columnCount()); | - | ||||||||||||||||||||||||
| 1644 | q_widths.resize(columnCount()); | - | ||||||||||||||||||||||||
| 1645 | q_yy.resize(rowCount()); | - | ||||||||||||||||||||||||
| 1646 | q_heights.resize(rowCount()); | - | ||||||||||||||||||||||||
| 1647 | q_descents.resize(rowCount()); | - | ||||||||||||||||||||||||
| 1648 | - | |||||||||||||||||||||||||
| 1649 | if (constraintOrientation() != Qt::Horizontal) {
| 0 | ||||||||||||||||||||||||
| 1650 | //We might have items whose height depends on their width (HFW) | - | ||||||||||||||||||||||||
| 1651 | ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], NULL, NULL, Qt::Horizontal, styleInfo); | - | ||||||||||||||||||||||||
| 1652 | //Calculate column widths and positions, and put results in q_xx.data() and q_widths.data() so that we can use this information as | - | ||||||||||||||||||||||||
| 1653 | //constraints to find the row heights | - | ||||||||||||||||||||||||
| 1654 | q_columnData.calculateGeometries(0, columnCount(), size.width(), q_xx.data(), q_widths.data(), | - | ||||||||||||||||||||||||
| 1655 | 0, q_totalBoxes[Hor], q_infos[Hor], m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1656 | ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], q_xx.data(), q_widths.data(), Qt::Vertical, styleInfo); | - | ||||||||||||||||||||||||
| 1657 | //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() | - | ||||||||||||||||||||||||
| 1658 | q_rowData.calculateGeometries(0, rowCount(), size.height(), q_yy.data(), q_heights.data(), | - | ||||||||||||||||||||||||
| 1659 | q_descents.data(), q_totalBoxes[Ver], q_infos[Ver], m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1660 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1661 | //We have items whose width depends on their height (WFH) | - | ||||||||||||||||||||||||
| 1662 | ensureColumnAndRowData(&q_rowData, &q_totalBoxes[Ver], NULL, NULL, Qt::Vertical, styleInfo); | - | ||||||||||||||||||||||||
| 1663 | //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() so that we can use this information as | - | ||||||||||||||||||||||||
| 1664 | //constraints to find the column widths | - | ||||||||||||||||||||||||
| 1665 | q_rowData.calculateGeometries(0, rowCount(), size.height(), q_yy.data(), q_heights.data(), | - | ||||||||||||||||||||||||
| 1666 | q_descents.data(), q_totalBoxes[Ver], q_infos[Ver], m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1667 | ensureColumnAndRowData(&q_columnData, &q_totalBoxes[Hor], q_yy.data(), q_heights.data(), Qt::Horizontal, styleInfo); | - | ||||||||||||||||||||||||
| 1668 | //Calculate row heights and positions, and put results in q_yy.data() and q_heights.data() | - | ||||||||||||||||||||||||
| 1669 | q_columnData.calculateGeometries(0, columnCount(), size.width(), q_xx.data(), q_widths.data(), | - | ||||||||||||||||||||||||
| 1670 | 0, q_totalBoxes[Hor], q_infos[Hor], m_snapToPixelGrid); | - | ||||||||||||||||||||||||
| 1671 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1672 | } | - | ||||||||||||||||||||||||
| 1673 | - | |||||||||||||||||||||||||
| 1674 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |