qcolorbaraxis.cpp
255 lines
| 5.4 KiB
| text/x-c
|
CppLexer
winter
|
r1 | //#include <QtCharts/QColorBarAxis> // TODO : fix this | ||
#include "colorbaraxis/qcolorbaraxis.h" | ||||
//#include <private/qcolorbaraxis_p.h> | ||||
#include "colorbaraxis/qcolorbaraxis_p.h" | ||||
#include <private/abstractdomain_p.h> | ||||
#include <private/chartdataset_p.h> | ||||
#include <private/chartpresenter_p.h> | ||||
#include <private/charttheme_p.h> | ||||
winter
|
r2 | //#include <private/chartcolorbaraxisy_p.h> | ||
#include <chartcolorbaraxisy_p.h> | ||||
winter
|
r1 | #include <QtGui> | ||
QT_CHARTS_BEGIN_NAMESPACE | ||||
/*! | ||||
Constructs an axis object which is a child of \a parent. | ||||
*/ | ||||
winter
|
r3 | QColorBarAxis::QColorBarAxis(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QObject *parent) : | ||
QAbstractAxis(*new QColorBarAxisPrivate(plotArea, gradient, min, max, this), parent) | ||||
winter
|
r1 | { | ||
winter
|
r3 | setGridLineVisible(false); | ||
winter
|
r1 | } | ||
/*! | ||||
\internal | ||||
*/ | ||||
QColorBarAxis::QColorBarAxis(QColorBarAxisPrivate &d, QObject *parent) | ||||
: QAbstractAxis(d, parent) | ||||
{ | ||||
} | ||||
/*! | ||||
Destroys the object | ||||
*/ | ||||
QColorBarAxis::~QColorBarAxis() | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
if (d->m_chart) | ||||
d->m_chart->removeAxis(this); | ||||
} | ||||
winter
|
r2 | void QColorBarAxis::setMin(qreal min) | ||
{ | ||||
Q_D(QColorBarAxis); | ||||
setRange(min, qMax(d->m_max, min)); | ||||
} | ||||
winter
|
r1 | qreal QColorBarAxis::min() const | ||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_min; | ||||
} | ||||
winter
|
r2 | void QColorBarAxis::setMax(qreal max) | ||
{ | ||||
Q_D(QColorBarAxis); | ||||
setRange(qMin(d->m_min, max), max); | ||||
} | ||||
winter
|
r1 | qreal QColorBarAxis::max() const | ||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_max; | ||||
} | ||||
winter
|
r2 | void QColorBarAxis::setRange(qreal min, qreal max) | ||
{ | ||||
Q_D(QColorBarAxis); | ||||
d->setRange(min,max); | ||||
} | ||||
winter
|
r1 | |||
winter
|
r2 | |||
void QColorBarAxis::setTickCount(int count) | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
if (d->m_tickCount != count && count >= 2) { | ||||
d->m_tickCount = count; | ||||
emit tickCountChanged(count); | ||||
} | ||||
} | ||||
winter
|
r1 | |||
winter
|
r2 | int QColorBarAxis::tickCount() const | ||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_tickCount; | ||||
} | ||||
winter
|
r1 | |||
winter
|
r2 | void QColorBarAxis::setMinorTickCount(int count) | ||
{ | ||||
Q_D(QColorBarAxis); | ||||
if (d->m_minorTickCount != count && count >= 0) { | ||||
d->m_minorTickCount = count; | ||||
emit minorTickCountChanged(count); | ||||
} | ||||
} | ||||
winter
|
r1 | |||
winter
|
r2 | int QColorBarAxis::minorTickCount() const | ||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_minorTickCount; | ||||
} | ||||
winter
|
r1 | |||
void QColorBarAxis::setLabelFormat(const QString &format) | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
d->m_format = format; | ||||
emit labelFormatChanged(format); | ||||
} | ||||
QString QColorBarAxis::labelFormat() const | ||||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_format; | ||||
} | ||||
/*! | ||||
Returns the type of the axis | ||||
*/ | ||||
QAbstractAxis::AxisType QColorBarAxis::type() const | ||||
{ | ||||
return AxisTypeValue; | ||||
//TODO : AxisTypeColorBar | ||||
} | ||||
winter
|
r2 | |||
winter
|
r1 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
winter
|
r3 | QColorBarAxisPrivate::QColorBarAxisPrivate(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QColorBarAxis *q) | ||
winter
|
r1 | : QAbstractAxisPrivate(q), | ||
winter
|
r3 | m_plotArea(plotArea), | ||
winter
|
r1 | m_min(min), | ||
m_max(max), | ||||
winter
|
r3 | m_tickCount(5), | ||
m_minorTickCount(0), | ||||
winter
|
r1 | m_format(QString::null), | ||
winter
|
r3 | // m_applying(false) | ||
winter
|
r1 | m_gradient(gradient) | ||
{ | ||||
} | ||||
QColorBarAxisPrivate::~QColorBarAxisPrivate() | ||||
{ | ||||
} | ||||
void QColorBarAxisPrivate::initializeGraphics(QGraphicsItem *parent) | ||||
{ | ||||
Q_Q(QColorBarAxis); | ||||
ChartAxisElement *axis(0); | ||||
setAlignment(Qt::AlignRight); //also set orientation (Vertical in this case) | ||||
winter
|
r3 | //TODO : change this position | ||
qreal x1; | ||||
qreal y1; | ||||
qreal x2; | ||||
qreal y2; | ||||
m_plotArea.getCoords(&x1,&y1,&x2,&y2); | ||||
QPoint pos(x2+5,y1); | ||||
axis = new ChartColorBarAxisY(q, pos, m_plotArea.height(),m_gradient, parent); | ||||
winter
|
r1 | |||
winter
|
r2 | m_item.reset(axis); | ||
winter
|
r1 | QAbstractAxisPrivate::initializeGraphics(parent); | ||
} | ||||
void QColorBarAxisPrivate::initializeDomain(AbstractDomain *domain) | ||||
{ | ||||
//domain is not supposed to have a rangeZ | ||||
winter
|
r3 | // if (orientation() == Qt::Vertical) { | ||
// if (!qFuzzyIsNull(m_max - m_min)) | ||||
// domain->setRangeY(m_min, m_max); | ||||
// else | ||||
// setRange(domain->minY(), domain->maxY()); | ||||
// } | ||||
winter
|
r2 | } | ||
void QColorBarAxisPrivate::setMin(const QVariant &min) | ||||
{ | ||||
Q_Q(QColorBarAxis); | ||||
bool ok; | ||||
qreal value = min.toReal(&ok); | ||||
if (ok) | ||||
q->setMin(value); | ||||
} | ||||
void QColorBarAxisPrivate::setMax(const QVariant &max) | ||||
{ | ||||
Q_Q(QColorBarAxis); | ||||
bool ok; | ||||
qreal value = max.toReal(&ok); | ||||
if (ok) | ||||
q->setMax(value); | ||||
} | ||||
void QColorBarAxisPrivate::setRange(const QVariant &min, const QVariant &max) | ||||
{ | ||||
Q_Q(QColorBarAxis); | ||||
bool ok1; | ||||
bool ok2; | ||||
qreal value1 = min.toReal(&ok1); | ||||
qreal value2 = max.toReal(&ok2); | ||||
if (ok1 && ok2) | ||||
q->setRange(value1, value2); | ||||
} | ||||
void QColorBarAxisPrivate::setRange(qreal min,qreal max) | ||||
{ | ||||
Q_Q(QColorBarAxis); | ||||
bool changed = false; | ||||
if (min > max) | ||||
return; | ||||
bool changeMin = false; | ||||
if (m_min == 0 || min == 0) | ||||
changeMin = !qFuzzyCompare(1 + m_min, 1 + min); | ||||
else | ||||
changeMin = !qFuzzyCompare(m_min, min); | ||||
bool changeMax = false; | ||||
if (m_max == 0 || max == 0) | ||||
changeMax = !qFuzzyCompare(1 + m_max, 1 + max); | ||||
else | ||||
changeMax = !qFuzzyCompare(m_max, max); | ||||
if (changeMin) { | ||||
m_min = min; | ||||
changed = true; | ||||
emit q->minChanged(min); | ||||
} | ||||
if (changeMax) { | ||||
m_max = max; | ||||
changed = true; | ||||
emit q->maxChanged(max); | ||||
} | ||||
if (changed) { | ||||
emit rangeChanged(min,max); | ||||
emit q->rangeChanged(min, max); | ||||
} | ||||
winter
|
r1 | } | ||
#include "moc_qcolorbaraxis.cpp" | ||||
#include "moc_qcolorbaraxis_p.cpp" | ||||
QT_CHARTS_END_NAMESPACE | ||||