diff --git a/examples/boxplotchart/main.cpp b/examples/boxplotchart/main.cpp index 2028257..e9634e1 100644 --- a/examples/boxplotchart/main.cpp +++ b/examples/boxplotchart/main.cpp @@ -22,10 +22,11 @@ #include #include #include -#include +#include #include #include #include +#include #include #include @@ -37,18 +38,18 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); //![1] - QBarSet *set0 = new QBarSet("Jan"); - QBarSet *set1 = new QBarSet("Feb"); - QBarSet *set2 = new QBarSet("Mar"); - QBarSet *set3 = new QBarSet("Apr"); - QBarSet *set4 = new QBarSet("May"); - QBarSet *set5 = new QBarSet("Jun"); - QBarSet *set6 = new QBarSet("Jul"); - QBarSet *set7 = new QBarSet("Aug"); - QBarSet *set8 = new QBarSet("Sep"); - QBarSet *set9 = new QBarSet("Oct"); - QBarSet *set10 = new QBarSet("Nov"); - QBarSet *set11 = new QBarSet("Dec"); + QBoxSet *set0 = new QBoxSet(); + QBoxSet *set1 = new QBoxSet(); + QBoxSet *set2 = new QBoxSet(); + QBoxSet *set3 = new QBoxSet(); + QBoxSet *set4 = new QBoxSet(); + QBoxSet *set5 = new QBoxSet(); + QBoxSet *set6 = new QBoxSet(); + QBoxSet *set7 = new QBoxSet(); + QBoxSet *set8 = new QBoxSet(); + QBoxSet *set9 = new QBoxSet(); + QBoxSet *set10 = new QBoxSet(); + QBoxSet *set11 = new QBoxSet(); // low bot med top upp *set0 << 3 << 4 << 4.4 << 6 << 7; @@ -98,10 +99,23 @@ int main(int argc, char *argv[]) lineSeries->append(11, 8.2); lineSeries->setName("Medians"); + QScatterSeries *scatterSeries = new QScatterSeries(); + scatterSeries->setName("Outliers"); + scatterSeries->setMarkerShape(QScatterSeries::MarkerShapeCircle); + scatterSeries->setMarkerSize(7.0); + scatterSeries->setBrush(QBrush(Qt::white)); + scatterSeries->setPen(QPen(Qt::black, 1.0)); + scatterSeries->append(1, 4); + scatterSeries->append(1, 4.1); + scatterSeries->append(1, 4.2); + scatterSeries->append(1, 4.3); + *scatterSeries << QPointF(3, 8.5) << QPointF(3, 8.6); + //![3] QChart *chart = new QChart(); chart->addSeries(series); chart->addSeries(lineSeries); + chart->addSeries(scatterSeries); chart->setTitle("Simple boxplotchart example"); chart->setAnimationOptions(QChart::SeriesAnimations); //![3] @@ -128,7 +142,7 @@ int main(int argc, char *argv[]) //![7] QMainWindow window; window.setCentralWidget(chartView); - window.resize(400, 300); + window.resize(600, 400); window.show(); //![7] diff --git a/examples/qmlboxplot/qml/qmlboxplot/main.qml b/examples/qmlboxplot/qml/qmlboxplot/main.qml index 554d4e6..d07c709 100644 --- a/examples/qmlboxplot/qml/qmlboxplot/main.qml +++ b/examples/qmlboxplot/qml/qmlboxplot/main.qml @@ -35,11 +35,11 @@ ChartView { id: plotSeries name: "Income" axisX: BarCategoryAxis { categories: ["Jan", "Feb", "Mar", "Apr", "May"] } - BarSet { label: "Jan"; values: [3, 4, 4.4, 6, 7] } - BarSet { label: "Feb"; values: [5, 6, 7.5, 8, 12] } - BarSet { label: "Mar"; values: [2, 5, 5.7, 8, 9] } - BarSet { label: "Apr"; values: [5, 6, 6.8, 7, 8] } - BarSet { label: "May"; values: [4, 5, 5.2, 6, 7] } + BoxSet { values: [3, 4, 4.4, 6, 7] } + BoxSet { values: [5, 6, 7.5, 8, 12] } + BoxSet { values: [2, 5, 5.7, 8, 9] } + BoxSet { values: [5, 6, 6.8, 7, 8] } + BoxSet { values: [4, 5, 5.2, 6, 7] } } //![2] diff --git a/plugins/declarative/declarativeboxplotseries.cpp b/plugins/declarative/declarativeboxplotseries.cpp index 544a337..bd064d3 100644 --- a/plugins/declarative/declarativeboxplotseries.cpp +++ b/plugins/declarative/declarativeboxplotseries.cpp @@ -20,12 +20,46 @@ #include "declarativebarseries.h" #include "declarativeboxplotseries.h" -#include "qbarset.h" +#include "qboxset.h" #include "qvbarmodelmapper.h" #include "qhbarmodelmapper.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE +DeclarativeBoxSet::DeclarativeBoxSet(QObject *parent) + : QBoxSet(parent) +{ + connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int,int))); + connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int,int))); +} + +void DeclarativeBoxSet::handleCountChanged(int index, int count) +{ + Q_UNUSED(index) + Q_UNUSED(count) + emit countChanged(QBoxSet::count()); +} + +QVariantList DeclarativeBoxSet::values() +{ + QVariantList values; + for (int i(0); i < count(); i++) + values.append(QVariant(QBoxSet::at(i))); + return values; +} + +void DeclarativeBoxSet::setValues(QVariantList values) +{ + while (count()) + remove(count() - 1); + + for (int i(0); i < values.count(); i++) { + if (values.at(i).canConvert(QVariant::Double)) + QBoxSet::append(values[i].toDouble()); + } +} + + DeclarativeBoxPlotSeries::DeclarativeBoxPlotSeries(QDeclarativeItem *parent) : QBoxPlotSeries(parent), m_axes(new DeclarativeAxes(this)) @@ -43,14 +77,14 @@ void DeclarativeBoxPlotSeries::classBegin() void DeclarativeBoxPlotSeries::componentComplete() { foreach (QObject *child, children()) { - if (qobject_cast(child)) { - QAbstractBarSeries::append(qobject_cast(child)); + if (qobject_cast(child)) { + QBoxPlotSeries::append(qobject_cast(child)); } else if (qobject_cast(child)) { QVBarModelMapper *mapper = qobject_cast(child); - mapper->setSeries(this); + //mapper->setSeries(this); } else if (qobject_cast(child)) { QHBarModelMapper *mapper = qobject_cast(child); - mapper->setSeries(this); + //mapper->setSeries(this); } } } @@ -67,19 +101,18 @@ void DeclarativeBoxPlotSeries::appendSeriesChildren(QDeclarativeListProperty setList = barSets(); + QList setList = boxSets(); if (index >= 0 && index < setList.count()) - return qobject_cast(setList[index]); + return qobject_cast(setList[index]); return 0; } -DeclarativeBarSet *DeclarativeBoxPlotSeries::insert(int index, QString label, QVariantList values) +DeclarativeBoxSet *DeclarativeBoxPlotSeries::insert(int index, QVariantList values) { - DeclarativeBarSet *barset = new DeclarativeBarSet(this); - barset->setLabel(label); + DeclarativeBoxSet *barset = new DeclarativeBoxSet(this); barset->setValues(values); if (QBoxPlotSeries::insert(index, barset)) return barset; diff --git a/plugins/declarative/declarativeboxplotseries.h b/plugins/declarative/declarativeboxplotseries.h index cd0c010..906268d 100644 --- a/plugins/declarative/declarativeboxplotseries.h +++ b/plugins/declarative/declarativeboxplotseries.h @@ -21,7 +21,7 @@ #ifndef DECLARATIVEBOXPLOT_H #define DECLARATIVEBOXPLOT_H -#include "qbarset.h" +#include "qboxset.h" #include "declarativeaxes.h" #include "qboxplotseries.h" #include @@ -29,6 +29,30 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +class DeclarativeBoxSet : public QBoxSet +{ + Q_OBJECT + Q_PROPERTY(QVariantList values READ values WRITE setValues) + Q_PROPERTY(int count READ count NOTIFY countChanged) + +public: + explicit DeclarativeBoxSet(QObject *parent = 0); + QVariantList values(); + void setValues(QVariantList values); + +public: // From QBoxSet + Q_INVOKABLE void append(qreal value) { QBoxSet::append(value); } + Q_INVOKABLE void remove(const int index, const int count = 1) { QBoxSet::remove(index, count); } + Q_INVOKABLE void replace(int index, qreal value) { QBoxSet::replace(index, value); } + Q_INVOKABLE qreal at(int index) { return QBoxSet::at(index); } + +Q_SIGNALS: + void countChanged(int count); + +private Q_SLOTS: + void handleCountChanged(int index, int count); +}; + class DeclarativeBoxPlotSeries : public QBoxPlotSeries, public QDeclarativeParserStatus { Q_OBJECT @@ -53,10 +77,10 @@ public: QDeclarativeListProperty seriesChildren(); public: - Q_INVOKABLE DeclarativeBarSet *at(int index); - Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); } - Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values); - Q_INVOKABLE bool remove(QBarSet *barset) { return QBoxPlotSeries::remove(barset); } + Q_INVOKABLE DeclarativeBoxSet *at(int index); + Q_INVOKABLE DeclarativeBoxSet *append(QVariantList values) { return insert(count(), values); } + Q_INVOKABLE DeclarativeBoxSet *insert(int index, QVariantList values); + Q_INVOKABLE bool remove(QBoxSet *boxset) { return QBoxPlotSeries::remove(boxset); } Q_INVOKABLE void clear() { return QBoxPlotSeries::clear(); } public: // from QDeclarativeParserStatus diff --git a/plugins/declarative/plugin.cpp b/plugins/declarative/plugin.cpp index dbde203..d2ecdd4 100644 --- a/plugins/declarative/plugin.cpp +++ b/plugins/declarative/plugin.cpp @@ -195,6 +195,7 @@ public: qmlRegisterType(uri, 1, 1, "HorizontalPercentBarSeries"); qmlRegisterType(uri, 1, 1, "PieSeries"); qmlRegisterType(uri, 1, 1, "BarSet"); + qmlRegisterType(uri, 1, 1, "BoxSet"); qmlRegisterType(uri, 1, 1, "ValueAxis"); #ifndef QT_ON_ARM qmlRegisterType(uri, 1, 1, "DateTimeAxis"); diff --git a/src/boxplotchart/boxplotchart.pri b/src/boxplotchart/boxplotchart.pri index 57e1772..c0b2327 100644 --- a/src/boxplotchart/boxplotchart.pri +++ b/src/boxplotchart/boxplotchart.pri @@ -4,13 +4,16 @@ DEPENDPATH += $$PWD SOURCES += \ $$PWD/boxplotchartitem.cpp \ $$PWD/qboxplotseries.cpp \ - $$PWD/boxwhiskers.cpp + $$PWD/boxwhiskers.cpp \ + $$PWD/qboxset.cpp PRIVATE_HEADERS += \ $$PWD/boxplotchartitem_p.h \ $$PWD/qboxplotseries_p.h \ $$PWD/boxwhiskers_p.h \ - $$PWD/boxwhiskersdata_p.h + $$PWD/boxwhiskersdata_p.h \ + $$PWD/qboxset_p.h PUBLIC_HEADERS += \ - $$PWD/qboxplotseries.h + $$PWD/qboxplotseries.h \ + $$PWD/qboxset.h diff --git a/src/boxplotchart/boxplotchartitem.cpp b/src/boxplotchart/boxplotchartitem.cpp index 0bd744c..b253859 100644 --- a/src/boxplotchart/boxplotchartitem.cpp +++ b/src/boxplotchart/boxplotchartitem.cpp @@ -21,9 +21,9 @@ #include "boxplotchartitem_p.h" #include "qboxplotseries_p.h" #include "bar_p.h" -#include "qbarset_p.h" +#include "qboxset_p.h" #include "qabstractbarseries_p.h" -#include "qbarset.h" +#include "qboxset.h" #include "boxwhiskers_p.h" #include @@ -35,15 +35,13 @@ BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) m_animation(0), m_animate(0) { - connect(series, SIGNAL(barsetsRemoved(QList)), this, SLOT(handleBarsetRemove(QList))); - connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); + connect(series, SIGNAL(boxsetsRemoved(QList)), this, SLOT(handleBoxsetRemove(QList))); + connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged())); connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); - connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); + connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars())); connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars())); // QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here setZValue(ChartPresenter::BoxPlotSeriesZValue); - - m_barSets = m_series->barSets(); } BoxPlotChartItem::~BoxPlotChartItem() @@ -82,7 +80,7 @@ void BoxPlotChartItem::handleDataStructureChanged() int setCount = m_series->count(); for (int s = 0; s < setCount; s++) { - QBarSet *set = m_series->d_func()->barsetAt(s); + QBoxSet *set = m_series->d_func()->boxsetAt(s); BoxWhiskers *boxWhiskersItem = m_boxTable.value(set); if (boxWhiskersItem == 0) { @@ -90,6 +88,7 @@ void BoxPlotChartItem::handleDataStructureChanged() boxWhiskersItem = new BoxWhiskers(domain(), this); m_boxTable.insert(set, boxWhiskersItem); + // Set the decorative issues for the newly created box boxWhiskersItem->setBrush(m_series->brush()); boxWhiskersItem->setPen(m_series->pen()); } @@ -113,8 +112,8 @@ void BoxPlotChartItem::handleUpdatedBars() item->setBrush(m_series->brush()); item->setPen(m_series->pen()); } - // Override with QBarSet specific settings - foreach (QBarSet *set, m_boxTable.keys()) { + // Override with QBoxSet specific settings + foreach (QBoxSet *set, m_boxTable.keys()) { if (set->brush().style() != Qt::NoBrush) m_boxTable.value(set)->setBrush(set->brush()); if (set->pen().style() != Qt::NoPen) @@ -122,11 +121,11 @@ void BoxPlotChartItem::handleUpdatedBars() } } -void BoxPlotChartItem::handleBarsetRemove(QList barSets) +void BoxPlotChartItem::handleBoxsetRemove(QList barSets) { //qDebug() << "BoxPlotChartItem::handleBarsetRemove"; - foreach (QBarSet *set, barSets) { + foreach (QBoxSet *set, barSets) { BoxWhiskers *boxItem = m_boxTable.value(set); m_boxTable.remove(set); delete boxItem; @@ -193,7 +192,7 @@ bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index) { bool changed = false; - QBarSet *set = m_series->d_func()->barsetAt(index); + QBoxSet *set = m_series->d_func()->boxsetAt(index); BoxWhiskersData &data = box->m_data; if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) || diff --git a/src/boxplotchart/boxplotchartitem_p.h b/src/boxplotchart/boxplotchartitem_p.h index 1c79ec1..5453036 100644 --- a/src/boxplotchart/boxplotchartitem_p.h +++ b/src/boxplotchart/boxplotchartitem_p.h @@ -35,7 +35,7 @@ #include "qboxplotseries.h" #include "chartitem_p.h" #include "boxplotanimation_p.h" -#include "qbarset.h" +#include "qboxset.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -59,7 +59,7 @@ public Q_SLOTS: void handleDomainUpdated(); void handleLayoutChanged(); void handleUpdatedBars(); - void handleBarsetRemove(QList barSets); + void handleBoxsetRemove(QList barSets); private: virtual QVector calculateLayout(); @@ -70,8 +70,7 @@ protected: friend class QBoxPlotSeriesPrivate; QBoxPlotSeries *m_series; // Not owned. QList m_boxes; - QHash m_boxTable; - QList m_barSets; + QHash m_boxTable; int m_seriesIndex; int m_seriesCount; diff --git a/src/boxplotchart/boxwhiskers.cpp b/src/boxplotchart/boxwhiskers.cpp index 4f34abe..46bd58e 100644 --- a/src/boxplotchart/boxwhiskers.cpp +++ b/src/boxplotchart/boxwhiskers.cpp @@ -73,8 +73,7 @@ void BoxWhiskers::setPen(const QPen &pen) void BoxWhiskers::setLayout(const BoxWhiskersData &data) { m_data = data; -// if (m_data.m_index == 1) -// qDebug() << "BoxWhiskers::setLayout"; + updateGeometry(); update(); } diff --git a/src/boxplotchart/qboxplotseries.cpp b/src/boxplotchart/qboxplotseries.cpp index 96fff7b..3d576a5 100644 --- a/src/boxplotchart/qboxplotseries.cpp +++ b/src/boxplotchart/qboxplotseries.cpp @@ -21,6 +21,7 @@ #include "qboxplotseries.h" #include "qboxplotseries_p.h" #include "qboxplotlegendmarker.h" +#include "qbarcategoryaxis.h" #include "boxplotchartitem_p.h" #include "chartdataset_p.h" #include "charttheme_p.h" @@ -28,6 +29,8 @@ #include "charttheme_p.h" #include "boxplotanimation_p.h" #include "qchart_p.h" +#include "qboxset.h" +#include "qboxset_p.h" #include @@ -45,7 +48,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE See the \l {BoxPlotChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. \image examples_boxplotchart.png - \sa QBarSet, QPercentBarSeries, QAbstractBarSeries + \sa QBoxSet, QPercentBarSeries, QAbstractBarSeries */ /*! @@ -65,7 +68,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QBoxPlotSeries is QObject which is a child of a \a parent. */ QBoxPlotSeries::QBoxPlotSeries(QObject *parent) - : QAbstractBarSeries(*new QBoxPlotSeriesPrivate(this), parent) + : QAbstractSeries(*new QBoxPlotSeriesPrivate(this), parent) { } @@ -82,6 +85,137 @@ 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. + Returns true, if appending succeeded. +*/ +bool QBoxPlotSeries::append(QBoxSet *set) +{ + Q_D(QBoxPlotSeries); + + bool success = d->append(set); + if (success) { + QList sets; + sets.append(set); + set->setParent(this); + emit boxsetsAdded(sets); + emit countChanged(); + } + return success; +} + +/*! + Removes boxset from the series. Releases ownership of the \a set. Deletes the set, if remove + was successful. + Returns true, if the set was removed. +*/ +bool QBoxPlotSeries::remove(QBoxSet *set) +{ + Q_D(QBoxPlotSeries); + bool success = d->remove(set); + if (success) { + QList sets; + sets.append(set); + set->setParent(0); + emit boxsetsRemoved(sets); + emit countChanged(); + delete set; + set = 0; + } + return success; +} + +/*! + Takes a single \a set from the series. Does not delete the boxset object. + + NOTE: The series remains as the boxset's parent object. You must set the + parent object to take full ownership. + + Returns true if take was successful. +*/ +bool QBoxPlotSeries::take(QBoxSet *set) +{ + Q_D(QBoxPlotSeries); + + bool success = d->remove(set); + if (success) { + QList sets; + sets.append(set); + emit boxsetsRemoved(sets); + emit countChanged(); + } + return success; +} + +/*! + Adds a list of boxsets to series. Takes ownership of the \a sets. + Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, + nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended + and function returns false. +*/ +bool QBoxPlotSeries::append(QList sets) +{ + Q_D(QBoxPlotSeries); + bool success = d->append(sets); + if (success) { + emit boxsetsAdded(sets); + emit countChanged(); + } + return success; +} + +/*! + Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. + Returns true, if inserting succeeded. + +*/ +bool QBoxPlotSeries::insert(int index, QBoxSet *set) +{ + Q_D(QBoxPlotSeries); + bool success = d->insert(index, set); + if (success) { + QList sets; + sets.append(set); + emit boxsetsAdded(sets); + emit countChanged(); + } + return success; +} + +/*! + Removes all boxsets from the series. Deletes removed sets. +*/ +void QBoxPlotSeries::clear() +{ + Q_D(QBoxPlotSeries); + QList sets = boxSets(); + bool success = d->remove(sets); + if (success) { + emit boxsetsRemoved(sets); + emit countChanged(); + foreach (QBoxSet *set, sets) + delete set; + } +} + +/*! + Returns number of sets in series. +*/ +int QBoxPlotSeries::count() const +{ + Q_D(const QBoxPlotSeries); + return d->m_boxSets.count(); +} + +/*! + Returns a list of sets in series. Keeps ownership of sets. + */ +QList QBoxPlotSeries::boxSets() const +{ + Q_D(const QBoxPlotSeries); + return d->m_boxSets; +} + +/*! Returns QChartSeries::SeriesTypeBoxPlot. */ QAbstractSeries::SeriesType QBoxPlotSeries::type() const @@ -126,7 +260,7 @@ QPen QBoxPlotSeries::pen() const /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QBoxPlotSeriesPrivate::QBoxPlotSeriesPrivate(QBoxPlotSeries *q) - : QAbstractBarSeriesPrivate(q), + : QAbstractSeriesPrivate(q), m_pen(QPen(Qt::NoPen)), m_brush(QBrush(Qt::NoBrush)) { @@ -145,16 +279,53 @@ void QBoxPlotSeriesPrivate::initializeDomain() qreal maxX(domain()->maxX()); qreal maxY(domain()->maxY()); - qreal x = categoryCount(); + qreal x = m_boxSets.count(); minX = qMin(minX, - (qreal)0.5); minY = qMin(minY, bottom()); maxX = qMax(maxX, x - (qreal)0.5); - //maxY = qMax(maxY, top()); maxY = qMax(maxY, max()); domain()->setRange(minX, maxX, minY, maxY); } +void QBoxPlotSeriesPrivate::initializeAxes() +{ + foreach (QAbstractAxis* axis, m_axes) { + if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { + if (axis->orientation() == Qt::Horizontal) + populateCategories(qobject_cast(axis)); + else + qDebug() << "ALERT: QBoxPlotSeriesPrivate::initializeAxes implement #1"; + } + } +} + +QAbstractAxis::AxisType QBoxPlotSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const +{ + if (orientation == Qt::Horizontal) + return QAbstractAxis::AxisTypeBarCategory; + + return QAbstractAxis::AxisTypeValue; +} + +QAbstractAxis* QBoxPlotSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const +{ + Q_UNUSED(orientation); + // This is not implemented even in barseries, keep in touch if something needs this + qDebug() << "ALERT: QBoxPlotSeriesPrivate::createDefaultAxis implement"; + return 0; +} + +void QBoxPlotSeriesPrivate::populateCategories(QBarCategoryAxis *axis) +{ + QStringList categories; + if (axis->categories().isEmpty()) { + for (int i(1); i < m_boxSets.count() + 1; i++) + categories << QString::number(i); + axis->append(categories); + } +} + void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent) { Q_Q(QBoxPlotSeries); @@ -276,6 +447,128 @@ void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series) boxPlot->handleDataStructureChanged(); } +bool QBoxPlotSeriesPrivate::append(QBoxSet *set) +{ + if ((m_boxSets.contains(set)) || (set == 0)) + return false; // Fail if set is already in list or set is null. + + m_boxSets.append(set); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); + QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); + + emit restructuredBoxes(); // this notifies boxplotchartitem + return true; +} + +bool QBoxPlotSeriesPrivate::remove(QBoxSet *set) +{ + if (!m_boxSets.contains(set)) + return false; // Fail if set is not in list + + m_boxSets.removeOne(set); + QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); + QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); + QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); + + emit restructuredBoxes(); // this notifies boxplotchartitem + return true; +} + +bool QBoxPlotSeriesPrivate::append(QList sets) +{ + foreach (QBoxSet *set, sets) { + if ((set == 0) || (m_boxSets.contains(set))) + return false; // Fail if any of the sets is null or is already appended. + if (sets.count(set) != 1) + return false; // Also fail if same set is more than once in given list. + } + + foreach (QBoxSet *set, sets) { + m_boxSets.append(set); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); + QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); + } + + emit restructuredBoxes(); // this notifies boxplotchartitem + return true; +} + +bool QBoxPlotSeriesPrivate::remove(QList sets) +{ + if (sets.count() == 0) + return false; + + foreach (QBoxSet *set, sets) { + if ((set == 0) || (!m_boxSets.contains(set))) + return false; // Fail if any of the sets is null or is not in series + if (sets.count(set) != 1) + return false; // Also fail if same set is more than once in given list. + } + + foreach (QBoxSet *set, sets) { + m_boxSets.removeOne(set); + QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); + QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); + QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); + } + + emit restructuredBoxes(); // this notifies boxplotchartitem + + return true; +} + +bool QBoxPlotSeriesPrivate::insert(int index, QBoxSet *set) +{ + if ((m_boxSets.contains(set)) || (set == 0)) + return false; // Fail if set is already in list or set is null. + + m_boxSets.insert(index, set); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); + QObject::connect(set->d_ptr.data(), SIGNAL(updatedBox()), this, SIGNAL(updatedBoxes())); + QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBox()), this, SIGNAL(restructuredBoxes())); + + emit restructuredBoxes(); // this notifies boxplotchartitem + return true; +} + +QBoxSet *QBoxPlotSeriesPrivate::boxsetAt(int index) +{ + return m_boxSets.at(index); +} + +qreal QBoxPlotSeriesPrivate::bottom() +{ + // Returns bottom of all boxes + qreal bottom(0); + foreach (QBoxSet *set, m_boxSets) { + for (int i = 0; i < set->count(); i++) { + if (set->at(i) < bottom) + bottom = set->at(i); + } + } + + return bottom; +} + +qreal QBoxPlotSeriesPrivate::max() +{ + if (m_boxSets.count() <= 0) + return 0; + + qreal max = INT_MIN; + + foreach (QBoxSet *set, m_boxSets) { + for (int i = 0; i < set->count(); i++) { + if (set->at(i) > max) + max = set->at(i); + } + } + + return max; +} + #include "moc_qboxplotseries.cpp" #include "moc_qboxplotseries_p.cpp" diff --git a/src/boxplotchart/qboxplotseries.h b/src/boxplotchart/qboxplotseries.h index 74ad187..466486f 100644 --- a/src/boxplotchart/qboxplotseries.h +++ b/src/boxplotchart/qboxplotseries.h @@ -22,20 +22,34 @@ #define QBOXPLOTSERIES_H #include -#include +#include +//#include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE class QBoxPlotSeriesPrivate; //class QBarSet; -class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractBarSeries +class QTCOMMERCIALCHART_EXPORT QBoxPlotSeries : public QAbstractSeries { Q_OBJECT public: explicit QBoxPlotSeries(QObject *parent = 0); ~QBoxPlotSeries(); + bool append(QBoxSet *box); + bool remove(QBoxSet *box); + bool take(QBoxSet *box); + bool append(QList boxes); + bool insert(int index, QBoxSet *box); + int count() const; + QList boxSets() const; + void clear(); + + void setLabelsVisible(bool visible = true); + bool isLabelsVisible() const; + QAbstractSeries::SeriesType type() const; void setBrush(const QBrush &brush); @@ -43,6 +57,15 @@ public: void setPen(const QPen &pen); QPen pen() const; +Q_SIGNALS: + void clicked(int index, QBoxSet *boxset); + void hovered(bool status, QBoxSet *boxset); + void countChanged(); + void labelsVisibleChanged(); + + void boxsetsAdded(QList sets); + void boxsetsRemoved(QList sets); + private: Q_DECLARE_PRIVATE(QBoxPlotSeries) Q_DISABLE_COPY(QBoxPlotSeries) diff --git a/src/boxplotchart/qboxplotseries_p.h b/src/boxplotchart/qboxplotseries_p.h index a0207ce..93a2c24 100644 --- a/src/boxplotchart/qboxplotseries_p.h +++ b/src/boxplotchart/qboxplotseries_p.h @@ -37,7 +37,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QBoxPlotSeriesPrivate : public QAbstractBarSeriesPrivate +class QBoxPlotSeriesPrivate : public QAbstractSeriesPrivate { Q_OBJECT @@ -47,19 +47,41 @@ public: void initializeGraphics(QGraphicsItem* parent); void initializeDomain(); + void initializeAxes(); void initializeAnimations(QChart::AnimationOptions options); void initializeTheme(int index, ChartTheme* theme, bool forced = false); QList createLegendMarkers(QLegend *legend); + virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; + QAbstractAxis* createDefaultAxis(Qt::Orientation orientation) const; + + bool append(QBoxSet *set); + bool remove(QBoxSet *set); + bool append(QList sets); + bool remove(QList sets); + bool insert(int index, QBoxSet *set); + QBoxSet *boxsetAt(int index); + + qreal max(); + qreal bottom(); + +private: + void populateCategories(QBarCategoryAxis *axis); + Q_SIGNALS: void updated(); + void clicked(int index, QBoxSet *barset); + void updatedBoxes(); + void updatedLayout(); + void restructuredBoxes(); private slots: void handleSeriesChange(QAbstractSeries *series); void handleSeriesRemove(QAbstractSeries *series); protected: + QList m_boxSets; QPen m_pen; QBrush m_brush; int m_index; diff --git a/src/boxplotchart/qboxset.cpp b/src/boxplotchart/qboxset.cpp new file mode 100644 index 0000000..8026b50 --- /dev/null +++ b/src/boxplotchart/qboxset.cpp @@ -0,0 +1,397 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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$ +** +****************************************************************************/ + +#include "qboxset.h" +#include "qboxset_p.h" +#include "charthelpers_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +/*! + Constructs QBoxSet with parent of \a parent +*/ +QBoxSet::QBoxSet(QObject *parent) + : QObject(parent), + d_ptr(new QBoxSetPrivate(this)) +{ +} + +QBoxSet::QBoxSet(qreal value1, qreal value2, qreal value3, qreal value4, qreal value5, QObject *parent) + : QObject(parent), + d_ptr(new QBoxSetPrivate(this)) +{ + d_ptr->append(value1); + d_ptr->append(value2); + d_ptr->append(value3); + d_ptr->append(value4); + d_ptr->append(value5); +} + +/*! + Destroys the boxset +*/ +QBoxSet::~QBoxSet() +{ + // NOTE: d_ptr destroyed by QObject +} + +/*! + Appends new value \a value to the end of set. +*/ +void QBoxSet::append(const qreal value) +{ + int index = d_ptr->m_values.count(); + d_ptr->append(value); + + emit valuesAdded(index, 1); +} + +/*! + Appends a list of reals to set. Works like append with single real value. The \a values in list + are appended to end of boxset + \sa append() +*/ +void QBoxSet::append(const QList &values) +{ + int index = d_ptr->m_values.count(); + d_ptr->append(values); + emit valuesAdded(index, values.count()); +} + +/*! + Sets new value \a value as the lower extreme for the set. +*/ +void QBoxSet::setLowerExtreme(const qreal value) +{ + d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value); + emit valueChanged(QBoxSetPrivate::PosLowerExtreme); +} + +/*! + Returns the lower extreme value of the set. +*/ +qreal QBoxSet::lowerExtreme() +{ + return d_ptr->m_values.at(QBoxSetPrivate::PosLowerExtreme); +} + +/*! + Sets new value \a value as the lower quartile for the set. +*/ +void QBoxSet::setLowerQuartile(const qreal value) +{ + d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value); + emit valueChanged(QBoxSetPrivate::PosLowerQuartile); +} + +/*! + Returns the lower quartile value of the set. +*/ +qreal QBoxSet::lowerQuartile() +{ + return d_ptr->m_values.at(QBoxSetPrivate::PosLowerQuartile); +} + +/*! + Sets new value \a value as the median for the set. +*/ +void QBoxSet::setMedian(const qreal value) +{ + d_ptr->replace(QBoxSetPrivate::PosMedian, value); + emit valueChanged(QBoxSetPrivate::PosMedian); +} + +/*! + Returns the median value of the set. +*/ +qreal QBoxSet::median() +{ + return d_ptr->m_values.at(QBoxSetPrivate::PosMedian); +} + +/*! + Sets new value \a value as the upper quartile for the set. +*/ +void QBoxSet::setUpperQuartile(const qreal value) +{ + d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value); + emit valueChanged(QBoxSetPrivate::PosUpperQuartile); +} + +/*! + Returns the upper quartile value of the set. +*/ +qreal QBoxSet::upperQuartile() +{ + return d_ptr->m_values.at(QBoxSetPrivate::PosUpperQuartile); +} + +/*! + Sets new value \a value as the upper extreme for the set. +*/ +void QBoxSet::setUpperExtreme(const qreal value) +{ + d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value); + emit valueChanged(QBoxSetPrivate::PosUpperQuartile); +} + +/*! + Returns the upper extreme value of the set. +*/ +qreal QBoxSet::upperExtreme() +{ + return d_ptr->m_values.at(QBoxSetPrivate::PosUpperExtreme); +} + +/*! + Convenience operator. Same as append, with real \a value. + \sa append() +*/ +QBoxSet &QBoxSet::operator << (const qreal &value) +{ + append(value); + return *this; +} + +/*! + 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 QBoxSet::insert(const int index, const qreal value) +{ + d_ptr->insert(index, value); + emit valuesAdded(index, 1); +} + +/*! + Removes \a count number of values from the set starting at \a index. + \sa insert() +*/ +void QBoxSet::remove(const int index, const int count) +{ + int removedCount = d_ptr->remove(index, count); + if (removedCount > 0) + emit valuesRemoved(index, removedCount); + return; +} + +/*! + Sets a new value \a value to set, indexed by \a index +*/ +void QBoxSet::replace(const int index, const qreal value) +{ + if (index >= 0 && index < d_ptr->m_values.count()) { + d_ptr->replace(index, value); + emit valueChanged(index); + } +} + + +/*! + Returns value of set indexed by \a index. + If the index is out of bounds 0.0 is returned. +*/ +qreal QBoxSet::at(const int index) const +{ + if (index < 0 || index >= d_ptr->m_values.count()) + return 0; + return d_ptr->m_values.at(index); +} + +/*! + Returns value of set indexed by \a index. + If the index is out of bounds 0.0 is returned. +*/ +qreal QBoxSet::operator [](const int index) const +{ + return at(index); +} + +/*! + Returns count of values in set. +*/ +int QBoxSet::count() const +{ + return d_ptr->m_values.count(); +} + +/*! + Sets pen for set. Boxes of this set are drawn using \a pen +*/ +void QBoxSet::setPen(const QPen &pen) +{ + if (d_ptr->m_pen != pen) { + d_ptr->m_pen = pen; + emit d_ptr->updatedBox(); + emit penChanged(); + } +} + +/*! + Returns pen of the set. +*/ +QPen QBoxSet::pen() const +{ + return d_ptr->m_pen; +} + +/*! + Sets brush for the set. Boxes of this set are drawn using \a brush +*/ +void QBoxSet::setBrush(const QBrush &brush) +{ + if (d_ptr->m_brush != brush) { + d_ptr->m_brush = brush; + emit d_ptr->updatedBox(); + emit brushChanged(); + } +} + +/*! + Returns brush of the set. +*/ +QBrush QBoxSet::brush() const +{ + return d_ptr->m_brush; +} + +/*! + Returns the color of the brush of boxset. +*/ +QColor QBoxSet::color() +{ + return brush().color(); +} + +/*! + Sets the \a color of brush for this boxset +*/ +void QBoxSet::setColor(QColor color) +{ + QBrush b = brush(); + if ((b.color() != color) || (b.style() == Qt::NoBrush)) { + b.setColor(color); + if (b.style() == Qt::NoBrush) { + // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) + // This prevents theme to override color defined in QML side: + // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] } + // The color must be obeyed, since user wanted it. + b.setStyle(Qt::SolidPattern); + } + setBrush(b); + emit colorChanged(color); + } +} + +/*! + Returns the color of pen of this boxset +*/ +QColor QBoxSet::borderColor() +{ + return pen().color(); +} + +/*! + Sets the color of pen for this boxset +*/ +void QBoxSet::setBorderColor(QColor color) +{ + QPen p = pen(); + if (p.color() != color) { + p.setColor(color); + setPen(p); + emit borderColorChanged(color); + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QBoxSetPrivate::QBoxSetPrivate(QBoxSet *parent) : QObject(parent), + q_ptr(parent), + m_pen(QPen(Qt::NoPen)), + m_brush(QBrush(Qt::NoBrush)) +{ +} + +QBoxSetPrivate::~QBoxSetPrivate() +{ +} + +void QBoxSetPrivate::append(qreal value) +{ + if (isValidValue(value)) { + m_values.append(value); + emit restructuredBox(); + } +} + +void QBoxSetPrivate::append(QList values) +{ + for (int i = 0; i < values.count(); i++) { + if (isValidValue(values.at(i))) + m_values.append(values.at(i)); + } + emit restructuredBox(); +} + +void QBoxSetPrivate::insert(const int index, const qreal value) +{ + if (isValidValue(value)) { + m_values.insert(index, value); + emit restructuredBox(); + } +} + +int QBoxSetPrivate::remove(const int index, const int count) +{ + int removeCount = count; + + 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. + + int c = 0; + while (c < removeCount) { + m_values.removeAt(index); + c++; + } + emit restructuredBox(); + return removeCount; +} + +void QBoxSetPrivate::replace(const int index, const qreal value) +{ + m_values.replace(index, value); + emit updatedLayout(); +} + +qreal QBoxSetPrivate::value(const int index) +{ + if (index < 0 || index >= m_values.count()) + return 0; + return m_values.at(index); +} + +#include "moc_qboxset.cpp" +#include "moc_qboxset_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/boxplotchart/qboxset.h b/src/boxplotchart/qboxset.h new file mode 100644 index 0000000..fb26a0f --- /dev/null +++ b/src/boxplotchart/qboxset.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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$ +** +****************************************************************************/ + +#ifndef QBOXSET_H +#define QBOXSET_H + +#include +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QBoxSetPrivate; + +class QTCOMMERCIALCHART_EXPORT QBoxSet : public QObject +{ + Q_OBJECT + Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) + Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) + +public: + explicit QBoxSet(QObject *parent = 0); + explicit QBoxSet(qreal value1, qreal value2, qreal value3, qreal value4, qreal value5, QObject *parent = 0); + virtual ~QBoxSet(); + + void append(const qreal value); + void append(const QList &values); + + void setLowerExtreme(const qreal value); + qreal lowerExtreme(); + void setLowerQuartile(const qreal value); + qreal lowerQuartile(); + void setMedian(const qreal value); + qreal median(); + void setUpperQuartile(const qreal value); + qreal upperQuartile(); + void setUpperExtreme(const qreal value); + qreal upperExtreme(); + + 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; + int count() const; + + void setPen(const QPen &pen); + QPen pen() const; + + void setBrush(const QBrush &brush); + QBrush brush() const; + + QColor color(); + void setColor(QColor color); + + QColor borderColor(); + void setBorderColor(QColor color); + + +Q_SIGNALS: + void clicked(int index); + void hovered(bool status); + void penChanged(); + void brushChanged(); + void colorChanged(QColor color); + void borderColorChanged(QColor color); + + void valuesAdded(int index, int count); + void valuesRemoved(int index, int count); + void valueChanged(int index); + +private: + QScopedPointer d_ptr; + Q_DISABLE_COPY(QBoxSet) + friend class BarLegendMarker; + friend class BarChartItem; + friend class BoxPlotChartItem; + friend class QBoxPlotSeriesPrivate; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QBOXSET_H diff --git a/src/boxplotchart/qboxset_p.h b/src/boxplotchart/qboxset_p.h new file mode 100644 index 0000000..0e4563a --- /dev/null +++ b/src/boxplotchart/qboxset_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef QBOXSET_P_H +#define QBOXSET_P_H + +#include "qboxset.h" +#include +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QBoxSetPrivate : public QObject +{ + Q_OBJECT + +public: + enum DataPositions { + PosLowerExtreme, + PosLowerQuartile, + PosMedian, + PosUpperQuartile, + PosUpperExtreme + }; + +public: + QBoxSetPrivate(QBoxSet *parent); + ~QBoxSetPrivate(); + + void append(qreal value); + void append(QList values); + + void insert(const int index, const qreal value); + int remove(const int index, const int count); + + void replace(const int index, const qreal value); + + qreal value(const int index); + +Q_SIGNALS: + void restructuredBox(); + void updatedBox(); + void updatedLayout(); + +public: + QBoxSet * const q_ptr; + //QString m_label; + QList m_values; + QPen m_pen; + QBrush m_brush; + QBrush m_labelBrush; + QFont m_labelFont; + + friend class QBoxSet; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QBOXSET_P_H diff --git a/tests/boxplottester/mainwidget.cpp b/tests/boxplottester/mainwidget.cpp index 0f7d5fc..a8ead32 100644 --- a/tests/boxplottester/mainwidget.cpp +++ b/tests/boxplottester/mainwidget.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -182,12 +182,12 @@ void MainWidget::addSeries() // Initial data //![1] - QBarSet *set0 = new QBarSet("Jan"); - QBarSet *set1 = new QBarSet("Feb"); - QBarSet *set2 = new QBarSet("Mar"); - QBarSet *set3 = new QBarSet("Apr"); - QBarSet *set4 = new QBarSet("May"); - QBarSet *set5 = new QBarSet("Jun"); + QBoxSet *set0 = new QBoxSet(); + QBoxSet *set1 = new QBoxSet(); + QBoxSet *set2 = new QBoxSet(); + QBoxSet *set3 = new QBoxSet(); + QBoxSet *set4 = new QBoxSet(); + QBoxSet *set5 = new QBoxSet(); // low bot med top upp *set0 << 3 << 4 << 4.4 << 6 << 7; @@ -204,7 +204,6 @@ void MainWidget::addSeries() m_series[nSeries]->append(set3); m_series[nSeries]->append(set4); m_series[nSeries]->append(set5); - m_series[nSeries]->type(); m_series[nSeries]->setName("Box & Whiskers"); m_chart->addSeries(m_series[nSeries]); @@ -215,7 +214,7 @@ void MainWidget::addSeries() m_axis = new QBarCategoryAxis(); m_axis->append(categories); m_chart->createDefaultAxes(); - m_chart->setAxisX(m_axis, m_series[nSeries]); + //m_chart->setAxisX(m_axis, m_series[nSeries]); } nSeries++; @@ -239,7 +238,7 @@ void MainWidget::addBox() qDebug() << "BoxPlotTester::MainWidget::addBox()"; if (nSeries > 0) { - QBarSet *newSet = new QBarSet("New"); + QBoxSet *newSet = new QBoxSet(); *newSet << 5 << 6 << 6.8 << 7 << 8; m_series[0]->append(newSet); @@ -255,7 +254,7 @@ void MainWidget::insertBox() qDebug() << "BoxPlotTester::MainWidget::insertBox()"; if (nSeries > 0) { - QBarSet *newSet = new QBarSet("New"); + QBoxSet *newSet = new QBoxSet(); *newSet << 2 << 6 << 6.8 << 7 << 10; m_series[0]->insert(1, newSet); @@ -271,7 +270,7 @@ void MainWidget::removeBox() qDebug() << "BoxPlotTester::MainWidget::removeBox"; if (nSeries > 0) { - QList sets = m_series[0]->barSets(); + QList sets = m_series[0]->boxSets(); m_series[0]->remove(sets.at(m_series[0]->count() - 3)); } else { qDebug() << "Create a series first"; @@ -294,7 +293,7 @@ void MainWidget::setBrush() qDebug() << "BoxPlotTester::MainWidget::setBrush"; if (nSeries > 0) { - QList sets = m_series[0]->barSets(); + QList sets = m_series[0]->boxSets(); sets.at(1)->setBrush(QBrush(QColor(Qt::yellow))); } else { qDebug() << "Create a series first"; @@ -339,7 +338,7 @@ void MainWidget::modelMapperToggled(bool enabled) mapper->setLastBarSetColumn(5); mapper->setFirstRow(first); mapper->setRowCount(count); - mapper->setSeries(m_series[nSeries]); + //mapper->setSeries(m_series[nSeries]); mapper->setModel(m_model); m_chart->addSeries(m_series[nSeries]);