00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef GRAPH_H
00030 #define GRAPH_H
00031
00032 #include <QList>
00033 #include <QPointer>
00034 #include <QPrinter>
00035 #include <QVector>
00036 #include <QEvent>
00037
00038 #include <qwt_text.h>
00039 #include <qwt_plot.h>
00040 #include <qwt_plot_marker.h>
00041 #include <qwt_plot_curve.h>
00042
00043 #include "Plot.h"
00044 #include "Table.h"
00045 #include "AxesDialog.h"
00046 #include "PlotToolInterface.h"
00047 #include "MultiLayer.h"
00048
00049 class QwtPlotCurve;
00050 class QwtPlotZoomer;
00051 class QwtPieCurve;
00052 class Table;
00053 class LegendWidget;
00054 class ArrowMarker;
00055 class ImageMarker;
00056 class TitlePicker;
00057 class ScalePicker;
00058 class CanvasPicker;
00059 class ApplicationWindow;
00060 class Matrix;
00061 class SelectionMoveResizer;
00062 class RangeSelectorTool;
00063 class DataCurve;
00064 class PlotCurve;
00065 class QwtErrorPlotCurve;
00066 class MultiLayer;
00067 class Spectrogram;
00068
00070 typedef struct{
00071 int lCol;
00072 int lWidth;
00073 int lStyle;
00074 int filledArea;
00075 int aCol;
00076 int aStyle;
00077 int symCol;
00078 int fillCol;
00079 int penWidth;
00080 int sSize;
00081 int sType;
00082 int connectType;
00083 } CurveLayout;
00084
00113 class Graph: public QWidget
00114 {
00115 Q_OBJECT
00116
00117 public:
00118 Graph (QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
00119 ~Graph();
00120
00121 enum Axis{Left, Right, Bottom, Top};
00122 enum ScaleType{Linear, Log10};
00123 enum Ticks{NoTicks = 0, Out = 1, InOut = 2, In = 3};
00124 enum AxisType{Numeric = 0, Txt = 1, Day = 2, Month = 3, Time = 4, Date = 5, ColHeader = 6};
00125 enum MarkerType{None = -1, Text = 0, Arrow = 1, Image = 2};
00126 enum CurveType{Line, Scatter, LineSymbols, VerticalBars, Area, Pie, VerticalDropLines,
00127 Spline, HorizontalSteps, Histogram, HorizontalBars, VectXYXY, ErrorBars,
00128 Box, VectXYAM, VerticalSteps, ColorMap, GrayScale, Contour, Function, ImagePlot};
00129
00131 QString parentPlotName();
00132
00134 MultiLayer *parentPlot(){return (MultiLayer *)(this->parent()->parent());};
00135
00137 void setActiveTool(PlotToolInterface *tool);
00139 PlotToolInterface* activeTool() const { return d_active_tool; }
00140
00141 Grid *grid(){return d_plot->grid();};
00142
00143 QList <LegendWidget *> textsList(){return d_texts_list;};
00144 LegendWidget *selectedText(){return d_selected_text;};
00145 void setSelectedText(LegendWidget *l);
00146
00147 void deselect();
00148 DataCurve* selectedCurveLabels();
00150 void restoreCurveLabels(int curveID, const QStringList& lst);
00151
00152 public slots:
00154 Plot* plotWidget(){return d_plot;};
00155 void copy(Graph* g);
00156
00158
00159
00160 bool isPiePlot(){return (c_type.count() == 1 && c_type[0] == Pie);};
00161 void plotPie(Table* w,const QString& name, int startRow = 0, int endRow = -1);
00163 void plotPie(Table* w,const QString& name, const QPen& pen, int brush, int size, int firstColor, int startRow = 0, int endRow = -1, bool visible = true);
00164 void removePie();
00165 QString pieLegendText();
00166 QString savePieCurveLayout();
00168
00169 bool addCurves(Table* w, const QStringList& names, int style = 0, int lWidth = 1, int sSize = 3, int startRow = 0, int endRow = -1);
00170 bool insertCurve(Table* w, const QString& name, int style, int startRow = 0, int endRow = -1);
00171 bool insertCurve(Table* w, int xcol, const QString& name, int style);
00172 bool insertCurve(Table* w, const QString& xColName, const QString& yColName, int style, int startRow = 0, int endRow = -1);
00173 void insertPlotItem(QwtPlotItem *i, int type);
00174
00176 void showCurve(int index, bool visible = true);
00177 int visibleCurves();
00178
00180 void removeCurve(int index);
00184 void removeCurve(const QString& s);
00188 void removeCurves(const QString& s);
00189
00190 void updateCurvesData(Table* w, const QString& yColName);
00191
00192 int curves(){return n_curves;};
00193 bool validCurvesDataSize();
00194 double selectedXStartValue();
00195 double selectedXEndValue();
00196
00197 long curveKey(int curve){return c_keys[curve];}
00198 int curveIndex(long key){return c_keys.indexOf(key);};
00200 int curveIndex(QwtPlotCurve *c) const;
00202 int curveIndex(const QString &title){return plotItemsList().findIndex(title);}
00204 QwtPlotCurve* curve(int index);
00206 QwtPlotCurve* curve(const QString &title){return curve(curveIndex(title));}
00207
00209 QStringList analysableCurvesList();
00211 QStringList curvesList();
00213 QStringList plotItemsList();
00215 QwtPlotItem* plotItem(int index);
00217 int plotItemIndex(QwtPlotItem *it) const;
00218
00219 void updateCurveNames(const QString& oldName, const QString& newName, bool updateTableName = true);
00220
00221 int curveType(int curveIndex);
00222 void setCurveType(int curve, int style);
00223 void setCurveFullRange(int curveIndex);
00224
00226
00227 void print();
00228 void setScaleOnPrint(bool on){d_scale_on_print = on;};
00229 void printCropmarks(bool on){d_print_cropmarks = on;};
00230
00231 void copyImage();
00232 QPixmap graphPixmap();
00234 void exportToFile(const QString& fileName);
00235 void exportSVG(const QString& fname);
00236 void exportEMF(const QString& fname);
00237 void exportVector(const QString& fileName, int res = 0, bool color = true,
00238 bool keepAspect = true, QPrinter::PageSize pageSize = QPrinter::Custom);
00239 void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
00241
00242 void replot(){d_plot->replot();};
00243 void updatePlot();
00244
00246
00247 bool addErrorBars(const QString& xColName, const QString& yColName, Table *errTable,
00248 const QString& errColName, int type = 1, int width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00249 bool through = true, bool minus = true, bool plus = true);
00250
00251 bool addErrorBars(const QString& yColName, Table *errTable, const QString& errColName,
00252 int type = 1, int width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00253 bool through = true, bool minus = true, bool plus = true);
00254
00255 void updateErrorBars(QwtErrorPlotCurve *er, bool xErr,int width, int cap, const QColor& c, bool plus, bool minus, bool through);
00256
00258 DataCurve* masterCurve(QwtErrorPlotCurve *er);
00260 DataCurve* masterCurve(const QString& xColName, const QString& yColName);
00262
00264
00265 void contextMenuEvent(QContextMenuEvent *);
00266 void closeEvent(QCloseEvent *e);
00267 bool focusNextPrevChild ( bool next );
00269
00271 void invertScale(int axis);
00272 void setScale(int axis, double start, double end, double step = 0.0,
00273 int majorTicks = 5, int minorTicks = 5, int type = 0, bool inverted = false);
00274 double axisStep(int axis){return d_user_step[axis];};
00275
00277
00278 CurveLayout initCurveLayout(int style, int curves = 0);
00279 static CurveLayout initCurveLayout();
00280 void updateCurveLayout(int index,const CurveLayout *cL);
00282 void guessUniqueCurveLayout(int& colorIndex, int& symbolIndex);
00284
00286
00287 void zoomed (const QwtDoubleRect &);
00288 void zoom(bool on);
00289 void zoomOut();
00290 bool zoomOn();
00292
00293 void setAutoScale();
00294 void updateScale();
00295
00297
00298 QString saveToString(bool saveAsTemplate = false);
00299 QString saveScale();
00300 QString saveScaleTitles();
00301 QString saveFonts();
00302 QString saveMarkers();
00303 QString saveCurveLayout(int index);
00304 QString saveAxesTitleColors();
00305 QString saveAxesColors();
00306 QString saveEnabledAxes();
00307 QString saveCanvas();
00308 QString saveTitle();
00309 QString saveAxesTitleAlignement();
00310 QString saveEnabledTickLabels();
00311 QString saveTicksType();
00312 QString saveCurves();
00313 QString saveLabelsFormat();
00314 QString saveLabelsRotation();
00315 QString saveAxesLabelsType();
00316 QString saveAxesBaseline();
00317 QString saveAxesFormulas();
00319
00321
00322 void drawText(bool on);
00323 bool drawTextActive(){return drawTextOn;};
00324 LegendWidget* insertText(LegendWidget*);
00325
00327 LegendWidget* insertText(const QStringList& list, int fileVersion);
00328
00329 QFont defaultTextMarkerFont(){return defaultMarkerFont;};
00330 QColor textMarkerDefaultColor(){return defaultTextMarkerColor;};
00331 QColor textMarkerDefaultBackground(){return defaultTextMarkerBackground;};
00332 int textMarkerDefaultFrame(){return defaultMarkerFrame;};
00333 void setTextMarkerDefaults(int f, const QFont &font, const QColor& textCol, const QColor& backgroundCol);
00334
00335 void addTimeStamp();
00336 void removeLegend();
00337 void removeLegendItem(int index);
00338 void addLegendItem(const QString& colName);
00339 void insertLegend(const QStringList& lst, int fileVersion);
00340
00341 LegendWidget *legend(){return d_legend;};
00342 LegendWidget* newLegend(const QString& text = QString());
00343
00345 QString legendText();
00347
00349
00350 ArrowMarker* arrow(long id);
00351 ArrowMarker* addArrow(ArrowMarker* mrk);
00352
00354 void addArrow(QStringList list, int fileVersion);
00355 QVector<int> lineMarkerKeys(){return d_lines;};
00356
00358 void drawLine(bool on, bool arrow = FALSE);
00359 bool drawArrow(){return drawArrowOn;};
00360 bool drawLineActive(){return drawLineOn;};
00361
00362 Qt::PenStyle arrowLineDefaultStyle(){return defaultArrowLineStyle;};
00363 bool arrowHeadDefaultFill(){return defaultArrowHeadFill;};
00364 int arrowDefaultWidth(){return defaultArrowLineWidth;};
00365 int arrowHeadDefaultLength(){return defaultArrowHeadLength;};
00366 int arrowHeadDefaultAngle(){return defaultArrowHeadAngle;};
00367 QColor arrowDefaultColor(){return defaultArrowColor;};
00368
00369 void setArrowDefaults(int lineWidth, const QColor& c, Qt::PenStyle style,
00370 int headLength, int headAngle, bool fillHead);
00371 bool arrowMarkerSelected();
00373
00375
00376 ImageMarker* imageMarker(long id);
00377 QVector<int> imageMarkerKeys(){return d_images;};
00378 ImageMarker* addImage(ImageMarker* mrk);
00379 ImageMarker* addImage(const QString& fileName);
00380
00381 void insertImageMarker(const QStringList& lst, int fileVersion);
00382 bool imageMarkerSelected();
00383 void updateImageMarker(int x, int y, int width, int height);
00385
00387
00388 void removeMarker();
00390 void updateMarkersBoundingRect();
00391
00392 long selectedMarkerKey();
00399 void setSelectedMarker(long mrk, bool add=false);
00400 QwtPlotMarker* selectedMarkerPtr();
00401 bool markerSelected();
00403 void deselectMarker();
00405
00407
00408 QwtScaleWidget* selectedScale();
00409 QRect axisTitleRect(const QwtScaleWidget *scale);
00410
00411 QList<int> axesType();
00412
00413 void setXAxisTitle(const QString& text);
00414 void setYAxisTitle(const QString& text);
00415 void setRightAxisTitle(const QString& text);
00416 void setTopAxisTitle(const QString& text);
00417
00418 QString axisTitle(int axis){return d_plot->axisTitle(axis).text();};
00419 void setAxisTitle(int axis, const QString& text);
00421 void setScaleTitle(int axis, const QString& text);
00422
00423 QFont axisTitleFont(int axis);
00424 void setXAxisTitleFont(const QFont &fnt);
00425 void setYAxisTitleFont(const QFont &fnt);
00426 void setRightAxisTitleFont(const QFont &fnt);
00427 void setTopAxisTitleFont(const QFont &fnt);
00428 void setAxisTitleFont(int axis,const QFont &fnt);
00429
00430 void setAxisFont(int axis, const QFont &fnt);
00431 QFont axisFont(int axis);
00432 void initFonts(const QFont &scaleTitleFnt,const QFont &numbersFnt);
00433
00434 QColor axisTitleColor(int axis);
00435 void setAxisTitleColor(int axis, const QColor& c);
00436
00437 void setXAxisTitleColor(const QColor& c);
00438 void setYAxisTitleColor(const QColor& c);
00439 void setRightAxisTitleColor(const QColor& c);
00440 void setTopAxisTitleColor(const QColor& c);
00441
00442 int axisTitleAlignment (int axis);
00443 void setAxisTitleAlignment(int axis, int align);
00444
00445 void setXAxisTitleAlignment(int align);
00446 void setYAxisTitleAlignment(int align);
00447 void setTopAxisTitleAlignment(int align);
00448 void setRightAxisTitleAlignment(int align);
00449
00450 QColor axisColor(int axis);
00451 void setAxisColor(int axis, const QColor& color);
00452
00453 QColor axisLabelsColor(int axis);
00454 void setAxisLabelsColor(int axis, const QColor& color);
00455
00456 void showAxis(int axis, int type, const QString& formatInfo, Table *table, bool axisOn,
00457 int majTicksType, int minTicksType, bool labelsOn, const QColor& c, int format,
00458 int prec, int rotation, int baselineDist, const QString& formula, const QColor& labelsColor);
00459
00460 void enableAxis(int axis, bool on = true);
00461 void enableAxisLabels(int axis, bool on = true);
00462
00463 int labelsRotation(int axis);
00464 void setAxisLabelRotation(int axis, int rotation);
00465
00466 void setAxesLinewidth(int width);
00468 void loadAxesLinewidth(int width);
00469
00470 void drawAxesBackbones(bool yes);
00471 bool axesBackbones(){return drawAxesBackbone;};
00473 void loadAxesOptions(const QString& s);
00474
00475 void setAxisMargin(int axis, int margin);
00476
00477 void setMajorTicksType(const QList<int>& lst);
00478 void setMajorTicksType(const QStringList& lst);
00479
00480 void setMinorTicksType(const QList<int>& lst);
00481 void setMinorTicksType(const QStringList& lst);
00482
00483 int minorTickLength();
00484 int majorTickLength();
00485 void setAxisTicksLength(int axis, int majTicksType, int minTicksType, int minLength, int majLength);
00486 void setTicksLength(int minLength, int majLength);
00487 void changeTicksLength(int minLength, int majLength);
00488
00489 void setLabelsNumericFormat(const QStringList& l);
00490 void setLabelsNumericFormat(int axis, const QStringList& l);
00491 void setLabelsNumericFormat(int axis, int format, int prec = 6, const QString& formula = QString());
00492 void setLabelsDateTimeFormat(int axis, int type, const QString& formatInfo);
00493 void setLabelsDayFormat(int axis, int format);
00494 void setLabelsMonthFormat(int axis, int format);
00495
00496 QString axisFormatInfo(int axis);
00497 QStringList axesLabelsFormatInfo(){return axesFormatInfo;};
00498
00499 void setLabelsTextFormat(int axis, int type, const QString& name, const QStringList& lst);
00500 void setLabelsTextFormat(int axis, int type, const QString& labelsColName, Table *table);
00501
00502 QStringList getAxesFormulas(){return axesFormulas;};
00503 void setAxesFormulas(const QStringList& l){axesFormulas = l;};
00504 void setAxisFormula(int pos, const QString &f){axesFormulas[pos] = f;};
00506
00508
00509 void setCanvasFrame(int width = 1, const QColor& color = QColor(Qt::black));
00510 QColor canvasFrameColor();
00511 int canvasFrameWidth();
00513
00515
00516 void setTitle(const QString& t);
00517 void setTitleFont(const QFont &fnt);
00518 void setTitleColor(const QColor &c);
00519 void setTitleAlignment(int align);
00520
00521 bool titleSelected();
00522 void selectTitle(bool select = true);
00523
00524 void removeTitle();
00525 void initTitle( bool on, const QFont& fnt);
00527
00529
00530 int selectedCurveID();
00531 int selectedCurveIndex() { return curveIndex(selectedCurveID()); }
00532 QString selectedCurveTitle();
00534
00535 void disableTools();
00536
00543 bool enableRangeSelectors(const QObject *status_target=NULL, const char *status_slot="");
00544
00546
00547 void setMargin (int d);
00548 void setFrame(int width = 1, const QColor& color = QColor(Qt::black));
00549 void setBackgroundColor(const QColor& color);
00550 void setCanvasBackground(const QColor& color);
00552
00553 void addFitCurve(QwtPlotCurve *c);
00554 void deleteFitCurves();
00555 QList<QwtPlotCurve *> fitCurvesList(){return d_fit_curves;};
00560 int range(int index, double *start, double *end);
00561
00563 void setBarsGap(int curve, int gapPercent, int offset);
00564
00566
00567 void modifyFunctionCurve(int curve, int type, const QStringList &formulas, const QString &var, double start, double end, int points);
00568 void addFunction(const QStringList &formulas, double start, double end, int points = 100, const QString &var = "x", int type = 0, const QString& title = QString::null);
00570 void insertFunctionCurve(const QString& formula, int points, int fileVersion);
00572 QString generateFunctionName(const QString& name = tr("F"));
00574
00576 void createTable(const QString& curveName);
00577 void createTable(const QwtPlotCurve* curve);
00578 void activateGraph();
00579
00581
00582 void plotVectorCurve(Table* w, const QStringList& colList, int style, int startRow = 0, int endRow = -1);
00583 void updateVectorsLayout(int curve, const QColor& color, int width, int arrowLength, int arrowAngle, bool filled, int position,
00584 const QString& xEndColName = QString(), const QString& yEndColName = QString());
00586
00588
00589 void openBoxDiagram(Table *w, const QStringList& l, int fileVersion);
00590 void plotBoxDiagram(Table *w, const QStringList& names, int startRow = 0, int endRow = -1);
00592
00593 void setCurveSymbol(int index, const QwtSymbol& s);
00594 void setCurvePen(int index, const QPen& p);
00595 void setCurveBrush(int index, const QBrush& b);
00596 void setCurveStyle(int index, int s);
00597
00599
00600 bool ignoresResizeEvents(){return ignoreResize;};
00601 void setIgnoreResizeEvents(bool ok){ignoreResize=ok;};
00602 void resizeEvent(QResizeEvent *e);
00603 void scaleFonts(double factor);
00605
00606 void notifyChanges();
00607
00608 void updateSecondaryAxis(int axis);
00609 void enableAutoscaling(bool yes){autoscale = yes;};
00610
00611 bool autoscaleFonts(){return autoScaleFonts;};
00612 void setAutoscaleFonts(bool yes){autoScaleFonts = yes;};
00613
00614 static int obsoleteSymbolStyle(int type);
00615 static QString penStyleName(Qt::PenStyle style);
00616 static Qt::PenStyle getPenStyle(const QString& s);
00617 static Qt::PenStyle getPenStyle(int style);
00618 static Qt::BrushStyle getBrushStyle(int style);
00619 static void showPlotErrorMessage(QWidget *parent, const QStringList& emptyColumns);
00620 static QPrinter::PageSize minPageSize(const QPrinter& printer, const QRect& r);
00621
00622 void showTitleContextMenu();
00623 void copyTitle();
00624 void cutTitle();
00625
00626 void removeAxisTitle();
00627 void cutAxisTitle();
00628 void copyAxisTitle();
00629 void showAxisTitleMenu(int axis);
00630 void showAxisContextMenu(int axis);
00631 void hideSelectedAxis();
00632 void showGrids();
00633
00635 void showGrid();
00637 void showGrid(int axis);
00638
00639 void showAxisDialog();
00640 void showScaleDialog();
00641
00643 Spectrogram* plotSpectrogram(Matrix *m, CurveType type);
00645 void restoreSpectrogram(ApplicationWindow *app, const QStringList& lst);
00647 void addHistogram(Matrix *m);
00649 void restoreHistogram(Matrix *m, const QStringList& l);
00650
00651 bool antialiasing(){return d_antialiasing;};
00653 void setAntialiasing(bool on = true, bool update = true);
00654
00655 void setCurrentFont(const QFont& f);
00656 void notifyFontChange(const QFont& f){emit currentFontChanged(f);};
00657 void enableTextEditor(){emit enableTextEditor(this);};
00658
00659 signals:
00660 void selectedGraph (Graph*);
00661 void closedGraph();
00662 void drawTextOff();
00663 void drawLineEnded(bool);
00664 void cursorInfo(const QString&);
00665 void showPlotDialog(int);
00666 void createTable(const QString&,int,int,const QString&);
00667
00668 void viewImageDialog();
00669 void viewTextDialog();
00670 void viewLineDialog();
00671 void viewTitleDialog();
00672 void modifiedGraph();
00673 void hiddenPlot(QWidget*);
00674
00675 void showContextMenu();
00676 void showCurveContextMenu(int);
00677 void showMarkerPopupMenu();
00678
00679 void showAxisDialog(int);
00680 void axisDblClicked(int);
00681
00682 void xAxisTitleDblClicked();
00683 void yAxisTitleDblClicked();
00684 void rightAxisTitleDblClicked();
00685 void topAxisTitleDblClicked();
00686
00687 void dataRangeChanged();
00688 void showFitResults(const QString&);
00689 void currentFontChanged(const QFont&);
00690 void enableTextEditor(Graph *);
00691
00692 private:
00693 void deselectCurves();
00694
00695 Plot *d_plot;
00696 QwtPlotZoomer *d_zoomer[2];
00697 TitlePicker *titlePicker;
00698 ScalePicker *scalePicker;
00699 CanvasPicker* cp;
00700
00702 QList<QwtPlotCurve *>d_fit_curves;
00704 bool d_antialiasing;
00705 bool autoScaleFonts;
00706 bool d_scale_on_print, d_print_cropmarks;
00707 int selectedAxis;
00708 QStringList axesFormulas;
00710 QStringList axesFormatInfo;
00711 QList <int> axisType;
00712
00714 QVector<double> d_user_step;
00716 QVector<int> c_type;
00718 QVector<int> c_keys;
00720 QVector<int> d_lines;
00722 QVector<int> d_images;
00724 QList <LegendWidget *> d_texts_list;
00725
00726 int n_curves, widthLine;
00727 long selectedMarker;
00728 bool drawTextOn, drawLineOn, drawArrowOn, ignoreResize, drawAxesBackbone, autoscale;
00729
00731
00732 QFont defaultMarkerFont;
00733 QColor defaultArrowColor, defaultTextMarkerColor, defaultTextMarkerBackground;
00734 int defaultMarkerFrame, defaultArrowLineWidth, defaultArrowHeadLength, defaultArrowHeadAngle;
00735 bool defaultArrowHeadFill;
00736 Qt::PenStyle defaultArrowLineStyle;
00738
00740 QPointer<SelectionMoveResizer> d_markers_selector;
00742 QPointer<RangeSelectorTool> d_range_selector;
00744 PlotToolInterface *d_active_tool;
00746 LegendWidget *d_selected_text;
00748 LegendWidget *d_legend;
00749 };
00750 #endif // GRAPH_H