@@ -1,102 +1,100 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include "qchartsplugin.h" |
|
22 | 20 | #include <QtCharts/QChartView> |
|
23 | 21 | #include <QtCore/QtPlugin> |
|
24 | 22 | |
|
25 | 23 | QT_CHARTS_USE_NAMESPACE |
|
26 | 24 | |
|
27 | 25 | QChartsPlugin::QChartsPlugin(QObject *parent) : |
|
28 | 26 | QObject(parent) |
|
29 | 27 | { |
|
30 | 28 | } |
|
31 | 29 | |
|
32 | 30 | QChartsPlugin::~QChartsPlugin() |
|
33 | 31 | { |
|
34 | 32 | } |
|
35 | 33 | |
|
36 | 34 | QString QChartsPlugin::name() const |
|
37 | 35 | { |
|
38 | 36 | return QStringLiteral("QtCharts::QChartView"); |
|
39 | 37 | } |
|
40 | 38 | |
|
41 | 39 | QString QChartsPlugin::includeFile() const |
|
42 | 40 | { |
|
43 | 41 | #ifdef linux |
|
44 | 42 | QString myNewLine = QStringLiteral("\n"); |
|
45 | 43 | #endif |
|
46 | 44 | #ifdef WIN32 |
|
47 | 45 | QString myNewLine = QStringLiteral("\n\r"); |
|
48 | 46 | #endif |
|
49 | 47 | #ifdef __APPLE__ |
|
50 | 48 | QString myNewLine = QStringLiteral("\n"); |
|
51 | 49 | #endif |
|
52 | 50 | return QStringLiteral("<QtCharts/QChartView>") + myNewLine |
|
53 | 51 | + QStringLiteral("#include <chartsnamespace.h>"); |
|
54 | 52 | } |
|
55 | 53 | |
|
56 | 54 | QString QChartsPlugin::group() const |
|
57 | 55 | { |
|
58 | 56 | return tr("Qt Charts Widgets"); |
|
59 | 57 | } |
|
60 | 58 | |
|
61 | 59 | QIcon QChartsPlugin::icon() const |
|
62 | 60 | { |
|
63 | 61 | return QIcon(QStringLiteral(":/images/qcharts.png")); |
|
64 | 62 | } |
|
65 | 63 | |
|
66 | 64 | QString QChartsPlugin::toolTip() const |
|
67 | 65 | { |
|
68 | 66 | return tr("A Qt Charts view widget"); |
|
69 | 67 | } |
|
70 | 68 | |
|
71 | 69 | QString QChartsPlugin::whatsThis() const |
|
72 | 70 | { |
|
73 | 71 | return tr("This widget is presents QChartView widget"); |
|
74 | 72 | } |
|
75 | 73 | |
|
76 | 74 | bool QChartsPlugin::isContainer() const |
|
77 | 75 | { |
|
78 | 76 | return false; |
|
79 | 77 | } |
|
80 | 78 | |
|
81 | 79 | QWidget *QChartsPlugin::createWidget(QWidget *parent) |
|
82 | 80 | { |
|
83 | 81 | return new QChartView(new QChart(), parent); |
|
84 | 82 | } |
|
85 | 83 | |
|
86 | 84 | QString QChartsPlugin::domXml() const |
|
87 | 85 | { |
|
88 | 86 | return QStringLiteral("\ |
|
89 | 87 | <ui language=\"c++\">\ |
|
90 | 88 | <widget class=\"QtCharts::QChartView\" name=\"chartview\">\ |
|
91 | 89 | <property name=\"geometry\">\ |
|
92 | 90 | <rect>\ |
|
93 | 91 | <x>0</x>\ |
|
94 | 92 | <y>0</y>\ |
|
95 | 93 | <width>200</width>\ |
|
96 | 94 | <height>200</height>\ |
|
97 | 95 | </rect>\ |
|
98 | 96 | </property>\ |
|
99 | 97 | </widget>\ |
|
100 | 98 | </ui>"); |
|
101 | 99 | } |
|
102 | 100 |
@@ -1,47 +1,45 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #ifndef QCHARTSPLUGIN_H |
|
22 | 20 | #define QCHARTSPLUGIN_H |
|
23 | 21 | |
|
24 | 22 | #include <QtDesigner/QDesignerCustomWidgetInterface> |
|
25 | 23 | |
|
26 | 24 | class QChartsPlugin: public QObject, public QDesignerCustomWidgetInterface |
|
27 | 25 | { |
|
28 | 26 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface") |
|
29 | 27 | |
|
30 | 28 | Q_OBJECT |
|
31 | 29 | Q_INTERFACES(QDesignerCustomWidgetInterface) |
|
32 | 30 | public: |
|
33 | 31 | QChartsPlugin(QObject *parent = 0); |
|
34 | 32 | ~QChartsPlugin(); |
|
35 | 33 | |
|
36 | 34 | QString name() const; |
|
37 | 35 | QString includeFile() const; |
|
38 | 36 | QString group() const; |
|
39 | 37 | QIcon icon() const; |
|
40 | 38 | QString toolTip() const; |
|
41 | 39 | QString whatsThis() const; |
|
42 | 40 | bool isContainer() const; |
|
43 | 41 | QWidget *createWidget(QWidget *parent); |
|
44 | 42 | QString domXml() const; |
|
45 | 43 | }; |
|
46 | 44 | |
|
47 | 45 | #endif /* QCHARTSPLUGIN_H */ |
@@ -1,33 +1,31 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include "brushwidget.h" |
|
22 | 20 | |
|
23 | 21 | BrushWidget::BrushWidget(QWidget *parent):QWidget(parent) |
|
24 | 22 | { |
|
25 | 23 | |
|
26 | 24 | |
|
27 | 25 | } |
|
28 | 26 | |
|
29 | 27 | BrushWidget::~BrushWidget() |
|
30 | 28 | { |
|
31 | 29 | |
|
32 | 30 | } |
|
33 | 31 |
@@ -1,39 +1,37 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #ifndef BRUSHWIDGET_H |
|
22 | 20 | #define BRUSHWIDGET_H |
|
23 | 21 | |
|
24 | 22 | #include <QtWidgets/QWidget> |
|
25 | 23 | |
|
26 | 24 | class BrushWidget: public QWidget |
|
27 | 25 | { |
|
28 | 26 | public: |
|
29 | 27 | explicit BrushWidget(QWidget *parent = 0); |
|
30 | 28 | ~BrushWidget(); |
|
31 | 29 | |
|
32 | 30 | QBrush brush() const { return m_brush; } |
|
33 | 31 | void setBrush(const QBrush &brush); |
|
34 | 32 | |
|
35 | 33 | private: |
|
36 | 34 | QBrush m_brush; |
|
37 | 35 | }; |
|
38 | 36 | |
|
39 | 37 | #endif /* BRUSHWIDGET_H */ |
@@ -1,343 +1,341 | |||
|
1 | 1 | /**************************************************************************** |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
2 | ** | |
|
3 | ** Copyright (C) 2014 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | ** | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
13 | ** | |
|
14 | ** If you have questions regarding the use of this file, please use | |
|
15 | ** contact form at http://qt.io | |
|
16 | ** | |
|
17 | ****************************************************************************/ | |
|
20 | 18 | |
|
21 | 19 | #include "engine.h" |
|
22 | 20 | #include <QtCore/QItemSelectionModel> |
|
23 | 21 | #include <QtGui/QStandardItemModel> |
|
24 | 22 | #include <QtCharts/QVXYModelMapper> |
|
25 | 23 | #include <QtCharts/QHBarModelMapper> |
|
26 | 24 | #include <QtCharts/QVPieModelMapper> |
|
27 | 25 | #include <QtCharts/QLineSeries> |
|
28 | 26 | #include <QtCharts/QSplineSeries> |
|
29 | 27 | #include <QtCharts/QScatterSeries> |
|
30 | 28 | #include <QtCharts/QBarSeries> |
|
31 | 29 | #include <QtCharts/QPercentBarSeries> |
|
32 | 30 | #include <QtCharts/QStackedBarSeries> |
|
33 | 31 | #include <QtCharts/QAreaSeries> |
|
34 | 32 | #include <QtCharts/QPieSeries> |
|
35 | 33 | #include <QtCharts/QChart> |
|
36 | 34 | #include <QtCharts/QBarSet> |
|
37 | 35 | |
|
38 | 36 | |
|
39 | 37 | const qint32 MAGIC_NUMBER = 0x66666666; |
|
40 | 38 | |
|
41 | 39 | Engine::Engine(QObject* parent) : |
|
42 | 40 | QObject(parent), m_count(10), m_chart(new QChart()), m_model(0), m_selection(0) |
|
43 | 41 | { |
|
44 | 42 | createModels(); |
|
45 | 43 | } |
|
46 | 44 | |
|
47 | 45 | Engine::~Engine() |
|
48 | 46 | { |
|
49 | 47 | delete m_chart; |
|
50 | 48 | delete m_selection; |
|
51 | 49 | delete m_model; |
|
52 | 50 | } |
|
53 | 51 | |
|
54 | 52 | void Engine::createModels() |
|
55 | 53 | { |
|
56 | 54 | m_model = new QStandardItemModel(m_count, m_count); |
|
57 | 55 | m_model->setHorizontalHeaderLabels( |
|
58 | 56 | QStringList() << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H" << "I" << "J"); |
|
59 | 57 | m_model->setVerticalHeaderLabels( |
|
60 | 58 | QStringList() << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10"); |
|
61 | 59 | m_selection = new QItemSelectionModel(m_model); |
|
62 | 60 | |
|
63 | 61 | } |
|
64 | 62 | |
|
65 | 63 | QList<QAbstractSeries*> Engine::addSeries(QAbstractSeries::SeriesType type) |
|
66 | 64 | { |
|
67 | 65 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
68 | 66 | |
|
69 | 67 | QMap<int, QModelIndex> columns; |
|
70 | 68 | |
|
71 | 69 | foreach (const QModelIndex& index, list) { |
|
72 | 70 | columns.insertMulti(index.column(), index); |
|
73 | 71 | } |
|
74 | 72 | |
|
75 | 73 | QList<int> keys = columns.uniqueKeys(); |
|
76 | 74 | |
|
77 | 75 | QModelIndexList rows = columns.values(keys.first()); |
|
78 | 76 | |
|
79 | 77 | int minRow = m_count + 1; |
|
80 | 78 | int maxRow = -1; |
|
81 | 79 | |
|
82 | 80 | foreach (const QModelIndex& index, rows) { |
|
83 | 81 | minRow = qMin(index.row(), minRow); |
|
84 | 82 | maxRow = qMax(index.row(), maxRow); |
|
85 | 83 | } |
|
86 | 84 | |
|
87 | 85 | QList<QAbstractSeries*> result; |
|
88 | 86 | QColor color; |
|
89 | 87 | |
|
90 | 88 | switch (type) { |
|
91 | 89 | |
|
92 | 90 | case QAbstractSeries::SeriesTypeLine: |
|
93 | 91 | { |
|
94 | 92 | for (int i = 1; i < keys.count(); ++i) { |
|
95 | 93 | QLineSeries *line = new QLineSeries(); |
|
96 | 94 | setupXYSeries(line, keys, i, minRow, maxRow); |
|
97 | 95 | result << line; |
|
98 | 96 | } |
|
99 | 97 | break; |
|
100 | 98 | } |
|
101 | 99 | case QAbstractSeries::SeriesTypeSpline: |
|
102 | 100 | { |
|
103 | 101 | for (int i = 1; i < keys.count(); ++i) { |
|
104 | 102 | QSplineSeries *line = new QSplineSeries(); |
|
105 | 103 | setupXYSeries(line, keys, i, minRow, maxRow); |
|
106 | 104 | result << line; |
|
107 | 105 | } |
|
108 | 106 | break; |
|
109 | 107 | } |
|
110 | 108 | case QAbstractSeries::SeriesTypeScatter: |
|
111 | 109 | { |
|
112 | 110 | for (int i = 1; i < keys.count(); ++i) { |
|
113 | 111 | QScatterSeries *line = new QScatterSeries(); |
|
114 | 112 | setupXYSeries(line, keys, i, minRow, maxRow); |
|
115 | 113 | result << line; |
|
116 | 114 | } |
|
117 | 115 | break; |
|
118 | 116 | } |
|
119 | 117 | case QAbstractSeries::SeriesTypeBar: |
|
120 | 118 | { |
|
121 | 119 | QBarSeries *bar = new QBarSeries(); |
|
122 | 120 | setupBarSeries(bar,keys,minRow,maxRow); |
|
123 | 121 | result << bar; |
|
124 | 122 | break; |
|
125 | 123 | } |
|
126 | 124 | case QAbstractSeries::SeriesTypePercentBar: |
|
127 | 125 | { |
|
128 | 126 | QPercentBarSeries *bar = new QPercentBarSeries(); |
|
129 | 127 | setupBarSeries(bar,keys,minRow,maxRow); |
|
130 | 128 | result << bar; |
|
131 | 129 | break; |
|
132 | 130 | } |
|
133 | 131 | case QAbstractSeries::SeriesTypeStackedBar: |
|
134 | 132 | { |
|
135 | 133 | QStackedBarSeries *bar = new QStackedBarSeries(); |
|
136 | 134 | setupBarSeries(bar,keys,minRow,maxRow); |
|
137 | 135 | result << bar; |
|
138 | 136 | break; |
|
139 | 137 | } |
|
140 | 138 | case QAbstractSeries::SeriesTypePie: |
|
141 | 139 | { |
|
142 | 140 | |
|
143 | 141 | QPieSeries *pie = new QPieSeries(); |
|
144 | 142 | setupPieSeries(pie,keys,minRow,maxRow); |
|
145 | 143 | result << pie; |
|
146 | 144 | break; |
|
147 | 145 | } |
|
148 | 146 | case QAbstractSeries::SeriesTypeArea: |
|
149 | 147 | { |
|
150 | 148 | QAreaSeries *area = new QAreaSeries( new QLineSeries(), new QLineSeries()); |
|
151 | 149 | setupAreaSeries(area,keys,minRow,maxRow); |
|
152 | 150 | result << area; |
|
153 | 151 | break; |
|
154 | 152 | } |
|
155 | 153 | } |
|
156 | 154 | |
|
157 | 155 | m_chart->createDefaultAxes(); |
|
158 | 156 | return result; |
|
159 | 157 | } |
|
160 | 158 | |
|
161 | 159 | void Engine::removeSeries(QAbstractSeries* series) |
|
162 | 160 | { |
|
163 | 161 | m_chart->removeSeries(series); |
|
164 | 162 | |
|
165 | 163 | foreach (const QModelIndex& index, m_seriesModelIndex.value(series)) { |
|
166 | 164 | m_model->setData(index, QColor(Qt::white), Qt::BackgroundRole); |
|
167 | 165 | } |
|
168 | 166 | } |
|
169 | 167 | |
|
170 | 168 | void Engine::clearModels() |
|
171 | 169 | { |
|
172 | 170 | delete m_selection; |
|
173 | 171 | m_selection = 0; |
|
174 | 172 | delete m_model; |
|
175 | 173 | m_model = 0; |
|
176 | 174 | createModels(); |
|
177 | 175 | } |
|
178 | 176 | |
|
179 | 177 | bool Engine::save(const QString &filename) const |
|
180 | 178 | { |
|
181 | 179 | if (filename.isEmpty()) |
|
182 | 180 | return false; |
|
183 | 181 | |
|
184 | 182 | QFile file(filename); |
|
185 | 183 | |
|
186 | 184 | if (!file.open(QIODevice::WriteOnly)) { |
|
187 | 185 | return false; |
|
188 | 186 | } |
|
189 | 187 | |
|
190 | 188 | QDataStream out(&file); |
|
191 | 189 | out << MAGIC_NUMBER; |
|
192 | 190 | out.setVersion(QDataStream::Qt_4_8); |
|
193 | 191 | out << m_model->rowCount(); |
|
194 | 192 | out << m_model->columnCount(); |
|
195 | 193 | |
|
196 | 194 | for (int row = 0; row < m_model->rowCount(); ++row) { |
|
197 | 195 | for (int column = 0; column < m_model->columnCount(); ++column) { |
|
198 | 196 | QStandardItem *item = m_model->item(row, column); |
|
199 | 197 | if (item) { |
|
200 | 198 | out << row; |
|
201 | 199 | out << column; |
|
202 | 200 | out << item->data(Qt::EditRole).toString(); |
|
203 | 201 | } |
|
204 | 202 | } |
|
205 | 203 | } |
|
206 | 204 | return true; |
|
207 | 205 | } |
|
208 | 206 | |
|
209 | 207 | bool Engine::load(const QString &filename) |
|
210 | 208 | { |
|
211 | 209 | clearModels(); |
|
212 | 210 | |
|
213 | 211 | if (filename.isEmpty()) |
|
214 | 212 | return false; |
|
215 | 213 | |
|
216 | 214 | QFile file(filename); |
|
217 | 215 | |
|
218 | 216 | if (!file.open(QIODevice::ReadOnly)) { |
|
219 | 217 | return false; |
|
220 | 218 | } |
|
221 | 219 | |
|
222 | 220 | QDataStream in(&file); |
|
223 | 221 | |
|
224 | 222 | qint32 magicNumber; |
|
225 | 223 | in >> magicNumber; |
|
226 | 224 | |
|
227 | 225 | if (magicNumber != MAGIC_NUMBER) |
|
228 | 226 | return false; |
|
229 | 227 | |
|
230 | 228 | in.setVersion(QDataStream::Qt_4_8); |
|
231 | 229 | |
|
232 | 230 | int rowCount; |
|
233 | 231 | in >> rowCount; |
|
234 | 232 | |
|
235 | 233 | int columnCount; |
|
236 | 234 | in >> columnCount; |
|
237 | 235 | |
|
238 | 236 | while (!in.atEnd()) { |
|
239 | 237 | int row; |
|
240 | 238 | int column; |
|
241 | 239 | QString value; |
|
242 | 240 | in >> row >> column >> value; |
|
243 | 241 | QStandardItem *item = new QStandardItem(); |
|
244 | 242 | bool ok; |
|
245 | 243 | double result = value.toDouble(&ok); |
|
246 | 244 | if(ok) |
|
247 | 245 | item->setData(result, Qt::EditRole); |
|
248 | 246 | else |
|
249 | 247 | item->setData(value, Qt::EditRole); |
|
250 | 248 | m_model->setItem(row, column, item); |
|
251 | 249 | } |
|
252 | 250 | |
|
253 | 251 | return true; |
|
254 | 252 | } |
|
255 | 253 | |
|
256 | 254 | void Engine::setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow) |
|
257 | 255 | { |
|
258 | 256 | QVXYModelMapper* mapper = new QVXYModelMapper(xyseries); |
|
259 | 257 | mapper->setSeries(xyseries); |
|
260 | 258 | mapper->setModel(m_model); |
|
261 | 259 | mapper->setXColumn(columns.first()); |
|
262 | 260 | mapper->setYColumn(columns.at(column)); |
|
263 | 261 | mapper->setFirstRow(minRow); |
|
264 | 262 | mapper->setRowCount(maxRow - minRow + 1); |
|
265 | 263 | m_chart->addSeries(xyseries); |
|
266 | 264 | xyseries->setName(QString("Series %1").arg(m_chart->series().count())); |
|
267 | 265 | QObject::connect(xyseries,SIGNAL(clicked(QPointF)),this,SIGNAL(selected())); |
|
268 | 266 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
269 | 267 | QModelIndexList result; |
|
270 | 268 | foreach (const QModelIndex& index, list) { |
|
271 | 269 | if (index.column() ==columns.at(column)){ |
|
272 | 270 | m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); |
|
273 | 271 | result << index; |
|
274 | 272 | } |
|
275 | 273 | } |
|
276 | 274 | m_seriesModelIndex.insert(xyseries,result); |
|
277 | 275 | } |
|
278 | 276 | |
|
279 | 277 | void Engine::setupBarSeries(QAbstractBarSeries *bar, const QList<int>& columns, int minRow, int maxRow) |
|
280 | 278 | { |
|
281 | 279 | QHBarModelMapper* mapper = new QHBarModelMapper(bar); |
|
282 | 280 | mapper->setSeries(bar); |
|
283 | 281 | mapper->setModel(m_model); |
|
284 | 282 | mapper->setFirstColumn(minRow); |
|
285 | 283 | mapper->setColumnCount(maxRow - minRow + 1); |
|
286 | 284 | mapper->setFirstBarSetRow(columns.at(1)); |
|
287 | 285 | mapper->setLastBarSetRow(columns.last()); |
|
288 | 286 | m_chart->addSeries(bar); |
|
289 | 287 | bar->setName(QString("Series %1").arg(m_chart->series().count())); |
|
290 | 288 | |
|
291 | 289 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
292 | 290 | foreach (const QModelIndex& index, list) { |
|
293 | 291 | if (index.column() >= columns.at(1) && index.column()<= columns.last()) { |
|
294 | 292 | //m_model->setData(index, bar->barSets().at(index.column())->brush().color(), Qt::BackgroundRole); |
|
295 | 293 | } |
|
296 | 294 | } |
|
297 | 295 | } |
|
298 | 296 | |
|
299 | 297 | void Engine::setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow) |
|
300 | 298 | { |
|
301 | 299 | QVPieModelMapper* mapper = new QVPieModelMapper(pie); |
|
302 | 300 | mapper->setSeries(pie); |
|
303 | 301 | mapper->setModel(m_model); |
|
304 | 302 | mapper->setValuesColumn(columns.at(1)); |
|
305 | 303 | mapper->setLabelsColumn(columns.first()); |
|
306 | 304 | mapper->setFirstRow(minRow); |
|
307 | 305 | mapper->setRowCount(maxRow - minRow + 1); |
|
308 | 306 | m_chart->addSeries(pie); |
|
309 | 307 | pie->setName(QString("Series %1").arg(m_chart->series().count())); |
|
310 | 308 | |
|
311 | 309 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
312 | 310 | foreach (const QModelIndex& index, list) { |
|
313 | 311 | // m_model->setData(index, bar->barSets()pen().color(), Qt::BackgroundRole); |
|
314 | 312 | } |
|
315 | 313 | } |
|
316 | 314 | |
|
317 | 315 | void Engine::setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow) |
|
318 | 316 | { |
|
319 | 317 | QVXYModelMapper* umapper = new QVXYModelMapper(series); |
|
320 | 318 | umapper->setSeries(series->upperSeries()); |
|
321 | 319 | umapper->setModel(m_model); |
|
322 | 320 | umapper->setXColumn(columns.first()); |
|
323 | 321 | umapper->setYColumn(columns.at(1)); |
|
324 | 322 | umapper->setFirstRow(minRow); |
|
325 | 323 | umapper->setRowCount(maxRow - minRow + 1); |
|
326 | 324 | |
|
327 | 325 | QVXYModelMapper* lmapper = new QVXYModelMapper(series); |
|
328 | 326 | lmapper->setSeries(series->lowerSeries()); |
|
329 | 327 | lmapper->setModel(m_model); |
|
330 | 328 | lmapper->setXColumn(columns.first()); |
|
331 | 329 | lmapper->setYColumn(columns.at(2)); |
|
332 | 330 | lmapper->setFirstRow(minRow); |
|
333 | 331 | lmapper->setRowCount(maxRow - minRow + 1); |
|
334 | 332 | |
|
335 | 333 | m_chart->addSeries(series); |
|
336 | 334 | series->setName(QString("Series %1").arg(m_chart->series().count())); |
|
337 | 335 | |
|
338 | 336 | const QModelIndexList& list = m_selection->selectedIndexes(); |
|
339 | 337 | foreach (const QModelIndex& index, list) { |
|
340 | 338 | //if (index.column() ==columns.at(column)) |
|
341 | 339 | // m_model->setData(index, xyseries->pen().color(), Qt::BackgroundRole); |
|
342 | 340 | } |
|
343 | 341 | } |
@@ -1,76 +1,74 | |||
|
1 | 1 | /**************************************************************************** |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
2 | ** | |
|
3 | ** Copyright (C) 2014 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | ** | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
13 | ** | |
|
14 | ** If you have questions regarding the use of this file, please use | |
|
15 | ** contact form at http://qt.io | |
|
16 | ** | |
|
17 | ****************************************************************************/ | |
|
20 | 18 | |
|
21 | 19 | #ifndef ENGINE_H |
|
22 | 20 | #define ENGINE_H |
|
23 | 21 | |
|
24 | 22 | #include <QtCore/QObject> |
|
25 | 23 | #include <QtCharts/QAbstractSeries> |
|
26 | 24 | #include <QtCore/QModelIndex> |
|
27 | 25 | |
|
28 | 26 | class QStandardItemModel; |
|
29 | 27 | class QItemSelectionModel; |
|
30 | 28 | |
|
31 | 29 | |
|
32 | 30 | QT_CHARTS_BEGIN_NAMESPACE |
|
33 | 31 | class QChart; |
|
34 | 32 | class QXYSeries; |
|
35 | 33 | class QAbstractBarSeries; |
|
36 | 34 | class QPieSeries; |
|
37 | 35 | class QAreaSeries; |
|
38 | 36 | QT_CHARTS_END_NAMESPACE |
|
39 | 37 | |
|
40 | 38 | QT_CHARTS_USE_NAMESPACE |
|
41 | 39 | |
|
42 | 40 | class Engine : public QObject |
|
43 | 41 | { |
|
44 | 42 | Q_OBJECT |
|
45 | 43 | public: |
|
46 | 44 | explicit Engine(QObject *parent = 0); |
|
47 | 45 | ~Engine(); |
|
48 | 46 | |
|
49 | 47 | int modelCount() { return m_count; } |
|
50 | 48 | QStandardItemModel *model() const { return m_model; } |
|
51 | 49 | QItemSelectionModel *selectionModel() const { return m_selection; } |
|
52 | 50 | QChart* chart() const { return m_chart; } |
|
53 | 51 | void clearModels(); |
|
54 | 52 | QList<QAbstractSeries*> addSeries(QAbstractSeries::SeriesType type); |
|
55 | 53 | void removeSeries(QAbstractSeries* series); |
|
56 | 54 | bool save(const QString &filename) const; |
|
57 | 55 | bool load(const QString &filename); |
|
58 | 56 | signals: |
|
59 | 57 | void selected(); |
|
60 | 58 | |
|
61 | 59 | private: |
|
62 | 60 | void createModels(); |
|
63 | 61 | void setupXYSeries(QXYSeries *xyseries, const QList<int>& columns, int column, int minRow, int maxRow); |
|
64 | 62 | void setupBarSeries(QAbstractBarSeries *series, const QList<int>& columns, int minRow, int maxRow); |
|
65 | 63 | void setupPieSeries(QPieSeries *pie, const QList<int>& columns, int minRow, int maxRow); |
|
66 | 64 | void setupAreaSeries(QAreaSeries *series, const QList<int>& columns, int minRow, int maxRow); |
|
67 | 65 | |
|
68 | 66 | private: |
|
69 | 67 | int m_count; |
|
70 | 68 | QChart *m_chart; |
|
71 | 69 | QStandardItemModel *m_model; |
|
72 | 70 | QItemSelectionModel *m_selection; |
|
73 | 71 | QMap<QAbstractSeries*, QList<QModelIndex> > m_seriesModelIndex; |
|
74 | 72 | }; |
|
75 | 73 | |
|
76 | 74 | #endif /* ENGINE_H */ |
@@ -1,32 +1,30 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include "mainwindow.h" |
|
22 | 20 | #include <QtWidgets/QApplication> |
|
23 | 21 | |
|
24 | 22 | int main(int argc, char *argv[]) |
|
25 | 23 | { |
|
26 | 24 | QApplication a(argc, argv); |
|
27 | 25 | |
|
28 | 26 | MainWindow window; |
|
29 | 27 | window.resize(1000,600); |
|
30 | 28 | window.show(); |
|
31 | 29 | return a.exec(); |
|
32 | 30 | } |
@@ -1,423 +1,421 | |||
|
1 | 1 | /**************************************************************************** |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
2 | ** | |
|
3 | ** Copyright (C) 2014 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | ** | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
13 | ** | |
|
14 | ** If you have questions regarding the use of this file, please use | |
|
15 | ** contact form at http://qt.io | |
|
16 | ** | |
|
17 | ****************************************************************************/ | |
|
20 | 18 | |
|
21 | 19 | #include "mainwindow.h" |
|
22 | 20 | #include "objectinspectorwidget.h" |
|
23 | 21 | #include "penwidget.h" |
|
24 | 22 | #include "brushwidget.h" |
|
25 | 23 | #include "engine.h" |
|
26 | 24 | #include <QtCore/QSettings> |
|
27 | 25 | #include <QtCharts/QChartView> |
|
28 | 26 | #include <QtWidgets/QDockWidget> |
|
29 | 27 | #include <QtWidgets/QMenuBar> |
|
30 | 28 | #include <QtWidgets/QTableWidget> |
|
31 | 29 | #include <QtWidgets/QSplitter> |
|
32 | 30 | #include <QtCore/QMetaEnum> |
|
33 | 31 | #include <QtGui/QStandardItemModel> |
|
34 | 32 | #include <QtWidgets/QHeaderView> |
|
35 | 33 | #include <QtCore/QDebug> |
|
36 | 34 | #include <QtWidgets/QMessageBox> |
|
37 | 35 | |
|
38 | 36 | static const QString FILENAME_SETTING("filename"); |
|
39 | 37 | static const QString GEOMETRY_SETTING("geometry"); |
|
40 | 38 | |
|
41 | 39 | MainWindow::MainWindow() : |
|
42 | 40 | m_engine(new Engine(this)), |
|
43 | 41 | m_view(new QChartView(m_engine->chart())), |
|
44 | 42 | m_scene(m_view->scene()), |
|
45 | 43 | m_table(new QTableView()), |
|
46 | 44 | m_addSeriesMenu(0), |
|
47 | 45 | m_seriesMenu(0), |
|
48 | 46 | m_chartMenu(0), |
|
49 | 47 | m_themeMenu(0), |
|
50 | 48 | m_animationMenu(0), |
|
51 | 49 | m_zoomMenu(0), |
|
52 | 50 | m_removeAllAction(0), |
|
53 | 51 | m_legendAction(0), |
|
54 | 52 | m_antialiasingAction(0) |
|
55 | 53 | { |
|
56 | 54 | createMenus(); |
|
57 | 55 | createDockWidgets(); |
|
58 | 56 | createTable(); |
|
59 | 57 | createLayout(); |
|
60 | 58 | |
|
61 | 59 | QSettings settings; |
|
62 | 60 | restoreGeometry(settings.value(GEOMETRY_SETTING).toByteArray()); |
|
63 | 61 | m_filename = settings.value(FILENAME_SETTING).toString(); |
|
64 | 62 | if (m_filename.isEmpty()) |
|
65 | 63 | m_filename = "untitled"; |
|
66 | 64 | |
|
67 | 65 | setWindowTitle(m_filename); |
|
68 | 66 | updateUI(); |
|
69 | 67 | } |
|
70 | 68 | |
|
71 | 69 | MainWindow::~MainWindow() |
|
72 | 70 | { |
|
73 | 71 | delete m_engine; |
|
74 | 72 | } |
|
75 | 73 | |
|
76 | 74 | void MainWindow::createMenus() |
|
77 | 75 | { |
|
78 | 76 | QMenu *file = menuBar()->addMenu(tr("File")); |
|
79 | 77 | QMenu *edit = menuBar()->addMenu(tr("Edit")); |
|
80 | 78 | m_seriesMenu = menuBar()->addMenu(tr("Series")); |
|
81 | 79 | m_chartMenu = menuBar()->addMenu(tr("Chart")); |
|
82 | 80 | |
|
83 | 81 | m_addSeriesMenu = new QMenu(tr("Add series")); |
|
84 | 82 | m_themeMenu = new QMenu(tr("Apply theme")); |
|
85 | 83 | m_animationMenu = new QMenu(tr("Animations")); |
|
86 | 84 | m_zoomMenu = new QMenu(tr("Zoom")); |
|
87 | 85 | |
|
88 | 86 | file->addAction(tr("New"), this, SLOT(handleNewAction())); |
|
89 | 87 | file->addAction(tr("Load"), this, SLOT(handleLoadAction())); |
|
90 | 88 | file->addAction(tr("Save"), this, SLOT(handleSaveAction())); |
|
91 | 89 | file->addAction(tr("Save As"), this, SLOT(handleSaveAsAction())); |
|
92 | 90 | |
|
93 | 91 | //seriesMenu |
|
94 | 92 | m_seriesMenu->addMenu(m_addSeriesMenu); |
|
95 | 93 | m_removeAllAction = new QAction(tr("Remove all series"), this); |
|
96 | 94 | QObject::connect(m_removeAllAction, SIGNAL(triggered()), this, SLOT(handleRemoveAllSeriesAction())); |
|
97 | 95 | m_seriesMenu->addAction(m_removeAllAction); |
|
98 | 96 | m_seriesMenu->addSeparator(); |
|
99 | 97 | |
|
100 | 98 | //seriesMenu /addSeriesMenu |
|
101 | 99 | { |
|
102 | 100 | int index = QAbstractSeries::staticMetaObject.indexOfEnumerator("SeriesType"); |
|
103 | 101 | QMetaEnum metaEnum = QAbstractSeries::staticMetaObject.enumerator(index); |
|
104 | 102 | |
|
105 | 103 | int count = metaEnum.keyCount(); |
|
106 | 104 | |
|
107 | 105 | for (int i = 0; i < count; ++i) { |
|
108 | 106 | QAction* action = new QAction(metaEnum.key(i), this); |
|
109 | 107 | action->setData(metaEnum.value(i)); |
|
110 | 108 | m_addSeriesMenu->addAction(action); |
|
111 | 109 | QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleAddSeriesMenu())); |
|
112 | 110 | } |
|
113 | 111 | } |
|
114 | 112 | |
|
115 | 113 | //chartMenu / themeMenu |
|
116 | 114 | { |
|
117 | 115 | m_chartMenu->addMenu(m_themeMenu); |
|
118 | 116 | int index = QChart::staticMetaObject.indexOfEnumerator("ChartTheme"); |
|
119 | 117 | QMetaEnum metaEnum = QChart::staticMetaObject.enumerator(index); |
|
120 | 118 | |
|
121 | 119 | int count = metaEnum.keyCount(); |
|
122 | 120 | |
|
123 | 121 | for (int i = 0; i < count; ++i) { |
|
124 | 122 | QAction* action = new QAction(metaEnum.key(i), this); |
|
125 | 123 | action->setData(metaEnum.value(i)); |
|
126 | 124 | action->setCheckable(true); |
|
127 | 125 | m_themeMenu->addAction(action); |
|
128 | 126 | QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleThemeMenu())); |
|
129 | 127 | } |
|
130 | 128 | } |
|
131 | 129 | |
|
132 | 130 | //chartMenu / animationMenu |
|
133 | 131 | { |
|
134 | 132 | m_chartMenu->addMenu(m_animationMenu); |
|
135 | 133 | int index = QChart::staticMetaObject.indexOfEnumerator("AnimationOption"); |
|
136 | 134 | QMetaEnum metaEnum = QChart::staticMetaObject.enumerator(index); |
|
137 | 135 | |
|
138 | 136 | int count = metaEnum.keyCount(); |
|
139 | 137 | |
|
140 | 138 | for (int i = 0; i < count; ++i) { |
|
141 | 139 | QAction* action = new QAction(metaEnum.key(i), this); |
|
142 | 140 | action->setData(metaEnum.value(i)); |
|
143 | 141 | action->setCheckable(true); |
|
144 | 142 | m_animationMenu->addAction(action); |
|
145 | 143 | QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleAnimationMenu())); |
|
146 | 144 | } |
|
147 | 145 | } |
|
148 | 146 | |
|
149 | 147 | //chartMenu / zoomMenu |
|
150 | 148 | { |
|
151 | 149 | m_chartMenu->addMenu(m_zoomMenu); |
|
152 | 150 | int index = QChartView::staticMetaObject.indexOfEnumerator("RubberBand"); |
|
153 | 151 | QMetaEnum metaEnum = QChartView::staticMetaObject.enumerator(index); |
|
154 | 152 | |
|
155 | 153 | int count = metaEnum.keyCount(); |
|
156 | 154 | |
|
157 | 155 | for (int i = 0; i < count; ++i) { |
|
158 | 156 | QAction* action = new QAction(metaEnum.key(i), this); |
|
159 | 157 | action->setData(metaEnum.value(i)); |
|
160 | 158 | action->setCheckable(true); |
|
161 | 159 | m_zoomMenu->addAction(action); |
|
162 | 160 | QObject::connect(action, SIGNAL(triggered()), this, SLOT(handleZoomMenu())); |
|
163 | 161 | } |
|
164 | 162 | } |
|
165 | 163 | |
|
166 | 164 | //chartMenu / legend |
|
167 | 165 | m_legendAction = new QAction(tr("Legend"), this); |
|
168 | 166 | m_legendAction->setCheckable(true); |
|
169 | 167 | m_chartMenu->addAction(m_legendAction); |
|
170 | 168 | QObject::connect(m_legendAction, SIGNAL(triggered()), this, SLOT(handleLegendAction())); |
|
171 | 169 | |
|
172 | 170 | //chartMenu / Anti-aliasing |
|
173 | 171 | m_antialiasingAction = new QAction(tr("Anti-aliasing"), this); |
|
174 | 172 | m_antialiasingAction->setCheckable(true); |
|
175 | 173 | m_chartMenu->addAction(m_antialiasingAction); |
|
176 | 174 | QObject::connect(m_antialiasingAction, SIGNAL(triggered()), this, SLOT(handleAntialiasingAction())); |
|
177 | 175 | |
|
178 | 176 | } |
|
179 | 177 | |
|
180 | 178 | void MainWindow::createDockWidgets() |
|
181 | 179 | { |
|
182 | 180 | m_brushWidget = new BrushWidget(); |
|
183 | 181 | QDockWidget *brushDockWidget = new QDockWidget(tr("Brush"), this); |
|
184 | 182 | brushDockWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
|
185 | 183 | brushDockWidget->setWidget(m_brushWidget); |
|
186 | 184 | addDockWidget(Qt::RightDockWidgetArea, brushDockWidget); |
|
187 | 185 | |
|
188 | 186 | m_penWidget = new PenWidget(); |
|
189 | 187 | QDockWidget *penDockWidget = new QDockWidget(tr("Pen"), this); |
|
190 | 188 | penDockWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
|
191 | 189 | penDockWidget->setWidget(m_penWidget); |
|
192 | 190 | addDockWidget(Qt::RightDockWidgetArea, penDockWidget); |
|
193 | 191 | |
|
194 | 192 | m_inspectorWidget = new InspectorWidget(); |
|
195 | 193 | QDockWidget *inspectorDockWidget = new QDockWidget(tr("Object Inspector"), this); |
|
196 | 194 | inspectorDockWidget->setFeatures( |
|
197 | 195 | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); |
|
198 | 196 | inspectorDockWidget->setWidget(m_inspectorWidget); |
|
199 | 197 | addDockWidget(Qt::RightDockWidgetArea, inspectorDockWidget); |
|
200 | 198 | |
|
201 | 199 | setDockOptions(QMainWindow::AnimatedDocks); |
|
202 | 200 | } |
|
203 | 201 | |
|
204 | 202 | void MainWindow::createLayout() |
|
205 | 203 | { |
|
206 | 204 | m_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
|
207 | 205 | |
|
208 | 206 | int rowHeight = m_table->rowHeight(0); |
|
209 | 207 | int tableHeight = (m_engine->modelCount() * rowHeight) + m_table->horizontalHeader()->height() + 2 * m_table->frameWidth(); |
|
210 | 208 | |
|
211 | 209 | m_table->setMinimumHeight(tableHeight); |
|
212 | 210 | m_table->setMaximumHeight(tableHeight); |
|
213 | 211 | |
|
214 | 212 | QSplitter *splitter = new QSplitter(this); |
|
215 | 213 | splitter->setOrientation(Qt::Vertical); |
|
216 | 214 | splitter->addWidget(m_table); |
|
217 | 215 | splitter->addWidget(m_view); |
|
218 | 216 | setCentralWidget(splitter); |
|
219 | 217 | m_view->hide(); |
|
220 | 218 | } |
|
221 | 219 | |
|
222 | 220 | void MainWindow::createTable() |
|
223 | 221 | { |
|
224 | 222 | m_table->setModel(m_engine->model()); |
|
225 | 223 | m_table->setSelectionModel(m_engine->selectionModel()); |
|
226 | 224 | QObject::connect(m_table->selectionModel(),SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,SLOT(updateUI())); |
|
227 | 225 | } |
|
228 | 226 | |
|
229 | 227 | void MainWindow::updateUI() |
|
230 | 228 | { |
|
231 | 229 | |
|
232 | 230 | QItemSelectionModel* selection = m_table->selectionModel(); |
|
233 | 231 | const QModelIndexList& list = selection->selectedIndexes(); |
|
234 | 232 | |
|
235 | 233 | QMap<int, QModelIndex> columns; |
|
236 | 234 | |
|
237 | 235 | foreach (const QModelIndex& index, list) { |
|
238 | 236 | columns.insertMulti(index.column(), index); |
|
239 | 237 | } |
|
240 | 238 | |
|
241 | 239 | QList<int> keys = columns.uniqueKeys(); |
|
242 | 240 | |
|
243 | 241 | bool seriesEnabled = false; |
|
244 | 242 | |
|
245 | 243 | foreach (QAction* action, m_addSeriesMenu->actions()) { |
|
246 | 244 | switch (action->data().toInt()) { |
|
247 | 245 | case QAbstractSeries::SeriesTypeLine: |
|
248 | 246 | case QAbstractSeries::SeriesTypeSpline: |
|
249 | 247 | case QAbstractSeries::SeriesTypeScatter: |
|
250 | 248 | action->setEnabled(list.count() > 0 && keys.count() >= 2); |
|
251 | 249 | seriesEnabled |= action->isEnabled(); |
|
252 | 250 | break; |
|
253 | 251 | case QAbstractSeries::SeriesTypeBar: |
|
254 | 252 | case QAbstractSeries::SeriesTypePercentBar: |
|
255 | 253 | case QAbstractSeries::SeriesTypeStackedBar: |
|
256 | 254 | action->setEnabled(list.count() > 0 && keys.count() >= 2); |
|
257 | 255 | seriesEnabled |= action->isEnabled(); |
|
258 | 256 | break; |
|
259 | 257 | case QAbstractSeries::SeriesTypePie: |
|
260 | 258 | action->setEnabled(list.count() > 0 && keys.count() == 2); |
|
261 | 259 | seriesEnabled |= action->isEnabled(); |
|
262 | 260 | break; |
|
263 | 261 | case QAbstractSeries::SeriesTypeArea: |
|
264 | 262 | action->setEnabled(list.count() > 0 && keys.count() == 3); |
|
265 | 263 | seriesEnabled |= action->isEnabled(); |
|
266 | 264 | break; |
|
267 | 265 | } |
|
268 | 266 | } |
|
269 | 267 | |
|
270 | 268 | m_chartMenu->setEnabled(m_engine->chart()->series().count() > 0); |
|
271 | 269 | m_seriesMenu->setEnabled(seriesEnabled || m_engine->chart()->series().count() > 0); |
|
272 | 270 | m_removeAllAction->setEnabled(m_engine->chart()->series().count() > 0); |
|
273 | 271 | |
|
274 | 272 | int theme = m_engine->chart()->theme(); |
|
275 | 273 | foreach (QAction* action, m_themeMenu->actions()) { |
|
276 | 274 | action->setChecked(action->data().toInt() == theme); |
|
277 | 275 | } |
|
278 | 276 | |
|
279 | 277 | int animation = m_engine->chart()->animationOptions(); |
|
280 | 278 | foreach (QAction* action, m_animationMenu->actions()) { |
|
281 | 279 | action->setChecked(action->data().toInt() == animation); |
|
282 | 280 | } |
|
283 | 281 | |
|
284 | 282 | int zoom = m_view->rubberBand(); |
|
285 | 283 | foreach (QAction* action, m_zoomMenu->actions()) { |
|
286 | 284 | action->setChecked(action->data().toInt() == zoom); |
|
287 | 285 | } |
|
288 | 286 | |
|
289 | 287 | m_legendAction->setChecked(m_engine->chart()->legend()->isVisible()); |
|
290 | 288 | m_antialiasingAction->setChecked(m_view->renderHints().testFlag(QPainter::Antialiasing)); |
|
291 | 289 | |
|
292 | 290 | foreach (QAction *action, m_seriesMenu->actions()) { |
|
293 | 291 | //TODO: visibility handling |
|
294 | 292 | //if (m_series.value(action->text())) |
|
295 | 293 | // ; |
|
296 | 294 | //action->setChecked(false); |
|
297 | 295 | } |
|
298 | 296 | } |
|
299 | 297 | |
|
300 | 298 | void MainWindow::closeEvent(QCloseEvent *event) |
|
301 | 299 | { |
|
302 | 300 | QSettings settings; |
|
303 | 301 | settings.setValue(GEOMETRY_SETTING, saveGeometry()); |
|
304 | 302 | settings.setValue(FILENAME_SETTING, m_filename); |
|
305 | 303 | QMainWindow::closeEvent(event); |
|
306 | 304 | } |
|
307 | 305 | |
|
308 | 306 | //handlers |
|
309 | 307 | |
|
310 | 308 | void MainWindow::handleNewAction() |
|
311 | 309 | { |
|
312 | 310 | m_engine->chart()->removeAllSeries(); |
|
313 | 311 | m_view->hide(); |
|
314 | 312 | m_engine->clearModels(); |
|
315 | 313 | createTable(); |
|
316 | 314 | m_filename = "untitled"; |
|
317 | 315 | setWindowTitle(m_filename); |
|
318 | 316 | updateUI(); |
|
319 | 317 | } |
|
320 | 318 | |
|
321 | 319 | void MainWindow::handleAddSeriesMenu() |
|
322 | 320 | { |
|
323 | 321 | m_view->show(); |
|
324 | 322 | QAction* action = qobject_cast<QAction*>(sender()); |
|
325 | 323 | QList<QAbstractSeries*> series = m_engine->addSeries(QAbstractSeries::SeriesType(action->data().toInt())); |
|
326 | 324 | |
|
327 | 325 | foreach (QAbstractSeries* s , series) |
|
328 | 326 | { |
|
329 | 327 | QAction *newAction = new QAction(s->name(),this); |
|
330 | 328 | //newAction->setCheckable(true); |
|
331 | 329 | m_series.insert(s->name(),s); |
|
332 | 330 | m_seriesMenu->addAction(newAction); |
|
333 | 331 | } |
|
334 | 332 | |
|
335 | 333 | updateUI(); |
|
336 | 334 | } |
|
337 | 335 | |
|
338 | 336 | void MainWindow::handleRemoveAllSeriesAction() |
|
339 | 337 | { |
|
340 | 338 | |
|
341 | 339 | foreach (QAction* action, m_seriesMenu->actions()){ |
|
342 | 340 | if(m_series.contains(action->text())){ |
|
343 | 341 | m_seriesMenu->removeAction(action); |
|
344 | 342 | m_engine->removeSeries(m_series.value(action->text())); |
|
345 | 343 | delete action; |
|
346 | 344 | } |
|
347 | 345 | } |
|
348 | 346 | |
|
349 | 347 | m_series.clear(); |
|
350 | 348 | |
|
351 | 349 | m_view->hide(); |
|
352 | 350 | updateUI(); |
|
353 | 351 | } |
|
354 | 352 | |
|
355 | 353 | void MainWindow::handleThemeMenu() |
|
356 | 354 | { |
|
357 | 355 | QAction* action = qobject_cast<QAction*>(sender()); |
|
358 | 356 | m_engine->chart()->setTheme(QChart::ChartTheme(action->data().toInt())); |
|
359 | 357 | updateUI(); |
|
360 | 358 | } |
|
361 | 359 | |
|
362 | 360 | void MainWindow::handleAnimationMenu() |
|
363 | 361 | { |
|
364 | 362 | QAction* action = qobject_cast<QAction*>(sender()); |
|
365 | 363 | m_engine->chart()->setAnimationOptions(QChart::AnimationOption(action->data().toInt())); |
|
366 | 364 | updateUI(); |
|
367 | 365 | } |
|
368 | 366 | |
|
369 | 367 | void MainWindow::handleZoomMenu() |
|
370 | 368 | { |
|
371 | 369 | QAction* action = qobject_cast<QAction*>(sender()); |
|
372 | 370 | m_view->setRubberBand(QChartView::RubberBand(action->data().toInt())); |
|
373 | 371 | updateUI(); |
|
374 | 372 | } |
|
375 | 373 | |
|
376 | 374 | void MainWindow::handleAntialiasingAction() |
|
377 | 375 | { |
|
378 | 376 | QAction* action = qobject_cast<QAction*>(sender()); |
|
379 | 377 | if (action->isChecked()) { |
|
380 | 378 | m_view->setRenderHint(QPainter::Antialiasing, true); |
|
381 | 379 | } |
|
382 | 380 | else { |
|
383 | 381 | m_view->setRenderHint(QPainter::Antialiasing, false); |
|
384 | 382 | } |
|
385 | 383 | } |
|
386 | 384 | |
|
387 | 385 | void MainWindow::handleLegendAction() |
|
388 | 386 | { |
|
389 | 387 | QAction* action = qobject_cast<QAction*>(sender()); |
|
390 | 388 | if (action->isChecked()) { |
|
391 | 389 | m_engine->chart()->legend()->setVisible(true); |
|
392 | 390 | } |
|
393 | 391 | else { |
|
394 | 392 | m_engine->chart()->legend()->setVisible(false); |
|
395 | 393 | } |
|
396 | 394 | } |
|
397 | 395 | |
|
398 | 396 | void MainWindow::handleSaveAction() |
|
399 | 397 | { |
|
400 | 398 | if(!m_engine->save(m_filename)) { |
|
401 | 399 | |
|
402 | 400 | QScopedPointer<QMessageBox> messageBox(new QMessageBox(this)); |
|
403 | 401 | messageBox->setIcon(QMessageBox::Warning); |
|
404 | 402 | messageBox->setWindowModality(Qt::WindowModal); |
|
405 | 403 | messageBox->setWindowTitle(QString(tr("Error"))); |
|
406 | 404 | messageBox->setText(tr("Could not write to ") + m_filename); |
|
407 | 405 | messageBox->exec(); |
|
408 | 406 | } |
|
409 | 407 | } |
|
410 | 408 | |
|
411 | 409 | void MainWindow::handleLoadAction() |
|
412 | 410 | { |
|
413 | 411 | if(!m_engine->load(m_filename)) { |
|
414 | 412 | |
|
415 | 413 | QScopedPointer<QMessageBox> messageBox(new QMessageBox(this)); |
|
416 | 414 | messageBox->setIcon(QMessageBox::Warning); |
|
417 | 415 | messageBox->setWindowModality(Qt::WindowModal); |
|
418 | 416 | messageBox->setWindowTitle(QString(tr("Error"))); |
|
419 | 417 | messageBox->setText(tr("Could not open ") + m_filename); |
|
420 | 418 | messageBox->exec(); |
|
421 | 419 | |
|
422 | 420 | }else createTable(); |
|
423 | 421 | } |
@@ -1,97 +1,95 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #ifndef MAINWINDOW_H |
|
22 | 20 | #define MAINWINDOW_H |
|
23 | 21 | |
|
24 | 22 | #include <QtWidgets/QMainWindow> |
|
25 | 23 | #include <QtCharts/QChartGlobal> |
|
26 | 24 | #include <QtCore/QMap> |
|
27 | 25 | |
|
28 | 26 | |
|
29 | 27 | QT_CHARTS_BEGIN_NAMESPACE |
|
30 | 28 | class QChartView; |
|
31 | 29 | class QAbstractSeries; |
|
32 | 30 | QT_CHARTS_END_NAMESPACE |
|
33 | 31 | |
|
34 | 32 | class QGraphicsScene; |
|
35 | 33 | class InspectorWidget; |
|
36 | 34 | class BrushWidget; |
|
37 | 35 | class PenWidget; |
|
38 | 36 | class QTableView; |
|
39 | 37 | class Engine; |
|
40 | 38 | |
|
41 | 39 | QT_CHARTS_USE_NAMESPACE |
|
42 | 40 | |
|
43 | 41 | class MainWindow : public QMainWindow |
|
44 | 42 | { |
|
45 | 43 | Q_OBJECT |
|
46 | 44 | public: |
|
47 | 45 | MainWindow(); |
|
48 | 46 | ~MainWindow(); |
|
49 | 47 | |
|
50 | 48 | private slots: |
|
51 | 49 | void handleNewAction(); |
|
52 | 50 | void handleAddSeriesMenu(); |
|
53 | 51 | void handleRemoveAllSeriesAction(); |
|
54 | 52 | void updateUI(); |
|
55 | 53 | void handleThemeMenu(); |
|
56 | 54 | void handleAnimationMenu(); |
|
57 | 55 | void handleZoomMenu(); |
|
58 | 56 | void handleAntialiasingAction(); |
|
59 | 57 | void handleLegendAction(); |
|
60 | 58 | void handleSaveAction(); |
|
61 | 59 | void handleLoadAction(); |
|
62 | 60 | |
|
63 | 61 | protected: |
|
64 | 62 | void closeEvent(QCloseEvent *event); |
|
65 | 63 | |
|
66 | 64 | private: |
|
67 | 65 | void createMenus(); |
|
68 | 66 | void createDockWidgets(); |
|
69 | 67 | void createModel(); |
|
70 | 68 | void createLayout(); |
|
71 | 69 | void createTable(); |
|
72 | 70 | |
|
73 | 71 | private: |
|
74 | 72 | Engine *m_engine; |
|
75 | 73 | QChartView *m_view; |
|
76 | 74 | QGraphicsScene *m_scene; |
|
77 | 75 | QTableView *m_table; |
|
78 | 76 | InspectorWidget *m_inspectorWidget; |
|
79 | 77 | PenWidget *m_penWidget; |
|
80 | 78 | BrushWidget *m_brushWidget; |
|
81 | 79 | QMenu *m_addSeriesMenu; |
|
82 | 80 | QMenu *m_seriesMenu; |
|
83 | 81 | QMenu *m_chartMenu; |
|
84 | 82 | QMenu *m_themeMenu; |
|
85 | 83 | QMenu *m_animationMenu; |
|
86 | 84 | QMenu *m_zoomMenu; |
|
87 | 85 | |
|
88 | 86 | QAction *m_removeAllAction; |
|
89 | 87 | QAction *m_legendAction; |
|
90 | 88 | QAction *m_antialiasingAction; |
|
91 | 89 | QString m_filename; |
|
92 | 90 | |
|
93 | 91 | QMap<QString,QAbstractSeries*> m_series; |
|
94 | 92 | |
|
95 | 93 | }; |
|
96 | 94 | |
|
97 | 95 | #endif /* MAINWINDOW_H */ |
@@ -1,51 +1,49 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include "objectinspectorwidget.h" |
|
22 | 20 | #include <QtGui/QIcon> |
|
23 | 21 | #include <QtGui/QPainter> |
|
24 | 22 | #include <QtGui/QPixmapCache> |
|
25 | 23 | |
|
26 | 24 | InspectorWidget::InspectorWidget() |
|
27 | 25 | { |
|
28 | 26 | |
|
29 | 27 | } |
|
30 | 28 | |
|
31 | 29 | InspectorWidget::~InspectorWidget() |
|
32 | 30 | { |
|
33 | 31 | |
|
34 | 32 | } |
|
35 | 33 | |
|
36 | 34 | QIcon InspectorWidget::getColorIcon(const QColor& color,const QSize &size) const |
|
37 | 35 | { |
|
38 | 36 | |
|
39 | 37 | QString key = QString("COLOR_ICON=%1:%2x%3").arg(color.name()).arg(size.width()).arg(size.height()); |
|
40 | 38 | |
|
41 | 39 | QPixmap pixmap(size); |
|
42 | 40 | |
|
43 | 41 | if (!QPixmapCache::find(key, &pixmap)) { |
|
44 | 42 | pixmap.fill(Qt::white); |
|
45 | 43 | QPainter painter(&pixmap); |
|
46 | 44 | painter.fillRect(2, 2, 46, 46, color); |
|
47 | 45 | QPixmapCache::insert(key, pixmap); |
|
48 | 46 | } |
|
49 | 47 | |
|
50 | 48 | return QIcon(pixmap); |
|
51 | 49 | } |
@@ -1,37 +1,35 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #ifndef INSPECTORWIDGET_H |
|
22 | 20 | #define INSPECTORWIDGET_H |
|
23 | 21 | |
|
24 | 22 | #include <QtWidgets/QWidget> |
|
25 | 23 | |
|
26 | 24 | class InspectorWidget : public QWidget |
|
27 | 25 | { |
|
28 | 26 | public: |
|
29 | 27 | InspectorWidget(); |
|
30 | 28 | ~InspectorWidget(); |
|
31 | 29 | |
|
32 | 30 | private: |
|
33 | 31 | QIcon getColorIcon(const QColor& color,const QSize &size) const; |
|
34 | 32 | |
|
35 | 33 | }; |
|
36 | 34 | |
|
37 | 35 | #endif |
@@ -1,56 +1,54 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include "penwidget.h" |
|
22 | 20 | #include <QtWidgets/QFormLayout> |
|
23 | 21 | #include <QtWidgets/QComboBox> |
|
24 | 22 | #include <QtWidgets/QSpinBox> |
|
25 | 23 | |
|
26 | 24 | PenWidget::PenWidget(QWidget *parent):QWidget(parent), |
|
27 | 25 | m_colorComboBox(0), |
|
28 | 26 | m_lineStyleComboBox(0), |
|
29 | 27 | m_widthSpinBox(0) |
|
30 | 28 | { |
|
31 | 29 | createContent(); |
|
32 | 30 | createLayout(); |
|
33 | 31 | setFixedSize(minimumSizeHint()); |
|
34 | 32 | } |
|
35 | 33 | |
|
36 | 34 | PenWidget::~PenWidget() |
|
37 | 35 | { |
|
38 | 36 | |
|
39 | 37 | } |
|
40 | 38 | |
|
41 | 39 | void PenWidget::createContent() |
|
42 | 40 | { |
|
43 | 41 | m_colorComboBox = new QComboBox(this); |
|
44 | 42 | m_lineStyleComboBox = new QComboBox(this); |
|
45 | 43 | m_widthSpinBox = new QSpinBox(this); |
|
46 | 44 | } |
|
47 | 45 | |
|
48 | 46 | void PenWidget::createLayout() |
|
49 | 47 | { |
|
50 | 48 | QFormLayout *layout = new QFormLayout(); |
|
51 | 49 | layout->addRow(tr("Color"), m_colorComboBox); |
|
52 | 50 | layout->addRow(tr("Style"), m_lineStyleComboBox); |
|
53 | 51 | layout->addRow(tr("Width"), m_widthSpinBox); |
|
54 | 52 | setLayout(layout); |
|
55 | 53 | } |
|
56 | 54 |
@@ -1,48 +1,46 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #ifndef PENWIDGET_H |
|
22 | 20 | #define PENWIDGET_H |
|
23 | 21 | |
|
24 | 22 | #include <QtWidgets/QWidget> |
|
25 | 23 | #include <QtWidgets/QPen> |
|
26 | 24 | |
|
27 | 25 | class QComboBox; |
|
28 | 26 | class QSpinBox; |
|
29 | 27 | |
|
30 | 28 | class PenWidget : public QWidget |
|
31 | 29 | { |
|
32 | 30 | public: |
|
33 | 31 | explicit PenWidget(QWidget* parent = 0); |
|
34 | 32 | ~PenWidget(); |
|
35 | 33 | |
|
36 | 34 | QPen pen() const { return m_pen; } |
|
37 | 35 | private: |
|
38 | 36 | void createContent(); |
|
39 | 37 | void createLayout(); |
|
40 | 38 | |
|
41 | 39 | private: |
|
42 | 40 | QPen m_pen; |
|
43 | 41 | QComboBox *m_colorComboBox; |
|
44 | 42 | QComboBox *m_lineStyleComboBox; |
|
45 | 43 | QSpinBox *m_widthSpinBox; |
|
46 | 44 | }; |
|
47 | 45 | |
|
48 | 46 | #endif /* PENWIDGET_H */ |
@@ -1,59 +1,57 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include "graphicsbutton.h" |
|
22 | 20 | #include <QPainter> |
|
23 | 21 | #include <QProcess> |
|
24 | 22 | #include <QMouseEvent> |
|
25 | 23 | |
|
26 | 24 | GraphicsButton::GraphicsButton(const QString &path, QDir appFolder, const QString &app, QWidget *parent) : |
|
27 | 25 | QWidget(parent), |
|
28 | 26 | m_path(path), |
|
29 | 27 | m_appFolder(appFolder), |
|
30 | 28 | m_app(app), |
|
31 | 29 | m_demoApp(0) |
|
32 | 30 | { |
|
33 | 31 | m_pixmap = QPixmap(path); |
|
34 | 32 | } |
|
35 | 33 | |
|
36 | 34 | GraphicsButton::~GraphicsButton() |
|
37 | 35 | { |
|
38 | 36 | if (m_demoApp) |
|
39 | 37 | m_demoApp->close(); |
|
40 | 38 | } |
|
41 | 39 | |
|
42 | 40 | void GraphicsButton::mousePressEvent(QMouseEvent *event) |
|
43 | 41 | { |
|
44 | 42 | QString program = m_appFolder.absolutePath() + QDir::separator() + m_app; |
|
45 | 43 | if (m_demoApp) { |
|
46 | 44 | m_demoApp->close(); |
|
47 | 45 | delete m_demoApp; |
|
48 | 46 | } |
|
49 | 47 | m_demoApp = new QProcess(this); |
|
50 | 48 | m_demoApp->start(program); |
|
51 | 49 | event->accept(); |
|
52 | 50 | } |
|
53 | 51 | |
|
54 | 52 | void GraphicsButton::paintEvent(QPaintEvent *event) |
|
55 | 53 | { |
|
56 | 54 | QPainter painter(this); |
|
57 | 55 | painter.drawPixmap(0, 0, this->width(), this->height(), m_pixmap); |
|
58 | 56 | QWidget::paintEvent(event); |
|
59 | 57 | } |
@@ -1,48 +1,46 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #ifndef GRAPHICSBUTTON_H |
|
22 | 20 | #define GRAPHICSBUTTON_H |
|
23 | 21 | |
|
24 | 22 | #include <QWidget> |
|
25 | 23 | #include <QDir> |
|
26 | 24 | |
|
27 | 25 | class QProcess; |
|
28 | 26 | |
|
29 | 27 | class GraphicsButton : public QWidget |
|
30 | 28 | { |
|
31 | 29 | Q_OBJECT |
|
32 | 30 | public: |
|
33 | 31 | explicit GraphicsButton(const QString &path, QDir appFolder, const QString &app, QWidget *parent = 0); |
|
34 | 32 | ~GraphicsButton(); |
|
35 | 33 | |
|
36 | 34 | protected: |
|
37 | 35 | void mousePressEvent(QMouseEvent *event); |
|
38 | 36 | void paintEvent(QPaintEvent *event); |
|
39 | 37 | |
|
40 | 38 | private: |
|
41 | 39 | QPixmap m_pixmap; |
|
42 | 40 | QString m_path; |
|
43 | 41 | QDir m_appFolder; |
|
44 | 42 | QString m_app; |
|
45 | 43 | QProcess *m_demoApp; |
|
46 | 44 | }; |
|
47 | 45 | |
|
48 | 46 | #endif // GRAPHICSBUTTON_H |
@@ -1,31 +1,29 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include <QApplication> |
|
22 | 20 | #include "widget.h" |
|
23 | 21 | |
|
24 | 22 | int main(int argc, char *argv[]) |
|
25 | 23 | { |
|
26 | 24 | QApplication a(argc, argv); |
|
27 | 25 | Widget w; |
|
28 | 26 | w.show(); |
|
29 | 27 | |
|
30 | 28 | return a.exec(); |
|
31 | 29 | } |
@@ -1,81 +1,79 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #include "widget.h" |
|
22 | 20 | #include <QDir> |
|
23 | 21 | #include <QGridLayout> |
|
24 | 22 | #include <QApplication> |
|
25 | 23 | #include "graphicsbutton.h" |
|
26 | 24 | |
|
27 | 25 | Widget::Widget(QWidget *parent) |
|
28 | 26 | : QWidget(parent) |
|
29 | 27 | { |
|
30 | 28 | setMinimumSize(800, 600); |
|
31 | 29 | |
|
32 | 30 | m_appFolder = QDir(QApplication::applicationDirPath()); |
|
33 | 31 | #ifdef Q_OS_MAC |
|
34 | 32 | // The executable is inside an application bundle (a folder) on OSX |
|
35 | 33 | m_appFolder.cdUp(); |
|
36 | 34 | m_appFolder.cdUp(); |
|
37 | 35 | m_appFolder.cdUp(); |
|
38 | 36 | #endif |
|
39 | 37 | |
|
40 | 38 | QDir imageFolder = m_appFolder; |
|
41 | 39 | imageFolder.cdUp(); |
|
42 | 40 | imageFolder.cdUp(); |
|
43 | 41 | imageFolder.cd("doc"); |
|
44 | 42 | imageFolder.cd("images"); |
|
45 | 43 | |
|
46 | 44 | // Create push buttons for starting the executables |
|
47 | 45 | QGridLayout* demosLayout = new QGridLayout; |
|
48 | 46 | |
|
49 | 47 | GraphicsButton *button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() + "examples_audio.png", m_appFolder, "audio", this); |
|
50 | 48 | demosLayout->addWidget(button, 0, 0); |
|
51 | 49 | |
|
52 | 50 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_callout.png", m_appFolder, "callout", this); |
|
53 | 51 | demosLayout->addWidget(button, 0, 1); |
|
54 | 52 | |
|
55 | 53 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"demo_chartthemes_blue_cerulean.png", m_appFolder, "chartthemes", this); |
|
56 | 54 | demosLayout->addWidget(button, 0, 2); |
|
57 | 55 | |
|
58 | 56 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_nesteddonuts.png", m_appFolder, "nesteddonuts", this); |
|
59 | 57 | demosLayout->addWidget(button, 1, 0); |
|
60 | 58 | |
|
61 | 59 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_zoomlinechart1.png", m_appFolder, "zoomlinechart", this); |
|
62 | 60 | demosLayout->addWidget(button, 1, 1); |
|
63 | 61 | |
|
64 | 62 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_stackedbarchartdrilldown1.png", m_appFolder, "stackedbarchartdrilldown", this); |
|
65 | 63 | demosLayout->addWidget(button, 1, 2); |
|
66 | 64 | |
|
67 | 65 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"piechart_customization.png", m_appFolder, "piechartcustomization", this); |
|
68 | 66 | demosLayout->addWidget(button, 2, 0); |
|
69 | 67 | |
|
70 | 68 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_datetimeaxis.png", m_appFolder, "datetimeaxis", this); |
|
71 | 69 | demosLayout->addWidget(button, 2, 1); |
|
72 | 70 | |
|
73 | 71 | button = new GraphicsButton(imageFolder.absolutePath() + QDir::separator() +"examples_donutbreakdown.png", m_appFolder, "donutbreakdown", this); |
|
74 | 72 | demosLayout->addWidget(button, 2, 2); |
|
75 | 73 | |
|
76 | 74 | setLayout(demosLayout); |
|
77 | 75 | } |
|
78 | 76 | |
|
79 | 77 | Widget::~Widget() |
|
80 | 78 | { |
|
81 | 79 | } |
@@ -1,39 +1,37 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 |
** For any questions to Digia, please use contact form at http://qt. |
|
|
5 | ** For any questions to Digia, please use contact form at http://qt.io | |
|
6 | 6 | ** |
|
7 |
** This file is part of the Qt |
|
|
7 | ** This file is part of the Qt Charts module. | |
|
8 | 8 | ** |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Enterprise licenses may use this file in | |
|
11 | ** accordance with the Qt Enterprise License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
9 | ** Licensees holding valid commercial license for Qt may use this file in | |
|
10 | ** accordance with the Qt License Agreement provided with the Software | |
|
11 | ** or, alternatively, in accordance with the terms contained in a written | |
|
12 | ** agreement between you and Digia. | |
|
14 | 13 | ** |
|
15 | 14 | ** If you have questions regarding the use of this file, please use |
|
16 |
** contact form at http://qt. |
|
|
17 | ** $QT_END_LICENSE$ | |
|
15 | ** contact form at http://qt.io | |
|
18 | 16 | ** |
|
19 | 17 | ****************************************************************************/ |
|
20 | 18 | |
|
21 | 19 | #ifndef WIDGET_H |
|
22 | 20 | #define WIDGET_H |
|
23 | 21 | |
|
24 | 22 | #include <QWidget> |
|
25 | 23 | #include <QDir> |
|
26 | 24 | |
|
27 | 25 | class Widget : public QWidget |
|
28 | 26 | { |
|
29 | 27 | Q_OBJECT |
|
30 | 28 | |
|
31 | 29 | public: |
|
32 | 30 | Widget(QWidget *parent = 0); |
|
33 | 31 | ~Widget(); |
|
34 | 32 | |
|
35 | 33 | private: |
|
36 | 34 | QDir m_appFolder; |
|
37 | 35 | }; |
|
38 | 36 | |
|
39 | 37 | #endif // WIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now