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_plot.h>
00039 #include <qwt_plot_marker.h>
00040 #include <qwt_plot_curve.h>
00041
00042 #include "Plot.h"
00043 #include "Table.h"
00044 #include "AxesDialog.h"
00045 #include "PlotToolInterface.h"
00046
00047 class QwtPlotCurve;
00048 class QwtPlotZoomer;
00049 class QwtPieCurve;
00050 class Table;
00051 class LegendMarker;
00052 class LineMarker;
00053 class ImageMarker;
00054 class TitlePicker;
00055 class ScalePicker;
00056 class CanvasPicker;
00057 class ApplicationWindow;
00058 class Matrix;
00059 class SelectionMoveResizer;
00060 class RangeSelectorTool;
00061 class DataCurve;
00062 class PlotCurve;
00063 class QwtErrorPlotCurve;
00064
00066 typedef struct{
00067 int lCol;
00068 int lWidth;
00069 int lStyle;
00070 int filledArea;
00071 int aCol;
00072 int aStyle;
00073 int symCol;
00074 int fillCol;
00075 int penWidth;
00076 int sSize;
00077 int sType;
00078 int connectType;
00079 } CurveLayout;
00080
00112 class Graph: public QWidget
00113 {
00114 Q_OBJECT
00115
00116 public:
00117 Graph (QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
00118 ~Graph();
00119
00120 enum AxisType{Numeric = 0, Txt = 1, Day = 2, Month = 3, Time = 4, Date = 5, ColHeader = 6};
00121 enum MarkerType{None = -1, Text = 0, Arrow = 1, Image = 2};
00122 enum CurveType{Line, Scatter, LineSymbols, VerticalBars, Area, Pie, VerticalDropLines,
00123 Spline, HorizontalSteps, Histogram, HorizontalBars, VectXYXY, ErrorBars,
00124 Box, VectXYAM, VerticalSteps, ColorMap, GrayMap, ContourMap, Function};
00125
00126 Plot *d_plot;
00127 QwtPlotZoomer *d_zoomer[2];
00128 TitlePicker *titlePicker;
00129 ScalePicker *scalePicker;
00130 CanvasPicker* cp;
00131
00133 QString parentPlotName();
00134
00136 void setActiveTool(PlotToolInterface *tool) { if(d_active_tool) delete d_active_tool; d_active_tool=tool; }
00138 PlotToolInterface* activeTool() const { return d_active_tool; }
00139
00140 public slots:
00142 Plot* plotWidget(){return d_plot;};
00143 void copy(Graph* g);
00144
00146
00147
00148 bool isPiePlot(){return (c_type.count() == 1 && c_type[0] == Pie);};
00149 void plotPie(Table* w,const QString& name, int startRow = 0, int endRow = -1);
00151 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);
00152 void removePie();
00153 QString pieLegendText();
00154 QString savePieCurveLayout();
00156
00157 bool insertCurvesList(Table* w, const QStringList& names, int style, int lWidth, int sSize, int startRow = 0, int endRow = -1);
00158 bool insertCurve(Table* w, const QString& name, int style, int startRow = 0, int endRow = -1);
00159 bool insertCurve(Table* w, int xcol, const QString& name, int style);
00160 bool insertCurve(Table* w, const QString& xColName, const QString& yColName, int style, int startRow = 0, int endRow = -1);
00161 void insertPlotItem(QwtPlotItem *i, int type);
00162
00164 void showCurve(int index, bool visible = true);
00165 int visibleCurves();
00166
00168 void removeCurve(int index);
00172 void removeCurve(const QString& s);
00176 void removeCurves(const QString& s);
00177
00178 void updateCurvesData(Table* w, const QString& yColName);
00179
00180 int curves(){return n_curves;};
00181 bool validCurvesDataSize();
00182 double selectedXStartValue();
00183 double selectedXEndValue();
00184
00185 long curveKey(int curve){return c_keys[curve];}
00186 int curveIndex(long key){return c_keys.indexOf(key);};
00188 int curveIndex(QwtPlotCurve *c) const;
00190 int curveIndex(const QString &title){return plotItemsList().findIndex(title);}
00192 QwtPlotCurve* curve(int index);
00194 QwtPlotCurve* curve(const QString &title){return curve(curveIndex(title));}
00195
00197 QStringList analysableCurvesList();
00199 QStringList curvesList();
00201 QStringList plotItemsList();
00203 QwtPlotItem* plotItem(int index);
00205 int plotItemIndex(QwtPlotItem *it) const;
00206
00207 void updateCurveNames(const QString& oldName, const QString& newName, bool updateTableName = true);
00208
00209 int curveType(int curveIndex);
00210 void setCurveType(int curve, int style);
00211 void setCurveFullRange(int curveIndex);
00212
00214
00215 void print();
00216 void setScaleOnPrint(bool on){d_scale_on_print = on;};
00217 void printCropmarks(bool on){d_print_cropmarks = on;};
00218
00219 void copyImage();
00220 QPixmap graphPixmap();
00222 void exportToFile(const QString& fileName);
00223 void exportSVG(const QString& fname);
00224 void exportVector(const QString& fileName, int res = 0, bool color = true);
00225 void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
00227
00228 void replot();
00229 void updatePlot();
00230
00232
00233 bool addErrorBars(const QString& xColName, const QString& yColName, Table *errTable,
00234 const QString& errColName, int type = 1, int width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00235 bool through = true, bool minus = true, bool plus = true);
00236
00237 bool addErrorBars(const QString& yColName, Table *errTable, const QString& errColName,
00238 int type = 1, int width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00239 bool through = true, bool minus = true, bool plus = true);
00240
00241 void updateErrorBars(QwtErrorPlotCurve *er, bool xErr,int width, int cap, const QColor& c, bool plus, bool minus, bool through);
00242
00244 DataCurve* masterCurve(QwtErrorPlotCurve *er);
00246 DataCurve* masterCurve(const QString& xColName, const QString& yColName);
00248
00250
00251 void contextMenuEvent(QContextMenuEvent *);
00252 void closeEvent(QCloseEvent *e);
00253 bool focusNextPrevChild ( bool next );
00255
00257 void setScale(int axis, double start, double end, double step = 0.0,
00258 int majorTicks = 5, int minorTicks = 5, int type = 0, bool inverted = false);
00259 double axisStep(int axis){return d_user_step[axis];};
00260
00262
00263 CurveLayout initCurveLayout(int style, int curves = 0);
00264 static CurveLayout initCurveLayout();
00265 void updateCurveLayout(int index,const CurveLayout *cL);
00267 void guessUniqueCurveLayout(int& colorIndex, int& symbolIndex);
00269
00270 GridOptions gridOptions(){return grid;};
00271 void setGridOptions(const GridOptions& options);
00272
00274
00275 void zoomed (const QwtDoubleRect &);
00276 void zoom(bool on);
00277 void zoomOut();
00278 bool zoomOn();
00280
00281 void setAutoScale();
00282 void updateScale();
00283
00285
00286 QString saveToString(bool saveAsTemplate = false);
00287 QString saveGridOptions();
00288 QString saveScale();
00289 QString saveScaleTitles();
00290 QString saveFonts();
00291 QString saveMarkers();
00292 QString saveCurveLayout(int index);
00293 QString saveAxesTitleColors();
00294 QString saveAxesColors();
00295 QString saveEnabledAxes();
00296 QString saveCanvas();
00297 QString saveTitle();
00298 QString saveAxesTitleAlignement();
00299 QString saveEnabledTickLabels();
00300 QString saveTicksType();
00301 QString saveCurves();
00302 QString saveLabelsFormat();
00303 QString saveLabelsRotation();
00304 QString saveAxesLabelsType();
00305 QString saveAxesBaseline();
00306 QString saveAxesFormulas();
00308
00310
00311 void drawText(bool on);
00312 bool drawTextActive(){return drawTextOn;};
00313 long insertTextMarker(LegendMarker* mrk);
00314
00316 long insertTextMarker(const QStringList& list, int fileVersion);
00317 void updateTextMarker(const QString& text,int angle, int bkg,const QFont& fnt,
00318 const QColor& textColor, const QColor& backgroundColor);
00319
00320 QFont defaultTextMarkerFont(){return defaultMarkerFont;};
00321 QColor textMarkerDefaultColor(){return defaultTextMarkerColor;};
00322 QColor textMarkerDefaultBackground(){return defaultTextMarkerBackground;};
00323 int textMarkerDefaultFrame(){return defaultMarkerFrame;};
00324 void setTextMarkerDefaults(int f, const QFont &font, const QColor& textCol, const QColor& backgroundCol);
00325
00326 void setCopiedMarkerType(Graph::MarkerType type){selectedMarkerType=type;};
00327 void setCopiedMarkerEnds(const QPoint& start, const QPoint& end);
00328 void setCopiedTextOptions(int bkg, const QString& text, const QFont& font,
00329 const QColor& color, const QColor& bkgColor);
00330 void setCopiedArrowOptions(int width, Qt::PenStyle style, const QColor& color,
00331 bool start, bool end, int headLength, int headAngle, bool filledHead);
00332 void setCopiedImageName(const QString& fn){auxMrkFileName=fn;};
00333 QRect copiedMarkerRect(){return QRect(auxMrkStart, auxMrkEnd);};
00334 QVector<int> textMarkerKeys(){return d_texts;};
00335 LegendMarker* textMarker(long id);
00336
00337 void addTimeStamp();
00338
00339 void removeLegend();
00340 void removeLegendItem(int index);
00341 void addLegendItem(const QString& colName);
00342 void insertLegend(const QStringList& lst, int fileVersion);
00343 LegendMarker *legend();
00344 void newLegend();
00345 LegendMarker *newLegend(const QString& text);
00346 bool hasLegend(){return legendMarkerID >= 0;};
00347
00349 QString legendText();
00351
00353
00354 LineMarker* lineMarker(long id);
00355 void insertLineMarker(LineMarker* mrk);
00356
00358 void insertLineMarker(QStringList list, int fileVersion);
00359 QVector<int> lineMarkerKeys(){return d_lines;};
00360
00362 void drawLine(bool on, bool arrow = FALSE);
00363 bool drawArrow(){return drawArrowOn;};
00364 bool drawLineActive(){return drawLineOn;};
00365
00366 Qt::PenStyle arrowLineDefaultStyle(){return defaultArrowLineStyle;};
00367 bool arrowHeadDefaultFill(){return defaultArrowHeadFill;};
00368 int arrowDefaultWidth(){return defaultArrowLineWidth;};
00369 int arrowHeadDefaultLength(){return defaultArrowHeadLength;};
00370 int arrowHeadDefaultAngle(){return defaultArrowHeadAngle;};
00371 QColor arrowDefaultColor(){return defaultArrowColor;};
00372
00373 void setArrowDefaults(int lineWidth, const QColor& c, Qt::PenStyle style,
00374 int headLength, int headAngle, bool fillHead);
00376
00378
00379 ImageMarker* imageMarker(long id);
00380 QVector<int> imageMarkerKeys(){return d_images;};
00381 void insertImageMarker(ImageMarker* mrk);
00382 void insertImageMarker(const QPixmap& photo, const QString& fileName);
00383
00384 void insertImageMarker(const QStringList& lst, int fileVersion);
00385 bool imageMarkerSelected();
00386 void updateImageMarker(int x, int y, int width, int height);
00387
00388 bool arrowMarkerSelected();
00390
00392
00393 void removeMarker();
00394 void cutMarker();
00395 void copyMarker();
00396 void pasteMarker();
00398 void updateMarkersBoundingRect();
00399
00400 long selectedMarkerKey();
00407 void setSelectedMarker(long mrk, bool add=false);
00408 QwtPlotMarker* selectedMarkerPtr();
00409 bool markerSelected();
00411 void deselectMarker();
00412 MarkerType copiedMarkerType(){return selectedMarkerType;};
00414
00416
00417 QList<int> axesType();
00418 void setAxesType(const QList<int> tl);
00419
00420 QStringList scalesTitles();
00421 void setXAxisTitle(const QString& text);
00422 void setYAxisTitle(const QString& text);
00423 void setRightAxisTitle(const QString& text);
00424 void setTopAxisTitle(const QString& text);
00425 void setAxisTitle(int axis, const QString& text);
00426
00427 QFont axisTitleFont(int axis);
00428 void setXAxisTitleFont(const QFont &fnt);
00429 void setYAxisTitleFont(const QFont &fnt);
00430 void setRightAxisTitleFont(const QFont &fnt);
00431 void setTopAxisTitleFont(const QFont &fnt);
00432 void setAxisTitleFont(int axis,const QFont &fnt);
00433
00434 void setAxisFont(int axis,const QFont &fnt);
00435 QFont axisFont(int axis);
00436 void initFonts(const QFont &scaleTitleFnt,const QFont &numbersFnt);
00437
00438 QColor axisTitleColor(int axis);
00439 void setXAxisTitleColor(const QColor& c);
00440 void setYAxisTitleColor(const QColor& c);
00441 void setRightAxisTitleColor(const QColor& c);
00442 void setTopAxisTitleColor(const QColor& c);
00443 void setAxesTitleColor(QStringList l);
00444
00445 int axisTitleAlignment (int axis);
00446 void setXAxisTitleAlignment(int align);
00447 void setYAxisTitleAlignment(int align);
00448 void setTopAxisTitleAlignment(int align);
00449 void setRightAxisTitleAlignment(int align);
00450 void setAxesTitlesAlignment(const QStringList& align);
00451
00452 QColor axisColor(int axis);
00453 QStringList axesColors();
00454 void setAxesColors(const QStringList& colors);
00455
00456 QColor axisNumbersColor(int axis);
00457 QStringList axesNumColors();
00458 void setAxesNumColors(const QStringList& colors);
00459
00460 void showAxis(int axis, int type, const QString& formatInfo, Table *table, bool axisOn,
00461 int majTicksType, int minTicksType, bool labelsOn, const QColor& c, int format,
00462 int prec, int rotation, int baselineDist, const QString& formula, const QColor& labelsColor);
00463
00464 QVector<bool> enabledAxes();
00465 void enableAxes(QVector<bool> axesOn);
00466 void enableAxes(const QStringList& list);
00467
00468 int labelsRotation(int axis);
00469 void setAxisLabelRotation(int axis, int rotation);
00470
00471 QStringList enabledTickLabels();
00472 void setEnabledTickLabels(const QStringList& list);
00473
00474 void setAxesLinewidth(int width);
00476 void loadAxesLinewidth(int width);
00477
00478 void drawAxesBackbones(bool yes);
00479 bool axesBackbones(){return drawAxesBackbone;};
00481 void loadAxesOptions(const QString& s);
00482
00483 QList<int> axesBaseline();
00484 void setAxesBaseline(const QList<int> &lst);
00485 void setAxesBaseline(QStringList &lst);
00486
00487 void setMajorTicksType(const QList<int>& lst);
00488 void setMajorTicksType(const QStringList& lst);
00489
00490 void setMinorTicksType(const QList<int>& lst);
00491 void setMinorTicksType(const QStringList& lst);
00492
00493 int minorTickLength();
00494 int majorTickLength();
00495 void setAxisTicksLength(int axis, int majTicksType, int minTicksType,
00496 int minLength, int majLength);
00497 void setTicksLength(int minLength, int majLength);
00498 void changeTicksLength(int minLength, int majLength);
00499
00500 void setLabelsNumericFormat(const QStringList& l);
00501 void setLabelsNumericFormat(int axis, const QStringList& l);
00502 void setLabelsNumericFormat(int axis, int format, int prec, const QString& formula);
00503 void setLabelsDateTimeFormat(int axis, int type, const QString& formatInfo);
00504 void setLabelsDayFormat(int axis, int format);
00505 void setLabelsMonthFormat(int axis, int format);
00506
00507 QString axisFormatInfo(int axis);
00508 QStringList axesLabelsFormatInfo(){return axesFormatInfo;};
00509
00510 void setLabelsTextFormat(int axis, int type, const QString& name, const QStringList& lst);
00511 void setLabelsTextFormat(int axis, int type, const QString& labelsColName, Table *table);
00512
00513 QStringList getAxesFormulas(){return axesFormulas;};
00514 void setAxesFormulas(const QStringList& l){axesFormulas = l;};
00515 void setAxisFormula(int pos, const QString &f){axesFormulas[pos] = f;};
00517
00519
00520 void drawCanvasFrame(bool frameOn, int width);
00521 void drawCanvasFrame(const QStringList& frame);
00522 void drawCanvasFrame(bool frameOn, int width, const QColor& color);
00523 QColor canvasFrameColor();
00524 int canvasFrameWidth();
00525 bool framed();
00527
00529
00530 void setTitle(const QString& t);
00531 void setTitleFont(const QFont &fnt);
00532 void setTitleColor(const QColor &c);
00533 void setTitleAlignment(int align);
00534
00535 bool titleSelected();
00536 void selectTitle();
00537
00538 void removeTitle();
00539 void initTitle( bool on, const QFont& fnt);
00541
00543
00544 int selectedCurveID();
00545 int selectedCurveIndex() { return curveIndex(selectedCurveID()); }
00546 QString selectedCurveTitle();
00548
00549 void disableTools();
00550
00557 bool enableRangeSelectors(const QObject *status_target=NULL, const char *status_slot="");
00558
00560
00561 void changeMargin (int d);
00562 void setBorder (int width = 1, const QColor& color = QColor(Qt::black));
00563 void setBackgroundColor(const QColor& color);
00564 void setCanvasBackground(const QColor& color);
00566
00567 void addFitCurve(QwtPlotCurve *c);
00568 void deleteFitCurves();
00569 QList<QwtPlotCurve *> fitCurvesList(){return d_fit_curves;};
00574 int range(int index, double *start, double *end);
00575
00577 void setBarsGap(int curve, int gapPercent, int offset);
00578
00580
00581 void showIntensityTable();
00583
00585
00586 void modifyFunctionCurve(int curve, int type, const QStringList &formulas, const QString &var,QList<double> &ranges, int points);
00587 void addFunctionCurve(int type, const QStringList &formulas, const QString& var,
00588 QList<double> &ranges, int points, const QString& title = QString::null);
00590 void insertFunctionCurve(const QString& formula, int points, int fileVersion);
00592 QString generateFunctionName(const QString& name = tr("F"));
00594
00596 void createTable(const QString& curveName);
00597 void createTable(const QwtPlotCurve* curve);
00598 void activateGraph();
00599
00601
00602 void plotVectorCurve(Table* w, const QStringList& colList, int style, int startRow = 0, int endRow = -1);
00603 void updateVectorsLayout(int curve, const QColor& color, int width, int arrowLength, int arrowAngle, bool filled, int position,
00604 const QString& xEndColName = QString(), const QString& yEndColName = QString());
00606
00608
00609 void openBoxDiagram(Table *w, const QStringList& l, int fileVersion);
00610 void plotBoxDiagram(Table *w, const QStringList& names, int startRow = 0, int endRow = -1);
00612
00613 void setCurveSymbol(int index, const QwtSymbol& s);
00614 void setCurvePen(int index, const QPen& p);
00615 void setCurveBrush(int index, const QBrush& b);
00616 void setCurveStyle(int index, int s);
00617
00619
00620 bool ignoresResizeEvents(){return ignoreResize;};
00621 void setIgnoreResizeEvents(bool ok){ignoreResize=ok;};
00622 void resizeEvent(QResizeEvent *e);
00623 void scaleFonts(double factor);
00625
00626 void notifyChanges();
00627
00628 void updateSecondaryAxis(int axis);
00629 void enableAutoscaling(bool yes){autoscale = yes;};
00630
00631 bool autoscaleFonts(){return autoScaleFonts;};
00632 void setAutoscaleFonts(bool yes){autoScaleFonts = yes;};
00633
00634 static int obsoleteSymbolStyle(int type);
00635 static QString penStyleName(Qt::PenStyle style);
00636 static Qt::PenStyle getPenStyle(const QString& s);
00637 static Qt::PenStyle getPenStyle(int style);
00638 static Qt::BrushStyle getBrushStyle(int style);
00639 static void showPlotErrorMessage(QWidget *parent, const QStringList& emptyColumns);
00640 static QPrinter::PageSize minPageSize(const QPrinter& printer, const QRect& r);
00641
00642 void showTitleContextMenu();
00643 void copyTitle();
00644 void cutTitle();
00645
00646 void removeAxisTitle();
00647 void cutAxisTitle();
00648 void copyAxisTitle();
00649 void showAxisTitleMenu(int axis);
00650 void showAxisContextMenu(int axis);
00651 void hideSelectedAxis();
00652 void showGrids();
00653 void showAxisDialog();
00654 void showScaleDialog();
00655
00657 void plotSpectrogram(Matrix *m, CurveType type);
00659 void restoreSpectrogram(ApplicationWindow *app, const QStringList& lst);
00660
00661 bool antialiasing(){return d_antialiasing;};
00663 void setAntialiasing(bool on = true, bool update = true);
00664
00665 signals:
00666 void selectedGraph (Graph*);
00667 void closedGraph();
00668 void drawTextOff();
00669 void drawLineEnded(bool);
00670 void cursorInfo(const QString&);
00671 void showPlotDialog(int);
00672 void createTable(const QString&,int,int,const QString&);
00673
00674 void viewImageDialog();
00675 void viewTextDialog();
00676 void viewLineDialog();
00677 void viewTitleDialog();
00678 void modifiedGraph();
00679 void hiddenPlot(QWidget*);
00680
00681 void showContextMenu();
00682 void showCurveContextMenu(int);
00683 void showMarkerPopupMenu();
00684
00685 void showAxisDialog(int);
00686 void axisDblClicked(int);
00687 void xAxisTitleDblClicked();
00688 void yAxisTitleDblClicked();
00689 void rightAxisTitleDblClicked();
00690 void topAxisTitleDblClicked();
00691
00692 void createIntensityTable(const QString&);
00693 void dataRangeChanged();
00694 void showFitResults(const QString&);
00695
00696 private:
00698 QList<QwtPlotCurve *>d_fit_curves;
00700 bool d_antialiasing;
00701 bool autoScaleFonts;
00702 bool d_scale_on_print, d_print_cropmarks;
00703 int selectedAxis;
00704 QStringList axesFormulas;
00706 QStringList axesFormatInfo;
00707 QList <int> axisType;
00709 GridOptions grid;
00710 MarkerType selectedMarkerType;
00711 QwtPlotMarker::LineStyle mrklStyle;
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 QVector<int> d_texts;
00725
00726 QPen mrkLinePen;
00727 QFont auxMrkFont, defaultMarkerFont;
00728 QColor auxMrkColor, auxMrkBkgColor;
00729 QPoint auxMrkStart, auxMrkEnd;
00730 Qt::PenStyle auxMrkStyle;
00731 QString auxMrkFileName, auxMrkText;
00732
00733 int n_curves;
00734 int widthLine, defaultMarkerFrame;
00735 QColor defaultTextMarkerColor, defaultTextMarkerBackground;
00736 int auxMrkAngle,auxMrkBkg,auxMrkWidth;
00737 int auxArrowHeadLength, auxArrowHeadAngle;
00738 long selectedMarker,legendMarkerID;
00739 long mrkX, mrkY;
00740 bool startArrowOn, endArrowOn, drawTextOn, drawLineOn, drawArrowOn;
00741
00742 bool auxFilledArrowHead, ignoreResize;
00743 bool drawAxesBackbone, autoscale;
00744
00745 QColor defaultArrowColor;
00746 int defaultArrowLineWidth, defaultArrowHeadLength, defaultArrowHeadAngle;
00747 bool defaultArrowHeadFill;
00748 Qt::PenStyle defaultArrowLineStyle;
00749
00751 QPointer<SelectionMoveResizer> d_markers_selector;
00753 QPointer<RangeSelectorTool> d_range_selector;
00755 PlotToolInterface *d_active_tool;
00756 };
00757 #endif // GRAPH_H