[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: koffice/libs/flake/tests
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2009-09-28 18:45:51
Message-ID: 200909282045.53274.t.zachmann () zagge ! de
[Download RAW message or body]

On Sun September 27 2009, Thomas Zander wrote:
> On Sunday 27. September 2009 12.29.32 Thorsten Zachmann wrote:
> > We also need a resolution to the problem that when loading a file a
> > hierarchy of shapes with layers is not a must. Otherwise we will reorder
> > the shape which should be avoided.
> 
> I don't understand this.
> 
> > As said I will work on this. I will post for review before committing. If
> > you want to fix all this please let me know so that we don't do the work
> > twice.
> 
> I just made a quick patch, which I sent, to clarify what I thought was a
> good solution.
> I see that Jans solution is very similar, so I'll leave him and you to it.
> No need to duplicate work :)

I will continue to work on this.

> You say you did some benchmarking, thats certainly good. it would be good
>  to test if using a QList like I see in the patch from Jan is not too much
>  slower. I tried to avoid it using the solution I pasted.
> Anyway, thats just a thought.

I had a very similar idea like Jan but as the benchmarking showed that is much 
slower (8-10 times) than the algorithm you posted. I have worked a bit on your 
idea and improved it so that it has the correct result.

Patch is attached.

Thorsten



["order.diff" (text/x-patch)]

Index: KoShape.cpp
===================================================================
--- KoShape.cpp	(revision 1028738)
+++ KoShape.cpp	(working copy)
@@ -383,22 +383,35 @@ QMatrix KoShape::transformation() const
 
 bool KoShape::compareShapeZIndex(KoShape *s1, KoShape *s2)
 {
-    int diff = s1->zIndex() - s2->zIndex();
-    if (diff == 0) {
-        KoShape *s = s1->parent();
-        while (s) {
-            if (s == s2) // s1 is a child of s2
-                return false; // children are always on top of their parents.
-            s = s->parent();
+    bool foundCommonParent = false;
+    KoShape *parentShapeS1 = s1;
+    KoShape *parentShapeS2 = s2;
+    int index1 = parentShapeS1->zIndex();
+    int index2 = parentShapeS2->zIndex();
+    while (parentShapeS1 && !foundCommonParent) {
+        parentShapeS2 = s2;
+        index2 = parentShapeS2->zIndex();
+        while (parentShapeS2) {
+            if (parentShapeS2 == parentShapeS1) {
+                foundCommonParent = true;
+                break;
+            }
+            index2 = parentShapeS2->zIndex();
+            parentShapeS2 = parentShapeS2->parent();
         }
-        s = s2->parent();
-        while (s) {
-            if (s == s1) // s2 is a child of s1
-                return true;
-            s = s->parent();
+
+        if (!foundCommonParent) {
+            index1 = parentShapeS1->zIndex();
+            parentShapeS1 = parentShapeS1->parent();
         }
     }
-    return diff < 0;
+    if (s1 == parentShapeS2) {
+        return true;
+    }
+    else if (s2 == parentShapeS1) {
+        return false;
+    }
+    return index1 < index2;
 }
 
 void KoShape::setParent(KoShapeContainer *parent)
@@ -421,8 +434,6 @@ void KoShape::setParent(KoShapeContainer
 int KoShape::zIndex() const
 {
     Q_D(const KoShape);
-    if (parent()) // we can't be under our parent...
-        return qMax((int) d->zIndex, parent()->zIndex());
     return d->zIndex;
 }
 


_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic