##// END OF EJS Templates
Fix warning about uninitialized variable...
Fix warning about uninitialized variable Change-Id: Ie4bb39b548622e002258e3e82142f128224332f6 Reviewed-by: Mika Salmela <mika.salmela@digia.com>

File last commit:

r2574:599370d0561c
r2580:a20cc56483ba
Show More
boxdatareader.cpp
79 lines | 2.2 KiB | text/x-c | CppLexer
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 /****************************************************************************
**
** Copyright (C) 2013 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
Miikka Heikkinen
Qt Commercial -> Qt Enterprise...
r2574 ** This file is part of the Qt Enterprise Charts Add-on.
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 **
** $QT_BEGIN_LICENSE$
Miikka Heikkinen
Qt Commercial -> Qt Enterprise...
r2574 ** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 ** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
#include "boxdatareader.h"
BoxDataReader::BoxDataReader(QIODevice *device) :
QTextStream(device)
{
}
Mika Salmela
Example finalization and documentation...
r2556 void BoxDataReader::readFile(QIODevice *device)
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 {
Mika Salmela
Example finalization and documentation...
r2556 QTextStream::setDevice(device);
}
QBoxSet *BoxDataReader::readBox()
{
//! [1]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 QString line = readLine();
if (line.startsWith("#"))
return 0;
Mika Salmela
Example finalization and documentation...
r2556 //! [1]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548
Mika Salmela
Example finalization and documentation...
r2556 //! [2]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 QStringList strList = line.split(" ", QString::SkipEmptyParts);
Mika Salmela
Example finalization and documentation...
r2556 //! [2]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548
Mika Salmela
Example finalization and documentation...
r2556 //! [3]
sortedList.clear();
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 for (int i = 1; i < strList.count(); i++)
sortedList.append(strList.at(i).toDouble());
qSort(sortedList.begin(), sortedList.end());
Mika Salmela
Example finalization and documentation...
r2556 //! [3]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548
int count = sortedList.count();
Mika Salmela
Example finalization and documentation...
r2556 //! [4]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 QBoxSet *box = new QBoxSet(strList.first());
box->setValue(QBoxSet::LowerExtreme, sortedList.first());
box->setValue(QBoxSet::UpperExtreme, sortedList.last());
box->setValue(QBoxSet::Median, findMedian(0, count));
box->setValue(QBoxSet::LowerQuartile, findMedian(0, count / 2));
Mika Salmela
Example finalization and documentation...
r2556 box->setValue(QBoxSet::UpperQuartile, findMedian(count / 2 + (count % 2), count));
//! [4]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548
return box;
}
qreal BoxDataReader::findMedian(int begin, int end)
{
Mika Salmela
Example finalization and documentation...
r2556 //! [5]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 int count = end - begin;
Mika Salmela
Example finalization and documentation...
r2556 if (count % 2) {
return sortedList.at(count / 2 + begin);
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 } else {
qreal right = sortedList.at(count / 2 + begin);
qreal left = sortedList.at(count / 2 - 1 + begin);
return (right + left) / 2.0;
}
Mika Salmela
Example finalization and documentation...
r2556 //! [5]
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 }