~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to plugins/chartshape/kdchart/src/KDChartStockDiagram_p.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB.  All rights reserved.
 
3
**
 
4
** This file is part of the KD Chart library.
 
5
**
 
6
** Licensees holding valid commercial KD Chart licenses may use this file in
 
7
** accordance with the KD Chart Commercial License Agreement provided with
 
8
** the Software.
 
9
**
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 and version 3 as published by the
 
13
** Free Software Foundation and appearing in the file LICENSE.GPL included.
 
14
**
 
15
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
16
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
17
**
 
18
** Contact info@kdab.com if any conditions of this licensing are not
 
19
** clear to you.
 
20
**
 
21
**********************************************************************/
 
22
 
 
23
#include "KDChartStockDiagram_p.h"
 
24
 
 
25
using namespace KDChart;
 
26
 
 
27
 
 
28
class StockDiagram::Private::ThreeDPainter
 
29
{
 
30
public:
 
31
    struct ThreeDProperties {
 
32
        qreal depth;
 
33
        qreal angle;
 
34
        bool useShadowColors;
 
35
    };
 
36
 
 
37
    ThreeDPainter( QPainter *p )
 
38
        : painter( p ) {};
 
39
 
 
40
    QPolygonF drawTwoDLine( const QLineF &line, const QPen &pen,
 
41
                            const ThreeDProperties &props );
 
42
    QPolygonF drawThreeDLine( const QLineF &line, const QBrush &brush,
 
43
                              const QPen &pen, const ThreeDProperties &props );
 
44
    QPolygonF drawThreeDRect( const QRectF &rect, const QBrush &brush,
 
45
                              const QPen &pen, const ThreeDProperties &props );
 
46
 
 
47
private:
 
48
    QPointF projectPoint( const QPointF &point, qreal depth, qreal angle ) const;
 
49
    QColor calcShadowColor( const QColor &color, qreal angle ) const;
 
50
 
 
51
    QPainter *painter;
 
52
};
 
53
 
 
54
/**
 
55
 * Projects a point in 3D space
 
56
 *
 
57
 * @param depth The distance from the point and the projected point
 
58
 * @param angle The angle the projected point is rotated by around the original point
 
59
 */
 
60
QPointF StockDiagram::Private::ThreeDPainter::projectPoint( const QPointF &point, qreal depth, qreal angle ) const
 
61
{
 
62
    const qreal angleInRad = DEGTORAD( angle );
 
63
    const qreal distX = depth * cos( angleInRad );
 
64
    // Y coordinates are reversed on our coordinate plane
 
65
    const qreal distY = depth * -sin( angleInRad );
 
66
 
 
67
    return QPointF( point.x() + distX, point.y() + distY );
 
68
}
 
69
 
 
70
/**
 
71
 * Returns the shadow color for a given color, depending on the angle of rotation
 
72
 *
 
73
 * @param color The color to calculate the shadow color for
 
74
 * @param angle The angle that the colored area is rotated by
 
75
 */
 
76
QColor StockDiagram::Private::ThreeDPainter::calcShadowColor( const QColor &color, qreal angle ) const
 
77
{
 
78
    // The shadow factor determines to how many percent the brightness
 
79
    // of the color can be reduced. That is, the darkest shadow color
 
80
    // is color * shadowFactor.
 
81
    const qreal shadowFactor = 0.5;
 
82
    const qreal sinAngle = 1.0 - qAbs( sin( DEGTORAD( angle ) ) ) * shadowFactor;
 
83
    return QColor( qRound( color.red()   * sinAngle ),
 
84
                   qRound( color.green() * sinAngle ),
 
85
                   qRound( color.blue()  * sinAngle ) );
 
86
}
 
87
 
 
88
/**
 
89
 * Draws a 2D line in 3D space by painting it with a z-coordinate of props.depth / 2.0
 
90
 *
 
91
 * @param line The line to draw
 
92
 * @param pen The pen to use to draw the line
 
93
 * @param props The 3D properties to draw the line with
 
94
 * @return The drawn line, but with a width of 2px, as a polygon
 
95
 */
 
96
QPolygonF StockDiagram::Private::ThreeDPainter::drawTwoDLine( const QLineF &line, const QPen &pen,
 
97
                                                              const ThreeDProperties &props )
 
98
{
 
99
    // Restores the painting properties when destroyed
 
100
    PainterSaver painterSaver( painter );
 
101
 
 
102
    // The z coordinate to use (i.e., at what depth to draw the line)
 
103
    const qreal z = props.depth / 2.0;
 
104
 
 
105
    // Projec the 2D points of the line in 3D
 
106
    const QPointF deepP1 = projectPoint( line.p1(), z, props.angle );
 
107
    const QPointF deepP2 = projectPoint( line.p2(), z, props.angle );
 
108
 
 
109
    // The drawn line with a width of 2px
 
110
    QPolygonF threeDArea;
 
111
    // The offset of the line "borders" from the center to each side
 
112
    const QPointF offset( 0.0, 1.0 );
 
113
    threeDArea << deepP1 - offset << deepP2 - offset
 
114
               << deepP1 + offset << deepP2 + offset << deepP1 - offset;
 
115
 
 
116
    painter->setPen( pen );
 
117
    painter->drawLine( QLineF( deepP1, deepP2 ) );
 
118
 
 
119
    return threeDArea;
 
120
}
 
121
 
 
122
/**
 
123
 * Draws an ordinary line in 3D by expanding it in the z-axis by the given depth.
 
124
 *
 
125
 * @param line The line to draw
 
126
 * @param brush The brush to fill the resulting polygon with
 
127
 * @param pen The pen to paint the borders of the resulting polygon with
 
128
 * @param props The 3D properties to draw the line with
 
129
 * @return The 3D shape drawn
 
130
 */
 
131
QPolygonF StockDiagram::Private::ThreeDPainter::drawThreeDLine( const QLineF &line, const QBrush &brush,
 
132
                                                                const QPen &pen, const ThreeDProperties &props )
 
133
{
 
134
    // Restores the painting properties when destroyed
 
135
    PainterSaver painterSaver( painter );
 
136
 
 
137
    const QPointF p1 = line.p1();
 
138
    const QPointF p2 = line.p2();
 
139
 
 
140
    // Project the 2D points of the line in 3D
 
141
    const QPointF deepP1 = projectPoint( p1, props.depth, props.angle );
 
142
    const QPointF deepP2 = projectPoint( p2, props.depth, props.angle );
 
143
 
 
144
    // The result is a 3D representation of the 2D line
 
145
    QPolygonF threeDArea;
 
146
    threeDArea << p1 << p2 << deepP2 << deepP1 << p1;
 
147
 
 
148
    // Use shadow colors if ThreeDProperties::useShadowColors is set
 
149
    // Note: Setting a new color on a brush or pen does not effect gradients or textures
 
150
    if ( props.useShadowColors ) {
 
151
        QBrush shadowBrush( brush );
 
152
        QPen shadowPen( pen );
 
153
        shadowBrush.setColor( calcShadowColor( brush.color(), props.angle ) );
 
154
        shadowPen.setColor( calcShadowColor( pen.color(), props.angle ) );
 
155
        painter->setBrush( shadowBrush );
 
156
        painter->setPen( shadowPen );
 
157
    } else {
 
158
        painter->setBrush( brush );
 
159
        painter->setPen( pen );
 
160
    }
 
161
 
 
162
    painter->drawPolygon( threeDArea );
 
163
 
 
164
    return threeDArea;
 
165
}
 
166
 
 
167
/**
 
168
 * Draws a 3D cuboid by extending a 2D rectangle in the z-axis
 
169
 *
 
170
 * @param rect The rectangle to draw
 
171
 * @param brush The brush fill the surfaces of the cuboid with
 
172
 * @param pen The pen to draw the edges with
 
173
 * @param props The 3D properties to use for drawing the cuboid
 
174
 * @return The drawn cuboid as a polygon
 
175
 */
 
176
QPolygonF StockDiagram::Private::ThreeDPainter::drawThreeDRect( const QRectF &rect, const QBrush &brush,
 
177
                                                                const QPen &pen, const ThreeDProperties &props )
 
178
{
 
179
    // Restores the painting properties when destroyed
 
180
    PainterSaver painterSaver( painter );
 
181
 
 
182
    // Make sure that the top really is the top
 
183
    const QRectF normalizedRect = rect.normalized();
 
184
 
 
185
    // Calculate all the four sides of the rectangle
 
186
    const QLineF topSide = QLineF( normalizedRect.topLeft(), normalizedRect.topRight() );
 
187
    const QLineF bottomSide = QLineF( normalizedRect.bottomLeft(), normalizedRect.bottomRight() );
 
188
    const QLineF leftSide = QLineF( normalizedRect.topLeft(), normalizedRect.bottomLeft() );
 
189
    const QLineF rightSide = QLineF( normalizedRect.topRight(), normalizedRect.bottomRight() );
 
190
 
 
191
    QPolygonF drawnPolygon;
 
192
 
 
193
    // Shorter names are easier on the eyes
 
194
    const qreal angle = props.angle;
 
195
 
 
196
    // Only top and right side is visible
 
197
    if ( angle >= 0.0 && angle < 90.0 ) {
 
198
        drawnPolygon = drawnPolygon.united( drawThreeDLine( topSide, brush, pen, props ) );
 
199
        drawnPolygon = drawnPolygon.united( drawThreeDLine( rightSide, brush, pen, props ) );
 
200
    // Only top and left side is visible
 
201
    } else if ( angle >= 90.0 && angle < 180.0 ) {
 
202
        drawnPolygon = drawnPolygon.united( drawThreeDLine( topSide, brush, pen, props ) );
 
203
        drawnPolygon = drawnPolygon.united( drawThreeDLine( leftSide, brush, pen, props ) );
 
204
    // Only bottom and left side is visible
 
205
    } else if ( angle >= 180.0 && angle < 270.0 ) {
 
206
        drawnPolygon = drawnPolygon.united( drawThreeDLine( bottomSide, brush, pen, props ) );
 
207
        drawnPolygon = drawnPolygon.united( drawThreeDLine( leftSide, brush, pen, props ) );
 
208
    // Only bottom and right side is visible
 
209
    } else if ( angle >= 270.0 && angle <= 360.0 ) {
 
210
        drawnPolygon = drawnPolygon.united( drawThreeDLine( bottomSide, brush, pen, props ) );
 
211
        drawnPolygon = drawnPolygon.united( drawThreeDLine( rightSide, brush, pen, props ) );
 
212
    }
 
213
 
 
214
    // Draw the front side
 
215
    painter->setPen( pen );
 
216
    painter->setBrush( brush );
 
217
    painter->drawRect( normalizedRect );
 
218
 
 
219
    return drawnPolygon;
 
220
}
 
221
 
 
222
 
 
223
StockDiagram::Private::Private()
 
224
    : AbstractCartesianDiagram::Private()
 
225
{
 
226
}
 
227
 
 
228
StockDiagram::Private::Private( const Private& r )
 
229
    : AbstractCartesianDiagram::Private( r )
 
230
{
 
231
}
 
232
 
 
233
StockDiagram::Private::~Private()
 
234
{
 
235
}
 
236
 
 
237
/**
 
238
 * Projects a point onto the coordinate plane
 
239
 *
 
240
 * @param context The context to paint the point in
 
241
 * @point The point to project onto the coordinate plane
 
242
 * @return The projected point
 
243
 */
 
244
QPointF StockDiagram::Private::projectPoint( PaintContext *context, const QPointF &point ) const
 
245
{
 
246
    return context->coordinatePlane()->translate( QPointF( point.x() + 0.5, point.y() ) );
 
247
}
 
248
 
 
249
/**
 
250
 * Projects a candlestick onto the coordinate plane
 
251
 *
 
252
 * @param context The context to paint the candlestick in
 
253
 * @param low The
 
254
 */
 
255
QRectF StockDiagram::Private::projectCandlestick( PaintContext *context, const QPointF &open, const QPointF &close, qreal width ) const
 
256
{
 
257
    const QPointF leftHighPoint = context->coordinatePlane()->translate( QPointF( close.x() + 0.5 - width / 2.0, close.y() ) );
 
258
    const QPointF rightLowPoint = context->coordinatePlane()->translate( QPointF( open.x() + 0.5 + width / 2.0, open.y() ) );
 
259
    const QPointF rightHighPoint = context->coordinatePlane()->translate( QPointF( close.x() + 0.5 + width / 2.0, close.y() ) );
 
260
 
 
261
    return QRectF( leftHighPoint, QSizeF( rightHighPoint.x() - leftHighPoint.x(),
 
262
                                          rightLowPoint.y() - leftHighPoint.y() ) );
 
263
}
 
264
 
 
265
void StockDiagram::Private::drawOHLCBar( const CartesianDiagramDataCompressor::DataPoint &open,
 
266
        const CartesianDiagramDataCompressor::DataPoint &high,
 
267
        const CartesianDiagramDataCompressor::DataPoint &low,
 
268
        const CartesianDiagramDataCompressor::DataPoint &close,
 
269
        PaintContext *context )
 
270
{
 
271
    // Note: A row in the model is a column in a StockDiagram
 
272
    const int col = low.index.row();
 
273
 
 
274
    StockBarAttributes attr = diagram->stockBarAttributes( col );
 
275
    ThreeDBarAttributes threeDAttr = diagram->threeDBarAttributes( col );
 
276
    const qreal tickLength = attr.tickLength();
 
277
 
 
278
    const QPointF leftOpenPoint( open.key + 0.5 - tickLength, open.value );
 
279
    const QPointF rightOpenPoint( open.key + 0.5, open.value );
 
280
    const QPointF highPoint( high.key + 0.5, high.value );
 
281
    const QPointF lowPoint( low.key + 0.5, low.value );
 
282
    const QPointF leftClosePoint( close.key + 0.5, close.value );
 
283
    const QPointF rightClosePoint( close.key + 0.5 + tickLength, close.value );
 
284
 
 
285
    bool reversedOrder = false;
 
286
    // If 3D mode is enabled, we have to make sure the z-order is right
 
287
    if ( threeDAttr.isEnabled() ) {
 
288
        const int angle = threeDAttr.angle();
 
289
        // Z-order is from right to left
 
290
        if ( ( angle >= 0 && angle < 90 ) || ( angle >= 180 && angle < 270 ) )
 
291
            reversedOrder = true;
 
292
        // Z-order is from left to right
 
293
        if ( ( angle >= 90 && angle < 180 ) || ( angle >= 270 && angle < 0 ) )
 
294
            reversedOrder = false;
 
295
    }
 
296
 
 
297
    if ( reversedOrder ) {
 
298
        if ( !open.hidden )
 
299
            drawLine( col, leftOpenPoint, rightOpenPoint, context ); // Open marker
 
300
        if ( !low.hidden && !high.hidden )
 
301
            drawLine( col, lowPoint, highPoint, context ); // Low-High line
 
302
        if ( !close.hidden )
 
303
            drawLine( col, leftClosePoint, rightClosePoint, context ); // Close marker
 
304
    } else {
 
305
        if ( !close.hidden )
 
306
            drawLine( col, leftClosePoint, rightClosePoint, context ); // Close marker
 
307
        if ( !low.hidden && !high.hidden )
 
308
            drawLine( col, lowPoint, highPoint, context ); // Low-High line
 
309
        if ( !open.hidden )
 
310
            drawLine( col, leftOpenPoint, rightOpenPoint, context ); // Open marker
 
311
    }
 
312
 
 
313
    DataValueTextInfoList list;
 
314
    if ( !open.hidden )
 
315
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( open.index ), 0,
 
316
                                       PositionPoints( leftOpenPoint ), Position::South, Position::South, open.value );
 
317
    if ( !high.hidden )
 
318
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( high.index ), 0,
 
319
                                       PositionPoints( highPoint ), Position::South, Position::South, high.value );
 
320
    if ( !low.hidden )
 
321
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( low.index ), 0,
 
322
                                       PositionPoints( lowPoint ), Position::South, Position::South, low.value );
 
323
    if ( !close.hidden )
 
324
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( close.index ), 0,
 
325
                                       PositionPoints( rightClosePoint ), Position::South, Position::South, close.value );
 
326
    paintDataValueTextsAndMarkers( diagram, context, list, false );
 
327
}
 
328
 
 
329
/**
 
330
  * Draws a line connecting the low and the high value of an OHLC chart
 
331
  *
 
332
  * @param low The low data point
 
333
  * @param high The high data point
 
334
  * @param context The context to draw the candlestick in
 
335
  */
 
336
void StockDiagram::Private::drawCandlestick( const CartesianDiagramDataCompressor::DataPoint &open,
 
337
                                             const CartesianDiagramDataCompressor::DataPoint &high,
 
338
                                             const CartesianDiagramDataCompressor::DataPoint &low,
 
339
                                             const CartesianDiagramDataCompressor::DataPoint &close,
 
340
                                             PaintContext *context )
 
341
{
 
342
    PainterSaver painterSaver( context->painter() );
 
343
 
 
344
    // Note: A row in the model is a column in a StockDiagram, and the other way around
 
345
    const int row = low.index.row();
 
346
    const int col = low.index.column();
 
347
 
 
348
    QPointF bottomCandlestickPoint;
 
349
    QPointF topCandlestickPoint;
 
350
    QBrush brush;
 
351
    QPen pen;
 
352
    bool drawLowerLine;
 
353
    bool drawCandlestick = !open.hidden && !close.hidden;
 
354
    bool drawUpperLine;
 
355
 
 
356
    // Find out if we need to paint a down-trend or up-trend candlestick
 
357
    // and set brush and pen accordingly
 
358
    // Also, determine what the top and bottom points of the candlestick are
 
359
    if ( open.value <= close.value ) {
 
360
        pen = diagram->upTrendCandlestickPen( row );
 
361
        brush = diagram->upTrendCandlestickBrush( row );
 
362
        bottomCandlestickPoint = QPointF( open.key, open.value );
 
363
        topCandlestickPoint = QPointF( close.key, close.value );
 
364
        drawLowerLine = !low.hidden && !open.hidden;
 
365
        drawUpperLine = !low.hidden && !close.hidden;
 
366
    } else {
 
367
        pen = diagram->downTrendCandlestickPen( row );
 
368
        brush = diagram->downTrendCandlestickBrush( row );
 
369
        bottomCandlestickPoint = QPointF( close.key, close.value );
 
370
        topCandlestickPoint = QPointF( open.key, open.value );
 
371
        drawLowerLine = !low.hidden && !close.hidden;
 
372
        drawUpperLine = !low.hidden && !open.hidden;
 
373
    }
 
374
 
 
375
    StockBarAttributes attr = diagram->stockBarAttributes( col );
 
376
    ThreeDBarAttributes threeDAttr = diagram->threeDBarAttributes( col );
 
377
 
 
378
    const QPointF lowPoint = projectPoint( context, QPointF( low.key, low.value ) );
 
379
    const QPointF highPoint = projectPoint( context, QPointF( high.key, high.value ) );
 
380
    const QLineF lowerLine = QLineF( lowPoint, projectPoint( context, bottomCandlestickPoint ) );
 
381
    const QLineF upperLine = QLineF( projectPoint( context, topCandlestickPoint ), highPoint );
 
382
 
 
383
    // Convert the data point into coordinates on the coordinate plane
 
384
    QRectF candlestick = projectCandlestick( context, bottomCandlestickPoint,
 
385
                                             topCandlestickPoint, attr.candlestickWidth() );
 
386
 
 
387
    // Remember the drawn polygon to add it to the ReverseMapper later
 
388
    QPolygonF drawnPolygon;
 
389
 
 
390
    // Use the ThreeDPainter class to draw a 3D candlestick
 
391
    if ( threeDAttr.isEnabled() ) {
 
392
        ThreeDPainter threeDPainter( context->painter() );
 
393
 
 
394
        ThreeDPainter::ThreeDProperties threeDProps;
 
395
        threeDProps.depth = threeDAttr.depth();
 
396
        threeDProps.angle = threeDAttr.angle();
 
397
        threeDProps.useShadowColors = threeDAttr.useShadowColors();
 
398
 
 
399
        // If the perspective angle is within [0,180], we paint from bottom to top,
 
400
        // otherwise from top to bottom to ensure the correct z order
 
401
        if ( threeDProps.angle > 0.0 && threeDProps.angle < 180.0 ) {
 
402
            if ( drawLowerLine )
 
403
                drawnPolygon = threeDPainter.drawTwoDLine( lowerLine, pen, threeDProps );
 
404
            if ( drawCandlestick )
 
405
                drawnPolygon = threeDPainter.drawThreeDRect( candlestick, brush, pen, threeDProps );
 
406
            if ( drawUpperLine )
 
407
            drawnPolygon = threeDPainter.drawTwoDLine( upperLine, pen, threeDProps );
 
408
        } else {
 
409
            if ( drawUpperLine )
 
410
                drawnPolygon = threeDPainter.drawTwoDLine( upperLine, pen, threeDProps );
 
411
            if ( drawCandlestick )
 
412
                drawnPolygon = threeDPainter.drawThreeDRect( candlestick, brush, pen, threeDProps );
 
413
            if ( drawLowerLine )
 
414
                drawnPolygon = threeDPainter.drawTwoDLine( lowerLine, pen, threeDProps );
 
415
        }
 
416
    } else {
 
417
        QPainter *const painter = context->painter();
 
418
        painter->setBrush( brush );
 
419
        painter->setPen( pen );
 
420
        if ( drawLowerLine )
 
421
            painter->drawLine( lowerLine );
 
422
        if ( drawUpperLine )
 
423
            painter->drawLine( upperLine );
 
424
        if ( drawCandlestick )
 
425
            painter->drawRect( candlestick );
 
426
 
 
427
        // The 2D representation is the projected candlestick itself
 
428
        drawnPolygon = candlestick;
 
429
 
 
430
        // FIXME: Add lower and upper line to reverse mapper
 
431
    }
 
432
 
 
433
    DataValueTextInfoList list;
 
434
 
 
435
    if ( !low.hidden )
 
436
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( low.index ), 0,
 
437
                                       PositionPoints( lowPoint ), Position::South, Position::South, low.value );
 
438
    if ( drawCandlestick ) {
 
439
        // Both, the open as well as the close value are represented by this candlestick
 
440
        reverseMapper.addPolygon( row, openValueColumn(), drawnPolygon );
 
441
        reverseMapper.addPolygon( row, closeValueColumn(), drawnPolygon );
 
442
 
 
443
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( open.index ), 0,
 
444
                                       PositionPoints( candlestick.bottomRight() ), Position::South, Position::South, open.value );
 
445
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( close.index ), 0,
 
446
                                       PositionPoints( candlestick.topRight() ), Position::South, Position::South, close.value );
 
447
    }
 
448
    if ( !high.hidden )
 
449
        appendDataValueTextInfoToList( diagram, list, diagram->attributesModel()->mapToSource( high.index ), 0,
 
450
                                       PositionPoints( highPoint ), Position::South, Position::South, high.value );
 
451
 
 
452
    paintDataValueTextsAndMarkers( diagram, context, list, false );
 
453
}
 
454
 
 
455
/**
 
456
  * Draws a line connecting two points
 
457
  *
 
458
  * @param col The column of the diagram to paint the line in
 
459
  * @param point1 The first point
 
460
  * @param point2 The second point
 
461
  * @param context The context to draw the low-high line in
 
462
  */
 
463
void StockDiagram::Private::drawLine( int col, const QPointF &point1, const QPointF &point2, PaintContext *context )
 
464
{
 
465
    PainterSaver painterSaver( context->painter() );
 
466
 
 
467
    // A row in the model is a column in the diagram
 
468
    const int modelRow = col;
 
469
    const int modelCol = 0;
 
470
 
 
471
    const QPen pen = diagram->pen( col );
 
472
    const QBrush brush = diagram->brush( col );
 
473
    const ThreeDBarAttributes threeDBarAttr = diagram->threeDBarAttributes( col );
 
474
 
 
475
    QPointF transP1 = context->coordinatePlane()->translate( point1 );
 
476
    QPointF transP2 = context->coordinatePlane()->translate( point2 );
 
477
    QLineF line = QLineF( transP1, transP2 );
 
478
 
 
479
    if ( threeDBarAttr.isEnabled() ) {
 
480
        ThreeDPainter::ThreeDProperties threeDProps;
 
481
        threeDProps.angle = threeDBarAttr.angle();
 
482
        threeDProps.depth = threeDBarAttr.depth();
 
483
        threeDProps.useShadowColors = threeDBarAttr.useShadowColors();
 
484
 
 
485
        ThreeDPainter painter( context->painter() );
 
486
        reverseMapper.addPolygon( modelCol, modelRow, painter.drawThreeDLine( line, brush, pen, threeDProps ) );
 
487
    } else {
 
488
        context->painter()->setPen( pen );
 
489
        //context->painter()->setBrush( brush );
 
490
        reverseMapper.addLine( modelCol, modelRow, transP1, transP2 );
 
491
        context->painter()->drawLine( line );
 
492
    }
 
493
}
 
494
 
 
495
/**
 
496
 * Returns the column of the open value in the model
 
497
 *
 
498
 * @return The column of the open value
 
499
 */
 
500
int StockDiagram::Private::openValueColumn() const
 
501
{
 
502
    // Return an invalid column if diagram has no open values
 
503
    return type == HighLowClose ? -1 : 0;
 
504
}
 
505
 
 
506
/**
 
507
 * Returns the column of the high value in the model
 
508
 *
 
509
 * @return The column of the high value
 
510
 */
 
511
int StockDiagram::Private::highValueColumn() const
 
512
{
 
513
    return type == HighLowClose ? 0 : 1;
 
514
}
 
515
 
 
516
/**
 
517
 * Returns the column of the low value in the model
 
518
 *
 
519
 * @return The column of the low value
 
520
 */
 
521
int StockDiagram::Private::lowValueColumn() const
 
522
{
 
523
    return type == HighLowClose ? 1 : 2;
 
524
}
 
525
 
 
526
/**
 
527
 * Returns the column of the close value in the model
 
528
 *
 
529
 * @return The column of the close value
 
530
 */
 
531
int StockDiagram::Private::closeValueColumn() const
 
532
{
 
533
    return type == HighLowClose ? 2 : 3;
 
534
}
 
535