[Kst] branches/work/kst/portto4/kst

Barth Netterfield netterfield at astro.utoronto.ca
Fri Apr 9 19:53:27 CEST 2010


SVN commit 1113015 by netterfield:

Convince auto layout mode to not suck.



 M  +0 -2      devel-docs/Kst2Specs/Bugs  
 M  +4 -0      devel-docs/Kst2Specs/FixedBugs  
 M  +19 -9     src/libkstapp/gridlayouthelper.cpp  
 M  +3 -9      src/libkstapp/sharedaxisboxitem.cpp  
 M  +0 -1      src/libkstapp/sharedaxisboxitem.h  
 M  +3 -2      src/libkstapp/viewitem.cpp  


--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/Bugs #1113014:1113015
@@ -16,6 +16,4 @@
 
 Windows MEMleak
 
-------------------
 
-Cleanup layout totally sucks!
--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/FixedBugs #1113014:1113015
@@ -1208,3 +1208,7 @@
 displayed correctly on the axis labels, but just displays as the raw
 value in the status bar (on the lower left of the window).  This is both
 in "normal mode" and in "data mode".
+
+------------------
+
+Cleanup layout totally sucks!
--- branches/work/kst/portto4/kst/src/libkstapp/gridlayouthelper.cpp #1113014:1113015
@@ -55,7 +55,7 @@
 #include <math.h>
 #include <QDebug>
 
-// #define DEBUG_GRID_BUILDING 1
+#define DEBUG_GRID_BUILDING 0
 
 namespace Kst {
 
@@ -71,6 +71,8 @@
     // the item layout.
     // -----------------------------------------------------------------
 
+    // modified by cbn to have a tolerance of 1/8 the size of the smallest object
+
     // We need a list of both start and stop values for x- & y-axis
     QVector<int> x( itemList.count()*2 );
     QVector<int> y( itemList.count()*2 );
@@ -78,6 +80,8 @@
     // Using push_back would look nicer, but operator[] is much faster
     int index  = 0;
     ViewItem* v = 0;
+    int minWidth = itemList.at(0)->viewRect().width();
+    int minHeight = itemList.at(0)->viewRect().height();
     for (int i = 0; i < itemList.size(); ++i) {
         v = itemList.at(i);
         QRect itemPos = QRect(v->pos().toPoint(), v->viewRect().size().toSize());
@@ -85,6 +89,12 @@
         x[index+1] = itemPos.right();
         y[index]   = itemPos.top();
         y[index+1] = itemPos.bottom();
+        if (itemPos.width() < minWidth) {
+          minWidth = itemPos.width();
+        }
+        if (itemPos.height() < minHeight) {
+          minHeight = itemPos.height();
+        }
         index += 2;
     }
 
@@ -95,7 +105,7 @@
     if ( !x.empty() ) {
         for (QVector<int>::iterator current = x.begin() ;
              (current != x.end()) && ((current+1) != x.end()) ; )
-            if ( (*current == *(current+1)) )
+            if ( abs(*current - *(current+1)) < minWidth/8 )
                 x.erase(current+1);
             else
                 current++;
@@ -105,7 +115,7 @@
     if ( !y.empty() ) {
         for (QVector<int>::iterator current = y.begin() ;
              (current != y.end()) && ((current+1) != y.end()) ; )
-            if ( (*current == *(current+1)) )
+            if ( abs(*current - *(current+1)) < minHeight/8 )
                 y.erase(current+1);
             else
                 current++;
@@ -129,17 +139,17 @@
 
         // From left til right (not including)
         for (int cw=0; cw<x.size(); cw++) {
-            if (x[cw] == itemPos.left())
+            if (abs(x[cw] - itemPos.left()) <= minWidth/8)
                 c.setLeft(cw);
-            if (x[cw] <  itemPos.right())
+            if (x[cw] <  itemPos.right()+ minWidth/8)
                 c.setRight(cw);
         }
 
         // From top til bottom (not including)
         for (int ch=0; ch<y.size(); ch++) {
-            if (y[ch] == itemPos.top()   )
+            if (abs(y[ch] - itemPos.top()) < minHeight/8  )
                 c.setTop(ch);
-            if (y[ch] <  itemPos.bottom())
+            if (y[ch] <  itemPos.bottom() + minHeight/8)
                 c.setBottom(ch);
         }
 
@@ -164,8 +174,8 @@
 #endif
     QVector<int> skippedRows;
     QVector<int> skippedColumns;
-    for (int rows = c.bottom()-c.top(); rows >= 0; rows--)
-        for (int cols = c.right()-c.left(); cols >= 0; cols--) {
+    for (int rows = c.bottom()-c.top()-1; rows >= 0; rows--)
+        for (int cols = c.right()-c.left()-1; cols >= 0; cols--) {
             if (!(skippedRows.contains(c.top()+rows) || skippedColumns.contains(c.left()+cols))) {
               if (!setCell(c.top()+rows, c.left()+cols, w)) {
                 skippedRows.append(c.top()+rows);
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.cpp #1113014:1113015
@@ -149,7 +149,8 @@
     QList<QGraphicsItem*> list = parentView()->items();
     foreach (QGraphicsItem *item, list) {
       ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
-      if (!viewItem || !viewItem->isVisible() || viewItem == this ||  viewItem == parentItem() || !collidesWithItem(viewItem, Qt::IntersectsItemBoundingRect)) {
+      if (!viewItem || !viewItem->isVisible() || viewItem == this ||
+          viewItem == parentItem() || !collidesWithItem(viewItem, Qt::IntersectsItemBoundingRect)) {
         continue;
       }
 
@@ -344,13 +345,6 @@
 }
 
 
-QList<PlotItem*> SharedAxisBoxItem::getAllPlots() {
-  QList<PlotItem*> plots = _sharedPlots;
-  //plots << PlotItemManager::tiedZoomPlotsForView(parentView());
-
-  return plots;
-}
-
 QList<PlotItem*> SharedAxisBoxItem::getSharedPlots() {
   return _sharedPlots;
 }
@@ -388,7 +382,7 @@
 
 
 void SharedAxisBoxItem::applyZoom(const QRectF &projection, PlotItem* originPlotItem, bool applyX, bool applyY) {
-  QList<PlotItem*> allPlots = getAllPlots();
+  QList<PlotItem*> allPlots = getSharedPlots();
   QList<PlotItem*> plotTied;
   if (originPlotItem && 
       originPlotItem->isTiedZoom() && 
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.h #1113014:1113015
@@ -104,7 +104,6 @@
 
     QList<PlotItem*> getSharedPlots();
     QList<PlotItem*> getTiedPlots(PlotItem* originPlotItem);
-    QList<PlotItem*> getAllPlots();
 
     QAction *_breakAction;
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1113014:1113015
@@ -2008,8 +2008,9 @@
 
 
 void AppendLayoutCommand::undo() {
-  Q_ASSERT(_layout);
-  _layout->reset();
+  if (_layout) {
+    _layout->reset();
+  }
 }
 
 


More information about the Kst mailing list