src/gui/graphicsview/qgraphicsanchorlayout_p.h
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    58 
    58 
    59 #include "qgraphicslayout_p.h"
    59 #include "qgraphicslayout_p.h"
    60 #include "qgraphicsanchorlayout.h"
    60 #include "qgraphicsanchorlayout.h"
    61 #include "qgraph_p.h"
    61 #include "qgraph_p.h"
    62 #include "qsimplex_p.h"
    62 #include "qsimplex_p.h"
    63 
    63 #ifndef QT_NO_GRAPHICSVIEW
    64 QT_BEGIN_NAMESPACE
    64 QT_BEGIN_NAMESPACE
    65 
    65 
    66 /*
    66 /*
    67   The public QGraphicsAnchorLayout interface represents an anchorage point
    67   The public QGraphicsAnchorLayout interface represents an anchorage point
    68   as a pair of a <QGraphicsLayoutItem *> and a <Qt::AnchorPoint>.
    68   as a pair of a <QGraphicsLayoutItem *> and a <Qt::AnchorPoint>.
    76   \internal
    76   \internal
    77 
    77 
    78   Represents a vertex (anchorage point) in the internal graph
    78   Represents a vertex (anchorage point) in the internal graph
    79 */
    79 */
    80 struct AnchorVertex {
    80 struct AnchorVertex {
       
    81     enum Type {
       
    82         Normal = 0,
       
    83         Pair
       
    84     };
       
    85 
    81     AnchorVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge)
    86     AnchorVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge)
    82         : m_item(item), m_edge(edge) {}
    87         : m_item(item), m_edge(edge), m_type(Normal) {}
    83 
    88 
    84     AnchorVertex()
    89     AnchorVertex()
    85         : m_item(0), m_edge(Qt::AnchorPoint(0)) {}
    90         : m_item(0), m_edge(Qt::AnchorPoint(0)), m_type(Normal) {}
    86 
    91 
    87 #ifdef QT_DEBUG
    92 #ifdef QT_DEBUG
    88     inline QString toString() const;
    93     inline QString toString() const;
    89 #endif
    94 #endif
       
    95 
    90     QGraphicsLayoutItem *m_item;
    96     QGraphicsLayoutItem *m_item;
    91     Qt::AnchorPoint m_edge;
    97     Qt::AnchorPoint m_edge;
       
    98     uint m_type : 1;
    92 
    99 
    93     // Current distance from this vertex to the layout edge (Left or Top)
   100     // Current distance from this vertex to the layout edge (Left or Top)
    94     // Value is calculated from the current anchors sizes.
   101     // Value is calculated from the current anchors sizes.
    95     qreal distance;
   102     qreal distance;
    96 };
   103 };
    97 
       
    98 #ifdef QT_DEBUG
       
    99 inline QString AnchorVertex::toString() const
       
   100 {
       
   101     if (!this || !m_item) {
       
   102         return QLatin1String("NULL");
       
   103     }
       
   104     QString edge;
       
   105     switch (m_edge) {
       
   106     case Qt::AnchorLeft:
       
   107         edge = QLatin1String("Left");
       
   108         break;
       
   109     case Qt::AnchorHorizontalCenter:
       
   110         edge = QLatin1String("HorizontalCenter");
       
   111         break;
       
   112     case Qt::AnchorRight:
       
   113         edge = QLatin1String("Right");
       
   114         break;
       
   115     case Qt::AnchorTop:
       
   116         edge = QLatin1String("Top");
       
   117         break;
       
   118     case Qt::AnchorVerticalCenter:
       
   119         edge = QLatin1String("VerticalCenter");
       
   120         break;
       
   121     case Qt::AnchorBottom:
       
   122         edge = QLatin1String("Bottom");
       
   123         break;
       
   124     default:
       
   125         edge = QLatin1String("None");
       
   126         break;
       
   127     }
       
   128     QString itemName;
       
   129     if (m_item->isLayout()) {
       
   130         itemName = QLatin1String("layout");
       
   131     } else {
       
   132         if (QGraphicsItem *item = m_item->graphicsItem()) {
       
   133             itemName = item->data(0).toString();
       
   134         }
       
   135     }
       
   136     edge.insert(0, QLatin1String("%1_"));
       
   137     return edge.arg(itemName);
       
   138 }
       
   139 #endif
       
   140 
   104 
   141 /*!
   105 /*!
   142   \internal
   106   \internal
   143 
   107 
   144   Represents an edge (anchor) in the internal graph.
   108   Represents an edge (anchor) in the internal graph.
   148         Normal = 0,
   112         Normal = 0,
   149         Sequential,
   113         Sequential,
   150         Parallel
   114         Parallel
   151     };
   115     };
   152 
   116 
       
   117     enum Dependency {
       
   118         Independent = 0,
       
   119         Master,
       
   120         Slave
       
   121     };
       
   122 
   153     AnchorData()
   123     AnchorData()
   154         : QSimplexVariable(), from(0), to(0),
   124         : QSimplexVariable(), from(0), to(0),
   155           minSize(0), prefSize(0), expSize(0), maxSize(0),
   125           minSize(0), prefSize(0), maxSize(0),
       
   126           minPrefSize(0), maxPrefSize(0),
   156           sizeAtMinimum(0), sizeAtPreferred(0),
   127           sizeAtMinimum(0), sizeAtPreferred(0),
   157           sizeAtExpanding(0), sizeAtMaximum(0),
   128           sizeAtMaximum(0), item(0), graphicsAnchor(0),
   158           graphicsAnchor(0), skipInPreferred(0),
   129           type(Normal), isLayoutAnchor(false),
   159           type(Normal), hasSize(true), isLayoutAnchor(false) {}
   130           isCenterAnchor(false), orientation(0),
       
   131           dependency(Independent) {}
       
   132     virtual ~AnchorData();
   160 
   133 
   161     virtual void updateChildrenSizes() {}
   134     virtual void updateChildrenSizes() {}
   162     virtual void refreshSizeHints(qreal effectiveSpacing);
   135     void refreshSizeHints(const QLayoutStyleInfo *styleInfo = 0);
   163 
       
   164     virtual ~AnchorData() {}
       
   165 
   136 
   166 #ifdef QT_DEBUG
   137 #ifdef QT_DEBUG
   167     void dump(int indent = 2);
   138     void dump(int indent = 2);
   168     inline QString toString() const;
   139     inline QString toString() const;
   169     QString name;
   140     QString name;
   170 #endif
   141 #endif
   171 
   142 
   172     inline void setPreferredSize(qreal size)
       
   173     {
       
   174         prefSize = size;
       
   175         hasSize = true;
       
   176     }
       
   177 
       
   178     inline void unsetSize()
       
   179     {
       
   180         hasSize = false;
       
   181     }
       
   182 
       
   183     // Anchor is semantically directed
   143     // Anchor is semantically directed
   184     AnchorVertex *from;
   144     AnchorVertex *from;
   185     AnchorVertex *to;
   145     AnchorVertex *to;
   186 
   146 
   187     // Size restrictions of this edge. For anchors internal to items, these
   147     // Nominal sizes
   188     // values are derived from the respective item size hints. For anchors
   148     // These are the intrinsic size restrictions for a given item. They are
   189     // that were added by users, these values are equal to the specified anchor
   149     // used as input for the calculation of the actual sizes.
   190     // size.
   150     // These values are filled by the refreshSizeHints method, based on the
       
   151     // anchor size policy, the size hints of the item it (possibly) represents
       
   152     // and the layout spacing information.
   191     qreal minSize;
   153     qreal minSize;
   192     qreal prefSize;
   154     qreal prefSize;
   193     qreal expSize;
       
   194     qreal maxSize;
   155     qreal maxSize;
   195 
   156 
       
   157     qreal minPrefSize;
       
   158     qreal maxPrefSize;
       
   159 
       
   160     // Calculated sizes
   196     // These attributes define which sizes should that anchor be in when the
   161     // These attributes define which sizes should that anchor be in when the
   197     // layout is at its minimum, preferred or maximum sizes. Values are
   162     // layout is at its minimum, preferred or maximum sizes. Values are
   198     // calculated by the Simplex solver based on the current layout setup.
   163     // calculated by the Simplex solver based on the current layout setup.
   199     qreal sizeAtMinimum;
   164     qreal sizeAtMinimum;
   200     qreal sizeAtPreferred;
   165     qreal sizeAtPreferred;
   201     qreal sizeAtExpanding;
       
   202     qreal sizeAtMaximum;
   166     qreal sizeAtMaximum;
       
   167 
       
   168     // References to the classes that represent this anchor in the public world
       
   169     // An anchor may represent a LayoutItem, it may also be acessible externally
       
   170     // through a GraphicsAnchor "handler".
       
   171     QGraphicsLayoutItem *item;
   203     QGraphicsAnchor *graphicsAnchor;
   172     QGraphicsAnchor *graphicsAnchor;
   204 
   173 
   205     uint skipInPreferred : 1;
       
   206     uint type : 2;            // either Normal, Sequential or Parallel
   174     uint type : 2;            // either Normal, Sequential or Parallel
   207     uint hasSize : 1;         // if false, get size from style.
   175     uint isLayoutAnchor : 1;  // if this anchor is an internal layout anchor
   208     uint isLayoutAnchor : 1;  // if this anchor is connected to a layout 'edge'
   176     uint isCenterAnchor : 1;
       
   177     uint orientation : 1;
       
   178     uint dependency : 2;      // either Independent, Master or Slave
   209 };
   179 };
   210 
   180 
   211 #ifdef QT_DEBUG
   181 #ifdef QT_DEBUG
   212 inline QString AnchorData::toString() const
   182 inline QString AnchorData::toString() const
   213 {
   183 {
   215 }
   185 }
   216 #endif
   186 #endif
   217 
   187 
   218 struct SequentialAnchorData : public AnchorData
   188 struct SequentialAnchorData : public AnchorData
   219 {
   189 {
   220     SequentialAnchorData() : AnchorData()
   190     SequentialAnchorData(const QVector<AnchorVertex *> &vertices, const QVector<AnchorData *> &edges)
       
   191         : AnchorData(), m_children(vertices), m_edges(edges)
   221     {
   192     {
   222         type = AnchorData::Sequential;
   193         type = AnchorData::Sequential;
   223 #ifdef QT_DEBUG
   194         orientation = m_edges.at(0)->orientation;
   224         name = QLatin1String("SequentialAnchorData");
   195 #ifdef QT_DEBUG
       
   196         name = QString::fromAscii("%1 -- %2").arg(vertices.first()->toString(), vertices.last()->toString());
   225 #endif
   197 #endif
   226     }
   198     }
   227 
   199 
   228     virtual void updateChildrenSizes();
   200     virtual void updateChildrenSizes();
   229     virtual void refreshSizeHints(qreal effectiveSpacing);
   201     void calculateSizeHints();
   230 
       
   231     void refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
       
   232 
       
   233     void setVertices(const QVector<AnchorVertex*> &vertices)
       
   234     {
       
   235         m_children = vertices;
       
   236 #ifdef QT_DEBUG
       
   237         name = QString::fromAscii("%1 -- %2").arg(vertices.first()->toString(), vertices.last()->toString());
       
   238 #endif
       
   239     }
       
   240 
   202 
   241     QVector<AnchorVertex*> m_children;          // list of vertices in the sequence
   203     QVector<AnchorVertex*> m_children;          // list of vertices in the sequence
   242     QVector<AnchorData*> m_edges;               // keep the list of edges too.
   204     QVector<AnchorData*> m_edges;               // keep the list of edges too.
   243 };
   205 };
   244 
   206 
   246 {
   208 {
   247     ParallelAnchorData(AnchorData *first, AnchorData *second)
   209     ParallelAnchorData(AnchorData *first, AnchorData *second)
   248         : AnchorData(), firstEdge(first), secondEdge(second)
   210         : AnchorData(), firstEdge(first), secondEdge(second)
   249     {
   211     {
   250         type = AnchorData::Parallel;
   212         type = AnchorData::Parallel;
   251 
   213         orientation = first->orientation;
   252         // ### Those asserts force that both child anchors have the same direction,
   214 
   253         // but can't we simplify a pair of anchors in opposite directions?
   215         // This assert whether the child anchors share their vertices
   254         Q_ASSERT(first->from == second->from);
   216         Q_ASSERT(((first->from == second->from) && (first->to == second->to)) ||
   255         Q_ASSERT(first->to == second->to);
   217                  ((first->from == second->to) && (first->to == second->from)));
       
   218 
       
   219         // Our convention will be that the parallel group anchor will have the same
       
   220         // direction as the first anchor.
   256         from = first->from;
   221         from = first->from;
   257         to = first->to;
   222         to = first->to;
   258 #ifdef QT_DEBUG
   223 #ifdef QT_DEBUG
   259         name = QString::fromAscii("%1 | %2").arg(first->toString(), second->toString());
   224         name = QString::fromAscii("%1 | %2").arg(first->toString(), second->toString());
   260 #endif
   225 #endif
   261     }
   226     }
   262 
   227 
   263     virtual void updateChildrenSizes();
   228     virtual void updateChildrenSizes();
   264     virtual void refreshSizeHints(qreal effectiveSpacing);
   229     bool calculateSizeHints();
   265 
   230 
   266     void refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
   231     bool secondForward() const {
       
   232         // We have the convention that the first children will define the direction of the
       
   233         // pararell group. Note that we can't rely on 'this->from' or 'this->to'  because they
       
   234         // might be changed by vertex simplification.
       
   235         return firstEdge->from == secondEdge->from;
       
   236     }
   267 
   237 
   268     AnchorData* firstEdge;
   238     AnchorData* firstEdge;
   269     AnchorData* secondEdge;
   239     AnchorData* secondEdge;
   270 };
   240 
       
   241     QList<QSimplexConstraint *> m_firstConstraints;
       
   242     QList<QSimplexConstraint *> m_secondConstraints;
       
   243 };
       
   244 
       
   245 struct AnchorVertexPair : public AnchorVertex {
       
   246     AnchorVertexPair(AnchorVertex *v1, AnchorVertex *v2, AnchorData *data)
       
   247         : AnchorVertex(), m_first(v1), m_second(v2), m_removedAnchor(data) {
       
   248         m_type = AnchorVertex::Pair;
       
   249     }
       
   250 
       
   251     AnchorVertex *m_first;
       
   252     AnchorVertex *m_second;
       
   253 
       
   254     AnchorData *m_removedAnchor;
       
   255     QList<AnchorData *> m_firstAnchors;
       
   256     QList<AnchorData *> m_secondAnchors;
       
   257 };
       
   258 
       
   259 #ifdef QT_DEBUG
       
   260 inline QString AnchorVertex::toString() const
       
   261 {
       
   262     if (!this) {
       
   263         return QLatin1String("NULL");
       
   264     } else if (m_type == Pair) {
       
   265         const AnchorVertexPair *vp = static_cast<const AnchorVertexPair *>(this);
       
   266         return QString::fromAscii("(%1, %2)").arg(vp->m_first->toString()).arg(vp->m_second->toString());
       
   267     } else if (!m_item) {
       
   268         return QString::fromAscii("NULL_%1").arg(quintptr(this));
       
   269     }
       
   270     QString edge;
       
   271     switch (m_edge) {
       
   272     case Qt::AnchorLeft:
       
   273         edge = QLatin1String("Left");
       
   274         break;
       
   275     case Qt::AnchorHorizontalCenter:
       
   276         edge = QLatin1String("HorizontalCenter");
       
   277         break;
       
   278     case Qt::AnchorRight:
       
   279         edge = QLatin1String("Right");
       
   280         break;
       
   281     case Qt::AnchorTop:
       
   282         edge = QLatin1String("Top");
       
   283         break;
       
   284     case Qt::AnchorVerticalCenter:
       
   285         edge = QLatin1String("VerticalCenter");
       
   286         break;
       
   287     case Qt::AnchorBottom:
       
   288         edge = QLatin1String("Bottom");
       
   289         break;
       
   290     default:
       
   291         edge = QLatin1String("None");
       
   292         break;
       
   293     }
       
   294     QString itemName;
       
   295     if (m_item->isLayout()) {
       
   296         itemName = QLatin1String("layout");
       
   297     } else {
       
   298         if (QGraphicsItem *item = m_item->graphicsItem()) {
       
   299             itemName = item->data(0).toString();
       
   300         }
       
   301     }
       
   302     edge.insert(0, QLatin1String("%1_"));
       
   303     return edge.arg(itemName);
       
   304 }
       
   305 #endif
   271 
   306 
   272 /*!
   307 /*!
   273   \internal
   308   \internal
   274 
   309 
   275   Representation of a valid path for a given vertex in the graph.
   310   Representation of a valid path for a given vertex in the graph.
   311 
   346 
   312     void setSizePolicy(QSizePolicy::Policy policy);
   347     void setSizePolicy(QSizePolicy::Policy policy);
   313 
   348 
   314     QGraphicsAnchorLayoutPrivate *layoutPrivate;
   349     QGraphicsAnchorLayoutPrivate *layoutPrivate;
   315     AnchorData *data;
   350     AnchorData *data;
       
   351 
       
   352     // Size information for user controlled anchor
   316     QSizePolicy::Policy sizePolicy;
   353     QSizePolicy::Policy sizePolicy;
       
   354     qreal preferredSize;
       
   355 
       
   356     uint hasSize : 1;         // if false, get size from style.
   317 };
   357 };
   318 
   358 
   319 
   359 
   320 
   360 
   321 
   361 
   333     // or Maximum values, interpolation is used to calculate the geometries
   373     // or Maximum values, interpolation is used to calculate the geometries
   334     // of the items.
   374     // of the items.
   335     //
   375     //
   336     // Interval represents which interpolation interval are we operating in.
   376     // Interval represents which interpolation interval are we operating in.
   337     enum Interval {
   377     enum Interval {
   338         MinToPreferred = 0,
   378         MinimumToMinPreferred = 0,
   339         PreferredToExpanding,
   379         MinPreferredToPreferred,
   340         ExpandingToMax
   380         PreferredToMaxPreferred,
       
   381         MaxPreferredToMaximum
   341     };
   382     };
   342 
   383 
   343     // Several structures internal to the layout are duplicated to handle
   384     // Several structures internal to the layout are duplicated to handle
   344     // both Horizontal and Vertical restrictions.
   385     // both Horizontal and Vertical restrictions.
   345     //
   386     //
   407     QGraphicsAnchor *getAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
   448     QGraphicsAnchor *getAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
   408                                QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
   449                                QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
   409 
   450 
   410     void removeAnchor(AnchorVertex *firstVertex, AnchorVertex *secondVertex);
   451     void removeAnchor(AnchorVertex *firstVertex, AnchorVertex *secondVertex);
   411     void removeAnchor_helper(AnchorVertex *v1, AnchorVertex *v2);
   452     void removeAnchor_helper(AnchorVertex *v1, AnchorVertex *v2);
   412     void setAnchorSize(AnchorData *data, const qreal *anchorSize);
       
   413     void anchorSize(const AnchorData *data,
       
   414                     qreal *minSize = 0,
       
   415                     qreal *prefSize = 0,
       
   416                     qreal *maxSize = 0) const;
       
   417 
   453 
   418     void removeAnchors(QGraphicsLayoutItem *item);
   454     void removeAnchors(QGraphicsLayoutItem *item);
   419 
   455 
   420     void removeVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
   456     void removeVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
   421 
   457 
   422     void correctEdgeDirection(QGraphicsLayoutItem *&firstItem,
   458     void correctEdgeDirection(QGraphicsLayoutItem *&firstItem,
   423                               Qt::AnchorPoint &firstEdge,
   459                               Qt::AnchorPoint &firstEdge,
   424                               QGraphicsLayoutItem *&secondItem,
   460                               QGraphicsLayoutItem *&secondItem,
   425                               Qt::AnchorPoint &secondEdge);
   461                               Qt::AnchorPoint &secondEdge);
   426     // for getting the actual spacing (will query the style if the
   462 
   427     // spacing is not explicitly set).
   463     QLayoutStyleInfo &styleInfo() const;
   428     qreal effectiveSpacing(Orientation orientation) const;
   464 
   429 
   465     AnchorData *addAnchorMaybeParallel(AnchorData *newAnchor, bool *feasible);
   430     // Activation methods
   466 
   431     void simplifyGraph(Orientation orientation);
   467     // Activation
   432     bool simplifyGraphIteration(Orientation orientation);
       
   433     void restoreSimplifiedGraph(Orientation orientation);
       
   434 
       
   435     void calculateGraphs();
   468     void calculateGraphs();
   436     void calculateGraphs(Orientation orientation);
   469     void calculateGraphs(Orientation orientation);
       
   470 
       
   471     // Simplification
       
   472     bool simplifyGraph(Orientation orientation);
       
   473     bool simplifyVertices(Orientation orientation);
       
   474     bool simplifyGraphIteration(Orientation orientation, bool *feasible);
       
   475 
       
   476     bool replaceVertex(Orientation orientation, AnchorVertex *oldV,
       
   477                        AnchorVertex *newV, const QList<AnchorData *> &edges);
       
   478 
       
   479 
       
   480     void restoreSimplifiedGraph(Orientation orientation);
       
   481     void restoreSimplifiedAnchor(AnchorData *edge);
       
   482     void restoreSimplifiedConstraints(ParallelAnchorData *parallel);
       
   483     void restoreVertices(Orientation orientation);
   437 
   484 
   438     bool calculateTrunk(Orientation orientation, const GraphPath &trunkPath,
   485     bool calculateTrunk(Orientation orientation, const GraphPath &trunkPath,
   439                         const QList<QSimplexConstraint *> &constraints,
   486                         const QList<QSimplexConstraint *> &constraints,
   440                         const QList<AnchorData *> &variables);
   487                         const QList<AnchorData *> &variables);
   441     bool calculateNonTrunk(const QList<QSimplexConstraint *> &constraints,
   488     bool calculateNonTrunk(const QList<QSimplexConstraint *> &constraints,
   442                            const QList<AnchorData *> &variables);
   489                            const QList<AnchorData *> &variables);
   443 
   490 
   444     void setAnchorSizeHintsFromItems(Orientation orientation);
   491     // Support functions for calculateGraph()
       
   492     void refreshAllSizeHints(Orientation orientation);
   445     void findPaths(Orientation orientation);
   493     void findPaths(Orientation orientation);
   446     void constraintsFromPaths(Orientation orientation);
   494     void constraintsFromPaths(Orientation orientation);
   447     void updateAnchorSizes(Orientation orientation);
   495     void updateAnchorSizes(Orientation orientation);
   448     QList<QSimplexConstraint *> constraintsFromSizeHints(const QList<AnchorData *> &anchors);
   496     QList<QSimplexConstraint *> constraintsFromSizeHints(const QList<AnchorData *> &anchors);
   449     QList<QList<QSimplexConstraint *> > getGraphParts(Orientation orientation);
   497     QList<QList<QSimplexConstraint *> > getGraphParts(Orientation orientation);
   458     inline AnchorVertex *internalVertex(const QGraphicsLayoutItem *item, Qt::AnchorPoint edge) const
   506     inline AnchorVertex *internalVertex(const QGraphicsLayoutItem *item, Qt::AnchorPoint edge) const
   459     {
   507     {
   460         return internalVertex(qMakePair(const_cast<QGraphicsLayoutItem *>(item), edge));
   508         return internalVertex(qMakePair(const_cast<QGraphicsLayoutItem *>(item), edge));
   461     }
   509     }
   462 
   510 
       
   511     inline void changeLayoutVertex(Orientation orientation, AnchorVertex *oldV, AnchorVertex *newV)
       
   512     {
       
   513         if (layoutFirstVertex[orientation] == oldV)
       
   514             layoutFirstVertex[orientation] = newV;
       
   515         else if (layoutCentralVertex[orientation] == oldV)
       
   516             layoutCentralVertex[orientation] = newV;
       
   517         else if (layoutLastVertex[orientation] == oldV)
       
   518             layoutLastVertex[orientation] = newV;
       
   519     }
       
   520 
       
   521 
   463     AnchorVertex *addInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
   522     AnchorVertex *addInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
   464     void removeInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
   523     void removeInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge);
   465 
   524 
   466     // Geometry interpolation methods
   525     // Geometry interpolation methods
   467     void setItemsGeometries(const QRectF &geom);
   526     void setItemsGeometries(const QRectF &geom);
   468 
   527 
   469     void calculateVertexPositions(Orientation orientation);
   528     void calculateVertexPositions(Orientation orientation);
   470     void setupEdgesInterpolation(Orientation orientation);
   529     void setupEdgesInterpolation(Orientation orientation);
   471     void interpolateEdge(AnchorVertex *base, AnchorData *edge, Orientation orientation);
   530     void interpolateEdge(AnchorVertex *base, AnchorData *edge);
   472     void interpolateSequentialEdges(AnchorVertex *base, SequentialAnchorData *edge,
       
   473                                     Orientation orientation);
       
   474     void interpolateParallelEdges(AnchorVertex *base, ParallelAnchorData *edge,
       
   475                                   Orientation orientation);
       
   476 
   531 
   477     // Linear Programming solver methods
   532     // Linear Programming solver methods
   478     bool solveMinMax(const QList<QSimplexConstraint *> &constraints,
   533     bool solveMinMax(const QList<QSimplexConstraint *> &constraints,
   479                      GraphPath path, qreal *min, qreal *max);
   534                      GraphPath path, qreal *min, qreal *max);
   480     bool solvePreferred(const QList<QSimplexConstraint *> &constraints,
   535     bool solvePreferred(const QList<QSimplexConstraint *> &constraints,
   481                         const QList<AnchorData *> &variables);
   536                         const QList<AnchorData *> &variables);
   482     void solveExpanding(const QList<QSimplexConstraint *> &constraints,
       
   483                         const QList<AnchorData *> &variables);
       
   484     bool hasConflicts() const;
   537     bool hasConflicts() const;
   485 
   538 
   486 #ifdef QT_DEBUG
   539 #ifdef QT_DEBUG
   487     void dumpGraph(const QString &name = QString());
   540     void dumpGraph(const QString &name = QString());
   488 #endif
   541 #endif
   489 
   542 
   490 
   543 
   491     qreal spacings[NOrientations];
   544     qreal spacings[NOrientations];
   492     // Size hints from simplex engine
   545     // Size hints from simplex engine
   493     qreal sizeHints[2][3];
   546     qreal sizeHints[2][3];
   494     qreal sizeAtExpanding[2];
       
   495 
   547 
   496     // Items
   548     // Items
   497     QVector<QGraphicsLayoutItem *> items;
   549     QVector<QGraphicsLayoutItem *> items;
   498 
   550 
   499     // Mapping between high level anchorage points (Item, Edge) to low level
   551     // Mapping between high level anchorage points (Item, Edge) to low level
   501 
   553 
   502     QHash<QPair<QGraphicsLayoutItem*, Qt::AnchorPoint>, QPair<AnchorVertex *, int> > m_vertexList;
   554     QHash<QPair<QGraphicsLayoutItem*, Qt::AnchorPoint>, QPair<AnchorVertex *, int> > m_vertexList;
   503 
   555 
   504     // Internal graph of anchorage points and anchors, for both orientations
   556     // Internal graph of anchorage points and anchors, for both orientations
   505     Graph<AnchorVertex, AnchorData> graph[2];
   557     Graph<AnchorVertex, AnchorData> graph[2];
       
   558 
       
   559     AnchorVertex *layoutFirstVertex[2];
       
   560     AnchorVertex *layoutCentralVertex[2];
       
   561     AnchorVertex *layoutLastVertex[2];
       
   562 
       
   563     // Combined anchors in order of creation
       
   564     QList<AnchorVertexPair *> simplifiedVertices[2];
       
   565     QList<AnchorData *> anchorsFromSimplifiedVertices[2];
   506 
   566 
   507     // Graph paths and constraints, for both orientations
   567     // Graph paths and constraints, for both orientations
   508     QMultiHash<AnchorVertex *, GraphPath> graphPaths[2];
   568     QMultiHash<AnchorVertex *, GraphPath> graphPaths[2];
   509     QList<QSimplexConstraint *> constraints[2];
   569     QList<QSimplexConstraint *> constraints[2];
   510     QList<QSimplexConstraint *> itemCenterConstraints[2];
   570     QList<QSimplexConstraint *> itemCenterConstraints[2];
   512     // The interpolation interval and progress based on the current size
   572     // The interpolation interval and progress based on the current size
   513     // as well as the key values (minimum, preferred and maximum)
   573     // as well as the key values (minimum, preferred and maximum)
   514     Interval interpolationInterval[2];
   574     Interval interpolationInterval[2];
   515     qreal interpolationProgress[2];
   575     qreal interpolationProgress[2];
   516 
   576 
   517     // ###
       
   518     bool graphSimplified[2];
       
   519     bool graphHasConflicts[2];
   577     bool graphHasConflicts[2];
   520     QSet<QGraphicsLayoutItem *> m_floatItems[2];
   578     QSet<QGraphicsLayoutItem *> m_floatItems[2];
   521 
   579 
   522 #if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT)
   580 #if defined(QT_DEBUG) || defined(Q_AUTOTEST_EXPORT)
   523     bool lastCalculationUsedSimplex[2];
   581     bool lastCalculationUsedSimplex[2];
   524 #endif
   582 #endif
   525 
   583 
   526     uint calculateGraphCacheDirty : 1;
   584     uint calculateGraphCacheDirty : 1;
       
   585     mutable uint styleInfoDirty : 1;
       
   586     mutable QLayoutStyleInfo cachedStyleInfo;
   527 
   587 
   528     friend class QGraphicsAnchorPrivate;
   588     friend class QGraphicsAnchorPrivate;
   529 };
   589 };
   530 
   590 
   531 QT_END_NAMESPACE
   591 QT_END_NAMESPACE
   532 
   592 #endif //QT_NO_GRAPHICSVIEW
   533 #endif
   593 
       
   594 #endif