1 /* GNUPLOT - QtGnuplotInstance.h */ 2 3 /*[ 4 * Copyright 2009 Jérôme Lodewyck 5 * 6 * Permission to use, copy, and distribute this software and its 7 * documentation for any purpose with or without fee is hereby granted, 8 * provided that the above copyright notice appear in all copies and 9 * that both that copyright notice and this permission notice appear 10 * in supporting documentation. 11 * 12 * Permission to modify the software is granted, but not the right to 13 * distribute the complete modified source code. Modifications are to 14 * be distributed as patches to the released version. Permission to 15 * distribute binaries produced by compiling modified sources is granted, 16 * provided you 17 * 1. distribute the corresponding source modifications from the 18 * released version in the form of a patch file along with the binaries, 19 * 2. add special version identification to distinguish your version 20 * in addition to the base release version number, 21 * 3. provide your name and address as the primary contact for the 22 * support of your modified version, and 23 * 4. retain our contact information in regard to use of the base 24 * software. 25 * Permission to distribute the released version of the source code along 26 * with corresponding source modifications in the form of a patch file is 27 * granted with same provisions 2 through 4 for binary distributions. 28 * 29 * This software is provided "as is" without express or implied warranty 30 * to the extent permitted by applicable law. 31 * 32 * 33 * Alternatively, the contents of this file may be used under the terms of the 34 * GNU General Public License Version 2 or later (the "GPL"), in which case the 35 * provisions of GPL are applicable instead of those above. If you wish to allow 36 * use of your version of this file only under the terms of the GPL and not 37 * to allow others to use your version of this file under the above gnuplot 38 * license, indicate your decision by deleting the provisions above and replace 39 * them with the notice and other provisions required by the GPL. If you do not 40 * delete the provisions above, a recipient may use your version of this file 41 * under either the GPL or the gnuplot license. 42 ]*/ 43 44 #ifndef QTGNUPLOTINSTANCE_H 45 #define QTGNUPLOTINSTANCE_H 46 47 #include <QtCore> 48 49 class QtGnuplotWidget; 50 51 class QtGnuplotInstance : public QObject 52 { 53 Q_OBJECT 54 55 public: 56 QtGnuplotInstance(QtGnuplotWidget* widget = 0, QString gnuplotPath = "gnuplot"); 57 ~QtGnuplotInstance(); 58 59 public: 60 /// Redirect the instance plotting to widget @p widget 61 void setWidget(QtGnuplotWidget* widget); 62 /// Returns the widget to which the instance plots 63 QtGnuplotWidget* widget(); 64 /// Send the given command to gnuplot 65 void exec(const QByteArray& command); 66 /// Send the given command to gnuplot and return the result string. Timeout after @p msecs milliseconds 67 QByteArray execAndRead(const QByteArray& command, int msecs = 30000); 68 69 signals: 70 /// Emitted when gnuplot sends data through it standards outputs 71 void gnuplotOutput(const QString& output); 72 73 private slots: 74 void gnuplotDataReady(); 75 76 private: 77 QtGnuplotWidget* m_widget; 78 QProcess m_gnuplot; 79 }; 80 81 /// Overloaded from QtGnuplotInstance::exec 82 QtGnuplotInstance& operator<<(QtGnuplotInstance& instance, const QString& command); 83 /// Overloaded from QtGnuplotInstance::exec 84 QtGnuplotInstance& operator<<(QtGnuplotInstance& instance, const QVector<QPointF>& points); 85 86 #endif // QTGNUPLOTINSTANCE_H 87