summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>2009-10-19 10:30:52 (GMT)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>2009-10-26 20:03:31 (GMT)
commit96f59cb98c248185a3873f06d0e1a2e7652d8cec (patch)
tree8a519ad2457863f983b2cf5daa7056a4b828c58d /src/gui/graphicsview
parent9a1ee410d24321e7eedaea6bb4f1b21fcc6fb427 (diff)
downloadQt-96f59cb98c248185a3873f06d0e1a2e7652d8cec.zip
Qt-96f59cb98c248185a3873f06d0e1a2e7652d8cec.tar.gz
Qt-96f59cb98c248185a3873f06d0e1a2e7652d8cec.tar.bz2
QGAL: complex anchors can indicate errors when refreshing sizehint
Now the refreshSizeHints() returns a boolean, and the parallel anchor will return false in unfeasible cases, e.g. one anchor has maximum size smaller than other minimum size. Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> Reviewed-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org>
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp43
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h10
2 files changed, 31 insertions, 22 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index 8c8c303..a92a63e 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -141,7 +141,7 @@ static void internalSizeHints(QSizePolicy::Policy policy,
*expSize = *prefSize;
}
-void AnchorData::refreshSizeHints(qreal effectiveSpacing)
+bool AnchorData::refreshSizeHints(qreal effectiveSpacing)
{
const bool isInternalAnchor = from->m_item == to->m_item;
@@ -164,7 +164,7 @@ void AnchorData::refreshSizeHints(qreal effectiveSpacing)
maxSize = QWIDGETSIZE_MAX;
if (hasCenter)
maxSize /= 2;
- return;
+ return true;
} else {
QGraphicsLayoutItem *item = from->m_item;
@@ -214,6 +214,8 @@ void AnchorData::refreshSizeHints(qreal effectiveSpacing)
sizeAtPreferred = prefSize;
sizeAtExpanding = prefSize;
sizeAtMaximum = prefSize;
+
+ return true;
}
void ParallelAnchorData::updateChildrenSizes()
@@ -227,26 +229,29 @@ void ParallelAnchorData::updateChildrenSizes()
secondEdge->updateChildrenSizes();
}
-void ParallelAnchorData::refreshSizeHints(qreal effectiveSpacing)
+bool ParallelAnchorData::refreshSizeHints(qreal effectiveSpacing)
{
- refreshSizeHints_helper(effectiveSpacing);
+ return refreshSizeHints_helper(effectiveSpacing);
}
-void ParallelAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
+bool ParallelAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
bool refreshChildren)
{
- if (refreshChildren) {
- firstEdge->refreshSizeHints(effectiveSpacing);
- secondEdge->refreshSizeHints(effectiveSpacing);
+ if (refreshChildren && (!firstEdge->refreshSizeHints(effectiveSpacing)
+ || !secondEdge->refreshSizeHints(effectiveSpacing))) {
+ return false;
}
- // ### should we warn if the parallel connection is invalid?
- // e.g. 1-2-3 with 10-20-30, the minimum of the latter is
- // bigger than the maximum of the former.
-
minSize = qMax(firstEdge->minSize, secondEdge->minSize);
maxSize = qMin(firstEdge->maxSize, secondEdge->maxSize);
+ // This condition means that the maximum size of one anchor being simplified is smaller than
+ // the minimum size of the other anchor. The consequence is that there won't be a valid size
+ // for this parallel setup.
+ if (minSize > maxSize) {
+ return false;
+ }
+
expSize = qMax(firstEdge->expSize, secondEdge->expSize);
expSize = qMin(expSize, maxSize);
@@ -258,6 +263,8 @@ void ParallelAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
sizeAtPreferred = prefSize;
sizeAtExpanding = prefSize;
sizeAtMaximum = prefSize;
+
+ return true;
}
/*!
@@ -362,12 +369,12 @@ void SequentialAnchorData::updateChildrenSizes()
}
}
-void SequentialAnchorData::refreshSizeHints(qreal effectiveSpacing)
+bool SequentialAnchorData::refreshSizeHints(qreal effectiveSpacing)
{
- refreshSizeHints_helper(effectiveSpacing);
+ return refreshSizeHints_helper(effectiveSpacing);
}
-void SequentialAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
+bool SequentialAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
bool refreshChildren)
{
minSize = 0;
@@ -379,8 +386,8 @@ void SequentialAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
AnchorData *edge = m_edges.at(i);
// If it's the case refresh children information first
- if (refreshChildren)
- edge->refreshSizeHints(effectiveSpacing);
+ if (refreshChildren && !edge->refreshSizeHints(effectiveSpacing))
+ return false;
minSize += edge->minSize;
prefSize += edge->prefSize;
@@ -393,6 +400,8 @@ void SequentialAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
sizeAtPreferred = prefSize;
sizeAtExpanding = prefSize;
sizeAtMaximum = prefSize;
+
+ return true;
}
#ifdef QT_DEBUG
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index d45c004..d4eb2d4 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -159,7 +159,7 @@ struct AnchorData : public QSimplexVariable {
type(Normal), hasSize(true), isLayoutAnchor(false) {}
virtual void updateChildrenSizes() {}
- virtual void refreshSizeHints(qreal effectiveSpacing);
+ virtual bool refreshSizeHints(qreal effectiveSpacing);
virtual ~AnchorData() {}
@@ -226,9 +226,9 @@ struct SequentialAnchorData : public AnchorData
}
virtual void updateChildrenSizes();
- virtual void refreshSizeHints(qreal effectiveSpacing);
+ virtual bool refreshSizeHints(qreal effectiveSpacing);
- void refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
+ bool refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
void setVertices(const QVector<AnchorVertex*> &vertices)
{
@@ -261,9 +261,9 @@ struct ParallelAnchorData : public AnchorData
}
virtual void updateChildrenSizes();
- virtual void refreshSizeHints(qreal effectiveSpacing);
+ virtual bool refreshSizeHints(qreal effectiveSpacing);
- void refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
+ bool refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
AnchorData* firstEdge;
AnchorData* secondEdge;