summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-11 10:34:08 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-09-14 12:22:01 (GMT)
commit89620720e9969360254f950fc63d131d82dd3471 (patch)
tree1117641c58ac7810549647e01ac26d5ab4845029 /src
parent41dbc4406791f82b7e3c1385acc594e22b5b0799 (diff)
downloadQt-89620720e9969360254f950fc63d131d82dd3471.zip
Qt-89620720e9969360254f950fc63d131d82dd3471.tar.gz
Qt-89620720e9969360254f950fc63d131d82dd3471.tar.bz2
API change. This will get rid of the ugly setAnchorSpacing() method.
Say hello to QGraphicsAnchor, move the spacing (and removeAnchor) functionality over to that class. This also opens up for a cleaner API when we add support for size policies or min/pref/max sizes for anchors. Also remove - addLeftAndRightAnchors() - addTopAndBottomAnchors() - addAllAnchors() in favor of - addAnchors(itemA, itemB, Qt::Orientations) API change discussed with Caio and Andreas. Reviewed-by: Alexis
Diffstat (limited to 'src')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.cpp185
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.h73
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp168
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h66
4 files changed, 292 insertions, 200 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
index c7033c6..f57f65f 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
@@ -84,6 +84,55 @@
QT_BEGIN_NAMESPACE
+QGraphicsAnchor::QGraphicsAnchor(QGraphicsAnchorLayout *parentLayout)
+ : QObject(*(new QGraphicsAnchorPrivate))
+{
+ Q_D(QGraphicsAnchor);
+ Q_ASSERT(parentLayout);
+ d->layoutPrivate = parentLayout->d_func();
+}
+
+/*!
+ Removes the QGraphicsAnchor object from the layout and destroys it.
+*/
+QGraphicsAnchor::~QGraphicsAnchor()
+{
+}
+
+/*!
+ Set the spacing for the anchor to \a spacing.
+
+ \sa spacing(), unsetSpacing()
+*/
+void QGraphicsAnchor::setSpacing(qreal spacing)
+{
+ Q_D(QGraphicsAnchor);
+ d->setSpacing(spacing);
+}
+
+/*!
+ Returns the spacing for the anchor
+
+ \sa setSpacing()
+*/
+qreal QGraphicsAnchor::spacing() const
+{
+ Q_D(const QGraphicsAnchor);
+ return d->spacing();
+}
+
+/*!
+ Resets the spacing of the anchor point to be the default spacing. Depending on the anchor type,
+ the default spacing is either 0 or a value returned from the style.
+
+ \sa setSpacing(), spacing(), QGraphicsAnchorLayout::anchor()
+*/
+void QGraphicsAnchor::unsetSpacing()
+{
+ Q_D(QGraphicsAnchor);
+ d->unsetSpacing();
+}
+
/*!
Constructs a QGraphicsAnchorLayout instance. \a parent is passed to
QGraphicsLayout's constructor.
@@ -136,17 +185,30 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout()
* the default vertical spacing). For all other anchor combinations, the spacing will be 0.
* All anchoring functions will follow this rule.
*
- * The spacing can also be set manually by using setAnchorSpacing() method.
+ * The spacing can also be set manually by using QGraphicsAnchor::setSpacing() method.
*
- * \sa removeAnchor(), addCornerAnchors(), addLeftAndRightAnchors(), addTopAndBottomAnchors(),
- * addAllAnchors()
+ * \sa addCornerAnchors(), addAnchors()
*/
-void QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
+QGraphicsAnchor *
+QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
{
Q_D(QGraphicsAnchorLayout);
- d->anchor(firstItem, firstEdge, secondItem, secondEdge);
+ QGraphicsAnchor *a = d->anchor(firstItem, firstEdge, secondItem, secondEdge);
invalidate();
+ return a;
+}
+
+/*!
+ Returns the anchor between the anchor points defined by \a firstItem and \a firstEdge and
+ \a secondItem and \a secondEdge. If there is no such anchor, the function will return 0.
+*/
+QGraphicsAnchor *
+QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
+{
+ Q_D(QGraphicsAnchorLayout);
+ return d->getAnchor(firstItem, firstEdge, secondItem, secondEdge);
}
/*!
@@ -195,6 +257,37 @@ void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem,
}
/*!
+ Anchors two or four edges of \a firstItem with the corresponding edges of \secondItem,
+ so that \a firstItem has the same size as \a secondItem in the dimensions specified by
+ \a orientation.
+
+ Calling this convenience function with the following arguments
+ \code
+ l->addAnchors(firstItem, secondItem, Qt::Horizontal)
+ \endcode
+
+ is the same as
+
+ \code
+ l->addAnchor(firstItem, Qt::AnchorLeft, secondItem, Qt::AnchorLeft);
+ l->addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
+ \endcode
+*/
+void QGraphicsAnchorLayout::addAnchors(QGraphicsLayoutItem *firstItem,
+ QGraphicsLayoutItem *secondItem,
+ Qt::Orientations orientations)
+{
+ if (orientations & Qt::Horizontal) {
+ addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft);
+ addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
+ }
+ if (orientations & Qt::Vertical) {
+ addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop);
+ addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom);
+ }
+}
+
+/*!
\fn QGraphicsAnchorLayout::addLeftAndRightAnchors(QGraphicsLayoutItem *firstItem, QGraphicsLayoutItem *secondItem)
Anchors the left and right edges of \a firstItem to the same edges of
@@ -234,86 +327,6 @@ void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem,
*/
/*!
- Set the spacing between the anchor point defined by \a firstItem and \a firstEdge and
- \a secondItem and \a secondEdge to be \a spacing.
-*/
-void QGraphicsAnchorLayout::setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge,
- qreal spacing)
-{
- Q_D(QGraphicsAnchorLayout);
-
- if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, &spacing)) {
- qWarning("setAnchorSpacing: The anchor does not exist.");
- return;
- }
- invalidate();
-}
-
-/*!
- Returns the spacing between the anchor point defined by \a firstItem and \a firstEdge and
- \a secondItem and \a secondEdge. The anchor must exist.
-*/
-qreal QGraphicsAnchorLayout::anchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) const
-{
- Q_D(const QGraphicsAnchorLayout);
- qreal size = 0;
- if (!d->anchorSize(firstItem, firstEdge, secondItem, secondEdge, 0, &size)) {
- qWarning("anchorSpacing: The anchor does not exist.");
- }
- return size;
-}
-
-/*!
- Resets the spacing between the anchor point defined by \a firstItem and \a firstEdge and
- \a secondItem and \a secondEdge to be the default spacing. Depending on the anchor type, the
- default spacing is either 0 or a value returned from the style.
-
- \sa setAnchorSpacing(), anchorSpacing(), addAnchor()
-*/
-void QGraphicsAnchorLayout::unsetAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
-{
- Q_D(QGraphicsAnchorLayout);
-
- if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, 0)) {
- qWarning("unsetAnchorSpacing: The anchor does not exist.");
- }
- invalidate();
-}
-
-/*!
- Removes the anchor between the edge \a firstEdge of item \a firstItem and the edge \a secondEdge
- of item \a secondItem. If such an anchor does not exist, the layout will be left unchanged.
-*/
-void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge)
-{
- Q_D(QGraphicsAnchorLayout);
- if ((firstItem == 0) || (secondItem == 0)) {
- qWarning("QGraphicsAnchorLayout::removeAnchor: "
- "Cannot remove anchor between NULL items");
- return;
- }
-
- if (firstItem == secondItem) {
- qWarning("QGraphicsAnchorLayout::removeAnchor: "
- "Cannot remove anchor from the item to itself");
- return;
- }
-
- if (d->edgeOrientation(secondEdge) != d->edgeOrientation(firstEdge)) {
- qWarning("QGraphicsAnchorLayout::removeAnchor: "
- "Cannot remove anchor from edges of different orientations");
- return;
- }
-
- d->removeAnchor(firstItem, firstEdge, secondItem, secondEdge);
- invalidate();
-}
-
-/*!
Sets the default horizontal spacing for the anchor layout to \a spacing.
\sa horizontalSpacing(), setVerticalSpacing(), setSpacing()
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.h b/src/gui/graphicsview/qgraphicsanchorlayout.h
index 70b73ef..d9a87ba 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.h
@@ -54,41 +54,44 @@ QT_MODULE(Gui)
#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
+class QGraphicsAnchorPrivate;
+class QGraphicsAnchorLayout;
class QGraphicsAnchorLayoutPrivate;
+class Q_GUI_EXPORT QGraphicsAnchor : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing)
+public:
+ void setSpacing(qreal spacing);
+ void unsetSpacing();
+ qreal spacing() const;
+ ~QGraphicsAnchor();
+private:
+ QGraphicsAnchor(QGraphicsAnchorLayout *parent);
+
+ Q_DECLARE_PRIVATE(QGraphicsAnchor)
+
+ friend class QGraphicsAnchorLayoutPrivate;
+};
+
class Q_GUI_EXPORT QGraphicsAnchorLayout : public QGraphicsLayout
{
public:
QGraphicsAnchorLayout(QGraphicsLayoutItem *parent = 0);
virtual ~QGraphicsAnchorLayout();
- void addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
+ QGraphicsAnchor *addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
+ QGraphicsAnchor *anchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
void addCornerAnchors(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner,
QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner);
- inline void addLeftAndRightAnchors(QGraphicsLayoutItem *firstItem,
- QGraphicsLayoutItem *secondItem);
-
- inline void addTopAndBottomAnchors(QGraphicsLayoutItem *firstItem,
- QGraphicsLayoutItem *secondItem);
-
- inline void addAllAnchors(QGraphicsLayoutItem *firstItem,
- QGraphicsLayoutItem *secondItem);
-
- void setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge,
- qreal spacing);
-
- qreal anchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) const;
-
- void unsetAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
-
- void removeAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
- QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
+ void addAnchors(QGraphicsLayoutItem *firstItem,
+ QGraphicsLayoutItem *secondItem,
+ Qt::Orientations orientations = Qt::Horizontal | Qt::Vertical);
void setHorizontalSpacing(qreal spacing);
void setVerticalSpacing(qreal spacing);
@@ -108,29 +111,9 @@ protected:
private:
Q_DISABLE_COPY(QGraphicsAnchorLayout)
Q_DECLARE_PRIVATE(QGraphicsAnchorLayout)
-};
-
-void QGraphicsAnchorLayout::addLeftAndRightAnchors(QGraphicsLayoutItem *firstItem,
- QGraphicsLayoutItem *secondItem)
-{
- addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft);
- addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight);
-}
-
-void QGraphicsAnchorLayout::addTopAndBottomAnchors(QGraphicsLayoutItem *firstItem,
- QGraphicsLayoutItem *secondItem)
-{
- addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop);
- addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom);
-}
-
-void QGraphicsAnchorLayout::addAllAnchors(QGraphicsLayoutItem *firstItem,
- QGraphicsLayoutItem *secondItem)
-{
- addLeftAndRightAnchors(firstItem, secondItem);
- addTopAndBottomAnchors(firstItem, secondItem);
-}
+ friend class QGraphicsAnchor;
+};
#endif
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index f81ede0..a37ec96 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -51,6 +51,47 @@
QT_BEGIN_NAMESPACE
+
+QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version)
+ : QObjectPrivate(version), layoutPrivate(0), data(0)
+{
+}
+
+QGraphicsAnchorPrivate::~QGraphicsAnchorPrivate()
+{
+ layoutPrivate->deleteAnchorData(data);
+}
+
+void QGraphicsAnchorPrivate::setSpacing(qreal value)
+{
+ if (data) {
+ layoutPrivate->setAnchorSize(data, &value);
+ } else {
+ qWarning("QGraphicsAnchor::setSpacing: The anchor does not exist.");
+ }
+}
+
+void QGraphicsAnchorPrivate::unsetSpacing()
+{
+ if (data) {
+ layoutPrivate->setAnchorSize(data, 0);
+ } else {
+ qWarning("QGraphicsAnchor::setSpacing: The anchor does not exist.");
+ }
+}
+
+qreal QGraphicsAnchorPrivate::spacing() const
+{
+ qreal size = 0;
+ if (data) {
+ layoutPrivate->anchorSize(data, 0, &size, 0);
+ } else {
+ qWarning("QGraphicsAnchor::setSpacing: The anchor does not exist.");
+ }
+ return size;
+}
+
+
void AnchorData::refreshSizeHints(qreal effectiveSpacing)
{
if (!isLayoutAnchor && from->m_item == to->m_item) {
@@ -998,29 +1039,29 @@ void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem *
* Helper function that is called from the anchor functions in the public API.
* If \a spacing is 0, it will pick up the spacing defined by the style.
*/
-void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem,
- Qt::AnchorPoint firstEdge,
- QGraphicsLayoutItem *secondItem,
- Qt::AnchorPoint secondEdge,
- qreal *spacing)
+QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem,
+ Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem,
+ Qt::AnchorPoint secondEdge,
+ qreal *spacing)
{
Q_Q(QGraphicsAnchorLayout);
if ((firstItem == 0) || (secondItem == 0)) {
qWarning("QGraphicsAnchorLayout::addAnchor(): "
"Cannot anchor NULL items");
- return;
+ return 0;
}
if (firstItem == secondItem) {
qWarning("QGraphicsAnchorLayout::addAnchor(): "
"Cannot anchor the item to itself");
- return;
+ return 0;
}
if (edgeOrientation(secondEdge) != edgeOrientation(firstEdge)) {
qWarning("QGraphicsAnchorLayout::addAnchor(): "
"Cannot anchor edges of different orientations");
- return;
+ return 0;
}
// Guarantee that the graph is no simplified when adding this anchor,
@@ -1079,6 +1120,7 @@ void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem,
data = new AnchorData(-*spacing);
addAnchor(secondItem, secondEdge, firstItem, firstEdge, data);
}
+ return acquireGraphicsAnchor(data);
}
void QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem,
@@ -1117,77 +1159,97 @@ void QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem,
graph[edgeOrientation(firstEdge)].createEdge(v1, v2, data);
}
+QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::getAnchor(QGraphicsLayoutItem *firstItem,
+ Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem,
+ Qt::AnchorPoint secondEdge)
+{
+ Orientation orient = edgeOrientation(firstEdge);
+ restoreSimplifiedGraph(orient);
+
+ AnchorVertex *v1 = internalVertex(firstItem, firstEdge);
+ AnchorVertex *v2 = internalVertex(secondItem, secondEdge);
+
+ QGraphicsAnchor *graphicsAnchor = 0;
+
+ AnchorData *data = graph[orient].edgeData(v1, v2);
+ if (data)
+ graphicsAnchor = acquireGraphicsAnchor(data);
+ return graphicsAnchor;
+}
+
void QGraphicsAnchorLayoutPrivate::removeAnchor(QGraphicsLayoutItem *firstItem,
Qt::AnchorPoint firstEdge,
QGraphicsLayoutItem *secondItem,
Qt::AnchorPoint secondEdge)
{
- // Guarantee that the graph is no simplified when adding this anchor,
- // anchor manipulation always happen in the full graph
- restoreSimplifiedGraph(edgeOrientation(firstEdge));
-
- // Look for both vertices
- AnchorVertex *v1 = internalVertex(firstItem, firstEdge);
- AnchorVertex *v2 = internalVertex(secondItem, secondEdge);
+ removeAnchor_helper(internalVertex(firstItem, firstEdge),
+ internalVertex(secondItem, secondEdge));
+}
+void QGraphicsAnchorLayoutPrivate::removeAnchor_helper(AnchorVertex *v1, AnchorVertex *v2)
+{
Q_ASSERT(v1 && v2);
+ // Guarantee that the graph is no simplified when removing this anchor,
+ // anchor manipulation always happen in the full graph
+ Orientation o = edgeOrientation(v1->m_edge);
+ restoreSimplifiedGraph(o);
// Remove edge from graph
- graph[edgeOrientation(firstEdge)].removeEdge(v1, v2);
+ graph[o].removeEdge(v1, v2);
// Decrease vertices reference count (may trigger a deletion)
- removeInternalVertex(firstItem, firstEdge);
- removeInternalVertex(secondItem, secondEdge);
+ removeInternalVertex(v1->m_item, v1->m_edge);
+ removeInternalVertex(v2->m_item, v2->m_edge);
}
-bool QGraphicsAnchorLayoutPrivate::setAnchorSize(const QGraphicsLayoutItem *firstItem,
- Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem,
- Qt::AnchorPoint secondEdge,
- const qreal *anchorSize)
+/*!
+ \internal
+ Only called from outside. (calls invalidate())
+*/
+void QGraphicsAnchorLayoutPrivate::deleteAnchorData(AnchorData *data)
{
+ Q_Q(QGraphicsAnchorLayout);
+ removeAnchor_helper(data->from, data->to);
+ q->invalidate();
+}
+
+/*!
+ \internal
+ Only called from outside. (calls invalidate())
+*/
+void QGraphicsAnchorLayoutPrivate::setAnchorSize(AnchorData *data, const qreal *anchorSize)
+{
+ Q_Q(QGraphicsAnchorLayout);
// ### we can avoid restoration if we really want to, but we would have to
// search recursively through all composite anchors
- restoreSimplifiedGraph(edgeOrientation(firstEdge));
- AnchorVertex *v1 = internalVertex(firstItem, firstEdge);
- AnchorVertex *v2 = internalVertex(secondItem, secondEdge);
-
- AnchorData *data = graph[edgeOrientation(firstEdge)].edgeData(v1, v2);
- if (data) {
- if (anchorSize) {
- data->setFixedSize(*anchorSize);
- } else {
- data->unsetSize();
- }
+ Q_ASSERT(data);
+ restoreSimplifiedGraph(edgeOrientation(data->from->m_edge));
+ if (anchorSize) {
+ data->setFixedSize(*anchorSize);
+ } else {
+ data->unsetSize();
}
- return data;
+ q->invalidate();
}
-bool QGraphicsAnchorLayoutPrivate::anchorSize(const QGraphicsLayoutItem *firstItem,
- Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem,
- Qt::AnchorPoint secondEdge,
+void QGraphicsAnchorLayoutPrivate::anchorSize(const AnchorData *data,
qreal *minSize,
qreal *prefSize,
qreal *maxSize) const
{
Q_ASSERT(minSize || prefSize || maxSize);
+ Q_ASSERT(data);
QGraphicsAnchorLayoutPrivate *that = const_cast<QGraphicsAnchorLayoutPrivate *>(this);
- that->restoreSimplifiedGraph(edgeOrientation(firstEdge));
- AnchorVertex *v1 = internalVertex(firstItem, firstEdge);
- AnchorVertex *v2 = internalVertex(secondItem, secondEdge);
-
- AnchorData *data = that->graph[edgeOrientation(firstEdge)].edgeData(v1, v2);
- if (data) {
- if (minSize)
- *minSize = data->minSize;
- if (prefSize)
- *prefSize = data->prefSize;
- if (maxSize)
- *maxSize = data->maxSize;
- }
- return data;
+ that->restoreSimplifiedGraph(edgeOrientation(data->from->m_edge));
+
+ if (minSize)
+ *minSize = data->minSize;
+ if (prefSize)
+ *prefSize = data->prefSize;
+ if (maxSize)
+ *maxSize = data->maxSize;
}
AnchorVertex *QGraphicsAnchorLayoutPrivate::addInternalVertex(QGraphicsLayoutItem *item,
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index 31da1a1..f701c3f 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -54,6 +54,7 @@
//
#include <QGraphicsWidget>
+#include <private/qobject_p.h>
#include "qgraphicslayout_p.h"
#include "qgraphicsanchorlayout.h"
@@ -153,6 +154,7 @@ struct AnchorData : public QSimplexVariable {
minSize(minimumSize), prefSize(preferredSize),
maxSize(maximumSize), sizeAtMinimum(preferredSize),
sizeAtPreferred(preferredSize), sizeAtMaximum(preferredSize),
+ graphicsAnchor(0),
skipInPreferred(0), type(Normal), hasSize(true),
isLayoutAnchor(false) {}
@@ -160,6 +162,7 @@ struct AnchorData : public QSimplexVariable {
: QSimplexVariable(), from(0), to(0),
minSize(size), prefSize(size), maxSize(size),
sizeAtMinimum(size), sizeAtPreferred(size), sizeAtMaximum(size),
+ graphicsAnchor(0),
skipInPreferred(0), type(Normal), hasSize(true),
isLayoutAnchor(false) {}
@@ -167,6 +170,7 @@ struct AnchorData : public QSimplexVariable {
: QSimplexVariable(), from(0), to(0),
minSize(0), prefSize(0), maxSize(0),
sizeAtMinimum(0), sizeAtPreferred(0), sizeAtMaximum(0),
+ graphicsAnchor(0),
skipInPreferred(0), type(Normal), hasSize(false),
isLayoutAnchor(false) {}
@@ -215,6 +219,7 @@ struct AnchorData : public QSimplexVariable {
qreal sizeAtMinimum;
qreal sizeAtPreferred;
qreal sizeAtMaximum;
+ QGraphicsAnchor *graphicsAnchor;
uint skipInPreferred : 1;
uint type : 2; // either Normal, Sequential or Parallel
@@ -226,6 +231,7 @@ protected:
minSize(size), prefSize(size),
maxSize(size), sizeAtMinimum(size),
sizeAtPreferred(size), sizeAtMaximum(size),
+ graphicsAnchor(0),
skipInPreferred(0), type(type), hasSize(true),
isLayoutAnchor(false) {}
};
@@ -309,6 +315,28 @@ public:
QSet<AnchorData *> negatives;
};
+class QGraphicsAnchorLayoutPrivate;
+/*!
+ \internal
+*/
+class QGraphicsAnchorPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QGraphicsAnchor)
+
+public:
+ explicit QGraphicsAnchorPrivate(int version = QObjectPrivateVersion);
+ ~QGraphicsAnchorPrivate();
+
+ void setSpacing(qreal value);
+ void unsetSpacing();
+ qreal spacing() const;
+
+ QGraphicsAnchorLayoutPrivate *layoutPrivate;
+ AnchorData *data;
+};
+
+
+
/*!
\internal
@@ -365,12 +393,22 @@ public:
void removeCenterAnchors(QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge, bool substitute = true);
void removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation);
+ QGraphicsAnchor *acquireGraphicsAnchor(AnchorData *data)
+ {
+ Q_Q(QGraphicsAnchorLayout);
+ if (!data->graphicsAnchor) {
+ data->graphicsAnchor = new QGraphicsAnchor(q);
+ data->graphicsAnchor->d_func()->data = data;
+ }
+ return data->graphicsAnchor;
+ }
+
// helper function used by the 4 API functions
- void anchor(QGraphicsLayoutItem *firstItem,
- Qt::AnchorPoint firstEdge,
- QGraphicsLayoutItem *secondItem,
- Qt::AnchorPoint secondEdge,
- qreal *spacing = 0);
+ QGraphicsAnchor *anchor(QGraphicsLayoutItem *firstItem,
+ Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem,
+ Qt::AnchorPoint secondEdge,
+ qreal *spacing = 0);
// Anchor Manipulation methods
void addAnchor(QGraphicsLayoutItem *firstItem,
@@ -379,21 +417,17 @@ public:
Qt::AnchorPoint secondEdge,
AnchorData *data);
+ QGraphicsAnchor *getAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge,
+ QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge);
+
void removeAnchor(QGraphicsLayoutItem *firstItem,
Qt::AnchorPoint firstEdge,
QGraphicsLayoutItem *secondItem,
Qt::AnchorPoint secondEdge);
-
- bool setAnchorSize(const QGraphicsLayoutItem *firstItem,
- Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem,
- Qt::AnchorPoint secondEdge,
- const qreal *anchorSize);
-
- bool anchorSize(const QGraphicsLayoutItem *firstItem,
- Qt::AnchorPoint firstEdge,
- const QGraphicsLayoutItem *secondItem,
- Qt::AnchorPoint secondEdge,
+ void removeAnchor_helper(AnchorVertex *v1, AnchorVertex *v2);
+ void deleteAnchorData(AnchorData *data);
+ void setAnchorSize(AnchorData *data, const qreal *anchorSize);
+ void anchorSize(const AnchorData *data,
qreal *minSize = 0,
qreal *prefSize = 0,
qreal *maxSize = 0) const;