Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include <qpainter.h>
#include <qpixmap.h>
#include <qbitarray.h>
#include "qwt_global.h"
#include "qwt_legend.h"
#include "qwt_legend_item.h"
#include "qwt_data.h"
#include "qwt_scale_map.h"
#include "qwt_double_rect.h"
#include "qwt_math.h"
#include "qwt_clipper.h"
#include "qwt_painter.h"
#include "qwt_plot.h"
#include "qwt_plot_canvas.h"
#include "qwt_curve_fitter.h"
#include "qwt_symbol.h"
#include "qwt_plot_curve.h"
#define SCALE_PEN 0
#if QT_VERSION < 0x040000
#include <qguardedptr.h>
#else
#include <qpointer.h>
#endif
#if QT_VERSION >= 0x040000
#include <qevent.h>
#include <qpaintengine.h>
class QwtPlotCurvePaintHelper: public QObject
{
public:
QwtPlotCurvePaintHelper(const QwtPlotCurve *curve, int from, int to):
_curve(curve),
_from(from),
_to(to)
{
}
virtual bool eventFilter(QObject *, QEvent *event)
{
if ( event->type() == QEvent::Paint )
{
_curve->draw(_from, _to);
return true;
}
return false;
}
private:
const QwtPlotCurve *_curve;
int _from;
int _to;
};
#endif // QT_VERSION >= 0x040000
// Creating and initializing a QPainter is an
// expensive operation. So we keep an painter
// open for situations, where we paint outside
// of paint events. This improves the performance
// of incremental painting like in the realtime
// example a lot.
// But it is not possible to have more than
// one QPainter open at the same time. So we
// need to close it before regular paint events
// are processed.
class QwtGuardedPainter: public QObject
{
public:
~QwtGuardedPainter()
{
end();
}
QPainter *begin(QwtPlotCanvas *canvas)
{
_canvas = canvas;
QMap<QwtPlotCanvas *, QPainter *>::iterator it = _map.find(_canvas);
if ( it == _map.end() )
{
QPainter *painter = new QPainter(_canvas);
painter->setClipping(true);
painter->setClipRect(_canvas->contentsRect());
it = _map.insert(_canvas, painter);
_canvas->installEventFilter(this);
}
#if QT_VERSION < 0x040000
return it.data();
#else
return it.value();
#endif
}
void end()
{
if ( _canvas )
{
QMap<QwtPlotCanvas *, QPainter *>::iterator it = _map.find(_canvas);
if ( it != _map.end() )
{
_canvas->removeEventFilter(this);
#if QT_VERSION < 0x040000
delete it.data();
#else
delete it.value();
#endif
_map.erase(it);
}
}
}
virtual bool eventFilter(QObject *, QEvent *event)
{
if ( event->type() == QEvent::Paint )
end();
return false;
}
private:
#if QT_VERSION < 0x040000
QGuardedPtr<QwtPlotCanvas> _canvas;
#else
QPointer<QwtPlotCanvas> _canvas;
#endif
static QMap<QwtPlotCanvas *, QPainter *> _map;
};
QMap<QwtPlotCanvas *, QPainter *> QwtGuardedPainter::_map;
static QwtPolygon clipPolygon(QPainter *painter, int attributes,
const QwtPolygon &polygon)
{
bool doClipping = attributes & QwtPlotCurve::ClipPolygons;
QRect clipRect = painter->window();
if ( !doClipping )
{
#if QT_VERSION >= 0x040000
const QPaintEngine *pe = painter->paintEngine();
if ( pe && pe->type() == QPaintEngine::SVG )
#else
if ( painter->device()->devType() == QInternal::Picture )
#endif
{
// The SVG paint engine ignores any clipping,
// so we enable polygon clipping.
doClipping = true;
if ( painter->hasClipping() )
clipRect &= painter->clipRegion().boundingRect();
}
}
if ( doClipping )
return QwtClipper::clipPolygon(clipRect, polygon);
return polygon;
}
static int verifyRange(int size, int &i1, int &i2)
{
if (size < 1)
return 0;
i1 = qwtLim(i1, 0, size-1);
i2 = qwtLim(i2, 0, size-1);
if ( i1 > i2 )
qSwap(i1, i2);
return (i2 - i1 + 1);
}
class QwtPlotCurve::PrivateData
{
public:
class PixelMatrix: private QBitArray
{
public:
PixelMatrix(const QRect& rect):
QBitArray(rect.width() * rect.height()),
_rect(rect)
{
fill(false);
Loading
Loading full blame...