summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-10-20 21:54:43 (GMT)
committerEduardo M. Fleury <eduardo.fleury@openbossa.org>2009-10-26 22:17:55 (GMT)
commitfa767bf7b104a4e44e4e283522f0dfd942094375 (patch)
treedc069c09dc298ac914317ed1c60574eac6c3c343 /src/gui
parent3f29c77a26d0a898ca3a7c9c6715da90f1ecc50a (diff)
downloadQt-fa767bf7b104a4e44e4e283522f0dfd942094375.zip
Qt-fa767bf7b104a4e44e4e283522f0dfd942094375.tar.gz
Qt-fa767bf7b104a4e44e4e283522f0dfd942094375.tar.bz2
QGAL (QSimplex): Make deep copy of constraints inside QSimplex
The idea is to allow QSimplex solver to modify the constraints without breaking other parts of the code that rely on the original ones. Signed-off-by: Eduardo M. Fleury <eduardo.fleury@openbossa.org> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp2
-rw-r--r--src/gui/graphicsview/qsimplex_p.cpp15
-rw-r--r--src/gui/graphicsview/qsimplex_p.h8
3 files changed, 13 insertions, 12 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index a83e619..b4666c6 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -2459,7 +2459,7 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList<QSimplexConstraint *>
*min = simplex.solveMin();
// Save sizeAtMinimum results
- QList<QSimplexVariable *> variables = simplex.constraintsVariables();
+ QList<AnchorData *> variables = getVariables(constraints);
for (int i = 0; i < variables.size(); ++i) {
AnchorData *ad = static_cast<AnchorData *>(variables[i]);
Q_ASSERT(ad->result >= ad->minSize || qFuzzyCompare(ad->result, ad->minSize));
diff --git a/src/gui/graphicsview/qsimplex_p.cpp b/src/gui/graphicsview/qsimplex_p.cpp
index b8f8fb4..b3997fa 100644
--- a/src/gui/graphicsview/qsimplex_p.cpp
+++ b/src/gui/graphicsview/qsimplex_p.cpp
@@ -108,10 +108,8 @@ void QSimplex::clearDataStructures()
// Constraints
for (int i = 0; i < constraints.size(); ++i) {
delete constraints[i]->helper.first;
- constraints[i]->helper.first = 0;
- constraints[i]->helper.second = 0.0;
delete constraints[i]->artificial;
- constraints[i]->artificial = 0;
+ delete constraints[i];
}
constraints.clear();
@@ -137,7 +135,16 @@ bool QSimplex::setConstraints(const QList<QSimplexConstraint *> newConstraints)
if (newConstraints.isEmpty())
return true; // we are ok with no constraints
- constraints = newConstraints;
+
+ // Make deep copy of constraints. We need this copy because we may change
+ // them in the simplification method.
+ for (int i = 0; i < newConstraints.size(); ++i) {
+ QSimplexConstraint *c = new QSimplexConstraint;
+ c->constant = newConstraints[i]->constant;
+ c->ratio = newConstraints[i]->ratio;
+ c->variables = newConstraints[i]->variables;
+ constraints << c;
+ }
///////////////////////////////////////
// Prepare variables and constraints //
diff --git a/src/gui/graphicsview/qsimplex_p.h b/src/gui/graphicsview/qsimplex_p.h
index 423f9bc..5ec13c3 100644
--- a/src/gui/graphicsview/qsimplex_p.h
+++ b/src/gui/graphicsview/qsimplex_p.h
@@ -106,7 +106,7 @@ struct QSimplexConstraint
Q_ASSERT(constant > 0 || qFuzzyCompare(1, 1 + constant));
- if (qFuzzyCompare(1000 + leftHandSide, 1000 + constant))
+ if ((leftHandSide == constant) || qFuzzyCompare(1000 + leftHandSide, 1000 + constant))
return true;
switch (ratio) {
@@ -152,7 +152,6 @@ public:
qreal solveMin();
qreal solveMax();
- QList<QSimplexVariable *> constraintsVariables();
bool setConstraints(const QList<QSimplexConstraint *> constraints);
void setObjective(QSimplexConstraint *objective);
@@ -191,11 +190,6 @@ private:
qreal *matrix;
};
-inline QList<QSimplexVariable *> QSimplex::constraintsVariables()
-{
- return variables;
-}
-
inline qreal QSimplex::valueAt(int rowIndex, int columnIndex)
{
return matrix[rowIndex * columns + columnIndex];