qbarset.cpp
691 lines
| 17.0 KiB
| text/x-c
|
CppLexer
Titta Heikkala
|
r2845 | /****************************************************************************** | ||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2845 | ** Copyright (C) 2015 The Qt Company Ltd. | ||
** Contact: http://www.qt.io/licensing/ | ||||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2740 | ** This file is part of the Qt Charts module. | ||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2845 | ** $QT_BEGIN_LICENSE:COMM$ | ||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2845 | ** Commercial License Usage | ||
** Licensees holding valid commercial Qt licenses may use this file in | ||||
** accordance with the commercial license agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and The Qt Company. For licensing terms | ||||
** and conditions see http://www.qt.io/terms-conditions. For further | ||||
** information use the contact form at http://www.qt.io/contact-us. | ||||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2845 | ** $QT_END_LICENSE$ | ||
** | ||||
******************************************************************************/ | ||||
Jani Honkonen
|
r794 | |||
Titta Heikkala
|
r2714 | #include <QtCharts/QBarSet> | ||
#include <private/qbarset_p.h> | ||||
#include <private/charthelpers_p.h> | ||||
#include <private/qchart_p.h> | ||||
sauimone
|
r169 | |||
Titta Heikkala
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
sauimone
|
r169 | |||
sauimone
|
r313 | /*! | ||
\class QBarSet | ||||
Titta Heikkala
|
r2639 | \inmodule Qt Charts | ||
Miikka Heikkinen
|
r2520 | \brief Building block for different bar charts. | ||
sauimone
|
r313 | |||
QBarSet represents one set of bars. Set of bars contains one data value for each category. | ||||
First value of set is assumed to belong to first category, second to second category and so on. | ||||
If set has fewer values than there are categories, then the missing values are assumed to be | ||||
at the end of set. For missing values in middle of a set, numerical value of zero is used. | ||||
Titta Heikkala
|
r2814 | Labels for zero value sets are not shown. | ||
sauimone
|
r313 | |||
sauimone
|
r1594 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | ||
sauimone
|
r313 | */ | ||
Titta Heikkala
|
r2639 | /*! | ||
\qmltype BarSet | ||||
\instantiates QBarSet | ||||
Titta Heikkala
|
r2712 | \inqmlmodule QtCharts | ||
Titta Heikkala
|
r2639 | |||
Titta Heikkala
|
r2712 | \brief Building block for different bar charts. | ||
Tero Ahola
|
r1489 | |||
Titta Heikkala
|
r2712 | BarSet represents one set of bars. Set of bars contains one data value for each category. | ||
First value of set is assumed to belong to first category, second to second category and so on. | ||||
If set has fewer values than there are categories, then the missing values are assumed to be | ||||
at the end of set. For missing values in middle of a set, numerical value of zero is used. | ||||
Titta Heikkala
|
r2814 | Labels for zero value sets are not shown. | ||
Titta Heikkala
|
r2712 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | ||
Tero Ahola
|
r1489 | */ | ||
sauimone
|
r313 | |||
Marek Rosa
|
r1361 | /*! | ||
sauimone
|
r1429 | \property QBarSet::label | ||
Miikka Heikkinen
|
r2520 | Defines the label of the bar set. | ||
Tero Ahola
|
r1489 | */ | ||
/*! | ||||
\qmlproperty string BarSet::label | ||||
Miikka Heikkinen
|
r2520 | Defines the label of the bar set. | ||
Marek Rosa
|
r1361 | */ | ||
/*! | ||||
\property QBarSet::pen | ||||
Miikka Heikkinen
|
r2520 | \brief Defines the pen used by the bar set. | ||
Marek Rosa
|
r1361 | */ | ||
/*! | ||||
\property QBarSet::brush | ||||
Miikka Heikkinen
|
r2520 | \brief Defines the brush used by the bar set. | ||
Marek Rosa
|
r1361 | */ | ||
Titta Heikkala
|
r2681 | /*! | ||
\qmlproperty QString BarSet::brushFilename | ||||
The name of the file used as a brush for the set. | ||||
*/ | ||||
Marek Rosa
|
r1361 | /*! | ||
\property QBarSet::labelBrush | ||||
Miikka Heikkinen
|
r2520 | \brief Defines the brush used by the bar set's label. | ||
Marek Rosa
|
r1361 | */ | ||
/*! | ||||
\property QBarSet::labelFont | ||||
Miikka Heikkinen
|
r2520 | \brief Defines the font used by the bar set's label. | ||
Marek Rosa
|
r1361 | */ | ||
Jani Honkonen
|
r1517 | /*! | ||
\qmlproperty Font BarSet::labelFont | ||||
Miikka Heikkinen
|
r2520 | Defines the font used by the bar set's label. | ||
Jani Honkonen
|
r1517 | |||
Titta Heikkala
|
r2639 | See the Qt documentation for more details of Font. | ||
Jani Honkonen
|
r1517 | */ | ||
Tero Ahola
|
r1465 | /*! | ||
\property QBarSet::color | ||||
Tero Ahola
|
r1489 | The fill (brush) color of the bar set. | ||
*/ | ||||
/*! | ||||
\qmlproperty color BarSet::color | ||||
The fill (brush) color of the bar set. | ||||
Tero Ahola
|
r1465 | */ | ||
/*! | ||||
\property QBarSet::borderColor | ||||
Tero Ahola
|
r1489 | The line (pen) color of the bar set. | ||
*/ | ||||
/*! | ||||
\qmlproperty color BarSet::borderColor | ||||
The line (pen) color of the bar set. | ||||
Tero Ahola
|
r1465 | */ | ||
Tero Ahola
|
r1904 | /*! | ||
\qmlproperty real BarSet::borderWidth | ||||
The width of the border line. By default the width is 2.0. | ||||
*/ | ||||
Tero Ahola
|
r1465 | /*! | ||
\property QBarSet::labelColor | ||||
Tero Ahola
|
r1489 | The text (label) color of the bar set. | ||
*/ | ||||
/*! | ||||
\qmlproperty color BarSet::labelColor | ||||
The text (label) color of the bar set. | ||||
Tero Ahola
|
r1465 | */ | ||
sauimone
|
r1490 | /*! | ||
\fn void QBarSet::clicked(int index) | ||||
Miikka Heikkinen
|
r2520 | The signal is emitted if the user clicks with a mouse on top of bar set. | ||
sauimone
|
r1490 | Clicked bar inside set is indexed by \a index | ||
*/ | ||||
Titta Heikkala
|
r2739 | /*! | ||
\fn void QBarSet::pressed(int index) | ||||
The signal is emitted if the user presses with a mouse on top of bar set. | ||||
Pressed bar inside set is indexed by \a index | ||||
*/ | ||||
/*! | ||||
\fn void QBarSet::released(int index) | ||||
The signal is emitted if the user releases with a mouse on top of bar set. | ||||
Released bar inside set is indexed by \a index | ||||
*/ | ||||
/*! | ||||
\fn void QBarSet::doubleClicked(int index) | ||||
The signal is emitted if the user doubleclicks with a mouse on top of bar set. | ||||
Doubleclicked bar inside set is indexed by \a index | ||||
*/ | ||||
Titta Heikkala
|
r2600 | /*! | ||
\fn void QBarSet::hovered(bool status, int index) | ||||
The signal is emitted if mouse is hovered on top of bar set. | ||||
Parameter \a status is true, if mouse entered on top of bar set, false if mouse left from top of bar set. | ||||
Hovered bar inside the set is indexed by \a index. | ||||
*/ | ||||
sauimone
|
r1490 | |||
Marek Rosa
|
r1361 | /*! | ||
sauimone
|
r1429 | \fn void QBarSet::labelChanged() | ||
Miikka Heikkinen
|
r2520 | This signal is emitted when the label of the bar set has changed. | ||
sauimone
|
r1429 | \sa label | ||
Marek Rosa
|
r1361 | */ | ||
Tero Ahola
|
r1531 | /*! | ||
\qmlsignal BarSet::onLabelChanged() | ||||
Miikka Heikkinen
|
r2520 | This signal is emitted when the label of the bar set has changed. | ||
Tero Ahola
|
r1531 | */ | ||
Marek Rosa
|
r1361 | |||
/*! | ||||
\fn void QBarSet::penChanged() | ||||
Miikka Heikkinen
|
r2520 | This signal is emitted when the pen of the bar set has changed. | ||
Marek Rosa
|
r1361 | \sa pen | ||
*/ | ||||
/*! | ||||
\fn void QBarSet::brushChanged() | ||||
Miikka Heikkinen
|
r2520 | This signal is emitted when the brush of the bar set has changed. | ||
Marek Rosa
|
r1361 | \sa brush | ||
*/ | ||||
/*! | ||||
\fn void QBarSet::labelBrushChanged() | ||||
Miikka Heikkinen
|
r2520 | This signal is emitted when the brush of the bar set's label has changed. | ||
Marek Rosa
|
r1361 | \sa labelBrush | ||
*/ | ||||
/*! | ||||
\fn void QBarSet::labelFontChanged() | ||||
Miikka Heikkinen
|
r2520 | This signal is emitted when the font of the bar set's label has changed. | ||
Marek Rosa
|
r1361 | \sa labelBrush | ||
*/ | ||||
Tero Ahola
|
r1465 | /*! | ||
\fn void QBarSet::colorChanged(QColor) | ||||
This signal is emitted when the fill (brush) color of the set has changed to \a color. | ||||
*/ | ||||
Tero Ahola
|
r1489 | /*! | ||
\qmlsignal BarSet::onColorChanged(color color) | ||||
This signal is emitted when the fill (brush) color of the set has changed to \a color. | ||||
*/ | ||||
Tero Ahola
|
r1465 | |||
/*! | ||||
\fn void QBarSet::borderColorChanged(QColor) | ||||
This signal is emitted when the line (pen) color of the set has changed to \a color. | ||||
*/ | ||||
Tero Ahola
|
r1489 | /*! | ||
\qmlsignal BarSet::onBorderColorChanged(color color) | ||||
This signal is emitted when the line (pen) color of the set has changed to \a color. | ||||
*/ | ||||
Tero Ahola
|
r1465 | |||
/*! | ||||
\fn void QBarSet::labelColorChanged(QColor) | ||||
This signal is emitted when the text (label) color of the set has changed to \a color. | ||||
*/ | ||||
Tero Ahola
|
r1489 | /*! | ||
\qmlsignal BarSet::onLabelColorChanged(color color) | ||||
This signal is emitted when the text (label) color of the set has changed to \a color. | ||||
*/ | ||||
Tero Ahola
|
r1465 | |||
Marek Rosa
|
r1361 | /*! | ||
\fn void QBarSet::valuesAdded(int index, int count) | ||||
This signal is emitted when new values have been added to the set. | ||||
Parameter \a index indicates the position of the first inserted value. | ||||
Miikka Heikkinen
|
r2494 | Parameter \a count is the number of inserted values. | ||
Marek Rosa
|
r1361 | \sa append(), insert() | ||
*/ | ||||
Tero Ahola
|
r1489 | /*! | ||
\qmlsignal BarSet::onValuesAdded(int index, int count) | ||||
This signal is emitted when new values have been added to the set. | ||||
Parameter \a index indicates the position of the first inserted value. | ||||
Miikka Heikkinen
|
r2494 | Parameter \a count is the number of inserted values. | ||
Tero Ahola
|
r1489 | */ | ||
Marek Rosa
|
r1361 | |||
/*! | ||||
\fn void QBarSet::valuesRemoved(int index, int count) | ||||
This signal is emitted values have been removed from the set. | ||||
Parameter \a index indicates the position of the first removed value. | ||||
Parameter \a count is the number of removed values. | ||||
\sa remove() | ||||
*/ | ||||
Tero Ahola
|
r1489 | /*! | ||
\qmlsignal BarSet::onValuesRemoved(int index, int count) | ||||
This signal is emitted values have been removed from the set. | ||||
Parameter \a index indicates the position of the first removed value. | ||||
Parameter \a count is the number of removed values. | ||||
*/ | ||||
Marek Rosa
|
r1361 | |||
/*! | ||||
\fn void QBarSet::valueChanged(int index) | ||||
This signal is emitted values the value in the set has been modified. | ||||
Parameter \a index indicates the position of the modified value. | ||||
\sa at() | ||||
*/ | ||||
Tero Ahola
|
r1489 | /*! | ||
\qmlsignal BarSet::onValueChanged(int index) | ||||
This signal is emitted values the value in the set has been modified. | ||||
Parameter \a index indicates the position of the modified value. | ||||
*/ | ||||
Marek Rosa
|
r1361 | |||
Tero Ahola
|
r1523 | /*! | ||
\qmlproperty int BarSet::count | ||||
Miikka Heikkinen
|
r2520 | The count of values on the bar set | ||
Tero Ahola
|
r1523 | */ | ||
/*! | ||||
\qmlproperty QVariantList BarSet::values | ||||
Miikka Heikkinen
|
r2520 | The values of the bar set. You can set either a list of reals or a list of points as values. If you set a list of | ||
Tero Ahola
|
r1523 | reals as values, the values are automatically completed to points by using the index of a value as it's | ||
Titta Heikkala
|
r2678 | x-coordinate. For example the following sets have equal values: | ||
Tero Ahola
|
r1523 | \code | ||
myBarSet1.values = [0, 5, 1, 5]; | ||||
Titta Heikkala
|
r2678 | myBarSet2.values = [Qt.point(0, 0), Qt.point(1, 5), Qt.point(2, 1), Qt.point(3, 5)]; | ||
Tero Ahola
|
r1523 | \endcode | ||
*/ | ||||
sauimone
|
r313 | /*! | ||
Miikka Heikkinen
|
r2494 | Constructs QBarSet with a label of \a label and with parent of \a parent. | ||
sauimone
|
r313 | */ | ||
sauimone
|
r1429 | QBarSet::QBarSet(const QString label, QObject *parent) | ||
Jani Honkonen
|
r2097 | : QObject(parent), | ||
d_ptr(new QBarSetPrivate(label, this)) | ||||
sauimone
|
r169 | { | ||
} | ||||
sauimone
|
r980 | /*! | ||
Miikka Heikkinen
|
r2520 | Destroys the bar set. | ||
sauimone
|
r980 | */ | ||
Jani Honkonen
|
r944 | QBarSet::~QBarSet() | ||
{ | ||||
sauimone
|
r980 | // NOTE: d_ptr destroyed by QObject | ||
Jani Honkonen
|
r944 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r1429 | Sets new \a label for set. | ||
sauimone
|
r313 | */ | ||
sauimone
|
r1429 | void QBarSet::setLabel(const QString label) | ||
sauimone
|
r169 | { | ||
sauimone
|
r1429 | d_ptr->m_label = label; | ||
emit labelChanged(); | ||||
sauimone
|
r169 | } | ||
sauimone
|
r313 | |||
/*! | ||||
sauimone
|
r1429 | Returns label of the set. | ||
sauimone
|
r313 | */ | ||
sauimone
|
r1429 | QString QBarSet::label() const | ||
sauimone
|
r171 | { | ||
sauimone
|
r1429 | return d_ptr->m_label; | ||
sauimone
|
r171 | } | ||
sauimone
|
r169 | |||
sauimone
|
r1208 | /*! | ||
sauimone
|
r1580 | Appends new value \a value to the end of set. | ||
sauimone
|
r313 | */ | ||
sauimone
|
r993 | void QBarSet::append(const qreal value) | ||
sauimone
|
r169 | { | ||
sauimone
|
r1580 | // Convert to QPointF | ||
sauimone
|
r1601 | int index = d_ptr->m_values.count(); | ||
sauimone
|
r1580 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | ||
Marek Rosa
|
r1602 | emit valuesAdded(index, 1); | ||
sauimone
|
r1167 | } | ||
sauimone
|
r1208 | /*! | ||
Marek Rosa
|
r1361 | Appends a list of reals to set. Works like append with single real value. The \a values in list | ||
Miikka Heikkinen
|
r2520 | are appended to end of bar set. | ||
sauimone
|
r1208 | \sa append() | ||
*/ | ||||
sauimone
|
r1500 | void QBarSet::append(const QList<qreal> &values) | ||
sauimone
|
r1167 | { | ||
int index = d_ptr->m_values.count(); | ||||
sauimone
|
r1353 | d_ptr->append(values); | ||
emit valuesAdded(index, values.count()); | ||||
sauimone
|
r993 | } | ||
/*! | ||||
Jani Honkonen
|
r1932 | Convenience operator. Same as append, with real \a value. | ||
sauimone
|
r1208 | \sa append() | ||
sauimone
|
r993 | */ | ||
Jani Honkonen
|
r2104 | QBarSet &QBarSet::operator << (const qreal &value) | ||
sauimone
|
r993 | { | ||
sauimone
|
r1601 | append(value); | ||
sauimone
|
r1167 | return *this; | ||
} | ||||
Marek Rosa
|
r901 | /*! | ||
sauimone
|
r993 | Inserts new \a value on the \a index position. | ||
Miikka Heikkinen
|
r2494 | The value that is currently at this postion is moved to position index + 1 | ||
sauimone
|
r993 | \sa remove() | ||
Marek Rosa
|
r901 | */ | ||
sauimone
|
r993 | void QBarSet::insert(const int index, const qreal value) | ||
Marek Rosa
|
r662 | { | ||
sauimone
|
r1353 | d_ptr->insert(index, value); | ||
Jani Honkonen
|
r2097 | emit valuesAdded(index, 1); | ||
sauimone
|
r1353 | } | ||
Marek Rosa
|
r901 | /*! | ||
Marek Rosa
|
r1361 | Removes \a count number of values from the set starting at \a index. | ||
sauimone
|
r993 | \sa insert() | ||
Marek Rosa
|
r901 | */ | ||
sauimone
|
r1514 | void QBarSet::remove(const int index, const int count) | ||
Marek Rosa
|
r663 | { | ||
Jani Honkonen
|
r2097 | int removedCount = d_ptr->remove(index, count); | ||
if (removedCount > 0) | ||||
emit valuesRemoved(index, removedCount); | ||||
sauimone
|
r1514 | return; | ||
Marek Rosa
|
r663 | } | ||
sauimone
|
r313 | /*! | ||
Miikka Heikkinen
|
r2494 | Sets a new value \a value to set, indexed by \a index. | ||
sauimone
|
r313 | */ | ||
sauimone
|
r993 | void QBarSet::replace(const int index, const qreal value) | ||
sauimone
|
r171 | { | ||
Tero Ahola
|
r1512 | if (index >= 0 && index < d_ptr->m_values.count()) { | ||
Jani Honkonen
|
r2097 | d_ptr->replace(index, value); | ||
Tero Ahola
|
r1512 | emit valueChanged(index); | ||
} | ||||
sauimone
|
r1353 | } | ||
sauimone
|
r171 | |||
sauimone
|
r313 | /*! | ||
sauimone
|
r1580 | Returns value of set indexed by \a index. | ||
If the index is out of bounds 0.0 is returned. | ||||
sauimone
|
r313 | */ | ||
sauimone
|
r1580 | qreal QBarSet::at(const int index) const | ||
sauimone
|
r171 | { | ||
Jani Honkonen
|
r2097 | if (index < 0 || index >= d_ptr->m_values.count()) | ||
sauimone
|
r1580 | return 0; | ||
return d_ptr->m_values.at(index).y(); | ||||
sauimone
|
r171 | } | ||
sauimone
|
r313 | /*! | ||
sauimone
|
r1580 | Returns value of set indexed by \a index. | ||
If the index is out of bounds 0.0 is returned. | ||||
sauimone
|
r313 | */ | ||
sauimone
|
r1580 | qreal QBarSet::operator [](const int index) const | ||
sauimone
|
r183 | { | ||
sauimone
|
r1580 | return at(index); | ||
sauimone
|
r993 | } | ||
/*! | ||||
Returns count of values in set. | ||||
*/ | ||||
int QBarSet::count() const | ||||
{ | ||||
return d_ptr->m_values.count(); | ||||
sauimone
|
r183 | } | ||
sauimone
|
r492 | /*! | ||
Miikka Heikkinen
|
r2520 | Returns sum of all values in the bar set. | ||
sauimone
|
r492 | */ | ||
sauimone
|
r934 | qreal QBarSet::sum() const | ||
sauimone
|
r438 | { | ||
qreal total(0); | ||||
Jani Honkonen
|
r2097 | for (int i = 0; i < d_ptr->m_values.count(); i++) | ||
sauimone
|
r1167 | total += d_ptr->m_values.at(i).y(); | ||
sauimone
|
r438 | return total; | ||
} | ||||
sauimone
|
r313 | /*! | ||
Sets pen for set. Bars of this set are drawn using \a pen | ||||
*/ | ||||
sauimone
|
r763 | void QBarSet::setPen(const QPen &pen) | ||
sauimone
|
r214 | { | ||
Jani Honkonen
|
r2097 | if (d_ptr->m_pen != pen) { | ||
d_ptr->m_pen = pen; | ||||
emit d_ptr->updatedBars(); | ||||
emit penChanged(); | ||||
} | ||||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Returns pen of the set. | ||||
*/ | ||||
sauimone
|
r473 | QPen QBarSet::pen() const | ||
sauimone
|
r214 | { | ||
Miikka Heikkinen
|
r2519 | if (d_ptr->m_pen == QChartPrivate::defaultPen()) | ||
return QPen(); | ||||
else | ||||
return d_ptr->m_pen; | ||||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Miikka Heikkinen
|
r2520 | Sets brush for the set. Bars of this set are drawn using \a brush. | ||
sauimone
|
r313 | */ | ||
sauimone
|
r763 | void QBarSet::setBrush(const QBrush &brush) | ||
sauimone
|
r214 | { | ||
Jani Honkonen
|
r2097 | if (d_ptr->m_brush != brush) { | ||
d_ptr->m_brush = brush; | ||||
emit d_ptr->updatedBars(); | ||||
emit brushChanged(); | ||||
Michal Klocek
|
r938 | } | ||
sauimone
|
r214 | } | ||
sauimone
|
r313 | /*! | ||
Returns brush of the set. | ||||
*/ | ||||
sauimone
|
r473 | QBrush QBarSet::brush() const | ||
sauimone
|
r214 | { | ||
Miikka Heikkinen
|
r2519 | if (d_ptr->m_brush == QChartPrivate::defaultBrush()) | ||
return QBrush(); | ||||
else | ||||
return d_ptr->m_brush; | ||||
sauimone
|
r214 | } | ||
sauimone
|
r820 | /*! | ||
Miikka Heikkinen
|
r2520 | Sets \a brush of the values that are drawn on top of this bar set. | ||
sauimone
|
r820 | */ | ||
void QBarSet::setLabelBrush(const QBrush &brush) | ||||
{ | ||||
Jani Honkonen
|
r2097 | if (d_ptr->m_labelBrush != brush) { | ||
Michal Klocek
|
r938 | d_ptr->m_labelBrush = brush; | ||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
sauimone
|
r1353 | emit labelBrushChanged(); | ||
Michal Klocek
|
r938 | } | ||
sauimone
|
r820 | } | ||
/*! | ||||
Miikka Heikkinen
|
r2520 | Returns brush of the values that are drawn on top of this bar set. | ||
sauimone
|
r820 | */ | ||
QBrush QBarSet::labelBrush() const | ||||
{ | ||||
Miikka Heikkinen
|
r2519 | if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush()) | ||
return QBrush(); | ||||
else | ||||
return d_ptr->m_labelBrush; | ||||
sauimone
|
r820 | } | ||
/*! | ||||
Miikka Heikkinen
|
r2520 | Sets the \a font for values that are drawn on top of this bar set. | ||
sauimone
|
r820 | */ | ||
void QBarSet::setLabelFont(const QFont &font) | ||||
{ | ||||
Jani Honkonen
|
r2097 | if (d_ptr->m_labelFont != font) { | ||
Michal Klocek
|
r938 | d_ptr->m_labelFont = font; | ||
sauimone
|
r1008 | emit d_ptr->updatedBars(); | ||
sauimone
|
r1353 | emit labelFontChanged(); | ||
Michal Klocek
|
r938 | } | ||
sauimone
|
r512 | } | ||
/*! | ||||
Miikka Heikkinen
|
r2520 | Returns the pen for values that are drawn on top of this bar set. | ||
sauimone
|
r512 | */ | ||
sauimone
|
r820 | QFont QBarSet::labelFont() const | ||
sauimone
|
r512 | { | ||
Michal Klocek
|
r938 | return d_ptr->m_labelFont; | ||
sauimone
|
r512 | } | ||
sauimone
|
r1493 | /*! | ||
Miikka Heikkinen
|
r2520 | Returns the color of the brush of bar set. | ||
sauimone
|
r1493 | */ | ||
Tero Ahola
|
r1465 | QColor QBarSet::color() | ||
{ | ||||
return brush().color(); | ||||
} | ||||
sauimone
|
r1493 | /*! | ||
Miikka Heikkinen
|
r2520 | Sets the \a color of brush for this bar set. | ||
sauimone
|
r1493 | */ | ||
Tero Ahola
|
r1465 | void QBarSet::setColor(QColor color) | ||
{ | ||||
QBrush b = brush(); | ||||
sauimone
|
r1788 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { | ||
Tero Ahola
|
r1465 | b.setColor(color); | ||
sauimone
|
r1788 | if (b.style() == Qt::NoBrush) { | ||
// Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) | ||||
// This prevents theme to override color defined in QML side: | ||||
// BarSet { label: "Bob"; color:"red"; values: [1,2,3] } | ||||
// The color must be obeyed, since user wanted it. | ||||
b.setStyle(Qt::SolidPattern); | ||||
} | ||||
Tero Ahola
|
r1465 | setBrush(b); | ||
emit colorChanged(color); | ||||
} | ||||
} | ||||
sauimone
|
r1493 | /*! | ||
Miikka Heikkinen
|
r2520 | Returns the color of pen of this bar set. | ||
sauimone
|
r1493 | */ | ||
Tero Ahola
|
r1465 | QColor QBarSet::borderColor() | ||
{ | ||||
return pen().color(); | ||||
} | ||||
sauimone
|
r1493 | /*! | ||
Miikka Heikkinen
|
r2820 | Sets the \a color of pen for this bar set. | ||
sauimone
|
r1493 | */ | ||
Tero Ahola
|
r1465 | void QBarSet::setBorderColor(QColor color) | ||
{ | ||||
QPen p = pen(); | ||||
if (p.color() != color) { | ||||
p.setColor(color); | ||||
setPen(p); | ||||
emit borderColorChanged(color); | ||||
} | ||||
} | ||||
sauimone
|
r1493 | /*! | ||
Miikka Heikkinen
|
r2520 | Returns the color of labels of this bar set. | ||
sauimone
|
r1493 | */ | ||
Tero Ahola
|
r1465 | QColor QBarSet::labelColor() | ||
{ | ||||
return labelBrush().color(); | ||||
} | ||||
sauimone
|
r1493 | /*! | ||
Miikka Heikkinen
|
r2820 | Sets the \a color of labels for this bar set. | ||
sauimone
|
r1493 | */ | ||
Tero Ahola
|
r1465 | void QBarSet::setLabelColor(QColor color) | ||
Jani Honkonen
|
r2097 | { | ||
Tero Ahola
|
r1465 | QBrush b = labelBrush(); | ||
Marek Rosa
|
r1776 | if (b == QBrush()) | ||
Marek Rosa
|
r1760 | b.setStyle(Qt::SolidPattern); | ||
Titta Heikkala
|
r2768 | if (d_ptr->m_labelBrush.color() != color) { | ||
Tero Ahola
|
r1465 | b.setColor(color); | ||
setLabelBrush(b); | ||||
emit labelColorChanged(color); | ||||
} | ||||
} | ||||
Michal Klocek
|
r938 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
sauimone
|
r1429 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | ||
Michal Klocek
|
r938 | q_ptr(parent), | ||
Miikka Heikkinen
|
r2516 | m_label(label), | ||
m_pen(QChartPrivate::defaultPen()), | ||||
m_brush(QChartPrivate::defaultBrush()), | ||||
m_labelBrush(QChartPrivate::defaultBrush()) | ||||
Michal Klocek
|
r938 | { | ||
} | ||||
QBarSetPrivate::~QBarSetPrivate() | ||||
{ | ||||
} | ||||
sauimone
|
r1017 | |||
sauimone
|
r1353 | void QBarSetPrivate::append(QPointF value) | ||
{ | ||||
Mika Salmela
|
r2424 | if (isValidValue(value)) { | ||
m_values.append(value); | ||||
emit restructuredBars(); | ||||
} | ||||
sauimone
|
r1353 | } | ||
void QBarSetPrivate::append(QList<QPointF> values) | ||||
{ | ||||
Mika Salmela
|
r2424 | for (int i = 0; i < values.count(); i++) { | ||
if (isValidValue(values.at(i))) | ||||
m_values.append(values.at(i)); | ||||
} | ||||
sauimone
|
r1353 | emit restructuredBars(); | ||
} | ||||
void QBarSetPrivate::append(QList<qreal> values) | ||||
{ | ||||
int index = m_values.count(); | ||||
Jani Honkonen
|
r2097 | for (int i = 0; i < values.count(); i++) { | ||
Mika Salmela
|
r2424 | if (isValidValue(values.at(i))) { | ||
m_values.append(QPointF(index, values.at(i))); | ||||
index++; | ||||
} | ||||
sauimone
|
r1353 | } | ||
emit restructuredBars(); | ||||
} | ||||
void QBarSetPrivate::insert(const int index, const qreal value) | ||||
{ | ||||
m_values.insert(index, QPointF(index, value)); | ||||
emit restructuredBars(); | ||||
} | ||||
void QBarSetPrivate::insert(const int index, const QPointF value) | ||||
{ | ||||
m_values.insert(index, value); | ||||
emit restructuredBars(); | ||||
} | ||||
sauimone
|
r1514 | int QBarSetPrivate::remove(const int index, const int count) | ||
sauimone
|
r1353 | { | ||
sauimone
|
r1514 | int removeCount = count; | ||
Jani Honkonen
|
r2097 | if ((index < 0) || (m_values.count() == 0)) | ||
return 0; // Invalid index or not values in list, remove nothing. | ||||
else if ((index + count) > m_values.count()) | ||||
removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed. | ||||
sauimone
|
r1514 | |||
int c = 0; | ||||
while (c < removeCount) { | ||||
sauimone
|
r1353 | m_values.removeAt(index); | ||
sauimone
|
r1514 | c++; | ||
sauimone
|
r1353 | } | ||
emit restructuredBars(); | ||||
sauimone
|
r1514 | return removeCount; | ||
sauimone
|
r1353 | } | ||
void QBarSetPrivate::replace(const int index, const qreal value) | ||||
{ | ||||
Jani Honkonen
|
r2097 | m_values.replace(index, QPointF(index, value)); | ||
sauimone
|
r1917 | emit updatedLayout(); | ||
sauimone
|
r1353 | } | ||
void QBarSetPrivate::replace(const int index, const QPointF value) | ||||
{ | ||||
Jani Honkonen
|
r2097 | m_values.replace(index, value); | ||
sauimone
|
r1917 | emit updatedLayout(); | ||
sauimone
|
r1353 | } | ||
sauimone
|
r1681 | qreal QBarSetPrivate::pos(const int index) | ||
sauimone
|
r1603 | { | ||
Jani Honkonen
|
r2097 | if (index < 0 || index >= m_values.count()) | ||
sauimone
|
r1681 | return 0; | ||
return m_values.at(index).x(); | ||||
sauimone
|
r1603 | } | ||
sauimone
|
r1681 | qreal QBarSetPrivate::value(const int index) | ||
{ | ||||
Jani Honkonen
|
r2097 | if (index < 0 || index >= m_values.count()) | ||
sauimone
|
r1681 | return 0; | ||
return m_values.at(index).y(); | ||||
} | ||||
sauimone
|
r1603 | |||
sauimone
|
r239 | #include "moc_qbarset.cpp" | ||
Michal Klocek
|
r938 | #include "moc_qbarset_p.cpp" | ||
Tero Ahola
|
r737 | |||
Titta Heikkala
|
r2712 | QT_CHARTS_END_NAMESPACE | ||