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

Barth Netterfield netterfield at astro.utoronto.ca
Mon Mar 18 13:57:52 UTC 2013


SVN commit 1345052 by netterfield:

BUG: 315362

Allow the x and y plot labels to be changed from the command line.


 M  +35 -1     commandlineparser.cpp  
 M  +3 -0      commandlineparser.h  


--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.cpp #1345051:1345052
@@ -77,6 +77,10 @@
 "      -d:                      use points for the next curve\n"
 "      -l:                      use lines for the next curve\n"
 "      -b:                      use bargraph for the next curve\n"
+"      --xlabel <X Label>       Set X label of all future plots.\n"
+"      --ylabel <Y Label>       Set Y label of all future plots.\n"
+"      --xlabelauto             AutoSet X label of all future plots.\n"
+"      --ylabelauto             AutoSet Y label of all future plots.\n"
 "Data Object Modifiers\n"
 "      -x <field>:              Create vector and use as X vector for curves.\n"
 "      -e <field>:              Create vector and use as Y-error vector for next -y.\n"
@@ -156,6 +160,8 @@
   _fileNames.clear();
   _vectors.clear();
   _plotItems.clear();
+  _xlabel.clear();
+  _ylabel.clear();
 }
 
 
@@ -296,6 +302,7 @@
       cmd->createItem();
       _plotItem = static_cast<PlotItem*>(cmd->item());
       _plotItem->view()->appendToLayout(CurvePlacement::Auto, _plotItem);
+      applyLabels();
     }
     PlotRenderItem *renderItem = _plotItem->renderItem(PlotRenderItem::Cartesian);
     renderItem->addRelation(kst_cast<Relation>(curve));
@@ -316,6 +323,7 @@
       cmd->createItem();
       _plotItem = static_cast<PlotItem*>(cmd->item());
       _plotItem->view()->appendToLayout(CurvePlacement::Auto, _plotItem);
+      applyLabels();
     }
     PlotRenderItem *renderItem = _plotItem->renderItem(PlotRenderItem::Cartesian);
     renderItem->addRelation(kst_cast<Relation>(image));
@@ -344,10 +352,29 @@
       pi->setDescriptiveName( plot_name );
       _plotItems.append(pi);
       pi->view()->appendToLayout(CurvePlacement::Auto, pi);
+      _plotItem = pi;
+      applyLabels();
     }
     _plotItem = pi;
+
 }
 
+void CommandLineParser::applyLabels() {
+  if (!_plotItem) {
+    return;
+  }
+
+  if (!_xlabel.isEmpty()) {
+    _plotItem->bottomLabelDetails()->setText(_xlabel);
+    _plotItem->bottomLabelDetails()->setIsAuto(false);
+  }
+  if (!_ylabel.isEmpty()) {
+    _plotItem->leftLabelDetails()->setText(_ylabel);
+    _plotItem->leftLabelDetails()->setIsAuto(false);
+  }
+
+}
+
 QString CommandLineParser::kstFileName() {
   if (_fileNames.size()>0) {
     return (_fileNames.at(0));
@@ -406,7 +433,6 @@
       QString plot_name;
       *ok = _setStringArg(plot_name,i18n("Usage: -P <plotname>\n"));
       _doConsecutivePlots=false;
-
       createOrFindPlot(plot_name);
     } else if (arg == "-A") {
       _doConsecutivePlots = true;
@@ -519,6 +545,14 @@
         new_fileList = true;
         _overrideStyle = false;
       }
+    } else if (arg == "--xlabel") {
+      *ok = _setStringArg(_xlabel, "Usage -xlabel <label>\n");
+    } else if (arg == "--ylabel") {
+      *ok = _setStringArg(_ylabel, "Usage -ylabel <label>\n");
+    } else if (arg == "--xlabelauto") {
+      _xlabel.clear();
+    } else if (arg == "--ylabelauto") {
+      _ylabel.clear();
     } else if (arg == "-h") {
       QString field;
       *ok = _setStringArg(field,i18n("Usage: -h <fieldname>\n"));
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.h #1345051:1345052
@@ -66,6 +66,8 @@
   QStringList _fileNames;
   QStringList _arguments;
   PlotItem *_plotItem;
+  QString _xlabel;
+  QString _ylabel;
   
   // lists of command line named plot items (and their names).
   QList<PlotItem*> _plotItems;
@@ -83,6 +85,7 @@
   void createImageInPlot(MatrixPtr m);
   void addCurve(CurvePtr curve);
   ObjectList<Object> autoCurves(DataSourcePtr ds);
+  void applyLabels();
 };
 
 }


More information about the Kst mailing list