##// END OF EJS Templates
Refactors internals...
Refactors internals * rewrite axisUpdated signal handling * create handlers for each property of axis * decouple chartdataset, presenter, theme * adds theme manager * adds axis add/remove/attach/detach handling * refactors createGraphics * add initializers (graphics,domain,theme,animations) * refactor the way the charts are constructed (decouple form presenter) * fix initialization issues with qchart * refactor domain logic to handle also geometry size for charts * delegate xyseries geometry calculation to domian * fix lazy initialization of animations * remove hadnleGeomoetryChanged * add shared pointers to handle reference count for domain * moves nice number algorithm to domain * adds applyNiceNumbers(), depreciate setNiceNumbers * refactor multiple charts handling * domain is shared object * each domain can have multiple axis for controlling * multiple charts share now the same domain

File last commit:

r2273:1c49aa901cb2
r2273:1c49aa901cb2
Show More
domain.cpp
296 lines | 7.1 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** 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$
**
****************************************************************************/
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "domain_p.h"
Michal Klocek
Refactors Domain and Axis...
r1698 #include "qabstractaxis_p.h"
Michal Klocek
Refactors internals...
r2273 #include <qmath.h>
Michal Klocek
Refactors qchart , adds line animation...
r131
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
more coding style fixes for src-folder...
r2104 Domain::Domain(QObject *parent)
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 : QObject(parent),
m_minX(0),
m_maxX(0),
m_minY(0),
Michal Klocek
Refactors internals...
r2273 m_maxY(0),
m_axisSignalsBlocked(false)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
}
Domain::~Domain()
{
}
Michal Klocek
Refactors internals...
r2273 void Domain::setSize(const QSizeF& size)
{
if(m_size!=size)
{
m_size=size;
emit updated();
}
}
QSizeF Domain::size() const
{
return m_size;
}
Michal Klocek
Refactor domain model...
r439 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
Michal Klocek
Adds loosenumber algorithm...
r678 {
Michal Klocek
Refactor axis hadnling...
r1078 bool axisXChanged = false;
bool axisYChanged = false;
Michal Klocek
Refactor domain model...
r439
Marek Rosa
Replaced qFuzzyIsNull with qFuzzyCompare. Once qchart test case still uses qFuzzyIsNull becasue it started failing when qFuzzyCompare was used
r2242 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_minX = minX;
m_maxX = maxX;
axisXChanged = true;
Michal Klocek
Refactors internals...
r2273 emit rangeHorizontalChanged(m_minX, m_maxX);
Michal Klocek
Adds loosenumber algorithm...
r678 }
Marek Rosa
Replaced qFuzzyIsNull with qFuzzyCompare. Once qchart test case still uses qFuzzyIsNull becasue it started failing when qFuzzyCompare was used
r2242 if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_minY = minY;
m_maxY = maxY;
axisYChanged = true;
Michal Klocek
Refactors internals...
r2273 emit rangeVerticalChanged(m_minY, m_maxY);
Michal Klocek
Adds loosenumber algorithm...
r678 }
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (axisXChanged || axisYChanged)
Michal Klocek
Refactors Domain and Axis...
r1698 emit updated();
Michal Klocek
Refactor domain model...
r439 }
Michal Klocek
Adds loosenumber algorithm...
r678
Michal Klocek
Refactor domain model...
r439 void Domain::setRangeX(qreal min, qreal max)
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 setRange(min, max, m_minY, m_maxY);
Michal Klocek
Refactor domain model...
r439 }
Michal Klocek
Refactors barchart axis hadnling...
r679
Michal Klocek
Refactor domain model...
r439 void Domain::setRangeY(qreal min, qreal max)
{
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(m_minX, m_maxX, min, max);
Michal Klocek
Refactor domain model...
r439 }
void Domain::setMinX(qreal min)
{
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(min, m_maxX, m_minY, m_maxY);
Michal Klocek
Refactor domain model...
r439 }
void Domain::setMaxX(qreal max)
{
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(m_minX, max, m_minY, m_maxY);
Michal Klocek
Refactor domain model...
r439 }
void Domain::setMinY(qreal min)
{
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(m_minX, m_maxX, min, m_maxY);
Michal Klocek
Refactor domain model...
r439 }
void Domain::setMaxY(qreal max)
{
setRange(m_minX, m_maxX, m_minY, max);
}
Michal Klocek
Refactors qchart , adds line animation...
r131 qreal Domain::spanX() const
{
Michal Klocek
Refactor domain model...
r439 Q_ASSERT(m_maxX >= m_minX);
return m_maxX - m_minX;
Michal Klocek
Refactors qchart , adds line animation...
r131 }
qreal Domain::spanY() const
{
Michal Klocek
Refactor domain model...
r439 Q_ASSERT(m_maxY >= m_minY);
return m_maxY - m_minY;
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Adds isEmpty to domain
r388 bool Domain::isEmpty() const
{
Michal Klocek
Refactors internals...
r2273 return qFuzzyCompare(spanX(),0) || qFuzzyCompare(spanY(),0) || m_size.isEmpty() ;
Michal Klocek
Adds isEmpty to domain
r388 }
Michal Klocek
Refactors internals...
r2273 void Domain::zoomIn(const QRectF &rect)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactors internals...
r2273 qreal dx = spanX() / m_size.width();
qreal dy = spanY() / m_size.height();
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactor axis hadnling...
r1078 qreal maxX = m_maxX;
qreal minX = m_minX;
qreal minY = m_minY;
qreal maxY = m_maxY;
Michal Klocek
Refactor domain model...
r439
Michal Klocek
Refactor axis hadnling...
r1078 maxX = minX + dx * rect.right();
minX = minX + dx * rect.left();
minY = maxY - dy * rect.bottom();
maxY = maxY - dy * rect.top();
Michal Klocek
Adds loosenumber algorithm...
r678
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 setRange(minX, maxX, minY, maxY);
Michal Klocek
Refactor domain model...
r439 }
Michal Klocek
Refactors internals...
r2273 void Domain::zoomOut(const QRectF &rect)
Michal Klocek
Refactor domain model...
r439 {
qreal dx = spanX() / rect.width();
qreal dy = spanY() / rect.height();
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactor axis hadnling...
r1078 qreal maxX = m_maxX;
qreal minX = m_minX;
qreal minY = m_minY;
qreal maxY = m_maxY;
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactor axis hadnling...
r1078 minX = maxX - dx * rect.right();
Michal Klocek
Refactors internals...
r2273 maxX = minX + dx * m_size.width();
Michal Klocek
Refactor axis hadnling...
r1078 maxY = minY + dy * rect.bottom();
Michal Klocek
Refactors internals...
r2273 minY = maxY - dy * m_size.height();
Michal Klocek
Refactor axis hadnling...
r1078
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 setRange(minX, maxX, minY, maxY);
Michal Klocek
Adds scroll support...
r531 }
Michal Klocek
Refactors internals...
r2273 void Domain::move(qreal dx, qreal dy)
Michal Klocek
Adds scroll support...
r531 {
Michal Klocek
Refactors internals...
r2273 qreal x = spanX() / m_size.width();
qreal y = spanY() / m_size.height();
Michal Klocek
Adds scroll support...
r531
Michal Klocek
Refactor axis hadnling...
r1078 qreal maxX = m_maxX;
qreal minX = m_minX;
qreal minY = m_minY;
qreal maxY = m_maxY;
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (dx != 0) {
Michal Klocek
Refactor axis hadnling...
r1078 minX = minX + x * dx;
maxX = maxX + x * dx;
Michal Klocek
Adds scroll support...
r531 }
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if (dy != 0) {
Michal Klocek
Refactor axis hadnling...
r1078 minY = minY + y * dy;
maxY = maxY + y * dy;
Michal Klocek
Adds scroll support...
r531 }
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 setRange(minX, maxX, minY, maxY);
Michal Klocek
Refactor domain model...
r439 }
Michal Klocek
Refactors internals...
r2273 QPointF Domain::calculateGeometryPoint(const QPointF &point) const
Michal Klocek
Adds loosenumber algorithm...
r678 {
Michal Klocek
Refactors internals...
r2273 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
const qreal deltaY = m_size.height() / (m_maxY - m_minY);
qreal x = (point.x() - m_minX) * deltaX;
qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
return QPointF(x, y);
Michal Klocek
Adds loosenumber algorithm...
r678 }
Michal Klocek
Refactors internals...
r2273 QVector<QPointF> Domain::calculateGeometryPoints(const QList<QPointF>& vector) const
Michal Klocek
Adds missing ticks hadnling
r554 {
Michal Klocek
Refactors internals...
r2273 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
const qreal deltaY = m_size.height() / (m_maxY - m_minY);
QVector<QPointF> result;
result.resize(vector.count());
for (int i = 0; i < vector.count(); ++i) {
qreal x = (vector[i].x() - m_minX) * deltaX;
qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height();
result[i].setX(x);
result[i].setY(y);
}
return result;
Michal Klocek
Adds missing ticks hadnling
r554 }
Michal Klocek
Refactors internals...
r2273 QPointF Domain::calculateDomainPoint(const QPointF &point) const
{
const qreal deltaX = m_size.width() / (m_maxX - m_minX);
const qreal deltaY = m_size.height() / (m_maxY - m_minY);
qreal x = point.x() / deltaX + m_minX;
qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY;
return QPointF(x, y);
}
// handlers
void Domain::handleVerticalAxisRangeChanged(qreal min, qreal max)
{
if(!m_axisSignalsBlocked)
setRangeY(min, max);
}
void Domain::handleHorizontalAxisRangeChanged(qreal min, qreal max)
{
if(!m_axisSignalsBlocked)
setRangeX(min, max);
}
void Domain::blockAxisSignals(bool block)
{
m_axisSignalsBlocked=block;
}
//algorithm defined by Paul S.Heckbert GraphicalGems I
void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount)
{
qreal range = niceNumber(max - min, true); //range with ceiling
qreal step = niceNumber(range / (ticksCount - 1), false);
min = qFloor(min / step);
max = qCeil(max / step);
ticksCount = int(max - min) + 1;
min *= step;
max *= step;
}
//nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
qreal Domain::niceNumber(qreal x, bool ceiling)
{
qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
qreal q = x / z; //q<10 && q>=1;
if (ceiling) {
if (q <= 1.0) q = 1;
else if (q <= 2.0) q = 2;
else if (q <= 5.0) q = 5;
else q = 10;
} else {
if (q < 1.5) q = 1;
else if (q < 3.0) q = 2;
else if (q < 7.0) q = 5;
else q = 10;
}
return q * z;
}
// operators
Michal Klocek
Another attempt to fix issue with visual sutudio hidden export attributes in domain
r1066 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
Michal Klocek
Add overloaded comparison operators to domain
r220 {
Marek Rosa
Replaced qFuzzyIsNull with qFuzzyCompare. Once qchart test case still uses qFuzzyIsNull becasue it started failing when qFuzzyCompare was used
r2242 return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) &&
qFuzzyCompare(domain1.m_maxY, domain2.m_maxY) &&
qFuzzyCompare(domain1.m_minX, domain2.m_minX) &&
qFuzzyCompare(domain1.m_minY, domain2.m_minY));
Michal Klocek
Add overloaded comparison operators to domain
r220 }
Michal Klocek
Another attempt to fix issue with visual sutudio hidden export attributes in domain
r1066
bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
Michal Klocek
Add overloaded comparison operators to domain
r220 {
return !(domain1 == domain2);
}
Michal Klocek
Another attempt to fix issue with visual sutudio hidden export attributes in domain
r1066
QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
Michal Klocek
Adds debug operator to domain
r222 {
Michal Klocek
Refactors internals...
r2273 dbg.nospace() << "Domain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
Michal Klocek
Adds debug operator to domain
r222 return dbg.maybeSpace();
}
Michal Klocek
Refactor domain model...
r439 #include "moc_domain_p.cpp"
Michal Klocek
Refactors qchart , adds line animation...
r131 QTCOMMERCIALCHART_END_NAMESPACE