chartaxis.cpp
553 lines
| 16.9 KiB
| text/x-c
|
CppLexer
|
r794 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 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 Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r1006 | #include "chartaxis_p.h" | ||
|
r1541 | #include "qabstractaxis.h" | ||
#include "qabstractaxis_p.h" | ||||
|
r262 | #include "chartpresenter_p.h" | ||
|
r2105 | #include "chartlayout_p.h" | ||
|
r2275 | #include "abstractdomain_p.h" | ||
|
r1577 | #include <qmath.h> | ||
|
r1717 | #include <QDateTime> | ||
|
r1854 | #include <QValueAxis> | ||
|
r2274 | #include <QLogValueAxis> | ||
|
r1890 | #include <QGraphicsLayout> | ||
|
r1965 | #include <QFontMetrics> | ||
|
r67 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
|
r2273 | ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis) | ||
: ChartElement(item), | ||||
m_axis(axis), | ||||
|
r2410 | m_labelsAngle(axis->labelsAngle()), | ||
|
r2273 | m_grid(new QGraphicsItemGroup(item)), | ||
m_arrow(new QGraphicsItemGroup(item)), | ||||
m_shades(new QGraphicsItemGroup(item)), | ||||
m_labels(new QGraphicsItemGroup(item)), | ||||
m_title(new QGraphicsSimpleTextItem(item)), | ||||
|
r2131 | m_animation(0), | ||
m_labelPadding(5), | ||||
|
r2413 | m_intervalAxis(intervalAxis), | ||
m_titlePadding(3) | ||||
|
r67 | { | ||
|
r2273 | Q_ASSERT(item); | ||
|
r2345 | //initial initialization | ||
|
r1729 | m_arrow->setHandlesChildEvents(false); | ||
|
r2273 | m_arrow->setZValue(ChartPresenter::AxisZValue); | ||
|
r1745 | m_labels->setZValue(ChartPresenter::AxisZValue); | ||
|
r784 | m_shades->setZValue(ChartPresenter::ShadesZValue); | ||
m_grid->setZValue(ChartPresenter::GridZValue); | ||||
|
r2142 | m_title->setZValue(ChartPresenter::GridZValue); | ||
|
r2345 | handleVisibleChanged(m_axis->isVisible()); | ||
|
r2273 | connectSlots(); | ||
|
r439 | |||
|
r2273 | setFlag(QGraphicsItem::ItemHasNoContents,true); | ||
} | ||||
|
r1837 | |||
|
r2273 | void ChartAxis::connectSlots() | ||
{ | ||||
QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool))); | ||||
QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool))); | ||||
|
r2282 | QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool))); | ||
|
r2273 | QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool))); | ||
QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool))); | ||||
QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int))); | ||||
QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&))); | ||||
QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&))); | ||||
QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&))); | ||||
QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&))); | ||||
QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&))); | ||||
QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&))); | ||||
QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&))); | ||||
QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&))); | ||||
QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&))); | ||||
QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&))); | ||||
QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&))); | ||||
|
r2297 | QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool))); | ||
|
r2273 | QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal))); | ||
|
r67 | } | ||
|
r1006 | ChartAxis::~ChartAxis() | ||
|
r67 | { | ||
} | ||||
|
r2131 | void ChartAxis::setAnimation(AxisAnimation *animation) | ||
|
r176 | { | ||
|
r2131 | m_animation = animation; | ||
|
r1241 | } | ||
|
r530 | |||
|
r1241 | void ChartAxis::setLayout(QVector<qreal> &layout) | ||
{ | ||||
|
r2131 | m_layoutVector = layout; | ||
|
r1241 | } | ||
void ChartAxis::createItems(int count) | ||||
{ | ||||
|
r2277 | if (m_arrow->childItems().size() == 0){ | ||
|
r2273 | QGraphicsLineItem* arrow = new ArrowItem(this, this); | ||
arrow->setPen(m_axis->linePen()); | ||||
m_arrow->addToGroup(arrow); | ||||
} | ||||
|
r2131 | |||
|
r2277 | if (m_intervalAxis && m_grid->childItems().size() == 0) { | ||
|
r2273 | for (int i = 0 ; i < 2 ; i ++){ | ||
|
r2277 | QGraphicsLineItem* item = new QGraphicsLineItem(this); | ||
item->setPen(m_axis->gridLinePen()); | ||||
|
r2273 | m_grid->addToGroup(item); | ||
} | ||||
|
r2111 | } | ||
|
r2131 | |||
|
r223 | for (int i = 0; i < count; ++i) { | ||
|
r2273 | QGraphicsLineItem* arrow = new QGraphicsLineItem(this); | ||
arrow->setPen(m_axis->linePen()); | ||||
|
r2277 | QGraphicsLineItem* grid = new QGraphicsLineItem(this); | ||
grid->setPen(m_axis->gridLinePen()); | ||||
QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this); | ||||
label->setFont(m_axis->labelsFont()); | ||||
label->setPen(m_axis->labelsPen()); | ||||
label->setBrush(m_axis->labelsBrush()); | ||||
|
r2406 | label->setRotation(m_labelsAngle); | ||
|
r2277 | m_arrow->addToGroup(arrow); | ||
|
r2273 | m_grid->addToGroup(grid); | ||
|
r2221 | m_labels->addToGroup(label); | ||
|
r2273 | |||
if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){ | ||||
|
r2277 | QGraphicsRectItem* shades = new QGraphicsRectItem(this); | ||
shades->setPen(m_axis->shadesPen()); | ||||
shades->setBrush(m_axis->shadesBrush()); | ||||
|
r2273 | m_shades->addToGroup(shades); | ||
} | ||||
|
r1241 | } | ||
|
r2273 | |||
|
r176 | } | ||
|
r1006 | void ChartAxis::deleteItems(int count) | ||
|
r176 | { | ||
|
r784 | QList<QGraphicsItem *> lines = m_grid->childItems(); | ||
QList<QGraphicsItem *> labels = m_labels->childItems(); | ||||
QList<QGraphicsItem *> shades = m_shades->childItems(); | ||||
|
r1729 | QList<QGraphicsItem *> axis = m_arrow->childItems(); | ||
|
r176 | |||
|
r291 | for (int i = 0; i < count; ++i) { | ||
|
r2131 | if (lines.size() % 2 && lines.size() > 1) | ||
delete(shades.takeLast()); | ||||
|
r291 | delete(lines.takeLast()); | ||
delete(labels.takeLast()); | ||||
delete(axis.takeLast()); | ||||
|
r272 | } | ||
|
r176 | } | ||
|
r1006 | void ChartAxis::updateLayout(QVector<qreal> &layout) | ||
|
r176 | { | ||
|
r1241 | int diff = m_layoutVector.size() - layout.size(); | ||
|
r2131 | if (diff > 0) | ||
|
r1241 | deleteItems(diff); | ||
|
r2131 | else if (diff < 0) | ||
|
r1241 | createItems(-diff); | ||
if (m_animation) { | ||||
|
r2131 | switch (presenter()->state()) { | ||
case ChartPresenter::ZoomInState: | ||||
m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | ||||
m_animation->setAnimationPoint(presenter()->statePoint()); | ||||
break; | ||||
case ChartPresenter::ZoomOutState: | ||||
m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | ||||
m_animation->setAnimationPoint(presenter()->statePoint()); | ||||
break; | ||||
case ChartPresenter::ScrollUpState: | ||||
case ChartPresenter::ScrollLeftState: | ||||
m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | ||||
break; | ||||
case ChartPresenter::ScrollDownState: | ||||
case ChartPresenter::ScrollRightState: | ||||
m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | ||||
break; | ||||
case ChartPresenter::ShowState: | ||||
m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | ||||
break; | ||||
} | ||||
m_animation->setValues(m_layoutVector, layout); | ||||
presenter()->startAnimation(m_animation); | ||||
} else { | ||||
|
r745 | setLayout(layout); | ||
|
r1241 | updateGeometry(); | ||
|
r530 | } | ||
|
r85 | } | ||
|
r176 | |||
|
r2273 | void ChartAxis::setLabelPadding(int padding) | ||
{ | ||||
m_labelPadding = padding; | ||||
} | ||||
|
r2413 | void ChartAxis::setTitlePadding(int padding) | ||
{ | ||||
m_titlePadding = padding; | ||||
} | ||||
|
r2273 | bool ChartAxis::isEmpty() | ||
{ | ||||
return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max()); | ||||
} | ||||
void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) | ||||
{ | ||||
m_gridRect = grid; | ||||
m_axisRect = axis; | ||||
if (isEmpty()) | ||||
return; | ||||
QVector<qreal> layout = calculateLayout(); | ||||
updateLayout(layout); | ||||
} | ||||
qreal ChartAxis::min() const | ||||
|
r184 | { | ||
|
r2277 | return m_axis->d_ptr->min(); | ||
|
r184 | } | ||
|
r2273 | qreal ChartAxis::max() const | ||
|
r184 | { | ||
|
r2277 | return m_axis->d_ptr->max(); | ||
|
r1729 | } | ||
|
r2273 | QFont ChartAxis::font() const | ||
|
r1729 | { | ||
|
r2277 | return m_axis->labelsFont(); | ||
|
r184 | } | ||
|
r2273 | QFont ChartAxis::titleFont() const | ||
|
r176 | { | ||
|
r2277 | return m_axis->titleFont(); | ||
|
r176 | } | ||
|
r85 | |||
|
r2273 | QString ChartAxis::titleText() const | ||
|
r176 | { | ||
|
r2277 | return m_axis->titleText(); | ||
|
r176 | } | ||
|
r85 | |||
|
r2273 | void ChartAxis::axisSelected() | ||
|
r1729 | { | ||
|
r2277 | emit clicked(); | ||
|
r1729 | } | ||
|
r2273 | Qt::Orientation ChartAxis::orientation() const | ||
|
r176 | { | ||
|
r2273 | return m_axis->orientation(); | ||
|
r176 | } | ||
|
r85 | |||
|
r2273 | Qt::Alignment ChartAxis::alignment() const | ||
{ | ||||
return m_axis->alignment(); | ||||
} | ||||
void ChartAxis::setLabels(const QStringList &labels) | ||||
{ | ||||
m_labelsList = labels; | ||||
} | ||||
QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const | ||||
|
r176 | { | ||
|
r2273 | Q_UNUSED(which); | ||
Q_UNUSED(constraint); | ||||
return QSizeF(); | ||||
|
r176 | } | ||
|
r85 | |||
|
r2273 | //handlers | ||
void ChartAxis::handleArrowVisibleChanged(bool visible) | ||||
|
r1729 | { | ||
|
r2273 | m_arrow->setVisible(visible); | ||
|
r1729 | } | ||
|
r2273 | void ChartAxis::handleGridVisibleChanged(bool visible) | ||
|
r176 | { | ||
|
r2273 | m_grid->setVisible(visible); | ||
|
r176 | } | ||
|
r85 | |||
|
r2273 | void ChartAxis::handleLabelsVisibleChanged(bool visible) | ||
|
r176 | { | ||
|
r2273 | m_labels->setVisible(visible); | ||
|
r176 | } | ||
|
r67 | |||
|
r2273 | void ChartAxis::handleShadesVisibleChanged(bool visible) | ||
|
r1729 | { | ||
m_shades->setVisible(visible); | ||||
} | ||||
|
r2297 | void ChartAxis::handleTitleVisibleChanged(bool visible) | ||
{ | ||||
|
r2415 | QGraphicsLayoutItem::updateGeometry(); | ||
|
r2297 | presenter()->layout()->invalidate(); | ||
|
r2415 | m_title->setVisible(visible); | ||
|
r2297 | } | ||
|
r2273 | void ChartAxis::handleLabelsAngleChanged(int angle) | ||
|
r176 | { | ||
|
r2131 | foreach (QGraphicsItem *item, m_labels->childItems()) | ||
item->setRotation(angle); | ||||
|
r176 | |||
|
r2131 | m_labelsAngle = angle; | ||
|
r67 | } | ||
|
r2273 | void ChartAxis::handleLabelsPenChanged(const QPen &pen) | ||
|
r140 | { | ||
|
r2131 | foreach (QGraphicsItem *item , m_labels->childItems()) | ||
static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen); | ||||
|
r140 | } | ||
|
r2273 | void ChartAxis::handleLabelsBrushChanged(const QBrush &brush) | ||
|
r140 | { | ||
|
r2131 | foreach (QGraphicsItem *item , m_labels->childItems()) | ||
static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush); | ||||
|
r140 | } | ||
|
r2273 | void ChartAxis::handleLabelsFontChanged(const QFont &font) | ||
|
r140 | { | ||
|
r2277 | foreach (QGraphicsItem *item , m_labels->childItems()) | ||
static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font); | ||||
QGraphicsLayoutItem::updateGeometry(); | ||||
presenter()->layout()->invalidate(); | ||||
|
r140 | } | ||
|
r2273 | void ChartAxis::handleShadesBrushChanged(const QBrush &brush) | ||
|
r140 | { | ||
|
r2131 | foreach (QGraphicsItem *item , m_shades->childItems()) | ||
static_cast<QGraphicsRectItem *>(item)->setBrush(brush); | ||||
|
r140 | } | ||
|
r2273 | void ChartAxis::handleShadesPenChanged(const QPen &pen) | ||
|
r140 | { | ||
|
r2131 | foreach (QGraphicsItem *item , m_shades->childItems()) | ||
static_cast<QGraphicsRectItem *>(item)->setPen(pen); | ||||
|
r176 | } | ||
|
r2273 | void ChartAxis::handleArrowPenChanged(const QPen &pen) | ||
|
r184 | { | ||
|
r2131 | foreach (QGraphicsItem *item , m_arrow->childItems()) | ||
static_cast<QGraphicsLineItem *>(item)->setPen(pen); | ||||
|
r184 | } | ||
|
r2273 | void ChartAxis::handleGridPenChanged(const QPen &pen) | ||
|
r176 | { | ||
|
r2131 | foreach (QGraphicsItem *item , m_grid->childItems()) | ||
static_cast<QGraphicsLineItem *>(item)->setPen(pen); | ||||
|
r2105 | } | ||
|
r2273 | void ChartAxis::handleTitleTextChanged(const QString &title) | ||
|
r497 | { | ||
|
r2277 | QGraphicsLayoutItem::updateGeometry(); | ||
presenter()->layout()->invalidate(); | ||||
|
r2415 | m_title->setText(title); | ||
|
r497 | } | ||
|
r439 | |||
|
r2273 | void ChartAxis::handleTitlePenChanged(const QPen &pen) | ||
|
r2153 | { | ||
m_title->setPen(pen); | ||||
} | ||||
|
r2273 | void ChartAxis::handleTitleBrushChanged(const QBrush &brush) | ||
|
r2153 | { | ||
m_title->setBrush(brush); | ||||
} | ||||
|
r2273 | void ChartAxis::handleTitleFontChanged(const QFont &font) | ||
|
r2153 | { | ||
if(m_title->font() != font){ | ||||
m_title->setFont(font); | ||||
QGraphicsLayoutItem::updateGeometry(); | ||||
presenter()->layout()->invalidate(); | ||||
} | ||||
} | ||||
|
r2273 | void ChartAxis::handleVisibleChanged(bool visible) | ||
|
r1729 | { | ||
|
r2277 | setVisible(visible); | ||
|
r2297 | if(!visible) { | ||
m_grid->setVisible(visible); | ||||
m_arrow->setVisible(visible); | ||||
m_shades->setVisible(visible); | ||||
m_labels->setVisible(visible); | ||||
m_title->setVisible(visible); | ||||
}else { | ||||
m_grid->setVisible(m_axis->isGridLineVisible()); | ||||
m_arrow->setVisible(m_axis->isLineVisible()); | ||||
m_shades->setVisible(m_axis->shadesVisible()); | ||||
m_labels->setVisible(m_axis->labelsVisible()); | ||||
m_title->setVisible(m_axis->isTitleVisible()); | ||||
} | ||||
|
r2345 | if(presenter()) presenter()->layout()->invalidate(); | ||
|
r1729 | } | ||
|
r2273 | void ChartAxis::handleRangeChanged(qreal min, qreal max) | ||
|
r439 | { | ||
|
r2277 | Q_UNUSED(min); | ||
Q_UNUSED(max); | ||||
|
r1534 | |||
|
r2277 | if (!isEmpty()) { | ||
|
r2093 | |||
|
r2277 | QVector<qreal> layout = calculateLayout(); | ||
updateLayout(layout); | ||||
QSizeF before = effectiveSizeHint(Qt::PreferredSize); | ||||
QSizeF after = sizeHint(Qt::PreferredSize); | ||||
|
r439 | |||
|
r2277 | if (before != after) { | ||
QGraphicsLayoutItem::updateGeometry(); | ||||
//we don't want to call invalidate on layout, since it will change minimum size of component, | ||||
//which we would like to avoid since it causes nasty flips when scrolling or zooming, | ||||
//instead recalculate layout and use plotArea for extra space. | ||||
presenter()->layout()->setGeometry(presenter()->layout()->geometry()); | ||||
} | ||||
} | ||||
|
r1890 | |||
|
r1965 | } | ||
|
r2273 | //helpers | ||
|
r2111 | |||
|
r2273 | QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format) | ||
|
r2111 | { | ||
|
r2407 | //TODO: Q_ASSERT(m_max > m_min); | ||
//TODO: Q_ASSERT(ticks > 1); | ||||
|
r2111 | QStringList labels; | ||
|
r2273 | if(max <= min || ticks < 1){ | ||
return labels; | ||||
} | ||||
|
r2111 | |||
|
r2273 | int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | ||
n++; | ||||
|
r2111 | |||
|
r2131 | if (format.isNull()) { | ||
for (int i = 0; i < ticks; i++) { | ||||
|
r2273 | qreal value = min + (i * (max - min) / (ticks - 1)); | ||
|
r2131 | labels << QString::number(value, 'f', n); | ||
|
r2111 | } | ||
|
r2131 | } else { | ||
|
r2241 | QByteArray array = format.toLatin1(); | ||
|
r2131 | for (int i = 0; i < ticks; i++) { | ||
|
r2273 | qreal value = min + (i * (max - min) / (ticks - 1)); | ||
|
r2268 | if (format.contains("d") | ||
|| format.contains("i") | ||||
|| format.contains("c")) | ||||
labels << QString().sprintf(array, (qint64)value); | ||||
else if (format.contains("u") | ||||
|| format.contains("o") | ||||
|| format.contains("x", Qt::CaseInsensitive)) | ||||
labels << QString().sprintf(array, (quint64)value); | ||||
|
r2269 | else if (format.contains("f", Qt::CaseInsensitive) | ||
|| format.contains("e", Qt::CaseInsensitive) | ||||
|| format.contains("g", Qt::CaseInsensitive)) | ||||
|
r2268 | labels << QString().sprintf(array, value); | ||
|
r2323 | else | ||
labels << QString(); | ||||
|
r2111 | } | ||
} | ||||
return labels; | ||||
} | ||||
|
r2274 | QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format) | ||
{ | ||||
// Q_ASSERT(m_max > m_min); | ||||
// Q_ASSERT(ticks > 1); | ||||
QStringList labels; | ||||
int n = 0; | ||||
if (ticks > 1) | ||||
n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0); | ||||
n++; | ||||
int firstTick; | ||||
if (base > 1) | ||||
|
r2275 | firstTick = ceil(log10(min) / log10(base)); | ||
|
r2274 | else | ||
|
r2275 | firstTick = ceil(log10(max) / log10(base)); | ||
|
r2274 | |||
if (format.isNull()) { | ||||
for (int i = firstTick; i < ticks + firstTick; i++) { | ||||
qreal value = qPow(base, i); | ||||
labels << QString::number(value, 'f', n); | ||||
} | ||||
} else { | ||||
|
r2277 | QByteArray array = format.toLatin1(); | ||
|
r2274 | for (int i = firstTick; i < ticks + firstTick; i++) { | ||
qreal value = qPow(base, i); | ||||
|
r2293 | if (format.contains("d") | ||
|| format.contains("i") | ||||
|| format.contains("c")) | ||||
labels << QString().sprintf(array, (qint64)value); | ||||
else if (format.contains("u") | ||||
|| format.contains("o") | ||||
|| format.contains("x", Qt::CaseInsensitive)) | ||||
labels << QString().sprintf(array, (quint64)value); | ||||
else if (format.contains("f", Qt::CaseInsensitive) | ||||
|| format.contains("e", Qt::CaseInsensitive) | ||||
|| format.contains("g", Qt::CaseInsensitive)) | ||||
labels << QString().sprintf(array, value); | ||||
|
r2323 | else | ||
labels << QString(); | ||||
|
r2274 | } | ||
} | ||||
return labels; | ||||
} | ||||
|
r2273 | QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format) | ||
|
r2111 | { | ||
|
r2407 | //TODO: Q_ASSERT(m_max > m_min); | ||
//TODO: Q_ASSERT(ticks > 1); | ||||
|
r2111 | QStringList labels; | ||
|
r2273 | |||
if(max <= min || ticks < 1) { | ||||
return labels; | ||||
} | ||||
int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0); | ||||
|
r2111 | n++; | ||
|
r2131 | for (int i = 0; i < ticks; i++) { | ||
|
r2273 | qreal value = min + (i * (max - min) / (ticks - 1)); | ||
|
r2111 | labels << QDateTime::fromMSecsSinceEpoch(value).toString(format); | ||
} | ||||
return labels; | ||||
} | ||||
|
r2412 | QRect ChartAxis::labelBoundingRect(const QFontMetrics &fn, const QString &label) const | ||
{ | ||||
QRect boundingRect = fn.boundingRect(label); | ||||
// Take label rotation into account | ||||
if (m_labelsAngle) { | ||||
QTransform transform; | ||||
transform.rotate(m_labelsAngle); | ||||
boundingRect = transform.mapRect(boundingRect); | ||||
} | ||||
return boundingRect; | ||||
} | ||||
|
r1006 | #include "moc_chartaxis_p.cpp" | ||
|
r67 | |||
QTCOMMERCIALCHART_END_NAMESPACE | ||||