diff --git a/doc/src/examples-boxplotchart.qdoc b/doc/src/examples-boxplotchart.qdoc new file mode 100644 index 0000000..b9bde2b --- /dev/null +++ b/doc/src/examples-boxplotchart.qdoc @@ -0,0 +1,38 @@ +/*! + \example examples/boxplotchart + \title Box and Whiskers Example + \subtitle + + The example shows how to create a box-and-whiskers chart. + + \image examples_barchart.png + + Introduction here + + \snippet ../examples/barchart/main.cpp 1 + + Ykk�skohta + + \snippet ../examples/barchart/main.cpp 2 + + Kakkoskohta + + \snippet ../examples/barchart/main.cpp 3 + + Kolmoskohta + + \snippet ../examples/barchart/main.cpp 4 + + Neloskohta + + \snippet ../examples/barchart/main.cpp 5 + + Tarkista numerointi. Finally we add the chart onto a view. We also turn on the antialiasing for the chartView. + + \snippet ../examples/barchart/main.cpp 6 + + Tarkista numerointi. Chart is ready to be shown. We set the chart to be central widget of the window. + We also set the size for the chart window and show it. + + \snippet ../examples/barchart/main.cpp 7 +*/ diff --git a/src/barchart/qvbarmodelmapper.cpp b/src/barchart/qvbarmodelmapper.cpp index 5f99e98..87f454e 100644 --- a/src/barchart/qvbarmodelmapper.cpp +++ b/src/barchart/qvbarmodelmapper.cpp @@ -58,7 +58,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! \property QVBarModelMapper::series - \brief Defines the QPieSeries object that is used by the mapper. + \brief Defines the QBarSeries object that is used by the mapper. All the data in the series is discarded when it is set to the mapper. When new series is specified the old series is disconnected (it preserves its data) diff --git a/src/boxplotchart/boxplotchartitem.cpp b/src/boxplotchart/boxplotchartitem.cpp index b253859..7fb1531 100644 --- a/src/boxplotchart/boxplotchartitem.cpp +++ b/src/boxplotchart/boxplotchartitem.cpp @@ -82,22 +82,26 @@ void BoxPlotChartItem::handleDataStructureChanged() for (int s = 0; s < setCount; s++) { QBoxSet *set = m_series->d_func()->boxsetAt(s); - BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); - if (boxWhiskersItem == 0) { + BoxWhiskers *box = m_boxTable.value(set); + if (!box) { // Item is not yet created, make a box and add it to hash table - boxWhiskersItem = new BoxWhiskers(domain(), this); - m_boxTable.insert(set, boxWhiskersItem); + box = new BoxWhiskers(set, domain(), this); + m_boxTable.insert(set, box); + connect(box, SIGNAL(clicked(QBoxSet *)), m_series, SIGNAL(clicked(QBoxSet*))); + connect(box, SIGNAL(hovered(bool,QBoxSet*)), m_series, SIGNAL(hovered(bool,QBoxSet*))); + connect(box, SIGNAL(clicked(QBoxSet*)), set, SIGNAL(clicked())); + connect(box, SIGNAL(hovered(bool,QBoxSet*)), set, SIGNAL(hovered(bool))); // Set the decorative issues for the newly created box - boxWhiskersItem->setBrush(m_series->brush()); - boxWhiskersItem->setPen(m_series->pen()); + box->setBrush(m_series->brush()); + box->setPen(m_series->pen()); } - updateBoxGeometry(boxWhiskersItem, s); + updateBoxGeometry(box, s); - boxWhiskersItem->updateGeometry(); + box->updateGeometry(); if (m_animation) - m_animation->addBox(boxWhiskersItem); + m_animation->addBox(box); } // diff --git a/src/boxplotchart/boxwhiskers.cpp b/src/boxplotchart/boxwhiskers.cpp index 46bd58e..805657a 100644 --- a/src/boxplotchart/boxwhiskers.cpp +++ b/src/boxplotchart/boxwhiskers.cpp @@ -20,42 +20,41 @@ #include "boxwhiskers_p.h" #include -#include #include +#include + QTCOMMERCIALCHART_BEGIN_NAMESPACE -BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) : +BoxWhiskers::BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent) : QGraphicsObject(parent), + m_boxSet(set), m_domain(domain) { - //qDebug() << "BoxWhiskers::BoxWhiskers()"; + setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::MouseButtonMask); } BoxWhiskers::~BoxWhiskers() { - //qDebug() << "BoxWhiskers::~BoxWhiskers()"; } void BoxWhiskers::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event) - - qDebug() << "BoxWhiskers::mousePressEvent"; + emit clicked(m_boxSet); } void BoxWhiskers::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event) - - qDebug() << "BoxWhiskers::hoverEnterEvent"; + emit hovered(true, m_boxSet); } void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event) - - qDebug() << "BoxWhiskers::hoverLeaveEvent"; + emit hovered(false, m_boxSet); } void BoxWhiskers::setBrush(const QBrush &brush) diff --git a/src/boxplotchart/boxwhiskers_p.h b/src/boxplotchart/boxwhiskers_p.h index b1fb268..ea4f9d8 100644 --- a/src/boxplotchart/boxwhiskers_p.h +++ b/src/boxplotchart/boxwhiskers_p.h @@ -32,8 +32,8 @@ #include "boxwhiskersdata_p.h" #include "qchartglobal.h" -#include "qbarset.h" #include "abstractdomain_p.h" +#include #include #include #include @@ -48,7 +48,7 @@ class BoxWhiskers : public QGraphicsObject/*, public QGraphicsLayoutItem*/ Q_OBJECT //Q_INTERFACES(QGraphicsLayoutItem) public: - BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent); + BoxWhiskers(QBoxSet *set, AbstractDomain *domain, QGraphicsObject *parent); ~BoxWhiskers(); void setBrush(const QBrush &brush); @@ -73,13 +73,14 @@ private: void updateBoundingRect(); Q_SIGNALS: - void clicked(int index, QBarSet *barset); - void hovered(bool status, QBarSet *barset); + void clicked(QBoxSet *boxset); + void hovered(bool status, QBoxSet *boxset); private: friend class BoxPlotChartItem; friend class BoxPlotAnimation; + QBoxSet *m_boxSet; AbstractDomain *m_domain; QPainterPath m_boxPath; QRectF m_boundingRect; diff --git a/src/boxplotchart/qboxplotseries.cpp b/src/boxplotchart/qboxplotseries.cpp index b851767..93188d2 100644 --- a/src/boxplotchart/qboxplotseries.cpp +++ b/src/boxplotchart/qboxplotseries.cpp @@ -38,25 +38,25 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! \class QBoxPlotSeries - \brief Series for creating stacked bar chart + \brief Series for creating box-and-whiskers chart \mainclass - QBoxPlotSeries 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. - QBoxPlotSeries groups the data from sets to categories, which are defined by QStringList. + QBoxPlotSeries represents a series of data shown as box-and-whisker bars. The purpose of this class is to act as + a container for single box-and-whisker items. Each item is drawn to own slot. If chart includes multiple QBoxPlotSeries + items with the same index are drawn to same slot. - See the \l {BoxPlotChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. + See the \l {Box and Whiskers Example} {box-and-whiskers chart example} to learn how to create a box-and-whiskers chart. \image examples_boxplotchart.png - \sa QBoxSet, QPercentBarSeries, QAbstractBarSeries + \sa QBoxSet */ /*! \qmlclass BoxPlotSeries QBoxPlotSeries \inherits AbstractBarSeries - The following QML shows how to create a simple stacked bar chart: - \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 + The following QML shows how to create a simple box-and-whiskers chart: + \snippet ../examples/qmlboxplot/qml/qmlboxplot/main.qml 1 \beginfloatleft \image demos_qmlchart7.png \endfloat @@ -64,6 +64,31 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! + \fn QBoxPlotSeries::boxsetsAdded(QList sets) + \brief Signal is emitted when a new \a sets of box-and-whiskers data is added to the series. +*/ + +/*! + \fn QBoxPlotSeries::boxsetsRemoved(QList sets) + \brief Signal is emitted when \a sets of box-and-whiskers data is removed from the series. +*/ + +/*! + \fn QBoxPlotSeries::clicked(QBoxSet *boxset) + \brief Signal is emitted when the user clicks the \a boxset on the chart. +*/ + +/*! + \fn QBoxPlotSeries::hovered(bool status, QBoxSet *boxset) + \brief Signal is emitted when there is change in hover \a status over \a boxset. +*/ + +/*! + \fn QBoxPlotSeries::countChanged() + \brief Signal is emitted when there is change in count of box-and-whiskers items in the series. +*/ + +/*! Constructs empty QBoxPlotSeries. QBoxPlotSeries is QObject which is a child of a \a parent. */ @@ -85,7 +110,7 @@ QBoxPlotSeries::~QBoxPlotSeries() } /*! - Adds a single box and whiskers item to series. Takes ownership of \a the box. If the box is null or is already in series, it won't be appended. + Adds a single box and whiskers set to series. Takes ownership of the \a set. If the set is null or is already in series, it won't be appended. Returns true, if appending succeeded. */ bool QBoxPlotSeries::append(QBoxSet *set) @@ -223,6 +248,9 @@ QAbstractSeries::SeriesType QBoxPlotSeries::type() const return QAbstractSeries::SeriesTypeBoxPlot; } +/*! + Sets brush for the series. Box-and-whiskers items are drawn using \a brush +*/ void QBoxPlotSeries::setBrush(const QBrush &brush) { Q_D(QBoxPlotSeries); @@ -233,6 +261,9 @@ void QBoxPlotSeries::setBrush(const QBrush &brush) } } +/*! + Returns brush of the series. +*/ QBrush QBoxPlotSeries::brush() const { Q_D(const QBoxPlotSeries); @@ -240,6 +271,9 @@ QBrush QBoxPlotSeries::brush() const return d->m_brush; } +/*! + Sets pen for the series. Box-and-whiskers items are drawn using \a pen +*/ void QBoxPlotSeries::setPen(const QPen &pen) { Q_D(QBoxPlotSeries); @@ -250,6 +284,9 @@ void QBoxPlotSeries::setPen(const QPen &pen) } } +/*! + Returns the pen of this series. +*/ QPen QBoxPlotSeries::pen() const { Q_D(const QBoxPlotSeries); diff --git a/src/boxplotchart/qboxplotseries.h b/src/boxplotchart/qboxplotseries.h index 466486f..4a46c9e 100644 --- a/src/boxplotchart/qboxplotseries.h +++ b/src/boxplotchart/qboxplotseries.h @@ -23,13 +23,11 @@ #include #include -//#include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE class QBoxPlotSeriesPrivate; -//class QBarSet; class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries { @@ -47,9 +45,6 @@ public: QList boxSets() const; void clear(); - void setLabelsVisible(bool visible = true); - bool isLabelsVisible() const; - QAbstractSeries::SeriesType type() const; void setBrush(const QBrush &brush); @@ -58,10 +53,9 @@ public: QPen pen() const; Q_SIGNALS: - void clicked(int index, QBoxSet *boxset); + void clicked(QBoxSet *boxset); void hovered(bool status, QBoxSet *boxset); void countChanged(); - void labelsVisibleChanged(); void boxsetsAdded(QList sets); void boxsetsRemoved(QList sets); diff --git a/src/boxplotchart/qboxset.cpp b/src/boxplotchart/qboxset.cpp index aba37b0..2abc6ff 100644 --- a/src/boxplotchart/qboxset.cpp +++ b/src/boxplotchart/qboxset.cpp @@ -27,7 +27,101 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! - Constructs QBoxSet with parent of \a parent + \class QBoxSet + \brief Building block for box-and-whiskers chart + + QBoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation + of range and three medians. There's two type of methods to give the values. The first one is with constructor + or append type of methods (append and operator <<). In these the values have to be given in order lower extreme, + lower quartile, median, upper quartile and upper extre. Second method is to create an empty QBoxSet instance and + give the values using own methods. + + \mainclass + + \sa QBoxPlotSeries +*/ +/*! + \qmlclass BoxSet QBoxSet + + BoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation + of range and three medians. There's two type of methods to give the values. The first one is with constructor + or append type of methods (append and operator <<). In these the values have to be given in order lower extreme, + lower quartile, median, upper quartile and upper extre. Second method is to create an empty BoxSet instance and + give the values using own methods. + \sa BoxPlotSeries +*/ + +/*! + \property QBoxSet::pen + \brief Defines the pen used by the box-and-whiskers set. +*/ + +/*! + \property QBoxSet::brush + \brief Defines the brush used by the box-and-whiskers set. +*/ + +/*! + \property QBoxSet::color + The fill (brush) color of the box-and-whiskers set. +*/ + +/*! + \property QBoxSet::borderColor + The line (pen) color of the box-and-whiskers set. +*/ + +/*! + \fn void QBoxSet::clicked() + The signal is emitted if the user clicks with a mouse on top of box-and-whisker item. +*/ + +/*! + \fn void QBoxSet::hovered(bool status) + + The signal is emitted if mouse is hovered on top of box-and-whisker item. + Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item. +*/ + +/*! + \fn void QBoxSet::penChanged() + This signal is emitted when the pen of the box-and-whisker item has changed. + \sa pen +*/ + +/*! + \fn void QBoxSet::brushChanged() + This signal is emitted when the brush of the box-and-whisker item has changed. + \sa brush +*/ + +/*! + \fn void QBoxSet::colorChanged(QColor) + This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color. +*/ + +/*! + \fn void QBoxSet::valuesAdded(int index, int count) + This signal is emitted when new values have been added to the box-and-whisker item. + Parameter \a index indicates the position of the first inserted value. + Parameter \a count is the number of inserted values. + \sa append(), insert() +*/ + +/*! + \fn void QBoxSet::valueChanged(int index) + This signal is emitted values the value in the box-and-whisker item has been modified. + Parameter \a index indicates the position of the modified value. + \sa at() +*/ + +/*! + \fn void QBoxSet::borderColorChanged(QColor) + This signal is emitted when the line (pen) color of the box-and-whisker item has changed to \a color. +*/ + +/*! + Constructs QBoxSet with optional \a label and parent of \a parent */ QBoxSet::QBoxSet(const QString label, QObject *parent) : QObject(parent), @@ -35,15 +129,19 @@ QBoxSet::QBoxSet(const QString label, QObject *parent) { } -QBoxSet::QBoxSet(qreal value1, qreal value2, qreal value3, qreal value4, qreal value5, const QString label, QObject *parent) +/*! + Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median, + \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional. + */ +QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label = "", QObject *parent) : QObject(parent), d_ptr(new QBoxSetPrivate(label, this)) { - d_ptr->append(value1); - d_ptr->append(value2); - d_ptr->append(value3); - d_ptr->append(value4); - d_ptr->append(value5); + d_ptr->append(le); + d_ptr->append(lq); + d_ptr->append(m); + d_ptr->append(uq); + d_ptr->append(ue); } /*! diff --git a/src/boxplotchart/qboxset.h b/src/boxplotchart/qboxset.h index 93750c0..6cbc0dd 100644 --- a/src/boxplotchart/qboxset.h +++ b/src/boxplotchart/qboxset.h @@ -39,7 +39,7 @@ class QTCOMMERCIALCHART_EXPORT QBoxSet : public QObject public: explicit QBoxSet(const QString label = "", QObject *parent = 0); - explicit QBoxSet(const qreal value1, const qreal value2, const qreal value3, const qreal value4, const qreal value5, const QString label = "", QObject *parent = 0); + explicit QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label = "", QObject *parent = 0); virtual ~QBoxSet(); void append(const qreal value); @@ -62,7 +62,6 @@ public: QBoxSet &operator << (const qreal &value); void insert(const int index, const qreal value); - void remove(const int index, const int count = 1); void replace(const int index, const qreal value); qreal at(const int index) const; qreal operator [](const int index) const; @@ -82,7 +81,7 @@ public: Q_SIGNALS: - void clicked(int index); + void clicked(); void hovered(bool status); void penChanged(); void brushChanged(); @@ -90,7 +89,6 @@ Q_SIGNALS: void borderColorChanged(QColor color); void valuesAdded(int index, int count); - void valuesRemoved(int index, int count); void valueChanged(int index); private: diff --git a/src/boxplotchart/qvboxplotmodelmapper.cpp b/src/boxplotchart/qvboxplotmodelmapper.cpp index 750d9be..8188ca4 100644 --- a/src/boxplotchart/qvboxplotmodelmapper.cpp +++ b/src/boxplotchart/qvboxplotmodelmapper.cpp @@ -28,21 +28,21 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \mainclass Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. - Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. + Vertical model mapper is used to create a connection between QBoxPlotSeries and QAbstractItemModel derived model object. Model mapper maintains equal size of all the BarSets. - Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. Note: used model has to support adding/removing rows/columns and modifying the data of the cells. */ /*! - \qmlclass VBarModelMapper + \qmlclass VBoxPlotModelMapper \mainclass - VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source - for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. - VBarModelMapper keeps the series and the model in sync. + VBoxPlotModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source + for any box-and-whiskers series. It is possible to use both QAbstractItemModel and box-and-whiskers series data API to + manipulate data. + VBoxPlotModelMapper keeps the series and the model in sync. - The following QML example would create a bar series with three bar sets (assuming the - model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be + The following QML example would create a box-and-whiskers series with three box sets (assuming the + model has at least four columns). Each box set would contain data starting from row 1. The name of a set would be defined by the horizontal header (of the column). \code BarSeries { @@ -58,7 +58,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! \property QVBoxPlotModelMapper::series - \brief Defines the QPieSeries object that is used by the mapper. + \brief Defines the QBoxPlotSeries object that is used by the mapper. All the data in the series is discarded when it is set to the mapper. When new series is specified the old series is disconnected (it preserves its data) @@ -81,46 +81,46 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \property QVBoxPlotModelMapper::firstBarSetColumn - \brief Defines which column of the model is used as the data source for the first bar set + \property QVBoxPlotModelMapper::firstBoxSetColumn + \brief Defines which column of the model is used as the data source for the first box-and-whiskers set Default value is: -1 (invalid mapping) */ /*! - \qmlproperty int VBarModelMapper::firstBarSetColumn - Defines which column of the model is used as the data source for the first bar set. Default value + \qmlproperty int VBarModelMapper::firstBoxSetColumn + Defines which column of the model is used as the data source for the first box-and-whiskers set. Default value is: -1 (invalid mapping). */ /*! - \property QVBoxPlotModelMapper::lastBarSetColumn - \brief Defines which column of the model is used as the data source for the last bar set + \property QVBoxPlotModelMapper::lastBoxSetColumn + \brief Defines which column of the model is used as the data source for the last box-and-whiskers set Default value is: -1 (invalid mapping) */ /*! - \qmlproperty int VBarModelMapper::lastBarSetColumn - Defines which column of the model is used as the data source for the last bar set. Default + \qmlproperty int VBarModelMapper::lastBoxSetColumn + Defines which column of the model is used as the data source for the last box-and-whiskers set. Default value is: -1 (invalid mapping). */ /*! \property QVBoxPlotModelMapper::firstRow - \brief Defines which row of the model contains the first values of the QBarSets in the series. + \brief Defines which row of the model contains the first values of the QBoxSets in the series. Minimal and default value is: 0 */ /*! - \qmlproperty int VBarModelMapper::firstRow - Defines which row of the model contains the first values of the QBarSets in the series. + \qmlproperty int VBoxPlotModelMapper::firstRow + Defines which row of the model contains the first values of the QBoxSets in the series. The default value is 0. */ /*! \property QVBoxPlotModelMapper::rowCount - \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries + \brief Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries Minimal and default value is: -1 (count limited by the number of rows in the model) */ /*! - \qmlproperty int VBarModelMapper::rowCount - Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is + \qmlproperty int VBoxModelMapper::rowCount + Defines the number of rows of the model that are mapped as the data for QBoxPlotSeries. The default value is -1 (count limited by the number of rows in the model) */ @@ -137,13 +137,13 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE */ /*! - \fn void QVBoxPlotModelMapper::firstBarSetColumnChanged() - Emitted when the firstBarSetColumn has changed. + \fn void QVBoxPlotModelMapper::firstBoxSetColumnChanged() + Emitted when the firstBoxSetColumn has changed. */ /*! - \fn void QVBoxPlotModelMapper::lastBarSetColumnChanged() - Emitted when the lastBarSetColumn has changed. + \fn void QVBoxPlotModelMapper::lastBoxSetColumnChanged() + Emitted when the lastBoxSetColumn has changed. */ /*! diff --git a/src/legend/qlegendmarker.cpp b/src/legend/qlegendmarker.cpp index 8453a5b..e2a5b33 100644 --- a/src/legend/qlegendmarker.cpp +++ b/src/legend/qlegendmarker.cpp @@ -53,6 +53,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \value LegendMarkerTypeBar \value LegendMarkerTypePie \value LegendMarkerTypeXY + \value LegendMarkerTypeBoxPlot */ /*! diff --git a/src/qabstractseries.cpp b/src/qabstractseries.cpp index 9dae53b..1f6dd2a 100644 --- a/src/qabstractseries.cpp +++ b/src/qabstractseries.cpp @@ -62,6 +62,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE \value SeriesTypeHorizontalBar \value SeriesTypeHorizontalStackedBar \value SeriesTypeHorizontalPercentBar + \value SeriesTypeBoxPlot */ /*! diff --git a/tests/boxplottester/mainwidget.cpp b/tests/boxplottester/mainwidget.cpp index 0300f3f..37b21bd 100644 --- a/tests/boxplottester/mainwidget.cpp +++ b/tests/boxplottester/mainwidget.cpp @@ -206,6 +206,11 @@ void MainWidget::addSeries() m_series[nSeries]->append(set5); m_series[nSeries]->setName("Box & Whiskers"); + connect(m_series[nSeries], SIGNAL(clicked(QBoxSet*)), this, SLOT(boxClicked(QBoxSet*))); + connect(m_series[nSeries], SIGNAL(hovered(bool, QBoxSet*)), this, SLOT(boxHovered(bool, QBoxSet*))); + connect(set1, SIGNAL(clicked()), this, SLOT(singleBoxClicked())); + connect(set2, SIGNAL(hovered(bool)), this, SLOT(singleBoxHovered(bool))); + m_chart->addSeries(m_series[nSeries]); if (nSeries == 0) { @@ -356,3 +361,29 @@ void MainWidget::changeChartTheme(int themeIndex) else m_chart->setTheme((QChart::ChartTheme) (themeIndex - 1)); } + +void MainWidget::boxClicked(QBoxSet *set) +{ + qDebug() << "boxClicked, median = " << set->median(); +} + +void MainWidget::boxHovered(bool state, QBoxSet *set) +{ + if (state) + qDebug() << "box median " << set->median() << " hover started"; + else + qDebug() << "box median " << set->median() << " hover ended"; +} + +void MainWidget::singleBoxClicked() +{ + qDebug() << "singleBoxClicked"; +} + +void MainWidget::singleBoxHovered(bool state) +{ + if (state) + qDebug() << "single box hover started"; + else + qDebug() << "single box hover ended"; +} diff --git a/tests/boxplottester/mainwidget.h b/tests/boxplottester/mainwidget.h index 961ad3b..42480bd 100644 --- a/tests/boxplottester/mainwidget.h +++ b/tests/boxplottester/mainwidget.h @@ -28,6 +28,7 @@ #include #include #include +#include class QGridLayout; @@ -58,6 +59,10 @@ private slots: void titleToggled(bool enabled); void modelMapperToggled(bool enabled); void changeChartTheme(int themeIndex); + void boxClicked(QBoxSet *set); + void boxHovered(bool state, QBoxSet *set); + void singleBoxClicked(); + void singleBoxHovered(bool state); private: QChart *m_chart;