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

Barth Netterfield netterfield at astro.utoronto.ca
Fri Mar 11 14:02:24 CET 2011


SVN commit 1224488 by netterfield:

Legends and labels now properly handle curves with different units,
by putting them in the legend rather than in the axis label.



 M  +13 -8     legenditem.cpp  
 M  +29 -18    plotrenderitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/legenditem.cpp #1224487:1224488
@@ -91,7 +91,7 @@
   bool sameX = true;
   bool sameYUnits = true;
   LabelInfo label_info = legendItems.at(0)->xLabelInfo();
-  QString yUnits =  legendItems.at(0)->xLabelInfo().units;
+  QString yUnits =  legendItems.at(0)->yLabelInfo().units;
 
   for (int i = 0; i<count; i++) {
     RelationPtr relation = legendItems.at(i);
@@ -118,20 +118,25 @@
   } else {
     for (int i = 0; i<count; i++) {
       RelationPtr relation = legendItems.at(i);
-      label_info = relation->titleInfo();
-      QString label = label_info.singleRenderItemLabel();
+      QString label = relation->titleInfo().singleRenderItemLabel();
       if (label.isEmpty()) {
         label_info = relation->yLabelInfo();
-        if (!label_info.name.isEmpty()) {
+        QString y_label = label_info.name;
+        if (!sameYUnits) {
+          if (!label_info.units.isEmpty()) {
+            y_label = i18n("%1 \\[%2\\]").arg(y_label).arg(label_info.units);
+          }
+        }
+        if (!y_label.isEmpty()) {
           LabelInfo xlabel_info = relation->xLabelInfo();
           if (!sameX) {
-            label = i18n("%1 vs %2").arg(label_info.name).arg(xlabel_info.name);
+            label = i18n("%1 vs %2").arg(y_label).arg(xlabel_info.name);
           } else if (xlabel_info.quantity.isEmpty()) {
-            label = label_info.name;
+            label = y_label;
           } else if (xlabel_info.quantity != xlabel_info.name) {
-            label = i18n("%1 vs %2").arg(label_info.name).arg(xlabel_info.name);
+            label = i18n("%1 vs %2").arg(y_label).arg(xlabel_info.name);
           } else {
-            label = label_info.name;
+            label = y_label;
           }
         } else {
           label = relation->descriptiveName();
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #1224487:1224488
@@ -326,7 +326,10 @@
   units.clear();
   quantity.clear();
 
-  bool allSame = true;
+  bool nameSame = true;
+  bool unitsSame = true;
+  bool quantitySame = true;
+
   int count;
 
   count = relationList().size();
@@ -341,32 +344,40 @@
     } else {
       label_info = relationList().at(i)->yLabelInfo();
     }
-    if (label_info != first_label_info) {
-      allSame = false;
+    if (label_info.name != first_label_info.name) {
+      nameSame = false;
     }
+    if (!label_info.units.isEmpty()) {
+      if (units.isEmpty()) {
+        units = label_info.units;
+      } else {
+        if (label_info.units != units) {
+          unitsSame = false;
   }
-
-  if (allSame) {
-    return label_info.singleRenderItemLabel();
   }
-
-  // search for the first vector with quantity and units; use it.
-  foreach (const RelationPtr &relation, relationList()) {
-    if (isX) {
-      label_info = relation->xLabelInfo();
-    } else {
-      label_info = relation->yLabelInfo();
     }
-    if (!label_info.quantity.isEmpty() && !label_info.units.isEmpty()) {
-      return QString("%1 \\[%2\\]").arg(label_info.quantity).arg(label_info.units);
-    }
     if (!label_info.quantity.isEmpty()) {
+      if (quantity.isEmpty()) {
       quantity = label_info.quantity;
+      } else {
+        if (label_info.quantity != quantity) {
+          quantitySame = false;
     }
-    if (!label_info.units.isEmpty()) {
-      units = label_info.units;
     }
   }
+  }
+
+  if (nameSame && unitsSame && quantitySame) {
+    return label_info.singleRenderItemLabel();
+  }
+
+  if (!quantitySame) {
+    quantity.clear();
+  }
+  if (!unitsSame) {
+    units.clear();
+  }
+
   if (!units.isEmpty() && !quantity.isEmpty()) {
     return QString("%1 \\[%2\\]").arg(quantity).arg(units);
   } else if (!units.isEmpty()) {


More information about the Kst mailing list