##// END OF EJS Templates
Added new test case to BarSeries tests: clear() with animations enabled
Added new test case to BarSeries tests: clear() with animations enabled

File last commit:

r1361:4519c43323f7
r1375:ac4721bd933f
Show More
qbarset.cpp
500 lines | 11.5 KiB | text/x-c | CppLexer
Jani Honkonen
Add license headers
r794 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
sauimone
proof of concept implementation for barset and barcategory
r169 #include "qbarset.h"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "qbarset_p.h"
sauimone
proof of concept implementation for barset and barcategory
r169
QTCOMMERCIALCHART_BEGIN_NAMESPACE
sauimone
Documentation for bar charts
r313 /*!
\class QBarSet
\brief part of QtCommercial chart API.
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.
sauimone
updated documentation and examples for barcharts
r325 \mainclass
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
sauimone
Documentation for bar charts
r313 */
Marek Rosa
Docs update for BarSeries and BarSet
r1361 /*!
\property QBarSet::name
\brief Defines the name of the barSet.
*/
/*!
\property QBarSet::pen
\brief Defines the pen used by the barSet.
*/
/*!
\property QBarSet::brush
\brief Defines the brush used by the barSet.
*/
/*!
\property QBarSet::labelBrush
\brief Defines the brush used by the barSet's label.
*/
/*!
\property QBarSet::labelFont
\brief Defines the font used by the barSet's label.
*/
/*!
\fn void QBarSet::nameChanged()
This signal is emitted when the name of the barSet has changed.
\sa name
*/
/*!
\fn void QBarSet::penChanged()
This signal is emitted when the pen of the barSet has changed.
\sa pen
*/
/*!
\fn void QBarSet::brushChanged()
This signal is emitted when the brush of the barSet has changed.
\sa brush
*/
/*!
\fn void QBarSet::labelChanged()
This signal is emitted when the label of the barSet has changed.
*/
/*!
\fn void QBarSet::labelBrushChanged()
This signal is emitted when the brush of the barSet's label has changed.
\sa labelBrush
*/
/*!
\fn void QBarSet::labelFontChanged()
This signal is emitted when the font of the barSet's label has changed.
\sa labelBrush
*/
/*!
\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.
Parameter \a count is the number of iserted values.
\sa append(), insert()
*/
/*!
\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()
*/
/*!
\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()
*/
void valueChanged(int index);
sauimone
Documentation for bar charts
r313 /*!
Constructs QBarSet with a name of \a name and with parent of \a parent
*/
sauimone
barset: unified insert/set/remove methods
r993 QBarSet::QBarSet(const QString name, QObject *parent)
sauimone
updated barchart examples. minor fixes
r276 : QObject(parent)
sauimone
barchart pimpl part 1
r934 ,d_ptr(new QBarSetPrivate(name,this))
sauimone
proof of concept implementation for barset and barcategory
r169 {
}
sauimone
barchart: doc update for hover signals
r980 /*!
Destroys the barset
*/
Jani Honkonen
Fix vs build problems with bar
r944 QBarSet::~QBarSet()
{
sauimone
barchart: doc update for hover signals
r980 // NOTE: d_ptr destroyed by QObject
Jani Honkonen
Fix vs build problems with bar
r944 }
sauimone
Documentation for bar charts
r313 /*!
Sets new \a name for set.
*/
sauimone
barset: unified insert/set/remove methods
r993 void QBarSet::setName(const QString name)
sauimone
proof of concept implementation for barset and barcategory
r169 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 d_ptr->m_name = name;
sauimone
barchart signals for properties and changes
r1353 emit nameChanged();
sauimone
proof of concept implementation for barset and barcategory
r169 }
sauimone
Documentation for bar charts
r313
/*!
Returns name of the set.
*/
sauimone
const to getters, renamed addBarset to appendBarset
r776 QString QBarSet::name() const
sauimone
Barset and barcategory implememtation. Updated test application
r171 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 return d_ptr->m_name;
sauimone
Barset and barcategory implememtation. Updated test application
r171 }
sauimone
proof of concept implementation for barset and barcategory
r169
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 /*!
Appends a point to set. Parameter \a value x coordinate defines the
position in x-axis and y coordinate defines the height of bar.
Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
the x values are used or ignored.
*/
sauimone
new series: groupedbarseries
r1167 void QBarSet::append(const QPointF value)
{
sauimone
barchart signals for properties and changes
r1353 int index = d_ptr->m_values.count();
d_ptr->append(value);
emit valuesAdded(index, 1);
sauimone
new series: groupedbarseries
r1167 }
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 /*!
sauimone
documentation fix
r1243 Appends a list of \a values to set. Works like append with single point.
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 \sa append()
*/
sauimone
new series: groupedbarseries
r1167 void QBarSet::append(const QList<QPointF> values)
{
sauimone
barchart signals for properties and changes
r1353 int index = d_ptr->m_values.count();
d_ptr->append(values);
emit valuesAdded(index, values.count());
sauimone
new series: groupedbarseries
r1167 }
sauimone
Documentation for bar charts
r313 /*!
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
with x coordinate being the index of appended value and y coordinate is the value.
sauimone
Documentation for bar charts
r313 */
sauimone
barset: unified insert/set/remove methods
r993 void QBarSet::append(const qreal value)
sauimone
proof of concept implementation for barset and barcategory
r169 {
sauimone
barchart signals for properties and changes
r1353 // Convert to QPointF and use other append(QPointF) method.
sauimone
new series: groupedbarseries
r1167 append(QPointF(d_ptr->m_values.count(), value));
}
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 /*!
Marek Rosa
Docs update for BarSeries and BarSet
r1361 Appends a list of reals to set. Works like append with single real value. The \a values in list
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
\sa append()
*/
sauimone
new series: groupedbarseries
r1167 void QBarSet::append(const QList<qreal> values)
{
int index = d_ptr->m_values.count();
sauimone
barchart signals for properties and changes
r1353 d_ptr->append(values);
emit valuesAdded(index, values.count());
sauimone
barset: unified insert/set/remove methods
r993 }
/*!
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 Convinience operator. Same as append, with real \a value.
\sa append()
sauimone
barset: unified insert/set/remove methods
r993 */
QBarSet& QBarSet::operator << (const qreal &value)
{
append(value);
sauimone
proof of concept implementation for barset and barcategory
r169 return *this;
}
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 /*!
Convinience operator. Same as append, with QPointF \a value.
\sa append()
*/
sauimone
new series: groupedbarseries
r1167 QBarSet& QBarSet::operator << (const QPointF &value)
{
append(value);
return *this;
}
Marek Rosa
Updated spline chart example documentation and added some more docs to barseries
r901 /*!
sauimone
barset: unified insert/set/remove methods
r993 Inserts new \a value on the \a index position.
The value that is currently at this postion is moved to postion index + 1
\sa remove()
Marek Rosa
Updated spline chart example documentation and added some more docs to barseries
r901 */
sauimone
barset: unified insert/set/remove methods
r993 void QBarSet::insert(const int index, const qreal value)
Marek Rosa
Adding data to BarSet through model added
r662 {
sauimone
barchart signals for properties and changes
r1353 d_ptr->insert(index, value);
emit valuesAdded(index,1);
}
/*!
Inserts new \a value on the \a index position.
The value that is currently at this postion is moved to postion index + 1
\sa remove()
*/
void QBarSet::insert(const int index, const QPointF value)
{
d_ptr->insert(index,value);
emit valuesAdded(index,1);
Marek Rosa
Adding data to BarSet through model added
r662 }
Marek Rosa
Updated spline chart example documentation and added some more docs to barseries
r901 /*!
Marek Rosa
Docs update for BarSeries and BarSet
r1361 Removes \a count number of values from the set starting at \a index.
Returns true if remove operation was succesfull.
sauimone
barset: unified insert/set/remove methods
r993 \sa insert()
Marek Rosa
Updated spline chart example documentation and added some more docs to barseries
r901 */
sauimone
barchart signals for properties and changes
r1353 bool QBarSet::remove(const int index, const int count)
Marek Rosa
Removing data from BarSeries through model added
r663 {
sauimone
barchart signals for properties and changes
r1353 bool success = d_ptr->remove(index,count);
if (success) {
emit valuesRemoved(index,count);
}
return success;
Marek Rosa
Removing data from BarSeries through model added
r663 }
sauimone
Documentation for bar charts
r313 /*!
sauimone
barset: unified insert/set/remove methods
r993 Sets a new value \a value to set, indexed by \a index
sauimone
Documentation for bar charts
r313 */
sauimone
barset: unified insert/set/remove methods
r993 void QBarSet::replace(const int index, const qreal value)
sauimone
Barset and barcategory implememtation. Updated test application
r171 {
sauimone
barchart signals for properties and changes
r1353 d_ptr->replace(index,value);
emit valueChanged(index);
}
/*!
Sets a new value \a value to set, indexed by \a index
*/
void QBarSet::replace(const int index, const QPointF value)
{
d_ptr->replace(index,value);
emit valueChanged(index);
sauimone
Barset and barcategory implememtation. Updated test application
r171 }
sauimone
Documentation for bar charts
r313 /*!
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
of the QPointF (if appended with QPointF append).
If the index is out of bounds QPointF(0, 0.0) is returned.
sauimone
Documentation for bar charts
r313 */
sauimone
new series: groupedbarseries
r1167 QPointF QBarSet::at(const int index) const
sauimone
Barset and barcategory implememtation. Updated test application
r171 {
sauimone
warning are errors. fixed
r1168 if (index < 0 || index >= d_ptr->m_values.count()) {
return QPointF(index, 0.0);
}
Tero Ahola
Added declarative model for bar series
r1162
Michal Klocek
Adds big fat pimpl to series classes...
r938 return d_ptr->m_values.at(index);
sauimone
Barset and barcategory implememtation. Updated test application
r171 }
sauimone
Documentation for bar charts
r313 /*!
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
of the QPointF (if appended with QPointF append).
sauimone
Documentation for bar charts
r313 */
sauimone
new series: groupedbarseries
r1167 QPointF QBarSet::operator [](const int index) const
sauimone
brush support for bargroups
r183 {
sauimone
barset: unified insert/set/remove methods
r993 return d_ptr->m_values.at(index);
}
/*!
Returns count of values in set.
*/
int QBarSet::count() const
{
return d_ptr->m_values.count();
sauimone
brush support for bargroups
r183 }
sauimone
fixed example paths in barchart documentation
r492 /*!
sauimone
Fixed category handling of barcharts. Now the categories can be undefined. Updated documentation.
r1208 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
sauimone
fixed example paths in barchart documentation
r492 */
sauimone
barchart pimpl part 1
r934 qreal QBarSet::sum() const
sauimone
updating drilldown example. Needs some more thinking
r438 {
qreal total(0);
Michal Klocek
Adds big fat pimpl to series classes...
r938 for (int i=0; i < d_ptr->m_values.count(); i++) {
sauimone
new series: groupedbarseries
r1167 //total += d_ptr->m_values.at(i);
total += d_ptr->m_values.at(i).y();
sauimone
updating drilldown example. Needs some more thinking
r438 }
return total;
}
sauimone
Documentation for bar charts
r313 /*!
Sets pen for set. Bars of this set are drawn using \a pen
*/
sauimone
minor code review fixes, part n
r763 void QBarSet::setPen(const QPen &pen)
sauimone
Added pen & brush to QBarSet
r214 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 if(d_ptr->m_pen!=pen){
d_ptr->m_pen = pen;
sauimone
barchart: removed mousebuttons from clicked signal. removed selected signal. unified internal signal naming in barset and barseries private
r1008 emit d_ptr->updatedBars();
sauimone
barchart signals for properties and changes
r1353 emit penChanged();
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
Documentation for bar charts
r313 /*!
Returns pen of the set.
*/
sauimone
Fixed layout for barcharts
r473 QPen QBarSet::pen() const
sauimone
Added pen & brush to QBarSet
r214 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 return d_ptr->m_pen;
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
Documentation for bar charts
r313 /*!
Sets brush for the set. Bars of this set are drawn using \a brush
*/
sauimone
minor code review fixes, part n
r763 void QBarSet::setBrush(const QBrush &brush)
sauimone
Added pen & brush to QBarSet
r214 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 if(d_ptr->m_brush!=brush){
d_ptr->m_brush = brush;
sauimone
barchart: removed mousebuttons from clicked signal. removed selected signal. unified internal signal naming in barset and barseries private
r1008 emit d_ptr->updatedBars();
sauimone
barchart signals for properties and changes
r1353 emit brushChanged();
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
Documentation for bar charts
r313 /*!
Returns brush of the set.
*/
sauimone
Fixed layout for barcharts
r473 QBrush QBarSet::brush() const
sauimone
Added pen & brush to QBarSet
r214 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 return d_ptr->m_brush;
sauimone
Added pen & brush to QBarSet
r214 }
sauimone
renamed barchart floating values with labels to be consistent with piechart
r820 /*!
sauimone
fixed clipping in barcharts
r839 Sets \a brush of the values that are drawn on top of this barset
sauimone
renamed barchart floating values with labels to be consistent with piechart
r820 */
void QBarSet::setLabelBrush(const QBrush &brush)
{
Michal Klocek
Adds big fat pimpl to series classes...
r938 if(d_ptr->m_labelBrush!=brush){
d_ptr->m_labelBrush = brush;
sauimone
barchart: removed mousebuttons from clicked signal. removed selected signal. unified internal signal naming in barset and barseries private
r1008 emit d_ptr->updatedBars();
sauimone
barchart signals for properties and changes
r1353 emit labelBrushChanged();
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
sauimone
renamed barchart floating values with labels to be consistent with piechart
r820 }
/*!
Returns brush of the values that are drawn on top of this barset
*/
QBrush QBarSet::labelBrush() const
{
Michal Klocek
Adds big fat pimpl to series classes...
r938 return d_ptr->m_labelBrush;
sauimone
renamed barchart floating values with labels to be consistent with piechart
r820 }
/*!
sauimone
fixed clipping in barcharts
r839 Sets the \a font for values that are drawn on top of this barset
sauimone
renamed barchart floating values with labels to be consistent with piechart
r820 */
void QBarSet::setLabelFont(const QFont &font)
{
Michal Klocek
Adds big fat pimpl to series classes...
r938 if(d_ptr->m_labelFont!=font) {
d_ptr->m_labelFont = font;
sauimone
barchart: removed mousebuttons from clicked signal. removed selected signal. unified internal signal naming in barset and barseries private
r1008 emit d_ptr->updatedBars();
sauimone
barchart signals for properties and changes
r1353 emit labelFontChanged();
Michal Klocek
Adds big fat pimpl to series classes...
r938 }
sauimone
better use of gradients in barcharts
r512 }
/*!
sauimone
Barchart value layout fix
r817 Returns the pen for values that are drawn on top of this set
sauimone
better use of gradients in barcharts
r512 */
sauimone
renamed barchart floating values with labels to be consistent with piechart
r820 QFont QBarSet::labelFont() const
sauimone
better use of gradients in barcharts
r512 {
Michal Klocek
Adds big fat pimpl to series classes...
r938 return d_ptr->m_labelFont;
sauimone
better use of gradients in barcharts
r512 }
Michal Klocek
Adds big fat pimpl to series classes...
r938 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sauimone
barset: unified insert/set/remove methods
r993 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
Michal Klocek
Adds big fat pimpl to series classes...
r938 q_ptr(parent),
sauimone
removed barlabel. label visibility control is now per series instead of per set
r1246 m_name(name)
Michal Klocek
Adds big fat pimpl to series classes...
r938 {
}
QBarSetPrivate::~QBarSetPrivate()
{
}
sauimone
barset: selected is now private signal
r1017
sauimone
barchart signals for properties and changes
r1353 void QBarSetPrivate::append(QPointF value)
{
m_values.append(value);
emit restructuredBars();
}
void QBarSetPrivate::append(QList<QPointF> values)
{
for (int i=0; i<values.count(); i++) {
m_values.append(values.at(i));
}
emit restructuredBars();
}
void QBarSetPrivate::append(QList<qreal> values)
{
int index = m_values.count();
for (int i=0; i<values.count(); i++) {
m_values.append(QPointF(index,values.at(i)));
index++;
}
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();
}
bool QBarSetPrivate::remove(const int index, const int count)
{
if ((index + count) > m_values.count()) {
// cant remove more values than there are
return false;
}
int c = count;
while (c > 0) {
m_values.removeAt(index);
c--;
}
emit restructuredBars();
return true;
}
void QBarSetPrivate::replace(const int index, const qreal value)
{
m_values.replace(index,QPointF(index,value));
emit updatedBars();
}
void QBarSetPrivate::replace(const int index, const QPointF value)
{
m_values.replace(index,value);
emit updatedBars();
}
sauimone
signals and slots for bars and sets
r239 #include "moc_qbarset.cpp"
Michal Klocek
Adds big fat pimpl to series classes...
r938 #include "moc_qbarset_p.cpp"
Tero Ahola
Code review: Fixed simple issues in Bar and Legend
r737
sauimone
proof of concept implementation for barset and barcategory
r169 QTCOMMERCIALCHART_END_NAMESPACE