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 ArrowMarker;
00057 class ImageWidget;
00058 class TitlePicker;
00059 class ScalePicker;
00060 class CanvasPicker;
00061 class ApplicationWindow;
00062 class Matrix;
00063 class SelectionMoveResizer;
00064 class RangeSelectorTool;
00065 class DataCurve;
00066 class PlotCurve;
00067 class QwtErrorPlotCurve;
00068 class MultiLayer;
00069 class Spectrogram;
00070 class FunctionCurve;
00071 class VectorCurve;
00072 class BoxCurve;
00073 class QwtHistogram;
00074 class Grid;
00075 class TexWidget;
00076 class LegendWidget;
00077 class FrameWidget;
00078
00080 typedef struct{
00081 int lCol;
00082 float lWidth;
00083 int lStyle;
00084 int filledArea;
00085 int aCol;
00086 int aStyle;
00087 int symCol;
00088 int fillCol;
00089 float penWidth;
00090 int sSize;
00091 int sType;
00092 int connectType;
00093 } CurveLayout;
00094
00123 class Graph: public QwtPlot
00124 {
00125 Q_OBJECT
00126
00127 public:
00128 Graph (int x = 0, int y = 0, int width = 500, int height = 400, QWidget* parent=0, Qt::WFlags f=0);
00129 ~Graph();
00130
00131 enum Axis{Left, Right, Bottom, Top};
00132 enum Scale{Linear, Log10};
00133 enum Ticks{NoTicks = 0, Out = 1, InOut = 2, In = 3};
00134 enum MarkerType{None = -1, Text = 0, Arrow = 1, Image = 2};
00135 enum CurveType{Line, Scatter, LineSymbols, VerticalBars, Area, Pie, VerticalDropLines,
00136 Spline, HorizontalSteps, Histogram, HorizontalBars, VectXYXY, ErrorBars,
00137 Box, VectXYAM, VerticalSteps, ColorMap, GrayScale, Contour, Function, ImagePlot};
00138
00140 MultiLayer *multiLayer();
00141
00143 void setActiveTool(PlotToolInterface *tool);
00145 PlotToolInterface* activeTool() const { return d_active_tool; }
00146
00147 QList <LegendWidget *> textsList();
00148 LegendWidget *activeText();
00149 void setActiveText(LegendWidget *l){d_active_enrichment = (FrameWidget *)l;};
00150 void select(QWidget *l, bool add = false);
00151
00152 FrameWidget *activeEnrichment(){return d_active_enrichment;};
00153 QList <FrameWidget *> enrichmentsList(){return d_enrichments;};
00154
00155 bool hasSeletedItems();
00156 void deselect();
00157 void deselect(QWidget *);
00158
00159 DataCurve* selectedCurveLabels();
00161 void restoreCurveLabels(int curveID, const QStringList& lst);
00163 void initScaleLimits();
00164
00165 Grid *grid(){return (Grid *)d_grid;};
00166 QList<QwtPlotItem *> curvesList(){return d_curves;};
00167
00168 PlotCurve* closestCurve(int xpos, int ypos, int &dist, int &point);
00169
00170 void insertMarker(QwtPlotMarker *m);
00171
00172 QList<int> getMajorTicksType();
00173 void setMajorTicksType(int axis, int type);
00174
00175 QList<int> getMinorTicksType();
00176 void setMinorTicksType(int axis, int type);
00177
00178 int minorTickLength() const;
00179 int majorTickLength() const;
00180 void setTickLength (int minLength, int majLength);
00181
00182 int axesLinewidth() const;
00183 void setAxesLinewidth(int width);
00184
00185 void axisLabelFormat(int axis, char &f, int &prec) const;
00186
00187 int axisLabelFormat(int axis);
00188 int axisLabelPrecision(int axis);
00189
00190 QColor frameColor();
00191 const QColor & paletteBackgroundColor() const;
00192
00193 void print(QPainter *, const QRect &rect, const QwtPlotPrintFilter & = QwtPlotPrintFilter());
00194 void updateLayout();
00195
00196 void updateCurveLabels();
00197
00198 TexWidget* addTexFormula(const QString& s, const QPixmap& pix);
00199
00200 FrameWidget* add(FrameWidget* fw, bool copy = true);
00201 void remove(FrameWidget*);
00202
00203 QRect boundingRect();
00204 void raiseEnrichements();
00205
00206 public slots:
00207 void copy(Graph* g);
00208 void copyCurves(Graph* g);
00209
00211
00212
00213 bool isPiePlot();
00215 QwtPieCurve* plotPie(Table* w,const QString& name, int startRow = 0, int endRow = -1);
00217 QwtPieCurve* plotPie(Table* w, const QString& name, const QPen& pen, int brush, int size,
00218 int firstColor, int startRow = 0, int endRow = -1, bool visible = true,
00219 double d_start_azimuth = 270, double d_view_angle = 90, double d_thickness = 33,
00220 double d_horizontal_offset = 0.0, double d_edge_dist = 25, bool d_counter_clockwise = false,
00221 bool d_auto_labeling = true, bool d_values = false, bool d_percentages = true,
00222 bool d_categories = false, bool d_fixed_labels_pos = true);
00223
00224 void removePie();
00225 QString pieLegendText();
00226 QString savePieCurveLayout();
00228
00229 bool addCurves(Table* w, const QStringList& names, int style = 0, double lWidth = 1, int sSize = 3, int startRow = 0, int endRow = -1);
00230 PlotCurve* insertCurve(Table* w, const QString& name, int style, int startRow = 0, int endRow = -1);
00231 PlotCurve* insertCurve(Table* w, int xcol, const QString& name, int style);
00232 PlotCurve* insertCurve(Table* w, const QString& xColName, const QString& yColName, int style, int startRow = 0, int endRow = -1);
00233 void insertPlotItem(QwtPlotItem *i, int type);
00234 void insertCurve(QwtPlotItem *c);
00235
00237 void showCurve(int index, bool visible = true);
00238 int visibleCurves();
00239
00240 void removeCurve(QwtPlotItem *it);
00242 void removeCurve(int index);
00246 void removeCurve(const QString& s);
00250 void removeCurves(const QString& s);
00251
00252 void updateCurvesData(Table* w, const QString& yColName);
00253
00254 int curveCount(){return d_curves.size();};
00255 bool validCurvesDataSize();
00256 double selectedXStartValue();
00257 double selectedXEndValue();
00258
00260 int curveIndex(QwtPlotCurve *c){return d_curves.indexOf(c);};
00262 int curveIndex(const QString &title){return plotItemsList().findIndex(title);}
00264 QwtPlotCurve* curve(int index);
00266 QwtPlotCurve* curve(const QString &title){return curve(curveIndex(title));}
00267
00269 QStringList analysableCurvesList();
00271 QStringList curveNamesList();
00273 QStringList plotItemsList();
00275 QwtPlotItem* plotItem(int index);
00276
00277 void updateCurveNames(const QString& oldName, const QString& newName, bool updateTableName = true);
00278
00279 void setCurveStyle(int index, int s);
00280 void setCurveFullRange(int curveIndex);
00281
00283
00284 void print();
00285 void setScaleOnPrint(bool on){d_scale_on_print = on;};
00286 void printCropmarks(bool on){d_print_cropmarks = on;};
00287
00288 void copyImage();
00289 QPixmap graphPixmap();
00291 void exportToFile(const QString& fileName);
00292 void exportSVG(const QString& fname);
00293 #ifdef EMF_OUTPUT
00294 void exportEMF(const QString& fname);
00295 #endif
00296 void exportVector(const QString& fileName, int res = 0, bool color = true);
00297 void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
00299
00300 void updatePlot();
00301
00303
00304 QwtErrorPlotCurve* addErrorBars(const QString& xColName, const QString& yColName, Table *errTable,
00305 const QString& errColName, int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00306 bool through = true, bool minus = true, bool plus = true);
00307
00308 QwtErrorPlotCurve* addErrorBars(const QString& yColName, Table *errTable, const QString& errColName,
00309 int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
00310 bool through = true, bool minus = true, bool plus = true);
00311
00312 void updateErrorBars(QwtErrorPlotCurve *er, bool xErr, double width, int cap, const QColor& c, bool plus, bool minus, bool through);
00313
00315 DataCurve* masterCurve(QwtErrorPlotCurve *er);
00317 DataCurve* masterCurve(const QString& xColName, const QString& yColName);
00319
00321
00322 void contextMenuEvent(QContextMenuEvent *);
00323 void closeEvent(QCloseEvent *e);
00324 bool focusNextPrevChild ( bool next );
00326
00328 void invertScale(int axis);
00329 void setScale(int axis, double start, double end, double step = 0.0,
00330 int majorTicks = 5, int minorTicks = 5, int type = 0, bool inverted = false,
00331 double left_break = -DBL_MAX, double right_break = DBL_MAX, int pos = 50,
00332 double stepBeforeBreak = 0.0, double stepAfterBreak = 0.0, int minTicksBeforeBreak = 4,
00333 int minTicksAfterBreak = 4, bool log10AfterBreak = false, int breakWidth = 4, bool breakDecoration = true);
00334 double axisStep(int axis){return d_user_step[axis];};
00335 void setCanvasCoordinates(const QRectF&);
00336
00338
00339 CurveLayout initCurveLayout(int style, int curves = 0);
00340 static CurveLayout initCurveLayout();
00341 void updateCurveLayout(PlotCurve* c, const CurveLayout *cL);
00343 void guessUniqueCurveLayout(int& colorIndex, int& symbolIndex);
00345
00347
00348 void zoomed (const QwtDoubleRect &);
00349 void zoom(bool on);
00350 void zoomOut();
00351 bool zoomOn();
00353
00354 void setAutoScale();
00355 void updateScale();
00356
00358
00359 QString saveToString(bool saveAsTemplate = false);
00360 QString saveScale();
00361 QString saveScaleTitles();
00362 QString saveFonts();
00363 QString saveMarkers();
00364 QString saveCurveLayout(int index);
00365 QString saveAxesTitleColors();
00366 QString saveAxesColors();
00367 QString saveEnabledAxes();
00368 QString saveCanvas();
00369 QString saveTitle();
00370 QString saveAxesTitleAlignement();
00371 QString saveEnabledTickLabels();
00372 QString saveTicksType();
00373 QString saveCurves();
00374 QString saveLabelsFormat();
00375 QString saveLabelsRotation();
00376 QString saveAxesLabelsType();
00377 QString saveAxesBaseline();
00378 QString saveAxesFormulas();
00380
00382
00383 LegendWidget* addText(LegendWidget*);
00385 LegendWidget* insertText(const QStringList& list, int fileVersion);
00386
00387 LegendWidget* addTimeStamp();
00388 void removeLegendItem(int index);
00389 void insertLegend(const QStringList& lst, int fileVersion);
00390
00391 LegendWidget* newLegend(const QString& text = QString());
00393 QString legendText();
00395
00397
00398 LegendWidget* legend();
00399 void setLegend(const QString&);
00400 void removeLegend();
00402
00404
00405 ArrowMarker* addArrow(ArrowMarker* mrk);
00406 void remove(ArrowMarker* arrow);
00407
00409 void addArrow(QStringList list, int fileVersion);
00410 QList<QwtPlotMarker *> linesList(){return d_lines;};
00411
00413 void drawLine(bool on, bool arrow = false);
00414 bool drawArrow(){return drawArrowOn;};
00415 bool drawLineActive(){return drawLineOn;};
00416 bool arrowMarkerSelected();
00418
00420
00421 ImageWidget* addImage(ImageWidget* i);
00422 ImageWidget* addImage(const QString& fileName);
00423 ImageWidget* addImage(const QImage& image);
00424
00425 void insertImageMarker(const QStringList& lst, int fileVersion);
00426 bool imageMarkerSelected();
00428
00430
00431 void removeMarker();
00433 void updateMarkersBoundingRect();
00434
00441 void setSelectedMarker(QwtPlotMarker* mrk, bool add = false);
00442 QwtPlotMarker* selectedMarker(){return d_selected_marker;};
00443 bool markerSelected();
00445 void deselectMarker();
00447
00449
00450 QwtScaleWidget* currentScale();
00451 QwtScaleWidget* selectedScale();
00452 QRect axisTitleRect(const QwtScaleWidget *scale);
00453
00454 ScaleDraw::ScaleType axisType(int axis);
00455
00456 void setXAxisTitle(const QString& text);
00457 void setYAxisTitle(const QString& text);
00458 void setRightAxisTitle(const QString& text);
00459 void setTopAxisTitle(const QString& text);
00460
00461 QString axisTitleString(int axis){return axisTitle(axis).text();};
00462 void setAxisTitle(int axis, const QString& text);
00464 void setScaleTitle(int axis, const QString& text);
00465
00466 QFont axisTitleFont(int axis);
00467 void setAxisTitleFont(int axis,const QFont &fnt);
00468
00469 void setAxisFont(int axis, const QFont &fnt);
00470 void initFonts(const QFont &scaleTitleFnt,const QFont &numbersFnt);
00471
00472 QColor axisTitleColor(int axis);
00473 void setAxisTitleColor(int axis, const QColor& c);
00474
00475 int axisTitleAlignment (int axis);
00476 void setAxisTitleAlignment(int axis, int align);
00477
00478 QColor axisColor(int axis);
00479 void setAxisColor(int axis, const QColor& color);
00480
00481 QColor axisLabelsColor(int axis);
00482 void setAxisLabelsColor(int axis, const QColor& color);
00483
00484 void showAxis(int axis, int type, const QString& formatInfo, Table *table, bool axisOn,
00485 int majTicksType, int minTicksType, bool labelsOn, const QColor& c, int format,
00486 int prec, int rotation, int baselineDist, const QString& formula, const QColor& labelsColor);
00487
00488 void enableAxis(int axis, bool on = true);
00489 void enableAxisLabels(int axis, bool on = true);
00490
00491 int labelsRotation(int axis);
00492 void setAxisLabelRotation(int axis, int rotation);
00493
00495 void loadAxesLinewidth(int width);
00496
00497 void drawAxesBackbones(bool yes);
00498 bool axesBackbones(){return drawAxesBackbone;};
00500 void loadAxesOptions(const QString& s);
00501
00502 void setAxisMargin(int axis, int margin);
00503
00504 void setMajorTicksType(const QList<int>& lst);
00505 void setMajorTicksType(const QStringList& lst);
00506
00507 void setMinorTicksType(const QList<int>& lst);
00508 void setMinorTicksType(const QStringList& lst);
00509
00510 void setAxisTicksLength(int axis, int majTicksType, int minTicksType, int minLength, int majLength);
00511 void setTicksLength(int minLength, int majLength);
00512 void changeTicksLength(int minLength, int majLength);
00514 void setLabelsNumericFormat(const QStringList& l);
00515 void setLabelsNumericFormat(int axis, int format, int prec = 6, const QString& formula = QString());
00516 void setLabelsDateTimeFormat(int axis, int type, const QString& formatInfo);
00517 void setLabelsDayFormat(int axis, int format);
00518 void setLabelsMonthFormat(int axis, int format);
00519
00520 QString axisFormatInfo(int axis);
00521
00522 void setLabelsTextFormat(int axis, int type, const QString& name, const QStringList& lst);
00523 void setLabelsTextFormat(int axis, int type, const QString& labelsColName, Table *table);
00524
00525 QString axisFormula(int axis);
00526 void setAxisFormula(int axis, const QString &);
00528
00530
00531 void setCanvasFrame(int width = 1, const QColor& color = QColor(Qt::black));
00532 QColor canvasFrameColor();
00533 int canvasFrameWidth();
00535
00537
00538 void setTitleFont(const QFont &fnt);
00539 void setTitleColor(const QColor &c);
00540 void setTitleAlignment(int align);
00541
00542 bool titleSelected();
00543 void selectTitle(bool select = true);
00545 void clearTitle();
00547 void removeTitle();
00548 void initTitle( bool on, const QFont& fnt);
00550
00552
00553 QString selectedCurveTitle();
00555
00556 void disableTools();
00557
00564 bool enableRangeSelectors(const QObject *status_target=NULL, const char *status_slot="");
00565
00567
00568 void setFrame(int width = 1, const QColor& color = Qt::black);
00569 void setBackgroundColor(const QColor& color);
00571
00572 void addFitCurve(QwtPlotCurve *c);
00573 void deleteFitCurves();
00574 QList<QwtPlotCurve *> fitCurvesList(){return d_fit_curves;};
00579 int range(const QString& curveTitle, double *start, double *end);
00580
00582 void setBarsGap(int curve, int gapPercent, int offset);
00583
00585
00586 void modifyFunctionCurve(int curve, int type, const QStringList &formulas, const QString &var,
00587 double start, double end, int points, const QMap<QString, double>& constants);
00588 FunctionCurve* addFunction(const QStringList &formulas, double start, double end, int points = 100, const QString &var = "x", int type = 0, const QString& title = QString::null);
00590 FunctionCurve* insertFunctionCurve(const QString& formula, int points, int fileVersion);
00591
00593 QString generateFunctionName(const QString& name = tr("F"));
00595
00597 void createTable(const QString& curveName);
00598 void createTable(const QwtPlotCurve* curve);
00599 void activateGraph();
00600
00602
00603 VectorCurve* plotVectorCurve(Table* w, const QStringList& colList, int style, int startRow = 0, int endRow = -1);
00604 void updateVectorsLayout(int curve, const QColor& color, double width, int arrowLength, int arrowAngle, bool filled, int position,
00605 const QString& xEndColName = QString(), const QString& yEndColName = QString());
00607
00609
00610 BoxCurve* openBoxDiagram(Table *w, const QStringList& l, int fileVersion);
00611 void plotBoxDiagram(Table *w, const QStringList& names, int startRow = 0, int endRow = -1);
00613
00615
00616 void resizeEvent(QResizeEvent *e);
00617 void scaleFonts(double factor);
00619
00620 void notifyChanges();
00621
00622 void updateSecondaryAxis(int axis);
00623
00624 bool isAutoscalingEnabled(){return d_auto_scale;};
00625 void enableAutoscaling(bool on = true){d_auto_scale = on;};
00626
00627 bool autoscaleFonts(){return autoScaleFonts;};
00628 void setAutoscaleFonts(bool on = true){autoScaleFonts = on;};
00629
00630 static int obsoleteSymbolStyle(int type);
00631 static QString penStyleName(Qt::PenStyle style);
00632 static Qt::PenStyle getPenStyle(const QString& s);
00633 static Qt::PenStyle getPenStyle(int style);
00634 static void showPlotErrorMessage(QWidget *parent, const QStringList& emptyColumns);
00635
00636 void showTitleContextMenu();
00637 void copyTitle();
00638 void cutTitle();
00639
00640 void clearAxisTitle();
00641 void removeAxisTitle();
00642 void cutAxisTitle();
00643 void copyAxisTitle();
00644 void showAxisTitleMenu();
00645 void showAxisContextMenu(int axis);
00646 void hideSelectedAxis();
00647 void showGrids();
00648
00650 void showGrid();
00652 void showGrid(int axis);
00653
00654 void showAxisDialog();
00655 void showScaleDialog();
00656
00658 Spectrogram* plotSpectrogram(Matrix *m, CurveType type);
00660 void restoreSpectrogram(ApplicationWindow *app, const QStringList& lst);
00662 QwtHistogram* addHistogram(Matrix *m);
00664 QwtHistogram* restoreHistogram(Matrix *m, const QStringList& l);
00665
00666 bool antialiasing(){return d_antialiasing;};
00668 void setAntialiasing(bool on = true, bool update = true);
00669
00670 void setCurrentFont(const QFont& f);
00671 void notifyFontChange(const QFont& f){emit currentFontChanged(f);};
00672 void enableTextEditor();
00673
00674 signals:
00675 void selectedGraph (Graph*);
00676 void closedGraph();
00677 void drawLineEnded(bool);
00678 void cursorInfo(const QString&);
00679 void showPlotDialog(int);
00680 void createTable(const QString&,int,int,const QString&);
00681
00682 void viewLineDialog();
00683 void viewTitleDialog();
00684 void modifiedGraph();
00685 void hiddenPlot(QWidget*);
00686
00687 void showContextMenu();
00688 void showCurveContextMenu(QwtPlotCurve *);
00689 void showMarkerPopupMenu();
00690
00691 void showAxisDialog(int);
00692 void axisDblClicked(int);
00693
00694 void showAxisTitleDialog();
00695
00696 void dataRangeChanged();
00697 void showFitResults(const QString&);
00698 void currentFontChanged(const QFont&);
00699 void enableTextEditor(Graph *);
00700
00701 private:
00703 QwtDoubleInterval axisBoundingInterval(int axis);
00704 void deselectCurves();
00705 void addLegendItem();
00706
00707 void showEvent (QShowEvent * event);
00708 void printFrame(QPainter *painter, const QRect &rect) const;
00709 void printCanvas(QPainter *painter, const QRect &canvasRect,
00710 const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const;
00711 virtual void drawItems (QPainter *painter, const QRect &rect,
00712 const QwtScaleMap map[axisCnt], const QwtPlotPrintFilter &pfilter) const;
00713
00714 void drawInwardTicks(QPainter *painter, const QRect &rect,
00715 const QwtScaleMap&map, int axis, bool min, bool maj) const;
00716 void drawBreak(QPainter *painter, const QRect &rect, const QwtScaleMap &map, int axis) const;
00717
00718 QwtPlotZoomer *d_zoomer[2];
00719 TitlePicker *titlePicker;
00720 ScalePicker *scalePicker;
00721 CanvasPicker* cp;
00723 Grid *d_grid;
00725 QList<QwtPlotItem*> d_curves;
00727 QList<QwtPlotCurve *>d_fit_curves;
00729 bool d_antialiasing;
00730 bool autoScaleFonts;
00731 bool d_scale_on_print, d_print_cropmarks;
00732 bool drawLineOn, drawArrowOn, drawAxesBackbone;
00734 QVector<double> d_user_step;
00736 QList<QwtPlotMarker*> d_lines;
00738 QwtPlotMarker* d_selected_marker;
00740 QPointer<SelectionMoveResizer> d_markers_selector;
00742 QPointer<RangeSelectorTool> d_range_selector;
00744 PlotToolInterface *d_active_tool, *d_peak_fit_tool;
00746 FrameWidget *d_active_enrichment;
00748 bool d_auto_scale;
00750 int d_min_tick_length, d_maj_tick_length;
00751 QList<FrameWidget*> d_enrichments;
00752 };
00753 #endif // GRAPH_H