1
/****************************************************************************
2
** Copyright (C) 2007 Klarälvdalens Datakonsult AB. All rights reserved.
4
** This file is part of the KD Chart library.
6
** This file may be used under the terms of the GNU General Public
7
** License versions 2.0 or 3.0 as published by the Free Software
8
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
9
** included in the packaging of this file. Alternatively you may (at
10
** your option) use any later version of the GNU General Public
11
** License if such license has been publicly approved by
12
** Klarälvdalens Datakonsult AB (or its successors, if any).
14
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
15
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
16
** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
17
** not expressly granted herein.
19
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22
**********************************************************************/
24
#include "KDChartCartesianGrid.h"
25
#include "KDChartAbstractCartesianDiagram.h"
26
#include "KDChartPaintContext.h"
27
#include "KDChartPainterSaver_p.h"
28
#include "KDChartPrintingParameters.h"
32
#include <KDABLibFakes>
36
using namespace KDChart;
39
void CartesianGrid::drawGrid( PaintContext* context )
41
//qDebug() << "KDChart::CartesianGrid::drawGrid( PaintContext* context ) called";
43
CartesianCoordinatePlane* plane = dynamic_cast<CartesianCoordinatePlane*>(context->coordinatePlane());
45
// This plane is used for tranlating the coordinates - not for the data boundaries
46
PainterSaver p( context->painter() );
47
plane = dynamic_cast< CartesianCoordinatePlane* >( plane->sharedAxisMasterPlane( context->painter() ) );
49
Q_ASSERT_X ( plane, "CartesianGrid::drawGrid",
50
"Bad function call: PaintContext::coodinatePlane() NOT a cartesian plane." );
53
const GridAttributes gridAttrsX( plane->gridAttributes( Qt::Horizontal ) );
54
const GridAttributes gridAttrsY( plane->gridAttributes( Qt::Vertical ) );
57
if ( !gridAttrsX.isGridVisible() && !gridAttrsY.isGridVisible() ) return;
60
// important: Need to update the calculated mData,
61
// before we may use it!
62
updateData( context->coordinatePlane() );
64
if( plane->axesCalcModeX() == KDChart::AbstractCoordinatePlane::Logarithmic && mData.first().stepWidth == 0.0 )
65
mData.first().stepWidth = 1.0;
66
if( plane->axesCalcModeY() == KDChart::AbstractCoordinatePlane::Logarithmic && mData.last().stepWidth == 0.0 )
67
mData.last().stepWidth = 1.0;
69
// test for programming errors: critical
70
Q_ASSERT_X ( mData.count() == 2, "CartesianGrid::drawGrid",
71
"Error: updateData did not return exactly two dimensions." );
73
// test for invalid boundaries: non-critical
74
if( !isBoundariesValid( mData ) ) return;
77
DataDimension dimX = mData.first();
78
const DataDimension& dimY = mData.last();
79
// test for other programming errors: critical
80
Q_ASSERT_X ( dimX.stepWidth, "CartesianGrid::drawGrid",
81
"Error: updateData returned a Zero step width for the X grid." );
82
Q_ASSERT_X ( dimY.stepWidth, "CartesianGrid::drawGrid",
83
"Error: updateData returned a Zero step width for the Y grid." );
86
qreal numberOfUnitLinesX =
87
qAbs( dimX.distance() / dimX.stepWidth )
88
+ (dimX.isCalculated ? 1.0 : 0.0);
89
qreal numberOfUnitLinesY =
90
qAbs( dimY.distance() / dimY.stepWidth )
91
+ (dimY.isCalculated ? 1.0 : 0.0);
92
//qDebug("numberOfUnitLinesX: %f numberOfUnitLinesY: %f",numberOfUnitLinesX,numberOfUnitLinesY);
94
// do not draw a Zero size grid (and do not divide by Zero)
95
if( numberOfUnitLinesX <= 0.0 || numberOfUnitLinesY <= 0.0 ) return;
98
const QPointF p1 = plane->translate( QPointF(dimX.start, dimY.start) );
99
const QPointF p2 = plane->translate( QPointF(dimX.end, dimY.end) );
100
//qDebug() << "dimX.isCalculated:" << dimX.isCalculated << "dimY.isCalculated:" << dimY.isCalculated;
101
//qDebug() << "dimX.start: " << dimX.start << "dimX.end: " << dimX.end;
102
//qDebug() << "dimY.start: " << dimY.start << "dimY.end: " << dimY.end;
103
//qDebug() << "p1:" << p1 << " p2:" << p2;
105
const qreal screenRangeX = qAbs ( p1.x() - p2.x() );
106
const qreal screenRangeY = qAbs ( p1.y() - p2.y() );
109
* let us paint the grid at a smaller resolution
110
* the user can disable at any time
111
* by setting the grid attribute to false
112
* Same Value as for Cartesian Axis
114
static const qreal GridLineDistanceTreshold = 4.0; // <Treshold> pixels between each grid line
115
const qreal MinimumPixelsBetweenLines =
116
GridLineDistanceTreshold;
117
//qDebug() << "x step " << dimX.stepWidth << " y step " << dimY.stepWidth;
119
//qreal unitFactorX = 1.0;
120
// qreal unitFactorY = 1.0;
122
//FIXME(khz): Remove this code, and do the calculation in the grid calc function
123
if( ! dimX.isCalculated ){
125
while( screenRangeX / numberOfUnitLinesX <= MinimumPixelsBetweenLines ){
126
dimX.stepWidth *= 10.0;
127
dimX.subStepWidth *= 10.0;
128
numberOfUnitLinesX = qAbs( dimX.distance() / dimX.stepWidth );
131
if( dimX.subStepWidth && (screenRangeX / (dimX.distance() / dimX.subStepWidth) <= MinimumPixelsBetweenLines) ){
132
dimX.subStepWidth = 0.0;
133
//qDebug() << "de-activating grid sub steps: not enough space";
136
const bool drawUnitLinesX = gridAttrsX.isGridVisible() &&
137
(screenRangeX / numberOfUnitLinesX > MinimumPixelsBetweenLines);
138
const bool drawUnitLinesY = gridAttrsY.isGridVisible() &&
139
(screenRangeY / numberOfUnitLinesY > MinimumPixelsBetweenLines);
141
const bool isLogarithmicX = dimX.isCalculated && (dimX.calcMode == AbstractCoordinatePlane::Logarithmic );
142
const bool isLogarithmicY = (dimY.calcMode == AbstractCoordinatePlane::Logarithmic );
144
while ( !drawUnitLinesX ) {
146
drawUnitLinesX = screenRangeX / (numberOfUnitLinesX / unitFactorX) > MinimumPixelsBetweenLines;
148
while ( !drawUnitLinesY ) {
150
drawUnitLinesY = screenRangeY / (numberOfUnitLinesY / unitFactorY) > MinimumPixelsBetweenLines;
154
const bool drawSubGridLinesX = isLogarithmicX ||
155
((dimX.subStepWidth != 0.0) &&
156
(screenRangeX / (numberOfUnitLinesX / dimX.stepWidth * dimX.subStepWidth) > MinimumPixelsBetweenLines) &&
157
gridAttrsX.isSubGridVisible());
159
const bool drawSubGridLinesY = isLogarithmicY ||
160
((dimY.subStepWidth != 0.0) &&
161
(screenRangeY / (numberOfUnitLinesY / dimY.stepWidth * dimY.subStepWidth) > MinimumPixelsBetweenLines) &&
162
gridAttrsY.isSubGridVisible());
164
qreal minValueX = qMin( dimX.start, dimX.end );
165
qreal maxValueX = qMax( dimX.start, dimX.end );
166
qreal minValueY = qMin( dimY.start, dimY.end );
167
qreal maxValueY = qMax( dimY.start, dimY.end );
168
AbstractGrid::adjustLowerUpperRange( minValueX, maxValueX, dimX.stepWidth, true, true );
169
AbstractGrid::adjustLowerUpperRange( minValueY, maxValueY, dimY.stepWidth, true, true );
171
if ( drawSubGridLinesX ) {
172
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsX.subGridPen() ) );
174
qreal fLogSubstep = minValueX;
177
while ( f <= maxValueX ) {
178
QPointF topPoint( f, maxValueY );
179
QPointF bottomPoint( f, minValueY );
180
topPoint = plane->translate( topPoint );
181
bottomPoint = plane->translate( bottomPoint );
182
context->painter()->drawLine( topPoint, bottomPoint );
183
if ( isLogarithmicX ){
184
if( logSubstep == 9 ){
185
fLogSubstep *= ( fLogSubstep > 0.0 ) ? 10.0 : 0.1;
186
if( fLogSubstep == 0.0 )
187
fLogSubstep = pow( 10.0, floor( log10( dimX.start ) ) );
198
f += dimX.subStepWidth;
203
if ( drawSubGridLinesY ) {
204
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsY.subGridPen() ) );
206
qreal fLogSubstep = minValueY;
209
while ( f <= maxValueY ) {
210
//qDebug() << "sub grid line Y at" << f;
211
QPointF leftPoint( minValueX, f );
212
QPointF rightPoint( maxValueX, f );
213
leftPoint = plane->translate( leftPoint );
214
rightPoint = plane->translate( rightPoint );
215
context->painter()->drawLine( leftPoint, rightPoint );
216
if ( isLogarithmicY ){
217
if( logSubstep == 9 ){
218
fLogSubstep *= ( fLogSubstep > 0.0 ) ? 10.0 : 0.1;
219
if( fLogSubstep == 0.0 )
220
fLogSubstep = pow( 10.0, floor( log10( dimY.start ) ) );
231
f += dimY.subStepWidth;
236
const bool drawXZeroLineX
237
= dimX.isCalculated &&
238
gridAttrsX.zeroLinePen().style() != Qt::NoPen;
240
const bool drawZeroLineY
241
= gridAttrsY.zeroLinePen().style() != Qt::NoPen;
243
if ( drawUnitLinesX || drawXZeroLineX ) {
245
if ( drawUnitLinesX )
246
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsX.gridPen() ) );
247
// const qreal minX = dimX.start;
251
while ( f <= maxValueX ) {
252
// PENDING(khz) FIXME: make draving/not drawing of Zero line more sophisticated?:
253
const bool zeroLineHere = drawXZeroLineX && (f == 0.0);
254
if ( drawUnitLinesX || zeroLineHere ){
255
//qDebug("main grid line X at: %f --------------------------",f);
256
QPointF topPoint( f, maxValueY );
257
QPointF bottomPoint( f, minValueY );
258
topPoint = plane->translate( topPoint );
259
bottomPoint = plane->translate( bottomPoint );
261
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsX.zeroLinePen() ) );
262
context->painter()->drawLine( topPoint, bottomPoint );
264
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsX.gridPen() ) );
266
if ( isLogarithmicX ) {
267
f *= ( f > 0.0 ) ? 10.0 : 0.1;
269
f = pow( 10.0, floor( log10( dimX.start ) ) );
274
// draw the last line if not logarithmic calculation
275
// we need the in order to get the right grid line painted
276
// when f + dimX.stepWidth jump over maxValueX
277
if ( ! isLogarithmicX )
278
context->painter()->drawLine( plane->translate( QPointF( maxValueX, maxValueY ) ),
279
plane->translate( QPointF( maxValueX, minValueY ) ) );
282
if ( drawUnitLinesY || drawZeroLineY ) {
284
if ( drawUnitLinesY )
285
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsY.gridPen() ) );
286
//const qreal minY = dimY.start;
287
//qDebug("minY: %f maxValueY: %f dimY.stepWidth: %f",minY,maxValueY,dimY.stepWidth);
290
while ( f <= maxValueY ) {
291
// PENDING(khz) FIXME: make draving/not drawing of Zero line more sophisticated?:
292
//qDebug("main grid line Y at: %f",f);
293
const bool zeroLineHere = (f == 0.0);
294
if ( drawUnitLinesY || zeroLineHere ){
295
QPointF leftPoint( minValueX, f );
296
QPointF rightPoint( maxValueX, f );
297
leftPoint = plane->translate( leftPoint );
298
rightPoint = plane->translate( rightPoint );
300
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsY.zeroLinePen() ) );
301
context->painter()->drawLine( leftPoint, rightPoint );
303
context->painter()->setPen( PrintingParameters::scalePen( gridAttrsY.gridPen() ) );
305
if ( isLogarithmicY ) {
306
f *= ( f > 0.0 ) ? 10.0 : 0.1;
308
f = pow( 10.0, floor( log10( dimY.start ) ) );
318
DataDimensionsList CartesianGrid::calculateGrid(
319
const DataDimensionsList& rawDataDimensions ) const
321
Q_ASSERT_X ( rawDataDimensions.count() == 2, "CartesianGrid::calculateGrid",
322
"Error: calculateGrid() expects a list with exactly two entries." );
324
CartesianCoordinatePlane* plane = dynamic_cast<CartesianCoordinatePlane*>( mPlane );
325
Q_ASSERT_X ( plane, "CartesianGrid::calculateGrid",
326
"Error: PaintContext::calculatePlane() called, but no cartesian plane set." );
328
DataDimensionsList l( rawDataDimensions );
329
// rule: Returned list is either empty, or it is providing two
330
// valid dimensions, complete with two non-Zero step widths.
331
if( isBoundariesValid( l ) ) {
332
const QPointF translatedBottomLeft( plane->translateBack( plane->geometry().bottomLeft() ) );
333
const QPointF translatedTopRight( plane->translateBack( plane->geometry().topRight() ) );
334
//qDebug() << "CartesianGrid::calculateGrid() first:" << l.first().start << l.first().end << " last:" << l.last().start << l.last().end;
335
//qDebug() << "CartesianGrid::calculateGrid() translated x:" << translatedBottomLeft.x() << translatedTopRight.x() << " y:" << translatedBottomLeft.y() << translatedTopRight.y();
336
//qDebug() << "CartesianGrid::calculateGrid() raw data y-range :" << l.last().end - l.last().start;
337
//qDebug() << "CartesianGrid::calculateGrid() translated y-range:" << translatedTopRight.y() - translatedBottomLeft.y();
339
/* Code is obsolete. The dataset dimension of the diagram should *never* be > 1.
340
if( l.first().isCalculated
341
&& plane->autoAdjustGridToZoom()
342
&& plane->axesCalcModeX() == CartesianCoordinatePlane::Linear
343
&& plane->zoomFactorX() > 1.0 )
345
l.first().start = translatedBottomLeft.x();
346
l.first().end = translatedTopRight.x();
350
const GridAttributes gridAttrsX( plane->gridAttributes( Qt::Horizontal ) );
351
const GridAttributes gridAttrsY( plane->gridAttributes( Qt::Vertical ) );
353
const DataDimension dimX
354
= calculateGridXY( l.first(), Qt::Horizontal,
355
gridAttrsX.adjustLowerBoundToGrid(),
356
gridAttrsX.adjustUpperBoundToGrid() );
357
if( dimX.stepWidth ){
358
//qDebug("CartesianGrid::calculateGrid() l.last().start: %f l.last().end: %f", l.last().start, l.last().end);
359
//qDebug(" l.first().start: %f l.first().end: %f", l.first().start, l.first().end);
361
// one time for the min/max value
362
const DataDimension minMaxY
363
= calculateGridXY( l.last(), Qt::Vertical,
364
gridAttrsY.adjustLowerBoundToGrid(),
365
gridAttrsY.adjustUpperBoundToGrid() );
367
if( plane->autoAdjustGridToZoom()
368
&& plane->axesCalcModeY() == CartesianCoordinatePlane::Linear
369
&& plane->zoomFactorY() > 1.0 )
371
l.last().start = translatedBottomLeft.y();
372
l.last().end = translatedTopRight.y();
374
// and one other time for the step width
375
const DataDimension dimY
376
= calculateGridXY( l.last(), Qt::Vertical,
377
gridAttrsY.adjustLowerBoundToGrid(),
378
gridAttrsY.adjustUpperBoundToGrid() );
379
if( dimY.stepWidth ){
380
l.first().start = dimX.start;
381
l.first().end = dimX.end;
382
l.first().stepWidth = dimX.stepWidth;
383
l.first().subStepWidth = dimX.subStepWidth;
384
l.last().start = minMaxY.start;
385
l.last().end = minMaxY.end;
386
l.last().stepWidth = dimY.stepWidth;
387
l.last().subStepWidth = dimY.subStepWidth;
388
//qDebug() << "CartesianGrid::calculateGrid() final grid y-range:" << l.last().end - l.last().start << " step width:" << l.last().stepWidth << endl;
389
// calculate some reasonable subSteps if the
390
// user did not set the sub grid but did set
394
// the last (y) dimension is not always the dimension for the ordinate!
395
// since there's no way to check for the orientation of this dimension here,
396
// we cannot automatically assume substep values
397
//if ( dimY.subStepWidth == 0 )
398
// l.last().subStepWidth = dimY.stepWidth/2;
400
// l.last().subStepWidth = dimY.subStepWidth;
404
//qDebug() << "CartesianGrid::calculateGrid() final grid Y-range:" << l.last().end - l.last().start << " substep width:" << l.last().subStepWidth;
405
//qDebug() << "CartesianGrid::calculateGrid() final grid X-range:" << l.first().end - l.first().start << " substep width:" << l.first().subStepWidth;
411
qreal fastPow10( int x )
415
for( int i = 1; i <= x; ++i )
418
for( int i = -1; i >= x; --i )
424
#if defined ( Q_WS_WIN)
425
#define trunc(x) ((int)(x))
428
DataDimension CartesianGrid::calculateGridXY(
429
const DataDimension& rawDataDimension,
430
Qt::Orientation orientation,
431
bool adjustLower, bool adjustUpper ) const
433
CartesianCoordinatePlane* const plane = dynamic_cast<CartesianCoordinatePlane*>( mPlane );
434
if( ((orientation == Qt::Vertical) && (plane->autoAdjustVerticalRangeToData() >= 100))
435
|| ((orientation == Qt::Horizontal) && (plane->autoAdjustHorizontalRangeToData() >= 100)) )
441
DataDimension dim( rawDataDimension );
442
if( dim.isCalculated && dim.start != dim.end ){
443
if( dim.calcMode == AbstractCoordinatePlane::Linear ){
444
// linear ( == not-logarithmic) calculation
445
if( dim.stepWidth == 0.0 ){
446
QList<qreal> granularities;
447
switch( dim.sequence ){
448
case KDChartEnums::GranularitySequence_10_20:
449
granularities << 1.0 << 2.0;
451
case KDChartEnums::GranularitySequence_10_50:
452
granularities << 1.0 << 5.0;
454
case KDChartEnums::GranularitySequence_25_50:
455
granularities << 2.5 << 5.0;
457
case KDChartEnums::GranularitySequence_125_25:
458
granularities << 1.25 << 2.5;
460
case KDChartEnums::GranularitySequenceIrregular:
461
granularities << 1.0 << 1.25 << 2.0 << 2.5 << 5.0;
466
//qDebug("CartesianGrid::calculateGridXY() dim.start: %f dim.end: %f", dim.start, dim.end);
468
dim.start, dim.end, granularities, orientation,
469
dim.stepWidth, dim.subStepWidth,
470
adjustLower, adjustUpper );
472
// if needed, adjust start/end to match the step width:
473
//qDebug() << "CartesianGrid::calculateGridXY() has 1st linear range: min " << dim.start << " and max" << dim.end;
475
AbstractGrid::adjustLowerUpperRange( dim.start, dim.end, dim.stepWidth,
476
adjustLower, adjustUpper );
477
//qDebug() << "CartesianGrid::calculateGridXY() returns linear range: min " << dim.start << " and max" << dim.end;
479
// logarithmic calculation with negative values
483
const qreal minRaw = qMin( dim.start, dim.end );
484
const int minLog = -static_cast<int>(trunc( log10( -minRaw ) ) );
486
min = qMin( minRaw, -std::numeric_limits< qreal >::epsilon() );
488
min = -fastPow10( -(minLog-1) );
491
const qreal maxRaw = qMin( -std::numeric_limits< qreal >::epsilon(), qMax( dim.start, dim.end ) );
492
const int maxLog = -static_cast<int>(ceil( log10( -maxRaw ) ) );
495
else if( fastPow10( -maxLog ) < maxRaw )
496
max = -fastPow10( -(maxLog+1) );
498
max = -fastPow10( -maxLog );
503
dim.stepWidth = -pow( 10.0, ceil( log10( qAbs( max - min ) / 10.0 ) ) );
505
// logarithmic calculation (ignoring all negative values)
509
const qreal minRaw = qMax( qMin( dim.start, dim.end ), qreal( 0.0 ) );
510
const int minLog = static_cast<int>(trunc( log10( minRaw ) ) );
511
if( minLog <= 0 && dim.end < 1.0 )
512
min = qMax( minRaw, std::numeric_limits< qreal >::epsilon() );
513
else if( minLog <= 0 )
514
min = qMax( qreal(0.00001), dim.start );
516
min = fastPow10( minLog-1 );
518
// Uh oh. Logarithmic scaling doesn't work with a lower or upper
520
const bool zeroBound = dim.start == 0.0 || dim.end == 0.0;
523
const qreal maxRaw = qMax( qMax( dim.start, dim.end ), qreal( 0.0 ) );
524
const int maxLog = static_cast<int>(ceil( log10( maxRaw ) ) );
527
else if( fastPow10( maxLog ) < maxRaw )
528
max = fastPow10( maxLog+1 );
530
max = fastPow10( maxLog );
531
if( adjustLower || zeroBound )
533
if( adjustUpper || zeroBound )
535
dim.stepWidth = pow( 10.0, ceil( log10( qAbs( max - min ) / 10.0 ) ) );
539
//qDebug() << "CartesianGrid::calculateGridXY() returns stepWidth 1.0 !!";
540
// Do not ignore the user configuration
541
dim.stepWidth = dim.stepWidth ? dim.stepWidth : 1.0;
547
static void calculateSteps(
548
qreal start_, qreal end_, const QList<qreal>& list,
549
int minSteps, int maxSteps,
551
qreal& steps, qreal& stepWidth,
552
bool adjustLower, bool adjustUpper )
554
//qDebug("-----------------------------------\nstart: %f end: %f power-of-ten: %i", start_, end_, power);
559
const int lastIdx = list.count()-1;
560
for( int i = 0; i <= lastIdx; ++i ){
561
const qreal testStepWidth = list.at(lastIdx - i) * fastPow10( power );
562
//qDebug( "testing step width: %f", testStepWidth);
563
qreal start = qMin( start_, end_ );
564
qreal end = qMax( start_, end_ );
565
//qDebug("pre adjusting start: %f end: %f", start, end);
566
AbstractGrid::adjustLowerUpperRange( start, end, testStepWidth, adjustLower, adjustUpper );
567
//qDebug("post adjusting start: %f end: %f", start, end);
569
const qreal testDistance = qAbs(end - start);
570
const qreal testSteps = testDistance / testStepWidth;
572
//qDebug() << "testDistance:" << testDistance << " distance:" << distance;
573
if( (minSteps <= testSteps) && (testSteps <= maxSteps)
574
&& ( (steps == 0.0) || (testDistance <= distance) ) ){
576
stepWidth = testStepWidth;
577
distance = testDistance;
578
//qDebug( "start: %f end: %f step width: %f steps: %f distance: %f", start, end, stepWidth, steps, distance);
584
void CartesianGrid::calculateStepWidth(
585
qreal start_, qreal end_,
586
const QList<qreal>& granularities,
587
Qt::Orientation orientation,
588
qreal& stepWidth, qreal& subStepWidth,
589
bool adjustLower, bool adjustUpper ) const
591
Q_UNUSED( orientation );
593
Q_ASSERT_X ( granularities.count(), "CartesianGrid::calculateStepWidth",
594
"Error: The list of GranularitySequence values is empty." );
595
QList<qreal> list( granularities );
598
const qreal start = qMin( start_, end_);
599
const qreal end = qMax( start_, end_);
600
const qreal distance = end - start;
601
//qDebug( "raw data start: %f end: %f", start, end);
603
//FIXME(khz): make minSteps and maxSteps configurable by the user.
604
const int minSteps = 2;
605
const int maxSteps = 12;
609
while( list.last() * fastPow10( power ) < distance ){
612
// We have the sequence *two* times in the calculation test list,
613
// so we will be sure to find the best match:
614
const int count = list.count();
615
QList<qreal> testList;
617
for( int dec = -1; dec == -1 || fastPow10( dec + 1 ) >= distance; --dec )
618
for( int i = 0; i < count; ++i )
619
testList << list.at(i) * fastPow10( dec );
624
//qDebug() << "list:" << testList;
625
//qDebug( "calculating steps: power: %i", power);
626
calculateSteps( start, end, testList, minSteps, maxSteps, power,
628
adjustLower, adjustUpper );
630
}while( steps == 0.0 );
632
//qDebug( "steps calculated: stepWidth: %f steps: %f", stepWidth, steps);
634
// find the matching sub-grid line width in case it is
635
// not set by the user
637
if ( subStepWidth == 0.0 ) {
638
if( stepWidth == list.first() * fastPow10( power ) ){
639
subStepWidth = list.last() * fastPow10( power-1 );
641
}else if( stepWidth == list.first() * fastPow10( power-1 ) ){
642
subStepWidth = list.last() * fastPow10( power-2 );
645
qreal smallerStepWidth = list.first();
646
for( int i = 1; i < list.count(); ++i ){
647
if( stepWidth == list.at( i ) * fastPow10( power ) ){
648
subStepWidth = smallerStepWidth * fastPow10( power );
651
if( stepWidth == list.at( i ) * fastPow10( power-1 ) ){
652
subStepWidth = smallerStepWidth * fastPow10( power-1 );
655
smallerStepWidth = list.at( i );
661
//qDebug("CartesianGrid::calculateStepWidth() found stepWidth %f (%f steps) and sub-stepWidth %f", stepWidth, steps, subStepWidth);