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

Barth Netterfield netterfield at astro.utoronto.ca
Wed Oct 14 23:33:31 CEST 2009


SVN commit 1035386 by netterfield:

Fix some bugs in reading files
Some auto-label changes


 M  +4 -0      devel-docs/Kst2Specs/Wishlist  
 M  +6 -5      src/datasources/ascii/ascii.cpp  
 M  +8 -1      src/datasources/qimagesource/qimagesource.cpp  
 M  +28 -10    src/libkst/datavector.cpp  
 M  +17 -10    src/libkstapp/plotitem.cpp  
 M  +19 -6     src/libkstapp/plotrenderitem.cpp  
 M  +26 -27    src/libkstmath/curve.cpp  
 M  +1 -0      tests/dirfile_maker/dirfile_maker.c  


--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/Wishlist #1035385:1035386
@@ -61,3 +61,7 @@
 
 Fixup line/arrow dimensions tab:
   x,y instead of length/angle
+
+------------
+
+Names in multipage graphics file export.  name_2.png, not name.png_2, etc
--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.cpp #1035385:1035386
@@ -1012,6 +1012,10 @@
   AsciiSource::Config config;
   config.read(cfg, filename);
 
+  if (!QFile::exists(filename) || QFileInfo(filename).isDir()) {
+    return 0;
+  }
+
   if (!config._fileNamePattern.isEmpty()) {
     QRegExp filenamePattern(config._fileNamePattern);
     filenamePattern.setPatternSyntax(QRegExp::Wildcard);
@@ -1020,10 +1024,6 @@
     }
   }
 
-  if (!QFile::exists(filename) || QFileInfo(filename).isDir()) {
-    return 0;
-  }
-
   QFile f(filename);
   if (f.open(QIODevice::ReadOnly)) {
     QByteArray s;
@@ -1060,7 +1060,8 @@
         // a number - this may be an ascii file - assume that it is
         // This line checks for an indirect file and gives that a chance too.
         // Indirect files look like ascii files.
-        return QFile::exists(s.trimmed()) ? 49 : 75;
+        return 75;
+        //return QFile::exists(s.trimmed()) ? 49 : 75;
       } else {
         return 20;
       }
--- branches/work/kst/portto4/kst/src/datasources/qimagesource/qimagesource.cpp #1035385:1035386
@@ -411,9 +411,16 @@
     return 0;
 
   if ( ftype == "TIFF" ) {
-    if ( !filename.endsWith(".tif") ) return 0;
+    if ( !filename.toLower().endsWith(".tif") ) return 0;
   }
 
+
+  //QImageReader is incorrectly identifying a single column ascii file with
+  // the first row blank as a pcx file... so... enforce filename...
+  if ( ftype == "pcx" ) {
+    if ( !filename.toLower().endsWith(".pcx") ) return 0;
+  }
+
   return 90;
 }
 
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #1035385:1035386
@@ -299,20 +299,33 @@
   bool ok;
   QString label;
 
-  _field.toInt(&ok);
-  if (ok && _file) {
-    _file->readLock();
-    if (_file->fileType() == "ASCII") {
-      label = i18n("Column %1", _field);
+  if (_fieldStrings.contains("quantity")) {
+    label = _fieldStrings.value("quantity")->value();
+  }
+
+  if (!label.isEmpty()) {
+    if (_fieldStrings.contains("units")) {
+      QString units = _fieldStrings.value("units")->value();
+      if (!units.isEmpty()) {
+        label += "\\[" + units + "\\]";
+      }
+    }
+  } else {
+    _field.toInt(&ok);
+    if (ok && _file) {
+      _file->readLock();
+      if (_file->fileType() == "ASCII file") {
+        label = i18n("Column %1", _field);
+      } else {
+        label = _field;
+      }
+      _file->unlock();
     } else {
       label = _field;
     }
-    _file->unlock();
-  } else {
-    label = _field;
+    label.replace('_', "\\_");
   }
 
-  label.replace('_', "\\_");
   return label;
 }
 
@@ -757,7 +770,12 @@
 }
 
 QString DataVector::_automaticDescriptiveName() const {
-  QString name = field();
+  QString name;
+  if (_file->fileType() == "ASCII file") {
+    name = i18n("Column %1", _field);
+  } else {
+    name = _field;
+  }
   return name.replace("_", "\\_");
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #1035385:1035386
@@ -1821,8 +1821,9 @@
 
 QString PlotItem::autoLeftLabel() const {
   foreach (PlotRenderItem *renderer, renderItems()) {
-    if (!renderer->leftLabel().isEmpty())
-      return renderer->leftLabel();
+    QString label = renderer->leftLabel();
+    if (!label.isEmpty())
+      return label;
   }
   return QString();
 }
@@ -1839,8 +1840,9 @@
 
 QString PlotItem::autoBottomLabel() const {
   foreach (PlotRenderItem *renderer, renderItems()) {
-    if (!renderer->bottomLabel().isEmpty())
-      return renderer->bottomLabel();
+    QString label = renderer->bottomLabel();
+    if (!label.isEmpty())
+      return label;
   }
   return QString();
 }
@@ -1857,8 +1859,9 @@
 
 QString PlotItem::autoRightLabel() const {
   foreach (PlotRenderItem *renderer, renderItems()) {
-    if (!renderer->rightLabel().isEmpty())
-      return renderer->rightLabel();
+    QString label = renderer->rightLabel();
+    if (!label.isEmpty())
+      return label;
   }
   return QString();
 }
@@ -1874,11 +1877,15 @@
 
 
 QString PlotItem::autoTopLabel() const {
-  foreach (PlotRenderItem *renderer, renderItems()) {
-    if (!renderer->topLabel().isEmpty())
-      return renderer->topLabel();
+  if (showLegend()) {
+    return QString();
+  } else {
+    QString label;
+    foreach (PlotRenderItem *renderer, renderItems()) {
+      label += renderer->topLabel() + " ";
+    }
+    return label;
   }
-  return QString();
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #1035385:1035386
@@ -317,10 +317,11 @@
 
 
 QString PlotRenderItem::leftLabel() const {
-  // This will make sense once curves learn
-  // to return <Quantity> [<Units>]
   QStringList labels;
 
+  // chose the first vector with a label.
+  // for best results here, vectors should define
+  // fieldScalars "quantity" and "units".
   foreach (RelationPtr relation, relationList()) {
     if (!relation->yLabel().isEmpty()) {
       return relation->yLabel();
@@ -340,16 +341,28 @@
 
 
 QString PlotRenderItem::rightLabel() const {
-  // right labels should only be used where there is more htan one 
+  // right labels should only be used where there is more than one
   // projection in the plot...
   return QString();
 }
 
 
 QString PlotRenderItem::topLabel() const {
-  // right labels should only be used where there is more htan one 
-  // projection in the plot...
-  return QString();
+  QString label;
+  int count;
+  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 ");
+      } else {
+        //label += i18n(", ", "separater in a list");
+        label += i18n(", ");
+      }
+    }
+    label += relationList().at(i)->topLabel();
+  }
+  return label;
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstmath/curve.cpp #1035385:1035386
@@ -58,8 +58,8 @@
 const QString Curve::staticTypeString = I18N_NOOP("Curve");
 const QString Curve::staticTypeTag = I18N_NOOP("curve");
 
-static const QLatin1String& COLOR_XVECTOR = QLatin1String("X");
-static const QLatin1String& COLOR_YVECTOR = QLatin1String("Y");
+static const QLatin1String& XVECTOR = QLatin1String("X");
+static const QLatin1String& YVECTOR = QLatin1String("Y");
 static const QLatin1String& EXVECTOR = QLatin1String("EX");
 static const QLatin1String& EYVECTOR = QLatin1String("EY");
 static const QLatin1String& EXMINUSVECTOR = QLatin1String("EXMinus");
@@ -106,8 +106,8 @@
 Object::UpdateType Curve::update() {
   Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
 
-  VectorPtr cxV = *_inputVectors.find(COLOR_XVECTOR);
-  VectorPtr cyV = *_inputVectors.find(COLOR_YVECTOR);
+  VectorPtr cxV = *_inputVectors.find(XVECTOR);
+  VectorPtr cyV = *_inputVectors.find(YVECTOR);
   if (!cxV || !cyV) {
     return NO_CHANGE;
   }
@@ -283,8 +283,8 @@
 
 void Curve::save(QXmlStreamWriter &s) {
   s.writeStartElement(staticTypeTag);
-  s.writeAttribute("xvector", _inputVectors[COLOR_XVECTOR]->Name());
-  s.writeAttribute("yvector", _inputVectors[COLOR_YVECTOR]->Name());
+  s.writeAttribute("xvector", _inputVectors[XVECTOR]->Name());
+  s.writeAttribute("yvector", _inputVectors[YVECTOR]->Name());
   if (_inputVectors.contains(EXVECTOR)) {
     s.writeAttribute("errorxvector", _inputVectors[EXVECTOR]->Name());
   }
@@ -319,22 +319,22 @@
 
 void Curve::setXVector(VectorPtr new_vx) {
   if (new_vx) {
-    _inputVectors[COLOR_XVECTOR] = new_vx;
+    _inputVectors[XVECTOR] = new_vx;
     connect(new_vx, SIGNAL(updated(ObjectPtr)), this, SLOT(vectorUpdated(ObjectPtr)));
   } else {
-    disconnect(_inputVectors[COLOR_XVECTOR], SIGNAL(updated(ObjectPtr)));
-    _inputVectors.remove(COLOR_XVECTOR);
+    disconnect(_inputVectors[XVECTOR], SIGNAL(updated(ObjectPtr)));
+    _inputVectors.remove(XVECTOR);
   }
 }
 
 
 void Curve::setYVector(VectorPtr new_vy) {
   if (new_vy) {
-    _inputVectors[COLOR_YVECTOR] = new_vy;
+    _inputVectors[YVECTOR] = new_vy;
     connect(new_vy, SIGNAL(updated(ObjectPtr)), this, SLOT(vectorUpdated(ObjectPtr)));
   } else {
-    disconnect(_inputVectors[COLOR_YVECTOR], SIGNAL(updated(ObjectPtr)));
-    _inputVectors.remove(COLOR_YVECTOR);
+    disconnect(_inputVectors[YVECTOR], SIGNAL(updated(ObjectPtr)));
+    _inputVectors.remove(YVECTOR);
   }
 }
 
@@ -392,18 +392,17 @@
 
 
 QString Curve::xLabel() const {
-  return _inputVectors[COLOR_XVECTOR]->label();
+  return _inputVectors[XVECTOR]->label();
 }
 
 
 QString Curve::yLabel() const {
-  return _inputVectors[COLOR_YVECTOR]->label();
+  return _inputVectors[YVECTOR]->label();
 }
 
 
 QString Curve::topLabel() const {
-  return QString::null;
-  //return VY->fileLabel();
+  return _inputVectors[YVECTOR]->descriptiveName();
 }
 
 
@@ -428,18 +427,18 @@
 
 
 int Curve::samplesPerFrame() const {
-  const DataVector *rvp = dynamic_cast<const DataVector*>(_inputVectors[COLOR_YVECTOR].data());
+  const DataVector *rvp = dynamic_cast<const DataVector*>(_inputVectors[YVECTOR].data());
   return rvp ? rvp->samplesPerFrame() : 1;
 }
 
 
 VectorPtr Curve::xVector() const {
-  return *_inputVectors.find(COLOR_XVECTOR);
+  return *_inputVectors.find(XVECTOR);
 }
 
 
 VectorPtr Curve::yVector() const {
-  return *_inputVectors.find(COLOR_YVECTOR);
+  return *_inputVectors.find(YVECTOR);
 }
 
 
@@ -464,7 +463,7 @@
 
 
 bool Curve::xIsRising() const {
-  return _inputVectors[COLOR_XVECTOR]->isRising();
+  return _inputVectors[XVECTOR]->isRising();
 }
 
 
@@ -516,8 +515,8 @@
 /** getIndexNearXY: return index of point within (or closest too)
     x +- dx which is closest to y **/
 int Curve::getIndexNearXY(double x, double dx_per_pix, double y) const {
-  VectorPtr xv = *_inputVectors.find(COLOR_XVECTOR);
-  VectorPtr yv = *_inputVectors.find(COLOR_YVECTOR);
+  VectorPtr xv = *_inputVectors.find(XVECTOR);
+  VectorPtr yv = *_inputVectors.find(YVECTOR);
   if (!xv || !yv) {
     return 0; // anything better we can do?
   }
@@ -719,8 +718,8 @@
   _filledRects.clear();
   _rects.clear();
 
-  VectorPtr xv = *_inputVectors.find(COLOR_XVECTOR);
-  VectorPtr yv = *_inputVectors.find(COLOR_YVECTOR);
+  VectorPtr xv = *_inputVectors.find(XVECTOR);
+  VectorPtr yv = *_inputVectors.find(YVECTOR);
   if (!xv || !yv) {
     return;
   }
@@ -1503,8 +1502,8 @@
     return;
   }
 
-  VectorPtr xv = *_inputVectors.find(COLOR_XVECTOR);
-  VectorPtr yv = *_inputVectors.find(COLOR_YVECTOR);
+  VectorPtr xv = *_inputVectors.find(XVECTOR);
+  VectorPtr yv = *_inputVectors.find(YVECTOR);
   if (!xv || !yv) {
     *yMin = *yMax = 0;
     return;
@@ -1561,7 +1560,7 @@
 
 double Curve::distanceToPoint(double xpos, double dx, double ypos) const {
 // find the y distance between the curve and a point. return 1.0E300 if this distance is undefined. i don't want to use -1 because it will make the code which uses this function messy.
-  VectorPtr xv = *_inputVectors.find(COLOR_XVECTOR);
+  VectorPtr xv = *_inputVectors.find(XVECTOR);
   if (!xv) {
     return 1.0E300; // anything better we can do?
   }
--- branches/work/kst/portto4/kst/tests/dirfile_maker/dirfile_maker.c #1035385:1035386
@@ -73,6 +73,7 @@
   fprintf(fpf,"META cos metaC CONST FLOAT64 3.291882\n"
   "META cos metaS STRING Test_String\n");
 
+  fprintf(fpf, "cos/units STRING ^o\ncos/quantity STRING Angle\n");
   fclose(fpf);
 
   /* make curfile */


More information about the Kst mailing list