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

Mike Fenton mike at staikos.net
Tue Jun 16 19:58:20 CEST 2009


SVN commit 982724 by fenton:

Fix layout bugs associated with multiple columns / rows in SharedAxisBoxes.
Add immediate sharing update when switching ShareX/ShareY settings.


 M  +14 -1     sharedaxisboxitem.cpp  
 M  +1 -0      sharedaxisboxitem.h  
 M  +26 -8     viewgridlayout.cpp  
 M  +2 -1      viewgridlayout.h  


--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.cpp #982723:982724
@@ -223,14 +223,27 @@
 
 void SharedAxisBoxItem::shareXAxis() {
   _shareX = !_shareX;
+  updateShare();
 }
 
 
 void SharedAxisBoxItem::shareYAxis() {
   _shareY = !_shareY;
+  updateShare();
 }
 
 
+void SharedAxisBoxItem::updateShare() {
+  if (!_shareX && !_shareY) {
+    breakShare();
+  } else {
+    ViewGridLayout::updateProjections(this, _shareX, _shareY);
+    setDirty();
+    update();
+  }
+}
+
+
 void SharedAxisBoxItem::addToMenuForContextEvent(QMenu &menu) {
   menu.addAction(_breakAction);
 }
@@ -362,7 +375,7 @@
 
 void SharedAxisBoxItem::zoomFixedExpression(const QRectF &projection, PlotItem* originPlotItem) {
 #if DEBUG_ZOOM
-  qDebug() << "zoomFixedExpression" << projection << "current" << projectionRect();
+  qDebug() << "zoomFixedExpression" << projection;
 #endif
   _xAxisZoomMode = PlotAxis::FixedExpression;
   _yAxisZoomMode = PlotAxis::FixedExpression;
--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.h #982723:982724
@@ -91,6 +91,7 @@
     virtual void creationPolygonChanged(View::CreationEvent event);
 
   private:
+    void updateShare();
     void highlightPlots(QList<PlotItem*> plots);
 
     QRectF computeRect(PlotAxis::ZoomMode xMode, PlotAxis::ZoomMode yMode);
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #982723:982724
@@ -286,7 +286,7 @@
     qreal rightPadding = rightMarginWidths[floor(plotItem->width()*PLOT_STANDARDIZATION_FACTOR)] - plotItem->rightMarginSize();
     qreal topPadding = topMarginWidths[floor(plotItem->height()*PLOT_STANDARDIZATION_FACTOR)] - plotItem->topMarginSize();
     qreal bottomPadding = bottomMarginHeights[floor(plotItem->height()*PLOT_STANDARDIZATION_FACTOR)] - plotItem->bottomMarginSize();
-
+  
     plotItem->setPadding(leftPadding, rightPadding, topPadding, bottomPadding);
   }
 }
@@ -391,6 +391,8 @@
   } else {
     _shareX = shareBox->isXAxisShared();
     _shareY = shareBox->isYAxisShared();
+    unshareAxis();
+    updateSharedAxis();
   }
 
   // Determine area of layout.  Minimal spacing on SharedAxisBoxItems.
@@ -492,7 +494,7 @@
   } else if (rowMode) {
     int totalHeight = 0;
     for (int i = 0; i < rowCount(); i++) {
-      totalHeight = topLabelBounds[i] + bottomLabelBounds[i];
+      totalHeight += topLabelBounds[i] + bottomLabelBounds[i];
     }
     totalProjWidth = layoutRect.width() - leftLabelBounds[0] - rightLabelBounds[columnCount() - 1];
     totalProjHeight = layoutRect.height() - totalHeight;
@@ -500,10 +502,10 @@
   } else if (colMode) {
     int totalWidth = 0;
     for (int i = 0; i < columnCount(); i++) {
-      totalWidth = leftLabelBounds[i] + rightLabelBounds[i];
+      totalWidth += leftLabelBounds[i] + rightLabelBounds[i];
     }
     totalProjWidth = layoutRect.width() - totalWidth;
-    totalProjHeight = layoutRect.height() - topLabelBounds[0] - bottomLabelBounds[columnCount() - 1];
+    totalProjHeight = layoutRect.height() - topLabelBounds[0] - bottomLabelBounds[rowCount() - 1];
   } else {
     return;
   }
@@ -635,6 +637,19 @@
 }
 
 
+void ViewGridLayout::unshareAxis() {
+  foreach (LayoutItem item, _items) {
+    PlotItem *plotItem = qobject_cast<PlotItem*>(item.viewItem);
+
+    if (!plotItem)
+      continue;
+
+    plotItem->setLabelsVisible(true);
+    plotItem->update();
+  }
+}
+
+
 void ViewGridLayout::updateSharedAxis() {
   if (!_shareX && !_shareY) {
     return;
@@ -699,7 +714,7 @@
 }
 
 
-void ViewGridLayout::updateProjections(ViewItem *item) {
+void ViewGridLayout::updateProjections(ViewItem *item, bool forceXShare, bool forceYShare) {
   bool xMatch = true;
   bool yMatch = true;
 
@@ -756,6 +771,9 @@
     }
   }
 
+  xMatch = xMatch || forceXShare;
+  yMatch = yMatch || forceYShare;
+
   if (!xMatch && !yMatch) {
     xMatch = true;
     yMatch = true;
@@ -770,11 +788,11 @@
 
     if (PlotItem *plotItem = qobject_cast<PlotItem*>(viewItem)) {
       if (xMatch && yMatch) {
-        plotItem->zoomFixedExpression(projectionRect);
+        plotItem->zoomFixedExpression(projectionRect, true);
       } else if (xMatch) {
-        plotItem->zoomXRange(projectionRect);
+        plotItem->zoomXRange(projectionRect, true);
       } else if (yMatch) {
-        plotItem->zoomYRange(projectionRect);
+        plotItem->zoomYRange(projectionRect, true);
       }
     }
   }
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.h #982723:982724
@@ -56,7 +56,7 @@
     void setEnabled(bool enabled);
 
     void calculateSharing();
-    static void updateProjections(ViewItem *item);
+    static void updateProjections(ViewItem *item, bool forceXShare = false, bool forceYShare = false);
 
     static void standardizePlotMargins(ViewItem *item, QPainter *painter);
     static void sharePlots(ViewItem *item, QPainter *painter, bool creation);
@@ -92,6 +92,7 @@
 
   private:
     void updateSharedAxis();
+    void unshareAxis();
     void shareAxisWithPlotToLeft(LayoutItem item);
     void shareAxisWithPlotToRight(LayoutItem item);
     void shareAxisWithPlotAbove(LayoutItem item);


More information about the Kst mailing list