[Kst] extragear/graphics/kst/kst

Rick Chern rchern at interchange.ubc.ca
Thu Aug 18 20:59:06 CEST 2005


SVN commit 450665 by rchern:

- backwards compatibility with old user labels (convert them to kstviewlabels)
- save full info (not just tagname) for objects within plots

 M  +54 -4     kst2dplot.cpp  
 M  +8 -2      kst2dplot.h  
 M  +1 -1      ksttoplevelview.cpp  
 M  +15 -1     kstviewobject.cpp  
 M  +1 -0      kstviewobject.h  


--- trunk/extragear/graphics/kst/kst/kst2dplot.cpp #450664:450665
@@ -52,6 +52,7 @@
 #include "kstsettings.h"
 #include "ksttimers.h"
 #include "kstviewwindow.h"
+#include "kstviewlabel.h"
 #include "kstvcurve.h"
 #include "kstvectordialog_i.h"
 #include "plotmimesource.h"
@@ -273,10 +274,8 @@
         in_legend = new KstLegend;
         in_legend->read(el);
       } else if (el.tagName() == "label") {
-        // FIXME support backward compatibility
-        //in_alabel = new KstLabel(" ");
-        //in_alabel->read(el);
-        //_labelList.append(in_alabel);
+        KstViewLabelPtr label = convertLabelToViewLabel(el);
+        appendChild(KstViewObjectPtr(label), true);
       } else if (el.tagName() == "curvetag") {
         ctaglist.append(el.text()); 
       } else if (el.tagName() == "image") { // for compatibility with older kst files
@@ -6543,6 +6542,57 @@
 } 
 
 
+KstViewLabelPtr Kst2DPlot::convertLabelToViewLabel(const QDomElement &e) {
+  KstViewLabelPtr label = new KstViewLabel("label");
+  label->setRotation(0.0);
+  label->setJustification(SET_KST_JUSTIFY(KST_JUSTIFY_H_CENTER, KST_JUSTIFY_V_BOTTOM));
+  label->setTransparent(true);
+  label->resizeFromAspect(0.05, 0.05, 0.05, 0.05);
+  label->setDataPrecision(LABEL_PRECISION);
+  
+  float xPos = 0.0, yPos = 0.0;
+  
+  QDomNode n = e.firstChild();
+  while (!n.isNull()) {
+    QDomElement e = n.toElement(); // try to convert the node to an element.
+    if (!e.isNull()) { // the node was really an element.
+      if (e.tagName() == "text") {
+        label->setText(e.text());
+      } else if  (e.tagName() == "justify") {
+        label->setJustification((KstJustifyType) e.text().toInt());
+      } else if  (e.tagName() == "rotation") {
+        label->setRotation(e.text().toFloat());
+      } else if  (e.tagName() == "interpret") {
+        label->setInterpreted(true);
+      } else if  (e.tagName() == "xpos") {
+        xPos = e.text().toFloat();
+      } else if (e.tagName() == "ypos") {
+        yPos = e.text().toFloat();
+      } else if (e.tagName() == "fontfamily") {
+        label->setFontName(e.text());
+      } else if (e.tagName() == "symbolfontfamily") {
+        // unsupported 
+      } else if (e.tagName() == "fontsize") {
+        label->setFontSize(e.text().toInt() - 12);
+      } else if (e.tagName() == "size") {
+        label->setFontSize(e.text().toInt());
+      } else if (e.tagName() == "useusercolor") {
+        label->setTransparent(false);
+      } else if (e.tagName() == "color") {
+        label->setForegroundColor(QColor(e.text()));
+      }
+    }
+    n = n.nextSibling();
+  }
+  
+  label->resizeFromAspect(xPos, yPos, 0.05, 0.05);
+  label->setAutoResize(true);
+  label->adjustSizeForText();
+  
+  return label;
+}
+
+
 #undef LABEL_PRECISION
 #include "kst2dplot.moc"
 
--- trunk/extragear/graphics/kst/kst/kst2dplot.h #450664:450665
@@ -20,8 +20,6 @@
 
 #include <time.h>
 
-#include <qvaluestack.h>
-
 #include "kstbackbuffer.h"
 #include "kstbasecurve.h"
 #include "kstcolorsequence.h"
@@ -29,6 +27,8 @@
 #include "kstplotdefines.h"
 #include "kstviewwidget.h"
 
+#include <qvaluestack.h>
+
 namespace Equation {
   class Node;
 }
@@ -37,6 +37,8 @@
 typedef KstSharedPtr<KstLegend> KstLegendPtr;
 class Kst2DPlot;
 typedef KstObjectList<KstSharedPtr<Kst2DPlot> > Kst2DPlotList;
+class KstViewLabel;
+typedef KstSharedPtr<KstViewLabel> KstViewLabelPtr;
 
 enum KstScaleModeType { AUTO, AC, FIXED, AUTOUP, NOSPIKE, AUTOBORDER, EXPRESSION };
 
@@ -393,6 +395,10 @@
   virtual KstViewObjectFactoryMethod factory() const;
 
 private:
+  
+  // for backwards compatibility with old labels - convert an old saved label to a KstViewLabel
+  KstViewLabelPtr convertLabelToViewLabel(const QDomElement &e);
+  
   void updateDirtyFromLabels();
 
   template<class T> void updateTiedPlots(void (Kst2DPlot::*method)(T), T arg);
--- trunk/extragear/graphics/kst/kst/ksttoplevelview.cpp #450664:450665
@@ -119,7 +119,7 @@
   }
   for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
     if ((*i)->type() == "plot") {
-      (*i)->saveTag(ts, indent);  // special case: only save tags for plots when they are children
+      (*i)->saveTagOnce(ts, indent);  // special case: only save tags for plots when they are children
     } else {
       (*i)->save(ts, indent);  // all other view objects are saved normally
     }
--- trunk/extragear/graphics/kst/kst/kstviewobject.cpp #450664:450665
@@ -236,7 +236,7 @@
 
   for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
     if ((*i)->type() == "plot") {
-      (*i)->saveTag(ts, indent); // special case: only save tags for plots when they are children  
+      (*i)->saveTagOnce(ts, indent); // special case: only save tags for plots when they are children  
     } else {
       (*i)->save(ts, indent + "  "); // all other view objects are saved normally
     }
@@ -255,6 +255,20 @@
 }
 
 
+void KstViewObject::saveTagOnce(QTextStream& ts, const QString& indent) {
+  QString l2 = indent + "  ";
+  ts << indent << "<" << type() << ">" << endl;
+  for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
+    if ((*i)->type() == "plot") {
+      (*i)->saveTagOnce(ts, indent); // special case: only save tags for plots when they are children  
+    } else {
+      (*i)->save(ts, indent + "  "); // all other view objects are saved normally
+    }
+  }
+  ts << indent << "</" << type() << ">" << endl;
+}
+
+
 void KstViewObject::paint(KstPaintType type, QPainter& p) {
   bool hadClipping = p.hasClipping();
   QRegion oldRegion = p.clipRegion();
--- trunk/extragear/graphics/kst/kst/kstviewobject.h #450664:450665
@@ -71,6 +71,7 @@
     virtual UpdateType update(int = -1);
     virtual void save(QTextStream& ts, const QString& indent = QString::null);
     virtual void saveTag(QTextStream& ts, const QString& indent = QString::null);
+    virtual void saveTagOnce(QTextStream& ts, const QString& indent = QString::null);
     virtual void loadChildren(const QDomElement& e);
 
     virtual QRegion clipRegion();


More information about the Kst mailing list