2 * Copyright (c) 2012-2015, Red Hat.
3 * Copyright (c) 2012, Nathan Scott. All Rights Reserved.
4 * Copyright (c) 2006-2010, Aconex. All Rights Reserved.
5 * Copyright (c) 2006, Ken McDonell. All Rights Reserved.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 #include <QTreeWidget>
25 #include <qwt_plot_curve.h>
26 #include <qwt_plot_picker.h>
27 #include <qwt_plot_canvas.h>
28 #include <qwt_text_label.h>
29 #include <qmc_metric.h>
40 // Centre of the pmchart universe
42 class Chart
: public QwtPlot
, public Gadget
47 Chart(Tab
*, QWidget
*);
60 virtual void resetFont();
61 virtual void setCurrent(bool);
62 virtual QString
scheme() const; // return chart color scheme
63 virtual void setScheme(const QString
&); // set chart color scheme
65 int addItem(pmMetricSpec
*, const QString
&);
66 bool activeItem(int) const;
70 QString
title(void); // return copy of chart title
71 void changeTitle(QString
, bool); // QString::null to clear; expand?
72 QString
hostNameString(bool); // short/long host names as qstring
74 Style
style(void); // return chart style
75 void setStyle(Style
); // set default chart plot style
77 QColor
color(int); // return color for ith plot
78 static QColor
schemeColor(QString
, int *);
79 void setStroke(int, Style
, QColor
); // set chart style and color
80 void setScheme(const QString
&, int); // set chart scheme and position
82 int sequence() // return chart color scheme position
83 { return my
.sequence
; }
84 void setSequence(int sequence
) // set the chart color scheme position
85 { my
.sequence
= sequence
; }
87 QString
label(int); // return legend label for ith plot
88 void setLabel(int, const QString
&); // set plot legend label
91 void scale(bool *, double *, double *);
92 // return autoscale state and fixed scale parameters
93 void setScale(bool, double, double);
94 // set autoscale state and fixed scale parameters
95 QString
YAxisTitle() const;
96 void setYAxisTitle(const char *);
98 void setLegendVisible(bool);
100 void setRateConvert(bool);
102 void setAntiAliasing(bool);
104 virtual void save(FILE *, bool);
105 virtual void print(QPainter
*, QRect
&, bool);
107 virtual void updateValues(bool, bool, int, int, double, double, double);
108 virtual void resetValues(int, double, double);
109 virtual void adjustValues();
111 virtual void preserveSample(int, int);
112 virtual void punchoutSample(int);
114 virtual int metricCount() const;
115 virtual bool activeMetric(int) const;
116 virtual QString
name(int) const;
117 virtual QString
legend(int) const;
118 virtual QmcMetric
*metricPtr(int) const;
119 virtual QString
metricName(int) const;
120 virtual QmcDesc
*metricDesc(int) const;
121 virtual QString
metricInstance(int) const;
122 virtual QmcContext
*metricContext(int) const;
124 virtual QSize
sizeHint() const;
125 virtual QSize
minimumSizeHint() const;
127 void setupTree(QTreeWidget
*);
128 void addToTree(QTreeWidget
*, const QString
&, const QmcContext
*,
129 bool, QColor
, const QString
&);
131 void activateTime(QMouseEvent
*);
132 void reactivateTime(QMouseEvent
*);
133 void deactivateTime(QMouseEvent
*);
136 void timeSelectionActive(Gadget
*, int);
137 void timeSelectionReactive(Gadget
*, int);
138 void timeSelectionInactive(Gadget
*);
144 void activated(bool);
145 void selected(const QPolygon
&);
146 void selected(const QPointF
&);
147 void moved(const QPointF
&);
148 void showItem(const QVariant
&, bool);
151 // changing properties
152 void setStroke(ChartItem
*, Style
, QColor
);
153 void resetTitleFont(void);
155 // handling selection
157 void showPoint(const QPointF
&);
158 void showPoints(const QPolygon
&);
162 QList
<ChartItem
*> items
;
173 friend class TracingEngine
;
174 friend class SamplingEngine
;
178 // Wrapper class that simply allows us to call the mouse event handlers
179 // for the picker class. Helps implement the time axis picker extender.
181 class ChartPicker
: public QwtPlotPicker
184 ChartPicker(QWidget
*canvas
) :
185 QwtPlotPicker(QwtPlot::xBottom
, QwtPlot::yLeft
,
186 QwtPicker::CrossRubberBand
, QwtPicker::AlwaysOff
, canvas
) { }
188 QPoint
transform(const QPointF
&point
) const
189 { return QwtPlotPicker::transform(point
); }
190 QRectF
invTransform(const QRect
&rect
) const
191 { return QwtPlotPicker::invTransform(rect
); }
193 void widgetMousePressEvent(QMouseEvent
*event
)
194 { QwtPlotPicker::widgetMousePressEvent(event
); }
195 void widgetMouseReleaseEvent(QMouseEvent
*event
)
196 { QwtPlotPicker::widgetMouseReleaseEvent(event
); }
197 void widgetMouseMoveEvent(QMouseEvent
*event
)
198 { QwtPlotPicker::widgetMouseMoveEvent(event
); }
202 // Abstraction for differences between event tracing and sampling models
203 // Note that this base class is used for an initially empty chart
209 ChartEngine(Chart
*chart
);
210 virtual ~ChartEngine() {}
212 // test whether a new metric (type and units) would be compatible
213 // with this engine and any metrics already plotted in the chart.
214 virtual bool isCompatible(pmDesc
&) { return true; }
216 // insert a new item (plot curve) into a chart
217 virtual ChartItem
*addItem(QmcMetric
*, pmMetricSpec
*, pmDesc
*, const QString
&)
218 { return NULL
; } // cannot add to an empty engine
220 // indicates movement forward/backward occurred
221 virtual void updateValues(bool, int, int, double, double, double) { }
223 // indicates the Y-axis scale needs updating
224 virtual bool autoScale(void) { return false; }
225 virtual void redoScale(void) { }
226 virtual void setScale(bool, double, double) { }
227 virtual void scale(bool *autoScale
, double *yMin
, double *yMax
)
228 { *autoScale
= false; *yMin
= 0.0; *yMax
= 1.0; }
230 // get/set other attributes of the chart
231 virtual bool rateConvert(void) const { return my
.rateConvert
; }
232 virtual void setRateConvert(bool enabled
) { my
.rateConvert
= enabled
; }
233 virtual bool antiAliasing(void) const { return my
.antiAliasing
; }
234 virtual void setAntiAliasing(bool enabled
) { my
.antiAliasing
= enabled
; }
235 virtual void setStyle(Chart::Style
) { }
237 // prepare for chart replot() being called
238 virtual void replot(void) { }
240 // a selection has been made/changed, handle it
241 virtual void selected(const QPolygon
&) { }
242 virtual void moved(const QPointF
&) { }
252 // Helper dealing with overriding of legend behaviour
254 class ChartCurve
: public QwtPlotCurve
257 ChartCurve(const QString
&title
)
258 : QwtPlotCurve(title
), legendColor(Qt::white
) { }
260 virtual void drawLegendIdentifier(QPainter
*painter
,
261 const QRectF
&rect
) const;
262 void setLegendColor(QColor color
) { legendColor
= color
; }
267 // Container for an individual plot item within a chart,
268 // which is always backed by a single metric.
274 ChartItem(QmcMetric
*, pmMetricSpec
*, pmDesc
*, const QString
&);
275 virtual ~ChartItem(void) { }
277 virtual QwtPlotItem
*item(void) = 0;
278 virtual QwtPlotCurve
*curve(void) = 0;
280 virtual void preserveSample(int, int) = 0;
281 virtual void punchoutSample(int) = 0;
282 virtual void resetValues(int, double, double) = 0;
284 virtual void clearCursor() = 0;
285 virtual bool containsPoint(const QRectF
&, int) = 0;
286 virtual void updateCursor(const QPointF
&, int) = 0;
287 virtual const QString
&cursorInfo() = 0;
289 virtual void setVisible(bool on
) { item()->setVisible(on
); }
290 virtual void setStroke(Chart::Style
, QColor
, bool) = 0;
291 virtual void revive(void) = 0;
292 virtual void remove(void) = 0;
294 QString
name(void) const { return my
.name
; }
295 QString
label(void) const { return my
.label
; } // as displayed, expanded
296 QString
legend(void) const { return my
.legend
; } // no %i/%h/.. expansion
297 QString
metricName(void) const { return my
.metric
->name(); }
298 QString
metricInstance(void) const
299 { return my
.metric
->numInst() > 0 ? my
.metric
->instName(0) : QString::null
; }
300 bool metricHasInstances(void) const { return my
.metric
->hasInstances(); }
301 QmcDesc
*metricDesc(void) const { return (QmcDesc
*)&my
.metric
->desc(); }
302 QmcContext
*metricContext(void) const { return my
.metric
->context(); }
303 QmcMetric
*metricPtr(void) const { return my
.metric
; }
304 QColor
color(void) const { return my
.color
; }
306 void setColor(QColor color
) { my
.color
= color
; }
307 void setLegend(const QString
&legend
); // may include wildcards
310 bool hidden(void) { return my
.hidden
; }
311 void setHidden(bool hidden
) { my
.hidden
= hidden
; }
313 bool removed(void) { return my
.removed
; }
314 void setRemoved(bool removed
) { my
.removed
= removed
; }
319 pmUnits units
; // base units, *not* scaled
323 QString legend
; // may contain wildcards (not expanded)
324 QString label
; // as appears visibly, in plot legend
328 bool hidden
; // true if hidden through legend push button
332 void expandLegendLabel(const QString
&legend
);
333 void clearLegendLabel(void);
335 QString
hostname(void) const;
336 QString
shortHostName(void) const;
337 QString
shortMetricName(void) const;
338 QString
shortInstName(void) const;