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

Barth Netterfield netterfield at astro.utoronto.ca
Wed Jul 27 16:59:17 CEST 2011


SVN commit 1243396 by netterfield:

When breaking a shared axis box, reset the plots to be equal sized, as expected.



 M  +32 -7     sharedaxisboxitem.cpp  
 M  +0 -6      viewgridlayout.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/sharedaxisboxitem.cpp #1243395:1243396
@@ -15,8 +15,8 @@
 #include "plotitem.h"
 #include "plotitemmanager.h"
 
-//#include "gridlayouthelper.h"
 #include "viewgridlayout.h"
+#include "formatgridhelper.h"
 
 #include "application.h"
 
@@ -207,9 +207,34 @@
 
 void SharedAxisBoxItem::breakShare() {
   _loaded = false;
-  QList<PlotItem*> list = getSharedPlots();
-  foreach (PlotItem *plotItem, list) {
-    plotItem->setPos(mapToParent(plotItem->pos()));
+  QList<PlotItem*> plotList = getSharedPlots();
+  QList<ViewItem*> viewItemList;
+  int n_plots = plotList.size();
+  for (int i_plot = 0; i_plot<n_plots; i_plot++) {
+    viewItemList.append(dynamic_cast<ViewItem*>(plotList.at(i_plot)));
+  }
+
+  FormatGridHelper grid(viewItemList);
+
+  double height;
+  double width;
+
+  if (grid.n_rows>0) {
+    height = double(rect().height())/double(grid.n_rows);
+  } else {
+    height = rect().height();
+  }
+  if (grid.n_cols>0) {
+    width = double(rect().width())/double(grid.n_cols);
+  } else {
+    width = rect().width();
+  }
+  QPointF P0 = rect().topLeft();
+  for (int i_plot = 0; i_plot<n_plots; i_plot++) {
+    PlotItem *plotItem = plotList.at(i_plot);
+
+    plotItem->setRect(0,0,width, height);
+    plotItem->setPos(mapToParent(P0 + QPointF(grid.rcList.at(i_plot).col*width, grid.rcList.at(i_plot).row*height)));
     plotItem->setSharedAxisBox(0);
     plotItem->setTopSuppressed(false);
     plotItem->setBottomSuppressed(false);
@@ -261,13 +286,13 @@
 
 
 void SharedAxisBoxItem::updateShare() {
-  if (!_shareX && !_shareY) {
-    breakShare();
-  } else {
     ViewGridLayout::updateProjections(this, _shareX, _shareY);
     view()->setPlotBordersDirty(true);
     setDirty();
     update();
+  if (!_shareX && !_shareY) {
+    breakShare();
+  } else {
   }
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #1243395:1243396
@@ -16,7 +16,6 @@
 #include "viewitem.h"
 #include "plotitem.h"
 #include "layoutboxitem.h"
-//#include "gridlayouthelper.h"
 #include "sharedaxisboxitem.h"
 #include "formatgridhelper.h"
 
@@ -178,10 +177,6 @@
     return; //not added to undostack
 
 
-  // Build an automatic layout to try to maintain the existing layout.
-  //Grid *grid = Grid::buildGrid(viewItems, 0);
-  //Q_ASSERT(grid);
-
   ViewGridLayout *layout = new ViewGridLayout(item);
 
   FormatGridHelper grid(viewItems);
@@ -350,7 +345,6 @@
 
 void ViewGridLayout::shareAxis(QPainter *painter, bool creation) {
 
-
   SharedAxisBoxItem *shareBox = qobject_cast<SharedAxisBoxItem*>(parentItem());
   if (!shareBox) {
     return;


More information about the Kst mailing list