351 Q_DECLARE_PUBLIC(QGraphicsAnchorLayout)
360 MinimumToMinPreferred = 0,
361 MinPreferredToPreferred,
362 PreferredToMaxPreferred,
363 MaxPreferredToMaximum
366 typedef Qt::Orientation Orientation [[deprecated]];
367 [[deprecated]]
static inline constexpr Qt::Orientation Horizontal = Qt::Horizontal;
368 [[deprecated]]
static inline constexpr Qt::Orientation Vertical = Qt::Vertical;
370 QGraphicsAnchorLayoutPrivate();
372 static QGraphicsAnchorLayoutPrivate *get(QGraphicsAnchorLayout *q)
374 return q ? q->d_func() :
nullptr;
377 static Qt::AnchorPoint oppositeEdge(
378 Qt::AnchorPoint edge);
380 static Qt::Orientation edgeOrientation(Qt::AnchorPoint edge)
noexcept;
382 static Qt::AnchorPoint pickEdge(Qt::AnchorPoint edge, Qt::Orientation orientation)
384 if (orientation == Qt::Vertical &&
int(edge) <= 2)
385 return (Qt::AnchorPoint)(edge + 3);
386 else if (orientation == Qt::Horizontal &&
int(edge) >= 3) {
387 return (Qt::AnchorPoint)(edge - 3);
393 void createLayoutEdges();
394 void deleteLayoutEdges();
395 void createItemEdges(QGraphicsLayoutItem *item);
396 void createCenterAnchors(QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge);
397 void removeCenterAnchors(QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge,
bool substitute =
true);
398 void removeCenterConstraints(QGraphicsLayoutItem *item, Qt::Orientation orientation);
400 QGraphicsAnchor *acquireGraphicsAnchor(AnchorData *data)
402 Q_Q(QGraphicsAnchorLayout);
403 if (!data->graphicsAnchor) {
404 data->graphicsAnchor =
new QGraphicsAnchor(q);
405 data->graphicsAnchor->d_func()->data = data;
407 return data->graphicsAnchor;
411 QGraphicsAnchor *addAnchor(QGraphicsLayoutItem *firstItem,
412 Qt::AnchorPoint firstEdge,
413 QGraphicsLayoutItem *secondItem,
414 Qt::AnchorPoint secondEdge,
415 qreal *spacing =
nullptr);
418 void addAnchor_helper(QGraphicsLayoutItem *firstItem,
419 Qt::AnchorPoint firstEdge,
420 QGraphicsLayoutItem *secondItem,
421 Qt::AnchorPoint secondEdge,
424 QGraphicsAnchor *getAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
425 QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
427 void removeAnchor(AnchorVertex *firstVertex, AnchorVertex *secondVertex);
428 void removeAnchor_helper(AnchorVertex *v1, AnchorVertex *v2);
430 void removeAnchors(QGraphicsLayoutItem *item);
432 void removeVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
434 void correctEdgeDirection(QGraphicsLayoutItem *&firstItem,
435 Qt::AnchorPoint &firstEdge,
436 QGraphicsLayoutItem *&secondItem,
437 Qt::AnchorPoint &secondEdge);
439 QLayoutStyleInfo &styleInfo()
const;
441 AnchorData *addAnchorMaybeParallel(AnchorData *newAnchor,
bool *feasible);
444 void calculateGraphs();
445 void calculateGraphs(Qt::Orientation orientation);
448 bool simplifyGraph(Qt::Orientation orientation);
449 bool simplifyVertices(Qt::Orientation orientation);
450 bool simplifyGraphIteration(Qt::Orientation orientation,
bool *feasible);
452 bool replaceVertex(Qt::Orientation orientation, AnchorVertex *oldV,
453 AnchorVertex *newV,
const QList<AnchorData *> &edges);
456 void restoreSimplifiedGraph(Qt::Orientation orientation);
457 void restoreSimplifiedAnchor(AnchorData *edge);
458 void restoreSimplifiedConstraints(ParallelAnchorData *parallel);
459 void restoreVertices(Qt::Orientation orientation);
461 bool calculateTrunk(Qt::Orientation orientation,
const GraphPath &trunkPath,
462 const QList<QSimplexConstraint *> &constraints,
463 const QList<AnchorData *> &variables);
464 bool calculateNonTrunk(
const QList<QSimplexConstraint *> &constraints,
465 const QList<AnchorData *> &variables);
468 void refreshAllSizeHints(Qt::Orientation orientation);
469 void findPaths(Qt::Orientation orientation);
470 void constraintsFromPaths(Qt::Orientation orientation);
471 void updateAnchorSizes(Qt::Orientation orientation);
472 QList<QSimplexConstraint *> constraintsFromSizeHints(
const QList<AnchorData *> &anchors);
474 QList<QSimplexConstraint *> trunkConstraints;
475 QList<QSimplexConstraint *> nonTrunkConstraints;
477 GraphParts getGraphParts(Qt::Orientation orientation);
478 void identifyFloatItems(
const QSet<AnchorData *> &visited, Qt::Orientation orientation);
479 void identifyNonFloatItems_helper(
const AnchorData *ad, QSet<QGraphicsLayoutItem *> *nonFloatingItemsIdentifiedSoFar);
481 inline AnchorVertex *internalVertex(
const std::pair<QGraphicsLayoutItem*, Qt::AnchorPoint> &itemEdge)
const
483 return m_vertexList.value(itemEdge).first;
486 inline AnchorVertex *internalVertex(
const QGraphicsLayoutItem *item, Qt::AnchorPoint edge)
const
488 return internalVertex(std::pair(
const_cast<QGraphicsLayoutItem *>(item), edge));
491 inline void changeLayoutVertex(Qt::Orientation orientation, AnchorVertex *oldV, AnchorVertex *newV)
493 if (layoutFirstVertex[orientation] == oldV)
494 layoutFirstVertex[orientation] = newV;
495 else if (layoutCentralVertex[orientation] == oldV)
496 layoutCentralVertex[orientation] = newV;
497 else if (layoutLastVertex[orientation] == oldV)
498 layoutLastVertex[orientation] = newV;
502 AnchorVertex *addInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
503 void removeInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
506 void setItemsGeometries(
const QRectF &geom);
508 void calculateVertexPositions(Qt::Orientation orientation);
509 void setupEdgesInterpolation(Qt::Orientation orientation);
510 void interpolateEdge(AnchorVertex *base, AnchorData *edge);
513 bool solveMinMax(
const QList<QSimplexConstraint *> &constraints,
514 const GraphPath &path, qreal *min, qreal *max);
515 bool solvePreferred(
const QList<QSimplexConstraint *> &constraints,
516 const QList<AnchorData *> &variables);
517 bool hasConflicts()
const;
520 void dumpGraph(
const QString &name = QString());
524 QHVContainer<qreal> spacings = {-1, -1};
526 QHVContainer<std::array<qreal, 3>> sizeHints = {{-1, -1, -1}, {-1, -1, -1}};
529 QList<QGraphicsLayoutItem *> items;
534 QHash<std::pair<QGraphicsLayoutItem*, Qt::AnchorPoint>, std::pair<AnchorVertex *,
int> > m_vertexList;
537 QHVContainer<Graph<AnchorVertex, AnchorData>> graph;
539 QHVContainer<AnchorVertex *> layoutFirstVertex = {};
540 QHVContainer<AnchorVertex *> layoutCentralVertex = {};
541 QHVContainer<AnchorVertex *> layoutLastVertex = {};
544 QHVContainer<QList<AnchorVertexPair *>> simplifiedVertices;
545 QHVContainer<QList<AnchorData *>> anchorsFromSimplifiedVertices;
548 QHVContainer<QMultiHash<AnchorVertex *, GraphPath>> graphPaths;
549 QHVContainer<QList<QSimplexConstraint *>> constraints;
550 QHVContainer<QList<QSimplexConstraint *>> itemCenterConstraints;
554 QHVContainer<Interval> interpolationInterval;
555 QHVContainer<qreal> interpolationProgress = {-1, -1};
557 QHVContainer<
bool> graphHasConflicts = {};
558 QHVContainer<QSet<QGraphicsLayoutItem *>> m_floatItems;
560#if defined(QT_DEBUG) || defined(QT_BUILD_INTERNAL)
561 QHVContainer<
bool> lastCalculationUsedSimplex;
564 uint calculateGraphCacheDirty : 1;
565 mutable uint styleInfoDirty : 1;
566 mutable QLayoutStyleInfo cachedStyleInfo;
568 friend class QGraphicsAnchorPrivate;