~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/Graph.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : Graph.h
 
3
    Project              : SciDAVis
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief, Tilman Benkert
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net
 
7
    Description          : Graph widget
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#ifndef GRAPH_H
 
30
#define GRAPH_H
 
31
 
 
32
#include <QList>
 
33
#include <QPointer>
 
34
#include <QPrinter>
 
35
#include <QVector>
 
36
#include <QEvent>
 
37
#include <QMap>
 
38
 
 
39
#include <qwt_plot.h>
 
40
#include <qwt_plot_marker.h>
 
41
#include <qwt_plot_curve.h>
 
42
 
 
43
#include "Plot.h"
 
44
#include "Table.h"
 
45
#include "AxesDialog.h"
 
46
#include "PlotToolInterface.h"
 
47
#include "core/column/Column.h"
 
48
 
 
49
class QwtPlotCurve;
 
50
class QwtPlotZoomer;
 
51
class QwtPieCurve;
 
52
class Table;
 
53
class Legend;
 
54
class ArrowMarker;
 
55
class ImageMarker;
 
56
class TitlePicker;
 
57
class ScalePicker;
 
58
class CanvasPicker;
 
59
class ApplicationWindow;
 
60
class Matrix;
 
61
class SelectionMoveResizer;
 
62
class RangeSelectorTool;
 
63
class DataCurve;
 
64
class PlotCurve;
 
65
class QwtErrorPlotCurve;
 
66
 
 
67
//! Structure containing curve layout parameters
 
68
typedef struct{
 
69
  int lCol;        //!< line color
 
70
  int lWidth;      //!< line width
 
71
  int lStyle;      //!< line style
 
72
  int filledArea;  //!< flag: toggles area filling under curve
 
73
  int aCol;        //!< curve area color
 
74
  int aStyle;      //!< area filling style
 
75
  int symCol;      //!< symbol outline color
 
76
  int fillCol;     //!< symbol fill color
 
77
  int penWidth;    //!< symbol outline width
 
78
  int sSize;       //!< symbol size
 
79
  int sType;       //!< symbol type (shape)
 
80
  int connectType; //!< symbol connection type
 
81
}  CurveLayout;
 
82
 
 
83
/**
 
84
 * \brief A 2D-plotting widget.
 
85
 *
 
86
 * Graphs are managed by a MultiLayer, where they are sometimes referred to as "graphs" and sometimes as "layers".
 
87
 * Other parts of the code also call them "plots", regardless of the fact that there's also a class Plot.
 
88
 * Within the user interface, they are quite consistently called "layers".
 
89
 *
 
90
 * Each graph owns a Plot called #d_plot, which handles parts of the curve, axis and marker management (similarly to QwtPlot),
 
91
 * as well as the pickers #d_zoomer (a QwtPlotZoomer), #titlePicker (a TitlePicker), #scalePicker (a ScalePicker) and #cp (a CanvasPicker),
 
92
 * which handle various parts of the user interaction.
 
93
 *
 
94
 * Graph contains support for various curve types (see #CurveType),
 
95
 * some of them relying on SciDAVis-specific QwtPlotCurve subclasses for parts of the functionality.
 
96
 *
 
97
 * %Note that some of Graph's methods are implemented in analysis.cpp.
 
98
 *
 
99
 * \section future_plans Future Plans
 
100
 * Merge with Plot and CanvasPicker.
 
101
 * Think about merging in TitlePicker and ScalePicker.
 
102
 * On the other hand, things like range selection, peak selection or (re)moving data points could be split out into tool classes
 
103
 * like QwtPlotZoomer or SelectionMoveResizer.
 
104
 *
 
105
 * What definitely should be split out are plot types like histograms and pie charts (TODO: which others?).
 
106
 * We need a generic framework for this in any case so that new plot types can be implemented in plugins,
 
107
 * and Graph could do with a little diet. Especially after merging in Plot and CanvasPicker.
 
108
 * [ Framework needs to support plug-ins; assigned to knut ]
 
109
 *
 
110
 * Add support for floating-point line widths of curves and axes (request 2300).
 
111
 * [ assigned to thzs ]
 
112
 */
 
113
 
 
114
class Graph: public QWidget
 
115
{
 
116
        Q_OBJECT
 
117
 
 
118
        public:
 
119
                Graph (QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
 
120
                ~Graph();
 
121
 
 
122
                enum AxisType{Numeric = 0, Txt = 1, Day = 2, Month = 3, Time = 4, Date = 5, ColHeader = 6, DateTime = 22};
 
123
                enum MarkerType{None = -1, Text = 0, Arrow = 1, Image = 2};
 
124
                enum CurveType{Line, Scatter, LineSymbols, VerticalBars, Area, Pie, VerticalDropLines,
 
125
                        Spline, HorizontalSteps, Histogram, HorizontalBars, VectXYXY, ErrorBars,
 
126
                        Box, VectXYAM, VerticalSteps, ColorMap, GrayMap, ContourMap, Function};
 
127
 
 
128
                Plot *d_plot;
 
129
                QwtPlotZoomer *d_zoomer[2];
 
130
                TitlePicker *titlePicker;
 
131
                ScalePicker *scalePicker;
 
132
                CanvasPicker* cp;
 
133
 
 
134
                static int mapToQwtAxis(int axis);
 
135
 
 
136
                //! Returns the name of the parent MultiLayer object.
 
137
                QString parentPlotName();
 
138
 
 
139
                //! Change the active tool, deleting the old one if it exists.
 
140
                void setActiveTool(PlotToolInterface *tool);
 
141
                //! Return the active tool, or NULL if none is active.
 
142
                PlotToolInterface* activeTool() const { return d_active_tool; }
 
143
 
 
144
                Grid *grid(){return d_plot->grid();};
 
145
 
 
146
        public slots:
 
147
                //! Accessor method for #d_plot.
 
148
                Plot* plotWidget(){return d_plot;};
 
149
                void copy(ApplicationWindow *parent, Graph* g);
 
150
 
 
151
                //! \name Pie Curves
 
152
                //@{
 
153
                //! Returns true if this Graph is a pie plot, false otherwise.
 
154
                bool isPiePlot(){return (c_type.count() == 1 && c_type[0] == Pie);};
 
155
                void plotPie(Table* w,const QString& name, int startRow = 0, int endRow = -1);
 
156
                //! Used when restoring a pie plot from a project file
 
157
                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);
 
158
                void removePie();
 
159
                QString pieLegendText();
 
160
                QString savePieCurveLayout();
 
161
                //@}
 
162
 
 
163
                bool insertCurvesList(Table* w, const QStringList& names, int style, int lWidth, int sSize, int startRow = 0, int endRow = -1);
 
164
                bool insertCurve(Table* w, const QString& name, int style, int startRow = 0, int endRow = -1);
 
165
                bool insertCurve(Table* w, int xcol, const QString& name, int style);
 
166
                bool insertCurve(Table* w, const QString& xColName, const QString& yColName, int style, int startRow = 0, int endRow = -1);
 
167
                void insertPlotItem(QwtPlotItem *i, int type);
 
168
 
 
169
                //! Shows/Hides a curve defined by its index.
 
170
                void showCurve(int index, bool visible = true);
 
171
                int visibleCurves();
 
172
 
 
173
                //! Removes a curve defined by its index.
 
174
                void removeCurve(int index);
 
175
                /**
 
176
                 * \brief Removes a curve defined by its title string s.
 
177
                 */
 
178
                void removeCurve(const QString& s);
 
179
                /**
 
180
                 * \brief Removes all curves defined by the title/plot association string s.
 
181
                 */
 
182
                void removeCurves(const QString& s);
 
183
 
 
184
                void updateCurvesData(Table* w, const QString& yColName);
 
185
 
 
186
                int curves(){return n_curves;};
 
187
                bool validCurvesDataSize();
 
188
                double selectedXStartValue();
 
189
                double selectedXEndValue();
 
190
 
 
191
        long curveKey(int curve){return c_keys[curve];}
 
192
                int curveIndex(long key){return c_keys.indexOf(key);};
 
193
                //! Map curve pointer to index.
 
194
                int curveIndex(QwtPlotCurve *c) const;
 
195
                //! map curve title to index
 
196
            int curveIndex(const QString &title){return plotItemsList().indexOf(title);}
 
197
            //! get curve by index
 
198
            QwtPlotCurve* curve(int index);
 
199
            //! get curve by name
 
200
            QwtPlotCurve* curve(const QString &title){return curve(curveIndex(title));}
 
201
 
 
202
                //! Returns the names of all the curves suitable for data analysis, as a string list. The list excludes error bars and spectrograms.
 
203
                QStringList analysableCurvesList();
 
204
                //! Returns the names of all the QwtPlotCurve items on the plot, as a string list
 
205
                QStringList curvesList();
 
206
            //! Returns the names of all plot items, including spectrograms, as a string list
 
207
                QStringList plotItemsList();
 
208
                 //! get plotted item by index
 
209
            QwtPlotItem* plotItem(int index);
 
210
            //! get plot item by index
 
211
            int plotItemIndex(QwtPlotItem *it) const;
 
212
 
 
213
        void updateCurveNames(const QString& oldName, const QString& newName, bool updateTableName = true);
 
214
 
 
215
                int curveType(int curveIndex);
 
216
                //! Test whether curve can be converted to type using setCurveType().
 
217
                static bool canConvertTo(QwtPlotCurve *curve, CurveType type);
 
218
                //! Change the type of the given curve.
 
219
                /**
 
220
                 * The option to disable updating is provided so as not to break the project opening code
 
221
                 * (ApplicationWindow::openGraph()).
 
222
                 */
 
223
                void setCurveType(int curve, CurveType type, bool update=true);
 
224
                void setCurveFullRange(int curveIndex);
 
225
 
 
226
                //! \name Output: Copy/Export/Print
 
227
                //@{
 
228
                void print();
 
229
                void setScaleOnPrint(bool on){d_scale_on_print = on;};
 
230
                void printCropmarks(bool on){d_print_cropmarks = on;};
 
231
 
 
232
                void copyImage();
 
233
                QPixmap graphPixmap();
 
234
                //! Provided for convenience in scripts
 
235
                void exportToFile(const QString& fileName);
 
236
                void exportSVG(const QString& fname);
 
237
                void exportVector(const QString& fileName, int res = 0, bool color = true,
 
238
                        bool keepAspect = true, QPrinter::PageSize pageSize = QPrinter::Custom, 
 
239
                                                QPrinter::Orientation orientation = QPrinter::Portrait);
 
240
                void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
 
241
                //@}
 
242
 
 
243
                void replot(){d_plot->replot();};
 
244
                void updatePlot();
 
245
 
 
246
                //! \name Error Bars
 
247
                //@{
 
248
                bool addErrorBars(const QString& xColName, const QString& yColName, Table *errTable,
 
249
                                const QString& errColName, int type = 1, int width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
 
250
                                bool through = true, bool minus = true, bool plus = true);
 
251
 
 
252
                bool addErrorBars(const QString& yColName, Table *errTable, const QString& errColName,
 
253
                                int type = 1, int width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
 
254
                                bool through = true, bool minus = true, bool plus = true);
 
255
 
 
256
                void updateErrorBars(QwtErrorPlotCurve *er, bool xErr,int width, int cap, const QColor& c, bool plus, bool minus, bool through);
 
257
 
 
258
                //! Returns a valid master curve for the error bars curve.
 
259
                DataCurve* masterCurve(QwtErrorPlotCurve *er);
 
260
                //! Returns a valid master curve for a plot association.
 
261
                DataCurve* masterCurve(const QString& xColName, const QString& yColName);
 
262
                //@}
 
263
 
 
264
                //! \name Event Handlers
 
265
                //@{
 
266
                void contextMenuEvent(QContextMenuEvent *);
 
267
                void closeEvent(QCloseEvent *e);
 
268
                bool focusNextPrevChild ( bool next );
 
269
                //@}
 
270
 
 
271
                //! Set axis scale
 
272
                void setScale(int axis, double start, double end, double step = 0.0,
 
273
                                int majorTicks = 5, int minorTicks = 5, int type = 0, bool inverted = false);
 
274
                double axisStep(int axis){return d_user_step[axis];};
 
275
 
 
276
                //! \name Curves Layout
 
277
                //@{
 
278
                CurveLayout initCurveLayout(int style, int curves = 0);
 
279
                static CurveLayout initCurveLayout();
 
280
                //! Set layout parameters of the curve given by index.
 
281
                void updateCurveLayout(int index,const CurveLayout *cL);
 
282
                //! Tries to guess not already used curve color and symbol style
 
283
                void guessUniqueCurveLayout(int& colorIndex, int& symbolIndex);
 
284
                //@}
 
285
 
 
286
                //! \name Zoom
 
287
                //@{
 
288
                void zoomed (const QwtDoubleRect &);
 
289
                void zoom(bool on);
 
290
                void zoomOut();
 
291
                bool zoomOn();
 
292
                //@}
 
293
 
 
294
                void setAutoScale();
 
295
                void updateScale();
 
296
 
 
297
                //! \name Saving to File
 
298
                //@{
 
299
                QString saveToString(bool saveAsTemplate = false);
 
300
                QString saveScale();
 
301
                QString saveScaleTitles();
 
302
                QString saveFonts();
 
303
                QString saveMarkers();
 
304
                QString saveCurveLayout(int index);
 
305
                QString saveAxesTitleColors();
 
306
                QString saveAxesColors();
 
307
                QString saveEnabledAxes();
 
308
                QString saveCanvas();
 
309
                QString saveTitle();
 
310
                QString saveAxesTitleAlignement();
 
311
                QString saveEnabledTickLabels();
 
312
                QString saveTicksType();
 
313
                QString saveCurves();
 
314
                QString saveLabelsFormat();
 
315
                QString saveLabelsRotation();
 
316
                QString saveAxesLabelsType();
 
317
                QString saveAxesBaseline();
 
318
                QString saveAxesFormulas();
 
319
                //@}
 
320
 
 
321
                //! \name Text Markers
 
322
                //@{
 
323
                void drawText(bool on);
 
324
                bool drawTextActive(){return drawTextOn;};
 
325
                long insertTextMarker(Legend* mrk);
 
326
 
 
327
                //! Used when opening a project file
 
328
                long insertTextMarker(const QStringList& list, int fileVersion);
 
329
                void updateTextMarker(const QString& text,int angle, int bkg,const QFont& fnt,
 
330
                                const QColor& textColor, const QColor& backgroundColor);
 
331
 
 
332
                QFont defaultTextMarkerFont(){return defaultMarkerFont;};
 
333
                QColor textMarkerDefaultColor(){return defaultTextMarkerColor;};
 
334
                QColor textMarkerDefaultBackground(){return defaultTextMarkerBackground;};
 
335
                int textMarkerDefaultFrame(){return defaultMarkerFrame;};
 
336
                void setTextMarkerDefaults(int f, const QFont &font, const QColor& textCol, const QColor& backgroundCol);
 
337
 
 
338
                void setCopiedMarkerType(Graph::MarkerType type){selectedMarkerType=type;};
 
339
                void setCopiedMarkerEnds(const QPoint& start, const QPoint& end);
 
340
                void setCopiedTextOptions(int bkg, const QString& text, const QFont& font,
 
341
                                const QColor& color, const QColor& bkgColor);
 
342
                void setCopiedArrowOptions(int width, Qt::PenStyle style, const QColor& color,
 
343
                                bool start, bool end, int headLength, int headAngle, bool filledHead);
 
344
                void setCopiedImageName(const QString& fn){auxMrkFileName=fn;};
 
345
                QRect copiedMarkerRect(){return QRect(auxMrkStart, auxMrkEnd);};
 
346
                QVector<int> textMarkerKeys(){return d_texts;};
 
347
                Legend* textMarker(long id);
 
348
 
 
349
                void addTimeStamp();
 
350
 
 
351
                void removeLegend();
 
352
                void removeLegendItem(int index);
 
353
                void addLegendItem(const QString& colName);
 
354
                void insertLegend(const QStringList& lst, int fileVersion);
 
355
                Legend *legend();
 
356
                Legend *newLegend();
 
357
                Legend *newLegend(const QString& text);
 
358
                bool hasLegend(){return legendMarkerID >= 0;};
 
359
 
 
360
                //! Creates a new legend text using the curves titles
 
361
                QString legendText();
 
362
                //@}
 
363
 
 
364
                //! \name Line Markers
 
365
                //@{
 
366
                ArrowMarker* arrow(long id);
 
367
                void addArrow(ArrowMarker* mrk);
 
368
 
 
369
                //! Used when opening a project file
 
370
                void addArrow(QStringList list, int fileVersion);
 
371
                QVector<int> lineMarkerKeys(){return d_lines;};
 
372
 
 
373
                //!Draws a line/arrow depending on the value of "arrow"
 
374
                void drawLine(bool on, bool arrow = FALSE);
 
375
                bool drawArrow(){return drawArrowOn;};
 
376
                bool drawLineActive(){return drawLineOn;};
 
377
 
 
378
                Qt::PenStyle arrowLineDefaultStyle(){return defaultArrowLineStyle;};
 
379
                bool arrowHeadDefaultFill(){return defaultArrowHeadFill;};
 
380
                int arrowDefaultWidth(){return defaultArrowLineWidth;};
 
381
                int arrowHeadDefaultLength(){return defaultArrowHeadLength;};
 
382
                int arrowHeadDefaultAngle(){return defaultArrowHeadAngle;};
 
383
                QColor arrowDefaultColor(){return defaultArrowColor;};
 
384
 
 
385
                void setArrowDefaults(int lineWidth,  const QColor& c, Qt::PenStyle style,
 
386
                                int headLength, int headAngle, bool fillHead);
 
387
        bool arrowMarkerSelected();
 
388
                //@}
 
389
 
 
390
                //! \name Image Markers
 
391
                //@{
 
392
                ImageMarker* imageMarker(long id);
 
393
                QVector<int> imageMarkerKeys(){return d_images;};
 
394
                ImageMarker* addImage(ImageMarker* mrk);
 
395
                ImageMarker* addImage(const QString& fileName);
 
396
 
 
397
                void insertImageMarker(const QStringList& lst, int fileVersion);
 
398
                bool imageMarkerSelected();
 
399
                void updateImageMarker(int x, int y, int width, int height);
 
400
                //@}
 
401
 
 
402
                //! \name Common to all Markers
 
403
                //@{
 
404
                void removeMarker();
 
405
                void cutMarker();
 
406
                void copyMarker();
 
407
                void pasteMarker();
 
408
                //! Keep the markers on screen each time the scales are modified by adding/removing curves
 
409
                void updateMarkersBoundingRect();
 
410
 
 
411
                long selectedMarkerKey();
 
412
                /*!\brief Set the selected marker.
 
413
                 * \param mrk key of the marker to be selected.
 
414
                 * \param add whether the marker is to be added to an existing selection.
 
415
                 * If <i>add</i> is false (the default) or there is no existing selection, a new SelectionMoveResizer is
 
416
                 * created and stored in #d_markers_selector.
 
417
                 */
 
418
                void setSelectedMarker(long mrk, bool add=false);
 
419
                QwtPlotMarker* selectedMarkerPtr();
 
420
                bool markerSelected();
 
421
                //! Reset any selection states on markers.
 
422
                void deselectMarker();
 
423
                MarkerType copiedMarkerType(){return selectedMarkerType;};
 
424
                //@}
 
425
        
 
426
                //! \name Axes
 
427
                //@{
 
428
                QList<int> axesType();
 
429
 
 
430
                QStringList scalesTitles();
 
431
                void setXAxisTitle(const QString& text);
 
432
                void setYAxisTitle(const QString& text);
 
433
                void setRightAxisTitle(const QString& text);
 
434
                void setTopAxisTitle(const QString& text);
 
435
                void setAxisTitle(int axis, const QString& text);
 
436
                QString axisTitle(int axis) { return d_plot->axisTitle(axis).text(); }
 
437
 
 
438
                QFont axisTitleFont(int axis);
 
439
                void setXAxisTitleFont(const QFont &fnt);
 
440
                void setYAxisTitleFont(const QFont &fnt);
 
441
                void setRightAxisTitleFont(const QFont &fnt);
 
442
                void setTopAxisTitleFont(const QFont &fnt);
 
443
                void setAxisTitleFont(int axis,const QFont &fnt);
 
444
 
 
445
                void setAxisFont(int axis,const QFont &fnt);
 
446
                QFont axisFont(int axis);
 
447
                void initFonts(const QFont &scaleTitleFnt,const QFont &numbersFnt);
 
448
 
 
449
                QColor axisTitleColor(int axis);
 
450
                void setXAxisTitleColor(const QColor& c);
 
451
                void setYAxisTitleColor(const QColor& c);
 
452
                void setRightAxisTitleColor(const QColor& c);
 
453
                void setTopAxisTitleColor(const QColor& c);
 
454
                void setAxesTitleColor(QStringList l);
 
455
 
 
456
                int axisTitleAlignment (int axis);
 
457
                void setXAxisTitleAlignment(int align);
 
458
                void setYAxisTitleAlignment(int align);
 
459
                void setTopAxisTitleAlignment(int align);
 
460
                void setRightAxisTitleAlignment(int align);
 
461
                void setAxesTitlesAlignment(const QStringList& align);
 
462
 
 
463
        QColor axisColor(int axis);
 
464
                QStringList axesColors();
 
465
                void setAxesColors(const QStringList& colors);
 
466
 
 
467
        QColor axisNumbersColor(int axis);
 
468
            QStringList axesNumColors();
 
469
            void setAxesNumColors(const QStringList& colors);
 
470
 
 
471
                void showAxis(int axis, int type, const QString& formatInfo, Table *table, bool axisOn,
 
472
                                int majTicksType, int minTicksType, bool labelsOn, const QColor& c, int format,
 
473
                int prec, int rotation, int baselineDist, const QString& formula, const QColor& labelsColor);
 
474
 
 
475
                void enableAxis(int axis, bool on = true);
 
476
                QVector<bool> enabledAxes();
 
477
                void enableAxes(QVector<bool> axesOn);
 
478
                void enableAxes(const QStringList& list);
 
479
 
 
480
                int labelsRotation(int axis);
 
481
                void setAxisLabelRotation(int axis, int rotation);
 
482
 
 
483
                QStringList enabledTickLabels();
 
484
                void setEnabledTickLabels(const QStringList& list);
 
485
 
 
486
                void setAxesLinewidth(int width);
 
487
                //! used when opening a project file
 
488
                void loadAxesLinewidth(int width);
 
489
 
 
490
                void drawAxesBackbones(bool yes);
 
491
                bool axesBackbones(){return drawAxesBackbone;};
 
492
                //! used when opening a project file
 
493
                void loadAxesOptions(const QString& s);
 
494
 
 
495
                QList<int> axesBaseline();
 
496
                void setAxesBaseline(const QList<int> &lst);
 
497
                void setAxesBaseline(QStringList &lst);
 
498
 
 
499
                void setMajorTicksType(const QList<int>& lst);
 
500
                void setMajorTicksType(const QStringList& lst);
 
501
 
 
502
                void setMinorTicksType(const QList<int>& lst);
 
503
                void setMinorTicksType(const QStringList& lst);
 
504
 
 
505
                int minorTickLength();
 
506
                int majorTickLength();
 
507
                void setAxisTicksLength(int axis, int majTicksType, int minTicksType,
 
508
                                int minLength, int majLength);
 
509
                void setTicksLength(int minLength, int majLength);
 
510
                void changeTicksLength(int minLength, int majLength);
 
511
 
 
512
                void setLabelsNumericFormat(const QStringList& l);
 
513
                void setLabelsNumericFormat(int axis, const QStringList& l);
 
514
                void setLabelsNumericFormat(int axis, int format, int prec = 6, const QString& formula = QString());
 
515
                void setLabelsDateTimeFormat(int axis, int type, const QString& formatInfo);
 
516
                void setLabelsDayFormat(int axis, int format);
 
517
                void setLabelsMonthFormat(int axis, int format);
 
518
 
 
519
                QString axisFormatInfo(int axis);
 
520
                QStringList axesLabelsFormatInfo(){return axesFormatInfo;};
 
521
 
 
522
                void setLabelsTextFormat(int axis, const Column *column, int startRow, int endRow);
 
523
                void setLabelsTextFormat(int axis, Table *table, const QString& columnName);
 
524
                void setLabelsColHeaderFormat(int axis, Table *table);
 
525
 
 
526
                QStringList getAxesFormulas(){return axesFormulas;};
 
527
                void setAxesFormulas(const QStringList& l){axesFormulas = l;};
 
528
                void setAxisFormula(int pos, const QString &f){axesFormulas[pos] = f;};
 
529
                //@}
 
530
 
 
531
                //! \name Canvas Frame
 
532
                //@{
 
533
                void drawCanvasFrame(bool frameOn, int width);
 
534
                void drawCanvasFrame(const QStringList& frame);
 
535
                void drawCanvasFrame(bool frameOn, int width, const QColor& color);
 
536
                QColor canvasFrameColor();
 
537
                int canvasFrameWidth();
 
538
                bool framed();
 
539
                //@}
 
540
 
 
541
                //! \name Plot Title
 
542
                //@{
 
543
                void setTitle(const QString& t);
 
544
                void setTitleFont(const QFont &fnt);
 
545
                void setTitleColor(const QColor &c);
 
546
                void setTitleAlignment(int align);
 
547
 
 
548
                bool titleSelected();
 
549
                void selectTitle();
 
550
 
 
551
                void removeTitle();
 
552
                void initTitle( bool on, const QFont& fnt);
 
553
                //@}
 
554
 
 
555
                //! \name Modifing insertCurve Data
 
556
                //@{
 
557
                int selectedCurveID();
 
558
                int selectedCurveIndex() { return curveIndex(selectedCurveID()); }
 
559
                QString selectedCurveTitle();
 
560
                //@}
 
561
 
 
562
                void disableTools();
 
563
 
 
564
                /*! Enables the data range selector tool.
 
565
                 *
 
566
                 * This one is a bit special, because other tools can depend upon an existing selection.
 
567
                 * Therefore, range selection (like zooming) has to be provided in addition to the generic
 
568
                 * tool interface.
 
569
                 */
 
570
                bool enableRangeSelectors(const QObject *status_target=NULL, const char *status_slot="");
 
571
 
 
572
                //! \name Border and Margin
 
573
                //@{
 
574
                void setMargin (int d);
 
575
                void setFrame(int width = 1, const QColor& color = QColor(Qt::black));
 
576
                void setBackgroundColor(const QColor& color);
 
577
                void setCanvasBackground(const QColor& color);
 
578
                //@}
 
579
 
 
580
                void addFitCurve(QwtPlotCurve *c);
 
581
                void deleteFitCurves();
 
582
                QList<QwtPlotCurve *> fitCurvesList(){return d_fit_curves;};
 
583
                /*! Set start and end to selected X range of curve index or, if there's no selection, to the curve's total range.
 
584
                 *
 
585
                 * \return the number of selected or total points
 
586
                 */
 
587
                int range(int index, double *start, double *end);
 
588
 
 
589
                //!  Used for VerticalBars, HorizontalBars and Histograms
 
590
                void setBarsGap(int curve, int gapPercent, int offset);
 
591
 
 
592
                //! \name Image Analysis Tools
 
593
                //@{
 
594
                void showIntensityTable();
 
595
                //@}
 
596
 
 
597
                //! \name User-defined Functions
 
598
                //@{
 
599
                bool modifyFunctionCurve(ApplicationWindow * parent, int curve, int type, const QStringList &formulas, const QString &var,QList<double> &ranges, int points);
 
600
                bool addFunctionCurve(ApplicationWindow *parent, int type, const QStringList &formulas, const QString& var,
 
601
                                QList<double> &ranges, int points, const QString& title = QString::null);
 
602
                //! Used when reading from a project file.
 
603
                bool insertFunctionCurve(ApplicationWindow * parent, const QStringList& func_spec, int points, int fileVersion);
 
604
                //! Returns an unique function name
 
605
        QString generateFunctionName(const QString& name = tr("F"));
 
606
                //@}
 
607
 
 
608
        //! Provided for convenience in scripts.
 
609
                void createTable(const QString& curveName);
 
610
        void createTable(const QwtPlotCurve* curve);
 
611
                void activateGraph();
 
612
 
 
613
                //! \name Vector Curves
 
614
                //@{
 
615
                void plotVectorCurve(Table* w, const QStringList& colList, int style, int startRow = 0, int endRow = -1);
 
616
                void updateVectorsLayout(int curve, const QColor& color, int width, int arrowLength, int arrowAngle, bool filled, int position,
 
617
                                const QString& xEndColName = QString(), const QString& yEndColName = QString());
 
618
                //@}
 
619
 
 
620
                //! \name Box Plots
 
621
                //@{
 
622
                void openBoxDiagram(Table *w, const QStringList& l, int fileVersion);
 
623
                void plotBoxDiagram(Table *w, const QStringList& names, int startRow = 0, int endRow = -1);
 
624
                //@}
 
625
 
 
626
                void setCurveSymbol(int index, const QwtSymbol& s);
 
627
                void setCurvePen(int index, const QPen& p);
 
628
                void setCurveBrush(int index, const QBrush& b);
 
629
                void setCurveStyle(int index, int s);
 
630
 
 
631
                //! \name Resizing
 
632
                //@{
 
633
                bool ignoresResizeEvents(){return ignoreResize;};
 
634
                void setIgnoreResizeEvents(bool ok){ignoreResize=ok;};
 
635
                void resizeEvent(QResizeEvent *e);
 
636
                void scaleFonts(double factor);
 
637
                //@}
 
638
 
 
639
                void notifyChanges();
 
640
 
 
641
                void updateSecondaryAxis(int axis);
 
642
                void enableAutoscaling(bool yes){m_autoscale = yes;};
 
643
 
 
644
                bool autoscaleFonts(){return autoScaleFonts;};
 
645
                void setAutoscaleFonts(bool yes){autoScaleFonts = yes;};
 
646
 
 
647
                static int obsoleteSymbolStyle(int type);
 
648
                static QString penStyleName(Qt::PenStyle style);
 
649
                static Qt::PenStyle getPenStyle(const QString& s);
 
650
                static Qt::PenStyle getPenStyle(int style);
 
651
                static Qt::BrushStyle getBrushStyle(int style);
 
652
                static void showPlotErrorMessage(QWidget *parent, const QStringList& emptyColumns);
 
653
                static QPrinter::PageSize minPageSize(const QPrinter& printer, const QRect& r);
 
654
 
 
655
                void showTitleContextMenu();
 
656
                void copyTitle();
 
657
                void cutTitle();
 
658
 
 
659
                void removeAxisTitle();
 
660
                void cutAxisTitle();
 
661
                void copyAxisTitle();
 
662
                void showAxisTitleMenu(int axis);
 
663
                void showAxisContextMenu(int axis);
 
664
                void hideSelectedAxis();
 
665
                void showGrids();
 
666
 
 
667
                //! Convenience function enabling the grid for QwtScaleDraw::Left and Bottom Scales
 
668
                void showGrid();
 
669
                //! Convenience function enabling the grid for a user defined axis
 
670
                void showGrid(int axis);
 
671
 
 
672
                void showAxisDialog();
 
673
                void showScaleDialog();
 
674
 
 
675
                //! Add a spectrogram to the graph
 
676
                void plotSpectrogram(Matrix *m, CurveType type);
 
677
                //! Restores a spectrogram. Used when opening a project file.
 
678
                void restoreSpectrogram(ApplicationWindow *app, const QStringList& lst);
 
679
 
 
680
                bool antialiasing(){return d_antialiasing;};
 
681
                //! Enables/Disables antialiasing of plot items.
 
682
                void setAntialiasing(bool on = true, bool update = true);
 
683
 
 
684
                void deselect();
 
685
                void print(QPainter *, const QRect &rect, const QwtPlotPrintFilter & = QwtPlotPrintFilter());
 
686
                void printCanvas(QPainter *painter, const QRect &canvasRect,
 
687
                         const QwtScaleMap map[QwtPlot::axisCnt], const QwtPlotPrintFilter &pfilter) const;
 
688
 
 
689
signals:
 
690
                void selectedGraph (Graph*);
 
691
                void closedGraph();
 
692
                void drawTextOff();
 
693
                void drawLineEnded(bool);
 
694
                void cursorInfo(const QString&);
 
695
                void showPlotDialog(int);
 
696
                void createTable(const QString&,const QString&,QList<Column*>);
 
697
 
 
698
                void viewImageDialog();
 
699
                void viewTextDialog();
 
700
                void viewLineDialog();
 
701
                void viewTitleDialog();
 
702
                void modifiedGraph();
 
703
                void hiddenPlot(QWidget*);
 
704
 
 
705
                void showLayerButtonContextMenu();
 
706
                void showContextMenu();
 
707
                void showCurveContextMenu(int);
 
708
                void showMarkerPopupMenu();
 
709
 
 
710
                void showAxisDialog(int);
 
711
                void axisDblClicked(int);
 
712
                void xAxisTitleDblClicked();
 
713
                void yAxisTitleDblClicked();
 
714
                void rightAxisTitleDblClicked();
 
715
                void topAxisTitleDblClicked();
 
716
 
 
717
                void createIntensityTable(const QString&);
 
718
                void dataRangeChanged();
 
719
                void showFitResults(const QString&);
 
720
 
 
721
        private:
 
722
                //! List storing pointers to the curves resulting after a fit session, in case the user wants to delete them later on.
 
723
                QList<QwtPlotCurve *>d_fit_curves;
 
724
                //! Render hint for plot items.
 
725
                bool d_antialiasing;
 
726
                bool autoScaleFonts;
 
727
                bool d_scale_on_print, d_print_cropmarks;
 
728
                int selectedAxis;
 
729
                QStringList axesFormulas;
 
730
                //! Stores columns used for axes with text labels or time/date format info
 
731
                QStringList axesFormatInfo;
 
732
                QList <int> axisType;
 
733
                MarkerType selectedMarkerType;
 
734
                QwtPlotMarker::LineStyle mrklStyle;
 
735
 
 
736
                //! Stores the step the user specified for the four scale. If step = 0.0, the step will be calculated automatically by the Qwt scale engine.
 
737
                QVector<double> d_user_step;
 
738
                //! Curve types
 
739
                QVector<int> c_type;
 
740
                //! Curves on plot keys
 
741
                QVector<int> c_keys;
 
742
                //! Arrows/lines on plot keys
 
743
                QVector<int> d_lines;
 
744
                //! Images on plot keys
 
745
                QVector<int> d_images;
 
746
                //! Stores the identifiers (keys) of the text objects on the plot
 
747
                QVector<int> d_texts;
 
748
 
 
749
                QPen mrkLinePen;
 
750
                QFont auxMrkFont, defaultMarkerFont;
 
751
                QColor auxMrkColor, auxMrkBkgColor;
 
752
                QPoint auxMrkStart, auxMrkEnd;
 
753
                Qt::PenStyle auxMrkStyle;
 
754
                QString auxMrkFileName, auxMrkText;
 
755
 
 
756
                int n_curves;
 
757
                int widthLine, defaultMarkerFrame;
 
758
                QColor defaultTextMarkerColor, defaultTextMarkerBackground;
 
759
                int auxMrkAngle,auxMrkBkg,auxMrkWidth;
 
760
                int auxArrowHeadLength, auxArrowHeadAngle;
 
761
                long selectedMarker,legendMarkerID;
 
762
                bool startArrowOn, endArrowOn, drawTextOn, drawLineOn, drawArrowOn;
 
763
 
 
764
                bool auxFilledArrowHead, ignoreResize;
 
765
                bool drawAxesBackbone, m_autoscale;
 
766
 
 
767
                QColor defaultArrowColor;
 
768
                int defaultArrowLineWidth, defaultArrowHeadLength, defaultArrowHeadAngle;
 
769
                bool defaultArrowHeadFill;
 
770
                Qt::PenStyle defaultArrowLineStyle;
 
771
 
 
772
                //! The markers selected for move/resize operations or NULL if none are selected.
 
773
                QPointer<SelectionMoveResizer> d_markers_selector;
 
774
                //! The current curve selection, or NULL if none is active.
 
775
                QPointer<RangeSelectorTool> d_range_selector;
 
776
                //! The currently active tool, or NULL for default (pointer).
 
777
                PlotToolInterface *d_active_tool;
 
778
};
 
779
#endif // GRAPH_H