@@ -1,112 +1,109 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include "customtablemodel.h" |
|
22 | #include "customtablemodel.h" | |
23 | #include <QGridLayout> |
|
23 | #include <QGridLayout> | |
24 | #include <QTableView> |
|
24 | #include <QTableView> | |
25 | #include <QChart> |
|
25 | #include <QChart> | |
26 | #include <QChartView> |
|
26 | #include <QChartView> | |
27 | #include <QLineSeries> |
|
27 | #include <QLineSeries> | |
28 |
#include |
|
28 | #include <QVXYModelMapper> | |
29 | #include <QHeaderView> |
|
29 | #include <QHeaderView> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
31 | QTCOMMERCIALCHART_USE_NAMESPACE | |
32 |
|
32 | |||
33 | TableWidget::TableWidget(QWidget *parent) |
|
33 | TableWidget::TableWidget(QWidget *parent) | |
34 | : QWidget(parent) |
|
34 | : QWidget(parent) | |
35 | { |
|
35 | { | |
36 | // create simple model for storing data |
|
36 | // create simple model for storing data | |
37 | // user's table data model |
|
37 | // user's table data model | |
38 | //! [1] |
|
38 | //! [1] | |
39 | CustomTableModel *model = new CustomTableModel; |
|
39 | CustomTableModel *model = new CustomTableModel; | |
40 | //! [1] |
|
40 | //! [1] | |
41 |
|
41 | |||
42 | //! [2] |
|
42 | //! [2] | |
43 | // create table view and add model to it |
|
43 | // create table view and add model to it | |
44 | QTableView *tableView = new QTableView; |
|
44 | QTableView *tableView = new QTableView; | |
45 | tableView->setModel(model); |
|
45 | tableView->setModel(model); | |
46 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); |
|
46 | tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | |
47 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); |
|
47 | tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | |
48 | //! [2] |
|
48 | //! [2] | |
49 |
|
49 | |||
50 | //! [3] |
|
50 | //! [3] | |
51 | QChart *chart = new QChart; |
|
51 | QChart *chart = new QChart; | |
52 | chart->setAnimationOptions(QChart::AllAnimations); |
|
52 | chart->setAnimationOptions(QChart::AllAnimations); | |
53 | //! [3] |
|
53 | //! [3] | |
54 |
|
54 | |||
55 |
|
|
55 | // series 1 | |
56 |
|
|
56 | //! [4] | |
57 |
|
|
57 | QLineSeries *series = new QLineSeries; | |
58 | // series->setModel(model); |
|
58 | QVXYModelMapper *mapper = new QVXYModelMapper(this); | |
|
59 | mapper->setXColumn(0); | |||
|
60 | mapper->setYColumn(1); | |||
|
61 | mapper->setSeries(series); | |||
|
62 | mapper->setModel(model); | |||
|
63 | chart->addSeries(series); | |||
|
64 | //! [4] | |||
59 |
|
65 | |||
60 | // QXYModelMapper *mapper = new QXYModelMapper; |
|
66 | //! [5] | |
61 | // mapper->setMapX(0); |
|
67 | // for storing color hex from the series | |
62 | // mapper->setMapY(1); |
|
68 | QString seriesColorHex = "#000000"; | |
63 | // series->setModelMapper(mapper); |
|
|||
64 | //// series->setModelMapping(0, 1, Qt::Vertical); |
|
|||
65 | // chart->addSeries(series); |
|
|||
66 | // //! [4] |
|
|||
67 |
|
69 | |||
68 | // //! [5] |
|
70 | // get the color of the series and use it for showing the mapped area | |
69 | // // for storing color hex from the series |
|
71 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
70 | // QString seriesColorHex = "#000000"; |
|
72 | model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount())); | |
|
73 | //! [5] | |||
71 |
|
74 | |||
72 | // // get the color of the series and use it for showing the mapped area |
|
|||
73 | // seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); |
|
|||
74 | // model->addMapping(seriesColorHex, QRect(0, 0, 2, model->rowCount())); |
|
|||
75 | // //! [5] |
|
|||
76 |
|
75 | |||
|
76 | // series 2 | |||
|
77 | //! [6] | |||
|
78 | series = new QLineSeries; | |||
77 |
|
79 | |||
78 | // // series 2 |
|
80 | mapper = new QVXYModelMapper(this); | |
79 | // //! [6] |
|
81 | mapper->setXColumn(2); | |
80 | // series = new QLineSeries; |
|
82 | mapper->setYColumn(3); | |
81 | // series->setModel(model); |
|
83 | mapper->setSeries(series); | |
|
84 | mapper->setModel(model); | |||
|
85 | chart->addSeries(series); | |||
|
86 | //! [6] | |||
82 |
|
87 | |||
83 | // mapper = new QXYModelMapper; |
|
88 | //! [7] | |
84 | // mapper->setMapX(2); |
|
89 | // get the color of the series and use it for showing the mapped area | |
85 | // mapper->setMapY(3); |
|
90 | seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); | |
86 | // series->setModelMapper(mapper); |
|
91 | model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount())); | |
87 | //// series->setModelMapping(2,3, Qt::Vertical); |
|
92 | //! [7] | |
88 | // chart->addSeries(series); |
|
|||
89 | // //! [6] |
|
|||
90 |
|
||||
91 | // //! [7] |
|
|||
92 | // // get the color of the series and use it for showing the mapped area |
|
|||
93 | // seriesColorHex = "#" + QString::number(series->pen().color().rgb(), 16).right(6).toUpper(); |
|
|||
94 | // model->addMapping(seriesColorHex, QRect(2, 0, 2, model->rowCount())); |
|
|||
95 | // //! [7] |
|
|||
96 |
|
93 | |||
97 | //! [8] |
|
94 | //! [8] | |
98 | QChartView *chartView = new QChartView(chart); |
|
95 | QChartView *chartView = new QChartView(chart); | |
99 | chartView->setRenderHint(QPainter::Antialiasing); |
|
96 | chartView->setRenderHint(QPainter::Antialiasing); | |
100 | chartView->setMinimumSize(640, 480); |
|
97 | chartView->setMinimumSize(640, 480); | |
101 | //! [8] |
|
98 | //! [8] | |
102 |
|
99 | |||
103 | //! [9] |
|
100 | //! [9] | |
104 | // create main layout |
|
101 | // create main layout | |
105 | QGridLayout* mainLayout = new QGridLayout; |
|
102 | QGridLayout* mainLayout = new QGridLayout; | |
106 | mainLayout->addWidget(tableView, 1, 0); |
|
103 | mainLayout->addWidget(tableView, 1, 0); | |
107 | mainLayout->addWidget(chartView, 1, 1); |
|
104 | mainLayout->addWidget(chartView, 1, 1); | |
108 | mainLayout->setColumnStretch(1, 1); |
|
105 | mainLayout->setColumnStretch(1, 1); | |
109 | mainLayout->setColumnStretch(0, 0); |
|
106 | mainLayout->setColumnStretch(0, 0); | |
110 | setLayout(mainLayout); |
|
107 | setLayout(mainLayout); | |
111 | //! [9] |
|
108 | //! [9] | |
112 | } |
|
109 | } |
General Comments 0
You need to be logged in to leave comments.
Login now