declarativepieseries.cpp
104 lines
| 2.8 KiB
| text/x-c
|
CppLexer
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
|
r215 | #include "declarativepieseries.h" | ||
#include "declarativechart.h" | ||||
#include "qchart.h" | ||||
Tero Ahola
|
r1130 | #include <qdeclarativelist.h> | ||
Marek Rosa
|
r1164 | #include "qpiemodelmapper.h" | ||
Tero Ahola
|
r215 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Tero Ahola
|
r789 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : | ||
Tero Ahola
|
r1117 | QPieSeries(parent) | ||
Tero Ahola
|
r215 | { | ||
Tero Ahola
|
r1169 | // TODO: set default model on init? | ||
Tero Ahola
|
r1189 | // setModel(new DeclarativeTableModel()); | ||
Tero Ahola
|
r1169 | |||
Tero Ahola
|
r1189 | // TODO: Set default mapper parameters to allow easy to use PieSeries api? | ||
Tero Ahola
|
r1212 | // QPieModelMapper *mapper = modelMapper();//new QPieModelMapper(); | ||
// mapper->setMapLabels(0); | ||||
// mapper->setMapValues(1); | ||||
// mapper->setOrientation(Qt::Vertical); | ||||
// mapper->setFirst(0); | ||||
// mapper->setCount(-1); | ||||
Marek Rosa
|
r1195 | // setModelMapper(mapper); | ||
Tero Ahola
|
r215 | } | ||
Tero Ahola
|
r1186 | void DeclarativePieSeries::classBegin() | ||
{ | ||||
} | ||||
void DeclarativePieSeries::componentComplete() | ||||
{ | ||||
foreach(QObject *child, children()) { | ||||
if (qobject_cast<QPieSlice *>(child)) { | ||||
Tero Ahola
|
r1189 | QPieSeries::append(qobject_cast<QPieSlice *>(child)); | ||
Tero Ahola
|
r1186 | } | ||
} | ||||
} | ||||
QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::initialSlices() | ||||
{ | ||||
return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendInitialSlices); | ||||
} | ||||
Tero Ahola
|
r1189 | QPieSlice *DeclarativePieSeries::at(int index) | ||
Tero Ahola
|
r1162 | { | ||
QList<QPieSlice*> sliceList = slices(); | ||||
if (index < sliceList.count()) | ||||
return sliceList[index]; | ||||
return 0; | ||||
} | ||||
Tero Ahola
|
r1202 | QPieSlice* DeclarativePieSeries::find(QString label) | ||
{ | ||||
foreach (QPieSlice *slice, slices()) { | ||||
if (slice->label() == label) | ||||
return slice; | ||||
} | ||||
return 0; | ||||
} | ||||
Tero Ahola
|
r1189 | QPieSlice* DeclarativePieSeries::append(QString name, qreal value) | ||
{ | ||||
// TODO: parameter order is wrong, switch it: | ||||
Jani Honkonen
|
r1206 | return QPieSeries::append(name, value); | ||
Tero Ahola
|
r1189 | } | ||
Tero Ahola
|
r1169 | void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) | ||
Tero Ahola
|
r215 | { | ||
Tero Ahola
|
r1130 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | ||
if (m) { | ||||
Marek Rosa
|
r1230 | // QPieSeries::setModel(m); | ||
Tero Ahola
|
r1139 | } else { | ||
qWarning("DeclarativePieSeries: Illegal model"); | ||||
Tero Ahola
|
r1130 | } | ||
Tero Ahola
|
r215 | } | ||
Tero Ahola
|
r1169 | DeclarativeTableModel *DeclarativePieSeries::pieModel() | ||
Tero Ahola
|
r215 | { | ||
Marek Rosa
|
r1230 | return 0;//qobject_cast<DeclarativeTableModel *>(model()); | ||
Tero Ahola
|
r215 | } | ||
#include "moc_declarativepieseries.cpp" | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||