qbarset.cpp
688 lines
| 16.9 KiB
| text/x-c
|
CppLexer
|
r794 | /**************************************************************************** | ||
** | ||||
|
r2776 | ** Copyright (C) 2015 The Qt Company Ltd | ||
|
r794 | ** All rights reserved. | ||
|
r2776 | ** For any questions to The Qt Company, please use contact form at http://qt.io | ||
|
r794 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r794 | ** | ||
|
r2740 | ** Licensees holding valid commercial license for Qt may use this file in | ||
** accordance with the Qt License Agreement provided with the Software | ||||
** or, alternatively, in accordance with the terms contained in a written | ||||
|
r2776 | ** agreement between you and The Qt Company. | ||
|
r794 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r794 | ** | ||
****************************************************************************/ | ||||
|
r2714 | #include <QtCharts/QBarSet> | ||
#include <private/qbarset_p.h> | ||||
#include <private/charthelpers_p.h> | ||||
#include <private/qchart_p.h> | ||||
|
r169 | |||
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
|
r169 | |||
|
r313 | /*! | ||
\class QBarSet | ||||
|
r2639 | \inmodule Qt Charts | ||
|
r2520 | \brief Building block for different bar charts. | ||
|
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. | ||||
|
r2814 | Labels for zero value sets are not shown. | ||
|
r313 | |||
|
r1594 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | ||
|
r313 | */ | ||
|
r2639 | /*! | ||
\qmltype BarSet | ||||
\instantiates QBarSet | ||||
|
r2712 | \inqmlmodule QtCharts | ||
|
r2639 | |||
|
r2712 | \brief Building block for different bar charts. | ||
|
r1489 | |||
|
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. | ||||
|
r2814 | Labels for zero value sets are not shown. | ||
|
r2712 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | ||
|
r1489 | */ | ||
|
r313 | |||
|
r1361 | /*! | ||
|
r1429 | \property QBarSet::label | ||
|
r2520 | Defines the label of the bar set. | ||
|
r1489 | */ | ||
/*! | ||||
\qmlproperty string BarSet::label | ||||
|
r2520 | Defines the label of the bar set. | ||
|
r1361 | */ | ||
/*! | ||||
\property QBarSet::pen | ||||
|
r2520 | \brief Defines the pen used by the bar set. | ||
|
r1361 | */ | ||
/*! | ||||
\property QBarSet::brush | ||||
|
r2520 | \brief Defines the brush used by the bar set. | ||
|
r1361 | */ | ||
|
r2681 | /*! | ||
\qmlproperty QString BarSet::brushFilename | ||||
The name of the file used as a brush for the set. | ||||
*/ | ||||
|
r1361 | /*! | ||
\property QBarSet::labelBrush | ||||
|
r2520 | \brief Defines the brush used by the bar set's label. | ||
|
r1361 | */ | ||
/*! | ||||
\property QBarSet::labelFont | ||||
|
r2520 | \brief Defines the font used by the bar set's label. | ||
|
r1361 | */ | ||
|
r1517 | /*! | ||
\qmlproperty Font BarSet::labelFont | ||||
|
r2520 | Defines the font used by the bar set's label. | ||
|
r1517 | |||
|
r2639 | See the Qt documentation for more details of Font. | ||
|
r1517 | */ | ||
|
r1465 | /*! | ||
\property QBarSet::color | ||||
|
r1489 | The fill (brush) color of the bar set. | ||
*/ | ||||
/*! | ||||
\qmlproperty color BarSet::color | ||||
The fill (brush) color of the bar set. | ||||
|
r1465 | */ | ||
/*! | ||||
\property QBarSet::borderColor | ||||
|
r1489 | The line (pen) color of the bar set. | ||
*/ | ||||
/*! | ||||
\qmlproperty color BarSet::borderColor | ||||
The line (pen) color of the bar set. | ||||
|
r1465 | */ | ||
|
r1904 | /*! | ||
\qmlproperty real BarSet::borderWidth | ||||
The width of the border line. By default the width is 2.0. | ||||
*/ | ||||
|
r1465 | /*! | ||
\property QBarSet::labelColor | ||||
|
r1489 | The text (label) color of the bar set. | ||
*/ | ||||
/*! | ||||
\qmlproperty color BarSet::labelColor | ||||
The text (label) color of the bar set. | ||||
|
r1465 | */ | ||
|
r1490 | /*! | ||
\fn void QBarSet::clicked(int index) | ||||
|
r2520 | The signal is emitted if the user clicks with a mouse on top of bar set. | ||
|
r1490 | Clicked bar inside set is indexed by \a index | ||
*/ | ||||
|
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 | ||||
*/ | ||||
|
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. | ||||
*/ | ||||
|
r1490 | |||
|
r1361 | /*! | ||
|
r1429 | \fn void QBarSet::labelChanged() | ||
|
r2520 | This signal is emitted when the label of the bar set has changed. | ||
|
r1429 | \sa label | ||
|
r1361 | */ | ||
|
r1531 | /*! | ||
\qmlsignal BarSet::onLabelChanged() | ||||
|
r2520 | This signal is emitted when the label of the bar set has changed. | ||
|
r1531 | */ | ||
|
r1361 | |||
/*! | ||||
\fn void QBarSet::penChanged() | ||||
|
r2520 | This signal is emitted when the pen of the bar set has changed. | ||
|
r1361 | \sa pen | ||
*/ | ||||
/*! | ||||
\fn void QBarSet::brushChanged() | ||||
|
r2520 | This signal is emitted when the brush of the bar set has changed. | ||
|
r1361 | \sa brush | ||
*/ | ||||
/*! | ||||
\fn void QBarSet::labelBrushChanged() | ||||
|
r2520 | This signal is emitted when the brush of the bar set's label has changed. | ||
|
r1361 | \sa labelBrush | ||
*/ | ||||
/*! | ||||
\fn void QBarSet::labelFontChanged() | ||||
|
r2520 | This signal is emitted when the font of the bar set's label has changed. | ||
|
r1361 | \sa labelBrush | ||
*/ | ||||
|
r1465 | /*! | ||
\fn void QBarSet::colorChanged(QColor) | ||||
This signal is emitted when the fill (brush) color of the set has changed to \a color. | ||||
*/ | ||||
|
r1489 | /*! | ||
\qmlsignal BarSet::onColorChanged(color color) | ||||
This signal is emitted when the fill (brush) color of the set has changed to \a color. | ||||
*/ | ||||
|
r1465 | |||
/*! | ||||
\fn void QBarSet::borderColorChanged(QColor) | ||||
This signal is emitted when the line (pen) color of the set has changed to \a color. | ||||
*/ | ||||
|
r1489 | /*! | ||
\qmlsignal BarSet::onBorderColorChanged(color color) | ||||
This signal is emitted when the line (pen) color of the set has changed to \a color. | ||||
*/ | ||||
|
r1465 | |||
/*! | ||||
\fn void QBarSet::labelColorChanged(QColor) | ||||
This signal is emitted when the text (label) color of the set has changed to \a color. | ||||
*/ | ||||
|
r1489 | /*! | ||
\qmlsignal BarSet::onLabelColorChanged(color color) | ||||
This signal is emitted when the text (label) color of the set has changed to \a color. | ||||
*/ | ||||
|
r1465 | |||
|
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. | ||||
|
r2494 | Parameter \a count is the number of inserted values. | ||
|
r1361 | \sa append(), insert() | ||
*/ | ||||
|
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. | ||||
|
r2494 | Parameter \a count is the number of inserted values. | ||
|
r1489 | */ | ||
|
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() | ||||
*/ | ||||
|
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. | ||||
*/ | ||||
|
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() | ||||
*/ | ||||
|
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. | ||||
*/ | ||||
|
r1361 | |||
|
r1523 | /*! | ||
\qmlproperty int BarSet::count | ||||
|
r2520 | The count of values on the bar set | ||
|
r1523 | */ | ||
/*! | ||||
\qmlproperty QVariantList BarSet::values | ||||
|
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 | ||
|
r1523 | reals as values, the values are automatically completed to points by using the index of a value as it's | ||
|
r2678 | x-coordinate. For example the following sets have equal values: | ||
|
r1523 | \code | ||
myBarSet1.values = [0, 5, 1, 5]; | ||||
|
r2678 | myBarSet2.values = [Qt.point(0, 0), Qt.point(1, 5), Qt.point(2, 1), Qt.point(3, 5)]; | ||
|
r1523 | \endcode | ||
*/ | ||||
|
r313 | /*! | ||
|
r2494 | Constructs QBarSet with a label of \a label and with parent of \a parent. | ||
|
r313 | */ | ||
|
r1429 | QBarSet::QBarSet(const QString label, QObject *parent) | ||
|
r2097 | : QObject(parent), | ||
d_ptr(new QBarSetPrivate(label, this)) | ||||
|
r169 | { | ||
} | ||||
|
r980 | /*! | ||
|
r2520 | Destroys the bar set. | ||
|
r980 | */ | ||
|
r944 | QBarSet::~QBarSet() | ||
{ | ||||
|
r980 | // NOTE: d_ptr destroyed by QObject | ||
|
r944 | } | ||
|
r313 | /*! | ||
|
r1429 | Sets new \a label for set. | ||
|
r313 | */ | ||
|
r1429 | void QBarSet::setLabel(const QString label) | ||
|
r169 | { | ||
|
r1429 | d_ptr->m_label = label; | ||
emit labelChanged(); | ||||
|
r169 | } | ||
|
r313 | |||
/*! | ||||
|
r1429 | Returns label of the set. | ||
|
r313 | */ | ||
|
r1429 | QString QBarSet::label() const | ||
|
r171 | { | ||
|
r1429 | return d_ptr->m_label; | ||
|
r171 | } | ||
|
r169 | |||
|
r1208 | /*! | ||
|
r1580 | Appends new value \a value to the end of set. | ||
|
r313 | */ | ||
|
r993 | void QBarSet::append(const qreal value) | ||
|
r169 | { | ||
|
r1580 | // Convert to QPointF | ||
|
r1601 | int index = d_ptr->m_values.count(); | ||
|
r1580 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | ||
|
r1602 | emit valuesAdded(index, 1); | ||
|
r1167 | } | ||
|
r1208 | /*! | ||
|
r1361 | Appends a list of reals to set. Works like append with single real value. The \a values in list | ||
|
r2520 | are appended to end of bar set. | ||
|
r1208 | \sa append() | ||
*/ | ||||
|
r1500 | void QBarSet::append(const QList<qreal> &values) | ||
|
r1167 | { | ||
int index = d_ptr->m_values.count(); | ||||
|
r1353 | d_ptr->append(values); | ||
emit valuesAdded(index, values.count()); | ||||
|
r993 | } | ||
/*! | ||||
|
r1932 | Convenience operator. Same as append, with real \a value. | ||
|
r1208 | \sa append() | ||
|
r993 | */ | ||
|
r2104 | QBarSet &QBarSet::operator << (const qreal &value) | ||
|
r993 | { | ||
|
r1601 | append(value); | ||
|
r1167 | return *this; | ||
} | ||||
|
r901 | /*! | ||
|
r993 | Inserts new \a value on the \a index position. | ||
|
r2494 | The value that is currently at this postion is moved to position index + 1 | ||
|
r993 | \sa remove() | ||
|
r901 | */ | ||
|
r993 | void QBarSet::insert(const int index, const qreal value) | ||
|
r662 | { | ||
|
r1353 | d_ptr->insert(index, value); | ||
|
r2097 | emit valuesAdded(index, 1); | ||
|
r1353 | } | ||
|
r901 | /*! | ||
|
r1361 | Removes \a count number of values from the set starting at \a index. | ||
|
r993 | \sa insert() | ||
|
r901 | */ | ||
|
r1514 | void QBarSet::remove(const int index, const int count) | ||
|
r663 | { | ||
|
r2097 | int removedCount = d_ptr->remove(index, count); | ||
if (removedCount > 0) | ||||
emit valuesRemoved(index, removedCount); | ||||
|
r1514 | return; | ||
|
r663 | } | ||
|
r313 | /*! | ||
|
r2494 | Sets a new value \a value to set, indexed by \a index. | ||
|
r313 | */ | ||
|
r993 | void QBarSet::replace(const int index, const qreal value) | ||
|
r171 | { | ||
|
r1512 | if (index >= 0 && index < d_ptr->m_values.count()) { | ||
|
r2097 | d_ptr->replace(index, value); | ||
|
r1512 | emit valueChanged(index); | ||
} | ||||
|
r1353 | } | ||
|
r171 | |||
|
r313 | /*! | ||
|
r1580 | Returns value of set indexed by \a index. | ||
If the index is out of bounds 0.0 is returned. | ||||
|
r313 | */ | ||
|
r1580 | qreal QBarSet::at(const int index) const | ||
|
r171 | { | ||
|
r2097 | if (index < 0 || index >= d_ptr->m_values.count()) | ||
|
r1580 | return 0; | ||
return d_ptr->m_values.at(index).y(); | ||||
|
r171 | } | ||
|
r313 | /*! | ||
|
r1580 | Returns value of set indexed by \a index. | ||
If the index is out of bounds 0.0 is returned. | ||||
|
r313 | */ | ||
|
r1580 | qreal QBarSet::operator [](const int index) const | ||
|
r183 | { | ||
|
r1580 | return at(index); | ||
|
r993 | } | ||
/*! | ||||
Returns count of values in set. | ||||
*/ | ||||
int QBarSet::count() const | ||||
{ | ||||
return d_ptr->m_values.count(); | ||||
|
r183 | } | ||
|
r492 | /*! | ||
|
r2520 | Returns sum of all values in the bar set. | ||
|
r492 | */ | ||
|
r934 | qreal QBarSet::sum() const | ||
|
r438 | { | ||
qreal total(0); | ||||
|
r2097 | for (int i = 0; i < d_ptr->m_values.count(); i++) | ||
|
r1167 | total += d_ptr->m_values.at(i).y(); | ||
|
r438 | return total; | ||
} | ||||
|
r313 | /*! | ||
Sets pen for set. Bars of this set are drawn using \a pen | ||||
*/ | ||||
|
r763 | void QBarSet::setPen(const QPen &pen) | ||
|
r214 | { | ||
|
r2097 | if (d_ptr->m_pen != pen) { | ||
d_ptr->m_pen = pen; | ||||
emit d_ptr->updatedBars(); | ||||
emit penChanged(); | ||||
} | ||||
|
r214 | } | ||
|
r313 | /*! | ||
Returns pen of the set. | ||||
*/ | ||||
|
r473 | QPen QBarSet::pen() const | ||
|
r214 | { | ||
|
r2519 | if (d_ptr->m_pen == QChartPrivate::defaultPen()) | ||
return QPen(); | ||||
else | ||||
return d_ptr->m_pen; | ||||
|
r214 | } | ||
|
r313 | /*! | ||
|
r2520 | Sets brush for the set. Bars of this set are drawn using \a brush. | ||
|
r313 | */ | ||
|
r763 | void QBarSet::setBrush(const QBrush &brush) | ||
|
r214 | { | ||
|
r2097 | if (d_ptr->m_brush != brush) { | ||
d_ptr->m_brush = brush; | ||||
emit d_ptr->updatedBars(); | ||||
emit brushChanged(); | ||||
|
r938 | } | ||
|
r214 | } | ||
|
r313 | /*! | ||
Returns brush of the set. | ||||
*/ | ||||
|
r473 | QBrush QBarSet::brush() const | ||
|
r214 | { | ||
|
r2519 | if (d_ptr->m_brush == QChartPrivate::defaultBrush()) | ||
return QBrush(); | ||||
else | ||||
return d_ptr->m_brush; | ||||
|
r214 | } | ||
|
r820 | /*! | ||
|
r2520 | Sets \a brush of the values that are drawn on top of this bar set. | ||
|
r820 | */ | ||
void QBarSet::setLabelBrush(const QBrush &brush) | ||||
{ | ||||
|
r2097 | if (d_ptr->m_labelBrush != brush) { | ||
|
r938 | d_ptr->m_labelBrush = brush; | ||
|
r1008 | emit d_ptr->updatedBars(); | ||
|
r1353 | emit labelBrushChanged(); | ||
|
r938 | } | ||
|
r820 | } | ||
/*! | ||||
|
r2520 | Returns brush of the values that are drawn on top of this bar set. | ||
|
r820 | */ | ||
QBrush QBarSet::labelBrush() const | ||||
{ | ||||
|
r2519 | if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush()) | ||
return QBrush(); | ||||
else | ||||
return d_ptr->m_labelBrush; | ||||
|
r820 | } | ||
/*! | ||||
|
r2520 | Sets the \a font for values that are drawn on top of this bar set. | ||
|
r820 | */ | ||
void QBarSet::setLabelFont(const QFont &font) | ||||
{ | ||||
|
r2097 | if (d_ptr->m_labelFont != font) { | ||
|
r938 | d_ptr->m_labelFont = font; | ||
|
r1008 | emit d_ptr->updatedBars(); | ||
|
r1353 | emit labelFontChanged(); | ||
|
r938 | } | ||
|
r512 | } | ||
/*! | ||||
|
r2520 | Returns the pen for values that are drawn on top of this bar set. | ||
|
r512 | */ | ||
|
r820 | QFont QBarSet::labelFont() const | ||
|
r512 | { | ||
|
r938 | return d_ptr->m_labelFont; | ||
|
r512 | } | ||
|
r1493 | /*! | ||
|
r2520 | Returns the color of the brush of bar set. | ||
|
r1493 | */ | ||
|
r1465 | QColor QBarSet::color() | ||
{ | ||||
return brush().color(); | ||||
} | ||||
|
r1493 | /*! | ||
|
r2520 | Sets the \a color of brush for this bar set. | ||
|
r1493 | */ | ||
|
r1465 | void QBarSet::setColor(QColor color) | ||
{ | ||||
QBrush b = brush(); | ||||
|
r1788 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { | ||
|
r1465 | b.setColor(color); | ||
|
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); | ||||
} | ||||
|
r1465 | setBrush(b); | ||
emit colorChanged(color); | ||||
} | ||||
} | ||||
|
r1493 | /*! | ||
|
r2520 | Returns the color of pen of this bar set. | ||
|
r1493 | */ | ||
|
r1465 | QColor QBarSet::borderColor() | ||
{ | ||||
return pen().color(); | ||||
} | ||||
|
r1493 | /*! | ||
|
r2820 | Sets the \a color of pen for this bar set. | ||
|
r1493 | */ | ||
|
r1465 | void QBarSet::setBorderColor(QColor color) | ||
{ | ||||
QPen p = pen(); | ||||
if (p.color() != color) { | ||||
p.setColor(color); | ||||
setPen(p); | ||||
emit borderColorChanged(color); | ||||
} | ||||
} | ||||
|
r1493 | /*! | ||
|
r2520 | Returns the color of labels of this bar set. | ||
|
r1493 | */ | ||
|
r1465 | QColor QBarSet::labelColor() | ||
{ | ||||
return labelBrush().color(); | ||||
} | ||||
|
r1493 | /*! | ||
|
r2820 | Sets the \a color of labels for this bar set. | ||
|
r1493 | */ | ||
|
r1465 | void QBarSet::setLabelColor(QColor color) | ||
|
r2097 | { | ||
|
r1465 | QBrush b = labelBrush(); | ||
|
r1776 | if (b == QBrush()) | ||
|
r1760 | b.setStyle(Qt::SolidPattern); | ||
|
r2768 | if (d_ptr->m_labelBrush.color() != color) { | ||
|
r1465 | b.setColor(color); | ||
setLabelBrush(b); | ||||
emit labelColorChanged(color); | ||||
} | ||||
} | ||||
|
r938 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
r1429 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | ||
|
r938 | q_ptr(parent), | ||
|
r2516 | m_label(label), | ||
m_pen(QChartPrivate::defaultPen()), | ||||
m_brush(QChartPrivate::defaultBrush()), | ||||
m_labelBrush(QChartPrivate::defaultBrush()) | ||||
|
r938 | { | ||
} | ||||
QBarSetPrivate::~QBarSetPrivate() | ||||
{ | ||||
} | ||||
|
r1017 | |||
|
r1353 | void QBarSetPrivate::append(QPointF value) | ||
{ | ||||
|
r2424 | if (isValidValue(value)) { | ||
m_values.append(value); | ||||
emit restructuredBars(); | ||||
} | ||||
|
r1353 | } | ||
void QBarSetPrivate::append(QList<QPointF> values) | ||||
{ | ||||
|
r2424 | for (int i = 0; i < values.count(); i++) { | ||
if (isValidValue(values.at(i))) | ||||
m_values.append(values.at(i)); | ||||
} | ||||
|
r1353 | emit restructuredBars(); | ||
} | ||||
void QBarSetPrivate::append(QList<qreal> values) | ||||
{ | ||||
int index = m_values.count(); | ||||
|
r2097 | for (int i = 0; i < values.count(); i++) { | ||
|
r2424 | if (isValidValue(values.at(i))) { | ||
m_values.append(QPointF(index, values.at(i))); | ||||
index++; | ||||
} | ||||
|
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(); | ||||
} | ||||
|
r1514 | int QBarSetPrivate::remove(const int index, const int count) | ||
|
r1353 | { | ||
|
r1514 | int removeCount = count; | ||
|
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. | ||||
|
r1514 | |||
int c = 0; | ||||
while (c < removeCount) { | ||||
|
r1353 | m_values.removeAt(index); | ||
|
r1514 | c++; | ||
|
r1353 | } | ||
emit restructuredBars(); | ||||
|
r1514 | return removeCount; | ||
|
r1353 | } | ||
void QBarSetPrivate::replace(const int index, const qreal value) | ||||
{ | ||||
|
r2097 | m_values.replace(index, QPointF(index, value)); | ||
|
r1917 | emit updatedLayout(); | ||
|
r1353 | } | ||
void QBarSetPrivate::replace(const int index, const QPointF value) | ||||
{ | ||||
|
r2097 | m_values.replace(index, value); | ||
|
r1917 | emit updatedLayout(); | ||
|
r1353 | } | ||
|
r1681 | qreal QBarSetPrivate::pos(const int index) | ||
|
r1603 | { | ||
|
r2097 | if (index < 0 || index >= m_values.count()) | ||
|
r1681 | return 0; | ||
return m_values.at(index).x(); | ||||
|
r1603 | } | ||
|
r1681 | qreal QBarSetPrivate::value(const int index) | ||
{ | ||||
|
r2097 | if (index < 0 || index >= m_values.count()) | ||
|
r1681 | return 0; | ||
return m_values.at(index).y(); | ||||
} | ||||
|
r1603 | |||
|
r239 | #include "moc_qbarset.cpp" | ||
|
r938 | #include "moc_qbarset_p.cpp" | ||
|
r737 | |||
|
r2712 | QT_CHARTS_END_NAMESPACE | ||