Qt 4.8
Enumerations | Functions | Variables
qgraphicsanchorlayout_p.cpp File Reference
#include <QtGui/qwidget.h>
#include <QtGui/qapplication.h>
#include <QtCore/qlinkedlist.h>
#include <QtCore/qstack.h>
#include <QtCore/qfile.h>
#include "qgraphicsanchorlayout_p.h"

Go to the source code of this file.

Enumerations

enum  slackType { Grower = -1, Shrinker = 1 }
 

Functions

static void applySizePolicy (QSizePolicy::Policy policy, qreal minSizeHint, qreal prefSizeHint, qreal maxSizeHint, qreal *minSize, qreal *prefSize, qreal *maxSize)
 
static qreal checkAdd (qreal a, qreal b)
 
static AnchorDatacreateSequence (Graph< AnchorVertex, AnchorData > *graph, AnchorVertex *before, const QVector< AnchorVertex *> &vertices, AnchorVertex *after)
 Takes the sequence of vertices described by (before, vertices, after) and removes all anchors connected to the vertices in vertices, returning one simplified anchor between before and after. More...
 
static QPair< QSimplexVariable *, QSimplexConstraint * > createSlack (QSimplexConstraint *sizeConstraint, qreal interval, slackType type)
 
static QPair< QGraphicsAnchorLayoutPrivate::Interval, qrealgetFactor (qreal value, qreal min, qreal minPref, qreal pref, qreal maxPref, qreal max)
 
QList< AnchorData * > getVariables (QList< QSimplexConstraint *> constraints)
 
static qreal interpolate (const QPair< QGraphicsAnchorLayoutPrivate::Interval, qreal > &factor, qreal min, qreal minPref, qreal pref, qreal maxPref, qreal max)
 
static AnchorVertexreplaceVertex_helper (AnchorData *data, AnchorVertex *oldV, AnchorVertex *newV)
 
static void shiftConstraints (const QList< QSimplexConstraint *> &constraints, qreal amount)
 Shift all the constraints by a certain amount. More...
 

Variables

const qreal g_offset = (sizeof(qreal) == sizeof(double)) ? QWIDGETSIZE_MAX : QWIDGETSIZE_MAX / 32
 

Enumeration Type Documentation

◆ slackType

enum slackType
Enumerator
Grower 
Shrinker 

Definition at line 2916 of file qgraphicsanchorlayout_p.cpp.

Function Documentation

◆ applySizePolicy()

static void applySizePolicy ( QSizePolicy::Policy  policy,
qreal  minSizeHint,
qreal  prefSizeHint,
qreal  maxSizeHint,
qreal minSize,
qreal prefSize,
qreal maxSize 
)
static

Definition at line 131 of file qgraphicsanchorlayout_p.cpp.

Referenced by AnchorData::refreshSizeHints().

135 {
136  // minSize, prefSize and maxSize are initialized
137  // with item's preferred Size: this is QSizePolicy::Fixed.
138  //
139  // Then we check each flag to find the resultant QSizePolicy,
140  // according to the following table:
141  //
142  // constant value
143  // QSizePolicy::Fixed 0
144  // QSizePolicy::Minimum GrowFlag
145  // QSizePolicy::Maximum ShrinkFlag
146  // QSizePolicy::Preferred GrowFlag | ShrinkFlag
147  // QSizePolicy::Ignored GrowFlag | ShrinkFlag | IgnoreFlag
148 
149  if (policy & QSizePolicy::ShrinkFlag)
150  *minSize = minSizeHint;
151  else
152  *minSize = prefSizeHint;
153 
154  if (policy & QSizePolicy::GrowFlag)
155  *maxSize = maxSizeHint;
156  else
157  *maxSize = prefSizeHint;
158 
159  // Note that these two initializations are affected by the previous flags
160  if (policy & QSizePolicy::IgnoreFlag)
161  *prefSize = *minSize;
162  else
163  *prefSize = prefSizeHint;
164 }

◆ checkAdd()

static qreal checkAdd ( qreal  a,
qreal  b 
)
inlinestatic
Warning
This function is not part of the public interface.

helper function in order to avoid overflowing anchor sizes the returned size will never be larger than FLT_MAX

Definition at line 670 of file qgraphicsanchorlayout_p.cpp.

671 {
672  if (FLT_MAX - b < a)
673  return FLT_MAX;
674  return a + b;
675 }
long ASN1_INTEGER_get ASN1_INTEGER * a

◆ createSequence()

static AnchorData* createSequence ( Graph< AnchorVertex, AnchorData > *  graph,
AnchorVertex before,
const QVector< AnchorVertex *> &  vertices,
AnchorVertex after 
)
static

Takes the sequence of vertices described by (before, vertices, after) and removes all anchors connected to the vertices in vertices, returning one simplified anchor between before and after.

Warning
This function is not part of the public interface.

Note that this function doesn't add the created anchor to the graph. This should be done by the caller.

Definition at line 766 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::simplifyGraphIteration().

770 {
771 #if defined(QT_DEBUG) && 0
772  QString strVertices;
773  for (int i = 0; i < vertices.count(); ++i) {
774  strVertices += QString::fromAscii("%1 - ").arg(vertices.at(i)->toString());
775  }
776  QString strPath = QString::fromAscii("%1 - %2%3").arg(before->toString(), strVertices, after->toString());
777  qDebug("simplifying [%s] to [%s - %s]", qPrintable(strPath), qPrintable(before->toString()), qPrintable(after->toString()));
778 #endif
779 
780  AnchorVertex *prev = before;
781  QVector<AnchorData *> edges;
782 
783  // Take from the graph, the edges that will be simplificated
784  for (int i = 0; i < vertices.count(); ++i) {
785  AnchorVertex *next = vertices.at(i);
786  AnchorData *ad = graph->takeEdge(prev, next);
787  Q_ASSERT(ad);
788  edges.append(ad);
789  prev = next;
790  }
791 
792  // Take the last edge (not covered in the loop above)
793  AnchorData *ad = graph->takeEdge(vertices.last(), after);
794  Q_ASSERT(ad);
795  edges.append(ad);
796 
797  // Create sequence
798  SequentialAnchorData *sequence = new SequentialAnchorData(vertices, edges);
799  sequence->from = before;
800  sequence->to = after;
801 
802  sequence->calculateSizeHints();
803 
804  return sequence;
805 }
Represents an edge (anchor) in the internal graph.
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
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
Q_CORE_EXPORT void qDebug(const char *,...)
QString toString() const
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
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
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
EdgeData * takeEdge(Vertex *first, Vertex *second)
Definition: qgraph_p.h:179
#define qPrintable(string)
Definition: qglobal.h:1750

◆ createSlack()

static QPair<QSimplexVariable *, QSimplexConstraint *> createSlack ( QSimplexConstraint sizeConstraint,
qreal  interval,
slackType  type 
)
static

Definition at line 2917 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::solvePreferred().

2919 {
2920  QSimplexVariable *slack = new QSimplexVariable;
2921  sizeConstraint->variables.insert(slack, type);
2922 
2924  limit->variables.insert(slack, 1.0);
2926  limit->constant = interval;
2927 
2928  return qMakePair(slack, limit);
2929 }
int type
Definition: qmetatype.cpp:239
QHash< QSimplexVariable *, qreal > variables
Definition: qsimplex_p.h:91
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102

◆ getFactor()

static QPair<QGraphicsAnchorLayoutPrivate::Interval, qreal> getFactor ( qreal  value,
qreal  min,
qreal  minPref,
qreal  pref,
qreal  maxPref,
qreal  max 
)
static
Warning
This function is not part of the public interface. returns the factor in the interval [-1, 1]. -1 is at Minimum 0 is at Preferred 1 is at Maximum

Definition at line 415 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation(), and SequentialAnchorData::updateChildrenSizes().

418 {
420  qreal lower;
421  qreal upper;
422 
423  if (value < minPref) {
425  lower = min;
426  upper = minPref;
427  } else if (value < pref) {
429  lower = minPref;
430  upper = pref;
431  } else if (value < maxPref) {
433  lower = pref;
434  upper = maxPref;
435  } else {
437  lower = maxPref;
438  upper = max;
439  }
440 
441  qreal progress;
442  if (upper == lower) {
443  progress = 0;
444  } else {
445  progress = (value - lower) / (upper - lower);
446  }
447 
448  return qMakePair(interval, progress);
449 }
double qreal
Definition: qglobal.h:1193
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102

◆ getVariables()

QList<AnchorData *> getVariables ( QList< QSimplexConstraint *>  constraints)

Definition at line 2098 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::calculateGraphs(), and QGraphicsAnchorLayoutPrivate::solveMinMax().

2099 {
2100  QSet<AnchorData *> variableSet;
2101  for (int i = 0; i < constraints.count(); ++i) {
2102  const QSimplexConstraint *c = constraints.at(i);
2103  foreach (QSimplexVariable *var, c->variables.keys()) {
2104  variableSet += static_cast<AnchorData *>(var);
2105  }
2106  }
2107  return variableSet.toList();
2108 }
Represents an edge (anchor) in the internal graph.
unsigned char c[8]
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QHash< QSimplexVariable *, qreal > variables
Definition: qsimplex_p.h:91
QList< T > toList() const
Definition: qset.h:296
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648

◆ interpolate()

static qreal interpolate ( const QPair< QGraphicsAnchorLayoutPrivate::Interval, qreal > &  factor,
qreal  min,
qreal  minPref,
qreal  pref,
qreal  maxPref,
qreal  max 
)
static

Definition at line 451 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::interpolateEdge(), and SequentialAnchorData::updateChildrenSizes().

453 {
454  qreal lower = 0;
455  qreal upper = 0;
456 
457  switch (factor.first) {
459  lower = min;
460  upper = minPref;
461  break;
463  lower = minPref;
464  upper = pref;
465  break;
467  lower = pref;
468  upper = maxPref;
469  break;
471  lower = maxPref;
472  upper = max;
473  break;
474  }
475 
476  return lower + factor.second * (upper - lower);
477 }
double qreal
Definition: qglobal.h:1193
T1 first
Definition: qpair.h:65
T2 second
Definition: qpair.h:66

◆ replaceVertex_helper()

static AnchorVertex* replaceVertex_helper ( AnchorData data,
AnchorVertex oldV,
AnchorVertex newV 
)
static

Definition at line 891 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::replaceVertex(), and QGraphicsAnchorLayoutPrivate::restoreVertices().

892 {
893  AnchorVertex *other;
894  if (data->from == oldV) {
895  data->from = newV;
896  other = data->to;
897  } else {
898  data->to = newV;
899  other = data->from;
900  }
901  return other;
902 }
AnchorVertex * to
AnchorVertex * from

◆ shiftConstraints()

static void shiftConstraints ( const QList< QSimplexConstraint *> &  constraints,
qreal  amount 
)
static

Shift all the constraints by a certain amount.

Warning
This function is not part of the public interface.

This allows us to deal with negative values in the linear program if they are bounded by a certain limit. Functions should be careful to call it again with a negative amount, to shift the constraints back.

Definition at line 2228 of file qgraphicsanchorlayout_p.cpp.

Referenced by QGraphicsAnchorLayoutPrivate::calculateNonTrunk(), and QGraphicsAnchorLayoutPrivate::calculateTrunk().

2229 {
2230  for (int i = 0; i < constraints.count(); ++i) {
2231  QSimplexConstraint *c = constraints.at(i);
2232  qreal multiplier = 0;
2233  foreach (qreal v, c->variables.values()) {
2234  multiplier += v;
2235  }
2236  c->constant += multiplier * amount;
2237  }
2238 }
double qreal
Definition: qglobal.h:1193
unsigned char c[8]
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QHash< QSimplexVariable *, qreal > variables
Definition: qsimplex_p.h:91
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693

Variable Documentation

◆ g_offset

const qreal g_offset = (sizeof(qreal) == sizeof(double)) ? QWIDGETSIZE_MAX : QWIDGETSIZE_MAX / 32