##// END OF EJS Templates
Scatter API review: changed signal now private etc.
Scatter API review: changed signal now private etc.

File last commit:

r439:86afa1b4ff5f
r459:272f4a2e7431
Show More
domain.cpp
148 lines | 2.9 KiB | text/x-c | CppLexer
Michal Klocek
Refactors qchart , adds line animation...
r131 #include "domain_p.h"
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactor domain model...
r439 Domain::Domain(QObject* parent):QObject(parent),
m_minX(0),
m_maxX(0),
m_minY(0),
m_maxY(0)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
}
Domain::~Domain()
{
}
Michal Klocek
Refactor domain model...
r439 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
{
bool changed = false;
if(m_minX!=minX || m_maxX!=maxX)
{
m_minX=minX;
m_maxX=maxX;
changed=true;
emit rangeXChanged(minX,maxX);
}
if(m_minY!=minY || m_maxY!=maxY){
m_minY=minY;
m_maxY=maxY;
changed=true;
emit rangeYChanged(minY,maxY);
}
if(changed){
emit domainChanged(m_minX, m_maxX, m_minY, m_maxY);
}
}
void Domain::setRangeX(qreal min, qreal max)
{
setRange(min,max,m_minY, m_maxY);
}
void Domain::setRangeY(qreal min, qreal max)
{
setRange(m_minX, m_maxX, min, max);
}
void Domain::setMinX(qreal min)
{
setRange(min, m_maxX, m_minY, m_maxY);
}
void Domain::setMaxX(qreal max)
{
setRange(m_minX, max, m_minY, m_maxY);
}
void Domain::setMinY(qreal min)
{
setRange(m_minX, m_maxX, min, m_maxY);
}
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
{
return spanX()==0 || spanY()==0;
}
Michal Klocek
Refactor domain model...
r439 void Domain::zoomIn(const QRectF& rect, const QSizeF& size)
Michal Klocek
Refactors qchart , adds line animation...
r131 {
Michal Klocek
Refactor domain model...
r439 qreal dx = spanX() / size.width();
qreal dy = spanY() / size.height();
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactor domain model...
r439 m_maxX = m_minX + dx * rect.right();
m_minX = m_minX + dx * rect.left();
m_minY = m_maxY - dy * rect.bottom();
m_maxY = m_maxY - dy * rect.top();
emit domainChanged(m_minX, m_maxX, m_minY, m_maxY);
emit rangeXChanged(m_minX, m_maxX);
emit rangeYChanged(m_minY, m_maxY);
}
void Domain::zoomOut(const QRectF& rect, const QSizeF& size)
{
qreal dx = spanX() / rect.width();
qreal dy = spanY() / rect.height();
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactor domain model...
r439 m_minX = m_maxX - dx * rect.right();
m_maxX = m_minX + dx * size.width();
m_maxY = m_minY + dy * rect.bottom();
m_minY = m_maxY - dy * size.height();
Michal Klocek
Refactors qchart , adds line animation...
r131
Michal Klocek
Refactor domain model...
r439 emit domainChanged(m_minX, m_maxX, m_minY, m_maxY);
emit rangeXChanged(m_minX, m_maxX);
emit rangeYChanged(m_minY, m_maxY);
}
void Domain::handleAxisRangeXChanged(qreal min,qreal max)
{
setRangeX(min,max);
}
void Domain::handleAxisRangeYChanged(qreal min,qreal max)
{
setRangeY(min,max);
Michal Klocek
Refactors qchart , adds line animation...
r131 }
Michal Klocek
Add overloaded comparison operators to domain
r220
bool operator== (const Domain &domain1, const Domain &domain2)
{
return (domain1.m_maxX == domain2.m_maxX &&
Michal Klocek
Refactor domain model...
r439 domain1.m_maxY == domain2.m_maxY &&
domain1.m_minX == domain2.m_minX &&
domain1.m_minY == domain2.m_minY);
Michal Klocek
Add overloaded comparison operators to domain
r220 }
bool operator!= (const Domain &domain1, const Domain &domain2)
{
return !(domain1 == domain2);
}
Michal Klocek
Adds debug operator to domain
r222 QDebug operator<<(QDebug dbg, const Domain &domain)
{
dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')';
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