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

Barth Netterfield netterfield at astro.utoronto.ca
Wed Nov 11 01:22:02 CET 2009


SVN commit 1047321 by netterfield:

'Fix' a crash on exit.
Export to ps, pdf, or png files from the command line.


 M  +0 -3      devel-docs/Kst2Specs/Bugs  
 M  +16 -0     devel-docs/Kst2Specs/FixedBugs  
 M  +17 -33    devel-docs/Kst2Specs/Wishlist  
 M  +1 -0      src/kst/main.cpp  
 M  +8 -3      src/libkstapp/application.cpp  
 M  +5 -1      src/libkstapp/commandlineparser.cpp  
 M  +5 -0      src/libkstapp/commandlineparser.h  
 M  +3 -4      src/libkstapp/document.cpp  
 M  +2 -1      src/libkstapp/document.h  
 M  +79 -55    src/libkstapp/mainwindow.cpp  
 M  +3 -0      src/libkstapp/mainwindow.h  
 M  +0 -1      src/libkstapp/plotrenderitem.cpp  


--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/Bugs #1047320:1047321
@@ -9,6 +9,3 @@
 
 Artifacts when resizing large arrowheads.
 
---------------------
-
-Segfault on exit if there is a shared axis box.
--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/FixedBugs #1047320:1047321
@@ -1136,3 +1136,19 @@
 --------------------
 
 Datasources that are browsed are created, remembered, and saved/loaded.
+
+----------
+
+Improve behavior of data wizard selector
+
+
+------------
+
+Names in multipage graphics file export.  name_2.png, not name.png_2, etc
+
+--------
+
+Printing from the command line.  This existed in 1.x
+  Note: printing still requires parts of Qt which require a window session, so pure scripted 
+  headless prints are not possible :-(
+
--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/Wishlist #1047320:1047321
@@ -1,8 +1,10 @@
-Easier way to specify reversed axis when loading sky images:
-  -can desire to reverse be gleaned from the fits image?
-  -command line option?
-  -new-image (sticky) option?
+Export eps to vector format.
+  kst 1.x did this by printing to file a .ps file, and then modifying it by adding the bounding box.
 
+------------
+
+Shared axis from the command line
+
 ---------
 
 Smarter ASCII reader:
@@ -11,26 +13,18 @@
     (eg, is it a CSV?  Does it have a field name header?)
   these should be used only for new files, and should be used to sed the defaults, which can still be changed with 'configure'.
 
----------
+------------
 
-15. The text label behaviour is un-intuitive.  The typical interface is
-to choose a position first, and then input some text.
-   ** -a possible justification for the current order is that it could allow us to 
-      drag around the label once we have defined it, for more precision placement.
-      not sure yet if we should change anything. **
+Fixup line/arrow dimensions tab:
+  x,y instead of length/angle
 
+
 ----------
 
 Tooltips/whats this where helpful.
 
 ----------
 
-Printing from the command line.  This existed in 1.x
-  Note: printing still requires parts of Qt which require a window session, so pure scripted 
-  headless prints are not possible :-(
-
---------
-
 Scientific notation (instead of C's %e notation) for extreme axis numbers
 
 --------
@@ -39,11 +33,6 @@
 
 --------
 
-Export eps to vector format.
-  kst 1.x did this by printing to file a .ps file, and then modifying it by adding the bounding box.
-
-------------
-
 data source text box doesn't recognise initial ~ as a euphemism for
    the user's home directory (QDirModel doesn't handle this...)
    (nor QDir, though QDir seems to know about $HOME).
@@ -57,19 +46,14 @@
 DECIDE: absolute or relative file names in kst files?
   kst1.x uses absolute.  This becomes a problem when the directory changes.
 
-------------
-
-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
-
 -----------
 
-Improve behavior of data wizard selector
+Easier way to specify reversed axis when loading sky images:
+  -can desire to reverse be gleaned from the fits image?
+  -command line option?
+  -new-image (sticky) option?
 
-----------
+---------
 
-Shared axis from the command line
+After the label creation dialog has been applied, attach the label to
+the mouse, to allow it to be dragged around until placed by a click.
--- branches/work/kst/portto4/kst/src/kst/main.cpp #1047320:1047321
@@ -14,6 +14,7 @@
 int main(int argc, char *argv[]) {
   Kst::Application app(argc, argv);
   if (app.mainWindow()->initFromCommandLine()) {
+    app.mainWindow()->show();
     return app.exec();
   }
   return 0;
--- branches/work/kst/portto4/kst/src/libkstapp/application.cpp #1047320:1047321
@@ -29,6 +29,7 @@
     : QApplication(argc, argv) {
 
   QCoreApplication::setApplicationName("Kst");
+  setWindowIcon(QPixmap(":kst.png"));
 
   _dialogDefaults = new QSettings("kst", "dialog");
 
@@ -48,13 +49,17 @@
 
   connect(this, SIGNAL(aboutToQuit()), _mainWindow, SLOT(aboutToQuit()));
 
-  _mainWindow->show();
+  //_mainWindow->show();
 }
 
 
 Application::~Application() {
-  delete _mainWindow;
-  delete _dialogDefaults;
+  // lets not clean up before we leave....
+  // if we do, we'll end up crashing on exit
+  // unless we fix some stuff related to destruction
+  // in a multi-threaded situation.
+  //delete _mainWindow;
+  //delete _dialogDefaults;
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.cpp #1047320:1047321
@@ -128,7 +128,7 @@
       _doAve(false), _doSkip(false), _doConsecutivePlots(true), _useBargraph(false), 
       _useLines(true), _usePoints(false), _overrideStyle(false), _sampleRate(1.0), 
       _numFrames(-1), _startFrame(-1),
-      _skip(0), _plotName(), _errorField(), _fileName(), _xField(QString("INDEX")) {
+      _skip(0), _plotName(), _errorField(), _fileName(), _xField(QString("INDEX")), _pngFile(QString()){
 
   Q_ASSERT(QCoreApplication::instance());
   _arguments = QCoreApplication::instance()->arguments();
@@ -533,6 +533,10 @@
         new_fileList = true;
         dataPlotted = true;
       }
+    } else if (arg == "--png") {
+      *ok = _setStringArg(_pngFile, i18n("Usage: --png <filename>\n"));
+    } else if (arg == "--print") {
+      *ok = _setStringArg(_printFile, i18n("Usage: --print <filename>\n"));
     } else { // arg is not an option... must be a file
       if (new_fileList) { // if the file list has been used, clear it.
         _fileNames.clear();
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.h #1047320:1047321
@@ -28,6 +28,8 @@
 
   bool processCommandLine(bool *ok);
   QString kstFileName();
+  QString pngFile() {return _pngFile;}
+  QString printFile() {return _printFile;}
 private:
   bool _doAve;
   bool _doSkip;
@@ -44,6 +46,9 @@
   QString _errorField;
   QString _fileName;
   QString _xField;
+  QString _pngFile;
+  QString _printFile;
+
   QStringList _fileNames;
   QStringList _arguments;
   PlotItem *_plotItem;
--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #1047320:1047321
@@ -129,14 +129,13 @@
   return true;
 }
 
-bool Document::initFromCommandLine() {
-  CommandLineParser P(this);
+bool Document::initFromCommandLine(CommandLineParser *P) {
 
   bool ok;
-  bool dataPlotted = P.processCommandLine(&ok);
+  bool dataPlotted = P->processCommandLine(&ok);
 
   if (!dataPlotted && ok) {
-    QString kstfile = P.kstFileName();
+    QString kstfile = P->kstFileName();
     if (!kstfile.isEmpty()) {
       dataPlotted = open(kstfile);
     }
--- branches/work/kst/portto4/kst/src/libkstapp/document.h #1047320:1047321
@@ -23,6 +23,7 @@
 class SessionModel;
 class View;
 class ViewItem;
+class CommandLineParser;
 
 class Document : public CoreDocument {
   public:
@@ -33,7 +34,7 @@
 
     QString fileName() const;
 
-    bool initFromCommandLine();
+    bool initFromCommandLine(CommandLineParser *P);
 
     bool open(const QString& file);
     bool save(const QString& to = QString::null);
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1047320:1047321
@@ -49,6 +49,7 @@
 #include "datawizard.h"
 #include "aboutdialog.h"
 #include "datavector.h"
+#include "commandlineparser.h"
 
 #include <QtGui>
 
@@ -64,16 +65,16 @@
 namespace Kst {
 
 MainWindow::MainWindow() :
-  _dataManager(0),
-  _exportGraphics(0),
-  _differentiateCurvesDialog(0),
-  _chooseColorDialog(0),
-  _changeDataSampleDialog(0),
-  _changeFileDialog(0),
-  _bugReportWizard(0),
-  _applicationSettingsDialog(0),
-  _aboutDialog(0),
-  _dataMode(false) {
+    _dataManager(0),
+    _exportGraphics(0),
+    _differentiateCurvesDialog(0),
+    _chooseColorDialog(0),
+    _changeDataSampleDialog(0),
+    _changeFileDialog(0),
+    _bugReportWizard(0),
+    _applicationSettingsDialog(0),
+    _aboutDialog(0),
+    _dataMode(false) {
   _doc = new Document(this);
   _tabWidget = new TabWidget(this);
   _undoGroup = new QUndoGroup(this);
@@ -226,7 +227,17 @@
 bool MainWindow::initFromCommandLine() {
   delete _doc;
   _doc = new Document(this);
-  return _doc->initFromCommandLine();
+  CommandLineParser P(_doc);
+  bool ok = _doc->initFromCommandLine(&P);
+  if (!P.pngFile().isEmpty()) {
+    exportGraphicsFile(P.pngFile(), "png", 1280, 1024,0);
+    ok = false;
+  }
+  if (!P.printFile().isEmpty()) {
+    printFromCommandLine(P.printFile());
+    ok = false;
+  }
+  return ok;
 }
 
 void MainWindow::openFile(const QString &file) {
@@ -246,6 +257,7 @@
 void MainWindow::exportGraphicsFile(
     const QString &filename, const QString &format, int width, int height, int display) {
   int viewCount = 0;
+  int n_views = _tabWidget->views().length();
   foreach (View *view, _tabWidget->views()) {
     QSize size;
     if (display == 0) {
@@ -279,9 +291,12 @@
     view->processResize(currentSize);
 
     QString file = filename;
-    if (viewCount != 0) {
-      file += "_";
-      file += QString::number(viewCount);
+    if (n_views != 1) {
+      QFileInfo QFI(filename);
+      file = QFI.completeBaseName() +
+             "_" +
+             QString::number(viewCount+1) + "." +
+             QFI.suffix();
     }
 
     QImageWriter imageWriter(file, format.toLatin1());
@@ -290,7 +305,56 @@
   }
 }
 
+void MainWindow::printToPrinter(QPrinter *printer) {
 
+  QPainter painter(printer);
+  QList<View*> pages;
+
+  switch (printer->printRange()) {
+   case QPrinter::PageRange:
+    if (printer->fromPage()>0) {
+      for (int i_page = printer->fromPage(); i_page<=printer->toPage(); i_page++) {
+        pages.append(_tabWidget->views().at(i_page-1));
+      }
+    }
+    break;
+   case QPrinter::AllPages:
+    foreach (View *view, _tabWidget->views()) {
+      pages.append(view);
+    }
+    break;
+   case QPrinter::Selection:
+   default:
+    pages.append(_tabWidget->currentView());
+    break;
+  }
+
+  QSize printerPageSize = printer->pageRect().size();
+  for (int i = 0; i < printer->numCopies(); ++i) {
+    for (int i_page = 0; i_page<pages.count(); i_page++) {
+      View *view = pages.at(i_page);
+      QSize currentSize(view->size());
+      view->resize(printerPageSize);
+      view->processResize(printerPageSize);
+      view->setPrinting(true);
+      view->render(&painter);
+      view->setPrinting(false);
+      view->resize(currentSize);
+      view->processResize(currentSize);
+      if (i_page<pages.count()-1)
+        printer->newPage();
+
+    }
+  }
+}
+
+void MainWindow::printFromCommandLine(const QString &printFileName) {
+  QPrinter printer(QPrinter::ScreenResolution);
+  printer.setOutputFileName(printFileName);
+  printer.setPrintRange(QPrinter::AllPages);
+  printToPrinter(&printer);
+}
+
 void MainWindow::print() {
   // line widths in pixels make sense when using ScreenResolution
   // FIXME: come up with a better definition of line width!
@@ -304,47 +368,7 @@
   if (pd.exec() == QDialog::Accepted) {
 
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-
-    QPainter painter(&printer);
-    QList<View*> pages;
-
-    switch (printer.printRange()) {
-      case QPrinter::PageRange:
-        if (printer.fromPage()>0) {
-          for (int i_page = printer.fromPage(); i_page<=printer.toPage(); i_page++) {
-            pages.append(_tabWidget->views().at(i_page-1));
-          }
-        }
-        break;
-      case QPrinter::AllPages:
-        foreach (View *view, _tabWidget->views()) {
-          pages.append(view);
-        }
-        break;
-      case QPrinter::Selection:
-      default:
-        pages.append(_tabWidget->currentView());
-        break;
-    }
-
-    QSize printerPageSize = printer.pageRect().size();
-    for (int i = 0; i < printer.numCopies(); ++i) {
-      for (int i_page = 0; i_page<pages.count(); i_page++) {
-        View *view = pages.at(i_page);
-        QSize currentSize(view->size());
-        view->resize(printerPageSize);
-        view->processResize(printerPageSize);
-        view->setPrinting(true);
-        view->render(&painter);
-        view->setPrinting(false);
-        view->resize(currentSize);
-        view->processResize(currentSize);
-        if (i_page<pages.count()-1)
-          printer.newPage();
-
-      }
-    }
-
+    printToPrinter(&printer);
     QApplication::restoreOverrideCursor();
   }
 }
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #1047320:1047321
@@ -19,6 +19,7 @@
 class QAction;
 class QProgressBar;
 class QUndoGroup;
+class QPrinter;
 
 namespace Kst {
 
@@ -78,6 +79,8 @@
     void open();
     void openFile(const QString &file);
     void print();
+    void printToPrinter(QPrinter *printer);
+    void printFromCommandLine(const QString &printFileName);
     void exportGraphicsFile(const QString &filename, const QString &format, int w, int h, int display);
 
     void clearDrawingMarker();
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #1047320:1047321
@@ -349,7 +349,6 @@
 
 QString PlotRenderItem::topLabel() const {
   QString label;
-  int count;
   for (int i = 0, count = relationList().count(); i<count; i++) {
     if (i>0) {
       if (i==count-1) {


More information about the Kst mailing list