declarativebarseries.cpp
79 lines
| 2.2 KiB
| text/x-c
|
CppLexer
/ qmlplugin / declarativebarseries.cpp
Jani Honkonen
|
r830 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
Tero Ahola
|
r646 | #include "declarativebarseries.h" | ||
#include "declarativechart.h" | ||||
#include "qchart.h" | ||||
#include "qbarseries.h" | ||||
#include "qbarset.h" | ||||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | ||||
QDeclarativeItem(parent) | ||||
{ | ||||
setFlag(QGraphicsItem::ItemHasNoContents, false); | ||||
} | ||||
Tero Ahola
|
r726 | void DeclarativeBarSeries::componentComplete() | ||
Tero Ahola
|
r646 | { | ||
Tero Ahola
|
r1004 | } | ||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1004 | void DeclarativeBarSeries::setBarCategories(QStringList categories) | ||
{ | ||||
m_categories = categories; | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1004 | if (m_series) { | ||
delete m_series; | ||||
m_series = 0; | ||||
} | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1004 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | ||
if (declarativeChart) { | ||||
QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | ||||
Q_ASSERT(chart); | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1004 | m_series = new QBarSeries(m_categories); | ||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1004 | // TODO: use data from model | ||
QBarSet *set0 = new QBarSet("Bub"); | ||||
QBarSet *set1 = new QBarSet("Bob"); | ||||
QBarSet *set2 = new QBarSet("Guybrush"); | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1004 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | ||
*set1 << 5 << 1 << 2 << 4 << 1 << 7; | ||||
*set2 << 3 << 5 << 8 << 13 << 8 << 5; | ||||
Tero Ahola
|
r646 | |||
Tero Ahola
|
r1004 | m_series->appendBarSet(set0); | ||
m_series->appendBarSet(set1); | ||||
m_series->appendBarSet(set2); | ||||
chart->addSeries(m_series); | ||||
} | ||||
Tero Ahola
|
r726 | } | ||
QStringList DeclarativeBarSeries::barCategories() | ||||
{ | ||||
return m_categories; | ||||
} | ||||
Tero Ahola
|
r646 | #include "moc_declarativebarseries.cpp" | ||
QTCOMMERCIALCHART_END_NAMESPACE | ||||