diff options
Diffstat (limited to 'src/barchart/vertical')
-rw-r--r-- | src/barchart/vertical/bar/barchartitem.cpp | 125 | ||||
-rw-r--r-- | src/barchart/vertical/bar/barchartitem_p.h | 57 | ||||
-rw-r--r-- | src/barchart/vertical/bar/qbarseries.cpp | 124 | ||||
-rw-r--r-- | src/barchart/vertical/bar/qbarseries.h | 45 | ||||
-rw-r--r-- | src/barchart/vertical/bar/qbarseries_p.h | 52 | ||||
-rw-r--r-- | src/barchart/vertical/percent/percentbarchartitem.cpp | 171 | ||||
-rw-r--r-- | src/barchart/vertical/percent/percentbarchartitem_p.h | 59 | ||||
-rw-r--r-- | src/barchart/vertical/percent/qpercentbarseries.cpp | 125 | ||||
-rw-r--r-- | src/barchart/vertical/percent/qpercentbarseries.h | 46 | ||||
-rw-r--r-- | src/barchart/vertical/percent/qpercentbarseries_p.h | 51 | ||||
-rw-r--r-- | src/barchart/vertical/stacked/qstackedbarseries.cpp | 122 | ||||
-rw-r--r-- | src/barchart/vertical/stacked/qstackedbarseries.h | 46 | ||||
-rw-r--r-- | src/barchart/vertical/stacked/qstackedbarseries_p.h | 51 | ||||
-rw-r--r-- | src/barchart/vertical/stacked/stackedbarchartitem.cpp | 137 | ||||
-rw-r--r-- | src/barchart/vertical/stacked/stackedbarchartitem_p.h | 58 |
15 files changed, 0 insertions, 1269 deletions
diff --git a/src/barchart/vertical/bar/barchartitem.cpp b/src/barchart/vertical/bar/barchartitem.cpp deleted file mode 100644 index 9a57325a..00000000 --- a/src/barchart/vertical/bar/barchartitem.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 "barchartitem_p.h" -#include "bar_p.h" -#include "qabstractbarseries_p.h" -#include "qbarset.h" -#include "qbarset_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -BarChartItem::BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : - AbstractBarChartItem(series, item) -{ - connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), - this, SLOT(handleLabelsPositionChanged())); - connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); -} - -void BarChartItem::initializeLayout() -{ - qreal categoryCount = m_series->d_func()->categoryCount(); - qreal setCount = m_series->count(); - qreal barWidth = m_series->d_func()->barWidth(); - - m_layout.clear(); - for(int category = 0; category < categoryCount; category++) { - for (int set = 0; set < setCount; set++) { - QRectF rect; - QPointF topLeft; - QPointF bottomRight; - - if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { - topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY()), m_validData); - bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, domain()->minY()), m_validData); - } else { - topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0), m_validData); - bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0), m_validData); - } - - if (!m_validData) - return; - rect.setTopLeft(topLeft); - rect.setBottomRight(bottomRight); - m_layout.append(rect.normalized()); - } - } -} - -QVector<QRectF> BarChartItem::calculateLayout() -{ - QVector<QRectF> layout; - - // Use temporary qreals for accuracy - qreal categoryCount = m_series->d_func()->categoryCount(); - qreal setCount = m_series->count(); - qreal barWidth = m_series->d_func()->barWidth(); - - for(int category = 0; category < categoryCount; category++) { - for (int set = 0; set < setCount; set++) { - qreal value = m_series->barSets().at(set)->at(category); - QRectF rect; - QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value), m_validData); - QPointF bottomRight; - if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) - bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()), m_validData); - else - bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0), m_validData); - - rect.setTopLeft(topLeft); - rect.setBottomRight(bottomRight); - layout.append(rect.normalized()); - } - } - - return layout; -} - -void BarChartItem::handleLabelsPositionChanged() -{ - positionLabels(); -} - -void BarChartItem::positionLabels() -{ - for (int i = 0; i < m_layout.count(); i++) { - QGraphicsTextItem *label = m_labels.at(i); - qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); - qreal yPos = 0; - - int offset = m_bars.at(i)->pen().width() / 2 + 2; - if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) - yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) - yPos = m_layout.at(i).top() - offset; - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) - yPos = m_layout.at(i).bottom() - label->boundingRect().height() + offset; - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) - yPos = m_layout.at(i).top() - label->boundingRect().height() + offset; - - label->setPos(xPos, yPos); - label->setZValue(zValue() + 1); - } -} - -#include "moc_barchartitem_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/bar/barchartitem_p.h b/src/barchart/vertical/bar/barchartitem_p.h deleted file mode 100644 index b94e9c34..00000000 --- a/src/barchart/vertical/bar/barchartitem_p.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -// W A R N I N G -// ------------- -// -// This file is not part of the Qt Enterprise Chart API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - - -#ifndef BARCHARTITEM_H -#define BARCHARTITEM_H - -#include "abstractbarchartitem_p.h" -#include "qstackedbarseries.h" -#include <QGraphicsItem> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class BarChartItem : public AbstractBarChartItem -{ - Q_OBJECT -public: - BarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); - -private slots: - void handleLabelsPositionChanged(); - void positionLabels(); - -private: - virtual QVector<QRectF> calculateLayout(); - void initializeLayout(); -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // BARCHARTITEM_H diff --git a/src/barchart/vertical/bar/qbarseries.cpp b/src/barchart/vertical/bar/qbarseries.cpp deleted file mode 100644 index 780f5837..00000000 --- a/src/barchart/vertical/bar/qbarseries.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 "qbarseries.h" -#include "qbarseries_p.h" -#include "barchartitem_p.h" -#include "chartdataset_p.h" -#include "charttheme_p.h" -#include "qvalueaxis.h" -#include "qbarcategoryaxis.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -/*! - \class QBarSeries - \inmodule Qt Charts - \brief Series for creating bar chart. - \mainclass - - QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars - as groups, where bars in same category are grouped next to each other. QBarSeries groups the data - from sets to categories, which are defined by a QStringList. - - See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. - \image examples_barchart.png - - \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries -*/ -#ifdef QDOC_QT5 -/*! - \qmltype BarSeries - \instantiates QBarSeries - \inqmlmodule QtCommercial.Chart - - \include doc/src/barseries.qdocinc -*/ -#else -/*! - \qmlclass BarSeries QBarSeries - - \include ../doc/src/barseries.qdocinc -*/ -#endif - -/*! - Constructs empty QBarSeries. - QBarSeries is QObject which is a child of a \a parent. -*/ -QBarSeries::QBarSeries(QObject *parent) - : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) -{ - -} - -/*! - Returns QAbstractSeries::SeriesTypeBar. -*/ -QAbstractSeries::SeriesType QBarSeries::type() const -{ - return QAbstractSeries::SeriesTypeBar; -} - -/*! - Destructor. Removes series from chart. -*/ -QBarSeries::~QBarSeries() -{ - Q_D(QBarSeries); - if (d->m_chart) - d->m_chart->removeSeries(this); -} -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) -{ - -} - -void QBarSeriesPrivate::initializeDomain() -{ - qreal minX(domain()->minX()); - qreal minY(domain()->minY()); - qreal maxX(domain()->maxX()); - qreal maxY(domain()->maxY()); - - qreal x = categoryCount(); - minX = qMin(minX, - (qreal)0.5); - minY = qMin(minY, min()); - maxX = qMax(maxX, x - (qreal)0.5); - maxY = qMax(maxY, max()); - - domain()->setRange(minX, maxX, minY, maxY); -} - - -void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) -{ - Q_Q(QBarSeries); - BarChartItem *bar = new BarChartItem(q,parent); - m_item.reset(bar); - QAbstractSeriesPrivate::initializeGraphics(parent); -} - -#include "moc_qbarseries.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE - diff --git a/src/barchart/vertical/bar/qbarseries.h b/src/barchart/vertical/bar/qbarseries.h deleted file mode 100644 index 4e38543e..00000000 --- a/src/barchart/vertical/bar/qbarseries.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -#ifndef QBARSERIES_H -#define QBARSERIES_H - -#include <qabstractbarseries.h> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QBarSeriesPrivate; - -class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractBarSeries -{ - Q_OBJECT -public: - explicit QBarSeries(QObject *parent = 0); - ~QBarSeries(); - QAbstractSeries::SeriesType type() const; - -private: - Q_DECLARE_PRIVATE(QBarSeries) - Q_DISABLE_COPY(QBarSeries) -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // QBARSERIES_H diff --git a/src/barchart/vertical/bar/qbarseries_p.h b/src/barchart/vertical/bar/qbarseries_p.h deleted file mode 100644 index e6d3a8a7..00000000 --- a/src/barchart/vertical/bar/qbarseries_p.h +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -// W A R N I N G -// ------------- -// -// This file is not part of the Qt Enterprise Chart API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef QBARSERIES_P_H -#define QBARSERIES_P_H - -#include "qabstractbarseries_p.h" -#include "abstractdomain_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - - -class QBarSeriesPrivate: public QAbstractBarSeriesPrivate -{ -public: - QBarSeriesPrivate(QBarSeries *q); - void initializeGraphics(QGraphicsItem* parent); - void initializeDomain(); - -private: - Q_DECLARE_PUBLIC(QBarSeries) -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // QBARSERIES_P_H diff --git a/src/barchart/vertical/percent/percentbarchartitem.cpp b/src/barchart/vertical/percent/percentbarchartitem.cpp deleted file mode 100644 index d5a8430b..00000000 --- a/src/barchart/vertical/percent/percentbarchartitem.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 "percentbarchartitem_p.h" -#include "bar_p.h" -#include "qabstractbarseries_p.h" -#include "qbarset.h" -#include "qbarset_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : - AbstractBarChartItem(series, item) -{ - connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), - this, SLOT(handleLabelsPositionChanged())); - connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); -} - -void PercentBarChartItem::initializeLayout() -{ - qreal categoryCount = m_series->d_func()->categoryCount(); - qreal setCount = m_series->count(); - qreal barWidth = m_series->d_func()->barWidth(); - - m_layout.clear(); - for(int category = 0; category < categoryCount; category++) { - for (int set = 0; set < setCount; set++) { - QRectF rect; - QPointF topLeft; - QPointF bottomRight; - - if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { - topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()), m_validData); - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()), m_validData); - } else { - topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0), m_validData); - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0), m_validData); - } - - if (!m_validData) - return; - - rect.setTopLeft(topLeft); - rect.setBottomRight(bottomRight); - m_layout.append(rect.normalized()); - } - } -} - -QVector<QRectF> PercentBarChartItem::calculateLayout() -{ - QVector<QRectF> layout; - - // Use temporary qreals for accuracy - qreal categoryCount = m_series->d_func()->categoryCount(); - qreal setCount = m_series->count(); - qreal barWidth = m_series->d_func()->barWidth(); - - for(int category = 0; category < categoryCount; category++) { - qreal sum = 0; - qreal categorySum = m_series->d_func()->categorySum(category); - for (int set = 0; set < setCount; set++) { - qreal value = m_series->barSets().at(set)->at(category); - QRectF rect; - qreal topY = 0; - qreal newSum = value + sum; - if (newSum > 0) - topY = 100 * newSum / categorySum; - qreal bottomY = 0; - if (sum > 0) - bottomY = 100 * sum / categorySum; - QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, topY), m_validData); - QPointF bottomRight; - if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? bottomY : domain()->minY()), m_validData); - else - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? bottomY : 0), m_validData); - - rect.setTopLeft(topLeft); - rect.setBottomRight(bottomRight); - layout.append(rect.normalized()); - sum = newSum; - } - } - return layout; -} - -void PercentBarChartItem::handleUpdatedBars() -{ - // Handle changes in pen, brush, labels etc. - int categoryCount = m_series->d_func()->categoryCount(); - int setCount = m_series->count(); - int itemIndex(0); - static const QString valueTag(QLatin1String("@value")); - - for (int category = 0; category < categoryCount; category++) { - for (int set = 0; set < setCount; set++) { - QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); - Bar *bar = m_bars.at(itemIndex); - bar->setPen(barSet->m_pen); - bar->setBrush(barSet->m_brush); - bar->update(); - - QGraphicsTextItem *label = m_labels.at(itemIndex); - qreal p = m_series->d_func()->percentageAt(set, category) * 100.0; - QString vString(presenter()->numberToString(p, 'f', 0)); - QString valueLabel; - if (m_series->labelsFormat().isEmpty()) { - vString.append("%"); - valueLabel = vString; - } else { - valueLabel = m_series->labelsFormat(); - valueLabel.replace(valueTag, vString); - } - label->setHtml(valueLabel); - label->setFont(barSet->m_labelFont); - label->setDefaultTextColor(barSet->m_labelBrush.color()); - label->update(); - itemIndex++; - } - } -} - -void PercentBarChartItem::handleLabelsPositionChanged() -{ - positionLabels(); -} - -void PercentBarChartItem::positionLabels() -{ - for (int i = 0; i < m_layout.count(); i++) { - QGraphicsTextItem *label = m_labels.at(i); - qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); - qreal yPos = 0; - - int offset = m_bars.at(i)->pen().width() / 2 + 2; - if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) - yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) - yPos = m_layout.at(i).top() - offset; - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) - yPos = m_layout.at(i).bottom() - label->boundingRect().height() + offset; - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) - yPos = m_layout.at(i).top() - label->boundingRect().height() + offset; - - label->setPos(xPos, yPos); - label->setZValue(zValue() + 1); - } -} - -#include "moc_percentbarchartitem_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/percent/percentbarchartitem_p.h b/src/barchart/vertical/percent/percentbarchartitem_p.h deleted file mode 100644 index da9fb897..00000000 --- a/src/barchart/vertical/percent/percentbarchartitem_p.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -// W A R N I N G -// ------------- -// -// This file is not part of the Qt Enterprise Chart API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - - -#ifndef PERCENTBARCHARTITEM_H -#define PERCENTBARCHARTITEM_H - -#include "abstractbarchartitem_p.h" -#include <QGraphicsItem> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QAbstractBarSeries; - -class PercentBarChartItem : public AbstractBarChartItem -{ - Q_OBJECT -public: - PercentBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item = 0); - void handleUpdatedBars(); - -private slots: - void handleLabelsPositionChanged(); - void positionLabels(); - -private: - virtual QVector<QRectF> calculateLayout(); - void initializeLayout(); -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // PERCENTBARCHARTITEM_H diff --git a/src/barchart/vertical/percent/qpercentbarseries.cpp b/src/barchart/vertical/percent/qpercentbarseries.cpp deleted file mode 100644 index 2fde3658..00000000 --- a/src/barchart/vertical/percent/qpercentbarseries.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 "qpercentbarseries.h" -#include "qpercentbarseries_p.h" -#include "percentbarchartitem_p.h" -#include "chartdataset_p.h" -#include "charttheme_p.h" -#include "qvalueaxis.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -/*! - \class QPercentBarSeries - \inmodule Qt Charts - \brief Series for creating percent bar chart. - \mainclass - - QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to - draw bars as stacks, where each bar is shown as percentage of all bars in that category. - QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. - Bars with zero value are not drawn. - - See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a - percent bar chart. - \image examples_percentbarchart.png - - \sa QBarSet, QStackedBarSeries, QAbstractBarSeries -*/ -#ifdef QDOC_QT5 -/*! - \qmltype PercentBarSeries - \instantiates QPercentBarSeries - \inqmlmodule QtCommercial.Chart - - \include doc/src/persentbarseries.qdocinc -*/ -#else -/*! - \qmlclass PercentBarSeries QPercentBarSeries - - \include ../doc/src/persentbarseries.qdocinc -*/ -#endif - -/*! - Constructs empty QPercentBarSeries. - QPercentBarSeries is QObject which is a child of a \a parent. -*/ -QPercentBarSeries::QPercentBarSeries(QObject *parent) - : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) -{ -} - -/*! - Destructor. Removes series from chart. -*/ -QPercentBarSeries::~QPercentBarSeries() -{ - Q_D(QPercentBarSeries); - if (d->m_chart) - d->m_chart->removeSeries(this); -} - -/*! - Returns QAbstractSeries::SeriesTypePercentBar. -*/ -QAbstractSeries::SeriesType QPercentBarSeries::type() const -{ - return QAbstractSeries::SeriesTypePercentBar; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) -{ - -} - -void QPercentBarSeriesPrivate::initializeDomain() -{ - qreal minX(domain()->minX()); - qreal minY(domain()->minY()); - qreal maxX(domain()->maxX()); - qreal maxY(domain()->maxY()); - - qreal x = categoryCount(); - minX = qMin(minX, - (qreal)0.5); - maxX = qMax(maxX, x - (qreal)0.5); - minY = 0; - maxY = 100; - - domain()->setRange(minX, maxX, minY, maxY); -} - - -void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) -{ - Q_Q(QPercentBarSeries); - PercentBarChartItem *bar = new PercentBarChartItem(q,parent); - m_item.reset(bar); - QAbstractSeriesPrivate::initializeGraphics(parent); -} - -#include "moc_qpercentbarseries.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE - diff --git a/src/barchart/vertical/percent/qpercentbarseries.h b/src/barchart/vertical/percent/qpercentbarseries.h deleted file mode 100644 index d6745771..00000000 --- a/src/barchart/vertical/percent/qpercentbarseries.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -#ifndef QPERCENTBARSERIES_H -#define QPERCENTBARSERIES_H - -#include <QStringList> -#include <qabstractbarseries.h> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QPercentBarSeriesPrivate; - -class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QAbstractBarSeries -{ - Q_OBJECT -public: - explicit QPercentBarSeries(QObject *parent = 0); - ~QPercentBarSeries(); - QAbstractSeries::SeriesType type() const; - -private: - Q_DECLARE_PRIVATE(QPercentBarSeries) - Q_DISABLE_COPY(QPercentBarSeries) -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // QPERCENTBARSERIES_H diff --git a/src/barchart/vertical/percent/qpercentbarseries_p.h b/src/barchart/vertical/percent/qpercentbarseries_p.h deleted file mode 100644 index 1ab08430..00000000 --- a/src/barchart/vertical/percent/qpercentbarseries_p.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -// W A R N I N G -// ------------- -// -// This file is not part of the Qt Enterprise Chart API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef QPERCENTBARSERIES_P_H -#define QPERCENTBARSERIES_P_H - -#include "qabstractbarseries_p.h" -#include "abstractdomain_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - - -class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate -{ -public: - QPercentBarSeriesPrivate(QPercentBarSeries *q); - void initializeDomain(); - void initializeGraphics(QGraphicsItem* parent); -private: - Q_DECLARE_PUBLIC(QPercentBarSeries) -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif diff --git a/src/barchart/vertical/stacked/qstackedbarseries.cpp b/src/barchart/vertical/stacked/qstackedbarseries.cpp deleted file mode 100644 index 6ca42806..00000000 --- a/src/barchart/vertical/stacked/qstackedbarseries.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 "qstackedbarseries.h" -#include "qstackedbarseries_p.h" -#include "stackedbarchartitem_p.h" -#include "chartdataset_p.h" -#include "charttheme_p.h" -#include "qvalueaxis.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -/*! - \class QStackedBarSeries - \inmodule Qt Charts - \brief Series for creating stacked bar chart. - \mainclass - - QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars - as stacks, where bars in same category are stacked on top of each other. - QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. - - See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. - \image examples_stackedbarchart.png - - \sa QBarSet, QPercentBarSeries, QAbstractBarSeries -*/ - -#ifdef QDOC_QT5 -/*! - \qmltype StackedBarSeries - \instantiates QStackedBarSeries - \inqmlmodule QtCommercial.Chart - - \include doc/src/stackedbarseries.qdocinc -*/ -#else -/*! - \qmlclass StackedBarSeries QStackedBarSeries - - \include ../doc/src/stackedbarseries.qdocinc -*/ -#endif - -/*! - Constructs empty QStackedBarSeries. - QStackedBarSeries is QObject which is a child of a \a parent. -*/ -QStackedBarSeries::QStackedBarSeries(QObject *parent) - : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) -{ -} - -/*! - Destructor. Removes series from chart. -*/ -QStackedBarSeries::~QStackedBarSeries() -{ - Q_D(QStackedBarSeries); - if (d->m_chart) - d->m_chart->removeSeries(this); -} -/*! - Returns QAbstractSeries::SeriesTypeStackedBar. -*/ -QAbstractSeries::SeriesType QStackedBarSeries::type() const -{ - return QAbstractSeries::SeriesTypeStackedBar; -} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) -{ - -} - -void QStackedBarSeriesPrivate::initializeDomain() -{ - qreal minX(domain()->minX()); - qreal minY(domain()->minY()); - qreal maxX(domain()->maxX()); - qreal maxY(domain()->maxY()); - - qreal x = categoryCount(); - minX = qMin(minX, - (qreal)0.5); - minY = qMin(minY, bottom()); - maxX = qMax(maxX, x - (qreal)0.5); - maxY = qMax(maxY, top()); - - domain()->setRange(minX, maxX, minY, maxY); -} - -void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) -{ - Q_Q(QStackedBarSeries); - StackedBarChartItem *bar = new StackedBarChartItem(q,parent); - m_item.reset(bar); - QAbstractSeriesPrivate::initializeGraphics(parent); -} - -#include "moc_qstackedbarseries.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE - diff --git a/src/barchart/vertical/stacked/qstackedbarseries.h b/src/barchart/vertical/stacked/qstackedbarseries.h deleted file mode 100644 index ca262e03..00000000 --- a/src/barchart/vertical/stacked/qstackedbarseries.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -#ifndef QSTACKEDBARSERIES_H -#define QSTACKEDBARSERIES_H - -#include <QStringList> -#include <qabstractbarseries.h> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class QStackedBarSeriesPrivate; - -class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QAbstractBarSeries -{ - Q_OBJECT -public: - explicit QStackedBarSeries(QObject *parent = 0); - ~QStackedBarSeries(); - QAbstractSeries::SeriesType type() const; - -private: - Q_DECLARE_PRIVATE(QStackedBarSeries) - Q_DISABLE_COPY(QStackedBarSeries) -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // QSTACKEDBARSERIES_H diff --git a/src/barchart/vertical/stacked/qstackedbarseries_p.h b/src/barchart/vertical/stacked/qstackedbarseries_p.h deleted file mode 100644 index 99e0934a..00000000 --- a/src/barchart/vertical/stacked/qstackedbarseries_p.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -// W A R N I N G -// ------------- -// -// This file is not part of the Qt Enterprise Chart API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef QSTACKEDBARSERIES_P_H -#define QSTACKEDBARSERIES_P_H - -#include "qabstractbarseries_p.h" -#include "abstractdomain_p.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - - -class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate -{ -public: - QStackedBarSeriesPrivate(QStackedBarSeries *q); - void initializeGraphics(QGraphicsItem* parent); - void initializeDomain(); -private: - Q_DECLARE_PUBLIC(QStackedBarSeries) -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif diff --git a/src/barchart/vertical/stacked/stackedbarchartitem.cpp b/src/barchart/vertical/stacked/stackedbarchartitem.cpp deleted file mode 100644 index 72bc650a..00000000 --- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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 "stackedbarchartitem_p.h" -#include "bar_p.h" -#include "qbarset_p.h" -#include "qabstractbarseries_p.h" -#include "qbarset.h" - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item) : - AbstractBarChartItem(series, item) -{ - connect(series, SIGNAL(labelsPositionChanged(QAbstractBarSeries::LabelsPosition)), - this, SLOT(handleLabelsPositionChanged())); - connect(series, SIGNAL(labelsFormatChanged(QString)), this, SLOT(positionLabels())); -} - -void StackedBarChartItem::initializeLayout() -{ - qreal categoryCount = m_series->d_func()->categoryCount(); - qreal setCount = m_series->count(); - qreal barWidth = m_series->d_func()->barWidth(); - - m_layout.clear(); - for(int category = 0; category < categoryCount; category++) { - for (int set = 0; set < setCount; set++) { - QRectF rect; - QPointF topLeft; - QPointF bottomRight; - - if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) { - topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()), m_validData); - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()), m_validData); - } else { - topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0), m_validData); - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0), m_validData); - } - - if (!m_validData) - return; - - rect.setTopLeft(topLeft); - rect.setBottomRight(bottomRight); - m_layout.append(rect.normalized()); - } - } -} - -QVector<QRectF> StackedBarChartItem::calculateLayout() -{ - QVector<QRectF> layout; - // Use temporary qreals for accuracy - qreal categoryCount = m_series->d_func()->categoryCount(); - qreal setCount = m_series->count(); - qreal barWidth = m_series->d_func()->barWidth(); - - for(int category = 0; category < categoryCount; category++) { - qreal positiveSum = 0; - qreal negativeSum = 0; - for (int set = 0; set < setCount; set++) { - qreal value = m_series->barSets().at(set)->at(category); - QRectF rect; - QPointF topLeft; - QPointF bottomRight; - if (value < 0) { - bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + negativeSum), m_validData); - if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) - topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : domain()->minY()), m_validData); - else - topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : 0), m_validData); - negativeSum += value; - } else { - topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum), m_validData); - if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY()), m_validData); - else - bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0), m_validData); - positiveSum += value; - } - - rect.setTopLeft(topLeft); - rect.setBottomRight(bottomRight); - layout.append(rect.normalized()); - } - } - return layout; -} - -void StackedBarChartItem::handleLabelsPositionChanged() -{ - positionLabels(); -} - -void StackedBarChartItem::positionLabels() -{ - for (int i = 0; i < m_layout.count(); i++) { - QGraphicsTextItem *label = m_labels.at(i); - qreal xPos = m_layout.at(i).center().x() - label->boundingRect().center().x(); - qreal yPos = 0; - - int offset = m_bars.at(i)->pen().width() / 2 + 2; - if (m_series->labelsPosition() == QAbstractBarSeries::LabelsCenter) - yPos = m_layout.at(i).center().y() - label->boundingRect().center().y(); - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideEnd) - yPos = m_layout.at(i).top() - offset; - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsInsideBase) - yPos = m_layout.at(i).bottom() - label->boundingRect().height() + offset; - else if (m_series->labelsPosition() == QAbstractBarSeries::LabelsOutsideEnd) - yPos = m_layout.at(i).top() - label->boundingRect().height() + offset; - - label->setPos(xPos, yPos); - label->setZValue(zValue() + 1); - } -} - -#include "moc_stackedbarchartitem_p.cpp" - -QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/vertical/stacked/stackedbarchartitem_p.h b/src/barchart/vertical/stacked/stackedbarchartitem_p.h deleted file mode 100644 index f6f645a0..00000000 --- a/src/barchart/vertical/stacked/stackedbarchartitem_p.h +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 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 Enterprise Charts Add-on. -** -** $QT_BEGIN_LICENSE$ -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise 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$ -** -****************************************************************************/ - -// W A R N I N G -// ------------- -// -// This file is not part of the Qt Enterprise Chart API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - - -#ifndef STACKEDBARCHARTITEM_H -#define STACKEDBARCHARTITEM_H - -#include "abstractbarchartitem_p.h" -#include "qstackedbarseries.h" -#include <QGraphicsItem> - -QTCOMMERCIALCHART_BEGIN_NAMESPACE - -class StackedBarChartItem : public AbstractBarChartItem -{ - Q_OBJECT -public: - StackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item =0); - -private slots: - void handleLabelsPositionChanged(); - void positionLabels(); - -private: - virtual QVector<QRectF> calculateLayout(); - void initializeLayout(); - -}; - -QTCOMMERCIALCHART_END_NAMESPACE - -#endif // STACKEDBARCHARTITEM_H |