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 #include <QMap>
00038
00039 #include <qwt_text.h>
00040 #include <qwt_plot.h>
00041 #include <qwt_plot_marker.h>
00042 #include <qwt_plot_curve.h>
00043
00044 #include "../Table.h"
00045 #include "dialogs/AxesDialog.h"
00046 #include "PlotToolInterface.h"
00047 #include "MultiLayer.h"
00048 #include "ScaleDraw.h"
00049
00050 #include <float.h>
00051
00052 class QwtPlotCurve;
00053 class QwtPlotZoomer;
00054 class QwtPieCurve;
00055 class Table;
00056 class LegendWidget;
00057 class ArrowMarker;
00058 class ImageMarker;
00059 class TitlePicker;
00060 class ScalePicker;
00061 class CanvasPicker;
00062 class ApplicationWindow;
00063 class Matrix;
00064 class SelectionMoveResizer;
00065 class RangeSelectorTool;
00066 class DataCurve;
00067 class PlotCurve;
00068 class QwtErrorPlotCurve;
00069 class MultiLayer;
00070 class Spectrogram;
00071 class FunctionCurve;
00072 class VectorCurve;
00073 class BoxCurve;
00074 class QwtHistogram;
00075 class Grid;
00076
00078 typedef struct{
00079 int lCol;
00080 float lWidth;
00081 int lStyle;
00082 int filledArea;
00083 int aCol;
00084 int aStyle;
00085 int symCol;
00086 int fillCol;
00087 float penWidth;
00088 int sSize;
00089 int sType;
00090 int connectType;
00091 } CurveLayout;
00092
00121 class Graph: public QwtPlot
00122 {
00123 Q_OBJECT
00124
00125 public:
00126 Graph (int x = 0, int y = 0, int width = 500, int height = 400, QWidget* parent=0, Qt::WFlags f=0);
00127 ~Graph();
00128
00129 enum Axis{Left, Right, Bottom, Top};
00130 enum Scale{Linear, Log10};
00131 enum Ticks{NoTicks = 0, Out = 1, InOut = 2, In = 3};
00132 enum MarkerType{None = -1, Text = 0, Arrow = 1, Image = 2};
00133 enum CurveType{Line, Scatter, LineSymbols, VerticalBars, Area, Pie, VerticalDropLines,
00134 Spline, HorizontalSteps, Histogram, HorizontalBars, VectXYXY, ErrorBars,
00135 Box, VectXYAM, VerticalSteps, ColorMap, GrayScale, Contour, Function, ImagePlot};
00136
00138 MultiLayer *multiLayer();
00139
00141 void setActiveTool(PlotToolInterface *tool);
00143 PlotToolInterface* activeTool() const { return d_active_tool; }
00144
00145 QList <LegendWidget *> textsList();
00146 LegendWidget *activeText(){return d_active_text;};
00147 void setActiveText(LegendWidget *l){d_active_text = l;};
00148 void select(LegendWidget *l, bool add = false);
00149
00150 void deselect();
00151 void deselect(LegendWidget *);
00152
00153 DataCurve* selectedCurveLabels();
00155 void restoreCurveLabels(int curveID, const QStringList& lst);
00157 void initScaleLimits();
00158
00159 Grid *grid(){return (Grid *)d_grid;};
00160 QList<QwtPlotItem *> curvesList(){return d_curves;};
00161
00162 PlotCurve* closestCurve(int xpos, int ypos, int &dist, int &point);
00163
00164 void insertMarker(QwtPlotMarker *m);
00165
00166 QList<int> getMajorTicksType();
00167 void setMajorTicksType(int axis, int type);
00168
00169 QList<int> getMinorTicksType();
00170 void setMinorTicksType(int axis, int type);
00171
00172 int minorTickLength() const;
00173 int majorTickLength() const;
00174 void setTickLength (int minLength, int majLength);
00175
00176 int axesLinewidth() const;
00177 void setAxesLinewidth(int width);
00178
00179 void axisLabelFormat(int axis, char &f, int &prec) const;
00180
00181 int axisLabelFormat(int axis);
00182 int axisLabelPrecision(int axis);
00183
00184 QColor frameColor();
00185 const QColor & paletteBackgroundColor() const;
00186
00187 void print(QPainter *, const QRect &rect, const QwtPlotPrintFilter & = QwtPlotPrintFilter());
00188 void updateLayout();
00189
00190 void updateCurveLabels();
00191
00192 public slots:
00193 void copy(Graph* g);
00194
00196
00197
00198 bool isPiePlot();
00200 QwtPieCurve* plotPie(Table* w,const QString& name, int startRow = 0, int endRow = -1);
00202 QwtPieCurve* plotPie(Table* w, const QString& name, const QPen& pen, int brush, int size,
00203 int firstColor, int startRow = 0, int endRow = -1, bool visible = true,
00204 double d_start_azimuth = 270, double d_view_angle = 90, double d_thickness = 33,
00205 double d_horizontal_offset = 0.0, double d_edge_dist = 25, bool d_counter_clockwise = false,
00206 bool d_auto_labeling = true, bool d_values = false, bool d_percentages = true,
00207 bool d_categories = false, bool d_fixed_labels_pos = true);
00208
00209 void removePie();
00210 QString pieLegendText();
00211 QString savePieCurveLayout();
00213
00214 bool addCurves(Table* w, const QStringList& names, int style = 0, double lWidth = 1, int sSize = 3, int startRow = 0, int endRow = -1);
00215 PlotCurve* insertCurve(Table* w, const QString& name, int style, int startRow = 0, int endRow = -1);
00216 PlotCurve* insertCurve(Table* w, int xcol, const QString& name, int style);
00217 PlotCurve* insertCurve(Table* w, const QString& xColName, const QString& yColName, int style, int startRow = 0, int endRow = -1);
00218 void insertPlotItem(QwtPlotItem *i, int type);
00219
00221 void showCurve(int index, bool visible = true);
00222 int visibleCurves();
00223
00224 void removeCurve(QwtPlotItem *it);
00226 void removeCurve(int index);
00230 void removeCurve(const QString& s);
00234 void removeCurves(const QString& s);
00235
00236 void updateCurvesData(Table* w, const QString& yColName);
00237
00238 int curveCount(){return d_curves.size();};
00239 bool validCurvesDataSize();
00240 double selectedXStartValue();
00241 double selectedXEndValue();
00242
00244 int curveIndex(QwtPlotCurve *c){return d_curves.indexOf(c);};
00246 int curveIndex(const QString &title){return plotItemsList().findIndex(title);}
00248 QwtPlotCurve* curve(int index);
00250 QwtPlotCurve* curve(const QString &title){return curve(curveIndex(title));}
00251
00253 QStringList analysableCurvesList();
00255 QStringList curveNamesList();
00257 QStringList plotItemsList();
00259 QwtPlotItem* plotItem(int index);
00260
00261 void updateCurveNames(const QString& oldName, const QString& newName, bool updateTableName = true);
00262
00263 void setCurveStyle(int index, int s);
00264 void setCurveFullRange(int curveIndex);
00265
00267
00268 void print();
00269 void setScaleOnPrint(bool on){d_scale_on_print = on;};
00270 void printCropmarks(bool on){d_print_cropmarks = on;};
00271
00272 void copyImage();
00273 QPixmap graphPixmap();
00275 void exportToFile(const QString& fileName);
00276 void exportSVG(const QString& fname);
00277 #ifdef EMF_OUTPUT
00278 void exportEMF(const QString& fname);
00279 #endif
00280 void exportVector(const QString& fileName, int res = 0, bool color = true,
00281 bool keepAspect = true, QPrinter::PageSize pageSize = QPrinter::Custom);
00282 void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
00284
00285 void updatePlot();
00286
00288
00289 QwtErrorPlotCurve* addErrorBars(const QString& xColName, const QString& yColName, Table *errTable,
00290 const QString& errColName, int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00291 bool through = true, bool minus = true, bool plus = true);
00292
00293 QwtErrorPlotCurve* addErrorBars(const QString& yColName, Table *errTable, const QString& errColName,
00294 int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00295 bool through = true, bool minus = true, bool plus = true);
00296
00297 void updateErrorBars(QwtErrorPlotCurve *er, bool xErr, double width, int cap, const QColor& c, bool plus, bool minus, bool through);
00298
00300 DataCurve* masterCurve(QwtErrorPlotCurve *er);
00302 DataCurve* masterCurve(const QString& xColName, const QString& yColName);
00304
00306
00307 void contextMenuEvent(QContextMenuEvent *);
00308 void closeEvent(QCloseEvent *e);
00309 bool focusNextPrevChild ( bool next );
00311
00313 void invertScale(int axis);
00314 void setScale(int axis, double start, double end, double step = 0.0,
00315 int majorTicks = 5, int minorTicks = 5, int type = 0, bool inverted = false,
00316 double left_break = -DBL_MAX, double right_break = DBL_MAX, int pos = 50,
00317 double stepBeforeBreak = 0.0, double stepAfterBreak = 0.0, int minTicksBeforeBreak = 4,
00318 int minTicksAfterBreak = 4, bool log10AfterBreak = false, int breakWidth = 4, bool breakDecoration = true);
00319 double axisStep(int axis){return d_user_step[axis];};
00320
00322
00323 CurveLayout initCurveLayout(int style, int curves = 0);
00324 static CurveLayout initCurveLayout();
00325 void updateCurveLayout(PlotCurve* c, const CurveLayout *cL);
00327 void guessUniqueCurveLayout(int& colorIndex, int& symbolIndex);
00329
00331
00332 void zoomed (const QwtDoubleRect &);
00333 void zoom(bool on);
00334 void zoomOut();
00335 bool zoomOn();
00337
00338 void setAutoScale();
00339 void updateScale();
00340
00342
00343 QString saveToString(bool saveAsTemplate = false);
00344 QString saveScale();
00345 QString saveScaleTitles();
00346 QString saveFonts();
00347 QString saveMarkers();
00348 QString saveCurveLayout(int index);
00349 QString saveAxesTitleColors();
00350 QString saveAxesColors();
00351 QString saveEnabledAxes();
00352 QString saveCanvas();
00353 QString saveTitle();
00354 QString saveAxesTitleAlignement();
00355 QString saveEnabledTickLabels();
00356 QString saveTicksType();
00357 QString saveCurves();
00358 QString saveLabelsFormat();
00359 QString saveLabelsRotation();
00360 QString saveAxesLabelsType();
00361 QString saveAxesBaseline();
00362 QString saveAxesFormulas();
00364
00366
00367 void drawText(bool on);
00368 bool drawTextActive(){return drawTextOn;};
00369 LegendWidget* addText(LegendWidget*);
00370 void remove(LegendWidget*);
00371
00373 LegendWidget* insertText(const QStringList& list, int fileVersion);
00374
00375 LegendWidget* addTimeStamp();
00376 void removeLegend();
00377 void removeLegendItem(int index);
00378 void insertLegend(const QStringList& lst, int fileVersion);
00379
00380 LegendWidget *legend(){return d_legend;};
00381 LegendWidget* newLegend(const QString& text = QString());
00382
00384 QString legendText();
00386
00388
00389 ArrowMarker* addArrow(ArrowMarker* mrk);
00390 void remove(ArrowMarker* arrow);
00391
00393 void addArrow(QStringList list, int fileVersion);
00394 QList<QwtPlotMarker *> linesList(){return d_lines;};
00395
00397 void drawLine(bool on, bool arrow = false);
00398 bool drawArrow(){return drawArrowOn;};
00399 bool drawLineActive(){return drawLineOn;};
00400 bool arrowMarkerSelected();
00402
00404
00405 QList<QwtPlotMarker *> imagesList(){return d_images;};
00406 ImageMarker* addImage(ImageMarker* mrk);
00407 ImageMarker* addImage(const QString& fileName);
00408 void remove(ImageMarker* im);
00409
00410 void insertImageMarker(const QStringList& lst, int fileVersion);
00411 bool imageMarkerSelected();
00412 void updateImageMarker(int x, int y, int width, int height);
00414
00416
00417 void removeMarker();
00419 void updateMarkersBoundingRect();
00420
00427 void setSelectedMarker(QwtPlotMarker* mrk, bool add = false);
00428 QwtPlotMarker* selectedMarker(){return d_selected_marker;};
00429 bool markerSelected();
00431 void deselectMarker();
00433
00435
00436 QwtScaleWidget* currentScale();
00437 QwtScaleWidget* selectedScale();
00438 QRect axisTitleRect(const QwtScaleWidget *scale);
00439
00440 ScaleDraw::ScaleType axisType(int axis);
00441
00442 void setXAxisTitle(const QString& text);
00443 void setYAxisTitle(const QString& text);
00444 void setRightAxisTitle(const QString& text);
00445 void setTopAxisTitle(const QString& text);
00446
00447 QString axisTitleString(int axis){return axisTitle(axis).text();};
00448 void setAxisTitle(int axis, const QString& text);
00450 void setScaleTitle(int axis, const QString& text);
00451
00452 QFont axisTitleFont(int axis);
00453 void setAxisTitleFont(int axis,const QFont &fnt);
00454
00455 void setAxisFont(int axis, const QFont &fnt);
00456 void initFonts(const QFont &scaleTitleFnt,const QFont &numbersFnt);
00457
00458 QColor axisTitleColor(int axis);
00459 void setAxisTitleColor(int axis, const QColor& c);
00460
00461 int axisTitleAlignment (int axis);
00462 void setAxisTitleAlignment(int axis, int align);
00463
00464 QColor axisColor(int axis);
00465 void setAxisColor(int axis, const QColor& color);
00466
00467 QColor axisLabelsColor(int axis);
00468 void setAxisLabelsColor(int axis, const QColor& color);
00469
00470 void showAxis(int axis, int type, const QString& formatInfo, Table *table, bool axisOn,
00471 int majTicksType, int minTicksType, bool labelsOn, const QColor& c, int format,
00472 int prec, int rotation, int baselineDist, const QString& formula, const QColor& labelsColor);
00473
00474 void enableAxis(int axis, bool on = true);
00475 void enableAxisLabels(int axis, bool on = true);
00476
00477 int labelsRotation(int axis);
00478 void setAxisLabelRotation(int axis, int rotation);
00479
00481 void loadAxesLinewidth(int width);
00482
00483 void drawAxesBackbones(bool yes);
00484 bool axesBackbones(){return drawAxesBackbone;};
00486 void loadAxesOptions(const QString& s);
00487
00488 void setAxisMargin(int axis, int margin);
00489
00490 void setMajorTicksType(const QList<int>& lst);
00491 void setMajorTicksType(const QStringList& lst);
00492
00493 void setMinorTicksType(const QList<int>& lst);
00494 void setMinorTicksType(const QStringList& lst);
00495
00496 void setAxisTicksLength(int axis, int majTicksType, int minTicksType, int minLength, int majLength);
00497 void setTicksLength(int minLength, int majLength);
00498 void changeTicksLength(int minLength, int majLength);
00500 void setLabelsNumericFormat(const QStringList& l);
00501 void setLabelsNumericFormat(int axis, int format, int prec = 6, const QString& formula = QString());
00502 void setLabelsDateTimeFormat(int axis, int type, const QString& formatInfo);
00503 void setLabelsDayFormat(int axis, int format);
00504 void setLabelsMonthFormat(int axis, int format);
00505
00506 QString axisFormatInfo(int axis);
00507
00508 void setLabelsTextFormat(int axis, int type, const QString& name, const QStringList& lst);
00509 void setLabelsTextFormat(int axis, int type, const QString& labelsColName, Table *table);
00510
00511 QString axisFormula(int axis);
00512 void setAxisFormula(int axis, const QString &);
00514
00516
00517 void setCanvasFrame(int width = 1, const QColor& color = QColor(Qt::black));
00518 QColor canvasFrameColor();
00519 int canvasFrameWidth();
00521
00523
00524 void setTitleFont(const QFont &fnt);
00525 void setTitleColor(const QColor &c);
00526 void setTitleAlignment(int align);
00527
00528 bool titleSelected();
00529 void selectTitle(bool select = true);
00530
00531 void removeTitle();
00532 void initTitle( bool on, const QFont& fnt);
00534
00536
00537 QString selectedCurveTitle();
00539
00540 void disableTools();
00541
00548 bool enableRangeSelectors(const QObject *status_target=NULL, const char *status_slot="");
00549
00551
00552 void setMargin (int d);
00553 void setFrame(int width = 1, const QColor& color = QColor(Qt::black));
00554 void setBackgroundColor(const QColor& color);
00556
00557 void addFitCurve(QwtPlotCurve *c);
00558 void deleteFitCurves();
00559 QList<QwtPlotCurve *> fitCurvesList(){return d_fit_curves;};
00564 int range(const QString& curveTitle, double *start, double *end);
00565
00567 void setBarsGap(int curve, int gapPercent, int offset);
00568
00570
00571 void modifyFunctionCurve(int curve, int type, const QStringList &formulas, const QString &var, double start, double end, int points);
00572 FunctionCurve* addFunction(const QStringList &formulas, double start, double end, int points = 100, const QString &var = "x", int type = 0, const QString& title = QString::null);
00574 FunctionCurve* insertFunctionCurve(const QString& formula, int points, int fileVersion);
00576 void restoreFunction(const QStringList& lst);
00577
00579 QString generateFunctionName(const QString& name = tr("F"));
00581
00583 void createTable(const QString& curveName);
00584 void createTable(const QwtPlotCurve* curve);
00585 void activateGraph();
00586
00588
00589 VectorCurve* plotVectorCurve(Table* w, const QStringList& colList, int style, int startRow = 0, int endRow = -1);
00590 void updateVectorsLayout(int curve, const QColor& color, double width, int arrowLength, int arrowAngle, bool filled, int position,
00591 const QString& xEndColName = QString(), const QString& yEndColName = QString());
00593
00595
00596 BoxCurve* openBoxDiagram(Table *w, const QStringList& l, int fileVersion);
00597 void plotBoxDiagram(Table *w, const QStringList& names, int startRow = 0, int endRow = -1);
00599
00601
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){d_auto_scale = 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 void showPlotErrorMessage(QWidget *parent, const QStringList& emptyColumns);
00619 static QPrinter::PageSize minPageSize(const QPrinter& printer, const QRect& r);
00620
00621 void showTitleContextMenu();
00622 void copyTitle();
00623 void cutTitle();
00624
00625 void removeAxisTitle();
00626 void cutAxisTitle();
00627 void copyAxisTitle();
00628 void showAxisTitleMenu();
00629 void showAxisContextMenu(int axis);
00630 void hideSelectedAxis();
00631 void showGrids();
00632
00634 void showGrid();
00636 void showGrid(int axis);
00637
00638 void showAxisDialog();
00639 void showScaleDialog();
00640
00642 Spectrogram* plotSpectrogram(Matrix *m, CurveType type);
00644 void restoreSpectrogram(ApplicationWindow *app, const QStringList& lst);
00646 QwtHistogram* addHistogram(Matrix *m);
00648 QwtHistogram* restoreHistogram(Matrix *m, const QStringList& l);
00649
00650 bool antialiasing(){return d_antialiasing;};
00652 void setAntialiasing(bool on = true, bool update = true);
00653
00654 void setCurrentFont(const QFont& f);
00655 void notifyFontChange(const QFont& f){emit currentFontChanged(f);};
00656 void enableTextEditor();
00657
00658 signals:
00659 void selectedGraph (Graph*);
00660 void closedGraph();
00661 void drawTextOff();
00662 void drawLineEnded(bool);
00663 void cursorInfo(const QString&);
00664 void showPlotDialog(int);
00665 void createTable(const QString&,int,int,const QString&);
00666
00667 void viewImageDialog();
00668 void viewTextDialog();
00669 void viewLineDialog();
00670 void viewTitleDialog();
00671 void modifiedGraph();
00672 void hiddenPlot(QWidget*);
00673
00674 void showContextMenu();
00675 void showCurveContextMenu(QwtPlotCurve *);
00676 void showMarkerPopupMenu();
00677
00678 void showAxisDialog(int);
00679 void axisDblClicked(int);
00680
00681 void showAxisTitleDialog();
00682
00683 void dataRangeChanged();
00684 void showFitResults(const QString&);
00685 void currentFontChanged(const QFont&);
00686 void enableTextEditor(Graph *);
00687
00688 private:
00689 void insertCurve(QwtPlotItem *c);
00690
00692 QwtDoubleInterval axisBoundingInterval(int axis);
00693 void deselectCurves();
00694 void addLegendItem();
00695
00696 void showEvent (QShowEvent * event);
00697 void printFrame(QPainter *painter, const QRect &rect) const;
00698 void printCanvas(QPainter *painter, const QRect &canvasRect,
00699 const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const;
00700 virtual void drawItems (QPainter *painter, const QRect &rect,
00701 const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const;
00702
00703 void drawInwardTicks(QPainter *painter, const QRect &rect,
00704 const QwtScaleMap&map, int axis, bool min, bool maj) const;
00705 void drawBreak(QPainter *painter, const QRect &rect, const QwtScaleMap &map, int axis) const;
00706
00707 QwtPlotZoomer *d_zoomer[2];
00708 TitlePicker *titlePicker;
00709 ScalePicker *scalePicker;
00710 CanvasPicker* cp;
00712 Grid *d_grid;
00714 QList<QwtPlotItem*> d_curves;
00716 QList<QwtPlotCurve *>d_fit_curves;
00718 bool d_antialiasing;
00719 bool autoScaleFonts;
00720 bool d_scale_on_print, d_print_cropmarks;
00721 bool drawTextOn, drawLineOn, drawArrowOn, drawAxesBackbone;
00723 QVector<double> d_user_step;
00725 QList<QwtPlotMarker*> d_lines;
00727 QList<QwtPlotMarker*> d_images;
00729 QwtPlotMarker* d_selected_marker;
00731 QPointer<SelectionMoveResizer> d_markers_selector;
00733 QPointer<RangeSelectorTool> d_range_selector;
00735 PlotToolInterface *d_active_tool;
00737 LegendWidget *d_active_text;
00739 LegendWidget *d_legend;
00741 bool d_auto_scale;
00743 int d_min_tick_length, d_maj_tick_length;
00744 };
00745 #endif // GRAPH_H