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

Mike Fenton mike at staikos.net
Wed Apr 1 22:23:48 CEST 2009


SVN commit 947970 by fenton:

Cleanup LabelTab
Fix AutoLabels by making overrideText purely an override.


 M  +0 -12     labeltab.cpp  
 M  +0 -1      labeltab.h  
 M  +57 -30    plotitem.cpp  
 M  +10 -5     plotitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/labeltab.cpp #947969:947970
@@ -56,9 +56,6 @@
 
   connect(_showLegend, SIGNAL(stateChanged(int)), this, SIGNAL(modified()));
 
-  //connect(_applyGlobalsButton, SIGNAL(pressed()), this, SLOT(applyGlobals()));
-  //connect(_autoLabel, SIGNAL(pressed()), this, SLOT(autoLabel()));
-
   connect(_editLegendContents, SIGNAL(pressed()), _plotItem->legend(), SLOT(edit()));
 
   connect(_globalLabelFontSize, SIGNAL(valueChanged(double)), this, SIGNAL(globalFontUpdate()));
@@ -143,15 +140,6 @@
 }
 
 
-void LabelTab::autoLabel() {
-  setLeftLabel(_plotItem->leftLabel());
-  setBottomLabel(_plotItem->bottomLabel());
-  setTopLabel(_plotItem->topLabel());
-  setRightLabel(_plotItem->rightLabel());
-  emit modified();
-}
-
-
 bool LabelTab::showLegend() const {
   return _showLegend->isChecked();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/labeltab.h #947969:947970
@@ -51,7 +51,6 @@
 
   public Q_SLOTS:
     void update();
-    void autoLabel();
 
   private Q_SLOTS:
     void labelUpdate(const QString&);
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #947969:947970
@@ -513,6 +513,7 @@
   }
 }
 
+
 void PlotItem::calculateBorders(QPainter *painter) {
   calculateBottomTickLabelBound(painter);
   calculateLeftTickLabelBound(painter);
@@ -527,7 +528,13 @@
   setPlotRectsDirty();
 }
 
+
 void PlotItem::paint(QPainter *painter) {
+  if (parentView()->plotBordersDirty() || (creationState() == ViewItem::InProgress)) {
+    ViewGridLayout::standardizePlotMargins(this, painter);
+    setPlotBordersDirty(false);
+  }
+
 #ifdef BENCHMARK
   QTime bench_time, benchtmp;
   int b_1 = 0, b_2 = 0, b_3 = 0, b_4 = 0, b_5 = 0;
@@ -542,14 +549,6 @@
   painter->save();
   painter->setFont(numberLabelDetails()->calculatedFont());
 
-  // FIXME: the plot size calculations need to be separated from the 
-  // painting to avoid n^2 or worse behavior.
-
-  if (parentView()->plotBordersDirty() || (creationState() == ViewItem::InProgress)) {
-    ViewGridLayout::standardizePlotMargins(this, painter);
-    setPlotBordersDirty(false);
-  }
-
 #ifdef BENCHMARK
     b_1 = benchtmp.elapsed();
 #endif
@@ -1357,6 +1356,15 @@
 
 
 QString PlotItem::leftLabel() const {
+  if (!leftLabelDetails()->overrideText().isEmpty()) {
+    return leftLabelDetails()->overrideText();
+  } else {
+    return autoLeftLabel();
+  }
+}
+
+
+QString PlotItem::autoLeftLabel() const {
   foreach (PlotRenderItem *renderer, renderItems()) {
     if (!renderer->leftLabel().isEmpty())
       return renderer->leftLabel();
@@ -1366,6 +1374,15 @@
 
 
 QString PlotItem::bottomLabel() const {
+  if (!bottomLabelDetails()->overrideText().isEmpty()) {
+    return bottomLabelDetails()->overrideText();
+  } else {
+    return autoBottomLabel();
+  }
+}
+
+
+QString PlotItem::autoBottomLabel() const {
   foreach (PlotRenderItem *renderer, renderItems()) {
     if (!renderer->bottomLabel().isEmpty())
       return renderer->bottomLabel();
@@ -1375,6 +1392,15 @@
 
 
 QString PlotItem::rightLabel() const {
+  if (!rightLabelDetails()->overrideText().isEmpty()) {
+    return rightLabelDetails()->overrideText();
+  } else {
+    return autoRightLabel();
+  }
+}
+
+
+QString PlotItem::autoRightLabel() const {
   foreach (PlotRenderItem *renderer, renderItems()) {
     if (!renderer->rightLabel().isEmpty())
       return renderer->rightLabel();
@@ -1384,6 +1410,15 @@
 
 
 QString PlotItem::topLabel() const {
+  if (!topLabelDetails()->overrideText().isEmpty()) {
+    return topLabelDetails()->overrideText();
+  } else {
+    return autoTopLabel();
+  }
+}
+
+
+QString PlotItem::autoTopLabel() const {
   foreach (PlotRenderItem *renderer, renderItems()) {
     if (!renderer->topLabel().isEmpty())
       return renderer->topLabel();
@@ -1481,7 +1516,7 @@
   }
   _leftLabel.valid = false;
   _leftLabel.dirty = false;
-  Label::Parsed *parsed = Label::parse(_leftLabelDetails->overrideText());
+  Label::Parsed *parsed = Label::parse(leftLabel());
   if (parsed) {
     parsed->chunk->attributes.color = _leftLabelDetails->fontColor();
 
@@ -1514,7 +1549,7 @@
 
 
 void PlotItem::paintLeftLabel(QPainter *painter) {
-  if (!_leftLabelDetails->isVisible() || _leftLabelDetails->overrideText().isEmpty())
+  if (!_leftLabelDetails->isVisible() || leftLabel().isEmpty())
     return;
 
   generateLeftLabel();
@@ -1556,7 +1591,7 @@
 
     painter->setFont(leftLabelDetails()->calculatedFont());
     QRectF leftLabelBound = painter->boundingRect(t.mapRect(leftLabelRect()),
-        Qt::TextWordWrap | Qt::AlignCenter, _leftLabelDetails->overrideText());
+        Qt::TextWordWrap | Qt::AlignCenter, leftLabel());
     painter->restore();
 
     _calculatedLeftLabelMargin = leftLabelBound.height();
@@ -1574,7 +1609,7 @@
   }
   _bottomLabel.valid = false;
   _bottomLabel.dirty = false;
-  Label::Parsed *parsed = Label::parse(_bottomLabelDetails->overrideText());
+  Label::Parsed *parsed = Label::parse(bottomLabel());
   if (parsed) {
     parsed->chunk->attributes.color = _bottomLabelDetails->fontColor();
 
@@ -1604,7 +1639,7 @@
 
 
 void PlotItem::paintBottomLabel(QPainter *painter) {
-  if (!_bottomLabelDetails->isVisible() || _bottomLabelDetails->overrideText().isEmpty())
+  if (!_bottomLabelDetails->isVisible() || bottomLabel().isEmpty())
     return;
 
   generateBottomLabel();
@@ -1641,7 +1676,7 @@
     painter->setFont(bottomLabelDetails()->calculatedFont());
 
     QRectF bottomLabelBound = painter->boundingRect(bottomLabelRect(),
-        Qt::TextWordWrap | Qt::AlignCenter, _bottomLabelDetails->overrideText());
+        Qt::TextWordWrap | Qt::AlignCenter, bottomLabel());
     painter->restore();
 
     _calculatedBottomLabelMargin = bottomLabelBound.height();
@@ -1659,7 +1694,7 @@
   }
   _rightLabel.valid = false;
   _rightLabel.dirty = false;
-  Label::Parsed *parsed = Label::parse(_rightLabelDetails->overrideText());
+  Label::Parsed *parsed = Label::parse(rightLabel());
   QRectF rightLabel = rightLabelRect();
   if (parsed && rightLabel.isValid()) {
     parsed->chunk->attributes.color = _rightLabelDetails->fontColor();
@@ -1691,7 +1726,7 @@
 
 
 void PlotItem::paintRightLabel(QPainter *painter) {
-  if (!_rightLabelDetails->isVisible() || _rightLabelDetails->overrideText().isEmpty())
+  if (!_rightLabelDetails->isVisible() || rightLabel().isEmpty())
     return;
 
   generateRightLabel();
@@ -1734,7 +1769,7 @@
     painter->setFont(rightLabelDetails()->calculatedFont());
 
     QRectF rightLabelBound = painter->boundingRect(t.mapRect(rightLabelRect()),
-        Qt::TextWordWrap | Qt::AlignCenter, _rightLabelDetails->overrideText());
+        Qt::TextWordWrap | Qt::AlignCenter, rightLabel());
     painter->restore();
 
     _calculatedRightLabelMargin = qMax(_calculatedAxisMarginROverflow, rightLabelBound.height());
@@ -1752,7 +1787,7 @@
   }
   _topLabel.valid = false;
   _topLabel.dirty = false;
-  Label::Parsed *parsed = Label::parse(_topLabelDetails->overrideText());
+  Label::Parsed *parsed = Label::parse(topLabel());
   QRectF topLabel = topLabelRect();
   if (parsed && topLabel.isValid()) {
     parsed->chunk->attributes.color = _topLabelDetails->fontColor();
@@ -1782,7 +1817,7 @@
 
 
 void PlotItem::paintTopLabel(QPainter *painter) {
-  if (!_topLabelDetails->isVisible() || _topLabelDetails->overrideText().isEmpty())
+  if (!_topLabelDetails->isVisible() || topLabel().isEmpty())
     return;
 
   generateTopLabel();
@@ -1819,7 +1854,7 @@
     painter->setFont(topLabelDetails()->calculatedFont());
 
     QRectF topLabelBound = painter->boundingRect(topLabelRect(),
-        Qt::TextWordWrap | Qt::AlignCenter, _topLabelDetails->overrideText());
+        Qt::TextWordWrap | Qt::AlignCenter, topLabel());
 
     painter->restore();
 
@@ -2513,11 +2548,7 @@
 
 
 QString PlotLabel::overrideText() const {
-  if (_overrideText.isEmpty()) {
-    return _plotItem->leftLabel();
-  } else {
-    return _overrideText;
-  }
+  return _overrideText;
 }
 
 
@@ -2525,11 +2556,7 @@
   if (label == _overrideText) {
     return;
   }
-  if (label == _plotItem->leftLabel()) {
-    _overrideText.clear();
-  } else {
-    _overrideText = label;
-  }
+  _overrideText = label;
   emit labelChanged();
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #947969:947970
@@ -165,12 +165,17 @@
     QString rightLabel() const;
     QString topLabel() const;
 
-    PlotLabel* leftLabelDetails() { return _leftLabelDetails; };
-    PlotLabel* rightLabelDetails() { return _rightLabelDetails; };
-    PlotLabel* topLabelDetails() { return _topLabelDetails; };
-    PlotLabel* bottomLabelDetails() { return _bottomLabelDetails; };
-    PlotLabel* numberLabelDetails() { return _numberLabelDetails; };
+    QString autoLeftLabel() const;
+    QString autoBottomLabel() const;
+    QString autoRightLabel() const;
+    QString autoTopLabel() const;
 
+    PlotLabel* leftLabelDetails() const { return _leftLabelDetails; };
+    PlotLabel* rightLabelDetails() const { return _rightLabelDetails; };
+    PlotLabel* topLabelDetails() const { return _topLabelDetails; };
+    PlotLabel* bottomLabelDetails() const { return _bottomLabelDetails; };
+    PlotLabel* numberLabelDetails() const { return _numberLabelDetails; };
+
     void setTopSuppressed(bool suppressed);
     void setBottomSuppressed(bool suppressed);
     void setLeftSuppressed(bool suppressed);


More information about the Kst mailing list