##// END OF EJS Templates
Add support for reversed axis when useOpenGL is true...
Add support for reversed axis when useOpenGL is true Change-Id: If8b6690585c767b65eaa4a43e179c86183903637 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@theqtcompany.com>

File last commit:

r2855:aa5aba329d30
r2863:15eed6371853
Show More
abstractdomain.cpp
275 lines | 7.6 KiB | text/x-c | CppLexer
/ src / charts / domain / abstractdomain.cpp
Miikka Heikkinen
Updated license...
r2854 /****************************************************************************
Jani Honkonen
Add license headers
r794 **
Miikka Heikkinen
Updated license...
r2854 ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Jani Honkonen
Add license headers
r794 **
Miikka Heikkinen
Updated license...
r2854 ** This file is part of the Qt Charts module of the Qt Toolkit.
Jani Honkonen
Add license headers
r794 **
Miikka Heikkinen
Updated license...
r2854 ** $QT_BEGIN_LICENSE:GPL$
Titta Heikkala
Updated license headers...
r2845 ** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
Miikka Heikkinen
Updated license...
r2854 ** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
Jani Honkonen
Add license headers
r794 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_END_LICENSE$
**
Miikka Heikkinen
Updated license...
r2854 ****************************************************************************/
Jani Honkonen
Add license headers
r794
Titta Heikkala
Fix include syntax...
r2714 #include <private/abstractdomain_p.h>
#include <private/qabstractaxis_p.h>
#include <QtCore/QtMath>
Titta Heikkala
Fix QNX build issue...
r2775 #include <cmath>
Michal Klocek
Refactors qchart , adds line animation...
r131
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_BEGIN_NAMESPACE
Michal Klocek
Refactors qchart , adds line animation...
r131
Marek Rosa
Domains added
r2275 AbstractDomain::AbstractDomain(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),
Miikka Heikkinen
Added QChart::zoomReset() and QChart::isZoomed()...
r2545 m_signalsBlocked(false),
m_zoomed(false),
m_zoomResetMinX(0),
m_zoomResetMaxX(0),
m_zoomResetMinY(0),
m_zoomResetMaxY(0)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
}
Marek Rosa
Domains added
r2275 AbstractDomain::~AbstractDomain()
Michal Klocek
Refactors qchart , adds line animation...
r131 {
}
Miikka Heikkinen
Add Polar chart support...
r2483 void AbstractDomain::setSize(const QSizeF &size)
Michal Klocek
Refactors internals...
r2273 {
Titta Heikkala
Qt Charts project file structure change...
r2712 if (m_size != size) {
m_size=size;
emit updated();
}
Michal Klocek
Refactors internals...
r2273 }
Marek Rosa
Domains added
r2275 QSizeF AbstractDomain::size() const
Michal Klocek
Refactors internals...
r2273 {
Titta Heikkala
Qt Charts project file structure change...
r2712 return m_size;
Michal Klocek
Refactors internals...
r2273 }
Marek Rosa
Domains added
r2275 void AbstractDomain::setRangeX(qreal min, qreal max)
Michal Klocek
Refactor domain model...
r439 {
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
Marek Rosa
Domains added
r2275 void AbstractDomain::setRangeY(qreal min, qreal max)
Michal Klocek
Refactor domain model...
r439 {
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(m_minX, m_maxX, min, max);
Michal Klocek
Refactor domain model...
r439 }
Marek Rosa
Domains added
r2275 void AbstractDomain::setMinX(qreal min)
Michal Klocek
Refactor domain model...
r439 {
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(min, m_maxX, m_minY, m_maxY);
Michal Klocek
Refactor domain model...
r439 }
Marek Rosa
Domains added
r2275 void AbstractDomain::setMaxX(qreal max)
Michal Klocek
Refactor domain model...
r439 {
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(m_minX, max, m_minY, m_maxY);
Michal Klocek
Refactor domain model...
r439 }
Marek Rosa
Domains added
r2275 void AbstractDomain::setMinY(qreal min)
Michal Klocek
Refactor domain model...
r439 {
Michal Klocek
Adds loosenumber algorithm...
r678 setRange(m_minX, m_maxX, min, m_maxY);
Michal Klocek
Refactor domain model...
r439 }
Marek Rosa
Domains added
r2275 void AbstractDomain::setMaxY(qreal max)
Michal Klocek
Refactor domain model...
r439 {
setRange(m_minX, m_maxX, m_minY, max);
}
Marek Rosa
Domains added
r2275 qreal AbstractDomain::spanX() const
Michal Klocek
Refactors qchart , adds line animation...
r131 {
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 }
Marek Rosa
Domains added
r2275 qreal AbstractDomain::spanY() const
Michal Klocek
Refactors qchart , adds line animation...
r131 {
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 }
Marek Rosa
Domains added
r2275 bool AbstractDomain::isEmpty() const
Michal Klocek
Adds isEmpty to domain
r388 {
Titta Heikkala
Fix empty domain detection...
r2711 return qFuzzyCompare(spanX(), 0) || qFuzzyCompare(spanY(), 0) || m_size.isEmpty();
Michal Klocek
Adds isEmpty to domain
r388 }
Marek Rosa
Domains added
r2275 QPointF AbstractDomain::calculateDomainPoint(const QPointF &point) const
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() / deltaX + m_minX;
qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY;
return QPointF(x, y);
}
// handlers
Marek Rosa
Domains added
r2275 void AbstractDomain::handleVerticalAxisRangeChanged(qreal min, qreal max)
Michal Klocek
Refactors internals...
r2273 {
Michal Klocek
Bugfix resize event during zoomin
r2289 setRangeY(min, max);
Michal Klocek
Refactors internals...
r2273 }
Marek Rosa
Domains added
r2275 void AbstractDomain::handleHorizontalAxisRangeChanged(qreal min, qreal max)
Michal Klocek
Refactors internals...
r2273 {
Michal Klocek
Bugfix resize event during zoomin
r2289 setRangeX(min, max);
Michal Klocek
Refactors internals...
r2273 }
Michal Klocek
Bugfix resize event during zoomin
r2289 void AbstractDomain::blockRangeSignals(bool block)
Michal Klocek
Refactors internals...
r2273 {
Miikka Heikkinen
Add Polar chart support...
r2483 if (m_signalsBlocked!=block) {
Michal Klocek
Bugfix resize event during zoomin
r2289 m_signalsBlocked=block;
Miikka Heikkinen
Add Polar chart support...
r2483 if (!block) {
Michal Klocek
Bugfix resize event during zoomin
r2289 emit rangeHorizontalChanged(m_minX,m_maxX);
emit rangeVerticalChanged(m_minY,m_maxY);
}
}
Michal Klocek
Refactors internals...
r2273 }
Miikka Heikkinen
Added QChart::zoomReset() and QChart::isZoomed()...
r2545 void AbstractDomain::zoomReset()
{
if (m_zoomed) {
setRange(m_zoomResetMinX,
m_zoomResetMaxX,
m_zoomResetMinY,
m_zoomResetMaxY);
m_zoomed = false;
}
}
void AbstractDomain::storeZoomReset()
{
if (!m_zoomed) {
m_zoomed = true;
m_zoomResetMinX = m_minX;
m_zoomResetMaxX = m_maxX;
m_zoomResetMinY = m_minY;
m_zoomResetMaxY = m_maxY;
}
}
Michal Klocek
Refactors internals...
r2273 //algorithm defined by Paul S.Heckbert GraphicalGems I
Marek Rosa
Domains added
r2275 void AbstractDomain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount)
Michal Klocek
Refactors internals...
r2273 {
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
Marek Rosa
Domains added
r2275 qreal AbstractDomain::niceNumber(qreal x, bool ceiling)
Michal Klocek
Refactors internals...
r2273 {
Titta Heikkala
Fix QNX build issue...
r2775 qreal z = qPow(10, qFloor(std::log10(x))); //find corresponding number of the form of 10^n than is smaller than x
Michal Klocek
Refactors internals...
r2273 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;
}
Miikka Heikkinen
Add Polar chart support...
r2483 bool AbstractDomain::attachAxis(QAbstractAxis *axis)
Michal Klocek
Adds domains swap logic
r2284 {
Miikka Heikkinen
Add Polar chart support...
r2483 if (axis->orientation() == Qt::Vertical) {
Titta Heikkala
Qt Charts project file structure change...
r2712 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
QObject::connect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
}
Michal Klocek
Adds domains swap logic
r2284
Miikka Heikkinen
Add Polar chart support...
r2483 if (axis->orientation() == Qt::Horizontal) {
Titta Heikkala
Qt Charts project file structure change...
r2712 QObject::connect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
QObject::connect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
}
Michal Klocek
Adds domains swap logic
r2284
Titta Heikkala
Qt Charts project file structure change...
r2712 return true;
Michal Klocek
Adds domains swap logic
r2284 }
Miikka Heikkinen
Add Polar chart support...
r2483 bool AbstractDomain::detachAxis(QAbstractAxis *axis)
Michal Klocek
Adds domains swap logic
r2284 {
Miikka Heikkinen
Add Polar chart support...
r2483 if (axis->orientation() == Qt::Vertical) {
Michal Klocek
Adds domains swap logic
r2284 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleVerticalAxisRangeChanged(qreal,qreal)));
QObject::disconnect(this, SIGNAL(rangeVerticalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
}
Miikka Heikkinen
Add Polar chart support...
r2483 if (axis->orientation() == Qt::Horizontal) {
Michal Klocek
Adds domains swap logic
r2284 QObject::disconnect(axis->d_ptr.data(), SIGNAL(rangeChanged(qreal,qreal)), this, SLOT(handleHorizontalAxisRangeChanged(qreal,qreal)));
QObject::disconnect(this, SIGNAL(rangeHorizontalChanged(qreal,qreal)), axis->d_ptr.data(), SLOT(handleRangeChanged(qreal,qreal)));
}
return true;
}
Michal Klocek
Refactors internals...
r2273
// operators
Robin Burchell
charts: Follow Qt's already-existent -developer-build option....
r2855 bool Q_AUTOTEST_EXPORT operator== (const AbstractDomain &domain1, const AbstractDomain &domain2)
Michal Klocek
Add overloaded comparison operators to domain
r220 {
Miikka Heikkinen
Add Polar chart support...
r2483 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX)
&& qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY)
&& qFuzzyIsNull(domain1.m_minX - domain2.m_minX)
&& qFuzzyIsNull(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
Robin Burchell
charts: Follow Qt's already-existent -developer-build option....
r2855 bool Q_AUTOTEST_EXPORT operator!= (const AbstractDomain &domain1, const AbstractDomain &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
Robin Burchell
charts: Follow Qt's already-existent -developer-build option....
r2855 QDebug Q_AUTOTEST_EXPORT operator<<(QDebug dbg, const AbstractDomain &domain)
Michal Klocek
Adds debug operator to domain
r222 {
Titta Heikkala
Fix Chart build when QT_NO_TEXTSTREAM is defined...
r2620 #ifdef QT_NO_TEXTSTREAM
Q_UNUSED(domain)
#else
Marek Rosa
Domains added
r2275 dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size;
Titta Heikkala
Fix Chart build when QT_NO_TEXTSTREAM is defined...
r2620 #endif
Michal Klocek
Adds debug operator to domain
r222 return dbg.maybeSpace();
}
Miikka Heikkinen
Add Polar chart support...
r2483 // This function adjusts min/max ranges to failsafe values if negative/zero values are attempted.
void AbstractDomain::adjustLogDomainRanges(qreal &min, qreal &max)
{
if (min <= 0) {
min = 1.0;
if (max <= min)
max = min + 1.0;
}
}
Marek Rosa
Domains added
r2275 #include "moc_abstractdomain_p.cpp"
Michal Klocek
Refactor domain model...
r439
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_END_NAMESPACE