##// END OF EJS Templates
Fix zooming when presenter dimensions are not integers...
Fix zooming when presenter dimensions are not integers If presenter width (or height) is not an integer, zooming using vertical (or horizontal) rubberband will cause the fixed dimension to change, because rubberband uses QRect instead of QRectF. Fixed by forcing the corresponding plotArea dimension for the fixed rubberband dimension when calling zoomIn() in mouseReleaseEvent. Task-number: QTRD-1905 Reviewed-by: Mika Salmela

File last commit:

r2412:38736d0999b4
r2416:25b2e1c316cb
Show More
chartbarcategoryaxisx.cpp
144 lines | 4.1 KiB | text/x-c | CppLexer
/ src / axis / barcategoryaxis / chartbarcategoryaxisx.cpp
Marek Rosa
Added Chart classes for value and categories axis
r1555 /****************************************************************************
Michal Klocek
Adds scroll support for categories axis
r1716 **
** 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
Added Chart classes for value and categories axis
r1555
Marek Rosa
renamed QBarCategoryAxis related files
r1810 #include "chartbarcategoryaxisx_p.h"
Marek Rosa
Added Chart classes for value and categories axis
r1555 #include "chartpresenter_p.h"
Marek Rosa
renamed QBarCategoryAxis related files
r1810 #include "qbarcategoryaxis_p.h"
Michal Klocek
Fixes layout rounding issue
r2306 #include "chartlayout_p.h"
Michal Klocek
Refactors layout...
r1965 #include <QFontMetrics>
Michal Klocek
Fixes rounding issue with labels numbering
r1720 #include <QDebug>
#include <qmath.h>
Marek Rosa
Added Chart classes for value and categories axis
r1555
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactors internals...
r2273 ChartBarCategoryAxisX::ChartBarCategoryAxisX(QBarCategoryAxis *axis, QGraphicsItem* item)
: HorizontalAxis(axis, item, true),
Jani Honkonen
src folder: another massive victory for coding style police
r2131 m_categoriesAxis(axis)
Marek Rosa
Added Chart classes for value and categories axis
r1555 {
Michal Klocek
Fixes layout rounding issue
r2306 QObject::connect(m_categoriesAxis,SIGNAL(categoriesChanged()),this, SLOT(handleCategoriesChanged()));
handleCategoriesChanged();
Marek Rosa
Added Chart classes for value and categories axis
r1555 }
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 ChartBarCategoryAxisX::~ChartBarCategoryAxisX()
sauimone
categories axis implementation
r1570 {
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const
Marek Rosa
Added Chart classes for value and categories axis
r1555 {
Michal Klocek
Updates axis drawing code...
r2133 QVector<qreal> points;
const QRectF& gridRect = gridGeometry();
qreal range = max() - min();
const qreal delta = gridRect.width()/range;
Marek Rosa
Added Chart classes for value and categories axis
r1555
Michal Klocek
Updates axis drawing code...
r2133 if(delta<2) return points;
qreal offset =-min()-0.5;
offset = int(offset * delta)%int(delta);
Michal Klocek
Refactors axis updateGeometry handling...
r2111
Michal Klocek
Updates axis drawing code...
r2133 int count = qFloor(range);
if(count < 1 ) return points;
Michal Klocek
Fixes rounding issue with labels numbering
r1720
Michal Klocek
Updates axis drawing code...
r2133 points.resize(count+2);
Michal Klocek
Adds scroll support for categories axis
r1716
Michal Klocek
Updates axis drawing code...
r2133 for (int i = 0; i < count+2; ++i) {
Michal Klocek
Reimplement zoom/scroll hanling for barcategoryaxis Y
r2145 points[i] = offset + i * delta + gridRect.left();
Marek Rosa
Added Chart classes for value and categories axis
r1555 }
Michal Klocek
Updates axis drawing code...
r2133
Marek Rosa
Added Chart classes for value and categories axis
r1555 return points;
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& layout) const
Michal Klocek
Fixes rounding issue with labels numbering
r1720 {
Michal Klocek
Refactors axis updateGeometry handling...
r2111 QStringList result ;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 const QRectF &gridRect = gridGeometry();
qreal d = (max() - min()) / gridRect.width();
Michal Klocek
Reimplement zoom/scroll hanling for barcategoryaxis Y
r2145
Jani Honkonen
src folder: another massive victory for coding style police
r2131 for (int i = 0; i < layout.count() - 1; ++i) {
qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5));
Michal Klocek
Refactors layout:...
r2105 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
Michal Klocek
Fixes rounding issue with labels numbering
r1720 result << m_categoriesAxis->categories().at(x);
Jani Honkonen
src folder: another massive victory for coding style police
r2131 } else {
Michal Klocek
Refactors layout:...
r2105 // No label for x coordinate
result << "";
}
Michal Klocek
Fixes rounding issue with labels numbering
r1720 }
result << "";
return result;
}
Marek Rosa
Renamed barcategory grephics item class which has been previously ommited
r1918 void ChartBarCategoryAxisX::updateGeometry()
Marek Rosa
Added Chart classes for value and categories axis
r1555 {
const QVector<qreal>& layout = ChartAxis::layout();
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (layout.isEmpty())
return;
Michal Klocek
Refactors axis updateGeometry handling...
r2111 setLabels(createCategoryLabels(layout));
HorizontalAxis::updateGeometry();
Marek Rosa
Added Chart classes for value and categories axis
r1555 }
Michal Klocek
Fixes layout rounding issue
r2306 void ChartBarCategoryAxisX::handleCategoriesChanged()
Michal Klocek
Fixes missing update barcategory...
r1643 {
Michal Klocek
Fixes even more missing layout update calls
r2335 QGraphicsLayoutItem::updateGeometry();
Michal Klocek
Fixes layout rounding issue
r2306 if(presenter()) presenter()->layout()->invalidate();
Michal Klocek
Fixes missing update barcategory...
r1643 }
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QSizeF ChartBarCategoryAxisX::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 layout rounding issue
r2306 QStringList ticksList = m_categoriesAxis->categories();
Michal Klocek
Refactors layout...
r1965
Michal Klocek
Updates axis drawing code...
r2133 qreal width=0;
qreal height=0;
Miikka Heikkinen
Fix axis sizehints when labels are angled...
r2412 switch (which) {
case Qt::MinimumSize: {
QRectF boundingRect = labelBoundingRect(fn, "...");
width = qMax(boundingRect.width(), base.width());
height = boundingRect.height() + labelPadding();
Michal Klocek
Updates axis drawing code...
r2133 height += base.height();
Miikka Heikkinen
Fix axis sizehints when labels are angled...
r2412 sh = QSizeF(width, height);
Michal Klocek
Updates axis drawing code...
r2133 break;
Miikka Heikkinen
Fix axis sizehints when labels are angled...
r2412 }
Michal Klocek
Updates axis drawing code...
r2133 case Qt::PreferredSize:{
Miikka Heikkinen
Fix axis sizehints when labels are angled...
r2412 int labelHeight = 0;
foreach (const QString& s, ticksList) {
QRect rect = labelBoundingRect(fn, s);
labelHeight = qMax(rect.height(), labelHeight);
Michal Klocek
Updates axis drawing code...
r2133 width += rect.width();
}
Miikka Heikkinen
Fix axis sizehints when labels are angled...
r2412 height = labelHeight + labelPadding();
Michal Klocek
Updates axis drawing code...
r2133 height += base.height();
Miikka Heikkinen
Fix axis sizehints when labels are angled...
r2412 width = qMax(width, base.width());
sh = QSizeF(width, height);
Michal Klocek
Updates axis drawing code...
r2133 break;
}
default:
break;
Miikka Heikkinen
Fix axis sizehints when labels are angled...
r2412 }
return sh;
Michal Klocek
Refactors layout...
r1965 }
Michal Klocek
Fixes layout rounding issue
r2306 #include "moc_chartbarcategoryaxisx_p.cpp"
Marek Rosa
Added Chart classes for value and categories axis
r1555 QTCOMMERCIALCHART_END_NAMESPACE