##// END OF EJS Templates
Add missing include for QObject...
Add missing include for QObject Missing include cased build errors on android. Change-Id: I974cce869b41972e0992fe212672d6128521fe06 Reviewed-by: Titta Heikkala <titta.heikkala@theqtcompany.com>

File last commit:

r2712:c544258484ff
r2731:450ab64fa5cd
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 /****************************************************************************
**
Titta Heikkala
Update copyright year...
r2688 ** Copyright (C) 2014 Digia Plc
Mika Salmela
A new box-and-whiskers series type added to charts....
r2548 ** 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 }