##// END OF EJS Templates
Adding metatype declarations in qml plugin for Qt5...
Adding metatype declarations in qml plugin for Qt5 Not sure why they are needed for Qt5. Definetly NOT needed for Qt4.

File last commit:

r2110:a93a773ef512
r2257:b97c592cff78
Show More
abstractbarchartitem.cpp
204 lines | 6.1 KiB | text/x-c | CppLexer
/ src / barchart / abstractbarchartitem.cpp
sauimone
refactoring internal barchart items
r1674 /****************************************************************************
**
** 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 "abstractbarchartitem_p.h"
#include "bar_p.h"
#include "qbarset.h"
#include "qbarset_p.h"
#include "qabstractbarseries.h"
#include "qabstractbarseries_p.h"
#include "qchart.h"
#include "chartpresenter_p.h"
Michal Klocek
Refactor animator...
r1735 #include "charttheme_p.h"
sauimone
refactoring internal barchart items
r1674 #include "abstractbaranimation_p.h"
#include "chartdataset_p.h"
#include <QPainter>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
ChartItem(presenter),
m_animation(0),
m_series(series)
{
sauimone
fix: changing barset colors no more triggers layout calculations
r1917
sauimone
refactoring internal barchart items
r1674 setFlag(ItemClipsChildrenToShape);
sauimone
fix: changing barset colors no more triggers layout calculations
r1917 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
sauimone
refactoring internal barchart items
r1674 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
Tero Ahola
Added opacity property to QAbstractSeries
r2067 connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged()));
sauimone
refactoring internal barchart items
r1674 setZValue(ChartPresenter::BarSeriesZValue);
handleDataStructureChanged();
}
AbstractBarChartItem::~AbstractBarChartItem()
{
}
void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(painter);
Q_UNUSED(option);
Q_UNUSED(widget);
}
QRectF AbstractBarChartItem::boundingRect() const
{
return m_rect;
}
void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout)
{
if (m_animation) {
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 m_animation->setup(m_layout, layout);
sauimone
refactoring internal barchart items
r1674 presenter()->startAnimation(m_animation);
} else {
setLayout(layout);
update();
}
}
void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation)
{
m_animation = animation;
}
void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout)
{
if (layout.count() != m_bars.count())
return;
Michal Klocek
Refactors Domain and Axis...
r1698 m_layout = layout;
sauimone
refactoring internal barchart items
r1674
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 for (int i = 0; i < m_bars.count(); i++)
sauimone
refactoring internal barchart items
r1674 m_bars.at(i)->setRect(layout.at(i));
}
//handlers
Michal Klocek
Refactors Domain and Axis...
r1698 void AbstractBarChartItem::handleDomainUpdated()
sauimone
refactoring internal barchart items
r1674 {
Michal Klocek
Refactors Domain and Axis...
r1698 m_domainMinX = domain()->minX();
m_domainMaxX = domain()->maxX();
m_domainMinY = domain()->minY();
m_domainMaxY = domain()->maxY();
sauimone
refactoring internal barchart items
r1674 handleLayoutChanged();
}
void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect)
{
prepareGeometryChange();
m_rect = rect;
handleLayoutChanged();
}
void AbstractBarChartItem::handleLayoutChanged()
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 if ((m_rect.width() <= 0) || (m_rect.height() <= 0))
return; // rect size zero.
sauimone
refactoring internal barchart items
r1674 QVector<QRectF> layout = calculateLayout();
applyLayout(layout);
}
void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible)
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 foreach (QGraphicsSimpleTextItem *label, m_labels)
sauimone
refactoring internal barchart items
r1674 label->setVisible(visible);
update();
}
void AbstractBarChartItem::handleDataStructureChanged()
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 foreach (QGraphicsItem *item, childItems())
sauimone
refactoring internal barchart items
r1674 delete item;
m_bars.clear();
m_labels.clear();
m_layout.clear();
bool labelsVisible = m_series->isLabelsVisible();
// Create new graphic items for bars
for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
for (int s = 0; s < m_series->count(); s++) {
QBarSet *set = m_series->d_func()->barsetAt(s);
// Bars
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 Bar *bar = new Bar(set, c, this);
sauimone
refactoring internal barchart items
r1674 m_bars.append(bar);
Jani Honkonen
normalize signal/slot signatures
r2110 connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*)));
connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*)));
connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int)));
connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool)));
sauimone
refactoring internal barchart items
r1674 m_layout.append(QRectF(0, 0, 0, 0));
// Labels
QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
label->setVisible(labelsVisible);
m_labels.append(label);
}
}
presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
handleLayoutChanged();
}
void AbstractBarChartItem::handleVisibleChanged()
{
bool visible = m_series->isVisible();
handleLabelsVisibleChanged(visible);
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 foreach (QGraphicsItem *item, childItems())
sauimone
refactoring internal barchart items
r1674 item->setVisible(visible);
Tero Ahola
Added opacity property to QAbstractSeries
r2067 }
void AbstractBarChartItem::handleOpacityChanged()
{
Jani Honkonen
astyle and manual coding style fixes for src-folder
r2097 foreach (QGraphicsItem *item, childItems())
Tero Ahola
Added opacity property to QAbstractSeries
r2067 item->setOpacity(m_series->opacity());
sauimone
refactoring internal barchart items
r1674 }
sauimone
fix: changing barset colors no more triggers layout calculations
r1917 void AbstractBarChartItem::handleUpdatedBars()
{
// Handle changes in pen, brush, labels etc.
int categoryCount = m_series->d_func()->categoryCount();
int setCount = m_series->count();
int itemIndex(0);
for (int category = 0; category < categoryCount; category++) {
for (int set = 0; set < setCount; set++) {
Jani Honkonen
more coding style fixes for src-folder...
r2104 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
Bar *bar = m_bars.at(itemIndex);
sauimone
fix: changing barset colors no more triggers layout calculations
r1917 bar->setPen(barSet->m_pen);
bar->setBrush(barSet->m_brush);
bar->update();
Jani Honkonen
more coding style fixes for src-folder...
r2104 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
sauimone
fix: changing barset colors no more triggers layout calculations
r1917 label->setFont(barSet->m_labelFont);
label->setBrush(barSet->m_labelBrush);
label->update();
itemIndex++;
}
}
}
sauimone
refactoring internal barchart items
r1674 #include "moc_abstractbarchartitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE