| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | - | |||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | const qreal g_offset = (sizeof(qreal) == sizeof(double)) ? ((1<<24)-1) : ((1<<24)-1) / 32; | - | ||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version) | - | ||||||||||||||||||
| 20 | : QObjectPrivate(version), layoutPrivate(0), data(0), | - | ||||||||||||||||||
| 21 | sizePolicy(QSizePolicy::Fixed), preferredSize(0), | - | ||||||||||||||||||
| 22 | hasSize(true) | - | ||||||||||||||||||
| 23 | { | - | ||||||||||||||||||
| 24 | } | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | QGraphicsAnchorPrivate::~QGraphicsAnchorPrivate() | - | ||||||||||||||||||
| 27 | { | - | ||||||||||||||||||
| 28 | if (data) { | - | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | data->graphicsAnchor = 0; | - | ||||||||||||||||||
| 32 | - | |||||||||||||||||||
| 33 | layoutPrivate->removeAnchor(data->from, data->to); | - | ||||||||||||||||||
| 34 | } | - | ||||||||||||||||||
| 35 | } | - | ||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | void QGraphicsAnchorPrivate::setSizePolicy(QSizePolicy::Policy policy) | - | ||||||||||||||||||
| 38 | { | - | ||||||||||||||||||
| 39 | if (sizePolicy != policy) { | - | ||||||||||||||||||
| 40 | sizePolicy = policy; | - | ||||||||||||||||||
| 41 | layoutPrivate->q_func()->invalidate(); | - | ||||||||||||||||||
| 42 | } | - | ||||||||||||||||||
| 43 | } | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | void QGraphicsAnchorPrivate::setSpacing(qreal value) | - | ||||||||||||||||||
| 46 | { | - | ||||||||||||||||||
| 47 | if (!data) { | - | ||||||||||||||||||
| 48 | QMessageLogger(__FILE__, 8593, __PRETTY_FUNCTION__).warning("QGraphicsAnchor::setSpacing: The anchor does not exist."); | - | ||||||||||||||||||
| 49 | return; | - | ||||||||||||||||||
| 50 | } | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | if (hasSize && (preferredSize == value)) | - | ||||||||||||||||||
| 53 | return; | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | hasSize = true; | - | ||||||||||||||||||
| 57 | preferredSize = value; | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | layoutPrivate->q_func()->invalidate(); | - | ||||||||||||||||||
| 60 | } | - | ||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | void QGraphicsAnchorPrivate::unsetSpacing() | - | ||||||||||||||||||
| 63 | { | - | ||||||||||||||||||
| 64 | if (!data) { | - | ||||||||||||||||||
| 65 | QMessageLogger(__FILE__, 102110, __PRETTY_FUNCTION__).warning("QGraphicsAnchor::setSpacing: The anchor does not exist."); | - | ||||||||||||||||||
| 66 | return; | - | ||||||||||||||||||
| 67 | } | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | hasSize = false; | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | layoutPrivate->q_func()->invalidate(); | - | ||||||||||||||||||
| 73 | } | - | ||||||||||||||||||
| 74 | - | |||||||||||||||||||
| 75 | qreal QGraphicsAnchorPrivate::spacing() const | - | ||||||||||||||||||
| 76 | { | - | ||||||||||||||||||
| 77 | if (!data) { | - | ||||||||||||||||||
| 78 | QMessageLogger(__FILE__, 115123, __PRETTY_FUNCTION__).warning("QGraphicsAnchor::setSpacing: The anchor does not exist."); | - | ||||||||||||||||||
| 79 | return 0; | - | ||||||||||||||||||
| 80 | } | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | return preferredSize; | - | ||||||||||||||||||
| 83 | } | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | static void applySizePolicy(QSizePolicy::Policy policy, | - | ||||||||||||||||||
| 87 | qreal minSizeHint, qreal prefSizeHint, qreal maxSizeHint, | - | ||||||||||||||||||
| 88 | qreal *minSize, qreal *prefSize, | - | ||||||||||||||||||
| 89 | qreal *maxSize) | - | ||||||||||||||||||
| 90 | { | - | ||||||||||||||||||
| 91 | if (policy & QSizePolicy::ShrinkFlag) | - | ||||||||||||||||||
| 92 | *minSize = minSizeHint; | - | ||||||||||||||||||
| 93 | else | - | ||||||||||||||||||
| 94 | *minSize = prefSizeHint; | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | if (policy & QSizePolicy::GrowFlag) | - | ||||||||||||||||||
| 97 | *maxSize = maxSizeHint; | - | ||||||||||||||||||
| 98 | else | - | ||||||||||||||||||
| 99 | *maxSize = prefSizeHint; | - | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | if (policy & QSizePolicy::IgnoreFlag) | - | ||||||||||||||||||
| 103 | *prefSize = *minSize; | - | ||||||||||||||||||
| 104 | else | - | ||||||||||||||||||
| 105 | *prefSize = prefSizeHint; | - | ||||||||||||||||||
| 106 | } | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | AnchorData::~AnchorData() | - | ||||||||||||||||||
| 109 | { | - | ||||||||||||||||||
| 110 | if (graphicsAnchor) { | - | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | graphicsAnchor->d_func()->data = 0; | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | delete graphicsAnchor; | - | ||||||||||||||||||
| 116 | } | - | ||||||||||||||||||
| 117 | } | - | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) | - | ||||||||||||||||||
| 121 | { | - | ||||||||||||||||||
| 122 | QSizePolicy::Policy policy; | - | ||||||||||||||||||
| 123 | qreal minSizeHint; | - | ||||||||||||||||||
| 124 | qreal prefSizeHint; | - | ||||||||||||||||||
| 125 | qreal maxSizeHint; | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | if (item) { | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | if (isLayoutAnchor) { | - | ||||||||||||||||||
| 130 | minSize = 0; | - | ||||||||||||||||||
| 131 | prefSize = 0; | - | ||||||||||||||||||
| 132 | maxSize = ((1<<24)-1); | - | ||||||||||||||||||
| 133 | if (isCenterAnchor) | - | ||||||||||||||||||
| 134 | maxSize /= 2; | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | minPrefSize = prefSize; | - | ||||||||||||||||||
| 137 | maxPrefSize = maxSize; | - | ||||||||||||||||||
| 138 | return; | - | ||||||||||||||||||
| 139 | } else { | - | ||||||||||||||||||
| 140 | if (orientation == QGraphicsAnchorLayoutPrivate::Horizontal) { | - | ||||||||||||||||||
| 141 | policy = item->sizePolicy().horizontalPolicy(); | - | ||||||||||||||||||
| 142 | minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).width(); | - | ||||||||||||||||||
| 143 | prefSizeHint = item->effectiveSizeHint(Qt::PreferredSize).width(); | - | ||||||||||||||||||
| 144 | maxSizeHint = item->effectiveSizeHint(Qt::MaximumSize).width(); | - | ||||||||||||||||||
| 145 | } else { | - | ||||||||||||||||||
| 146 | policy = item->sizePolicy().verticalPolicy(); | - | ||||||||||||||||||
| 147 | minSizeHint = item->effectiveSizeHint(Qt::MinimumSize).height(); | - | ||||||||||||||||||
| 148 | prefSizeHint = item->effectiveSizeHint(Qt::PreferredSize).height(); | - | ||||||||||||||||||
| 149 | maxSizeHint = item->effectiveSizeHint(Qt::MaximumSize).height(); | - | ||||||||||||||||||
| 150 | } | - | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | if (isCenterAnchor) { | - | ||||||||||||||||||
| 153 | minSizeHint /= 2; | - | ||||||||||||||||||
| 154 | prefSizeHint /= 2; | - | ||||||||||||||||||
| 155 | maxSizeHint /= 2; | - | ||||||||||||||||||
| 156 | } | - | ||||||||||||||||||
| 157 | } | - | ||||||||||||||||||
| 158 | } else { | - | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | ((!(graphicsAnchor)) ? qt_assert("graphicsAnchor",__FILE__,210218) : qt_noop()); | - | ||||||||||||||||||
| 161 | QGraphicsAnchorPrivate *anchorPrivate = graphicsAnchor->d_func(); | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | policy = anchorPrivate->sizePolicy; | - | ||||||||||||||||||
| 165 | minSizeHint = 0; | - | ||||||||||||||||||
| 166 | maxSizeHint = ((1<<24)-1); | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | if (anchorPrivate->hasSize) { | - | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | prefSizeHint = anchorPrivate->preferredSize; | - | ||||||||||||||||||
| 172 | } else { | - | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | const Qt::Orientation orient = Qt::Orientation(QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge) + 1); | - | ||||||||||||||||||
| 175 | qreal s = styleInfo->defaultSpacing(orient); | - | ||||||||||||||||||
| 176 | if (s < 0) { | - | ||||||||||||||||||
| 177 | QSizePolicy::ControlType controlTypeFrom = from->m_item->sizePolicy().controlType(); | - | ||||||||||||||||||
| 178 | QSizePolicy::ControlType controlTypeTo = to->m_item->sizePolicy().controlType(); | - | ||||||||||||||||||
| 179 | s = styleInfo->perItemSpacing(controlTypeFrom, controlTypeTo, orient); | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | if (s < 0) | - | ||||||||||||||||||
| 185 | s = 0; | - | ||||||||||||||||||
| 186 | } | - | ||||||||||||||||||
| 187 | prefSizeHint = s; | - | ||||||||||||||||||
| 188 | } | - | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | applySizePolicy(policy, minSizeHint, prefSizeHint, maxSizeHint, | - | ||||||||||||||||||
| 193 | &minSize, &prefSize, &maxSize); | - | ||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | minPrefSize = prefSize; | - | ||||||||||||||||||
| 196 | maxPrefSize = maxSize; | - | ||||||||||||||||||
| 197 | sizeAtMinimum = prefSize; | - | ||||||||||||||||||
| 198 | sizeAtPreferred = prefSize; | - | ||||||||||||||||||
| 199 | sizeAtMaximum = prefSize; | - | ||||||||||||||||||
| 200 | } | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | void ParallelAnchorData::updateChildrenSizes() | - | ||||||||||||||||||
| 203 | { | - | ||||||||||||||||||
| 204 | firstEdge->sizeAtMinimum = sizeAtMinimum; | - | ||||||||||||||||||
| 205 | firstEdge->sizeAtPreferred = sizeAtPreferred; | - | ||||||||||||||||||
| 206 | firstEdge->sizeAtMaximum = sizeAtMaximum; | - | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | if (secondForward()) { | - | ||||||||||||||||||
| 209 | secondEdge->sizeAtMinimum = sizeAtMinimum; | - | ||||||||||||||||||
| 210 | secondEdge->sizeAtPreferred = sizeAtPreferred; | - | ||||||||||||||||||
| 211 | secondEdge->sizeAtMaximum = sizeAtMaximum; | - | ||||||||||||||||||
| 212 | } else { | - | ||||||||||||||||||
| 213 | secondEdge->sizeAtMinimum = -sizeAtMinimum; | - | ||||||||||||||||||
| 214 | secondEdge->sizeAtPreferred = -sizeAtPreferred; | - | ||||||||||||||||||
| 215 | secondEdge->sizeAtMaximum = -sizeAtMaximum; | - | ||||||||||||||||||
| 216 | } | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | firstEdge->updateChildrenSizes(); | - | ||||||||||||||||||
| 219 | secondEdge->updateChildrenSizes(); | - | ||||||||||||||||||
| 220 | } | - | ||||||||||||||||||
| 221 | bool ParallelAnchorData::calculateSizeHints() | - | ||||||||||||||||||
| 222 | { | - | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | qreal secondMin; | - | ||||||||||||||||||
| 227 | qreal secondMinPref; | - | ||||||||||||||||||
| 228 | qreal secondPref; | - | ||||||||||||||||||
| 229 | qreal secondMaxPref; | - | ||||||||||||||||||
| 230 | qreal secondMax; | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | if (secondForward()) { | - | ||||||||||||||||||
| 233 | secondMin = secondEdge->minSize; | - | ||||||||||||||||||
| 234 | secondMinPref = secondEdge->minPrefSize; | - | ||||||||||||||||||
| 235 | secondPref = secondEdge->prefSize; | - | ||||||||||||||||||
| 236 | secondMaxPref = secondEdge->maxPrefSize; | - | ||||||||||||||||||
| 237 | secondMax = secondEdge->maxSize; | - | ||||||||||||||||||
| 238 | } else { | - | ||||||||||||||||||
| 239 | secondMin = -secondEdge->maxSize; | - | ||||||||||||||||||
| 240 | secondMinPref = -secondEdge->maxPrefSize; | - | ||||||||||||||||||
| 241 | secondPref = -secondEdge->prefSize; | - | ||||||||||||||||||
| 242 | secondMaxPref = -secondEdge->minPrefSize; | - | ||||||||||||||||||
| 243 | secondMax = -secondEdge->minSize; | - | ||||||||||||||||||
| 244 | } | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | minSize = qMax(firstEdge->minSize, secondMin); | - | ||||||||||||||||||
| 247 | maxSize = qMin(firstEdge->maxSize, secondMax); | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | - | |||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | if (minSize > maxSize) { | - | ||||||||||||||||||
| 253 | return false; | - | ||||||||||||||||||
| 254 | } | - | ||||||||||||||||||
| 255 | if (firstEdge->isLayoutAnchor) { | - | ||||||||||||||||||
| 256 | prefSize = qBound(minSize, secondPref, maxSize); | - | ||||||||||||||||||
| 257 | minPrefSize = qBound(minSize, secondMinPref, maxSize); | - | ||||||||||||||||||
| 258 | maxPrefSize = qBound(minSize, secondMaxPref, maxSize); | - | ||||||||||||||||||
| 259 | } else if (secondEdge->isLayoutAnchor) { | - | ||||||||||||||||||
| 260 | prefSize = qBound(minSize, firstEdge->prefSize, maxSize); | - | ||||||||||||||||||
| 261 | minPrefSize = qBound(minSize, firstEdge->minPrefSize, maxSize); | - | ||||||||||||||||||
| 262 | maxPrefSize = qBound(minSize, firstEdge->maxPrefSize, maxSize); | - | ||||||||||||||||||
| 263 | } else { | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | const qreal lowerBoundary = | - | ||||||||||||||||||
| 266 | qBound(minSize, qMax(firstEdge->minPrefSize, secondMinPref), maxSize); | - | ||||||||||||||||||
| 267 | const qreal upperBoundary = | - | ||||||||||||||||||
| 268 | qBound(minSize, qMin(firstEdge->maxPrefSize, secondMaxPref), maxSize); | - | ||||||||||||||||||
| 269 | const qreal prefMean = | - | ||||||||||||||||||
| 270 | qBound(minSize, (firstEdge->prefSize + secondPref) / 2, maxSize); | - | ||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | if (lowerBoundary < upperBoundary) { | - | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | - | |||||||||||||||||||
| 277 | prefSize = qBound(lowerBoundary, prefMean, upperBoundary); | - | ||||||||||||||||||
| 278 | minPrefSize = lowerBoundary; | - | ||||||||||||||||||
| 279 | maxPrefSize = upperBoundary; | - | ||||||||||||||||||
| 280 | } else { | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | prefSize = qBound(upperBoundary, prefMean, lowerBoundary); | - | ||||||||||||||||||
| 288 | minPrefSize = upperBoundary; | - | ||||||||||||||||||
| 289 | maxPrefSize = lowerBoundary; | - | ||||||||||||||||||
| 290 | } | - | ||||||||||||||||||
| 291 | } | - | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | sizeAtMinimum = prefSize; | - | ||||||||||||||||||
| 295 | sizeAtPreferred = prefSize; | - | ||||||||||||||||||
| 296 | sizeAtMaximum = prefSize; | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | return true; | - | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | static QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> getFactor(qreal value, qreal min, | - | ||||||||||||||||||
| 301 | qreal minPref, qreal pref, | - | ||||||||||||||||||
| 302 | qreal maxPref, qreal max) | - | ||||||||||||||||||
| 303 | { | - | ||||||||||||||||||
| 304 | QGraphicsAnchorLayoutPrivate::Interval interval; | - | ||||||||||||||||||
| 305 | qreal lower; | - | ||||||||||||||||||
| 306 | qreal upper; | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | if (value < minPref) { | - | ||||||||||||||||||
| 309 | interval = QGraphicsAnchorLayoutPrivate::MinimumToMinPreferred; | - | ||||||||||||||||||
| 310 | lower = min; | - | ||||||||||||||||||
| 311 | upper = minPref; | - | ||||||||||||||||||
| 312 | } else if (value < pref) { | - | ||||||||||||||||||
| 313 | interval = QGraphicsAnchorLayoutPrivate::MinPreferredToPreferred; | - | ||||||||||||||||||
| 314 | lower = minPref; | - | ||||||||||||||||||
| 315 | upper = pref; | - | ||||||||||||||||||
| 316 | } else if (value < maxPref) { | - | ||||||||||||||||||
| 317 | interval = QGraphicsAnchorLayoutPrivate::PreferredToMaxPreferred; | - | ||||||||||||||||||
| 318 | lower = pref; | - | ||||||||||||||||||
| 319 | upper = maxPref; | - | ||||||||||||||||||
| 320 | } else { | - | ||||||||||||||||||
| 321 | interval = QGraphicsAnchorLayoutPrivate::MaxPreferredToMaximum; | - | ||||||||||||||||||
| 322 | lower = maxPref; | - | ||||||||||||||||||
| 323 | upper = max; | - | ||||||||||||||||||
| 324 | } | - | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | qreal progress; | - | ||||||||||||||||||
| 327 | if (upper == lower) { | - | ||||||||||||||||||
| 328 | progress = 0; | - | ||||||||||||||||||
| 329 | } else { | - | ||||||||||||||||||
| 330 | progress = (value - lower) / (upper - lower); | - | ||||||||||||||||||
| 331 | } | - | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | return qMakePair(interval, progress); | - | ||||||||||||||||||
| 334 | } | - | ||||||||||||||||||
| 335 | - | |||||||||||||||||||
| 336 | static qreal interpolate(const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> &factor, | - | ||||||||||||||||||
| 337 | qreal min, qreal minPref, qreal pref, qreal maxPref, qreal max) | - | ||||||||||||||||||
| 338 | { | - | ||||||||||||||||||
| 339 | qreal lower = 0; | - | ||||||||||||||||||
| 340 | qreal upper = 0; | - | ||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | switch (factor.first) { | - | ||||||||||||||||||
| 343 | case QGraphicsAnchorLayoutPrivate::MinimumToMinPreferred: | - | ||||||||||||||||||
| 344 | lower = min; | - | ||||||||||||||||||
| 345 | upper = minPref; | - | ||||||||||||||||||
| 346 | break; | - | ||||||||||||||||||
| 347 | case QGraphicsAnchorLayoutPrivate::MinPreferredToPreferred: | - | ||||||||||||||||||
| 348 | lower = minPref; | - | ||||||||||||||||||
| 349 | upper = pref; | - | ||||||||||||||||||
| 350 | break; | - | ||||||||||||||||||
| 351 | case QGraphicsAnchorLayoutPrivate::PreferredToMaxPreferred: | - | ||||||||||||||||||
| 352 | lower = pref; | - | ||||||||||||||||||
| 353 | upper = maxPref; | - | ||||||||||||||||||
| 354 | break; | - | ||||||||||||||||||
| 355 | case QGraphicsAnchorLayoutPrivate::MaxPreferredToMaximum: | - | ||||||||||||||||||
| 356 | lower = maxPref; | - | ||||||||||||||||||
| 357 | upper = max; | - | ||||||||||||||||||
| 358 | break; | - | ||||||||||||||||||
| 359 | } | - | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | return lower + factor.second * (upper - lower); | - | ||||||||||||||||||
| 362 | } | - | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | void SequentialAnchorData::updateChildrenSizes() | - | ||||||||||||||||||
| 365 | { | - | ||||||||||||||||||
| 366 | - | |||||||||||||||||||
| 367 | - | |||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> minFactor = | - | ||||||||||||||||||
| 370 | getFactor(sizeAtMinimum, minSize, minPrefSize, prefSize, maxPrefSize, maxSize); | - | ||||||||||||||||||
| 371 | const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> prefFactor = | - | ||||||||||||||||||
| 372 | getFactor(sizeAtPreferred, minSize, minPrefSize, prefSize, maxPrefSize, maxSize); | - | ||||||||||||||||||
| 373 | const QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> maxFactor = | - | ||||||||||||||||||
| 374 | getFactor(sizeAtMaximum, minSize, minPrefSize, prefSize, maxPrefSize, maxSize); | - | ||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | - | |||||||||||||||||||
| 377 | - | |||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | AnchorVertex *prev = from; | - | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | for (int i = 0; i < m_edges.count(); ++i) { | - | ||||||||||||||||||
| 382 | AnchorData *e = m_edges.at(i); | - | ||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | const bool edgeIsForward = (e->from == prev); | - | ||||||||||||||||||
| 385 | if (edgeIsForward) { | - | ||||||||||||||||||
| 386 | e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->minPrefSize, | - | ||||||||||||||||||
| 387 | e->prefSize, e->maxPrefSize, e->maxSize); | - | ||||||||||||||||||
| 388 | e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->minPrefSize, | - | ||||||||||||||||||
| 389 | e->prefSize, e->maxPrefSize, e->maxSize); | - | ||||||||||||||||||
| 390 | e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->minPrefSize, | - | ||||||||||||||||||
| 391 | e->prefSize, e->maxPrefSize, e->maxSize); | - | ||||||||||||||||||
| 392 | prev = e->to; | - | ||||||||||||||||||
| 393 | } else { | - | ||||||||||||||||||
| 394 | ((!(prev == e->to)) ? qt_assert("prev == e->to",__FILE__,501509) : qt_noop()); | - | ||||||||||||||||||
| 395 | e->sizeAtMinimum = interpolate(minFactor, e->maxSize, e->maxPrefSize, | - | ||||||||||||||||||
| 396 | e->prefSize, e->minPrefSize, e->minSize); | - | ||||||||||||||||||
| 397 | e->sizeAtPreferred = interpolate(prefFactor, e->maxSize, e->maxPrefSize, | - | ||||||||||||||||||
| 398 | e->prefSize, e->minPrefSize, e->minSize); | - | ||||||||||||||||||
| 399 | e->sizeAtMaximum = interpolate(maxFactor, e->maxSize, e->maxPrefSize, | - | ||||||||||||||||||
| 400 | e->prefSize, e->minPrefSize, e->minSize); | - | ||||||||||||||||||
| 401 | prev = e->from; | - | ||||||||||||||||||
| 402 | } | - | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | e->updateChildrenSizes(); | - | ||||||||||||||||||
| 405 | } | - | ||||||||||||||||||
| 406 | } | - | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | void SequentialAnchorData::calculateSizeHints() | - | ||||||||||||||||||
| 409 | { | - | ||||||||||||||||||
| 410 | minSize = 0; | - | ||||||||||||||||||
| 411 | prefSize = 0; | - | ||||||||||||||||||
| 412 | maxSize = 0; | - | ||||||||||||||||||
| 413 | minPrefSize = 0; | - | ||||||||||||||||||
| 414 | maxPrefSize = 0; | - | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | AnchorVertex *prev = from; | - | ||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | for (int i = 0; i < m_edges.count(); ++i) { | - | ||||||||||||||||||
| 419 | AnchorData *edge = m_edges.at(i); | - | ||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | const bool edgeIsForward = (edge->from == prev); | - | ||||||||||||||||||
| 422 | if (edgeIsForward) { | - | ||||||||||||||||||
| 423 | minSize += edge->minSize; | - | ||||||||||||||||||
| 424 | prefSize += edge->prefSize; | - | ||||||||||||||||||
| 425 | maxSize += edge->maxSize; | - | ||||||||||||||||||
| 426 | minPrefSize += edge->minPrefSize; | - | ||||||||||||||||||
| 427 | maxPrefSize += edge->maxPrefSize; | - | ||||||||||||||||||
| 428 | prev = edge->to; | - | ||||||||||||||||||
| 429 | } else { | - | ||||||||||||||||||
| 430 | ((!(prev == edge->to)) ? qt_assert("prev == edge->to",__FILE__,537545) : qt_noop()); | - | ||||||||||||||||||
| 431 | minSize -= edge->maxSize; | - | ||||||||||||||||||
| 432 | prefSize -= edge->prefSize; | - | ||||||||||||||||||
| 433 | maxSize -= edge->minSize; | - | ||||||||||||||||||
| 434 | minPrefSize -= edge->maxPrefSize; | - | ||||||||||||||||||
| 435 | maxPrefSize -= edge->minPrefSize; | - | ||||||||||||||||||
| 436 | prev = edge->from; | - | ||||||||||||||||||
| 437 | } | - | ||||||||||||||||||
| 438 | } | - | ||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | sizeAtMinimum = prefSize; | - | ||||||||||||||||||
| 442 | sizeAtPreferred = prefSize; | - | ||||||||||||||||||
| 443 | sizeAtMaximum = prefSize; | - | ||||||||||||||||||
| 444 | } | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | void AnchorData::dump(int indent) { | - | ||||||||||||||||||
| 448 | if (type == Parallel) { | - | ||||||||||||||||||
| 449 | QMessageLogger(__FILE__, 556564, __PRETTY_FUNCTION__).debug("%*s type: parallel:", indent, ""); | - | ||||||||||||||||||
| 450 | ParallelAnchorData *p = static_cast<ParallelAnchorData *>(this); | - | ||||||||||||||||||
| 451 | p->firstEdge->dump(indent+2); | - | ||||||||||||||||||
| 452 | p->secondEdge->dump(indent+2); | - | ||||||||||||||||||
| 453 | } else if (type == Sequential) { | - | ||||||||||||||||||
| 454 | SequentialAnchorData *s = static_cast<SequentialAnchorData *>(this); | - | ||||||||||||||||||
| 455 | int kids = s->m_edges.count(); | - | ||||||||||||||||||
| 456 | QMessageLogger(__FILE__, 563571, __PRETTY_FUNCTION__).debug("%*s type: sequential(%d):", indent, "", kids); | - | ||||||||||||||||||
| 457 | for (int i = 0; i < kids; ++i) { | - | ||||||||||||||||||
| 458 | s->m_edges.at(i)->dump(indent+2); | - | ||||||||||||||||||
| 459 | } | - | ||||||||||||||||||
| 460 | } else { | - | ||||||||||||||||||
| 461 | QMessageLogger(__FILE__, 568576, __PRETTY_FUNCTION__).debug("%*s type: Normal:", indent, ""); | - | ||||||||||||||||||
| 462 | } | - | ||||||||||||||||||
| 463 | } | - | ||||||||||||||||||
| 464 | - | |||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | - | |||||||||||||||||||
| 467 | QSimplexConstraint *GraphPath::constraint(const GraphPath &path) const | - | ||||||||||||||||||
| 468 | { | - | ||||||||||||||||||
| 469 | - | |||||||||||||||||||
| 470 | QSet<AnchorData *> cPositives; | - | ||||||||||||||||||
| 471 | QSet<AnchorData *> cNegatives; | - | ||||||||||||||||||
| 472 | QSet<AnchorData *> intersection; | - | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | cPositives = positives + path.negatives; | - | ||||||||||||||||||
| 475 | cNegatives = negatives + path.positives; | - | ||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | intersection = cPositives & cNegatives; | - | ||||||||||||||||||
| 478 | - | |||||||||||||||||||
| 479 | cPositives -= intersection; | - | ||||||||||||||||||
| 480 | cNegatives -= intersection; | - | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | - | |||||||||||||||||||
| 483 | QSimplexConstraint *c = new QSimplexConstraint; | - | ||||||||||||||||||
| 484 | QSet<AnchorData *>::iterator i; | - | ||||||||||||||||||
| 485 | for (i = cPositives.begin(); i != cPositives.end(); ++i) | - | ||||||||||||||||||
| 486 | c->variables.insert(*i, 1.0); | - | ||||||||||||||||||
| 487 | - | |||||||||||||||||||
| 488 | for (i = cNegatives.begin(); i != cNegatives.end(); ++i) | - | ||||||||||||||||||
| 489 | c->variables.insert(*i, -1.0); | - | ||||||||||||||||||
| 490 | - | |||||||||||||||||||
| 491 | return c; | - | ||||||||||||||||||
| 492 | } | - | ||||||||||||||||||
| 493 | - | |||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | QString GraphPath::toString() const | - | ||||||||||||||||||
| 496 | { | - | ||||||||||||||||||
| 497 | QString string(QLatin1String("Path: ")); | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(positives)>::type> _container_((positives)); | ||||||||||||||||||||
| 498 | _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (AnchorData *edge = *_container_.i; _container_.control; _container_.control = 0: positives) | - | ||||||||||||||||||
| 499 | string += QString::fromLatin1(" (+++) %1").arg(edge->toString()); never executed: string += QString::fromLatin1(" (+++) %1").arg(edge->toString()); | 0 | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(negatives)>::type> _container_((negatives)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (AnchorData *edge = *_container_.i; _container_.control; _container_.control = 0: negatives) | - | ||||||||||||||||||
| 502 | string += QString::fromLatin1(" (---) %1").arg(edge->toString()); never executed: string += QString::fromLatin1(" (---) %1").arg(edge->toString()); | 0 | ||||||||||||||||||
| 503 | - | |||||||||||||||||||
| 504 | return never executed: string;return string;never executed: return string; | 0 | ||||||||||||||||||
| 505 | } | - | ||||||||||||||||||
| 506 | - | |||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate() | - | ||||||||||||||||||
| 509 | : calculateGraphCacheDirty(true), styleInfoDirty(true) | - | ||||||||||||||||||
| 510 | { | - | ||||||||||||||||||
| 511 | for (int i = 0; i < NOrientations; ++i) { | - | ||||||||||||||||||
| 512 | for (int j = 0; j < 3; ++j) { | - | ||||||||||||||||||
| 513 | sizeHints[i][j] = -1; | - | ||||||||||||||||||
| 514 | } | - | ||||||||||||||||||
| 515 | interpolationProgress[i] = -1; | - | ||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | spacings[i] = -1; | - | ||||||||||||||||||
| 518 | graphHasConflicts[i] = false; | - | ||||||||||||||||||
| 519 | - | |||||||||||||||||||
| 520 | layoutFirstVertex[i] = 0; | - | ||||||||||||||||||
| 521 | layoutCentralVertex[i] = 0; | - | ||||||||||||||||||
| 522 | layoutLastVertex[i] = 0; | - | ||||||||||||||||||
| 523 | } | - | ||||||||||||||||||
| 524 | } | - | ||||||||||||||||||
| 525 | - | |||||||||||||||||||
| 526 | Qt::AnchorPoint QGraphicsAnchorLayoutPrivate::oppositeEdge(Qt::AnchorPoint edge) | - | ||||||||||||||||||
| 527 | { | - | ||||||||||||||||||
| 528 | switch (edge) { | - | ||||||||||||||||||
| 529 | case Qt::AnchorLeft: | - | ||||||||||||||||||
| 530 | edge = Qt::AnchorRight; | - | ||||||||||||||||||
| 531 | break; | - | ||||||||||||||||||
| 532 | case Qt::AnchorRight: | - | ||||||||||||||||||
| 533 | edge = Qt::AnchorLeft; | - | ||||||||||||||||||
| 534 | break; | - | ||||||||||||||||||
| 535 | case Qt::AnchorTop: | - | ||||||||||||||||||
| 536 | edge = Qt::AnchorBottom; | - | ||||||||||||||||||
| 537 | break; | - | ||||||||||||||||||
| 538 | case Qt::AnchorBottom: | - | ||||||||||||||||||
| 539 | edge = Qt::AnchorTop; | - | ||||||||||||||||||
| 540 | break; | - | ||||||||||||||||||
| 541 | default: | - | ||||||||||||||||||
| 542 | break; | - | ||||||||||||||||||
| 543 | } | - | ||||||||||||||||||
| 544 | return edge; | - | ||||||||||||||||||
| 545 | } | - | ||||||||||||||||||
| 546 | AnchorData *QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(AnchorData *newAnchor, bool *feasible) | - | ||||||||||||||||||
| 547 | { | - | ||||||||||||||||||
| 548 | Orientation orientation = Orientation(newAnchor->orientation); | - | ||||||||||||||||||
| 549 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 550 | *feasible = true; | - | ||||||||||||||||||
| 551 | - | |||||||||||||||||||
| 552 | - | |||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | if (AnchorData *oldAnchor = g.takeEdge(newAnchor->from, newAnchor->to)) { | - | ||||||||||||||||||
| 555 | ParallelAnchorData *parallel = new ParallelAnchorData(oldAnchor, newAnchor); | - | ||||||||||||||||||
| 556 | - | |||||||||||||||||||
| 557 | - | |||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | - | |||||||||||||||||||
| 560 | - | |||||||||||||||||||
| 561 | - | |||||||||||||||||||
| 562 | QList<QSimplexConstraint *> &constraints = itemCenterConstraints[orientation]; | - | ||||||||||||||||||
| 563 | - | |||||||||||||||||||
| 564 | AnchorData *children[2] = { oldAnchor, newAnchor }; | - | ||||||||||||||||||
| 565 | QList<QSimplexConstraint *> *childrenConstraints[2] = { ¶llel->m_firstConstraints, | - | ||||||||||||||||||
| 566 | ¶llel->m_secondConstraints }; | - | ||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | for (int i = 0; i < 2; ++i) { | - | ||||||||||||||||||
| 569 | AnchorData *child = children[i]; | - | ||||||||||||||||||
| 570 | QList<QSimplexConstraint *> *childConstraints = childrenConstraints[i]; | - | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | - | |||||||||||||||||||
| 573 | - | |||||||||||||||||||
| 574 | - | |||||||||||||||||||
| 575 | - | |||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | const bool needsReverse = i == 1 && !parallel->secondForward(); | - | ||||||||||||||||||
| 578 | - | |||||||||||||||||||
| 579 | if (!child->isCenterAnchor) | - | ||||||||||||||||||
| 580 | continue; | - | ||||||||||||||||||
| 581 | - | |||||||||||||||||||
| 582 | parallel->isCenterAnchor = true; | - | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | for (int j = 0; j < constraints.count(); ++j) { | - | ||||||||||||||||||
| 585 | QSimplexConstraint *c = constraints[j]; | - | ||||||||||||||||||
| 586 | if (c->variables.contains(child)) { | - | ||||||||||||||||||
| 587 | childConstraints->append(c); | - | ||||||||||||||||||
| 588 | qreal v = c->variables.take(child); | - | ||||||||||||||||||
| 589 | if (needsReverse) | - | ||||||||||||||||||
| 590 | v *= -1; | - | ||||||||||||||||||
| 591 | c->variables.insert(parallel, v); | - | ||||||||||||||||||
| 592 | } | - | ||||||||||||||||||
| 593 | } | - | ||||||||||||||||||
| 594 | } | - | ||||||||||||||||||
| 595 | - | |||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | *feasible = parallel->calculateSizeHints(); | - | ||||||||||||||||||
| 599 | newAnchor = parallel; | - | ||||||||||||||||||
| 600 | } | - | ||||||||||||||||||
| 601 | - | |||||||||||||||||||
| 602 | g.createEdge(newAnchor->from, newAnchor->to, newAnchor); | - | ||||||||||||||||||
| 603 | return newAnchor; | - | ||||||||||||||||||
| 604 | } | - | ||||||||||||||||||
| 605 | static AnchorData *createSequence(Graph<AnchorVertex, AnchorData> *graph, | - | ||||||||||||||||||
| 606 | AnchorVertex *before, | - | ||||||||||||||||||
| 607 | const QVector<AnchorVertex*> &vertices, | - | ||||||||||||||||||
| 608 | AnchorVertex *after) | - | ||||||||||||||||||
| 609 | { | - | ||||||||||||||||||
| 610 | AnchorVertex *prev = before; | - | ||||||||||||||||||
| 611 | QVector<AnchorData *> edges; | - | ||||||||||||||||||
| 612 | edges.reserve(vertices.count() + 1); | - | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | const int numVertices = vertices.count(); | - | ||||||||||||||||||
| 615 | edges.reserve(numVertices + 1); | - | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | for (int i = 0; i < numVertices; ++i) { | - | ||||||||||||||||||
| 618 | AnchorVertex *next = vertices.at(i); | - | ||||||||||||||||||
| 619 | AnchorData *ad = graph->takeEdge(prev, next); | - | ||||||||||||||||||
| 620 | ((!(ad)) ? qt_assert("ad",__FILE__,762770) : qt_noop()); | - | ||||||||||||||||||
| 621 | edges.append(ad); | - | ||||||||||||||||||
| 622 | prev = next; | - | ||||||||||||||||||
| 623 | } | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | AnchorData *ad = graph->takeEdge(vertices.last(), after); | - | ||||||||||||||||||
| 627 | ((!(ad)) ? qt_assert("ad",__FILE__,769777) : qt_noop()); | - | ||||||||||||||||||
| 628 | edges.append(ad); | - | ||||||||||||||||||
| 629 | - | |||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | SequentialAnchorData *sequence = new SequentialAnchorData(vertices, edges); | - | ||||||||||||||||||
| 632 | sequence->from = before; | - | ||||||||||||||||||
| 633 | sequence->to = after; | - | ||||||||||||||||||
| 634 | - | |||||||||||||||||||
| 635 | sequence->calculateSizeHints(); | - | ||||||||||||||||||
| 636 | - | |||||||||||||||||||
| 637 | return sequence; | - | ||||||||||||||||||
| 638 | } | - | ||||||||||||||||||
| 639 | bool QGraphicsAnchorLayoutPrivate::simplifyGraph(Orientation orientation) | - | ||||||||||||||||||
| 640 | { | - | ||||||||||||||||||
| 641 | if (items.isEmpty()) | - | ||||||||||||||||||
| 642 | return true; | - | ||||||||||||||||||
| 643 | if (!simplifyVertices(orientation)) { | - | ||||||||||||||||||
| 644 | restoreVertices(orientation); | - | ||||||||||||||||||
| 645 | return false; | - | ||||||||||||||||||
| 646 | } | - | ||||||||||||||||||
| 647 | - | |||||||||||||||||||
| 648 | - | |||||||||||||||||||
| 649 | bool dirty; | - | ||||||||||||||||||
| 650 | bool feasible = true; | - | ||||||||||||||||||
| 651 | do { | - | ||||||||||||||||||
| 652 | dirty = simplifyGraphIteration(orientation, &feasible); | - | ||||||||||||||||||
| 653 | } while (dirty && feasible); | - | ||||||||||||||||||
| 654 | - | |||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | if (!feasible) { | - | ||||||||||||||||||
| 657 | restoreSimplifiedGraph(orientation); | - | ||||||||||||||||||
| 658 | restoreVertices(orientation); | - | ||||||||||||||||||
| 659 | return false; | - | ||||||||||||||||||
| 660 | } | - | ||||||||||||||||||
| 661 | - | |||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | - | |||||||||||||||||||
| 664 | - | |||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | return true; | - | ||||||||||||||||||
| 668 | } | - | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | static AnchorVertex *replaceVertex_helper(AnchorData *data, AnchorVertex *oldV, AnchorVertex *newV) | - | ||||||||||||||||||
| 671 | { | - | ||||||||||||||||||
| 672 | AnchorVertex *other; | - | ||||||||||||||||||
| 673 | if (data->from == oldV) { | - | ||||||||||||||||||
| 674 | data->from = newV; | - | ||||||||||||||||||
| 675 | other = data->to; | - | ||||||||||||||||||
| 676 | } else { | - | ||||||||||||||||||
| 677 | data->to = newV; | - | ||||||||||||||||||
| 678 | other = data->from; | - | ||||||||||||||||||
| 679 | } | - | ||||||||||||||||||
| 680 | return other; | - | ||||||||||||||||||
| 681 | } | - | ||||||||||||||||||
| 682 | - | |||||||||||||||||||
| 683 | bool QGraphicsAnchorLayoutPrivate::replaceVertex(Orientation orientation, AnchorVertex *oldV, | - | ||||||||||||||||||
| 684 | AnchorVertex *newV, const QList<AnchorData *> &edges) | - | ||||||||||||||||||
| 685 | { | - | ||||||||||||||||||
| 686 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 687 | bool feasible = true; | - | ||||||||||||||||||
| 688 | - | |||||||||||||||||||
| 689 | for (int i = 0; i < edges.count(); ++i) { | - | ||||||||||||||||||
| 690 | AnchorData *ad = edges[i]; | - | ||||||||||||||||||
| 691 | AnchorVertex *otherV = replaceVertex_helper(ad, oldV, newV); | - | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | ad->name = QString::fromLatin1("%1 --to--> %2").arg(ad->from->toString()).arg(ad->to->toString()); | - | ||||||||||||||||||
| 695 | - | |||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | bool newFeasible; | - | ||||||||||||||||||
| 698 | AnchorData *newAnchor = addAnchorMaybeParallel(ad, &newFeasible); | - | ||||||||||||||||||
| 699 | feasible &= newFeasible; | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | if (newAnchor != ad) { | - | ||||||||||||||||||
| 702 | - | |||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | - | |||||||||||||||||||
| 705 | anchorsFromSimplifiedVertices[orientation].append(newAnchor); | - | ||||||||||||||||||
| 706 | } | - | ||||||||||||||||||
| 707 | - | |||||||||||||||||||
| 708 | g.takeEdge(oldV, otherV); | - | ||||||||||||||||||
| 709 | } | - | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | return feasible; | - | ||||||||||||||||||
| 712 | } | - | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | - | |||||||||||||||||||
| 715 | - | |||||||||||||||||||
| 716 | - | |||||||||||||||||||
| 717 | bool QGraphicsAnchorLayoutPrivate::simplifyVertices(Orientation orientation) | - | ||||||||||||||||||
| 718 | { | - | ||||||||||||||||||
| 719 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 720 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 721 | - | |||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | QStack<AnchorVertex *> stack; | - | ||||||||||||||||||
| 724 | stack.push(layoutFirstVertex[orientation]); | - | ||||||||||||||||||
| 725 | QSet<AnchorVertex *> visited; | - | ||||||||||||||||||
| 726 | - | |||||||||||||||||||
| 727 | while (!stack.isEmpty()) { | - | ||||||||||||||||||
| 728 | AnchorVertex *v = stack.pop(); | - | ||||||||||||||||||
| 729 | visited.insert(v); | - | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | - | |||||||||||||||||||
| 732 | - | |||||||||||||||||||
| 733 | - | |||||||||||||||||||
| 734 | QList<AnchorVertex *> adjacents = g.adjacentVertices(v); | - | ||||||||||||||||||
| 735 | int index = 0; | - | ||||||||||||||||||
| 736 | - | |||||||||||||||||||
| 737 | while (index < adjacents.count()) { | - | ||||||||||||||||||
| 738 | AnchorVertex *next = adjacents.at(index); | - | ||||||||||||||||||
| 739 | index++; | - | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | AnchorData *data = g.edgeData(v, next); | - | ||||||||||||||||||
| 742 | const bool bothLayoutVertices = v->m_item == q && next->m_item == q; | - | ||||||||||||||||||
| 743 | const bool zeroSized = !data->minSize && !data->maxSize; | - | ||||||||||||||||||
| 744 | - | |||||||||||||||||||
| 745 | if (!bothLayoutVertices && zeroSized) { | - | ||||||||||||||||||
| 746 | - | |||||||||||||||||||
| 747 | - | |||||||||||||||||||
| 748 | - | |||||||||||||||||||
| 749 | AnchorVertexPair *newV = new AnchorVertexPair(v, next, data); | - | ||||||||||||||||||
| 750 | simplifiedVertices[orientation].append(newV); | - | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | - | |||||||||||||||||||
| 753 | - | |||||||||||||||||||
| 754 | const QList<AnchorVertex *> &vAdjacents = g.adjacentVertices(v); | - | ||||||||||||||||||
| 755 | const QList<AnchorVertex *> &nextAdjacents = g.adjacentVertices(next); | - | ||||||||||||||||||
| 756 | - | |||||||||||||||||||
| 757 | for (int i = 0; i < vAdjacents.count(); ++i) { | - | ||||||||||||||||||
| 758 | AnchorVertex *adjacent = vAdjacents.at(i); | - | ||||||||||||||||||
| 759 | if (adjacent != next) { | - | ||||||||||||||||||
| 760 | AnchorData *ad = g.edgeData(v, adjacent); | - | ||||||||||||||||||
| 761 | newV->m_firstAnchors.append(ad); | - | ||||||||||||||||||
| 762 | } | - | ||||||||||||||||||
| 763 | } | - | ||||||||||||||||||
| 764 | - | |||||||||||||||||||
| 765 | for (int i = 0; i < nextAdjacents.count(); ++i) { | - | ||||||||||||||||||
| 766 | AnchorVertex *adjacent = nextAdjacents.at(i); | - | ||||||||||||||||||
| 767 | if (adjacent != v) { | - | ||||||||||||||||||
| 768 | AnchorData *ad = g.edgeData(next, adjacent); | - | ||||||||||||||||||
| 769 | newV->m_secondAnchors.append(ad); | - | ||||||||||||||||||
| 770 | - | |||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | if (!adjacents.contains(adjacent)) | - | ||||||||||||||||||
| 774 | adjacents.append(adjacent); | - | ||||||||||||||||||
| 775 | } | - | ||||||||||||||||||
| 776 | } | - | ||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | - | |||||||||||||||||||
| 779 | - | |||||||||||||||||||
| 780 | bool feasible = replaceVertex(orientation, v, newV, newV->m_firstAnchors); | - | ||||||||||||||||||
| 781 | feasible &= replaceVertex(orientation, next, newV, newV->m_secondAnchors); | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | - | |||||||||||||||||||
| 784 | AnchorVertex *layoutVertex = 0; | - | ||||||||||||||||||
| 785 | if (v->m_item == q) | - | ||||||||||||||||||
| 786 | layoutVertex = v; | - | ||||||||||||||||||
| 787 | else if (next->m_item == q) | - | ||||||||||||||||||
| 788 | layoutVertex = next; | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | if (layoutVertex) { | - | ||||||||||||||||||
| 791 | - | |||||||||||||||||||
| 792 | newV->m_item = q; | - | ||||||||||||||||||
| 793 | changeLayoutVertex(orientation, layoutVertex, newV); | - | ||||||||||||||||||
| 794 | } | - | ||||||||||||||||||
| 795 | - | |||||||||||||||||||
| 796 | g.takeEdge(v, next); | - | ||||||||||||||||||
| 797 | - | |||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | if (!feasible) | - | ||||||||||||||||||
| 800 | return false; | - | ||||||||||||||||||
| 801 | - | |||||||||||||||||||
| 802 | v = newV; | - | ||||||||||||||||||
| 803 | visited.insert(newV); | - | ||||||||||||||||||
| 804 | - | |||||||||||||||||||
| 805 | } else if (!visited.contains(next) && !stack.contains(next)) { | - | ||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | - | |||||||||||||||||||
| 808 | stack.push(next); | - | ||||||||||||||||||
| 809 | } | - | ||||||||||||||||||
| 810 | } | - | ||||||||||||||||||
| 811 | } | - | ||||||||||||||||||
| 812 | - | |||||||||||||||||||
| 813 | return true; | - | ||||||||||||||||||
| 814 | } | - | ||||||||||||||||||
| 815 | bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutPrivate::Orientation orientation, | - | ||||||||||||||||||
| 816 | bool *feasible) | - | ||||||||||||||||||
| 817 | { | - | ||||||||||||||||||
| 818 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 819 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 820 | - | |||||||||||||||||||
| 821 | QSet<AnchorVertex *> visited; | - | ||||||||||||||||||
| 822 | QStack<QPair<AnchorVertex *, AnchorVertex *> > stack; | - | ||||||||||||||||||
| 823 | stack.push(qMakePair(static_cast<AnchorVertex *>(0), layoutFirstVertex[orientation])); | - | ||||||||||||||||||
| 824 | QVector<AnchorVertex*> candidates; | - | ||||||||||||||||||
| 825 | - | |||||||||||||||||||
| 826 | - | |||||||||||||||||||
| 827 | - | |||||||||||||||||||
| 828 | while (!stack.isEmpty()
| 0 | ||||||||||||||||||
| 829 | QPair<AnchorVertex *, AnchorVertex *> pair = stack.pop(); | - | ||||||||||||||||||
| 830 | AnchorVertex *beforeSequence = pair.first; | - | ||||||||||||||||||
| 831 | AnchorVertex *v = pair.second; | - | ||||||||||||||||||
| 832 | const QList<AnchorVertex *> &adjacents = g.adjacentVertices(v); | - | ||||||||||||||||||
| 833 | const bool isLayoutVertex = v->m_item == q; | - | ||||||||||||||||||
| 834 | AnchorVertex *afterSequence = v; | - | ||||||||||||||||||
| 835 | bool endOfSequence = false; | - | ||||||||||||||||||
| 836 | - | |||||||||||||||||||
| 837 | - | |||||||||||||||||||
| 838 | - | |||||||||||||||||||
| 839 | - | |||||||||||||||||||
| 840 | - | |||||||||||||||||||
| 841 | - | |||||||||||||||||||
| 842 | endOfSequence = isLayoutVertex
| 0 | ||||||||||||||||||
| 843 | - | |||||||||||||||||||
| 844 | if (!endOfSequence
| 0 | ||||||||||||||||||
| 845 | AnchorVertex *after; | - | ||||||||||||||||||
| 846 | if (candidates.isEmpty()
| 0 | ||||||||||||||||||
| 847 | after = (beforeSequence == adjacents.last()
never executed: after = (beforeSequence == adjacents.last() ? adjacents.first() : adjacents.last()); | 0 | ||||||||||||||||||
| 848 | else | - | ||||||||||||||||||
| 849 | after = (candidates.lastconstLast() == adjacents.last()
never executed: after = (candidates.constLast() == adjacents.last() ? adjacents.first() : adjacents.last()); | 0 | ||||||||||||||||||
| 850 | - | |||||||||||||||||||
| 851 | - | |||||||||||||||||||
| 852 | - | |||||||||||||||||||
| 853 | ((!(!candidates.contains(after))) ? qt_assert("!candidates.contains(after)",__FILE__,10811089) : qt_noop()); | - | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | const AnchorData *data = g.edgeData(v, after); | - | ||||||||||||||||||
| 856 | ((!(data)) ? qt_assert("data",__FILE__,10841092) : qt_noop()); | - | ||||||||||||||||||
| 857 | const bool cycleFound = visited.contains(after); | - | ||||||||||||||||||
| 858 | - | |||||||||||||||||||
| 859 | - | |||||||||||||||||||
| 860 | endOfSequence = cycleFound
| 0 | ||||||||||||||||||
| 861 | - | |||||||||||||||||||
| 862 | if (!endOfSequence
| 0 | ||||||||||||||||||
| 863 | - | |||||||||||||||||||
| 864 | - | |||||||||||||||||||
| 865 | candidates.append(v); | - | ||||||||||||||||||
| 866 | } never executed: else if (cycleFoundend of block
| 0 | ||||||||||||||||||
| 867 | afterSequence = after; | - | ||||||||||||||||||
| 868 | candidates.append(v); | - | ||||||||||||||||||
| 869 | } never executed: end of block | 0 | ||||||||||||||||||
| 870 | } never executed: end of block | 0 | ||||||||||||||||||
| 871 | - | |||||||||||||||||||
| 872 | - | |||||||||||||||||||
| 873 | - | |||||||||||||||||||
| 874 | - | |||||||||||||||||||
| 875 | for (int i = 0; i < adjacents.count()
| 0 | ||||||||||||||||||
| 876 | AnchorVertex *next = adjacents.at(i); | - | ||||||||||||||||||
| 877 | if (visited.contains(next)
| 0 | ||||||||||||||||||
| 878 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 879 | - | |||||||||||||||||||
| 880 | - | |||||||||||||||||||
| 881 | - | |||||||||||||||||||
| 882 | - | |||||||||||||||||||
| 883 | - | |||||||||||||||||||
| 884 | if (endOfSequence
| 0 | ||||||||||||||||||
| 885 | stack.push(qMakePair(v, next)); never executed: stack.push(qMakePair(v, next)); | 0 | ||||||||||||||||||
| 886 | else | - | ||||||||||||||||||
| 887 | stack.push(qMakePair(beforeSequence, next)); never executed: stack.push(qMakePair(beforeSequence, next)); | 0 | ||||||||||||||||||
| 888 | } | - | ||||||||||||||||||
| 889 | - | |||||||||||||||||||
| 890 | visited.insert(v); | - | ||||||||||||||||||
| 891 | - | |||||||||||||||||||
| 892 | if (!endOfSequence
| 0 | ||||||||||||||||||
| 893 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 894 | - | |||||||||||||||||||
| 895 | - | |||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | - | |||||||||||||||||||
| 898 | - | |||||||||||||||||||
| 899 | - | |||||||||||||||||||
| 900 | - | |||||||||||||||||||
| 901 | const AnchorData *firstAnchor = g.edgeData(beforeSequence, candidates.firstconstFirst()); | - | ||||||||||||||||||
| 902 | if (firstAnchor->isCenterAnchor
| 0 | ||||||||||||||||||
| 903 | beforeSequence = candidates.firstconstFirst(); | - | ||||||||||||||||||
| 904 | candidates.remove(0); | - | ||||||||||||||||||
| 905 | - | |||||||||||||||||||
| 906 | - | |||||||||||||||||||
| 907 | if (candidates.isEmpty()
| 0 | ||||||||||||||||||
| 908 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 909 | } never executed: end of block | 0 | ||||||||||||||||||
| 910 | - | |||||||||||||||||||
| 911 | const AnchorData *lastAnchor = g.edgeData(candidates.lastconstLast(), afterSequence); | - | ||||||||||||||||||
| 912 | if (lastAnchor->isCenterAnchor
| 0 | ||||||||||||||||||
| 913 | afterSequence = candidates.lastconstLast(); | - | ||||||||||||||||||
| 914 | candidates.remove(candidates.count() - 1); | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | if (candidates.isEmpty()
| 0 | ||||||||||||||||||
| 917 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 918 | } never executed: end of block | 0 | ||||||||||||||||||
| 919 | - | |||||||||||||||||||
| 920 | - | |||||||||||||||||||
| 921 | - | |||||||||||||||||||
| 922 | - | |||||||||||||||||||
| 923 | - | |||||||||||||||||||
| 924 | AnchorData *sequence = createSequence(&g, beforeSequence, candidates, afterSequence); | - | ||||||||||||||||||
| 925 | - | |||||||||||||||||||
| 926 | - | |||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | bool newFeasible; | - | ||||||||||||||||||
| 929 | AnchorData *newAnchor = addAnchorMaybeParallel(sequence, &newFeasible); | - | ||||||||||||||||||
| 930 | - | |||||||||||||||||||
| 931 | if (!newFeasible
| 0 | ||||||||||||||||||
| 932 | *feasible = false; | - | ||||||||||||||||||
| 933 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 934 | } | - | ||||||||||||||||||
| 935 | - | |||||||||||||||||||
| 936 | - | |||||||||||||||||||
| 937 | - | |||||||||||||||||||
| 938 | - | |||||||||||||||||||
| 939 | - | |||||||||||||||||||
| 940 | if (newAnchor != sequence
| 0 | ||||||||||||||||||
| 941 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 942 | - | |||||||||||||||||||
| 943 | - | |||||||||||||||||||
| 944 | - | |||||||||||||||||||
| 945 | candidates.clear(); | - | ||||||||||||||||||
| 946 | } never executed: end of block | 0 | ||||||||||||||||||
| 947 | - | |||||||||||||||||||
| 948 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 949 | } | - | ||||||||||||||||||
| 950 | - | |||||||||||||||||||
| 951 | void QGraphicsAnchorLayoutPrivate::restoreSimplifiedAnchor(AnchorData *edge) | - | ||||||||||||||||||
| 952 | { | - | ||||||||||||||||||
| 953 | - | |||||||||||||||||||
| 954 | - | |||||||||||||||||||
| 955 | - | |||||||||||||||||||
| 956 | - | |||||||||||||||||||
| 957 | - | |||||||||||||||||||
| 958 | - | |||||||||||||||||||
| 959 | - | |||||||||||||||||||
| 960 | Graph<AnchorVertex, AnchorData> &g = graph[edge->orientation]; | - | ||||||||||||||||||
| 961 | - | |||||||||||||||||||
| 962 | if (edge->type == AnchorData::Normal) { | - | ||||||||||||||||||
| 963 | g.createEdge(edge->from, edge->to, edge); | - | ||||||||||||||||||
| 964 | - | |||||||||||||||||||
| 965 | } else if (edge->type == AnchorData::Sequential) { | - | ||||||||||||||||||
| 966 | SequentialAnchorData *sequence = static_cast<SequentialAnchorData *>(edge); | - | ||||||||||||||||||
| 967 | - | |||||||||||||||||||
| 968 | for (int i = 0; i < sequence->m_edges.count(); ++i) { | - | ||||||||||||||||||
| 969 | AnchorData *data = sequence->m_edges.at(i); | - | ||||||||||||||||||
| 970 | restoreSimplifiedAnchor(data); | - | ||||||||||||||||||
| 971 | } | - | ||||||||||||||||||
| 972 | - | |||||||||||||||||||
| 973 | delete sequence; | - | ||||||||||||||||||
| 974 | - | |||||||||||||||||||
| 975 | } else if (edge->type == AnchorData::Parallel) { | - | ||||||||||||||||||
| 976 | - | |||||||||||||||||||
| 977 | - | |||||||||||||||||||
| 978 | - | |||||||||||||||||||
| 979 | - | |||||||||||||||||||
| 980 | if (anchorsFromSimplifiedVertices[edge->orientation].contains(edge)) | - | ||||||||||||||||||
| 981 | return; | - | ||||||||||||||||||
| 982 | - | |||||||||||||||||||
| 983 | ParallelAnchorData* parallel = static_cast<ParallelAnchorData*>(edge); | - | ||||||||||||||||||
| 984 | restoreSimplifiedConstraints(parallel); | - | ||||||||||||||||||
| 985 | - | |||||||||||||||||||
| 986 | - | |||||||||||||||||||
| 987 | - | |||||||||||||||||||
| 988 | - | |||||||||||||||||||
| 989 | ((!(parallel->firstEdge->type == AnchorData::Sequential || parallel->secondEdge->type == AnchorData::Sequential)) ? qt_assert("parallel->firstEdge->type == AnchorData::Sequential || parallel->secondEdge->type == AnchorData::Sequential", | - | ||||||||||||||||||
| 990 | __FILE__ | - | ||||||||||||||||||
| 991 | , | - | ||||||||||||||||||
| 992 | 12181226 | - | ||||||||||||||||||
| 993 | ) : qt_noop()) | - | ||||||||||||||||||
| 994 | ; | - | ||||||||||||||||||
| 995 | restoreSimplifiedAnchor(parallel->firstEdge); | - | ||||||||||||||||||
| 996 | restoreSimplifiedAnchor(parallel->secondEdge); | - | ||||||||||||||||||
| 997 | - | |||||||||||||||||||
| 998 | delete parallel; | - | ||||||||||||||||||
| 999 | } | - | ||||||||||||||||||
| 1000 | } | - | ||||||||||||||||||
| 1001 | - | |||||||||||||||||||
| 1002 | void QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints(ParallelAnchorData *parallel) | - | ||||||||||||||||||
| 1003 | { | - | ||||||||||||||||||
| 1004 | if (!parallel->isCenterAnchor) | - | ||||||||||||||||||
| 1005 | return; | - | ||||||||||||||||||
| 1006 | - | |||||||||||||||||||
| 1007 | for (int i = 0; i < parallel->m_firstConstraints.count(); ++i) { | - | ||||||||||||||||||
| 1008 | QSimplexConstraint *c = parallel->m_firstConstraints.at(i); | - | ||||||||||||||||||
| 1009 | qreal v = c->variables[parallel]; | - | ||||||||||||||||||
| 1010 | c->variables.remove(parallel); | - | ||||||||||||||||||
| 1011 | c->variables.insert(parallel->firstEdge, v); | - | ||||||||||||||||||
| 1012 | } | - | ||||||||||||||||||
| 1013 | - | |||||||||||||||||||
| 1014 | - | |||||||||||||||||||
| 1015 | - | |||||||||||||||||||
| 1016 | const bool needsReverse = !parallel->secondForward(); | - | ||||||||||||||||||
| 1017 | - | |||||||||||||||||||
| 1018 | for (int i = 0; i < parallel->m_secondConstraints.count(); ++i) { | - | ||||||||||||||||||
| 1019 | QSimplexConstraint *c = parallel->m_secondConstraints.at(i); | - | ||||||||||||||||||
| 1020 | qreal v = c->variables[parallel]; | - | ||||||||||||||||||
| 1021 | if (needsReverse) | - | ||||||||||||||||||
| 1022 | v *= -1; | - | ||||||||||||||||||
| 1023 | c->variables.remove(parallel); | - | ||||||||||||||||||
| 1024 | c->variables.insert(parallel->secondEdge, v); | - | ||||||||||||||||||
| 1025 | } | - | ||||||||||||||||||
| 1026 | } | - | ||||||||||||||||||
| 1027 | - | |||||||||||||||||||
| 1028 | void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientation) | - | ||||||||||||||||||
| 1029 | { | - | ||||||||||||||||||
| 1030 | - | |||||||||||||||||||
| 1031 | - | |||||||||||||||||||
| 1032 | - | |||||||||||||||||||
| 1033 | - | |||||||||||||||||||
| 1034 | - | |||||||||||||||||||
| 1035 | - | |||||||||||||||||||
| 1036 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 1037 | QListQVector<QPair<AnchorVertex*, AnchorVertex*> > connections = g.connections(); | - | ||||||||||||||||||
| 1038 | for (int i = 0; i < connections.count()
| 0 | ||||||||||||||||||
| 1039 | AnchorVertex *v1 = connections.at(i).first; | - | ||||||||||||||||||
| 1040 | AnchorVertex *v2 = connections.at(i).second; | - | ||||||||||||||||||
| 1041 | AnchorData *edge = g.edgeData(v1, v2); | - | ||||||||||||||||||
| 1042 | - | |||||||||||||||||||
| 1043 | - | |||||||||||||||||||
| 1044 | - | |||||||||||||||||||
| 1045 | if (edge->type == AnchorData::Sequential
| 0 | ||||||||||||||||||
| 1046 | || (edge->type == AnchorData::Parallel
| 0 | ||||||||||||||||||
| 1047 | !anchorsFromSimplifiedVertices[orientation].contains(edge)
| 0 | ||||||||||||||||||
| 1048 | - | |||||||||||||||||||
| 1049 | g.takeEdge(v1, v2); | - | ||||||||||||||||||
| 1050 | restoreSimplifiedAnchor(edge); | - | ||||||||||||||||||
| 1051 | } never executed: end of block | 0 | ||||||||||||||||||
| 1052 | } never executed: end of block | 0 | ||||||||||||||||||
| 1053 | - | |||||||||||||||||||
| 1054 | restoreVertices(orientation); | - | ||||||||||||||||||
| 1055 | } never executed: end of block | 0 | ||||||||||||||||||
| 1056 | - | |||||||||||||||||||
| 1057 | void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation) | - | ||||||||||||||||||
| 1058 | { | - | ||||||||||||||||||
| 1059 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1060 | - | |||||||||||||||||||
| 1061 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 1062 | QList<AnchorVertexPair *> &toRestore = simplifiedVertices[orientation]; | - | ||||||||||||||||||
| 1063 | QList<AnchorData *> ¶llelAnchors = anchorsFromSimplifiedVertices[orientation]; | - | ||||||||||||||||||
| 1064 | - | |||||||||||||||||||
| 1065 | for (int i = parallelAnchors.count() - 1; i >= 0; --i) { | - | ||||||||||||||||||
| 1066 | ParallelAnchorData *parallel = static_cast<ParallelAnchorData *>(parallelAnchors.at(i)); | - | ||||||||||||||||||
| 1067 | restoreSimplifiedConstraints(parallel); | - | ||||||||||||||||||
| 1068 | } | - | ||||||||||||||||||
| 1069 | - | |||||||||||||||||||
| 1070 | - | |||||||||||||||||||
| 1071 | - | |||||||||||||||||||
| 1072 | for (int i = toRestore.count() - 1; i >= 0; --i) { | - | ||||||||||||||||||
| 1073 | AnchorVertexPair *pair = toRestore.at(i); | - | ||||||||||||||||||
| 1074 | QList<AnchorVertex *> adjacents = g.adjacentVertices(pair); | - | ||||||||||||||||||
| 1075 | - | |||||||||||||||||||
| 1076 | - | |||||||||||||||||||
| 1077 | - | |||||||||||||||||||
| 1078 | AnchorVertex *first = pair->m_first; | - | ||||||||||||||||||
| 1079 | AnchorVertex *second = pair->m_second; | - | ||||||||||||||||||
| 1080 | g.createEdge(first, second, pair->m_removedAnchor); | - | ||||||||||||||||||
| 1081 | - | |||||||||||||||||||
| 1082 | - | |||||||||||||||||||
| 1083 | for (int j = 0; j < pair->m_firstAnchors.count(); ++j) { | - | ||||||||||||||||||
| 1084 | AnchorData *ad = pair->m_firstAnchors.at(j); | - | ||||||||||||||||||
| 1085 | ((!(ad->from == pair || ad->to == pair)) ? qt_assert("ad->from == pair || ad->to == pair",__FILE__,13181326) : qt_noop()); | - | ||||||||||||||||||
| 1086 | - | |||||||||||||||||||
| 1087 | replaceVertex_helper(ad, pair, first); | - | ||||||||||||||||||
| 1088 | g.createEdge(ad->from, ad->to, ad); | - | ||||||||||||||||||
| 1089 | } | - | ||||||||||||||||||
| 1090 | - | |||||||||||||||||||
| 1091 | - | |||||||||||||||||||
| 1092 | for (int j = 0; j < pair->m_secondAnchors.count(); ++j) { | - | ||||||||||||||||||
| 1093 | AnchorData *ad = pair->m_secondAnchors.at(j); | - | ||||||||||||||||||
| 1094 | ((!(ad->from == pair || ad->to == pair)) ? qt_assert("ad->from == pair || ad->to == pair",__FILE__,13271335) : qt_noop()); | - | ||||||||||||||||||
| 1095 | - | |||||||||||||||||||
| 1096 | replaceVertex_helper(ad, pair, second); | - | ||||||||||||||||||
| 1097 | g.createEdge(ad->from, ad->to, ad); | - | ||||||||||||||||||
| 1098 | } | - | ||||||||||||||||||
| 1099 | - | |||||||||||||||||||
| 1100 | for (int j = 0; j < adjacents.count(); ++j) { | - | ||||||||||||||||||
| 1101 | g.takeEdge(pair, adjacents.at(j)); | - | ||||||||||||||||||
| 1102 | } | - | ||||||||||||||||||
| 1103 | - | |||||||||||||||||||
| 1104 | - | |||||||||||||||||||
| 1105 | - | |||||||||||||||||||
| 1106 | if (pair->m_item == q) { | - | ||||||||||||||||||
| 1107 | AnchorVertex *layoutVertex = first->m_item == q ? first : second; | - | ||||||||||||||||||
| 1108 | ((!(layoutVertex->m_item == q)) ? qt_assert("layoutVertex->m_item == q",__FILE__,13411349) : qt_noop()); | - | ||||||||||||||||||
| 1109 | changeLayoutVertex(orientation, pair, layoutVertex); | - | ||||||||||||||||||
| 1110 | } | - | ||||||||||||||||||
| 1111 | - | |||||||||||||||||||
| 1112 | delete pair; | - | ||||||||||||||||||
| 1113 | } | - | ||||||||||||||||||
| 1114 | qDeleteAll(parallelAnchors); | - | ||||||||||||||||||
| 1115 | parallelAnchors.clear(); | - | ||||||||||||||||||
| 1116 | toRestore.clear(); | - | ||||||||||||||||||
| 1117 | } | - | ||||||||||||||||||
| 1118 | - | |||||||||||||||||||
| 1119 | QGraphicsAnchorLayoutPrivate::Orientation | - | ||||||||||||||||||
| 1120 | QGraphicsAnchorLayoutPrivate::edgeOrientation(Qt::AnchorPoint edge) | - | ||||||||||||||||||
| 1121 | { | - | ||||||||||||||||||
| 1122 | return edge > Qt::AnchorRight ? Vertical : Horizontal; | - | ||||||||||||||||||
| 1123 | } | - | ||||||||||||||||||
| 1124 | void QGraphicsAnchorLayoutPrivate::createLayoutEdges() | - | ||||||||||||||||||
| 1125 | { | - | ||||||||||||||||||
| 1126 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1127 | QGraphicsLayoutItem *layout = q; | - | ||||||||||||||||||
| 1128 | - | |||||||||||||||||||
| 1129 | - | |||||||||||||||||||
| 1130 | AnchorData *data = new AnchorData; | - | ||||||||||||||||||
| 1131 | addAnchor_helper(layout, Qt::AnchorLeft, layout, | - | ||||||||||||||||||
| 1132 | Qt::AnchorRight, data); | - | ||||||||||||||||||
| 1133 | data->maxSize = ((1<<24)-1); | - | ||||||||||||||||||
| 1134 | - | |||||||||||||||||||
| 1135 | - | |||||||||||||||||||
| 1136 | layoutFirstVertex[Horizontal] = internalVertex(layout, Qt::AnchorLeft); | - | ||||||||||||||||||
| 1137 | layoutCentralVertex[Horizontal] = 0; | - | ||||||||||||||||||
| 1138 | layoutLastVertex[Horizontal] = internalVertex(layout, Qt::AnchorRight); | - | ||||||||||||||||||
| 1139 | - | |||||||||||||||||||
| 1140 | - | |||||||||||||||||||
| 1141 | data = new AnchorData; | - | ||||||||||||||||||
| 1142 | addAnchor_helper(layout, Qt::AnchorTop, layout, | - | ||||||||||||||||||
| 1143 | Qt::AnchorBottom, data); | - | ||||||||||||||||||
| 1144 | data->maxSize = ((1<<24)-1); | - | ||||||||||||||||||
| 1145 | - | |||||||||||||||||||
| 1146 | - | |||||||||||||||||||
| 1147 | layoutFirstVertex[Vertical] = internalVertex(layout, Qt::AnchorTop); | - | ||||||||||||||||||
| 1148 | layoutCentralVertex[Vertical] = 0; | - | ||||||||||||||||||
| 1149 | layoutLastVertex[Vertical] = internalVertex(layout, Qt::AnchorBottom); | - | ||||||||||||||||||
| 1150 | } | - | ||||||||||||||||||
| 1151 | - | |||||||||||||||||||
| 1152 | void QGraphicsAnchorLayoutPrivate::deleteLayoutEdges() | - | ||||||||||||||||||
| 1153 | { | - | ||||||||||||||||||
| 1154 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1155 | - | |||||||||||||||||||
| 1156 | ((!(!internalVertex(q, Qt::AnchorHorizontalCenter))) ? qt_assert("!internalVertex(q, Qt::AnchorHorizontalCenter)",__FILE__,13991407) : qt_noop()); | - | ||||||||||||||||||
| 1157 | ((!(!internalVertex(q, Qt::AnchorVerticalCenter))) ? qt_assert("!internalVertex(q, Qt::AnchorVerticalCenter)",__FILE__,14001408) : qt_noop()); | - | ||||||||||||||||||
| 1158 | - | |||||||||||||||||||
| 1159 | removeAnchor_helper(internalVertex(q, Qt::AnchorLeft), | - | ||||||||||||||||||
| 1160 | internalVertex(q, Qt::AnchorRight)); | - | ||||||||||||||||||
| 1161 | removeAnchor_helper(internalVertex(q, Qt::AnchorTop), | - | ||||||||||||||||||
| 1162 | internalVertex(q, Qt::AnchorBottom)); | - | ||||||||||||||||||
| 1163 | } | - | ||||||||||||||||||
| 1164 | - | |||||||||||||||||||
| 1165 | void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item) | - | ||||||||||||||||||
| 1166 | { | - | ||||||||||||||||||
| 1167 | items.append(item); | - | ||||||||||||||||||
| 1168 | - | |||||||||||||||||||
| 1169 | - | |||||||||||||||||||
| 1170 | - | |||||||||||||||||||
| 1171 | AnchorData *data = new AnchorData; | - | ||||||||||||||||||
| 1172 | addAnchor_helper(item, Qt::AnchorLeft, item, Qt::AnchorRight, data); | - | ||||||||||||||||||
| 1173 | data->refreshSizeHints(); | - | ||||||||||||||||||
| 1174 | - | |||||||||||||||||||
| 1175 | data = new AnchorData; | - | ||||||||||||||||||
| 1176 | addAnchor_helper(item, Qt::AnchorTop, item, Qt::AnchorBottom, data); | - | ||||||||||||||||||
| 1177 | data->refreshSizeHints(); | - | ||||||||||||||||||
| 1178 | } | - | ||||||||||||||||||
| 1179 | void QGraphicsAnchorLayoutPrivate::createCenterAnchors( | - | ||||||||||||||||||
| 1180 | QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge) | - | ||||||||||||||||||
| 1181 | { | - | ||||||||||||||||||
| 1182 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1183 | - | |||||||||||||||||||
| 1184 | Orientation orientation; | - | ||||||||||||||||||
| 1185 | switch (centerEdge) { | - | ||||||||||||||||||
| 1186 | case Qt::AnchorHorizontalCenter: | - | ||||||||||||||||||
| 1187 | orientation = Horizontal; | - | ||||||||||||||||||
| 1188 | break; | - | ||||||||||||||||||
| 1189 | case Qt::AnchorVerticalCenter: | - | ||||||||||||||||||
| 1190 | orientation = Vertical; | - | ||||||||||||||||||
| 1191 | break; | - | ||||||||||||||||||
| 1192 | default: | - | ||||||||||||||||||
| 1193 | - | |||||||||||||||||||
| 1194 | return; | - | ||||||||||||||||||
| 1195 | } | - | ||||||||||||||||||
| 1196 | - | |||||||||||||||||||
| 1197 | - | |||||||||||||||||||
| 1198 | if (internalVertex(item, centerEdge)) | - | ||||||||||||||||||
| 1199 | return; | - | ||||||||||||||||||
| 1200 | - | |||||||||||||||||||
| 1201 | - | |||||||||||||||||||
| 1202 | Qt::AnchorPoint firstEdge; | - | ||||||||||||||||||
| 1203 | Qt::AnchorPoint lastEdge; | - | ||||||||||||||||||
| 1204 | - | |||||||||||||||||||
| 1205 | if (orientation == Horizontal) { | - | ||||||||||||||||||
| 1206 | firstEdge = Qt::AnchorLeft; | - | ||||||||||||||||||
| 1207 | lastEdge = Qt::AnchorRight; | - | ||||||||||||||||||
| 1208 | } else { | - | ||||||||||||||||||
| 1209 | firstEdge = Qt::AnchorTop; | - | ||||||||||||||||||
| 1210 | lastEdge = Qt::AnchorBottom; | - | ||||||||||||||||||
| 1211 | } | - | ||||||||||||||||||
| 1212 | - | |||||||||||||||||||
| 1213 | AnchorVertex *first = internalVertex(item, firstEdge); | - | ||||||||||||||||||
| 1214 | AnchorVertex *last = internalVertex(item, lastEdge); | - | ||||||||||||||||||
| 1215 | ((!(first && last)) ? qt_assert("first && last",__FILE__,14701478) : qt_noop()); | - | ||||||||||||||||||
| 1216 | - | |||||||||||||||||||
| 1217 | - | |||||||||||||||||||
| 1218 | QSimplexConstraint *c = new QSimplexConstraint; | - | ||||||||||||||||||
| 1219 | - | |||||||||||||||||||
| 1220 | AnchorData *data = new AnchorData; | - | ||||||||||||||||||
| 1221 | c->variables.insert(data, 1.0); | - | ||||||||||||||||||
| 1222 | addAnchor_helper(item, firstEdge, item, centerEdge, data); | - | ||||||||||||||||||
| 1223 | data->isCenterAnchor = true; | - | ||||||||||||||||||
| 1224 | data->dependency = AnchorData::Master; | - | ||||||||||||||||||
| 1225 | data->refreshSizeHints(); | - | ||||||||||||||||||
| 1226 | - | |||||||||||||||||||
| 1227 | data = new AnchorData; | - | ||||||||||||||||||
| 1228 | c->variables.insert(data, -1.0); | - | ||||||||||||||||||
| 1229 | addAnchor_helper(item, centerEdge, item, lastEdge, data); | - | ||||||||||||||||||
| 1230 | data->isCenterAnchor = true; | - | ||||||||||||||||||
| 1231 | data->dependency = AnchorData::Slave; | - | ||||||||||||||||||
| 1232 | data->refreshSizeHints(); | - | ||||||||||||||||||
| 1233 | - | |||||||||||||||||||
| 1234 | itemCenterConstraints[orientation].append(c); | - | ||||||||||||||||||
| 1235 | - | |||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | removeAnchor_helper(first, last); | - | ||||||||||||||||||
| 1238 | - | |||||||||||||||||||
| 1239 | if (item == q) { | - | ||||||||||||||||||
| 1240 | layoutCentralVertex[orientation] = internalVertex(q, centerEdge); | - | ||||||||||||||||||
| 1241 | } | - | ||||||||||||||||||
| 1242 | } | - | ||||||||||||||||||
| 1243 | - | |||||||||||||||||||
| 1244 | void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( | - | ||||||||||||||||||
| 1245 | QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge, | - | ||||||||||||||||||
| 1246 | bool substitute) | - | ||||||||||||||||||
| 1247 | { | - | ||||||||||||||||||
| 1248 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1249 | - | |||||||||||||||||||
| 1250 | Orientation orientation; | - | ||||||||||||||||||
| 1251 | switch (centerEdge) { | - | ||||||||||||||||||
| 1252 | case Qt::AnchorHorizontalCenter: | - | ||||||||||||||||||
| 1253 | orientation = Horizontal; | - | ||||||||||||||||||
| 1254 | break; | - | ||||||||||||||||||
| 1255 | case Qt::AnchorVerticalCenter: | - | ||||||||||||||||||
| 1256 | orientation = Vertical; | - | ||||||||||||||||||
| 1257 | break; | - | ||||||||||||||||||
| 1258 | default: | - | ||||||||||||||||||
| 1259 | - | |||||||||||||||||||
| 1260 | return; | - | ||||||||||||||||||
| 1261 | } | - | ||||||||||||||||||
| 1262 | - | |||||||||||||||||||
| 1263 | - | |||||||||||||||||||
| 1264 | Qt::AnchorPoint firstEdge; | - | ||||||||||||||||||
| 1265 | Qt::AnchorPoint lastEdge; | - | ||||||||||||||||||
| 1266 | - | |||||||||||||||||||
| 1267 | if (orientation == Horizontal) { | - | ||||||||||||||||||
| 1268 | firstEdge = Qt::AnchorLeft; | - | ||||||||||||||||||
| 1269 | lastEdge = Qt::AnchorRight; | - | ||||||||||||||||||
| 1270 | } else { | - | ||||||||||||||||||
| 1271 | firstEdge = Qt::AnchorTop; | - | ||||||||||||||||||
| 1272 | lastEdge = Qt::AnchorBottom; | - | ||||||||||||||||||
| 1273 | } | - | ||||||||||||||||||
| 1274 | - | |||||||||||||||||||
| 1275 | AnchorVertex *center = internalVertex(item, centerEdge); | - | ||||||||||||||||||
| 1276 | if (!center) | - | ||||||||||||||||||
| 1277 | return; | - | ||||||||||||||||||
| 1278 | AnchorVertex *first = internalVertex(item, firstEdge); | - | ||||||||||||||||||
| 1279 | - | |||||||||||||||||||
| 1280 | ((!(first)) ? qt_assert("first",__FILE__,15351543) : qt_noop()); | - | ||||||||||||||||||
| 1281 | ((!(center)) ? qt_assert("center",__FILE__,15361544) : qt_noop()); | - | ||||||||||||||||||
| 1282 | - | |||||||||||||||||||
| 1283 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 1284 | - | |||||||||||||||||||
| 1285 | - | |||||||||||||||||||
| 1286 | AnchorData *oldData = g.edgeData(first, center); | - | ||||||||||||||||||
| 1287 | - | |||||||||||||||||||
| 1288 | for (int i = itemCenterConstraints[orientation].count() - 1; i >= 0; --i) { | - | ||||||||||||||||||
| 1289 | if (itemCenterConstraints[orientation].at(i)->variables.contains(oldData)) { | - | ||||||||||||||||||
| 1290 | delete itemCenterConstraints[orientation].takeAt(i); | - | ||||||||||||||||||
| 1291 | break; | - | ||||||||||||||||||
| 1292 | } | - | ||||||||||||||||||
| 1293 | } | - | ||||||||||||||||||
| 1294 | - | |||||||||||||||||||
| 1295 | if (substitute) { | - | ||||||||||||||||||
| 1296 | - | |||||||||||||||||||
| 1297 | AnchorData *data = new AnchorData; | - | ||||||||||||||||||
| 1298 | addAnchor_helper(item, firstEdge, item, lastEdge, data); | - | ||||||||||||||||||
| 1299 | data->refreshSizeHints(); | - | ||||||||||||||||||
| 1300 | - | |||||||||||||||||||
| 1301 | - | |||||||||||||||||||
| 1302 | removeAnchor_helper(first, center); | - | ||||||||||||||||||
| 1303 | removeAnchor_helper(center, internalVertex(item, lastEdge)); | - | ||||||||||||||||||
| 1304 | - | |||||||||||||||||||
| 1305 | } else { | - | ||||||||||||||||||
| 1306 | - | |||||||||||||||||||
| 1307 | - | |||||||||||||||||||
| 1308 | QList<AnchorVertex*> adjacents = g.adjacentVertices(center); | - | ||||||||||||||||||
| 1309 | for (int i = 0; i < adjacents.count(); ++i) { | - | ||||||||||||||||||
| 1310 | AnchorVertex *v = adjacents.at(i); | - | ||||||||||||||||||
| 1311 | if (v->m_item != item) { | - | ||||||||||||||||||
| 1312 | removeAnchor_helper(center, internalVertex(v->m_item, v->m_edge)); | - | ||||||||||||||||||
| 1313 | } | - | ||||||||||||||||||
| 1314 | } | - | ||||||||||||||||||
| 1315 | - | |||||||||||||||||||
| 1316 | - | |||||||||||||||||||
| 1317 | - | |||||||||||||||||||
| 1318 | removeAnchor_helper(first, internalVertex(item, lastEdge)); | - | ||||||||||||||||||
| 1319 | } | - | ||||||||||||||||||
| 1320 | - | |||||||||||||||||||
| 1321 | if (item == q) { | - | ||||||||||||||||||
| 1322 | layoutCentralVertex[orientation] = 0; | - | ||||||||||||||||||
| 1323 | } | - | ||||||||||||||||||
| 1324 | } | - | ||||||||||||||||||
| 1325 | - | |||||||||||||||||||
| 1326 | - | |||||||||||||||||||
| 1327 | void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem *item, | - | ||||||||||||||||||
| 1328 | Orientation orientation) | - | ||||||||||||||||||
| 1329 | { | - | ||||||||||||||||||
| 1330 | - | |||||||||||||||||||
| 1331 | - | |||||||||||||||||||
| 1332 | - | |||||||||||||||||||
| 1333 | - | |||||||||||||||||||
| 1334 | - | |||||||||||||||||||
| 1335 | AnchorVertex *first = internalVertex(item, orientation == Horizontal ? | - | ||||||||||||||||||
| 1336 | Qt::AnchorLeft : | - | ||||||||||||||||||
| 1337 | Qt::AnchorTop); | - | ||||||||||||||||||
| 1338 | AnchorVertex *center = internalVertex(item, orientation == Horizontal ? | - | ||||||||||||||||||
| 1339 | Qt::AnchorHorizontalCenter : | - | ||||||||||||||||||
| 1340 | Qt::AnchorVerticalCenter); | - | ||||||||||||||||||
| 1341 | - | |||||||||||||||||||
| 1342 | - | |||||||||||||||||||
| 1343 | if (!center) | - | ||||||||||||||||||
| 1344 | return; | - | ||||||||||||||||||
| 1345 | - | |||||||||||||||||||
| 1346 | ((!(first)) ? qt_assert("first",__FILE__,16011609) : qt_noop()); | - | ||||||||||||||||||
| 1347 | AnchorData *internalAnchor = graph[orientation].edgeData(first, center); | - | ||||||||||||||||||
| 1348 | - | |||||||||||||||||||
| 1349 | - | |||||||||||||||||||
| 1350 | for (int i = 0; i < itemCenterConstraints[orientation].size(); ++i) { | - | ||||||||||||||||||
| 1351 | if (itemCenterConstraints[orientation].at(i)->variables.contains(internalAnchor)) { | - | ||||||||||||||||||
| 1352 | delete itemCenterConstraints[orientation].takeAt(i); | - | ||||||||||||||||||
| 1353 | break; | - | ||||||||||||||||||
| 1354 | } | - | ||||||||||||||||||
| 1355 | } | - | ||||||||||||||||||
| 1356 | } | - | ||||||||||||||||||
| 1357 | QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem, | - | ||||||||||||||||||
| 1358 | Qt::AnchorPoint firstEdge, | - | ||||||||||||||||||
| 1359 | QGraphicsLayoutItem *secondItem, | - | ||||||||||||||||||
| 1360 | Qt::AnchorPoint secondEdge, | - | ||||||||||||||||||
| 1361 | qreal *spacing) | - | ||||||||||||||||||
| 1362 | { | - | ||||||||||||||||||
| 1363 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1364 | if ((firstItem == 0) || (secondItem == 0)) { | - | ||||||||||||||||||
| 1365 | QMessageLogger(__FILE__, 16331641, __PRETTY_FUNCTION__).warning("QGraphicsAnchorLayout::addAnchor(): " | - | ||||||||||||||||||
| 1366 | "Cannot anchor NULL items"); | - | ||||||||||||||||||
| 1367 | return 0; | - | ||||||||||||||||||
| 1368 | } | - | ||||||||||||||||||
| 1369 | - | |||||||||||||||||||
| 1370 | if (firstItem == secondItem) { | - | ||||||||||||||||||
| 1371 | QMessageLogger(__FILE__, 16391647, __PRETTY_FUNCTION__).warning("QGraphicsAnchorLayout::addAnchor(): " | - | ||||||||||||||||||
| 1372 | "Cannot anchor the item to itself"); | - | ||||||||||||||||||
| 1373 | return 0; | - | ||||||||||||||||||
| 1374 | } | - | ||||||||||||||||||
| 1375 | - | |||||||||||||||||||
| 1376 | if (edgeOrientation(secondEdge) != edgeOrientation(firstEdge)) { | - | ||||||||||||||||||
| 1377 | QMessageLogger(__FILE__, 16451653, __PRETTY_FUNCTION__).warning("QGraphicsAnchorLayout::addAnchor(): " | - | ||||||||||||||||||
| 1378 | "Cannot anchor edges of different orientations"); | - | ||||||||||||||||||
| 1379 | return 0; | - | ||||||||||||||||||
| 1380 | } | - | ||||||||||||||||||
| 1381 | - | |||||||||||||||||||
| 1382 | const QGraphicsLayoutItem *parentWidget = q->parentLayoutItem(); | - | ||||||||||||||||||
| 1383 | if (firstItem == parentWidget || secondItem == parentWidget) { | - | ||||||||||||||||||
| 1384 | QMessageLogger(__FILE__, 16521660, __PRETTY_FUNCTION__).warning("QGraphicsAnchorLayout::addAnchor(): " | - | ||||||||||||||||||
| 1385 | "You cannot add the parent of the layout to the layout."); | - | ||||||||||||||||||
| 1386 | return 0; | - | ||||||||||||||||||
| 1387 | } | - | ||||||||||||||||||
| 1388 | if (firstItem != q && !items.contains(firstItem)) { | - | ||||||||||||||||||
| 1389 | createItemEdges(firstItem); | - | ||||||||||||||||||
| 1390 | addChildLayoutItem(firstItem); | - | ||||||||||||||||||
| 1391 | } | - | ||||||||||||||||||
| 1392 | if (secondItem != q && !items.contains(secondItem)) { | - | ||||||||||||||||||
| 1393 | createItemEdges(secondItem); | - | ||||||||||||||||||
| 1394 | addChildLayoutItem(secondItem); | - | ||||||||||||||||||
| 1395 | } | - | ||||||||||||||||||
| 1396 | - | |||||||||||||||||||
| 1397 | - | |||||||||||||||||||
| 1398 | createCenterAnchors(firstItem, firstEdge); | - | ||||||||||||||||||
| 1399 | createCenterAnchors(secondItem, secondEdge); | - | ||||||||||||||||||
| 1400 | - | |||||||||||||||||||
| 1401 | - | |||||||||||||||||||
| 1402 | correctEdgeDirection(firstItem, firstEdge, secondItem, secondEdge); | - | ||||||||||||||||||
| 1403 | - | |||||||||||||||||||
| 1404 | AnchorData *data = new AnchorData; | - | ||||||||||||||||||
| 1405 | QGraphicsAnchor *graphicsAnchor = acquireGraphicsAnchor(data); | - | ||||||||||||||||||
| 1406 | - | |||||||||||||||||||
| 1407 | addAnchor_helper(firstItem, firstEdge, secondItem, secondEdge, data); | - | ||||||||||||||||||
| 1408 | - | |||||||||||||||||||
| 1409 | if (spacing) { | - | ||||||||||||||||||
| 1410 | graphicsAnchor->setSpacing(*spacing); | - | ||||||||||||||||||
| 1411 | } else { | - | ||||||||||||||||||
| 1412 | if (firstItem == q | - | ||||||||||||||||||
| 1413 | || secondItem == q | - | ||||||||||||||||||
| 1414 | || pickEdge(firstEdge, Horizontal) == Qt::AnchorHorizontalCenter | - | ||||||||||||||||||
| 1415 | || oppositeEdge(firstEdge) != secondEdge) { | - | ||||||||||||||||||
| 1416 | graphicsAnchor->setSpacing(0); | - | ||||||||||||||||||
| 1417 | } else { | - | ||||||||||||||||||
| 1418 | graphicsAnchor->unsetSpacing(); | - | ||||||||||||||||||
| 1419 | } | - | ||||||||||||||||||
| 1420 | } | - | ||||||||||||||||||
| 1421 | - | |||||||||||||||||||
| 1422 | return graphicsAnchor; | - | ||||||||||||||||||
| 1423 | } | - | ||||||||||||||||||
| 1424 | void QGraphicsAnchorLayoutPrivate::addAnchor_helper(QGraphicsLayoutItem *firstItem, | - | ||||||||||||||||||
| 1425 | Qt::AnchorPoint firstEdge, | - | ||||||||||||||||||
| 1426 | QGraphicsLayoutItem *secondItem, | - | ||||||||||||||||||
| 1427 | Qt::AnchorPoint secondEdge, | - | ||||||||||||||||||
| 1428 | AnchorData *data) | - | ||||||||||||||||||
| 1429 | { | - | ||||||||||||||||||
| 1430 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1431 | - | |||||||||||||||||||
| 1432 | const Orientation orientation = edgeOrientation(firstEdge); | - | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | - | |||||||||||||||||||
| 1435 | AnchorVertex *v1 = addInternalVertex(firstItem, firstEdge); | - | ||||||||||||||||||
| 1436 | AnchorVertex *v2 = addInternalVertex(secondItem, secondEdge); | - | ||||||||||||||||||
| 1437 | - | |||||||||||||||||||
| 1438 | - | |||||||||||||||||||
| 1439 | if (graph[orientation].edgeData(v1, v2)) { | - | ||||||||||||||||||
| 1440 | removeAnchor_helper(v1, v2); | - | ||||||||||||||||||
| 1441 | } | - | ||||||||||||||||||
| 1442 | - | |||||||||||||||||||
| 1443 | - | |||||||||||||||||||
| 1444 | if (firstItem == secondItem) | - | ||||||||||||||||||
| 1445 | data->item = firstItem; | - | ||||||||||||||||||
| 1446 | - | |||||||||||||||||||
| 1447 | data->orientation = orientation; | - | ||||||||||||||||||
| 1448 | - | |||||||||||||||||||
| 1449 | - | |||||||||||||||||||
| 1450 | - | |||||||||||||||||||
| 1451 | - | |||||||||||||||||||
| 1452 | data->from = v1; | - | ||||||||||||||||||
| 1453 | data->to = v2; | - | ||||||||||||||||||
| 1454 | - | |||||||||||||||||||
| 1455 | data->name = QString::fromLatin1("%1 --to--> %2").arg(v1->toString()).arg(v2->toString()); | - | ||||||||||||||||||
| 1456 | - | |||||||||||||||||||
| 1457 | - | |||||||||||||||||||
| 1458 | - | |||||||||||||||||||
| 1459 | data->isLayoutAnchor = (data->item == q); | - | ||||||||||||||||||
| 1460 | - | |||||||||||||||||||
| 1461 | graph[orientation].createEdge(v1, v2, data); | - | ||||||||||||||||||
| 1462 | } | - | ||||||||||||||||||
| 1463 | - | |||||||||||||||||||
| 1464 | QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::getAnchor(QGraphicsLayoutItem *firstItem, | - | ||||||||||||||||||
| 1465 | Qt::AnchorPoint firstEdge, | - | ||||||||||||||||||
| 1466 | QGraphicsLayoutItem *secondItem, | - | ||||||||||||||||||
| 1467 | Qt::AnchorPoint secondEdge) | - | ||||||||||||||||||
| 1468 | { | - | ||||||||||||||||||
| 1469 | - | |||||||||||||||||||
| 1470 | if (firstItem == secondItem) | - | ||||||||||||||||||
| 1471 | return 0; | - | ||||||||||||||||||
| 1472 | - | |||||||||||||||||||
| 1473 | const Orientation orientation = edgeOrientation(firstEdge); | - | ||||||||||||||||||
| 1474 | AnchorVertex *v1 = internalVertex(firstItem, firstEdge); | - | ||||||||||||||||||
| 1475 | AnchorVertex *v2 = internalVertex(secondItem, secondEdge); | - | ||||||||||||||||||
| 1476 | - | |||||||||||||||||||
| 1477 | QGraphicsAnchor *graphicsAnchor = 0; | - | ||||||||||||||||||
| 1478 | - | |||||||||||||||||||
| 1479 | AnchorData *data = graph[orientation].edgeData(v1, v2); | - | ||||||||||||||||||
| 1480 | if (data) { | - | ||||||||||||||||||
| 1481 | - | |||||||||||||||||||
| 1482 | - | |||||||||||||||||||
| 1483 | - | |||||||||||||||||||
| 1484 | - | |||||||||||||||||||
| 1485 | - | |||||||||||||||||||
| 1486 | - | |||||||||||||||||||
| 1487 | ((!(data->graphicsAnchor)) ? qt_assert("data->graphicsAnchor",__FILE__,17821790) : qt_noop()); | - | ||||||||||||||||||
| 1488 | graphicsAnchor = data->graphicsAnchor; | - | ||||||||||||||||||
| 1489 | } | - | ||||||||||||||||||
| 1490 | return graphicsAnchor; | - | ||||||||||||||||||
| 1491 | } | - | ||||||||||||||||||
| 1492 | - | |||||||||||||||||||
| 1493 | - | |||||||||||||||||||
| 1494 | - | |||||||||||||||||||
| 1495 | - | |||||||||||||||||||
| 1496 | - | |||||||||||||||||||
| 1497 | - | |||||||||||||||||||
| 1498 | - | |||||||||||||||||||
| 1499 | void QGraphicsAnchorLayoutPrivate::removeAnchor(AnchorVertex *firstVertex, | - | ||||||||||||||||||
| 1500 | AnchorVertex *secondVertex) | - | ||||||||||||||||||
| 1501 | { | - | ||||||||||||||||||
| 1502 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1503 | - | |||||||||||||||||||
| 1504 | - | |||||||||||||||||||
| 1505 | QGraphicsLayoutItem *firstItem = firstVertex->m_item; | - | ||||||||||||||||||
| 1506 | QGraphicsLayoutItem *secondItem = secondVertex->m_item; | - | ||||||||||||||||||
| 1507 | - | |||||||||||||||||||
| 1508 | - | |||||||||||||||||||
| 1509 | removeAnchor_helper(firstVertex, secondVertex); | - | ||||||||||||||||||
| 1510 | - | |||||||||||||||||||
| 1511 | - | |||||||||||||||||||
| 1512 | firstVertex = secondVertex = 0; | - | ||||||||||||||||||
| 1513 | - | |||||||||||||||||||
| 1514 | - | |||||||||||||||||||
| 1515 | bool keepFirstItem = false; | - | ||||||||||||||||||
| 1516 | bool keepSecondItem = false; | - | ||||||||||||||||||
| 1517 | - | |||||||||||||||||||
| 1518 | QPair<AnchorVertex *, int> v; | - | ||||||||||||||||||
| 1519 | int refcount = -1; | - | ||||||||||||||||||
| 1520 | - | |||||||||||||||||||
| 1521 | if (firstItem != q) { | - | ||||||||||||||||||
| 1522 | for (int i = Qt::AnchorLeft; i <= Qt::AnchorBottom; ++i) { | - | ||||||||||||||||||
| 1523 | v = m_vertexList.value(qMakePair(firstItem, static_cast<Qt::AnchorPoint>(i))); | - | ||||||||||||||||||
| 1524 | if (v.first) { | - | ||||||||||||||||||
| 1525 | if (i == Qt::AnchorHorizontalCenter || i == Qt::AnchorVerticalCenter) | - | ||||||||||||||||||
| 1526 | refcount = 2; | - | ||||||||||||||||||
| 1527 | else | - | ||||||||||||||||||
| 1528 | refcount = 1; | - | ||||||||||||||||||
| 1529 | - | |||||||||||||||||||
| 1530 | if (v.second > refcount) { | - | ||||||||||||||||||
| 1531 | keepFirstItem = true; | - | ||||||||||||||||||
| 1532 | break; | - | ||||||||||||||||||
| 1533 | } | - | ||||||||||||||||||
| 1534 | } | - | ||||||||||||||||||
| 1535 | } | - | ||||||||||||||||||
| 1536 | } else | - | ||||||||||||||||||
| 1537 | keepFirstItem = true; | - | ||||||||||||||||||
| 1538 | - | |||||||||||||||||||
| 1539 | if (secondItem != q) { | - | ||||||||||||||||||
| 1540 | for (int i = Qt::AnchorLeft; i <= Qt::AnchorBottom; ++i) { | - | ||||||||||||||||||
| 1541 | v = m_vertexList.value(qMakePair(secondItem, static_cast<Qt::AnchorPoint>(i))); | - | ||||||||||||||||||
| 1542 | if (v.first) { | - | ||||||||||||||||||
| 1543 | if (i == Qt::AnchorHorizontalCenter || i == Qt::AnchorVerticalCenter) | - | ||||||||||||||||||
| 1544 | refcount = 2; | - | ||||||||||||||||||
| 1545 | else | - | ||||||||||||||||||
| 1546 | refcount = 1; | - | ||||||||||||||||||
| 1547 | - | |||||||||||||||||||
| 1548 | if (v.second > refcount) { | - | ||||||||||||||||||
| 1549 | keepSecondItem = true; | - | ||||||||||||||||||
| 1550 | break; | - | ||||||||||||||||||
| 1551 | } | - | ||||||||||||||||||
| 1552 | } | - | ||||||||||||||||||
| 1553 | } | - | ||||||||||||||||||
| 1554 | } else | - | ||||||||||||||||||
| 1555 | keepSecondItem = true; | - | ||||||||||||||||||
| 1556 | - | |||||||||||||||||||
| 1557 | if (!keepFirstItem) | - | ||||||||||||||||||
| 1558 | q->removeAt(items.indexOf(firstItem)); | - | ||||||||||||||||||
| 1559 | - | |||||||||||||||||||
| 1560 | if (!keepSecondItem) | - | ||||||||||||||||||
| 1561 | q->removeAt(items.indexOf(secondItem)); | - | ||||||||||||||||||
| 1562 | - | |||||||||||||||||||
| 1563 | - | |||||||||||||||||||
| 1564 | q->invalidate(); | - | ||||||||||||||||||
| 1565 | } | - | ||||||||||||||||||
| 1566 | - | |||||||||||||||||||
| 1567 | - | |||||||||||||||||||
| 1568 | - | |||||||||||||||||||
| 1569 | - | |||||||||||||||||||
| 1570 | - | |||||||||||||||||||
| 1571 | - | |||||||||||||||||||
| 1572 | - | |||||||||||||||||||
| 1573 | void QGraphicsAnchorLayoutPrivate::removeAnchor_helper(AnchorVertex *v1, AnchorVertex *v2) | - | ||||||||||||||||||
| 1574 | { | - | ||||||||||||||||||
| 1575 | ((!(v1 && v2)) ? qt_assert("v1 && v2",__FILE__,18701878) : qt_noop()); | - | ||||||||||||||||||
| 1576 | - | |||||||||||||||||||
| 1577 | - | |||||||||||||||||||
| 1578 | const Orientation o = edgeOrientation(v1->m_edge); | - | ||||||||||||||||||
| 1579 | graph[o].removeEdge(v1, v2); | - | ||||||||||||||||||
| 1580 | - | |||||||||||||||||||
| 1581 | - | |||||||||||||||||||
| 1582 | removeInternalVertex(v1->m_item, v1->m_edge); | - | ||||||||||||||||||
| 1583 | removeInternalVertex(v2->m_item, v2->m_edge); | - | ||||||||||||||||||
| 1584 | } | - | ||||||||||||||||||
| 1585 | - | |||||||||||||||||||
| 1586 | AnchorVertex *QGraphicsAnchorLayoutPrivate::addInternalVertex(QGraphicsLayoutItem *item, | - | ||||||||||||||||||
| 1587 | Qt::AnchorPoint edge) | - | ||||||||||||||||||
| 1588 | { | - | ||||||||||||||||||
| 1589 | QPair<QGraphicsLayoutItem *, Qt::AnchorPoint> pair(item, edge); | - | ||||||||||||||||||
| 1590 | QPair<AnchorVertex *, int> v = m_vertexList.value(pair); | - | ||||||||||||||||||
| 1591 | - | |||||||||||||||||||
| 1592 | if (!v.first) { | - | ||||||||||||||||||
| 1593 | ((!(v.second == 0)) ? qt_assert("v.second == 0",__FILE__,18881896) : qt_noop()); | - | ||||||||||||||||||
| 1594 | v.first = new AnchorVertex(item, edge); | - | ||||||||||||||||||
| 1595 | } | - | ||||||||||||||||||
| 1596 | v.second++; | - | ||||||||||||||||||
| 1597 | m_vertexList.insert(pair, v); | - | ||||||||||||||||||
| 1598 | return v.first; | - | ||||||||||||||||||
| 1599 | } | - | ||||||||||||||||||
| 1600 | - | |||||||||||||||||||
| 1601 | - | |||||||||||||||||||
| 1602 | - | |||||||||||||||||||
| 1603 | - | |||||||||||||||||||
| 1604 | - | |||||||||||||||||||
| 1605 | - | |||||||||||||||||||
| 1606 | - | |||||||||||||||||||
| 1607 | void QGraphicsAnchorLayoutPrivate::removeInternalVertex(QGraphicsLayoutItem *item, | - | ||||||||||||||||||
| 1608 | Qt::AnchorPoint edge) | - | ||||||||||||||||||
| 1609 | { | - | ||||||||||||||||||
| 1610 | QPair<QGraphicsLayoutItem *, Qt::AnchorPoint> pair(item, edge); | - | ||||||||||||||||||
| 1611 | QPair<AnchorVertex *, int> v = m_vertexList.value(pair); | - | ||||||||||||||||||
| 1612 | - | |||||||||||||||||||
| 1613 | if (!v.first) { | - | ||||||||||||||||||
| 1614 | QMessageLogger(__FILE__, 19091917, __PRETTY_FUNCTION__).warning("This item with this edge is not in the graph"); | - | ||||||||||||||||||
| 1615 | return; | - | ||||||||||||||||||
| 1616 | } | - | ||||||||||||||||||
| 1617 | - | |||||||||||||||||||
| 1618 | v.second--; | - | ||||||||||||||||||
| 1619 | if (v.second == 0) { | - | ||||||||||||||||||
| 1620 | - | |||||||||||||||||||
| 1621 | m_vertexList.remove(pair); | - | ||||||||||||||||||
| 1622 | delete v.first; | - | ||||||||||||||||||
| 1623 | } else { | - | ||||||||||||||||||
| 1624 | - | |||||||||||||||||||
| 1625 | m_vertexList.insert(pair, v); | - | ||||||||||||||||||
| 1626 | - | |||||||||||||||||||
| 1627 | if ((v.second == 2) && | - | ||||||||||||||||||
| 1628 | ((edge == Qt::AnchorHorizontalCenter) || | - | ||||||||||||||||||
| 1629 | (edge == Qt::AnchorVerticalCenter))) { | - | ||||||||||||||||||
| 1630 | removeCenterAnchors(item, edge, true); | - | ||||||||||||||||||
| 1631 | } | - | ||||||||||||||||||
| 1632 | } | - | ||||||||||||||||||
| 1633 | } | - | ||||||||||||||||||
| 1634 | - | |||||||||||||||||||
| 1635 | void QGraphicsAnchorLayoutPrivate::removeVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge) | - | ||||||||||||||||||
| 1636 | { | - | ||||||||||||||||||
| 1637 | if (AnchorVertex *v = internalVertex(item, edge)
| 0 | ||||||||||||||||||
| 1638 | Graph<AnchorVertex, AnchorData> &g = graph[edgeOrientation(edge)]; | - | ||||||||||||||||||
| 1639 | const QList<AnchorVertex *> allVertices = graph[edgeOrientation(edge)].adjacentVertices(v); | - | ||||||||||||||||||
| 1640 | AnchorVertex *v2; | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(allVertices)>::type> _container_((allVertices)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (v2 =auto *_container_.i; _container_.control; _container_.control = 0v2 : allVertices) { | ||||||||||||||||||||
| 1641 | g.removeEdge(v, v2); | - | ||||||||||||||||||
| 1642 | removeInternalVertex(item, edge); | - | ||||||||||||||||||
| 1643 | removeInternalVertex(v2->m_item, v2->m_edge); | - | ||||||||||||||||||
| 1644 | } never executed: end of block | 0 | ||||||||||||||||||
| 1645 | } never executed: end of block | 0 | ||||||||||||||||||
| 1646 | } never executed: end of block | 0 | ||||||||||||||||||
| 1647 | - | |||||||||||||||||||
| 1648 | void QGraphicsAnchorLayoutPrivate::removeAnchors(QGraphicsLayoutItem *item) | - | ||||||||||||||||||
| 1649 | { | - | ||||||||||||||||||
| 1650 | - | |||||||||||||||||||
| 1651 | removeCenterAnchors(item, Qt::AnchorHorizontalCenter, false); | - | ||||||||||||||||||
| 1652 | removeVertex(item, Qt::AnchorLeft); | - | ||||||||||||||||||
| 1653 | removeVertex(item, Qt::AnchorRight); | - | ||||||||||||||||||
| 1654 | - | |||||||||||||||||||
| 1655 | removeCenterAnchors(item, Qt::AnchorVerticalCenter, false); | - | ||||||||||||||||||
| 1656 | removeVertex(item, Qt::AnchorTop); | - | ||||||||||||||||||
| 1657 | removeVertex(item, Qt::AnchorBottom); | - | ||||||||||||||||||
| 1658 | } | - | ||||||||||||||||||
| 1659 | void QGraphicsAnchorLayoutPrivate::correctEdgeDirection(QGraphicsLayoutItem *&firstItem, | - | ||||||||||||||||||
| 1660 | Qt::AnchorPoint &firstEdge, | - | ||||||||||||||||||
| 1661 | QGraphicsLayoutItem *&secondItem, | - | ||||||||||||||||||
| 1662 | Qt::AnchorPoint &secondEdge) | - | ||||||||||||||||||
| 1663 | { | - | ||||||||||||||||||
| 1664 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1665 | - | |||||||||||||||||||
| 1666 | if ((firstItem != q) && (secondItem != q)) { | - | ||||||||||||||||||
| 1667 | - | |||||||||||||||||||
| 1668 | - | |||||||||||||||||||
| 1669 | if (firstEdge < secondEdge) { | - | ||||||||||||||||||
| 1670 | qSwap(firstItem, secondItem); | - | ||||||||||||||||||
| 1671 | qSwap(firstEdge, secondEdge); | - | ||||||||||||||||||
| 1672 | } | - | ||||||||||||||||||
| 1673 | } else if (firstItem == q) { | - | ||||||||||||||||||
| 1674 | - | |||||||||||||||||||
| 1675 | - | |||||||||||||||||||
| 1676 | if ((firstEdge == Qt::AnchorRight) || (firstEdge == Qt::AnchorBottom)) { | - | ||||||||||||||||||
| 1677 | qSwap(firstItem, secondItem); | - | ||||||||||||||||||
| 1678 | qSwap(firstEdge, secondEdge); | - | ||||||||||||||||||
| 1679 | } | - | ||||||||||||||||||
| 1680 | } else if ((secondEdge != Qt::AnchorRight) && (secondEdge != Qt::AnchorBottom)) { | - | ||||||||||||||||||
| 1681 | - | |||||||||||||||||||
| 1682 | - | |||||||||||||||||||
| 1683 | qSwap(firstItem, secondItem); | - | ||||||||||||||||||
| 1684 | qSwap(firstEdge, secondEdge); | - | ||||||||||||||||||
| 1685 | } | - | ||||||||||||||||||
| 1686 | } | - | ||||||||||||||||||
| 1687 | - | |||||||||||||||||||
| 1688 | QLayoutStyleInfo &QGraphicsAnchorLayoutPrivate::styleInfo() const | - | ||||||||||||||||||
| 1689 | { | - | ||||||||||||||||||
| 1690 | if (styleInfoDirty) { | - | ||||||||||||||||||
| 1691 | const QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 1692 | - | |||||||||||||||||||
| 1693 | QWidget *wid = 0; | - | ||||||||||||||||||
| 1694 | - | |||||||||||||||||||
| 1695 | QGraphicsLayoutItem *parent = q->parentLayoutItem(); | - | ||||||||||||||||||
| 1696 | while (parent && parent->isLayout()) { | - | ||||||||||||||||||
| 1697 | parent = parent->parentLayoutItem(); | - | ||||||||||||||||||
| 1698 | } | - | ||||||||||||||||||
| 1699 | QGraphicsWidget *w = 0; | - | ||||||||||||||||||
| 1700 | if (parent) { | - | ||||||||||||||||||
| 1701 | QGraphicsItem *parentItem = parent->graphicsItem(); | - | ||||||||||||||||||
| 1702 | if (parentItem && parentItem->isWidget()) | - | ||||||||||||||||||
| 1703 | w = static_cast<QGraphicsWidget*>(parentItem); | - | ||||||||||||||||||
| 1704 | } | - | ||||||||||||||||||
| 1705 | - | |||||||||||||||||||
| 1706 | QStyle *style = w ? w->style() : QApplication::style(); | - | ||||||||||||||||||
| 1707 | cachedStyleInfo = QLayoutStyleInfo(style, wid); | - | ||||||||||||||||||
| 1708 | cachedStyleInfo.setDefaultSpacing(Qt::Horizontal, spacings[0]); | - | ||||||||||||||||||
| 1709 | cachedStyleInfo.setDefaultSpacing(Qt::Vertical, spacings[1]); | - | ||||||||||||||||||
| 1710 | - | |||||||||||||||||||
| 1711 | styleInfoDirty = false; | - | ||||||||||||||||||
| 1712 | } | - | ||||||||||||||||||
| 1713 | return cachedStyleInfo; | - | ||||||||||||||||||
| 1714 | } | - | ||||||||||||||||||
| 1715 | void QGraphicsAnchorLayoutPrivate::calculateGraphs() | - | ||||||||||||||||||
| 1716 | { | - | ||||||||||||||||||
| 1717 | if (!calculateGraphCacheDirty) | - | ||||||||||||||||||
| 1718 | return; | - | ||||||||||||||||||
| 1719 | calculateGraphs(Horizontal); | - | ||||||||||||||||||
| 1720 | calculateGraphs(Vertical); | - | ||||||||||||||||||
| 1721 | calculateGraphCacheDirty = false; | - | ||||||||||||||||||
| 1722 | } | - | ||||||||||||||||||
| 1723 | - | |||||||||||||||||||
| 1724 | - | |||||||||||||||||||
| 1725 | - | |||||||||||||||||||
| 1726 | QList<AnchorData *> getVariables(const QList<QSimplexConstraint *> &constraints) | - | ||||||||||||||||||
| 1727 | { | - | ||||||||||||||||||
| 1728 | QSet<AnchorData *> variableSet; | - | ||||||||||||||||||
| 1729 | for (int i = 0; i < constraints.count()
| 0 | ||||||||||||||||||
| 1730 | const QSimplexConstraint *c = constraints.at(i); | - | ||||||||||||||||||
| 1731 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(auto it = c->variables.keys())>::type> _container_((cbegin(), end = c->variables.keys())); _container_.control && _container_.icend(); it
| 0 | ||||||||||||||||||
| 1732 | {variableSet+=.insert(static_cast<AnchorData *>(var); never executed: variableSet.insert(static_cast<AnchorData *>(it.key())); | 0 | ||||||||||||||||||
| } never executed: variableSet.insert(static_cast<AnchorData *>(it.key()));never executed: it.key()));variableSet.insert(static_cast<AnchorData *>(it.key()));never executed: variableSet.insert(static_cast<AnchorData *>(it.key())); | ||||||||||||||||||||
| 1733 | } never executed: end of block | 0 | ||||||||||||||||||
| 1734 | return never executed: variableSet.toList();return variableSet.toList();never executed: return variableSet.toList(); | 0 | ||||||||||||||||||
| 1735 | } | - | ||||||||||||||||||
| 1736 | void QGraphicsAnchorLayoutPrivate::calculateGraphs( | - | ||||||||||||||||||
| 1737 | QGraphicsAnchorLayoutPrivate::Orientation orientation) | - | ||||||||||||||||||
| 1738 | { | - | ||||||||||||||||||
| 1739 | - | |||||||||||||||||||
| 1740 | lastCalculationUsedSimplex[orientation] = false; | - | ||||||||||||||||||
| 1741 | - | |||||||||||||||||||
| 1742 | - | |||||||||||||||||||
| 1743 | static bool simplificationEnabled = qEnvironmentVariableIsEmpty("QT_ANCHORLAYOUT_NO_SIMPLIFICATION"); | - | ||||||||||||||||||
| 1744 | - | |||||||||||||||||||
| 1745 | - | |||||||||||||||||||
| 1746 | refreshAllSizeHints(orientation); | - | ||||||||||||||||||
| 1747 | - | |||||||||||||||||||
| 1748 | - | |||||||||||||||||||
| 1749 | if (simplificationEnabled
| 0 | ||||||||||||||||||
| 1750 | QMessageLogger(__FILE__, 21042110, __PRETTY_FUNCTION__).warning("QGraphicsAnchorLayout: anchor setup is not feasible."); | - | ||||||||||||||||||
| 1751 | graphHasConflicts[orientation] = true; | - | ||||||||||||||||||
| 1752 | return; never executed: return; | 0 | ||||||||||||||||||
| 1753 | } | - | ||||||||||||||||||
| 1754 | - | |||||||||||||||||||
| 1755 | - | |||||||||||||||||||
| 1756 | findPaths(orientation); | - | ||||||||||||||||||
| 1757 | - | |||||||||||||||||||
| 1758 | - | |||||||||||||||||||
| 1759 | - | |||||||||||||||||||
| 1760 | constraintsFromPaths(orientation); | - | ||||||||||||||||||
| 1761 | QList<QList<QSimplexConstraint *> >const auto parts = getGraphParts(orientation); | - | ||||||||||||||||||
| QList<QSimplexConstraint *> trunkConstraints = parts.at(0); | ||||||||||||||||||||
| 1762 | - | |||||||||||||||||||
| 1763 | - | |||||||||||||||||||
| 1764 | - | |||||||||||||||||||
| 1765 | - | |||||||||||||||||||
| 1766 | const QList<AnchorData *> trunkVariables = getVariables(parts.trunkConstraints); | - | ||||||||||||||||||
| 1767 | - | |||||||||||||||||||
| 1768 | - | |||||||||||||||||||
| 1769 | - | |||||||||||||||||||
| 1770 | AnchorVertex *v = layoutLastVertex[orientation]; | - | ||||||||||||||||||
| 1771 | GraphPath trunkPath = graphPaths[orientation].value(v); | - | ||||||||||||||||||
| 1772 | - | |||||||||||||||||||
| 1773 | bool feasible = calculateTrunk(orientation, trunkPath, parts.trunkConstraints, trunkVariables); | - | ||||||||||||||||||
| 1774 | - | |||||||||||||||||||
| 1775 | - | |||||||||||||||||||
| 1776 | - | |||||||||||||||||||
| 1777 | - | |||||||||||||||||||
| 1778 | - | |||||||||||||||||||
| 1779 | for (int i = 1; i < parts.count(); ++i) {if (!(feasible
| 0 | ||||||||||||||||||
| break; | ||||||||||||||||||||
QList<QSimplexConstraint *> partConstraints =&& !
| ||||||||||||||||||||
| 1780 | const QList<AnchorData *> partVariables = getVariables(partConstraintsparts.nonTrunkConstraints); | - | ||||||||||||||||||
| 1781 | ((!(!partVariables.isEmpty())) ? qt_assert("!partVariables.isEmpty()",__FILE__,2152) : qt_noop()); | - | ||||||||||||||||||
| 1782 | feasible &= calculateNonTrunk(partConstraintsparts.nonTrunkConstraints, partVariables); | - | ||||||||||||||||||
| 1783 | } never executed: end of block | 0 | ||||||||||||||||||
| 1784 | - | |||||||||||||||||||
| 1785 | - | |||||||||||||||||||
| 1786 | - | |||||||||||||||||||
| 1787 | updateAnchorSizes(orientation); | - | ||||||||||||||||||
| 1788 | - | |||||||||||||||||||
| 1789 | graphHasConflicts[orientation] = !feasible; | - | ||||||||||||||||||
| 1790 | - | |||||||||||||||||||
| 1791 | - | |||||||||||||||||||
| 1792 | - | |||||||||||||||||||
| 1793 | qDeleteAll(constraints[orientation]); | - | ||||||||||||||||||
| 1794 | constraints[orientation].clear(); | - | ||||||||||||||||||
| 1795 | graphPaths[orientation].clear(); | - | ||||||||||||||||||
| 1796 | - | |||||||||||||||||||
| 1797 | if (simplificationEnabled
| 0 | ||||||||||||||||||
| 1798 | restoreSimplifiedGraph(orientation); never executed: restoreSimplifiedGraph(orientation); | 0 | ||||||||||||||||||
| 1799 | } never executed: end of block | 0 | ||||||||||||||||||
| 1800 | static void shiftConstraints(const QList<QSimplexConstraint *> &constraints, qreal amount) | - | ||||||||||||||||||
| 1801 | { | - | ||||||||||||||||||
| 1802 | for (int i = 0; i < constraints.count()
| 0 | ||||||||||||||||||
| 1803 | QSimplexConstraint *c = constraints.at(i); | - | ||||||||||||||||||
| 1804 | const qreal multiplier = 0; | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivatestd::remove_reference<decltypeaccumulate(c->variables)>::type> _container_((.cbegin(), c->variables)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (cend(), qrealv = *_container_.i; _container_.control; _container_.control =(0) { | ||||||||||||||||||||
| multiplier += v; | ||||||||||||||||||||
| })); | ||||||||||||||||||||
| 1805 | c->constant += multiplier * amount; | - | ||||||||||||||||||
| 1806 | } never executed: end of block | 0 | ||||||||||||||||||
| 1807 | } never executed: end of block | 0 | ||||||||||||||||||
| 1808 | - | |||||||||||||||||||
| 1809 | - | |||||||||||||||||||
| 1810 | - | |||||||||||||||||||
| 1811 | - | |||||||||||||||||||
| 1812 | - | |||||||||||||||||||
| 1813 | - | |||||||||||||||||||
| 1814 | - | |||||||||||||||||||
| 1815 | bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const GraphPath &path, | - | ||||||||||||||||||
| 1816 | const QList<QSimplexConstraint *> &constraints, | - | ||||||||||||||||||
| 1817 | const QList<AnchorData *> &variables) | - | ||||||||||||||||||
| 1818 | { | - | ||||||||||||||||||
| 1819 | bool feasible = true; | - | ||||||||||||||||||
| 1820 | bool needsSimplex = !constraints.isEmpty(); | - | ||||||||||||||||||
| 1821 | - | |||||||||||||||||||
| 1822 | - | |||||||||||||||||||
| 1823 | - | |||||||||||||||||||
| 1824 | - | |||||||||||||||||||
| 1825 | - | |||||||||||||||||||
| 1826 | - | |||||||||||||||||||
| 1827 | if (needsSimplex
| 0 | ||||||||||||||||||
| 1828 | - | |||||||||||||||||||
| 1829 | QList<QSimplexConstraint *> sizeHintConstraints = constraintsFromSizeHints(variables); | - | ||||||||||||||||||
| 1830 | QList<QSimplexConstraint *> allConstraints = constraints + sizeHintConstraints; | - | ||||||||||||||||||
| 1831 | - | |||||||||||||||||||
| 1832 | shiftConstraints(allConstraints, g_offset); | - | ||||||||||||||||||
| 1833 | - | |||||||||||||||||||
| 1834 | - | |||||||||||||||||||
| 1835 | qreal min, max; | - | ||||||||||||||||||
| 1836 | feasible = solveMinMax(allConstraints, path, &min, &max); | - | ||||||||||||||||||
| 1837 | - | |||||||||||||||||||
| 1838 | if (feasible
| 0 | ||||||||||||||||||
| 1839 | solvePreferred(constraints, variables); | - | ||||||||||||||||||
| 1840 | - | |||||||||||||||||||
| 1841 | - | |||||||||||||||||||
| 1842 | - | |||||||||||||||||||
| 1843 | qreal pref(0.0); | - | ||||||||||||||||||
| 1844 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(path.positives)>::type> _container_((path.positives)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const AnchorData *ad = *_container_.i; _container_.control; _container_: path.control = 0positives) | - | ||||||||||||||||||
| 1845 | {pref += ad->sizeAtPreferred; never executed: pref += ad->sizeAtPreferred; | 0 | ||||||||||||||||||
| } never executed: pref += ad->sizeAtPreferred; | ||||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(path.negatives)>::type> _container_((path.negatives)); _container_.control && _container_.i != _container_.e never executed: pref += ad->sizeAtPreferred;never executed: ;pref += ad->sizeAtPreferred;never executed: pref += ad->sizeAtPreferred; | ||||||||||||||||||||
| 1846 | ++_container_.i, _container_.control ^= 1)for (const AnchorData *ad = *_container_.i; _container_.control; _container_: path.control = 0negatives) | - | ||||||||||||||||||
| 1847 | {pref -= ad->sizeAtPreferred; never executed: pref -= ad->sizeAtPreferred; | 0 | ||||||||||||||||||
| 1848 | - | |||||||||||||||||||
| 1849 | }sizeHints[orientation][Qt::MinimumSize] = min; | - | ||||||||||||||||||
| 1850 | sizeHints[orientation][Qt::PreferredSize] = pref; | - | ||||||||||||||||||
| 1851 | sizeHints[orientation][Qt::MaximumSize] = max; | - | ||||||||||||||||||
| 1852 | } never executed: end of block | 0 | ||||||||||||||||||
| 1853 | - | |||||||||||||||||||
| 1854 | qDeleteAll(sizeHintConstraints); | - | ||||||||||||||||||
| 1855 | shiftConstraints(constraints, -g_offset); | - | ||||||||||||||||||
| 1856 | - | |||||||||||||||||||
| 1857 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 1858 | - | |||||||||||||||||||
| 1859 | - | |||||||||||||||||||
| 1860 | ((!(path.positives.count() == 1)) ? qt_assert("path.positives.count() == 1",__FILE__,22442239) : qt_noop()); | - | ||||||||||||||||||
| 1861 | ((!(path.negatives.count() == 0)) ? qt_assert("path.negatives.count() == 0",__FILE__,22452240) : qt_noop()); | - | ||||||||||||||||||
| 1862 | - | |||||||||||||||||||
| 1863 | AnchorData *ad = *path.positives.toList()[0];cbegin(); | - | ||||||||||||||||||
| 1864 | ad->sizeAtMinimum = ad->minSize; | - | ||||||||||||||||||
| 1865 | ad->sizeAtPreferred = ad->prefSize; | - | ||||||||||||||||||
| 1866 | ad->sizeAtMaximum = ad->maxSize; | - | ||||||||||||||||||
| 1867 | - | |||||||||||||||||||
| 1868 | sizeHints[orientation][Qt::MinimumSize] = ad->sizeAtMinimum; | - | ||||||||||||||||||
| 1869 | sizeHints[orientation][Qt::PreferredSize] = ad->sizeAtPreferred; | - | ||||||||||||||||||
| 1870 | sizeHints[orientation][Qt::MaximumSize] = ad->sizeAtMaximum; | - | ||||||||||||||||||
| 1871 | } never executed: end of block | 0 | ||||||||||||||||||
| 1872 | - | |||||||||||||||||||
| 1873 | - | |||||||||||||||||||
| 1874 | lastCalculationUsedSimplex[orientation] = needsSimplex; | - | ||||||||||||||||||
| 1875 | - | |||||||||||||||||||
| 1876 | - | |||||||||||||||||||
| 1877 | return never executed: feasible;return feasible;never executed: return feasible; | 0 | ||||||||||||||||||
| 1878 | } | - | ||||||||||||||||||
| 1879 | - | |||||||||||||||||||
| 1880 | - | |||||||||||||||||||
| 1881 | - | |||||||||||||||||||
| 1882 | - | |||||||||||||||||||
| 1883 | bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList<QSimplexConstraint *> &constraints, | - | ||||||||||||||||||
| 1884 | const QList<AnchorData *> &variables) | - | ||||||||||||||||||
| 1885 | { | - | ||||||||||||||||||
| 1886 | shiftConstraints(constraints, g_offset); | - | ||||||||||||||||||
| 1887 | bool feasible = solvePreferred(constraints, variables); | - | ||||||||||||||||||
| 1888 | - | |||||||||||||||||||
| 1889 | if (feasible) { | - | ||||||||||||||||||
| 1890 | - | |||||||||||||||||||
| 1891 | - | |||||||||||||||||||
| 1892 | for (int j = 0; j < variables.count(); ++j) { | - | ||||||||||||||||||
| 1893 | AnchorData *ad = variables.at(j); | - | ||||||||||||||||||
| 1894 | ((!(ad)) ? qt_assert("ad",__FILE__,22782273) : qt_noop()); | - | ||||||||||||||||||
| 1895 | ad->sizeAtMinimum = ad->sizeAtPreferred; | - | ||||||||||||||||||
| 1896 | ad->sizeAtMaximum = ad->sizeAtPreferred; | - | ||||||||||||||||||
| 1897 | } | - | ||||||||||||||||||
| 1898 | } | - | ||||||||||||||||||
| 1899 | - | |||||||||||||||||||
| 1900 | shiftConstraints(constraints, -g_offset); | - | ||||||||||||||||||
| 1901 | return feasible; | - | ||||||||||||||||||
| 1902 | } | - | ||||||||||||||||||
| 1903 | - | |||||||||||||||||||
| 1904 | - | |||||||||||||||||||
| 1905 | - | |||||||||||||||||||
| 1906 | - | |||||||||||||||||||
| 1907 | - | |||||||||||||||||||
| 1908 | - | |||||||||||||||||||
| 1909 | - | |||||||||||||||||||
| 1910 | void QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(Orientation orientation) | - | ||||||||||||||||||
| 1911 | { | - | ||||||||||||||||||
| 1912 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 1913 | QListQVector<QPair<AnchorVertex *, AnchorVertex *> > vertices = g.connections(); | - | ||||||||||||||||||
| 1914 | - | |||||||||||||||||||
| 1915 | QLayoutStyleInfo styleInf = styleInfo(); | - | ||||||||||||||||||
| 1916 | for (int i = 0; i < vertices.count()
| 0 | ||||||||||||||||||
| 1917 | AnchorData *data = g.edgeData(vertices.at(i).first, vertices.at(i).second); | - | ||||||||||||||||||
| 1918 | data->refreshSizeHints(&styleInf); | - | ||||||||||||||||||
| 1919 | } never executed: end of block | 0 | ||||||||||||||||||
| 1920 | } never executed: end of block | 0 | ||||||||||||||||||
| 1921 | void QGraphicsAnchorLayoutPrivate::findPaths(Orientation orientation) | - | ||||||||||||||||||
| 1922 | { | - | ||||||||||||||||||
| 1923 | QQueue<QPair<AnchorVertex *, AnchorVertex *> > queue; | - | ||||||||||||||||||
| 1924 | - | |||||||||||||||||||
| 1925 | QSet<AnchorData *> visited; | - | ||||||||||||||||||
| 1926 | - | |||||||||||||||||||
| 1927 | AnchorVertex *root = layoutFirstVertex[orientation]; | - | ||||||||||||||||||
| 1928 | - | |||||||||||||||||||
| 1929 | graphPaths[orientation].insert(root, GraphPath()); | - | ||||||||||||||||||
| 1930 | - | |||||||||||||||||||
| 1931 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(graph[orientation].const auto adjacentVertices (root))>::type> _container_((= graph[orientation].adjacentVertices(root))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)); | - | ||||||||||||||||||
| 1932 | for (AnchorVertex *v = *_container_.i; _container_.control; _container_.control = 0: adjacentVertices) | - | ||||||||||||||||||
| 1933 | {queue.enqueue(qMakePair(root, v)); never executed: queue.enqueue(qMakePair(root, v)); | 0 | ||||||||||||||||||
| 1934 | - | |||||||||||||||||||
| 1935 | }while(!queue.isEmpty()
| 0 | ||||||||||||||||||
| 1936 | QPair<AnchorVertex *, AnchorVertex *> pair = queue.dequeue(); | - | ||||||||||||||||||
| 1937 | AnchorData *edge = graph[orientation].edgeData(pair.first, pair.second); | - | ||||||||||||||||||
| 1938 | - | |||||||||||||||||||
| 1939 | if (visited.contains(edge)
| 0 | ||||||||||||||||||
| 1940 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1941 | - | |||||||||||||||||||
| 1942 | visited.insert(edge); | - | ||||||||||||||||||
| 1943 | GraphPath current = graphPaths[orientation].value(pair.first); | - | ||||||||||||||||||
| 1944 | - | |||||||||||||||||||
| 1945 | if (edge->from == pair.first
| 0 | ||||||||||||||||||
| 1946 | current.positives.insert(edge); never executed: current.positives.insert(edge); | 0 | ||||||||||||||||||
| 1947 | else | - | ||||||||||||||||||
| 1948 | current.negatives.insert(edge); never executed: current.negatives.insert(edge); | 0 | ||||||||||||||||||
| 1949 | - | |||||||||||||||||||
| 1950 | graphPaths[orientation].insert(pair.second, current); | - | ||||||||||||||||||
| 1951 | - | |||||||||||||||||||
| 1952 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(graph[orientation].const auto adjacentVertices (pair.second))>::type> _container_((= graph[orientation].adjacentVertices(pair.second))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)); | - | ||||||||||||||||||
| 1953 | for (AnchorVertex *v = *_container_.i; _container_.control; _container_.control = 0: adjacentVertices) | - | ||||||||||||||||||
| 1954 | {queue.enqueue(qMakePair(pair.second, v)); never executed: queue.enqueue(qMakePair(pair.second, v)); | 0 | ||||||||||||||||||
| 1955 | }} never executed: end of block | 0 | ||||||||||||||||||
| 1956 | - | |||||||||||||||||||
| 1957 | - | |||||||||||||||||||
| 1958 | - | |||||||||||||||||||
| 1959 | - | |||||||||||||||||||
| 1960 | identifyFloatItems(visited, orientation); | - | ||||||||||||||||||
| 1961 | } never executed: end of block | 0 | ||||||||||||||||||
| 1962 | void QGraphicsAnchorLayoutPrivate::constraintsFromPaths(Orientation orientation) | - | ||||||||||||||||||
| 1963 | { | - | ||||||||||||||||||
| 1964 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(graphPaths[orientation].uniqueKeys())>::type> _container_((const auto vertices = graphPaths[orientation].uniqueKeys())); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)(); | - | ||||||||||||||||||
| 1965 | for (AnchorVertex *vertex = *_container_.i; _container_.control; _container_.control = 0: vertices) { | - | ||||||||||||||||||
| 1966 | int valueCount = graphPaths[orientation].count(vertex); | - | ||||||||||||||||||
| 1967 | if (valueCount == 1
| 0 | ||||||||||||||||||
| 1968 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 1969 | - | |||||||||||||||||||
| 1970 | QList<GraphPath> pathsToVertex = graphPaths[orientation].values(vertex); | - | ||||||||||||||||||
| 1971 | for (int i = 1; i < valueCount
| 0 | ||||||||||||||||||
| 1972 | constraints[orientation] += | - | ||||||||||||||||||
| 1973 | pathsToVertex[0].constraint(pathsToVertex.at(i)); | - | ||||||||||||||||||
| 1974 | } never executed: end of block | 0 | ||||||||||||||||||
| 1975 | } never executed: end of block | 0 | ||||||||||||||||||
| 1976 | } never executed: end of block | 0 | ||||||||||||||||||
| 1977 | - | |||||||||||||||||||
| 1978 | - | |||||||||||||||||||
| 1979 | - | |||||||||||||||||||
| 1980 | - | |||||||||||||||||||
| 1981 | void QGraphicsAnchorLayoutPrivate::updateAnchorSizes(Orientation orientation) | - | ||||||||||||||||||
| 1982 | { | - | ||||||||||||||||||
| 1983 | Graph<AnchorVertex, AnchorData> &g = graph[orientation]; | - | ||||||||||||||||||
| 1984 | const QListQVector<QPair<AnchorVertex *, AnchorVertex *> > &vertices = g.connections(); | - | ||||||||||||||||||
| 1985 | - | |||||||||||||||||||
| 1986 | for (int i = 0; i < vertices.count()
| 0 | ||||||||||||||||||
| 1987 | AnchorData *ad = g.edgeData(vertices.at(i).first, vertices.at(i).second); | - | ||||||||||||||||||
| 1988 | ad->updateChildrenSizes(); | - | ||||||||||||||||||
| 1989 | } never executed: end of block | 0 | ||||||||||||||||||
| 1990 | } never executed: end of block | 0 | ||||||||||||||||||
| 1991 | - | |||||||||||||||||||
| 1992 | - | |||||||||||||||||||
| 1993 | - | |||||||||||||||||||
| 1994 | - | |||||||||||||||||||
| 1995 | - | |||||||||||||||||||
| 1996 | - | |||||||||||||||||||
| 1997 | - | |||||||||||||||||||
| 1998 | QList<QSimplexConstraint *> QGraphicsAnchorLayoutPrivate::constraintsFromSizeHints( | - | ||||||||||||||||||
| 1999 | const QList<AnchorData *> &anchors) | - | ||||||||||||||||||
| 2000 | { | - | ||||||||||||||||||
| 2001 | if (anchors.isEmpty()) | - | ||||||||||||||||||
| 2002 | return QList<QSimplexConstraint *>(); | - | ||||||||||||||||||
| 2003 | - | |||||||||||||||||||
| 2004 | - | |||||||||||||||||||
| 2005 | - | |||||||||||||||||||
| 2006 | Orientation orient = Orientation(anchors.first()->orientation); | - | ||||||||||||||||||
| 2007 | AnchorData *layoutEdge = 0; | - | ||||||||||||||||||
| 2008 | if (layoutCentralVertex[orient]) { | - | ||||||||||||||||||
| 2009 | layoutEdge = graph[orient].edgeData(layoutFirstVertex[orient], layoutCentralVertex[orient]); | - | ||||||||||||||||||
| 2010 | } else { | - | ||||||||||||||||||
| 2011 | layoutEdge = graph[orient].edgeData(layoutFirstVertex[orient], layoutLastVertex[orient]); | - | ||||||||||||||||||
| 2012 | } | - | ||||||||||||||||||
| 2013 | - | |||||||||||||||||||
| 2014 | - | |||||||||||||||||||
| 2015 | - | |||||||||||||||||||
| 2016 | - | |||||||||||||||||||
| 2017 | - | |||||||||||||||||||
| 2018 | const qreal expectedMax = layoutCentralVertex[orient] ? ((1<<24)-1) / 2 : ((1<<24)-1); | - | ||||||||||||||||||
| 2019 | qreal actualMax; | - | ||||||||||||||||||
| 2020 | if (layoutEdge->from == layoutFirstVertex[orient]) { | - | ||||||||||||||||||
| 2021 | actualMax = layoutEdge->maxSize; | - | ||||||||||||||||||
| 2022 | } else { | - | ||||||||||||||||||
| 2023 | actualMax = -layoutEdge->minSize; | - | ||||||||||||||||||
| 2024 | } | - | ||||||||||||||||||
| 2025 | if (actualMax != expectedMax) { | - | ||||||||||||||||||
| 2026 | layoutEdge = 0; | - | ||||||||||||||||||
| 2027 | } | - | ||||||||||||||||||
| 2028 | - | |||||||||||||||||||
| 2029 | - | |||||||||||||||||||
| 2030 | QList<QSimplexConstraint *> anchorConstraints; | - | ||||||||||||||||||
| 2031 | bool unboundedProblem = true; | - | ||||||||||||||||||
| 2032 | for (int i = 0; i < anchors.size(); ++i) { | - | ||||||||||||||||||
| 2033 | AnchorData *ad = anchors.at(i); | - | ||||||||||||||||||
| 2034 | - | |||||||||||||||||||
| 2035 | - | |||||||||||||||||||
| 2036 | - | |||||||||||||||||||
| 2037 | - | |||||||||||||||||||
| 2038 | if (ad->dependency == AnchorData::Slave) | - | ||||||||||||||||||
| 2039 | continue; | - | ||||||||||||||||||
| 2040 | - | |||||||||||||||||||
| 2041 | - | |||||||||||||||||||
| 2042 | - | |||||||||||||||||||
| 2043 | - | |||||||||||||||||||
| 2044 | qreal boundedMin = qBound(-g_offset, ad->minSize, g_offset); | - | ||||||||||||||||||
| 2045 | qreal boundedMax = qBound(-g_offset, ad->maxSize, g_offset); | - | ||||||||||||||||||
| 2046 | - | |||||||||||||||||||
| 2047 | if ((boundedMin == boundedMax) || qFuzzyCompare(boundedMin, boundedMax)) { | - | ||||||||||||||||||
| 2048 | QSimplexConstraint *c = new QSimplexConstraint; | - | ||||||||||||||||||
| 2049 | c->variables.insert(ad, 1.0); | - | ||||||||||||||||||
| 2050 | c->constant = boundedMin; | - | ||||||||||||||||||
| 2051 | c->ratio = QSimplexConstraint::Equal; | - | ||||||||||||||||||
| 2052 | anchorConstraints += c; | - | ||||||||||||||||||
| 2053 | unboundedProblem = false; | - | ||||||||||||||||||
| 2054 | } else { | - | ||||||||||||||||||
| 2055 | QSimplexConstraint *c = new QSimplexConstraint; | - | ||||||||||||||||||
| 2056 | c->variables.insert(ad, 1.0); | - | ||||||||||||||||||
| 2057 | c->constant = boundedMin; | - | ||||||||||||||||||
| 2058 | c->ratio = QSimplexConstraint::MoreOrEqual; | - | ||||||||||||||||||
| 2059 | anchorConstraints += c; | - | ||||||||||||||||||
| 2060 | - | |||||||||||||||||||
| 2061 | - | |||||||||||||||||||
| 2062 | - | |||||||||||||||||||
| 2063 | - | |||||||||||||||||||
| 2064 | if (ad == layoutEdge) | - | ||||||||||||||||||
| 2065 | continue; | - | ||||||||||||||||||
| 2066 | - | |||||||||||||||||||
| 2067 | c = new QSimplexConstraint; | - | ||||||||||||||||||
| 2068 | c->variables.insert(ad, 1.0); | - | ||||||||||||||||||
| 2069 | c->constant = boundedMax; | - | ||||||||||||||||||
| 2070 | c->ratio = QSimplexConstraint::LessOrEqual; | - | ||||||||||||||||||
| 2071 | anchorConstraints += c; | - | ||||||||||||||||||
| 2072 | unboundedProblem = false; | - | ||||||||||||||||||
| 2073 | } | - | ||||||||||||||||||
| 2074 | } | - | ||||||||||||||||||
| 2075 | - | |||||||||||||||||||
| 2076 | - | |||||||||||||||||||
| 2077 | if (unboundedProblem) { | - | ||||||||||||||||||
| 2078 | QSimplexConstraint *c = new QSimplexConstraint; | - | ||||||||||||||||||
| 2079 | c->variables.insert(layoutEdge, 1.0); | - | ||||||||||||||||||
| 2080 | - | |||||||||||||||||||
| 2081 | c->constant = g_offset; | - | ||||||||||||||||||
| 2082 | c->ratio = QSimplexConstraint::LessOrEqual; | - | ||||||||||||||||||
| 2083 | anchorConstraints += c; | - | ||||||||||||||||||
| 2084 | } | - | ||||||||||||||||||
| 2085 | - | |||||||||||||||||||
| 2086 | return anchorConstraints; | - | ||||||||||||||||||
| 2087 | } | - | ||||||||||||||||||
| 2088 | - | |||||||||||||||||||
| 2089 | - | |||||||||||||||||||
| 2090 | - | |||||||||||||||||||
| 2091 | - | |||||||||||||||||||
| QList< QList<QSimplexConstraint *> >QGraphicsAnchorLayoutPrivate::GraphParts | ||||||||||||||||||||
| 2093 | QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) | - | ||||||||||||||||||
| 2094 | { | - | ||||||||||||||||||
| 2095 | GraphParts result; | - | ||||||||||||||||||
| 2096 | - | |||||||||||||||||||
| 2097 | ((!(layoutFirstVertex[orientation] && layoutLastVertex[orientation])) ? qt_assert("layoutFirstVertex[orientation] && layoutLastVertex[orientation]",__FILE__,25022498) : qt_noop()); | - | ||||||||||||||||||
| 2098 | - | |||||||||||||||||||
| 2099 | AnchorData *edgeL1 = 0; | - | ||||||||||||||||||
| 2100 | AnchorData *edgeL2 = 0; | - | ||||||||||||||||||
| 2101 | - | |||||||||||||||||||
| 2102 | - | |||||||||||||||||||
| 2103 | - | |||||||||||||||||||
| 2104 | if (layoutCentralVertex[orientation]
| 0 | ||||||||||||||||||
| 2105 | edgeL1 = graph[orientation].edgeData(layoutFirstVertex[orientation], layoutCentralVertex[orientation]); | - | ||||||||||||||||||
| 2106 | edgeL2 = graph[orientation].edgeData(layoutCentralVertex[orientation], layoutLastVertex[orientation]); | - | ||||||||||||||||||
| 2107 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 2108 | edgeL1 = graph[orientation].edgeData(layoutFirstVertex[orientation], layoutLastVertex[orientation]); | - | ||||||||||||||||||
| 2109 | } never executed: end of block | 0 | ||||||||||||||||||
| 2110 | - | |||||||||||||||||||
| 2111 | QLinkedList<QSimplexConstraint *> remainingConstraints; | - | ||||||||||||||||||
| for (int iresult.nonTrunkConstraints = 0; i < constraints[orientation].count(); ++i) { | ||||||||||||||||||||
| remainingConstraints +=constraints[orientation].at(i); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| for (int i = 0; i < itemCenterConstraints[orientation].count(); ++i) { | ||||||||||||||||||||
| remainingConstraints +=] + itemCenterConstraints[orientation].at(i); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| QList<QSimplexConstraint *> trunkConstraints;]; | ||||||||||||||||||||
| 2112 | - | |||||||||||||||||||
| 2113 | QSet<QSimplexVariable *> trunkVariables; | - | ||||||||||||||||||
| 2114 | - | |||||||||||||||||||
| 2115 | trunkVariables += edgeL1; | - | ||||||||||||||||||
| 2116 | if (edgeL2
| 0 | ||||||||||||||||||
| 2117 | trunkVariables += edgeL2; never executed: trunkVariables += edgeL2; | 0 | ||||||||||||||||||
| 2118 | - | |||||||||||||||||||
| 2119 | bool dirty; | - | ||||||||||||||||||
| 2120 | auto end = result.nonTrunkConstraints.end(); | - | ||||||||||||||||||
| 2121 | do { | - | ||||||||||||||||||
| 2122 | dirty = false; | - | ||||||||||||||||||
| 2123 | - | |||||||||||||||||||
| 2124 | QLinkedList<QSimplexConstraint *>::iterator itauto isMatch = remainingConstraints.begin(); | - | ||||||||||||||||||
| while (it != remainingConstraints.end()) {[&result, &trunkVariables](QSimplexConstraint *c= *it;) -> bool { | ||||||||||||||||||||
| 2125 | bool match = false; | - | ||||||||||||||||||
| 2126 | - | |||||||||||||||||||
| 2127 | - | |||||||||||||||||||
| 2128 | - | |||||||||||||||||||
| 2129 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(trunkVariables)>::type> _container_((trunkVariables)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QSimplexVariable *ad = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 2130 | if (c->variables.contains(ad)
| 0 | ||||||||||||||||||
| 2131 | match = true; | - | ||||||||||||||||||
| 2132 | break; never executed: break; | 0 | ||||||||||||||||||
| 2133 | } | - | ||||||||||||||||||
| 2134 | } never executed: end of block | 0 | ||||||||||||||||||
| 2135 | - | |||||||||||||||||||
| 2136 | - | |||||||||||||||||||
| 2137 | - | |||||||||||||||||||
| 2138 | if (match
| 0 | ||||||||||||||||||
| 2139 | result.trunkConstraints += c; | - | ||||||||||||||||||
| 2140 | trunkVariables += QSet<QSimplexVariable *>::fromListfor (auto jt = c->variables.keys()); | 0 | ||||||||||||||||||
itcbegin(), end = remainingConstraintsc->variables.erasecend(); jt != end
| ||||||||||||||||||||
| 2141 | trunkVariables.insert never executed: trunkVariables.insert(jt.key());never executed: (it);trunkVariables.insert(jt.key());never executed: trunkVariables.insert(jt.key()); | 0 | ||||||||||||||||||
| dirty = never executed: trunkVariables.insert(jt.key());never executed: jt.key());trunkVariables.insert(jt.key());never executed: trunkVariables.insert(jt.key()); | ||||||||||||||||||||
| 2142 | return never executed: return true;never executed: return true;never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 2143 | } else { | - | ||||||||||||||||||
| 2144 | ++itreturn never executed: return false;never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 2145 | } | - | ||||||||||||||||||
| }} | ||||||||||||||||||||
| 2146 | while}; | - | ||||||||||||||||||
| 2147 | const auto newEnd = std::remove_if(dirty); | - | ||||||||||||||||||
| QList< QList<QSimplexConstraint *> > result;result+= trunkConstraints; | ||||||||||||||||||||
| if (!remainingConstraints.isEmpty()) { | ||||||||||||||||||||
| QList<QSimplexConstraint *> nonTrunkConstraints;nonTrunkConstraints.reserve(remainingConstraints.size()); | ||||||||||||||||||||
| QLinkedList<QSimplexConstraint *>::iterator it = remainingConstraints.begin(); | ||||||||||||||||||||
| while (it(), end, isMatch); | ||||||||||||||||||||
| 2148 | dirty = newEnd != remainingConstraints.end()) { | - | ||||||||||||||||||
| nonTrunkConstraints += *it; | ||||||||||||||||||||
| 2149 | ++itend = newEnd; | - | ||||||||||||||||||
| 2150 | } never executed: while (dirtyend of block
| 0 | ||||||||||||||||||
| 2151 | - | |||||||||||||||||||
| 2152 | result+=.nonTrunkConstraints; | - | ||||||||||||||||||
| }.erase(end, result.nonTrunkConstraints.end()); | ||||||||||||||||||||
| 2153 | - | |||||||||||||||||||
| 2154 | return never executed: result;return result;never executed: return result; | 0 | ||||||||||||||||||
| 2155 | } | - | ||||||||||||||||||
| 2156 | - | |||||||||||||||||||
| 2157 | - | |||||||||||||||||||
| 2158 | - | |||||||||||||||||||
| 2159 | - | |||||||||||||||||||
| 2160 | - | |||||||||||||||||||
| 2161 | - | |||||||||||||||||||
| 2162 | void QGraphicsAnchorLayoutPrivate::identifyFloatItems(const QSet<AnchorData *> &visited, Orientation orientation) | - | ||||||||||||||||||
| 2163 | { | - | ||||||||||||||||||
| 2164 | QSet<QGraphicsLayoutItem *> nonFloating; | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(visited)>::type> _container_((visited)); _container_.control && _container_.i != _container_.e; | ||||||||||||||||||||
| 2165 | - | |||||||||||||||||||
| 2166 | ++_container_.i, _container_.control ^= 1)for (const AnchorData *ad = *_container_.i; _container_.control; _container_.control = 0: visited) | - | ||||||||||||||||||
| 2167 | identifyNonFloatItems_helper(ad, &nonFloating); never executed: identifyNonFloatItems_helper(ad, &nonFloating); | 0 | ||||||||||||||||||
| 2168 | - | |||||||||||||||||||
| 2169 | QSet<QGraphicsLayoutItem *> allItems; | - | ||||||||||||||||||
| 2170 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(items)>::type> _container_((items)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsLayoutItem *item = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||||||||
| 2171 | allItems.insert(item); never executed: allItems.insert(item); | 0 | ||||||||||||||||||
| 2172 | m_floatItems[orientation] = allItems - nonFloating; | - | ||||||||||||||||||
| 2173 | } never executed: end of block | 0 | ||||||||||||||||||
| 2174 | void QGraphicsAnchorLayoutPrivate::identifyNonFloatItems_helper(const AnchorData *ad, QSet<QGraphicsLayoutItem *> *nonFloatingItemsIdentifiedSoFar) | - | ||||||||||||||||||
| 2175 | { | - | ||||||||||||||||||
| 2176 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 2177 | - | |||||||||||||||||||
| 2178 | switch(ad->type) { | - | ||||||||||||||||||
| 2179 | case AnchorData::Normal: | - | ||||||||||||||||||
| 2180 | if (ad->item && ad->item != q) | - | ||||||||||||||||||
| 2181 | nonFloatingItemsIdentifiedSoFar->insert(ad->item); | - | ||||||||||||||||||
| 2182 | break; | - | ||||||||||||||||||
| 2183 | case AnchorData::Sequential: | - | ||||||||||||||||||
| 2184 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(static_cast<const SequentialAnchorData *>(ad)->m_edges)>::type> _container_((static_cast<const SequentialAnchorData *>(ad)->m_edges)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const AnchorData *d = *_container_.i; _container_.control; _container_.control = 0) | - | ||||||||||||||||||
| 2185 | identifyNonFloatItems_helper(d, nonFloatingItemsIdentifiedSoFar); | - | ||||||||||||||||||
| 2186 | break; | - | ||||||||||||||||||
| 2187 | case AnchorData::Parallel: | - | ||||||||||||||||||
| 2188 | identifyNonFloatItems_helper(static_cast<const ParallelAnchorData *>(ad)->firstEdge, nonFloatingItemsIdentifiedSoFar); | - | ||||||||||||||||||
| 2189 | identifyNonFloatItems_helper(static_cast<const ParallelAnchorData *>(ad)->secondEdge, nonFloatingItemsIdentifiedSoFar); | - | ||||||||||||||||||
| 2190 | break; | - | ||||||||||||||||||
| 2191 | } | - | ||||||||||||||||||
| 2192 | } | - | ||||||||||||||||||
| 2193 | - | |||||||||||||||||||
| 2194 | - | |||||||||||||||||||
| 2195 | - | |||||||||||||||||||
| 2196 | - | |||||||||||||||||||
| 2197 | - | |||||||||||||||||||
| 2198 | - | |||||||||||||||||||
| 2199 | - | |||||||||||||||||||
| 2200 | void QGraphicsAnchorLayoutPrivate::setItemsGeometries(const QRectF &geom) | - | ||||||||||||||||||
| 2201 | { | - | ||||||||||||||||||
| 2202 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 2203 | AnchorVertex *firstH, *secondH, *firstV, *secondV; | - | ||||||||||||||||||
| 2204 | - | |||||||||||||||||||
| 2205 | qreal top; | - | ||||||||||||||||||
| 2206 | qreal left; | - | ||||||||||||||||||
| 2207 | qreal right; | - | ||||||||||||||||||
| 2208 | - | |||||||||||||||||||
| 2209 | q->getContentsMargins(&left, &top, &right, 0); | - | ||||||||||||||||||
| 2210 | const Qt::LayoutDirection visualDir = visualDirection(); | - | ||||||||||||||||||
| 2211 | if (visualDir == Qt::RightToLeft) | - | ||||||||||||||||||
| 2212 | qSwap(left, right); | - | ||||||||||||||||||
| 2213 | - | |||||||||||||||||||
| 2214 | left += geom.left(); | - | ||||||||||||||||||
| 2215 | top += geom.top(); | - | ||||||||||||||||||
| 2216 | right = geom.right() - right; | - | ||||||||||||||||||
| 2217 | - | |||||||||||||||||||
| 2218 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(items)>::type> _container_((items)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QGraphicsLayoutItem *item = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 2219 | QRectF newGeom; | - | ||||||||||||||||||
| 2220 | QSizeF itemPreferredSize = item->effectiveSizeHint(Qt::PreferredSize); | - | ||||||||||||||||||
| 2221 | if (m_floatItems[Horizontal].contains(item)) { | - | ||||||||||||||||||
| 2222 | newGeom.setLeft(0); | - | ||||||||||||||||||
| 2223 | newGeom.setRight(itemPreferredSize.width()); | - | ||||||||||||||||||
| 2224 | } else { | - | ||||||||||||||||||
| 2225 | firstH = internalVertex(item, Qt::AnchorLeft); | - | ||||||||||||||||||
| 2226 | secondH = internalVertex(item, Qt::AnchorRight); | - | ||||||||||||||||||
| 2227 | - | |||||||||||||||||||
| 2228 | if (visualDir == Qt::LeftToRight) { | - | ||||||||||||||||||
| 2229 | newGeom.setLeft(left + firstH->distance); | - | ||||||||||||||||||
| 2230 | newGeom.setRight(left + secondH->distance); | - | ||||||||||||||||||
| 2231 | } else { | - | ||||||||||||||||||
| 2232 | newGeom.setLeft(right - secondH->distance); | - | ||||||||||||||||||
| 2233 | newGeom.setRight(right - firstH->distance); | - | ||||||||||||||||||
| 2234 | } | - | ||||||||||||||||||
| 2235 | } | - | ||||||||||||||||||
| 2236 | - | |||||||||||||||||||
| 2237 | if (m_floatItems[Vertical].contains(item)) { | - | ||||||||||||||||||
| 2238 | newGeom.setTop(0); | - | ||||||||||||||||||
| 2239 | newGeom.setBottom(itemPreferredSize.height()); | - | ||||||||||||||||||
| 2240 | } else { | - | ||||||||||||||||||
| 2241 | firstV = internalVertex(item, Qt::AnchorTop); | - | ||||||||||||||||||
| 2242 | secondV = internalVertex(item, Qt::AnchorBottom); | - | ||||||||||||||||||
| 2243 | - | |||||||||||||||||||
| 2244 | newGeom.setTop(top + firstV->distance); | - | ||||||||||||||||||
| 2245 | newGeom.setBottom(top + secondV->distance); | - | ||||||||||||||||||
| 2246 | } | - | ||||||||||||||||||
| 2247 | - | |||||||||||||||||||
| 2248 | item->setGeometry(newGeom); | - | ||||||||||||||||||
| 2249 | } | - | ||||||||||||||||||
| 2250 | } | - | ||||||||||||||||||
| 2251 | - | |||||||||||||||||||
| 2252 | - | |||||||||||||||||||
| 2253 | - | |||||||||||||||||||
| 2254 | - | |||||||||||||||||||
| 2255 | - | |||||||||||||||||||
| 2256 | - | |||||||||||||||||||
| 2257 | - | |||||||||||||||||||
| 2258 | void QGraphicsAnchorLayoutPrivate::calculateVertexPositions( | - | ||||||||||||||||||
| 2259 | QGraphicsAnchorLayoutPrivate::Orientation orientation) | - | ||||||||||||||||||
| 2260 | { | - | ||||||||||||||||||
| 2261 | QQueue<QPair<AnchorVertex *, AnchorVertex *> > queue; | - | ||||||||||||||||||
| 2262 | QSet<AnchorVertex *> visited; | - | ||||||||||||||||||
| 2263 | - | |||||||||||||||||||
| 2264 | - | |||||||||||||||||||
| 2265 | AnchorVertex *root = layoutFirstVertex[orientation]; | - | ||||||||||||||||||
| 2266 | - | |||||||||||||||||||
| 2267 | root->distance = 0; | - | ||||||||||||||||||
| 2268 | visited.insert(root); | - | ||||||||||||||||||
| 2269 | - | |||||||||||||||||||
| 2270 | - | |||||||||||||||||||
| 2271 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(graph[orientation].const auto adjacentVertices (root))>::type> _container_((= graph[orientation].adjacentVertices(root))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)); | - | ||||||||||||||||||
| 2272 | for (AnchorVertex *v = *_container_.i; _container_.control; _container_.control = 0: adjacentVertices) | - | ||||||||||||||||||
| 2273 | {queue.enqueue(qMakePair(root, v)); never executed: queue.enqueue(qMakePair(root, v)); | 0 | ||||||||||||||||||
| 2274 | - | |||||||||||||||||||
| 2275 | - | |||||||||||||||||||
| 2276 | }setupEdgesInterpolation(orientation); | - | ||||||||||||||||||
| 2277 | - | |||||||||||||||||||
| 2278 | - | |||||||||||||||||||
| 2279 | while (!queue.isEmpty()
| 0 | ||||||||||||||||||
| 2280 | QPair<AnchorVertex *, AnchorVertex *> pair = queue.dequeue(); | - | ||||||||||||||||||
| 2281 | AnchorData *edge = graph[orientation].edgeData(pair.first, pair.second); | - | ||||||||||||||||||
| 2282 | - | |||||||||||||||||||
| 2283 | if (visited.contains(pair.second)
| 0 | ||||||||||||||||||
| 2284 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 2285 | - | |||||||||||||||||||
| 2286 | visited.insert(pair.second); | - | ||||||||||||||||||
| 2287 | interpolateEdge(pair.first, edge); | - | ||||||||||||||||||
| 2288 | - | |||||||||||||||||||
| 2289 | QList<AnchorVertex *> adjacents = graph[orientation].adjacentVertices(pair.second); | - | ||||||||||||||||||
| 2290 | for (int i = 0; i < adjacents.count()
| 0 | ||||||||||||||||||
| 2291 | if (!visited.contains(adjacents.at(i))
| 0 | ||||||||||||||||||
| 2292 | queue.enqueue(qMakePair(pair.second, adjacents.at(i))); never executed: queue.enqueue(qMakePair(pair.second, adjacents.at(i))); | 0 | ||||||||||||||||||
| 2293 | } never executed: end of block | 0 | ||||||||||||||||||
| 2294 | } never executed: end of block | 0 | ||||||||||||||||||
| 2295 | } never executed: end of block | 0 | ||||||||||||||||||
| 2296 | void QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation( | - | ||||||||||||||||||
| 2297 | Orientation orientation) | - | ||||||||||||||||||
| 2298 | { | - | ||||||||||||||||||
| 2299 | QGraphicsAnchorLayout * const q = q_func(); | - | ||||||||||||||||||
| 2300 | - | |||||||||||||||||||
| 2301 | qreal current; | - | ||||||||||||||||||
| 2302 | current = (orientation == Horizontal) ? q->contentsRect().width() : q->contentsRect().height(); | - | ||||||||||||||||||
| 2303 | - | |||||||||||||||||||
| 2304 | QPair<Interval, qreal> result; | - | ||||||||||||||||||
| 2305 | result = getFactor(current, | - | ||||||||||||||||||
| 2306 | sizeHints[orientation][Qt::MinimumSize], | - | ||||||||||||||||||
| 2307 | sizeHints[orientation][Qt::PreferredSize], | - | ||||||||||||||||||
| 2308 | sizeHints[orientation][Qt::PreferredSize], | - | ||||||||||||||||||
| 2309 | sizeHints[orientation][Qt::PreferredSize], | - | ||||||||||||||||||
| 2310 | sizeHints[orientation][Qt::MaximumSize]); | - | ||||||||||||||||||
| 2311 | - | |||||||||||||||||||
| 2312 | interpolationInterval[orientation] = result.first; | - | ||||||||||||||||||
| 2313 | interpolationProgress[orientation] = result.second; | - | ||||||||||||||||||
| 2314 | } | - | ||||||||||||||||||
| 2315 | void QGraphicsAnchorLayoutPrivate::interpolateEdge(AnchorVertex *base, AnchorData *edge) | - | ||||||||||||||||||
| 2316 | { | - | ||||||||||||||||||
| 2317 | const Orientation orientation = Orientation(edge->orientation); | - | ||||||||||||||||||
| 2318 | const QPair<Interval, qreal> factor(interpolationInterval[orientation], | - | ||||||||||||||||||
| 2319 | interpolationProgress[orientation]); | - | ||||||||||||||||||
| 2320 | - | |||||||||||||||||||
| 2321 | qreal edgeDistance = interpolate(factor, edge->sizeAtMinimum, edge->sizeAtPreferred, | - | ||||||||||||||||||
| 2322 | edge->sizeAtPreferred, edge->sizeAtPreferred, | - | ||||||||||||||||||
| 2323 | edge->sizeAtMaximum); | - | ||||||||||||||||||
| 2324 | - | |||||||||||||||||||
| 2325 | ((!(edge->from == base || edge->to == base)) ? qt_assert("edge->from == base || edge->to == base",__FILE__,27882767) : qt_noop()); | - | ||||||||||||||||||
| 2326 | - | |||||||||||||||||||
| 2327 | - | |||||||||||||||||||
| 2328 | if (edge->from == base) { | - | ||||||||||||||||||
| 2329 | edge->to->distance = base->distance + edgeDistance; | - | ||||||||||||||||||
| 2330 | } else { | - | ||||||||||||||||||
| 2331 | edge->from->distance = base->distance - edgeDistance; | - | ||||||||||||||||||
| 2332 | } | - | ||||||||||||||||||
| 2333 | } | - | ||||||||||||||||||
| 2334 | - | |||||||||||||||||||
| 2335 | bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList<QSimplexConstraint *> &constraints, | - | ||||||||||||||||||
| 2336 | const GraphPath path&path, qreal *min, qreal *max) | - | ||||||||||||||||||
| 2337 | { | - | ||||||||||||||||||
| 2338 | QSimplex simplex; | - | ||||||||||||||||||
| 2339 | bool feasible = simplex.setConstraints(constraints); | - | ||||||||||||||||||
| 2340 | if (feasible
| 0 | ||||||||||||||||||
| 2341 | - | |||||||||||||||||||
| 2342 | QSimplexConstraint objective; | - | ||||||||||||||||||
| 2343 | QSet<AnchorData *>::const_iterator iter; | - | ||||||||||||||||||
| 2344 | for (iter = path.positives.constBegin(); iter != path.positives.constEnd()
| 0 | ||||||||||||||||||
| 2345 | objective.variables.insert(*iter, 1.0); never executed: objective.variables.insert(*iter, 1.0); | 0 | ||||||||||||||||||
| 2346 | - | |||||||||||||||||||
| 2347 | for (iter = path.negatives.constBegin(); iter != path.negatives.constEnd()
| 0 | ||||||||||||||||||
| 2348 | objective.variables.insert(*iter, -1.0); never executed: objective.variables.insert(*iter, -1.0); | 0 | ||||||||||||||||||
| 2349 | - | |||||||||||||||||||
| 2350 | const qreal objectiveOffset = (path.positives.count() - path.negatives.count()) * g_offset; | - | ||||||||||||||||||
| 2351 | simplex.setObjective(&objective); | - | ||||||||||||||||||
| 2352 | - | |||||||||||||||||||
| 2353 | - | |||||||||||||||||||
| 2354 | *min = simplex.solveMin() - objectiveOffset; | - | ||||||||||||||||||
| 2355 | - | |||||||||||||||||||
| 2356 | - | |||||||||||||||||||
| 2357 | QList<AnchorData *> variables = getVariables(constraints); | - | ||||||||||||||||||
| 2358 | for (int i = 0; i < variables.size()
| 0 | ||||||||||||||||||
| 2359 | AnchorData *ad = static_cast<AnchorData *>(variables.at(i)); | - | ||||||||||||||||||
| 2360 | ad->sizeAtMinimum = ad->result - g_offset; | - | ||||||||||||||||||
| 2361 | } never executed: end of block | 0 | ||||||||||||||||||
| 2362 | - | |||||||||||||||||||
| 2363 | - | |||||||||||||||||||
| 2364 | *max = simplex.solveMax() - objectiveOffset; | - | ||||||||||||||||||
| 2365 | - | |||||||||||||||||||
| 2366 | - | |||||||||||||||||||
| 2367 | for (int i = 0; i < variables.size()
| 0 | ||||||||||||||||||
| 2368 | AnchorData *ad = static_cast<AnchorData *>(variables.at(i)); | - | ||||||||||||||||||
| 2369 | ad->sizeAtMaximum = ad->result - g_offset; | - | ||||||||||||||||||
| 2370 | } never executed: end of block | 0 | ||||||||||||||||||
| 2371 | } never executed: end of block | 0 | ||||||||||||||||||
| 2372 | return never executed: feasible;return feasible;never executed: return feasible; | 0 | ||||||||||||||||||
| 2373 | } | - | ||||||||||||||||||
| 2374 | - | |||||||||||||||||||
| 2375 | enum slackType { Grower = -1, Shrinker = 1 }; | - | ||||||||||||||||||
| 2376 | static QPair<QSimplexVariable *, QSimplexConstraint *> createSlack(QSimplexConstraint *sizeConstraint, | - | ||||||||||||||||||
| 2377 | qreal interval, slackType type) | - | ||||||||||||||||||
| 2378 | { | - | ||||||||||||||||||
| 2379 | QSimplexVariable *slack = new QSimplexVariable; | - | ||||||||||||||||||
| 2380 | sizeConstraint->variables.insert(slack, type); | - | ||||||||||||||||||
| 2381 | - | |||||||||||||||||||
| 2382 | QSimplexConstraint *limit = new QSimplexConstraint; | - | ||||||||||||||||||
| 2383 | limit->variables.insert(slack, 1.0); | - | ||||||||||||||||||
| 2384 | limit->ratio = QSimplexConstraint::LessOrEqual; | - | ||||||||||||||||||
| 2385 | limit->constant = interval; | - | ||||||||||||||||||
| 2386 | - | |||||||||||||||||||
| 2387 | return qMakePair(slack, limit); | - | ||||||||||||||||||
| 2388 | } | - | ||||||||||||||||||
| 2389 | - | |||||||||||||||||||
| 2390 | bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QList<QSimplexConstraint *> &constraints, | - | ||||||||||||||||||
| 2391 | const QList<AnchorData *> &variables) | - | ||||||||||||||||||
| 2392 | { | - | ||||||||||||||||||
| 2393 | QList<QSimplexConstraint *> preferredConstraints; | - | ||||||||||||||||||
| 2394 | QList<QSimplexVariable *> preferredVariables; | - | ||||||||||||||||||
| 2395 | QSimplexConstraint objective; | - | ||||||||||||||||||
| 2396 | for (int i = 0; i < variables.size(); ++i) { | - | ||||||||||||||||||
| 2397 | AnchorData *ad = variables.at(i); | - | ||||||||||||||||||
| 2398 | - | |||||||||||||||||||
| 2399 | - | |||||||||||||||||||
| 2400 | if (ad->isLayoutAnchor) | - | ||||||||||||||||||
| 2401 | continue; | - | ||||||||||||||||||
| 2402 | - | |||||||||||||||||||
| 2403 | - | |||||||||||||||||||
| 2404 | - | |||||||||||||||||||
| 2405 | QSimplexConstraint *sizeConstraint = new QSimplexConstraint; | - | ||||||||||||||||||
| 2406 | preferredConstraints += sizeConstraint; | - | ||||||||||||||||||
| 2407 | sizeConstraint->variables.insert(ad, 1.0); | - | ||||||||||||||||||
| 2408 | sizeConstraint->constant = ad->prefSize + g_offset; | - | ||||||||||||||||||
| 2409 | - | |||||||||||||||||||
| 2410 | - | |||||||||||||||||||
| 2411 | QPair<QSimplexVariable *, QSimplexConstraint *> slack; | - | ||||||||||||||||||
| 2412 | const qreal softShrinkInterval = ad->prefSize - ad->minPrefSize; | - | ||||||||||||||||||
| 2413 | if (softShrinkInterval) { | - | ||||||||||||||||||
| 2414 | slack = createSlack(sizeConstraint, softShrinkInterval, Shrinker); | - | ||||||||||||||||||
| 2415 | preferredVariables += slack.first; | - | ||||||||||||||||||
| 2416 | preferredConstraints += slack.second; | - | ||||||||||||||||||
| 2417 | - | |||||||||||||||||||
| 2418 | - | |||||||||||||||||||
| 2419 | objective.variables.insert(slack.first, 1.0); | - | ||||||||||||||||||
| 2420 | } | - | ||||||||||||||||||
| 2421 | - | |||||||||||||||||||
| 2422 | - | |||||||||||||||||||
| 2423 | const qreal softGrowInterval = ad->maxPrefSize - ad->prefSize; | - | ||||||||||||||||||
| 2424 | if (softGrowInterval) { | - | ||||||||||||||||||
| 2425 | slack = createSlack(sizeConstraint, softGrowInterval, Grower); | - | ||||||||||||||||||
| 2426 | preferredVariables += slack.first; | - | ||||||||||||||||||
| 2427 | preferredConstraints += slack.second; | - | ||||||||||||||||||
| 2428 | - | |||||||||||||||||||
| 2429 | - | |||||||||||||||||||
| 2430 | objective.variables.insert(slack.first, 1.0); | - | ||||||||||||||||||
| 2431 | } | - | ||||||||||||||||||
| 2432 | - | |||||||||||||||||||
| 2433 | - | |||||||||||||||||||
| 2434 | const qreal hardShrinkInterval = ad->minPrefSize - ad->minSize; | - | ||||||||||||||||||
| 2435 | if (hardShrinkInterval) { | - | ||||||||||||||||||
| 2436 | slack = createSlack(sizeConstraint, hardShrinkInterval, Shrinker); | - | ||||||||||||||||||
| 2437 | preferredVariables += slack.first; | - | ||||||||||||||||||
| 2438 | preferredConstraints += slack.second; | - | ||||||||||||||||||
| 2439 | - | |||||||||||||||||||
| 2440 | - | |||||||||||||||||||
| 2441 | objective.variables.insert(slack.first, variables.size()); | - | ||||||||||||||||||
| 2442 | } | - | ||||||||||||||||||
| 2443 | - | |||||||||||||||||||
| 2444 | - | |||||||||||||||||||
| 2445 | const qreal hardGrowInterval = ad->maxSize - ad->maxPrefSize; | - | ||||||||||||||||||
| 2446 | if (hardGrowInterval) { | - | ||||||||||||||||||
| 2447 | slack = createSlack(sizeConstraint, hardGrowInterval, Grower); | - | ||||||||||||||||||
| 2448 | preferredVariables += slack.first; | - | ||||||||||||||||||
| 2449 | preferredConstraints += slack.second; | - | ||||||||||||||||||
| 2450 | - | |||||||||||||||||||
| 2451 | - | |||||||||||||||||||
| 2452 | objective.variables.insert(slack.first, variables.size()); | - | ||||||||||||||||||
| 2453 | } | - | ||||||||||||||||||
| 2454 | } | - | ||||||||||||||||||
| 2455 | - | |||||||||||||||||||
| 2456 | QSimplex *simplex = new QSimplex; | - | ||||||||||||||||||
| 2457 | bool feasible = simplex->setConstraints(constraints + preferredConstraints); | - | ||||||||||||||||||
| 2458 | if (feasible) { | - | ||||||||||||||||||
| 2459 | simplex->setObjective(&objective); | - | ||||||||||||||||||
| 2460 | - | |||||||||||||||||||
| 2461 | - | |||||||||||||||||||
| 2462 | simplex->solveMin(); | - | ||||||||||||||||||
| 2463 | - | |||||||||||||||||||
| 2464 | - | |||||||||||||||||||
| 2465 | for (int i = 0; i < variables.size(); ++i) { | - | ||||||||||||||||||
| 2466 | AnchorData *ad = variables.at(i); | - | ||||||||||||||||||
| 2467 | ad->sizeAtPreferred = ad->result - g_offset; | - | ||||||||||||||||||
| 2468 | } | - | ||||||||||||||||||
| 2469 | } | - | ||||||||||||||||||
| 2470 | - | |||||||||||||||||||
| 2471 | - | |||||||||||||||||||
| 2472 | - | |||||||||||||||||||
| 2473 | delete simplex; | - | ||||||||||||||||||
| 2474 | - | |||||||||||||||||||
| 2475 | - | |||||||||||||||||||
| 2476 | qDeleteAll(preferredConstraints); | - | ||||||||||||||||||
| 2477 | qDeleteAll(preferredVariables); | - | ||||||||||||||||||
| 2478 | - | |||||||||||||||||||
| 2479 | return feasible; | - | ||||||||||||||||||
| 2480 | } | - | ||||||||||||||||||
| 2481 | bool QGraphicsAnchorLayoutPrivate::hasConflicts() const | - | ||||||||||||||||||
| 2482 | { | - | ||||||||||||||||||
| 2483 | QGraphicsAnchorLayoutPrivate *that = const_cast<QGraphicsAnchorLayoutPrivate*>(this); | - | ||||||||||||||||||
| 2484 | that->calculateGraphs(); | - | ||||||||||||||||||
| 2485 | - | |||||||||||||||||||
| 2486 | bool floatConflict = !m_floatItems[0].isEmpty() || !m_floatItems[1].isEmpty(); | - | ||||||||||||||||||
| 2487 | - | |||||||||||||||||||
| 2488 | return graphHasConflicts[0] || graphHasConflicts[1] || floatConflict; | - | ||||||||||||||||||
| 2489 | } | - | ||||||||||||||||||
| 2490 | - | |||||||||||||||||||
| 2491 | - | |||||||||||||||||||
| 2492 | void QGraphicsAnchorLayoutPrivate::dumpGraph(const QString &name) | - | ||||||||||||||||||
| 2493 | { | - | ||||||||||||||||||
| 2494 | QFile file(QString::fromLatin1("anchorlayout.%1.dot").arg(name)); | - | ||||||||||||||||||
| 2495 | if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)
| 0 | ||||||||||||||||||
| 2496 | QMessageLogger(__FILE__, 29862965, __PRETTY_FUNCTION__).warning("Could not write to %s"%ls", static_cast<const wchar_t*>(static_cast<const void*>(QString(file.fileName().toLocal8Bit().constData());()).utf16()))); never executed: QMessageLogger(__FILE__, 2965, __PRETTY_FUNCTION__).warning("Could not write to %ls", static_cast<const wchar_t*>(static_cast<const void*>(QString(file.fileName()).utf16()))); | 0 | ||||||||||||||||||
| 2497 | - | |||||||||||||||||||
| 2498 | QString str = QString::fromLatin1("digraph anchorlayout {\nnode [shape=\"rect\"]\n%1}"); | - | ||||||||||||||||||
| 2499 | QString dotContents = graph[0].serializeToDot(); | - | ||||||||||||||||||
| 2500 | dotContents += graph[1].serializeToDot(); | - | ||||||||||||||||||
| 2501 | file.write(str.arg(dotContents).toLocal8Bit()); | - | ||||||||||||||||||
| 2502 | - | |||||||||||||||||||
| 2503 | file.close(); | - | ||||||||||||||||||
| 2504 | } never executed: end of block | 0 | ||||||||||||||||||
| 2505 | - | |||||||||||||||||||
| 2506 | - | |||||||||||||||||||
| 2507 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |