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

Barth Netterfield netterfield at astro.utoronto.ca
Mon Feb 21 22:17:25 CET 2011


SVN commit 1222135 by netterfield:

More work on x, y, top labels.  
For single 'curve' per plot:
-Use top labels for Name when Name, Quantity, and Units are all defined.
 (if quantity is not defined, then the name still only goes in the axis).

-Define default top labels for equations, histograms and spectra

Please test.



 M  +1 -0      config.h  
 M  +20 -0     src/libkst/datamatrix.cpp  
 M  +1 -0      src/libkst/datamatrix.h  
 M  +8 -0      src/libkst/matrix.cpp  
 M  +3 -0      src/libkst/matrix.h  
 M  +11 -1     src/libkst/vector.cpp  
 M  +4 -1      src/libkst/vector.h  
 M  +16 -15    src/libkstapp/plotrenderitem.cpp  
 M  +7 -0      src/libkstmath/curve.cpp  
 M  +1 -0      src/libkstmath/curve.h  
 M  +1 -1      src/libkstmath/equation.cpp  
 M  +5 -22     src/libkstmath/histogram.cpp  
 M  +0 -4      src/libkstmath/histogram.h  
 M  +9 -0      src/libkstmath/image.cpp  
 M  +1 -0      src/libkstmath/image.h  
 M  +5 -0      src/libkstmath/psd.cpp  
 M  +1 -0      src/libkstmath/relation.h  


--- branches/work/kst/portto4/kst/config.h #1222134:1222135
@@ -10,4 +10,5 @@
 #define KST_INSTALL_LIBDIR  "lib"
 #define KST_INSTALL_PLUGINS "lib/kst2/plugins"
 
+
 #endif
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.cpp #1222134:1222135
@@ -415,6 +415,26 @@
 }
 
 
+LabelInfo DataMatrix::titleInfo() const {
+  LabelInfo label_info;
+
+  if (_fieldStrings.contains("z_quantity")) {
+    label_info.quantity = _fieldStrings.value("z_quantity")->value();
+  } else {
+    label_info.quantity = QString();
+  }
+  if (_fieldStrings.contains("z_units")) {
+    label_info.quantity = _fieldStrings.value("z_units")->value();
+  } else {
+    label_info.quantity = QString();
+  }
+
+  label_info.name = _field;
+
+  return label_info;
+}
+
+
 void DataMatrix::internalUpdate() {
   if (dataSource()) {
     dataSource()->writeLock();
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.h #1222134:1222135
@@ -121,6 +121,7 @@
 
     virtual LabelInfo xLabelInfo() const;
     virtual LabelInfo yLabelInfo() const;
+    virtual LabelInfo titleInfo() const;
 
   protected:
     DataMatrix(ObjectStore *store);
--- branches/work/kst/portto4/kst/src/libkst/matrix.cpp #1222134:1222135
@@ -370,6 +370,10 @@
   _yLabelInfo = label_info;
 }
 
+void Matrix::setTitleInfo(const LabelInfo &label_info) {
+  _titleInfo = label_info;
+}
+
 LabelInfo Matrix::xLabelInfo() const {
   return _xLabelInfo;
 }
@@ -379,6 +383,10 @@
 }
 
 
+LabelInfo Matrix::titleInfo() const {
+  return _titleInfo;
+}
+
 bool Matrix::editable() const {
   return _editable;
 }
--- branches/work/kst/portto4/kst/src/libkst/matrix.h #1222134:1222135
@@ -93,8 +93,10 @@
     // labels for plots
     virtual void setXLabelInfo(const LabelInfo &label_info);
     virtual void setYLabelInfo(const LabelInfo &label_info);
+    virtual void setTitleInfo(const LabelInfo &label_info);
     virtual LabelInfo xLabelInfo() const;
     virtual LabelInfo yLabelInfo() const;
+    virtual LabelInfo titleInfo() const;
 
     void zero();
 
@@ -171,6 +173,7 @@
     // labels for this matrix
     LabelInfo _xLabelInfo;
     LabelInfo _yLabelInfo;
+    LabelInfo _titleInfo;
 
     void createScalars(ObjectStore *store);
     void renameScalars();
--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #1222134:1222135
@@ -42,7 +42,7 @@
 
 /** Create a vector */
 Vector::Vector(ObjectStore *store)
-    : Primitive(store, 0L), _nsum(0) {
+    : Primitive(store, 0L), _nsum(0), _labelInfo(LabelInfo()), _titleInfo(LabelInfo()) {
 
   _initializeShortName();
 
@@ -632,10 +632,20 @@
 }
 
 
+LabelInfo Vector::titleInfo() const {
+  return _titleInfo;
+}
+
+
 void Vector::setLabelInfo(const LabelInfo &label_info) {
   _labelInfo = label_info;
 }
 
+
+void Vector::setTitleInfo(const LabelInfo &label_info) {
+  _titleInfo = label_info;
+}
+
 #undef INITSIZE
 
 }
--- branches/work/kst/portto4/kst/src/libkst/vector.h #1222134:1222135
@@ -123,9 +123,11 @@
     /* Generally you don't need to call this */
     void updateScalars();
 
-    /** return a sensible label for this vector */
+    /** return information for building a label for this vector */
     virtual LabelInfo labelInfo() const;
+    virtual LabelInfo titleInfo() const;
     virtual void setLabelInfo(const LabelInfo &label_info);
+    virtual void setTitleInfo(const LabelInfo &label_info);
 
     virtual int getUsage() const;
 
@@ -208,6 +210,7 @@
     virtual void deleteDependents();
 
     LabelInfo _labelInfo;
+    LabelInfo _titleInfo;
 
     friend class DataObject;
     friend class Matrix;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #1222134:1222135
@@ -338,10 +338,10 @@
     }
   } else if (label_info.name.isEmpty()) {
     return QString("%1 \\[%2\\]").arg(label_info.quantity).arg(label_info.units); // xQU
-  } else if (label_info.name.toLower().contains(label_info.quantity.toLower())) {
-    return QString("%1 \\[%2\\]").arg(label_info.name).arg(label_info.units); // NQU A
+  //} else if (label_info.name.toLower().contains(label_info.quantity.toLower())) {
+  //  return QString("%1 \\[%2\\]").arg(label_info.name).arg(label_info.units); // NQU A
   } else {
-    return QString("%1 \\[%2\\]").arg(label_info.name).arg(label_info.units); // NQU B
+    return QString("%1 \\[%2\\]").arg(label_info.quantity).arg(label_info.units); // NQU B
   }
 }
 
@@ -434,24 +434,25 @@
 
 
 QString PlotRenderItem::topLabel() const {
-  return QString();
-#if 0
-  QString label;
-  for (int i = 0, count = relationList().count(); i<count; i++) {
-    if (i>0) {
-      if (i==count-1) {
-        //label += i18n(" and ", "last separater in a list");
-        label += i18n(" and ");
+  if (relationList().size() == 1) {
+    LabelInfo label_info = relationList().at(0)->titleInfo();
+    QString label = singleRenderItemLabel(label_info);
+    if (label.isEmpty()) {
+      label_info = relationList().at(0)->yLabelInfo();
+      if ((!label_info.name.isEmpty()) && (!label_info.quantity.isEmpty())) {
+        LabelInfo xlabel_info = relationList().at(0)->xLabelInfo();
+        if ((!xlabel_info.name.isEmpty()) && (!xlabel_info.quantity.isEmpty())) {
+          label = i18n("%1 vs %2").arg(label_info.name).arg(xlabel_info.name);
       } else {
-        //label += i18n(", ", "separater in a list");
-        label += i18n(", ");
+          label = label_info.name;
       }
     }
-    label += relationList().at(i)->topLabel();
   }
   return label;
-#endif
+  } else {
+    return QString();
 }
+}
 
 
 void PlotRenderItem::keyPressEvent(QKeyEvent *event) {
--- branches/work/kst/portto4/kst/src/libkstmath/curve.cpp #1222134:1222135
@@ -373,10 +373,17 @@
   return xVector()->labelInfo();
 }
 
+
 LabelInfo Curve::yLabelInfo() const {
   return yVector()->labelInfo();
 }
 
+
+LabelInfo Curve::titleInfo() const {
+  return yVector()->titleInfo();
+}
+
+
 QString Curve::propertyString() const {
   return i18n("%1 vs %2").arg(yVector()->Name()).arg(xVector()->Name());
 }
--- branches/work/kst/portto4/kst/src/libkstmath/curve.h #1222134:1222135
@@ -159,6 +159,7 @@
     // labels for plots
     virtual LabelInfo xLabelInfo() const;
     virtual LabelInfo yLabelInfo() const;
+    virtual LabelInfo titleInfo() const;
 
 
   protected:
--- branches/work/kst/portto4/kst/src/libkstmath/equation.cpp #1222134:1222135
@@ -271,7 +271,7 @@
   label_info.quantity = QString();
   label_info.name = yl;
 
-  _yOutVector->setLabelInfo(label_info);
+  _yOutVector->setTitleInfo(label_info);
 }
 
 void Equation::setExistingXVector(VectorPtr in_xv, bool do_interp) {
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.cpp #1222134:1222135
@@ -203,6 +203,11 @@
   _hVector->setLabelInfo(label_info);
   _bVector->setLabelInfo(_inputVectors[RAWVECTOR]->labelInfo());
 
+  label_info.quantity.clear();
+  label_info.units.clear();
+  label_info.name = i18n( "Histogram of %1").arg(_bVector->labelInfo().name);
+  _hVector->setTitleInfo(label_info);
+
   double *bins = _bVector->value();
   double *hist = _hVector->value();
 
@@ -211,11 +216,6 @@
     hist[i_bin] = _Bins[i_bin]*_Normalization;
   }
 
-  // these will get updated by the update manager now
-  // that their provider been changed.
-  //_bVector->update();
-  //_hVector->update();
-
   unlockInputsAndOutputs();
 
 }
@@ -282,23 +282,6 @@
 }
 
 
-LabelInfo Histogram::yLabelInfo() const {
-  if (_hVector) {
-    _hVector->labelInfo();
-  } else {
-    return LabelInfo();
-  }
-}
-
-
-LabelInfo Histogram::xLabelInfo() const {
-  if (_bVector) {
-    _bVector->labelInfo();
-  } else {
-    return LabelInfo();
-  }
-}
-
 void Histogram::save(QXmlStreamWriter &xml) {
   xml.writeStartElement(staticTypeTag);
   xml.writeAttribute("vector", _inputVectors[RAWVECTOR]->Name());
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.h #1222134:1222135
@@ -52,10 +52,6 @@
     void setVector(VectorPtr);
     VectorPtr vector() const;
 
-    // labels for plots
-    virtual LabelInfo xLabelInfo() const;
-    virtual LabelInfo yLabelInfo() const;
-
     bool isNormalizationNumber() const { return _NormalizationMode == Number; }
     void setIsNormalizationNumber() { _NormalizationMode = Number; }
     bool isNormalizationPercent() const { return _NormalizationMode == Percent; }
--- branches/work/kst/portto4/kst/src/libkstmath/image.cpp #1222134:1222135
@@ -388,6 +388,15 @@
 }
 
 
+LabelInfo Image::titleInfo() const {
+  if (_inputMatrices.contains(THEMATRIX)) {
+    return (_inputMatrices[THEMATRIX]->titleInfo());
+  } else {
+    return LabelInfo();
+  }
+}
+
+
 DataObjectPtr Image::providerDataObject() const {
   DataObjectPtr provider = 0L;
   // FIXME: fix this.. I don't know what's going on here
--- branches/work/kst/portto4/kst/src/libkstmath/image.h #1222134:1222135
@@ -96,6 +96,7 @@
     // labels for plots
     virtual LabelInfo xLabelInfo() const;
     virtual LabelInfo yLabelInfo() const;
+    virtual LabelInfo titleInfo() const;
 
     virtual RelationPtr makeDuplicate() const;
 
--- branches/work/kst/portto4/kst/src/libkstmath/psd.cpp #1222134:1222135
@@ -448,6 +448,11 @@
   label_info.units = _rateUnits;
   _fVector->setLabelInfo(label_info);
 
+  label_info.quantity.clear();
+  label_info.units.clear();
+  label_info.name = _inputVectors[INVECTOR]->labelInfo().name;
+  _sVector->setTitleInfo(label_info);
+
 }
 
 QString PSD::_automaticDescriptiveName() const {
--- branches/work/kst/portto4/kst/src/libkstmath/relation.h #1222134:1222135
@@ -169,6 +169,7 @@
 
     virtual LabelInfo xLabelInfo() const = 0;
     virtual LabelInfo yLabelInfo() const = 0;
+    virtual LabelInfo titleInfo() const = 0;
 
   protected:
     virtual void writeLockInputsAndOutputs() const;


More information about the Kst mailing list