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

Adam Treat treat at kde.org
Sat Oct 6 20:43:48 CEST 2007


SVN commit 722154 by treat:

* Automatically set the spacing based on whether
any plotitem axis is being shared.
* Unfortunately need to update each plotrenderitem
each time the label visibility is changed. The algorithm
to share axis is not the greatest or most efficient. One
possibility is to not redraw the actual curve when in layout
mode.


 M  +40 -1     plotitem.cpp  
 M  +1 -1      plotitem.h  
 M  +1 -3      plotrenderitem.cpp  
 M  +8 -4      viewgridlayout.cpp  
 M  +4 -4      viewgridlayout.h  
 M  +2 -2      viewitemdialog.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #722153:722154
@@ -207,7 +207,11 @@
 
 
 void PlotItem::setLeftLabelVisible(bool visible) {
+  if (_isLeftLabelVisible == visible)
+    return;
+
   _isLeftLabelVisible = visible;
+  emit labelVisibilityChanged();
 }
 
 
@@ -217,7 +221,11 @@
 
 
 void PlotItem::setBottomLabelVisible(bool visible) {
+  if (_isBottomLabelVisible == visible)
+    return;
+
   _isBottomLabelVisible = visible;
+  emit labelVisibilityChanged();
 }
 
 
@@ -227,7 +235,11 @@
 
 
 void PlotItem::setRightLabelVisible(bool visible) {
+  if (_isRightLabelVisible == visible)
+    return;
+
   _isRightLabelVisible = visible;
+  emit labelVisibilityChanged();
 }
 
 
@@ -237,7 +249,11 @@
 
 
 void PlotItem::setTopLabelVisible(bool visible) {
+  if (_isTopLabelVisible == visible)
+    return;
+
   _isTopLabelVisible = visible;
+  emit labelVisibilityChanged();
 }
 
 
@@ -246,7 +262,6 @@
   setRightLabelVisible(visible);
   setBottomLabelVisible(visible);
   setTopLabelVisible(visible);
-  emit labelsVisibleChanged();
 }
 
 
@@ -305,6 +320,9 @@
 
 
 void PlotItem::paintLeftLabel(QPainter *painter) {
+  if (!isLeftLabelVisible())
+    return;
+
   painter->save();
   QTransform t;
   t.rotate(90.0);
@@ -318,6 +336,9 @@
 
 
 QSizeF PlotItem::calculateLeftLabelBound(QPainter *painter) {
+  if (!isLeftLabelVisible())
+    return QSizeF();
+
   painter->save();
   QTransform t;
   t.rotate(90.0);
@@ -334,6 +355,9 @@
 
 
 void PlotItem::paintBottomLabel(QPainter *painter) {
+  if (!isBottomLabelVisible())
+    return;
+
   painter->save();
   QRectF bottomLabelRect = horizontalLabelRect(false);
   bottomLabelRect.moveTopLeft(QPointF(marginWidth(), height() - marginHeight()));
@@ -343,6 +367,9 @@
 
 
 QSizeF PlotItem::calculateBottomLabelBound(QPainter *painter) {
+  if (!isBottomLabelVisible())
+    return QSizeF();
+
   QRectF bottomLabelBound = painter->boundingRect(horizontalLabelRect(true),
                                                   Qt::TextWordWrap | Qt::AlignCenter, bottomLabel());
 
@@ -353,6 +380,9 @@
 
 
 void PlotItem::paintRightLabel(QPainter *painter) {
+  if (!isRightLabelVisible())
+    return;
+
   painter->save();
   painter->translate(width() - marginWidth(), 0.0);
   QTransform t;
@@ -368,6 +398,9 @@
 
 
 QSizeF PlotItem::calculateRightLabelBound(QPainter *painter) {
+  if (!isRightLabelVisible())
+    return QSizeF();
+
   painter->save();
   QTransform t;
   t.rotate(-90.0);
@@ -383,6 +416,9 @@
 
 
 void PlotItem::paintTopLabel(QPainter *painter) {
+  if (!isTopLabelVisible())
+    return;
+
   painter->save();
   QRectF topLabelRect = horizontalLabelRect(false);
   topLabelRect.moveTopLeft(QPointF(marginWidth(), 0.0));
@@ -392,6 +428,9 @@
 
 
 QSizeF PlotItem::calculateTopLabelBound(QPainter *painter) {
+  if (!isTopLabelVisible())
+    return QSizeF();
+
   QRectF topLabelBound = painter->boundingRect(horizontalLabelRect(true),
                                                Qt::TextWordWrap | Qt::AlignCenter, topLabel());
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #722153:722154
@@ -69,7 +69,7 @@
     void setLabelsVisible(bool visible);
 
   Q_SIGNALS:
-    void labelsVisibleChanged(); //only emitted when 'setLabelsVisible' is called
+    void labelVisibilityChanged();
 
   private:
     qreal calculatedMarginWidth() const;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #722153:722154
@@ -44,7 +44,7 @@
 
   connect(parentItem, SIGNAL(geometryChanged()),
           this, SLOT(updateGeometry()));
-  connect(parentItem, SIGNAL(labelsVisibleChanged()),
+  connect(parentItem, SIGNAL(labelVisibilityChanged()),
           this, SLOT(updateGeometry()));
   connect(parentItem->parentView(), SIGNAL(viewModeChanged(View::ViewMode)),
           this, SLOT(updateViewMode()));
@@ -713,7 +713,6 @@
 void PlotRenderItem::zoomLogX() {
   qDebug() << "zoomLogX" << endl;
   setXAxisLog(_zoomLogX->isChecked());
-  zoomMaximum(); //FIXME this is wrong of course, but working on debugging..
   update();
 }
 
@@ -782,7 +781,6 @@
 void PlotRenderItem::zoomLogY() {
   qDebug() << "zoomLogY" << endl;
   setYAxisLog(_zoomLogY->isChecked());
-  zoomMaximum(); //FIXME this is wrong of course, but working on debugging..
   update();
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.cpp #722153:722154
@@ -233,7 +233,7 @@
 }
 
 
-void ViewGridLayout::shareAxisWithPlotToLeft(LayoutItem item) const {
+void ViewGridLayout::shareAxisWithPlotToLeft(LayoutItem item) {
   QPair<int, int> key = qMakePair(item.row, item.column - 1);
   if (!_itemLayouts.contains(key))
     return;
@@ -253,11 +253,12 @@
   if (item.rowSpan == left.rowSpan && item.columnSpan == left.columnSpan) {
     plotItem->setLeftLabelVisible(false);
     leftItem->setRightLabelVisible(false);
+    setSpacing(QSizeF(0.0, spacing().height()));
   }
 }
 
 
-void ViewGridLayout::shareAxisWithPlotToRight(LayoutItem item) const {
+void ViewGridLayout::shareAxisWithPlotToRight(LayoutItem item) {
   QPair<int, int> key = qMakePair(item.row, item.column + 1);
   if (!_itemLayouts.contains(key))
     return;
@@ -277,11 +278,12 @@
   if (item.rowSpan == right.rowSpan && item.columnSpan == right.columnSpan) {
     plotItem->setRightLabelVisible(false);
     rightItem->setLeftLabelVisible(false);
+    setSpacing(QSizeF(0.0, spacing().height()));
   }
 }
 
 
-void ViewGridLayout::shareAxisWithPlotAbove(LayoutItem item) const {
+void ViewGridLayout::shareAxisWithPlotAbove(LayoutItem item) {
   QPair<int, int> key = qMakePair(item.row - 1, item.column);
   if (!_itemLayouts.contains(key))
     return;
@@ -301,11 +303,12 @@
   if (item.rowSpan == top.rowSpan && item.columnSpan == top.columnSpan) {
     plotItem->setTopLabelVisible(false);
     topItem->setBottomLabelVisible(false);
+    setSpacing(QSizeF(spacing().width(), 0.0));
   }
 }
 
 
-void ViewGridLayout::shareAxisWithPlotBelow(LayoutItem item) const {
+void ViewGridLayout::shareAxisWithPlotBelow(LayoutItem item) {
   QPair<int, int> key = qMakePair(item.row + 1, item.column);
   if (!_itemLayouts.contains(key))
     return;
@@ -325,6 +328,7 @@
   if (item.rowSpan == bottom.rowSpan && item.columnSpan == bottom.columnSpan) {
     plotItem->setBottomLabelVisible(false);
     bottomItem->setTopLabelVisible(false);
+    setSpacing(QSizeF(spacing().width(), 0.0));
   }
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewgridlayout.h #722153:722154
@@ -76,10 +76,10 @@
 
   private:
     void updateSharedAxis();
-    void shareAxisWithPlotToLeft(LayoutItem item) const;
-    void shareAxisWithPlotToRight(LayoutItem item) const;
-    void shareAxisWithPlotAbove(LayoutItem item) const;
-    void shareAxisWithPlotBelow(LayoutItem item) const;
+    void shareAxisWithPlotToLeft(LayoutItem item);
+    void shareAxisWithPlotToRight(LayoutItem item);
+    void shareAxisWithPlotAbove(LayoutItem item);
+    void shareAxisWithPlotBelow(LayoutItem item);
 
   private:
     bool _enabled;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitemdialog.cpp #722153:722154
@@ -152,9 +152,9 @@
   }
 
   layout->setMargin(QSizeF(_layoutTab->horizontalMargin(),
-                              _layoutTab->verticalMargin()));
+                           _layoutTab->verticalMargin()));
   layout->setSpacing(QSizeF(_layoutTab->horizontalSpacing(),
-                               _layoutTab->verticalSpacing()));
+                            _layoutTab->verticalSpacing()));
   layout->update();
 }
 


More information about the Kst mailing list