Bug 116460 - cleanup layout should be smart in regards to number of columns
Summary: cleanup layout should be smart in regards to number of columns
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-16 00:42 UTC by Matthew Truch
Modified: 2005-11-22 22:59 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Truch 2005-11-16 00:42:40 UTC
Version:           1.2.0_svn_480257 (using KDE KDE 3.4.2)
OS:                Linux

Cleanup layout should be smarter in regards to number of columns.  When the user physically lays out the plots with a certain natural grid, cleanup layout shouldn't rearrange on a different grid.  Futhermore, if the user requests cleaning up on a different number of columns, cleaning up should try to keep the order of the plots the same even though there are a different number of columns.
Comment 1 Nicolas Brisset 2005-11-16 09:40:01 UTC
Would you agree that implementing feature #95030 would be approaching that goal ?
Comment 2 Andrew Walker 2005-11-16 22:39:09 UTC
I don't think these two issues are related, but I would agree that 95030 should be addressed. The number of plot columns is clearly a window property and should not be found in the plot dialog.
Comment 3 Netterfield 2005-11-17 03:55:30 UTC
I agree it is not a plot item.  But we don't have a window dialog anywhere 
(yet) and I don't think it belongs on the toolbar.  so.... The reason it is 
there is that you often want to consider how many columns you want when you 
are creating plots.  so... ?
Comment 4 Nicolas Brisset 2005-11-17 11:57:13 UTC
> I agree it is not a plot item.  But we don't have a window 
> dialog anywhere
> (yet) and I don't think it belongs on the toolbar.  so.... 

Let us wait and see what George has in mind. We can bring up the
discussion again later... or alternatively try to put it in the toolbar
and see what the users say (usability testing is sometimes the only way
to know). I personally don't see any problem with having it in the
toolbar, provided that it is updated when window focus changes. 

> The reason it is there is that you often want to consider how 
> many columns you want when you are creating plots.  so... ?

I think it is right to keep it here as well.
Comment 5 George Staikos 2005-11-17 15:59:02 UTC
On Thursday 17 November 2005 05:57, Nicolas Brisset wrote:
> discussion again later... or alternatively try to put it in the toolbar
> and see what the users say (usability testing is sometimes the only way


  I highly disagree with putting it in the toolbar.  I think we should keep 
the toolbar for toolbuttons only.
Comment 6 Nicolas Brisset 2005-11-17 16:10:32 UTC
OK, why not put it in the status bar then, like a lot of programs do for similar things (inkscape for example) ?
Comment 7 Netterfield 2005-11-17 18:04:46 UTC
It is a window property, not a global property or a plot property.  It belongs 
in the window/tlv dialog (which doesn't yet exist).  The 2nd best place 
remains where it is, since it is where it is used.
Comment 8 Andrew Walker 2005-11-22 22:59:08 UTC
SVN commit 482420 by arwalker:

BUG:116460 Attempt to preserve the inherent order of plots when regridding

 M  +81 -65    kstviewobject.cpp  
 M  +1 -0      kstviewobject.h  


--- trunk/extragear/graphics/kst/kst/kstviewobject.cpp #482419:482420
@@ -35,6 +35,7 @@
 #include "kstaccessibility.h"
 #include "kstdoc.h"
 #include "ksteditviewobjectdialog_i.h"
+#include "kstmath.h"
 #include "kstobject.h"
 #include "kstplotgroup.h"
 #include "kstsettings.h"
@@ -609,7 +610,7 @@
 
 void KstViewObject::cleanup(int cols) {
   KstViewObjectList childrenCopy;
-    
+
   for (KstViewObjectList::ConstIterator i = _children.begin(); i != _children.end(); ++i) {
     if ((*i)->followsFlow()) {
       childrenCopy.append(*i);
@@ -617,74 +618,85 @@
   }
   
   int cnt = childrenCopy.count();
-  if (cnt < 1) {
-    return;
-  }
-
-  // FIXME: don't allow regrid to a number of columns that will result in
-  //        >= height() plots in a column
-  if (!_onGrid) {
-    if (cols <= 0) {
-      cols = int(sqrt(cnt));
+  if (cnt > 0) {
+    // FIXME: don't allow regrid to a number of columns that will result in
+    //        >= height() plots in a column
+    if (!_onGrid) {
+      if (cols <= 0) {
+        cols = int(sqrt(cnt));
+      }
+      _onGrid = true;
+      _columns = QMAX(1, cols);
+    } else {
+      if (cols > 0) {
+        _columns = cols;
+      } else if (cols <= 0){
+        _columns = QMAX(1, int(sqrt(cnt)));
+      }
     }
-    _onGrid = true;
-    _columns = QMAX(1, cols);
-  } else {
-    if (cols > 0) {
-      _columns = cols;
-    } else if (cols <= 0){
-      _columns = QMAX(1, int(sqrt(cnt)));
-    }
-  }  
-  int rows = ( cnt + _columns - 1 ) / _columns;
-
-  double minDistance = 0.0;
-  int pos = 0;
-  int x = 0;
-  int y = 0;
-  int w = _geom.width() / _columns;
-  int h = _geom.height() / rows;
+    int rows = ( cnt + _columns - 1 ) / _columns;
     
-  //kstdDebug() << "cleanup with w=" << w << " and h=" << h << endl;
-  //kstdDebug() << "columns=" << _columns  << endl;
-  for (int i = 0; i < cnt; ++i) {
-    KstViewObjectList::Iterator nearest = childrenCopy.end();
-    QPoint pt(x, y);
-    QSize sz(w, h);
-
-    // adjust the last column to be sure that we don't spill over
-    if (pos % _columns == _columns - 1) {
-      sz.setWidth(_geom.width() - x);
-    }
-
-    // adjust the last row to be sure that we don't spill over
-    if (pos / _columns == rows - 1) {
-      sz.setHeight(_geom.height() - y);
-    }
-
-    for (KstViewObjectList::Iterator it = childrenCopy.begin(); it != childrenCopy.end(); ++it) {
-      // find plot closest to the desired position, based on top-left corner...
-      double distance = double((x - (*it)->geometry().x()) * (x - (*it)->geometry().x())) + 
-                        double((y - (*it)->geometry().y()) * (y - (*it)->geometry().y()));
-      if (it == childrenCopy.begin() || distance < minDistance) {
-        minDistance = distance;
-        nearest = it;
+    //
+    // the following is an attempt to arrange objects on a grid.
+    //  This should behave as both a snap-to-grid when the objects
+    //  are already roughly aligned to the desired grid, but should
+    //  also act to retain the inherent order when this is not the
+    //  case. The inherent order is defined by identifying objects
+    //  from left-to-right and top-to-bottom based on the position
+    //  of their top-left corner.
+    //
+    double minDistance = 0.0;
+    double distance;
+    int pos = 0;
+    int x = 0;
+    int y = 0;
+    int w = _geom.width() / _columns;
+    int h = _geom.height() / rows;
+      
+    //kstdDebug() << "cleanup with w=" << w << " and h=" << h << endl;
+    //kstdDebug() << "columns=" << _columns  << endl;
+    for (int i = 0; i < cnt; ++i) {
+      KstViewObjectList::Iterator nearest = childrenCopy.end();
+      QPoint pt(x, y);
+      QSize sz(w, h);
+  
+      // adjust the last column to be sure that we don't spill over
+      if (pos % _columns == _columns - 1) {
+        sz.setWidth(_geom.width() - x);
       }
+  
+      // adjust the last row to be sure that we don't spill over
+      if (pos / _columns == rows - 1) {
+        sz.setHeight(_geom.height() - y);
+      }
+  
+      for (KstViewObjectList::Iterator it = childrenCopy.begin(); it != childrenCopy.end(); ++it) {
+        distance  = ceil( (double)rows * 2.0 * (*it)->aspectRatio().y );
+        distance  = rows * d2i( distance );
+        distance += (*it)->aspectRatio().x * rows;
+        distance += (*it)->aspectRatio().y;
+        
+        if (it == childrenCopy.begin() || distance < minDistance) {
+          minDistance = distance;
+          nearest = it;
+        }
+      }
+  
+      if (nearest != childrenCopy.end()) {
+        KstViewObjectPtr vop = *nearest;
+        vop->move(pt);
+        vop->resize(sz);
+        vop->lowerToBottom();
+        childrenCopy.remove(vop);
+      }
+  
+      if (++pos % _columns == 0) {
+        x = 0;
+        y += h;
+      } else {
+        x += w;
+      }
     }
-
-    if (nearest != childrenCopy.end()) {
-      KstViewObjectPtr vop = *nearest;
-      vop->move(pt);
-      vop->resize(sz);
-      childrenCopy.remove(vop);
-    }
-
-    if (++pos % _columns == 0) {
-      x = 0;
-      y += h;
-    } else {
-      x += w;
-    }
   }
 }
 
@@ -808,6 +820,10 @@
 }
 
 
+const KstAspectRatio& KstViewObject::aspectRatio() const {
+  return _aspect;
+}
+
 const QRect& KstViewObject::geometry() const {
   return _geom;
 }
--- trunk/extragear/graphics/kst/kst/kstviewobject.h #482419:482420
@@ -94,6 +94,7 @@
     virtual void internalAlignment(KstPaintType type, QPainter& p, QRect& plotRegion);
     virtual QPoint position() const;
     virtual const QRect& geometry() const;
+    virtual const KstAspectRatio& aspectRatio() const;
     virtual QRect surroundingGeometry() const;
     virtual QRect contentsRect() const;
     virtual void setContentsRect(const QRect& rect);