##// END OF EJS Templates
Documentation...
Documentation Change-Id: I946f3b9875e8253879238fac0b3f6034ebe458d5 Reviewed-by: Mika Salmela <mika.salmela@digia.com>

File last commit:

r2517:26c3b5c0ed1d
r2517:26c3b5c0ed1d
Show More
boxplotchartitem.cpp
227 lines | 7.1 KiB | text/x-c | CppLexer
Mika Salmela
Initial revision of boxplot series handling...
r2461 /****************************************************************************
**
** 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$
**
****************************************************************************/
#include "boxplotchartitem_p.h"
#include "qboxplotseries_p.h"
#include "bar_p.h"
Mika Salmela
Created own boxset class...
r2486 #include "qboxset_p.h"
Mika Salmela
Initial revision of boxplot series handling...
r2461 #include "qabstractbarseries_p.h"
Mika Salmela
Created own boxset class...
r2486 #include "qboxset.h"
Mika Salmela
Initial revision of boxplot series handling...
r2461 #include "boxwhiskers_p.h"
#include <QPainter>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) :
ChartItem(series->d_func(), item),
m_series(series),
m_animation(0),
m_animate(0)
{
Mika Salmela
Created own boxset class...
r2486 connect(series, SIGNAL(boxsetsRemoved(QList<QBoxSet*>)), this, SLOT(handleBoxsetRemove(QList<QBoxSet*>)));
connect(series->d_func(), SIGNAL(restructuredBoxes()), this, SLOT(handleDataStructureChanged()));
Mika Salmela
Initial revision of boxplot series handling...
r2461 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
Mika Salmela
Created own boxset class...
r2486 connect(series->d_func(), SIGNAL(updatedBoxes()), this, SLOT(handleUpdatedBars()));
Mika Salmela
Initial revision of boxplot series handling...
r2461 connect(series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdatedBars()));
// QBoxPlotSeriesPrivate calls handleDataStructureChanged(), don't do it here
setZValue(ChartPresenter::BoxPlotSeriesZValue);
}
BoxPlotChartItem::~BoxPlotChartItem()
{
qDebug() << "BoxPlotChartItem::~BoxPlotChartItem() " << m_seriesIndex;
}
void BoxPlotChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(painter);
Q_UNUSED(option);
Q_UNUSED(widget);
//painter->setClipRect(QRectF(QPointF(0,0),domain()->size()));
//qDebug() << "ALERT EMPTY: BoxPlotChartItem::paint";
}
void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
{
//qDebug() << "BoxPlotChartItem::setAnimation :" << animation;
m_animation = animation;
if (m_animation) {
foreach (BoxWhiskers *item, m_boxTable.values()) {
m_animation->addBox(item);
}
handleDomainUpdated();
}
}
void BoxPlotChartItem::handleDataStructureChanged()
{
Mika Salmela
Added remove single box...
r2482 qDebug() << "BoxPlotChartItem::handleDataStructureChanged()";
Mika Salmela
Initial revision of boxplot series handling...
r2461 int setCount = m_series->count();
for (int s = 0; s < setCount; s++) {
Mika Salmela
Created own boxset class...
r2486 QBoxSet *set = m_series->d_func()->boxsetAt(s);
Mika Salmela
Initial revision of boxplot series handling...
r2461
Mika Salmela
Documentation...
r2517 BoxWhiskers *box = m_boxTable.value(set);
if (!box) {
Mika Salmela
Initial revision of boxplot series handling...
r2461 // Item is not yet created, make a box and add it to hash table
Mika Salmela
Documentation...
r2517 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)));
Mika Salmela
Initial revision of boxplot series handling...
r2461
Mika Salmela
Created own boxset class...
r2486 // Set the decorative issues for the newly created box
Mika Salmela
Documentation...
r2517 box->setBrush(m_series->brush());
box->setPen(m_series->pen());
Mika Salmela
Initial revision of boxplot series handling...
r2461 }
Mika Salmela
Documentation...
r2517 updateBoxGeometry(box, s);
Mika Salmela
Initial revision of boxplot series handling...
r2461
Mika Salmela
Documentation...
r2517 box->updateGeometry();
Mika Salmela
Initial revision of boxplot series handling...
r2461
if (m_animation)
Mika Salmela
Documentation...
r2517 m_animation->addBox(box);
Mika Salmela
Initial revision of boxplot series handling...
r2461 }
//
handleDomainUpdated();
}
void BoxPlotChartItem::handleUpdatedBars()
{
Mika Salmela
Added remove single box...
r2482 qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
Mika Salmela
Initial revision of boxplot series handling...
r2461
foreach (BoxWhiskers *item, m_boxTable.values()) {
item->setBrush(m_series->brush());
item->setPen(m_series->pen());
}
Mika Salmela
Created own boxset class...
r2486 // Override with QBoxSet specific settings
foreach (QBoxSet *set, m_boxTable.keys()) {
Mika Salmela
Improved handling of different serieses....
r2484 if (set->brush().style() != Qt::NoBrush)
m_boxTable.value(set)->setBrush(set->brush());
if (set->pen().style() != Qt::NoPen)
m_boxTable.value(set)->setPen(set->pen());
}
Mika Salmela
Initial revision of boxplot series handling...
r2461 }
Mika Salmela
Created own boxset class...
r2486 void BoxPlotChartItem::handleBoxsetRemove(QList<QBoxSet*> barSets)
Mika Salmela
Added remove single box...
r2482 {
//qDebug() << "BoxPlotChartItem::handleBarsetRemove";
Mika Salmela
Created own boxset class...
r2486 foreach (QBoxSet *set, barSets) {
Mika Salmela
Added remove single box...
r2482 BoxWhiskers *boxItem = m_boxTable.value(set);
m_boxTable.remove(set);
delete boxItem;
}
// We trust that series emits the restructuredBars, which handles restructuring
}
Mika Salmela
Initial revision of boxplot series handling...
r2461 void BoxPlotChartItem::handleDomainUpdated()
{
//qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
if ((domain()->size().width() <= 0) || (domain()->size().height() <= 0))
return;
// Set my bounding rect to same as domain size
m_boundingRect.setRect(0.0, 0.0, domain()->size().width(), domain()->size().height());
foreach (BoxWhiskers *item, m_boxTable.values()) {
// Update the domain size for each BoxWhisker item
item->setDomainSize(domain()->size());
// If the animation is set, start the animation for each BoxWhisker item
if (m_animation) {
presenter()->startAnimation(m_animation->boxAnimation(item));
}
}
}
void BoxPlotChartItem::handleLayoutChanged()
{
Mika Salmela
Added remove single box...
r2482 qDebug() << "BoxPlotChartItem::handleLayoutChanged";
Mika Salmela
Added handling of model mapping, meaning mostly animation changes....
r2480 foreach (BoxWhiskers *item, m_boxTable.values()) {
if (m_animation)
m_animation->setAnimationStart(item);
Mika Salmela
Initial revision of boxplot series handling...
r2461
Mika Salmela
Added handling of model mapping, meaning mostly animation changes....
r2480 bool dirty = updateBoxGeometry(item, item->m_data.m_index);
if (dirty && m_animation)
presenter()->startAnimation(m_animation->boxChangeAnimation(item));
else
item->updateGeometry();
Mika Salmela
Initial revision of boxplot series handling...
r2461 }
}
QRectF BoxPlotChartItem::boundingRect() const
{
return m_boundingRect;
}
void BoxPlotChartItem::initializeLayout()
{
qDebug() << "ALERT EMPTY: BoxPlotChartItem::initializeLayout";
}
QVector<QRectF> BoxPlotChartItem::calculateLayout()
{
Mika Salmela
Improved handling of different serieses....
r2484 qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()";
Mika Salmela
Initial revision of boxplot series handling...
r2461 return QVector<QRectF>();
}
Mika Salmela
Added handling of model mapping, meaning mostly animation changes....
r2480 bool BoxPlotChartItem::updateBoxGeometry(BoxWhiskers *box, int index)
Mika Salmela
Initial revision of boxplot series handling...
r2461 {
Mika Salmela
Added handling of model mapping, meaning mostly animation changes....
r2480 bool changed = false;
Mika Salmela
Created own boxset class...
r2486 QBoxSet *set = m_series->d_func()->boxsetAt(index);
Mika Salmela
Initial revision of boxplot series handling...
r2461 BoxWhiskersData &data = box->m_data;
Mika Salmela
Added handling of model mapping, meaning mostly animation changes....
r2480
if ((data.m_lowerExtreme != set->at(0)) || (data.m_lowerQuartile != set->at(1)) ||
(data.m_median != set->at(2)) || (data.m_upperQuartile != set->at(3)) || (data.m_upperExtreme != set->at(4)))
changed = true;
Mika Salmela
Initial revision of boxplot series handling...
r2461 data.m_lowerExtreme = set->at(0);
data.m_lowerQuartile = set->at(1);
data.m_median = set->at(2);
data.m_upperQuartile = set->at(3);
data.m_upperExtreme = set->at(4);
data.m_index = index;
data.m_boxItems = m_series->count();
data.m_maxX = domain()->maxX();
data.m_minX = domain()->minX();
data.m_maxY = domain()->maxY();
data.m_minY = domain()->minY();
data.m_seriesIndex = m_seriesIndex;
data.m_seriesCount = m_seriesCount;
Mika Salmela
Added handling of model mapping, meaning mostly animation changes....
r2480
return changed;
Mika Salmela
Initial revision of boxplot series handling...
r2461 }
#include "moc_boxplotchartitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE