From f9f8ff23359bb9d2dde2eebc8c6a2554d8b3fb53 2012-05-18 14:25:21 From: Tero Ahola Date: 2012-05-18 14:25:21 Subject: [PATCH] Cleaning up ChartModel impl before moving it into a demo app --- diff --git a/demos/qmlchart/qml/qmlchart/View1.qml b/demos/qmlchart/qml/qmlchart/View1.qml index ec85deb..6d3e1bb 100644 --- a/demos/qmlchart/qml/qmlchart/View1.qml +++ b/demos/qmlchart/qml/qmlchart/View1.qml @@ -50,11 +50,11 @@ Rectangle { // // For dynamic data you can use the ChartModel API. // ChartModel { // id: chartModel -// ChartModelRow { values: ["Volkswagen", 13.5] } -// ChartModelRow { values: ["Toyota", 10.9] } -// ChartModelRow { values: ["Ford", 8.6] } -// ChartModelRow { values: ["Skoda", 8.2] } -// ChartModelRow { values: ["Volvo", 6.8] } +// ChartModelElement { values: ["Volkswagen", 13.5] } +// ChartModelElement { values: ["Toyota", 10.9] } +// ChartModelElement { values: ["Ford", 8.6] } +// ChartModelElement { values: ["Skoda", 8.2] } +// ChartModelElement { values: ["Volvo", 6.8] } // } // // In this case you need to define how the data maps to pie slices with the ModelMapper API of the pie series. // PieSeries { diff --git a/demos/qmlchart/qml/qmlchart/View2.qml b/demos/qmlchart/qml/qmlchart/View2.qml index f2724e0..116f54a 100644 --- a/demos/qmlchart/qml/qmlchart/View2.qml +++ b/demos/qmlchart/qml/qmlchart/View2.qml @@ -50,13 +50,13 @@ Rectangle { ChartModel { id: chartModel - ChartModelRow { values: [0.0, 0.0, 0.3] } - ChartModelRow { values: [1.1, 2.1, 3.2] } - ChartModelRow { values: [1.9, 3.3, 2.4] } - ChartModelRow { values: [2.1, 2.1, 2.1] } - ChartModelRow { values: [2.9, 4.9, 2.6] } - ChartModelRow { values: [3.4, 3.0, 2.3] } - ChartModelRow { values: [4.1, 3.3, 3.1] } + ChartModelElement { values: [0.0, 0.0, 0.3] } + ChartModelElement { values: [1.1, 2.1, 3.2] } + ChartModelElement { values: [1.9, 3.3, 2.4] } + ChartModelElement { values: [2.1, 2.1, 2.1] } + ChartModelElement { values: [2.9, 4.9, 2.6] } + ChartModelElement { values: [3.4, 3.0, 2.3] } + ChartModelElement { values: [4.1, 3.3, 3.1] } } } diff --git a/demos/qmlchart/qml/qmlchart/View3.qml b/demos/qmlchart/qml/qmlchart/View3.qml index 7560f43..7f42654 100644 --- a/demos/qmlchart/qml/qmlchart/View3.qml +++ b/demos/qmlchart/qml/qmlchart/View3.qml @@ -62,17 +62,17 @@ Rectangle { ChartModel { id: chartModel - ChartModelRow { values: [0, 0, 1, 1, 0] } - ChartModelRow { values: [1, 0, 1, 1, 0] } - ChartModelRow { values: [2, 0, 1, 3, 0] } - ChartModelRow { values: [3, 0, 1, 3, 0] } - ChartModelRow { values: [4, 0, 1, 2, 0] } - ChartModelRow { values: [5, 0, 0, 0, 0] } - ChartModelRow { values: [6, 0, 1, 2, 1] } - ChartModelRow { values: [7, 0, 1, 1, 0] } - ChartModelRow { values: [8, 0, 4, 2, 0] } - ChartModelRow { values: [9, 0, 3, 1, 0] } - ChartModelRow { values: [10, 0, 2, 3, 0] } - ChartModelRow { values: [11, 0, 1, 3, 1] } + ChartModelElement { values: [0, 0, 1, 1, 0] } + ChartModelElement { values: [1, 0, 1, 1, 0] } + ChartModelElement { values: [2, 0, 1, 3, 0] } + ChartModelElement { values: [3, 0, 1, 3, 0] } + ChartModelElement { values: [4, 0, 1, 2, 0] } + ChartModelElement { values: [5, 0, 0, 0, 0] } + ChartModelElement { values: [6, 0, 1, 2, 1] } + ChartModelElement { values: [7, 0, 1, 1, 0] } + ChartModelElement { values: [8, 0, 4, 2, 0] } + ChartModelElement { values: [9, 0, 3, 1, 0] } + ChartModelElement { values: [10, 0, 2, 3, 0] } + ChartModelElement { values: [11, 0, 1, 3, 1] } } } diff --git a/demos/qmlchart/qml/qmlchart/View5.qml b/demos/qmlchart/qml/qmlchart/View5.qml index 6eb8b59..0d6a630 100644 --- a/demos/qmlchart/qml/qmlchart/View5.qml +++ b/demos/qmlchart/qml/qmlchart/View5.qml @@ -37,7 +37,6 @@ Rectangle { model: barModel } - // // TODO: optional syntax with ChartModel base model API // BarSeries { // model: chartModel @@ -65,8 +64,8 @@ Rectangle { BarModel { id: barModel BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] } - BarSet { name: "Bub"; values: [5, 1, 2, 4, 1, 7] } - BarSet { name: "Bib"; values: [3, 5, 8, 13, 5, 8] } + BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] } + BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] } } // TODO diff --git a/qmlplugin/declarativemodel.cpp b/qmlplugin/declarativemodel.cpp index 8a6aff4..61b7e76 100644 --- a/qmlplugin/declarativemodel.cpp +++ b/qmlplugin/declarativemodel.cpp @@ -27,17 +27,17 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE ////////////// Table model row /////////////////// -DeclarativeTableModelRow::DeclarativeTableModelRow(QObject *parent) +DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent) : QObject(parent) { } -QVariantList DeclarativeTableModelRow::values() +QVariantList DeclarativeTableModelElement::values() { return m_values; } -void DeclarativeTableModelRow::setValues(QVariantList values) +void DeclarativeTableModelElement::setValues(QVariantList values) { m_values = values; } @@ -56,8 +56,8 @@ void DeclarativeTableModel::classBegin() void DeclarativeTableModel::componentComplete() { foreach (QObject *child, children()) { - if (qobject_cast(child)) { - append(qobject_cast(child)->values()); + if (qobject_cast(child)) { + append(qobject_cast(child)->values()); } } } @@ -99,49 +99,13 @@ void DeclarativeTableModel::append(QVariantList values) void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point) { - qDebug() << "DeclarativeTableModel::appendPoint:" << point; +// qDebug() << "DeclarativeTableModel::appendPoint:" << point; QVariantList values; values.insert(mapper->mapX(), point->x()); values.insert(mapper->mapY(), point->y()); append(values); } -//void DeclarativeTableModel::appendPoints(QVariantList points) -//{ -// qreal x = 0.0; -// for (int i(0); i < points.count(); i++) { -// if (i % 2) { -// bool ok(false); -// qreal y = points.at(i).toReal(&ok); -// if (ok) { -// DeclarativeXyPoint *point= new DeclarativeXyPoint(); -// point->setX(x); -// point->setY(y); -// appendPoint(point); -// } else { -// qWarning() << "Illegal y value"; -// } -// } else { -// bool ok(false); -// x = points.at(i).toReal(&ok); -// if (!ok) { -// qWarning() << "Illegal x value"; -// } -// } -// } -//} - -//void DeclarativeTableModel::appendPoint(DeclarativeXyPoint* point) -//{ -//// qDebug() << "DeclarativeTableModel::append:" << point->x() << " " << point->y(); -// insertRow(rowCount()); -// QModelIndex xModelIndex = createIndex(rowCount() - 1, 0); -// QModelIndex yModelIndex = createIndex(rowCount() - 1, 1); -// setData(xModelIndex, point->x()); -// setData(yModelIndex, point->y()); -// dataChanged(xModelIndex, yModelIndex); -//} - ////////////// Bar model /////////////////////// DeclarativeBarModel::DeclarativeBarModel(QObject *parent) : diff --git a/qmlplugin/declarativemodel.h b/qmlplugin/declarativemodel.h index 43fc501..365a1f2 100644 --- a/qmlplugin/declarativemodel.h +++ b/qmlplugin/declarativemodel.h @@ -33,13 +33,13 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -class DeclarativeTableModelRow : public QObject +class DeclarativeTableModelElement : public QObject { Q_OBJECT Q_PROPERTY(QVariantList values READ values WRITE setValues) public: - explicit DeclarativeTableModelRow(QObject *parent = 0); + explicit DeclarativeTableModelElement(QObject *parent = 0); QVariantList values(); void setValues(QVariantList values); private: diff --git a/qmlplugin/plugin.cpp b/qmlplugin/plugin.cpp index c991097..7814fe5 100644 --- a/qmlplugin/plugin.cpp +++ b/qmlplugin/plugin.cpp @@ -57,7 +57,7 @@ public: qmlRegisterType(uri, 1, 0, "PieSeries"); qmlRegisterType(uri, 1, 0, "PieSlice"); qmlRegisterType(uri, 1, 0, "ChartModel"); - qmlRegisterType(uri, 1, 0, "ChartModelRow"); + qmlRegisterType(uri, 1, 0, "ChartModelElement"); //qmlRegisterType(uri, 1, 0, "PieMapping"); //qmlRegisterType(uri, 1, 0, "PieModelMapper"); qmlRegisterUncreatableType(uri, 1, 0, "PieModelMapper",