Qt 4.8
Public Functions | Public Variables | List of all members
ParallelAnchorData Struct Reference

#include <qgraphicsanchorlayout_p.h>

Inheritance diagram for ParallelAnchorData:
AnchorData QSimplexVariable

Public Functions

bool calculateSizeHints ()
 
 ParallelAnchorData (AnchorData *first, AnchorData *second)
 
bool secondForward () const
 
virtual void updateChildrenSizes ()
 
- Public Functions inherited from AnchorData
 AnchorData ()
 
void dump (int indent=2)
 
void refreshSizeHints (const QLayoutStyleInfo *styleInfo=0)
 
QString toString () const
 
virtual ~AnchorData ()
 
- Public Functions inherited from QSimplexVariable
 QSimplexVariable ()
 

Public Variables

AnchorDatafirstEdge
 
QList< QSimplexConstraint * > m_firstConstraints
 
QList< QSimplexConstraint * > m_secondConstraints
 
AnchorDatasecondEdge
 
- Public Variables inherited from AnchorData
uint dependency: 2
 
AnchorVertexfrom
 
QGraphicsAnchorgraphicsAnchor
 
uint isCenterAnchor: 1
 
uint isLayoutAnchor: 1
 
QGraphicsLayoutItemitem
 
qreal maxPrefSize
 
qreal maxSize
 
qreal minPrefSize
 
qreal minSize
 
QString name
 
uint orientation: 1
 
qreal prefSize
 
qreal sizeAtMaximum
 
qreal sizeAtMinimum
 
qreal sizeAtPreferred
 
AnchorVertexto
 
uint type: 2
 
- Public Variables inherited from QSimplexVariable
int index
 
qreal result
 

Additional Inherited Members

- Public Types inherited from AnchorData
enum  Dependency { Independent = 0, Master, Slave }
 
enum  Type { Normal = 0, Sequential, Parallel }
 

Detailed Description

Definition at line 210 of file qgraphicsanchorlayout_p.h.

Constructors and Destructors

◆ ParallelAnchorData()

ParallelAnchorData::ParallelAnchorData ( AnchorData first,
AnchorData second 
)
inline

Definition at line 212 of file qgraphicsanchorlayout_p.h.

213  : AnchorData(), firstEdge(first), secondEdge(second)
214  {
216  orientation = first->orientation;
217 
218  // This assert whether the child anchors share their vertices
219  Q_ASSERT(((first->from == second->from) && (first->to == second->to)) ||
220  ((first->from == second->to) && (first->to == second->from)));
221 
222  // Our convention will be that the parallel group anchor will have the same
223  // direction as the first anchor.
224  from = first->from;
225  to = first->to;
226 #ifdef QT_DEBUG
227  name = QString::fromAscii("%1 | %2").arg(first->toString(), second->toString());
228 #endif
229  }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
AnchorVertex * to
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
AnchorVertex * from
QString toString() const

Functions

◆ calculateSizeHints()

bool ParallelAnchorData::calculateSizeHints ( )

Definition at line 298 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel().

299 {
300  // Normalize second child sizes.
301  // A negative anchor of sizes min, minPref, pref, maxPref and max, is equivalent
302  // to a forward anchor of sizes -max, -maxPref, -pref, -minPref, -min
303  qreal secondMin;
304  qreal secondMinPref;
305  qreal secondPref;
306  qreal secondMaxPref;
307  qreal secondMax;
308 
309  if (secondForward()) {
310  secondMin = secondEdge->minSize;
311  secondMinPref = secondEdge->minPrefSize;
312  secondPref = secondEdge->prefSize;
313  secondMaxPref = secondEdge->maxPrefSize;
314  secondMax = secondEdge->maxSize;
315  } else {
316  secondMin = -secondEdge->maxSize;
317  secondMinPref = -secondEdge->maxPrefSize;
318  secondPref = -secondEdge->prefSize;
319  secondMaxPref = -secondEdge->minPrefSize;
320  secondMax = -secondEdge->minSize;
321  }
322 
323  minSize = qMax(firstEdge->minSize, secondMin);
324  maxSize = qMin(firstEdge->maxSize, secondMax);
325 
326  // This condition means that the maximum size of one anchor being simplified is smaller than
327  // the minimum size of the other anchor. The consequence is that there won't be a valid size
328  // for this parallel setup.
329  if (minSize > maxSize) {
330  return false;
331  }
332 
333  // Preferred size calculation
334  // The calculation of preferred size is done as follows:
335  //
336  // 1) Check whether one of the child anchors is the layout structural anchor
337  // If so, we can simply copy the preferred information from the other child,
338  // after bounding it to our minimum and maximum sizes.
339  // If not, then we proceed with the actual calculations.
340  //
341  // 2) The whole algorithm for preferred size calculation is based on the fact
342  // that, if a given anchor cannot remain at its preferred size, it'd rather
343  // grow than shrink.
344  //
345  // What happens though is that while this affirmative is true for simple
346  // anchors, it may not be true for sequential anchors that have one or more
347  // reversed anchors inside it. That happens because when a sequential anchor
348  // grows, any reversed anchors inside it may be required to shrink, something
349  // we try to avoid, as said above.
350  //
351  // To overcome this, besides their actual preferred size "prefSize", each anchor
352  // exports what we call "minPrefSize" and "maxPrefSize". These two values define
353  // a surrounding interval where, if required to move, the anchor would rather
354  // remain inside.
355  //
356  // For standard anchors, this area simply represents the region between
357  // prefSize and maxSize, which makes sense since our first affirmation.
358  // For composed anchors, these values are calculated as to reduce the global
359  // "damage", that is, to reduce the total deviation and the total amount of
360  // anchors that had to shrink.
361 
362  if (firstEdge->isLayoutAnchor) {
363  prefSize = qBound(minSize, secondPref, maxSize);
364  minPrefSize = qBound(minSize, secondMinPref, maxSize);
365  maxPrefSize = qBound(minSize, secondMaxPref, maxSize);
366  } else if (secondEdge->isLayoutAnchor) {
370  } else {
371  // Calculate the intersection between the "preferred" regions of each child
372  const qreal lowerBoundary =
373  qBound(minSize, qMax(firstEdge->minPrefSize, secondMinPref), maxSize);
374  const qreal upperBoundary =
375  qBound(minSize, qMin(firstEdge->maxPrefSize, secondMaxPref), maxSize);
376  const qreal prefMean =
377  qBound(minSize, (firstEdge->prefSize + secondPref) / 2, maxSize);
378 
379  if (lowerBoundary < upperBoundary) {
380  // If there is an intersection between the two regions, this intersection
381  // will be used as the preferred region of the parallel anchor itself.
382  // The preferred size will be the bounded average between the two preferred
383  // sizes.
384  prefSize = qBound(lowerBoundary, prefMean, upperBoundary);
385  minPrefSize = lowerBoundary;
386  maxPrefSize = upperBoundary;
387  } else {
388  // If there is no intersection, we have to attribute "damage" to at least
389  // one of the children. The minimum total damage is achieved in points
390  // inside the region that extends from (1) the upper boundary of the lower
391  // region to (2) the lower boundary of the upper region.
392  // Then, we expose this region as _our_ preferred region and once again,
393  // use the bounded average as our preferred size.
394  prefSize = qBound(upperBoundary, prefMean, lowerBoundary);
395  minPrefSize = upperBoundary;
396  maxPrefSize = lowerBoundary;
397  }
398  }
399 
400  // See comment in AnchorData::refreshSizeHints() about sizeAt* values
404 
405  return true;
406 }
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219

◆ secondForward()

bool ParallelAnchorData::secondForward ( ) const
inline

Definition at line 234 of file qgraphicsanchorlayout_p.h.

Referenced by QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(), and QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints().

234  {
235  // We have the convention that the first children will define the direction of the
236  // pararell group. Note that we can't rely on 'this->from' or 'this->to' because they
237  // might be changed by vertex simplification.
238  return firstEdge->from == secondEdge->from;
239  }
AnchorVertex * from

◆ updateChildrenSizes()

void ParallelAnchorData::updateChildrenSizes ( )
virtual

Properties

◆ firstEdge

AnchorData* ParallelAnchorData::firstEdge

◆ m_firstConstraints

QList<QSimplexConstraint *> ParallelAnchorData::m_firstConstraints

◆ m_secondConstraints

QList<QSimplexConstraint *> ParallelAnchorData::m_secondConstraints

◆ secondEdge

AnchorData* ParallelAnchorData::secondEdge

The documentation for this struct was generated from the following files: