diff --git a/demos/qmlcustommodel/declarativemodel.cpp b/demos/qmlcustommodel/declarativemodel.cpp index 468ca2a..f571275 100644 --- a/demos/qmlcustommodel/declarativemodel.cpp +++ b/demos/qmlcustommodel/declarativemodel.cpp @@ -94,16 +94,4 @@ void DeclarativeTableModel::append(QVariantList values) dataChanged(beginIndex, endIndex); } -//void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point) -//{ -// Q_UNUSED(mapper) -// Q_UNUSED(point) -// // TODO: XYModelMapper implementation has change, this code has to be updated. -//// qDebug() << "DeclarativeTableModel::appendPoint:" << point; -//// QVariantList values; -//// values.insert(mapper->mapX(), point->x()); -//// values.insert(mapper->mapY(), point->y()); -//// append(values); -//} - #include "moc_declarativemodel.cpp" diff --git a/demos/qmlcustommodel/declarativemodel.h b/demos/qmlcustommodel/declarativemodel.h index 94fc3d1..6b0a869 100644 --- a/demos/qmlcustommodel/declarativemodel.h +++ b/demos/qmlcustommodel/declarativemodel.h @@ -49,7 +49,6 @@ class DeclarativeTableModel : public CustomTableModel, public QDeclarativeParser public: explicit DeclarativeTableModel(QObject *parent = 0); QDeclarativeListProperty modelChildren(); -// void appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point); public: // from QDeclarativeParserStatus void classBegin(); diff --git a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml index 5b1f8bb..565f031 100644 --- a/demos/qmlcustommodel/qml/qmlcustommodel/main.qml +++ b/demos/qmlcustommodel/qml/qmlcustommodel/main.qml @@ -24,21 +24,23 @@ import QmlCustomModel 1.0 Rectangle { width: parent.width - height: parent.height + height: parent.heigh + //![1] ChartView { id: chartView title: "Top-5 car brand shares in Finland" anchors.fill: parent - theme: ChartView.ChartThemeLight axisX.max: 10 axisX.min: 0 axisY.max: 20 axisY.min: 0 animationOptions: ChartView.SeriesAnimations axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] + // ... + //![1] - // For dynamic data we use a custom data model derived from QAbstractiItemModel + //![2] CustomModel { id: customModel CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } @@ -49,7 +51,9 @@ Rectangle { CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } } + //![2] + //![5] BarSeries { name: "Others" barMargin: 0 @@ -61,7 +65,9 @@ Rectangle { first: 2 } } + //![5] + //![4] LineSeries { name: "Volkswagen" visible: false @@ -72,6 +78,7 @@ Rectangle { first: 2 } } + //![4] LineSeries { name: "Toyota" @@ -117,6 +124,7 @@ Rectangle { } } + //![3] PieSeries { id: pieSeries size: 0.4 @@ -134,6 +142,7 @@ Rectangle { } } } + //![3] VPieModelMapper { series: pieSeries diff --git a/doc/src/demos-qmlcustommodel.qdoc b/doc/src/demos-qmlcustommodel.qdoc new file mode 100644 index 0000000..4c75601 --- /dev/null +++ b/doc/src/demos-qmlcustommodel.qdoc @@ -0,0 +1,29 @@ +/*! + \example demos/qmlcustommodel + \title QML Custom Model + \subtitle + + This example shows how to use your own QAbstractItemModel derived data model as a data source for a ChartView. + \image demos_qmlcustommodel.png + + First we create a ChartView: + \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 1 + + Then our data model that contains the shares of top-5 car manufacturers in Finland for the last 5 years. The model + could be constructed from various sources depending on the use case, but here we use static data for the sake of + simplicity. Check customtablemodel.cpp, declarativemodel.cpp and plugin.cpp to see how to make your own + QAbstractItemModel accessible on QML. + \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 2 + + Then we create several series as children for the same ChartView. First a pie series that illustrates the shares of + the car manufacturers in Finland in 2011: + \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 3 + + And one line series for each manufacturer presenting the share between 2007-2011, for example this one is for + Volkswagen. The series is not visible by default; it is made visible when the user clicks on the Volkswagen slice + on the pie series: + \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 4 + + And finally a bar series that shows the share for all the other manufacturers between 2007-2011: + \snippet ../demos/qmlcustommodel/qml/qmlcustommodel/main.qml 5 +*/ diff --git a/doc/src/demos.qdoc b/doc/src/demos.qdoc index 3b19c18..73243e1 100644 --- a/doc/src/demos.qdoc +++ b/doc/src/demos.qdoc @@ -18,6 +18,7 @@
  • Dynamic spline chart
  • Qml Basic Charts
  • Qml Weather
  • +
  • Qml Custom Model