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

Barth Netterfield netterfield at astro.utoronto.ca
Mon Nov 1 21:20:41 CET 2010


SVN commit 1192057 by netterfield:

BUG: 250014
Handle special characters in field and vector names.
i) the characters _^[] in field names are escaped with \ so they
appear properly in automatically generated labels.  So, a data vector of the 
field GY_AZ will appear in the UI as "GY\_AZ (V2)" and as GY_AZ in automatic
labels.  The same applies to scalars, strings, and matrixes.

ii) the characters [] are removed from the descriptive names of vectors when they
are used in equations.  So a Vector called "WGS84 Altitude [m] (V4)" will appear in
in the equation as "[WGS84 Altitude m (V4)]" but will otherwise work as expected.
The same applies to matrixes and scalars.




 M  +6 -1      src/libkst/datamatrix.cpp  
 M  +7 -1      src/libkst/datascalar.cpp  
 M  +7 -1      src/libkst/datastring.cpp  
 M  +9 -2      src/libkst/datavector.cpp  
 M  +2 -0      src/libkst/namedobject.cpp  
 M  +3 -1      src/libkstapp/equationdialog.cpp  
 M  +7 -2      src/libkstmath/enodes.cpp  
 M  +4 -4      tests/dirfile_maker/dirfile_maker.c  


--- branches/work/kst/portto4/kst/src/libkst/datamatrix.cpp #1192056:1192057
@@ -637,7 +637,12 @@
 
 QString DataMatrix::_automaticDescriptiveName() const{
   QString name = field();
-  return name.replace('_', "\\_");
+  // un-escape escaped special characters so they aren't escaped 2x.
+  name.replace("\\_", "_").replace("\\^","^").replace("\\[", "[").replace("\\]", "]");
+  // now escape the special characters.
+  name.replace('_', "\\_").replace('^', "\\^").replace('[', "\\[").replace(']', "\\]");
+
+  return name;
 }
 
 QString DataMatrix::descriptionTip() const {
--- branches/work/kst/portto4/kst/src/libkst/datascalar.cpp #1192056:1192057
@@ -44,7 +44,13 @@
 
 QString DataScalar::_automaticDescriptiveName() const {
   QString name = _dp->_field;
-  return name.replace('_', "\\_");
+
+  // un-escape escaped special characters so they aren't escaped 2x.
+  name.replace("\\_", "_").replace("\\^","^").replace("\\[", "[").replace("\\]", "]");
+  // now escape the special characters.
+  name.replace('_', "\\_").replace('^', "\\^").replace('[', "\\[").replace(']', "\\]");
+
+  return name;
 }
 
 
--- branches/work/kst/portto4/kst/src/libkst/datastring.cpp #1192056:1192057
@@ -44,7 +44,13 @@
 
 QString DataString::_automaticDescriptiveName() const {
   QString name = _dp->_field;
-  return name.replace('_', "\\_");
+
+  // un-escape escaped special characters so they aren't escaped 2x.
+  name.replace("\\_", "_").replace("\\^","^").replace("\\[", "[").replace("\\]", "]");
+  // now escape the special characters.
+  name.replace('_', "\\_").replace('^', "\\^").replace('[', "\\[").replace(']', "\\]");
+
+  return name;
 }
 
 
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #1192056:1192057
@@ -321,7 +321,10 @@
     }
   } else {
     label = _dp->_field;
-    label.replace('_', "\\_");
+    // un-escape escaped special characters so they aren't escaped 2x.
+    label.replace("\\_", "_").replace("\\^","^").replace("\\[", "[").replace("\\]", "]");
+    // now escape the special characters.
+    label.replace('_', "\\_").replace('^', "\\^").replace('[', "\\[").replace(']', "\\]");
   }
 
   return label;
@@ -723,7 +726,11 @@
 QString DataVector::_automaticDescriptiveName() const {
   QString name;
   name = _dp->_field;
-  return name.replace('_', "\\_");
+  // un-escape escaped special characters so they aren't escaped 2x.
+  name.replace("\\_", "_").replace("\\^","^").replace("\\[", "[").replace("\\]", "]");
+  // now escape the special characters.
+  name.replace('_', "\\_").replace('^', "\\^").replace('[', "\\[").replace(']', "\\]");
+  return name;
 }
 
 QString DataVector::descriptionTip() const {
--- branches/work/kst/portto4/kst/src/libkst/namedobject.cpp #1192056:1192057
@@ -49,6 +49,8 @@
 QString NamedObject::CleanedName() const {
   QString clean_name = Name();
   clean_name.replace("\\_","_");
+  clean_name.replace("\\[","[");
+  clean_name.replace("\\]","]");
 
   return clean_name;
 }
--- branches/work/kst/portto4/kst/src/libkstapp/equationdialog.cpp #1192056:1192057
@@ -67,8 +67,10 @@
 
 
 void EquationTab::equationUpdate(const QString& string) {
+  QString cleanString = string;
+  cleanString.remove('[').remove(']'); // HACK: '[' in descriptive names mess up parser.  Remove them.
   QString equation = _equation->text();
-  equation += '[' + string + ']';
+  equation += '[' + cleanString + ']';
   _equation->setText(equation); 
 }
 
--- branches/work/kst/portto4/kst/src/libkstmath/enodes.cpp #1192056:1192057
@@ -792,13 +792,18 @@
 }
 
 
+// Hack alert: [ and ] in names confuse the parser, so strip them out.
 QString DataNode::text() const {
   if (_isEquation) {
     return QString("[=") + _tagName + ']';
   } else if (_vector) {
-    return QString('[') + _vector->Name() + QString(']');
+    QString Name = _vector->Name();
+    Name.remove("\\[").remove("\\]");
+    return QString('[') + Name.remove('[').remove(']') + QString(']');
   } else if (_scalar) {
-    return QString('[') + _scalar->Name() + QString(']');
+    QString Name = _scalar->Name();
+    Name.remove("\\[").remove("\\]");
+    return QString('[') + Name.remove('[').remove(']') + QString(']');
   } else {
     return QString();
   }
--- branches/work/kst/portto4/kst/tests/dirfile_maker/dirfile_maker.c #1192056:1192057
@@ -34,10 +34,10 @@
   {"E2", 20, -1, 'f'},
   {"E3", 20, -1, 'f'},
   {"E4", 20, -1, 'f'},
-  {"E5", 20, -1, 'f'},
-  {"E6", 20, -1, 'f'},
-  {"E7", 20, -1, 'f'},
-  {"E8", 20, -1, 'f'}
+  {"E5_test", 20, -1, 'f'},
+  {"E6_test", 20, -1, 'f'},
+  {"E7[m]", 20, -1, 'f'},
+  {"E8^2", 20, -1, 'f'}
 };
   
 int main() {


More information about the Kst mailing list