qcolorbaraxis.cpp
277 lines
| 6.6 KiB
| text/x-c
|
CppLexer
r2899 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the ColorMapChart API | ||||
-- Copyright (C) 2016, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 2 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Hugo Winter | ||||
-- Mail : hugo.winter@lpp.polytechnique.fr | ||||
----------------------------------------------------------------------------*/ | ||||
//#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> | ||||
//#include <private/chartcolorbaraxisy_p.h> | ||||
#include <chartcolorbaraxisy_p.h> | ||||
#include <QtGui> | ||||
QT_CHARTS_BEGIN_NAMESPACE | ||||
/*! | ||||
Constructs an axis object which is a child of \a parent. | ||||
*/ | ||||
QColorBarAxis::QColorBarAxis(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QObject *parent) : | ||||
QAbstractAxis(*new QColorBarAxisPrivate(plotArea, gradient, min, max, this), parent) | ||||
{ | ||||
setGridLineVisible(false); | ||||
} | ||||
/*! | ||||
\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); | ||||
} | ||||
void QColorBarAxis::setMin(qreal min) | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
setRange(min, qMax(d->m_max, min)); | ||||
} | ||||
qreal QColorBarAxis::min() const | ||||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_min; | ||||
} | ||||
void QColorBarAxis::setMax(qreal max) | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
setRange(qMin(d->m_min, max), max); | ||||
} | ||||
qreal QColorBarAxis::max() const | ||||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_max; | ||||
} | ||||
void QColorBarAxis::setRange(qreal min, qreal max) | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
d->setRange(min,max); | ||||
} | ||||
void QColorBarAxis::setTickCount(int count) | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
if (d->m_tickCount != count && count >= 2) { | ||||
d->m_tickCount = count; | ||||
emit tickCountChanged(count); | ||||
} | ||||
} | ||||
int QColorBarAxis::tickCount() const | ||||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_tickCount; | ||||
} | ||||
void QColorBarAxis::setMinorTickCount(int count) | ||||
{ | ||||
Q_D(QColorBarAxis); | ||||
if (d->m_minorTickCount != count && count >= 0) { | ||||
d->m_minorTickCount = count; | ||||
emit minorTickCountChanged(count); | ||||
} | ||||
} | ||||
int QColorBarAxis::minorTickCount() const | ||||
{ | ||||
Q_D(const QColorBarAxis); | ||||
return d->m_minorTickCount; | ||||
} | ||||
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 | ||||
} | ||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
QColorBarAxisPrivate::QColorBarAxisPrivate(QRectF plotArea, QLinearGradient gradient, qreal min, qreal max, QColorBarAxis *q) | ||||
: QAbstractAxisPrivate(q), | ||||
m_plotArea(plotArea), | ||||
m_min(min), | ||||
m_max(max), | ||||
m_tickCount(5), | ||||
m_minorTickCount(0), | ||||
m_format(QString::null), | ||||
// m_applying(false) | ||||
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) | ||||
//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); | ||||
m_item.reset(axis); | ||||
QAbstractAxisPrivate::initializeGraphics(parent); | ||||
} | ||||
void QColorBarAxisPrivate::initializeDomain(AbstractDomain *domain) | ||||
{ | ||||
//domain is not supposed to have a rangeZ | ||||
// if (orientation() == Qt::Vertical) { | ||||
// if (!qFuzzyIsNull(m_max - m_min)) | ||||
// domain->setRangeY(m_min, m_max); | ||||
// else | ||||
// setRange(domain->minY(), domain->maxY()); | ||||
// } | ||||
} | ||||
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); | ||||
} | ||||
} | ||||
#include "moc_qcolorbaraxis.cpp" | ||||
#include "moc_qcolorbaraxis_p.cpp" | ||||
QT_CHARTS_END_NAMESPACE | ||||