~ubuntu-branches/ubuntu/saucy/goldencheetah/saucy

« back to all changes in this revision

Viewing changes to qwt/examples/cpuplot/cpuplot.cpp

  • Committer: Package Import Robot
  • Author(s): KURASHIKI Satoru
  • Date: 2013-08-18 07:02:45 UTC
  • mfrom: (4.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130818070245-zgdvb47e1k3mtgil
Tags: 3.0-3
debian/control: remove needless dependency. (Closes: #719571)

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#include <qwt_scale_widget.h>
9
9
#include <qwt_legend.h>
10
10
#include <qwt_legend_item.h>
 
11
#include <qwt_plot_canvas.h>
11
12
#include "cpupiemarker.h"
12
13
#include "cpuplot.h"
13
14
 
42
43
 
43
44
    virtual void draw(QPainter *painter,
44
45
        const QwtScaleMap &, const QwtScaleMap &yMap,
45
 
        const QRect &rect) const
 
46
        const QRectF &rect) const
46
47
    {
47
48
        QColor c(Qt::white);
48
 
        QRect r = rect;
 
49
        QRectF r = rect;
49
50
 
50
51
        for ( int i = 100; i > 0; i -= 10 )
51
52
        {
64
65
    CpuCurve(const QString &title):
65
66
        QwtPlotCurve(title)
66
67
    {
67
 
#if QT_VERSION >= 0x040000
68
68
        setRenderHint(QwtPlotItem::RenderAntialiased);
69
 
#endif
70
69
    }
71
70
 
72
71
    void setColor(const QColor &color)
73
72
    {
74
 
#if QT_VERSION >= 0x040000
75
73
        QColor c = color;
76
74
        c.setAlpha(150);
77
75
 
78
76
        setPen(c);
79
77
        setBrush(c);
80
 
#else
81
 
        setPen(color);
82
 
        setBrush(QBrush(color, Qt::Dense4Pattern));
83
 
#endif
84
78
    }
85
79
};
86
80
 
90
84
{
91
85
    setAutoReplot(false);
92
86
 
 
87
    canvas()->setBorderRadius( 10 );
 
88
 
93
89
    plotLayout()->setAlignCanvasToScales(true);
94
90
 
95
91
    QwtLegend *legend = new QwtLegend;
97
93
    insertLegend(legend, QwtPlot::RightLegend);
98
94
 
99
95
    setAxisTitle(QwtPlot::xBottom, " System Uptime [h:m:s]");
100
 
    setAxisScaleDraw(QwtPlot::xBottom, 
 
96
    setAxisScaleDraw(QwtPlot::xBottom,
101
97
        new TimeScaleDraw(cpuStat.upTime()));
102
98
    setAxisScale(QwtPlot::xBottom, 0, HISTORY);
103
99
    setAxisLabelRotation(QwtPlot::xBottom, -50.0);
124
120
 
125
121
    CpuPieMarker *pie = new CpuPieMarker();
126
122
    pie->attach(this);
127
 
    
 
123
 
128
124
    CpuCurve *curve;
129
125
 
130
126
    curve = new CpuCurve("System");
177
173
 
178
174
    cpuStat.statistic(data[User].data[0], data[System].data[0]);
179
175
 
180
 
    data[Total].data[0] = data[User].data[0] + 
 
176
    data[Total].data[0] = data[User].data[0] +
181
177
        data[System].data[0];
182
178
    data[Idle].data[0] = 100.0 - data[Total].data[0];
183
179
 
187
183
    for ( int j = 0; j < HISTORY; j++ )
188
184
        timeData[j]++;
189
185
 
190
 
    setAxisScale(QwtPlot::xBottom, 
 
186
    setAxisScale(QwtPlot::xBottom,
191
187
        timeData[HISTORY - 1], timeData[0]);
192
188
 
193
189
    for ( int c = 0; c < NCpuData; c++ )
194
190
    {
195
 
        data[c].curve->setRawData(
 
191
        data[c].curve->setRawSamples(
196
192
            timeData, data[c].data, dataCount);
197
193
    }
198
194
 
205
201
    QWidget *w = legend()->find(item);
206
202
    if ( w && w->inherits("QwtLegendItem") )
207
203
        ((QwtLegendItem *)w)->setChecked(on);
208
 
    
 
204
 
209
205
    replot();
210
206
}
211
207
 
212
208
int main(int argc, char **argv)
213
209
{
214
 
    QApplication a(argc, argv); 
215
 
    
 
210
    QApplication a(argc, argv);
 
211
 
216
212
    QWidget vBox;
217
 
#if QT_VERSION >= 0x040000
218
213
    vBox.setWindowTitle("Cpu Plot");
219
 
#else
220
 
    vBox.setCaption("Cpu Plot");
221
 
#endif
222
214
 
223
215
    CpuPlot *plot = new CpuPlot(&vBox);
224
216
    plot->setTitle("History");
225
 
    plot->setMargin(5);
 
217
 
 
218
    const int margin = 5;
 
219
    plot->setContentsMargins(margin, margin, margin, margin);
226
220
 
227
221
    QString info("Press the legend to en/disable a curve");
228
222
 
232
226
    layout->addWidget(plot);
233
227
    layout->addWidget(label);
234
228
 
235
 
#if QT_VERSION < 0x040000
236
 
    a.setMainWidget(&vBox);
237
 
#endif
238
 
 
239
229
    vBox.resize(600,400);
240
230
    vBox.show();
241
231
 
242
 
    return a.exec();  
243
 
}   
244
 
 
 
232
    return a.exec();
 
233
}