##// END OF EJS Templates
Simple UI testing added using mago(LDTP):...
Simple UI testing added using mago(LDTP): -new basic test application added -new script added

File last commit:

r2131:730996457e67
r2132:45eed4d8b56a
Show More
verticalaxis.cpp
144 lines | 5.5 KiB | text/x-c | CppLexer
/ src / axis / verticalaxis.cpp
Michal Klocek
Refactors axis updateGeometry handling...
r2111 /****************************************************************************
**
** 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$
**
****************************************************************************/
#include "verticalaxis_p.h"
#include "qabstractaxis.h"
#include <QFontMetrics>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Jani Honkonen
src folder: another massive victory for coding style police
r2131 VerticalAxis::VerticalAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis)
: ChartAxis(axis, presenter, intervalAxis)
Michal Klocek
Refactors axis updateGeometry handling...
r2111 {
}
VerticalAxis::~VerticalAxis()
{
}
void VerticalAxis::updateGeometry()
{
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
QStringList labelList = labels();
QList<QGraphicsItem *> lines = lineItems();
QList<QGraphicsItem *> labels = labelItems();
QList<QGraphicsItem *> shades = shadeItems();
QList<QGraphicsItem *> axis = arrowItems();
Q_ASSERT(labels.size() == labelList.size());
Q_ASSERT(layout.size() == labelList.size());
Jani Honkonen
src folder: another massive victory for coding style police
r2131 const QRectF &axisRect = axisGeometry();
const QRectF &gridRect = gridGeometry();
Michal Klocek
Refactors axis updateGeometry handling...
r2111
qreal height = axisRect.bottom();
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem *>(axis.at(0));
Michal Klocek
Refactors axis updateGeometry handling...
r2111
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (alignment() == Qt::AlignLeft)
lineItem->setLine(axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom());
else if (alignment() == Qt::AlignRight)
lineItem->setLine(axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom());
Michal Klocek
Refactors axis updateGeometry handling...
r2111
QFontMetrics fn(font());
for (int i = 0; i < layout.size(); ++i) {
Jani Honkonen
src folder: another massive victory for coding style police
r2131 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1));
QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
Michal Klocek
Refactors axis updateGeometry handling...
r2111
//grid line
Jani Honkonen
src folder: another massive victory for coding style police
r2131 gridItem->setLine(gridRect.left() , layout[i], gridRect.right(), layout[i]);
Michal Klocek
Refactors axis updateGeometry handling...
r2111
//label text
QString text = labelList.at(i);
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (fn.boundingRect(text).width() > axisRect.right() - axisRect.left() - labelPadding()) {
Michal Klocek
Refactors axis updateGeometry handling...
r2111 QString label = text + "...";
while (fn.boundingRect(label).width() > axisRect.right() - axisRect.left() - labelPadding() && label.length() > 3)
Jani Honkonen
src folder: another massive victory for coding style police
r2131 label.remove(label.length() - 4, 1);
Michal Klocek
Refactors axis updateGeometry handling...
r2111 labelItem->setText(label);
Jani Honkonen
src folder: another massive victory for coding style police
r2131 } else {
Michal Klocek
Refactors axis updateGeometry handling...
r2111 labelItem->setText(text);
}
Jani Honkonen
src folder: another massive victory for coding style police
r2131 const QRectF &rect = labelItem->boundingRect();
Michal Klocek
Refactors axis updateGeometry handling...
r2111 QPointF center = rect.center();
labelItem->setTransformOriginPoint(center.x(), center.y());
//ticks and label position
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (alignment() == Qt::AlignLeft) {
labelItem->setPos(axisRect.right() - rect.width() - labelPadding() , layout[i] - center.y());
tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]);
} else if (alignment() == Qt::AlignRight) {
labelItem->setPos(axisRect.left() + labelPadding() , layout[i] - center.y());
tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]);
Michal Klocek
Refactors axis updateGeometry handling...
r2111 }
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (intervalAxis() && i + 1 != layout.size()) {
const qreal delta = (layout[i + 1] - layout[i]) / 2;
Michal Klocek
Refactors axis updateGeometry handling...
r2111 labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y());
}
//overlap detection
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (labelItem->pos().y() + rect.height() > height ||
Michal Klocek
Refactors axis updateGeometry handling...
r2111 labelItem->pos().y() + rect.height() > axisRect.bottom() ||
labelItem->pos().y() < axisRect.top()) {
labelItem->setVisible(false);
gridItem->setVisible(false);
tickItem->setVisible(false);
Jani Honkonen
src folder: another massive victory for coding style police
r2131 } else {
Michal Klocek
Refactors axis updateGeometry handling...
r2111 labelItem->setVisible(true);
gridItem->setVisible(true);
Jani Honkonen
src folder: another massive victory for coding style police
r2131 height = labelItem->pos().y();
Michal Klocek
Refactors axis updateGeometry handling...
r2111 }
//shades
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if ((i + 1) % 2 && i > 1) {
QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1));
rectItem->setRect(gridRect.left(), layout[i], gridRect.width(), layout[i - 1] - layout[i]);
Michal Klocek
Refactors axis updateGeometry handling...
r2111 }
// check if the grid line and the axis tick should be shown
qreal y = gridItem->line().p1().y();
if (y < gridRect.top() || y > gridRect.bottom()) {
gridItem->setVisible(false);
tickItem->setVisible(false);
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (intervalAxis() && (labelItem->pos().y() < gridRect.top() || labelItem->pos().y() + rect.height() > gridRect.bottom()))
labelItem->setVisible(false);
Michal Klocek
Refactors axis updateGeometry handling...
r2111 }
}
//begin/end grid line in case labels between
Jani Honkonen
src folder: another massive victory for coding style police
r2131 if (intervalAxis()) {
Michal Klocek
Refactors axis updateGeometry handling...
r2111 QGraphicsLineItem *gridLine;
Jani Honkonen
src folder: another massive victory for coding style police
r2131 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
Michal Klocek
Refactors axis updateGeometry handling...
r2111 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top());
Jani Honkonen
src folder: another massive victory for coding style police
r2131 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size() + 1));
Michal Klocek
Refactors axis updateGeometry handling...
r2111 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
}
}
QTCOMMERCIALCHART_END_NAMESPACE