summaryrefslogtreecommitdiffstats
path: root/src/axis/valueaxis/chartvalueaxisx.cpp
diff options
context:
space:
mode:
authorMichal Klocek <Michal.Klocek@digia.com>2012-11-16 13:21:46 +0200
committerMichal Klocek <Michal.Klocek@digia.com>2012-11-26 14:58:47 +0200
commit1c49aa901cb25b0bbdeb4922784fec273b97e781 (patch)
tree21469c4bf6070f109cb4dc12472f641c37644674 /src/axis/valueaxis/chartvalueaxisx.cpp
parentb1616762bd1e13608c1040c543e909698670b519 (diff)
Refactors internals
* rewrite axisUpdated signal handling * create handlers for each property of axis * decouple chartdataset, presenter, theme * adds theme manager * adds axis add/remove/attach/detach handling * refactors createGraphics * add initializers (graphics,domain,theme,animations) * refactor the way the charts are constructed (decouple form presenter) * fix initialization issues with qchart * refactor domain logic to handle also geometry size for charts * delegate xyseries geometry calculation to domian * fix lazy initialization of animations * remove hadnleGeomoetryChanged * add shared pointers to handle reference count for domain * moves nice number algorithm to domain * adds applyNiceNumbers(), depreciate setNiceNumbers * refactor multiple charts handling * domain is shared object * each domain can have multiple axis for controlling * multiple charts share now the same domain
Diffstat (limited to 'src/axis/valueaxis/chartvalueaxisx.cpp')
-rw-r--r--src/axis/valueaxis/chartvalueaxisx.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/axis/valueaxis/chartvalueaxisx.cpp b/src/axis/valueaxis/chartvalueaxisx.cpp
index 8cffb153..ce9113bb 100644
--- a/src/axis/valueaxis/chartvalueaxisx.cpp
+++ b/src/axis/valueaxis/chartvalueaxisx.cpp
@@ -26,14 +26,16 @@
#include <QGraphicsLayout>
#include <QFontMetrics>
#include <qmath.h>
+#include <QDebug>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
-ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, ChartPresenter *presenter)
- : HorizontalAxis(axis, presenter),
- m_tickCount(0), m_axis(axis)
+ChartValueAxisX::ChartValueAxisX(QValueAxis *axis, QGraphicsItem* item )
+ : HorizontalAxis(axis, item),
+ m_axis(axis)
{
+ QObject::connect(m_axis,SIGNAL(tickCountChanged(int)),this, SLOT(handleTickCountChanged(int)));
}
ChartValueAxisX::~ChartValueAxisX()
@@ -42,14 +44,16 @@ ChartValueAxisX::~ChartValueAxisX()
QVector<qreal> ChartValueAxisX::calculateLayout() const
{
- Q_ASSERT(m_tickCount >= 2);
+ int tickCount = m_axis->tickCount();
+
+ Q_ASSERT(tickCount >= 2);
QVector<qreal> points;
- points.resize(m_tickCount);
+ points.resize(tickCount);
const QRectF &gridRect = gridGeometry();
- const qreal deltaX = gridRect.width() / (m_tickCount - 1);
- for (int i = 0; i < m_tickCount; ++i) {
+ const qreal deltaX = gridRect.width() / (tickCount - 1);
+ for (int i = 0; i < tickCount; ++i) {
points[i] = i * deltaX + gridRect.left();
}
return points;
@@ -60,18 +64,16 @@ void ChartValueAxisX::updateGeometry()
const QVector<qreal>& layout = ChartAxis::layout();
if (layout.isEmpty())
return;
- setLabels(createValueLabels(layout.size()));
+ setLabels(createValueLabels(min(),max(),layout.size(),m_axis->labelFormat()));
HorizontalAxis::updateGeometry();
}
-void ChartValueAxisX::handleAxisUpdated()
+void ChartValueAxisX::handleTickCountChanged(int tick)
{
- if (m_tickCount != m_axis->tickCount()) {
- m_tickCount = m_axis->tickCount();
- presenter()->layout()->invalidate();
- }
-
- ChartAxis::handleAxisUpdated();
+ Q_UNUSED(tick);
+ if(presenter()) presenter()->layout()->invalidate();
+ //QVector<qreal> layout = calculateLayout();
+ //updateLayout(layout);
}
QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
@@ -82,13 +84,18 @@ QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
QSizeF sh;
QSizeF base = HorizontalAxis::sizeHint(which, constraint);
- QStringList ticksList = createValueLabels(m_tickCount);
+ QStringList ticksList = createValueLabels(min(),max(),m_axis->tickCount(),m_axis->labelFormat());
qreal width = 0;
qreal height = 0;
+ int count = 1;
+
+ if(!ticksList.empty()) {
+ count = qMax(ticksList.last().count(),ticksList.first().count());
+ }
+
switch (which) {
case Qt::MinimumSize:{
- int count = qMax(ticksList.last().count(),ticksList.first().count());
count = qMin(count,5);
width = fn.averageCharWidth() * count;
height = fn.height() + labelPadding();
@@ -98,7 +105,6 @@ QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
break;
}
case Qt::PreferredSize:{
- int count = qMax(ticksList.last().count(),ticksList.first().count());
width=fn.averageCharWidth() * count;
height=fn.height()+labelPadding();
width=qMax(width,base.width());
@@ -113,4 +119,6 @@ QSizeF ChartValueAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) c
return sh;
}
+#include "moc_chartvalueaxisx_p.cpp"
+
QTCOMMERCIALCHART_END_NAMESPACE