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

Barth Netterfield netterfield at astro.utoronto.ca
Mon Feb 9 16:20:18 CET 2009


SVN commit 923852 by netterfield:

Changes to the plot updating to avoid n^2 behavior in updating
plot axis.

There are still issues!



 M  +6 -1      libkst/updatemanager.cpp  
 M  +1 -1      libkstapp/plotaxis.cpp  
 M  +26 -15    libkstapp/plotitem.cpp  
 M  +2 -0      libkstapp/plotitem.h  
 M  +2 -1      libkstapp/view.cpp  
 M  +4 -0      libkstapp/view.h  
 M  +3 -3      libkstapp/viewgridlayout.cpp  
 M  +1 -1      libkstapp/viewgridlayout.h  


--- branches/work/kst/portto4/kst/src/libkst/updatemanager.cpp #923851:923852
@@ -171,7 +171,8 @@
       // Display level update required.
       if (_activeUpdates.empty()) {
 #if DEBUG_UPDATE_CYCLE > 0
-        qDebug() << "UM - All updates complete, updating plots";
+        qDebug() << "UM - All updates complete, updating plots "<< "Current dependent update list" <<  _dependentUpdateRequests;
+
 #endif
         foreach (QList<PlotItemInterface*> objectList, _displayUpdateRequests) {
           foreach (PlotItemInterface* object, objectList) {
@@ -179,6 +180,10 @@
           }
         }
         _dependentUpdateRequests.clear();
+#if DEBUG_UPDATE_CYCLE > 0
+      } else {
+        qDebug() << "UM - updates not complete: not updating plots: count:" << _updateRequests.count();
+#endif
       }
     }
   }
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.cpp #923851:923852
@@ -629,6 +629,7 @@
       _axisBaseOffsetOverride = true;
       _axisOverrideMajorTicks = Coarse;
     }
+
     update(true);
   }
 }
@@ -648,7 +649,6 @@
   return mode;
 }
 
-
 void PlotAxis::update(bool useOverrideTicks) {
   MajorTickMode majorTickCount;
   if (useOverrideTicks) {
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #923851:923852
@@ -500,7 +500,7 @@
 
 
 void PlotItem::marginsUpdated() {
-  ViewGridLayout::standardizePlotMargins(this);
+  //ViewGridLayout::standardizePlotMargins(this);
   //qDebug() << "---Margins updated called";
   if (isInSharedAxisBox() && parentItem()) {
     if (SharedAxisBoxItem *sharedBox = qgraphicsitem_cast<SharedAxisBoxItem*>(parentItem())) {
@@ -533,7 +533,17 @@
   }
 }
 
+void PlotItem::calculateBorders(QPainter *painter) {
+  calculateBottomTickLabelBound(painter);
+  calculateLeftTickLabelBound(painter);
 
+  setCalculatedLeftLabelMargin(calculateLeftLabelBound(painter).width());
+  setCalculatedRightLabelMargin(calculateRightLabelBound(painter).width());
+  setCalculatedTopLabelMargin(calculateTopLabelBound(painter).height());
+  setCalculatedBottomLabelMargin(calculateBottomLabelBound(painter).height());
+}
+
+
 void PlotItem::paint(QPainter *painter) {
   if (parentViewItem() && isInSharedAxisBox()) {
     setBrush(Qt::transparent);
@@ -552,15 +562,11 @@
   // FIXME: the plot size calculations need to be separated from the 
   // painting to avoid n^2 or worse behavior.
 
-  calculateBottomTickLabelBound(painter);
-  calculateLeftTickLabelBound(painter);
-  //setCalculatedAxisMarginWidth(calculateLeftTickLabelBound(painter).width());
+  if (parentView()->plotBordersDirty()) {
+    ViewGridLayout::standardizePlotMargins(this, painter);
+    parentView()->setPlotBordersDirty(false);
+  }
 
-  setCalculatedLeftLabelMargin(calculateLeftLabelBound(painter).width());
-  setCalculatedRightLabelMargin(calculateRightLabelBound(painter).width());
-  setCalculatedTopLabelMargin(calculateTopLabelBound(painter).height());
-  setCalculatedBottomLabelMargin(calculateBottomLabelBound(painter).height());
-
 #if DEBUG_LABEL_REGION
   //  qDebug() << "=============> leftLabel:" << leftLabel() << endl;
 #endif
@@ -1617,8 +1623,9 @@
 void PlotItem::setCalculatedLeftLabelMargin(qreal margin) {
   qreal before = this->calculatedLeftLabelMargin();
   _calculatedLeftLabelMargin = margin;
-  if (before != this->calculatedLeftLabelMargin())
+  if (before != this->calculatedLeftLabelMargin()) {
     emit marginsChanged();
+  }
 }
 
 
@@ -1636,8 +1643,9 @@
 void PlotItem::setCalculatedRightLabelMargin(qreal margin) {
   qreal before = this->calculatedRightLabelMargin();
   _calculatedRightLabelMargin = margin;
-  if (before != this->calculatedRightLabelMargin())
+  if (before != this->calculatedRightLabelMargin()) {
     emit marginsChanged();
+  }
 }
 
 
@@ -1666,8 +1674,9 @@
 void PlotItem::setCalculatedTopLabelMargin(qreal margin) {
   qreal before = this->calculatedTopLabelMargin();
   _calculatedTopLabelMargin = margin;
-  if (before != this->calculatedTopLabelMargin())
+  if (before != this->calculatedTopLabelMargin()) {
     emit marginsChanged();
+  }
 }
 
 
@@ -1685,8 +1694,9 @@
 void PlotItem::setCalculatedBottomLabelMargin(qreal margin) {
   qreal before = this->calculatedBottomLabelMargin();
   _calculatedBottomLabelMargin = margin;
-  if (before != this->calculatedBottomLabelMargin())
+  if (before != this->calculatedBottomLabelMargin()) {
     emit marginsChanged();
+  }
 }
 
 
@@ -2057,8 +2067,9 @@
 void PlotItem::setCalculatedAxisMarginWidth(qreal marginWidth) {
   qreal before = this->calculatedAxisMarginWidth();
   _calculatedAxisMarginWidth = marginWidth;
-  if (before != this->calculatedAxisMarginWidth())
+  if (before != this->calculatedAxisMarginWidth()) {
     emit marginsChanged();
+  }
 }
 
 
@@ -2214,7 +2225,7 @@
 #endif
 
     _projectionRect = rect;
-    emit marginsChanged();
+    parentView()->setPlotBordersDirty(true);
   }
   emit updateAxes();
   update(); //slow, but need to update everything...
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #923851:923852
@@ -302,6 +302,8 @@
 
     virtual void paintPlotMarkers(QPainter *painter);
 
+    void calculateBorders(QPainter *painter);
+
     qreal calculatedLabelMarginWidth() const;
     qreal calculatedLabelMarginHeight() const;
 
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #923851:923852
@@ -47,9 +47,9 @@
     _snapToGridHorizontal(false),
     _snapToGridVertical(false),
     _shareAxis(true),
+    _plotBordersDirty(false),
     _printing(false),
     _dataMode(false) {
-
   _undoStack = new QUndoStack(this);
   setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
   setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -363,6 +363,7 @@
 
 void View::resizeEvent(QResizeEvent *event) {
   QGraphicsView::resizeEvent(event);
+  setPlotBordersDirty(true);
 
   if (size() != sceneRect().size()) {
     QRectF oldSceneRect = sceneRect();
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #923851:923852
@@ -99,6 +99,9 @@
 
     virtual void contextMenuEvent();
 
+    bool plotBordersDirty() const {return _plotBordersDirty;}
+    void setPlotBordersDirty(bool dirty) {_plotBordersDirty = dirty;}
+
   Q_SIGNALS:
     void viewModeChanged(View::ViewMode oldMode);
     void mouseModeChanged(View::MouseMode oldMode);
@@ -147,6 +150,7 @@
     bool _snapToGridHorizontal;
     bool _snapToGridVertical;
     bool _shareAxis;
+    bool _plotBordersDirty;
     bool _printing;
     bool _dataMode;
 };
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #923851:923852
@@ -260,10 +260,9 @@
 }
 
 
-void ViewGridLayout::standardizePlotMargins(ViewItem *item) {
-
-  QList<QGraphicsItem*> list;
+void ViewGridLayout::standardizePlotMargins(ViewItem *item, QPainter *painter) {
   QList<PlotItem*> plotItems;
+  qDebug() << "standardizePlotMargins called";
   if (item->parentView()) {
     QList<QGraphicsItem*> list = item->parentView()->items();
     foreach (QGraphicsItem *item, list) {
@@ -283,6 +282,7 @@
   QMap<qreal, qreal> marginWidths;
   QMap<qreal, qreal> marginHeights;
   foreach (PlotItem* plotItem, plotItems) {
+    plotItem->calculateBorders(painter);
     if (marginWidths[plotItem->width()] < plotItem->leftMarginSize()) {
       marginWidths[plotItem->width()] = plotItem->leftMarginSize();
     }
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.h #923851:923852
@@ -59,7 +59,7 @@
     static void updateProjections(ViewItem *item);
 
     static void resetSharedPlots(ViewItem *item);
-    static void standardizePlotMargins(ViewItem *item);
+    static void standardizePlotMargins(ViewItem *item, QPainter *painter);
     static void sharePlots(ViewItem *item);
     static void sharePlots(View *view);
 


More information about the Kst mailing list