##// END OF EJS Templates
adds Andy's customer request, first call to createDaultAxis scales whole domain (if on common axis)
adds Andy's customer request, first call to createDaultAxis scales whole domain (if on common axis)

File last commit:

r2407:d108889b4c99
r2408:f065af9daaed
Show More
chartcategoryaxisx.cpp
119 lines | 3.3 KiB | text/x-c | CppLexer
/ src / axis / categoryaxis / chartcategoryaxisx.cpp
Marek Rosa
QIntervalsAxis working somewhat
r1701 /****************************************************************************
**
** 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$
**
****************************************************************************/
Marek Rosa
Renamed QCategoryAxis related files
r1817 #include "chartcategoryaxisx_p.h"
#include "qcategoryaxis.h"
Marek Rosa
QIntervalsAxis working somewhat
r1701 #include "qabstractaxis.h"
#include "chartpresenter_p.h"
#include <QGraphicsLayout>
#include <QFontMetrics>
Michal Klocek
Refactor animator...
r1735 #include <qmath.h>
Marek Rosa
QIntervalsAxis working somewhat
r1701
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactors internals...
r2273 ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item)
: HorizontalAxis(axis, item, true),
Jani Honkonen
src folder: another massive victory for coding style police
r2131 m_axis(axis)
Marek Rosa
QIntervalsAxis working somewhat
r1701 {
}
Marek Rosa
Renamed QCategoryAxis related files
r1817 ChartCategoryAxisX::~ChartCategoryAxisX()
Marek Rosa
QIntervalsAxis working somewhat
r1701 {
}
Marek Rosa
Renamed QCategoryAxis related files
r1817 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
Marek Rosa
QIntervalsAxis working somewhat
r1701 {
Michal Klocek
Refactors axis updateGeometry handling...
r2111 int tickCount = m_axis->categoriesLabels().count() + 1;
Marek Rosa
QIntervalsAxis working somewhat
r1701 QVector<qreal> points;
Marek Rosa
Fixes and tests to Interval axis
r1708
if (tickCount < 2)
return points;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 const QRectF &gridRect = gridGeometry();
Michal Klocek
Fixes categoryaxis sizeHints
r2136 qreal range = max() - min();
Marek Rosa
Fixed range handling in categoryAxis
r1846 if (range > 0) {
points.resize(tickCount);
Michal Klocek
Refactors axis updateGeometry handling...
r2111 qreal scale = gridRect.width() / range;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 for (int i = 0; i < tickCount; ++i) {
Marek Rosa
Fixed range handling in categoryAxis
r1846 if (i < tickCount - 1) {
Michal Klocek
Fixes categoryaxis sizeHints
r2136 int x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left();
Marek Rosa
Fixed range handling in categoryAxis
r1846 points[i] = x;
} else {
Michal Klocek
Fixes categoryaxis sizeHints
r2136 int x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left();
Marek Rosa
Fixed range handling in categoryAxis
r1846 points[i] = x;
}
Jani Honkonen
src folder: another massive victory for coding style police
r2131 }
Marek Rosa
Fixed range handling in categoryAxis
r1846 }
Michal Klocek
Refactors axis updateGeometry handling...
r2111
Marek Rosa
QIntervalsAxis working somewhat
r1701 return points;
}
Marek Rosa
Renamed QCategoryAxis related files
r1817 void ChartCategoryAxisX::updateGeometry()
Michal Klocek
Revert "TODOs removed from code. Undo me after release"...
r2407 {
//TODO: this is not optimal when many categories :( , create only visible lables
Jani Honkonen
src folder: another massive victory for coding style police
r2131 setLabels(m_axis->categoriesLabels() << "");
Michal Klocek
Refactors axis updateGeometry handling...
r2111 HorizontalAxis::updateGeometry();
Marek Rosa
QIntervalsAxis working somewhat
r1701 }
Marek Rosa
Renamed QCategoryAxis related files
r1817 void ChartCategoryAxisX::handleAxisUpdated()
Marek Rosa
Added posibility to replace interval's label in QIntervalsAxis
r1777 {
updateGeometry();
Michal Klocek
Refactors internals...
r2273 //TODO :: ChartAxis::handleAxisUpdated();
Marek Rosa
Added posibility to replace interval's label in QIntervalsAxis
r1777 }
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
Michal Klocek
Refactors layout...
r1965 {
Q_UNUSED(constraint)
Michal Klocek
Refactors axis updateGeometry handling...
r2111 QFontMetrics fn(font());
Michal Klocek
Refactors layout...
r1965 QSizeF sh;
Michal Klocek
Refactors ChartAxis...
r2138 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
Michal Klocek
Fixes categoryaxis sizeHints
r2136 QStringList ticksList = m_axis->categoriesLabels();
Jani Honkonen
src folder: another massive victory for coding style police
r2131 qreal width = 0;
qreal height = 0;
Michal Klocek
Refactors layout...
r1965
switch (which) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 case Qt::MinimumSize:
Michal Klocek
Refactors layout...
r1965 width = fn.boundingRect("...").width();
Michal Klocek
Refactors axis updateGeometry handling...
r2111 height = fn.height() + labelPadding();
Jani Honkonen
src folder: another massive victory for coding style police
r2131 width = qMax(width, base.width());
height += base.height();
sh = QSizeF(width, height);
Michal Klocek
Refactors layout...
r1965 break;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 case Qt::PreferredSize: {
Michal Klocek
Refactors layout:...
r2105
Jani Honkonen
src folder: another massive victory for coding style police
r2131 for (int i = 0; i < ticksList.size(); ++i) {
QRectF rect = fn.boundingRect(ticksList.at(i));
width += rect.width();
height = qMax(rect.height() + labelPadding(), height);
Michal Klocek
Refactors layout...
r1965 }
Jani Honkonen
src folder: another massive victory for coding style police
r2131 width = qMax(width, base.width());
height += base.height();
sh = QSizeF(width, height);
break;
}
default:
Michal Klocek
Refactors layout...
r1965 break;
}
return sh;
}
Marek Rosa
QIntervalsAxis working somewhat
r1701 QTCOMMERCIALCHART_END_NAMESPACE