|
|
/****************************************************************************
|
|
|
**
|
|
|
** Copyright (C) 2014 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 Enterprise Charts Add-on.
|
|
|
**
|
|
|
** $QT_BEGIN_LICENSE$
|
|
|
** Licensees holding valid Qt Enterprise licenses may use this file in
|
|
|
** accordance with the Qt Enterprise 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$
|
|
|
**
|
|
|
****************************************************************************/
|
|
|
|
|
|
#include "cartesianchartaxis_p.h"
|
|
|
#include "qabstractaxis.h"
|
|
|
#include "qabstractaxis_p.h"
|
|
|
#include "chartpresenter_p.h"
|
|
|
#include "abstractchartlayout_p.h"
|
|
|
#include "abstractdomain_p.h"
|
|
|
#include "linearrowitem_p.h"
|
|
|
#include <QValueAxis>
|
|
|
#include <QLogValueAxis>
|
|
|
#include <QGraphicsLayout>
|
|
|
#include <QTextDocument>
|
|
|
|
|
|
QT_CHARTS_BEGIN_NAMESPACE
|
|
|
|
|
|
CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis)
|
|
|
: ChartAxisElement(axis, item, intervalAxis)
|
|
|
{
|
|
|
Q_ASSERT(item);
|
|
|
}
|
|
|
|
|
|
|
|
|
CartesianChartAxis::~CartesianChartAxis()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::createItems(int count)
|
|
|
{
|
|
|
if (arrowItems().size() == 0) {
|
|
|
QGraphicsLineItem *arrow = new LineArrowItem(this, this);
|
|
|
arrow->setPen(axis()->linePen());
|
|
|
arrowGroup()->addToGroup(arrow);
|
|
|
}
|
|
|
|
|
|
if (intervalAxis() && gridItems().size() == 0) {
|
|
|
for (int i = 0 ; i < 2 ; i ++){
|
|
|
QGraphicsLineItem *item = new QGraphicsLineItem(this);
|
|
|
item->setPen(axis()->gridLinePen());
|
|
|
gridGroup()->addToGroup(item);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
QGraphicsTextItem *title = titleItem();
|
|
|
title->setFont(axis()->titleFont());
|
|
|
title->setDefaultTextColor(axis()->titleBrush().color());
|
|
|
title->setHtml(axis()->titleText());
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
|
|
|
QGraphicsLineItem *grid = new QGraphicsLineItem(this);
|
|
|
QGraphicsTextItem *label = new QGraphicsTextItem(this);
|
|
|
label->document()->setDocumentMargin(ChartPresenter::textMargin());
|
|
|
arrow->setPen(axis()->linePen());
|
|
|
grid->setPen(axis()->gridLinePen());
|
|
|
label->setFont(axis()->labelsFont());
|
|
|
label->setDefaultTextColor(axis()->labelsBrush().color());
|
|
|
label->setRotation(axis()->labelsAngle());
|
|
|
arrowGroup()->addToGroup(arrow);
|
|
|
gridGroup()->addToGroup(grid);
|
|
|
labelGroup()->addToGroup(label);
|
|
|
|
|
|
if ((gridItems().size()) % 2 && gridItems().size() > 2) {
|
|
|
QGraphicsRectItem* shades = new QGraphicsRectItem(this);
|
|
|
shades->setPen(axis()->shadesPen());
|
|
|
shades->setBrush(axis()->shadesBrush());
|
|
|
shadeGroup()->addToGroup(shades);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::deleteItems(int count)
|
|
|
{
|
|
|
QList<QGraphicsItem *> lines = gridItems();
|
|
|
QList<QGraphicsItem *> labels = labelItems();
|
|
|
QList<QGraphicsItem *> shades = shadeItems();
|
|
|
QList<QGraphicsItem *> axis = arrowItems();
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
if (lines.size() % 2 && lines.size() > 1)
|
|
|
delete(shades.takeLast());
|
|
|
delete(lines.takeLast());
|
|
|
delete(labels.takeLast());
|
|
|
delete(axis.takeLast());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::updateLayout(QVector<qreal> &layout)
|
|
|
{
|
|
|
int diff = ChartAxisElement::layout().size() - layout.size();
|
|
|
|
|
|
if (diff > 0)
|
|
|
deleteItems(diff);
|
|
|
else if (diff < 0)
|
|
|
createItems(-diff);
|
|
|
|
|
|
if (animation()) {
|
|
|
switch (presenter()->state()) {
|
|
|
case ChartPresenter::ZoomInState:
|
|
|
animation()->setAnimationType(AxisAnimation::ZoomInAnimation);
|
|
|
animation()->setAnimationPoint(presenter()->statePoint());
|
|
|
break;
|
|
|
case ChartPresenter::ZoomOutState:
|
|
|
animation()->setAnimationType(AxisAnimation::ZoomOutAnimation);
|
|
|
animation()->setAnimationPoint(presenter()->statePoint());
|
|
|
break;
|
|
|
case ChartPresenter::ScrollUpState:
|
|
|
case ChartPresenter::ScrollLeftState:
|
|
|
animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation);
|
|
|
break;
|
|
|
case ChartPresenter::ScrollDownState:
|
|
|
case ChartPresenter::ScrollRightState:
|
|
|
animation()->setAnimationType(AxisAnimation::MoveForwardAnimation);
|
|
|
break;
|
|
|
case ChartPresenter::ShowState:
|
|
|
animation()->setAnimationType(AxisAnimation::DefaultAnimation);
|
|
|
break;
|
|
|
}
|
|
|
animation()->setValues(ChartAxisElement::layout(), layout);
|
|
|
presenter()->startAnimation(animation());
|
|
|
} else {
|
|
|
setLayout(layout);
|
|
|
updateGeometry();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool CartesianChartAxis::isEmpty()
|
|
|
{
|
|
|
return axisGeometry().isEmpty()
|
|
|
|| gridGeometry().isEmpty()
|
|
|
|| qFuzzyCompare(min(), max());
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
|
|
|
{
|
|
|
m_gridRect = grid;
|
|
|
setAxisGeometry(axis);
|
|
|
|
|
|
if (isEmpty())
|
|
|
return;
|
|
|
|
|
|
QVector<qreal> layout = calculateLayout();
|
|
|
updateLayout(layout);
|
|
|
}
|
|
|
|
|
|
QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
|
{
|
|
|
Q_UNUSED(which);
|
|
|
Q_UNUSED(constraint);
|
|
|
return QSizeF();
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::handleArrowPenChanged(const QPen &pen)
|
|
|
{
|
|
|
foreach (QGraphicsItem *item, arrowItems())
|
|
|
static_cast<QGraphicsLineItem *>(item)->setPen(pen);
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::handleGridPenChanged(const QPen &pen)
|
|
|
{
|
|
|
foreach (QGraphicsItem *item, gridItems())
|
|
|
static_cast<QGraphicsLineItem *>(item)->setPen(pen);
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush)
|
|
|
{
|
|
|
foreach (QGraphicsItem *item, shadeItems())
|
|
|
static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
|
|
|
}
|
|
|
|
|
|
void CartesianChartAxis::handleShadesPenChanged(const QPen &pen)
|
|
|
{
|
|
|
foreach (QGraphicsItem *item, shadeItems())
|
|
|
static_cast<QGraphicsRectItem *>(item)->setPen(pen);
|
|
|
}
|
|
|
|
|
|
#include "moc_cartesianchartaxis_p.cpp"
|
|
|
|
|
|
QT_CHARTS_END_NAMESPACE
|
|
|
|