@@ -41,19 +41,18 public: | |||
|
41 | 41 | QBarSeries *series = new QBarSeries(chart); |
|
42 | 42 | QValueAxis *valueaxis = new QValueAxis(); |
|
43 | 43 | QBarCategoryAxis *barcategory = new QBarCategoryAxis(); |
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
44 | for (int i(0); i < table.count(); i++) { | |
|
45 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
|
46 | foreach (Data data, table[i]) | |
|
47 | *set << data.first.y(); | |
|
48 | series->append(set); | |
|
49 | } | |
|
50 | chart->addSeries(series); | |
|
51 | 51 | |
|
52 | 52 | int count = series->barSets().first()->count(); |
|
53 | 53 | |
|
54 |
for(int i =0 |
|
|
54 | for (int i = 0; i < count; i++) | |
|
55 | 55 | barcategory->append(QString::number(i)); |
|
56 | } | |
|
57 | 56 | |
|
58 | 57 | chart->setAxisY(valueaxis, series); |
|
59 | 58 | chart->setAxisX(barcategory, series); |
@@ -41,19 +41,18 public: | |||
|
41 | 41 | QHorizontalBarSeries *series = new QHorizontalBarSeries(chart); |
|
42 | 42 | QValueAxis *valueaxis = new QValueAxis(); |
|
43 | 43 | QBarCategoryAxis *barcategory = new QBarCategoryAxis(); |
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
44 | for (int i(0); i < table.count(); i++) { | |
|
45 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
|
46 | foreach(Data data, table[i]) | |
|
47 | *set << data.first.y(); | |
|
48 | series->append(set); | |
|
49 | } | |
|
50 | chart->addSeries(series); | |
|
51 | 51 | |
|
52 | 52 | int count = series->barSets().first()->count(); |
|
53 | 53 | |
|
54 |
for(int i =0 |
|
|
54 | for (int i = 0; i < count; i++) | |
|
55 | 55 | barcategory->append(QString::number(i)); |
|
56 | } | |
|
57 | 56 | |
|
58 | 57 | chart->setAxisX(valueaxis, series); |
|
59 | 58 | chart->setAxisY(barcategory, series); |
@@ -44,9 +44,9 public: | |||
|
44 | 44 | int nameIndex = 0; |
|
45 | 45 | foreach (DataList list, table) { |
|
46 | 46 | QLineSeries *series = new QLineSeries(chart); |
|
47 | foreach (Data data, list){ | |
|
47 | foreach (Data data, list) { | |
|
48 | 48 | QPointF point = data.first; |
|
49 | series->append(1000l*60l*60l*24l*365l*30l+point.x()*1000l*60l*60l*24l*365l,point.y()); | |
|
49 | series->append(1000l * 60l * 60l * 24l * 365l * 30l + point.x() * 1000l * 60l * 60l * 24l * 365l, point.y()); | |
|
50 | 50 | } |
|
51 | 51 | series->setName(name + QString::number(nameIndex)); |
|
52 | 52 | nameIndex++; |
@@ -44,9 +44,9 public: | |||
|
44 | 44 | int nameIndex = 0; |
|
45 | 45 | foreach (DataList list, table) { |
|
46 | 46 | QLineSeries *series = new QLineSeries(chart); |
|
47 | foreach (Data data, list){ | |
|
47 | foreach (Data data, list) { | |
|
48 | 48 | QPointF point = data.first; |
|
49 | series->append(point.x(),1000l*60l*60l*24l*365l*30l+point.y()*1000l*60l*60l*24l*365l); | |
|
49 | series->append(point.x(), 1000l * 60l * 60l * 24l * 365l * 30l + point.y() * 1000l * 60l * 60l * 24l * 365l); | |
|
50 | 50 | } |
|
51 | 51 | series->setName(name + QString::number(nameIndex)); |
|
52 | 52 | nameIndex++; |
@@ -30,7 +30,7 public: | |||
|
30 | 30 | QString subCategory() { return QString::null; } |
|
31 | 31 | |
|
32 | 32 | QChart *createChart(const DataTable &table) |
|
33 |
|
|
|
33 | { | |
|
34 | 34 | QChart *chart = new QChart(); |
|
35 | 35 | chart->setTitle("Donut chart"); |
|
36 | 36 | for (int i = 0, j = table.count(); i < table.count(); i++, j--) { |
@@ -25,16 +25,17 | |||
|
25 | 25 | #include <QGraphicsSceneMouseEvent> |
|
26 | 26 | #include <QDebug> |
|
27 | 27 | |
|
28 |
Grid::Grid(int size,QGraphicsItem *parent) |
|
|
29 | m_listCount(3), | |
|
30 | m_valueMax(10), | |
|
31 |
m_value |
|
|
32 | m_size(size), | |
|
33 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
|
34 | m_state(NoState), | |
|
35 |
|
|
|
36 | m_rubberBand(new QGraphicsRectItem()), | |
|
37 | m_gridLayout(new QGraphicsGridLayout()) | |
|
28 | Grid::Grid(int size, QGraphicsItem *parent) | |
|
29 | : QGraphicsWidget(parent), | |
|
30 | m_listCount(3), | |
|
31 | m_valueMax(10), | |
|
32 | m_valueCount(7), | |
|
33 | m_size(size), | |
|
34 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
|
35 | m_state(NoState), | |
|
36 | m_currentState(NoState), | |
|
37 | m_rubberBand(new QGraphicsRectItem()), | |
|
38 | m_gridLayout(new QGraphicsGridLayout()) | |
|
38 | 39 | { |
|
39 | 40 | setLayout(m_gridLayout); |
|
40 | 41 | m_rubberBand->setParentItem(this); |
@@ -47,7 +48,7 Grid::~Grid() | |||
|
47 | 48 | |
|
48 | 49 | } |
|
49 | 50 | |
|
50 |
void Grid::createCharts(const QString& |
|
|
51 | void Grid::createCharts(const QString &category) | |
|
51 | 52 | { |
|
52 | 53 | clear(); |
|
53 | 54 | |
@@ -55,23 +56,18 void Grid::createCharts(const QString& category) | |||
|
55 | 56 | Charts::ChartList list = Charts::chartList(); |
|
56 | 57 | |
|
57 | 58 | if (category.isEmpty()) { |
|
58 | ||
|
59 | 59 | for (int i = 0; i < m_size * m_size; ++i) { |
|
60 | 60 | QChart *chart = 0; |
|
61 | 61 | if (i < list.size()) { |
|
62 | 62 | chart = list.at(i)->createChart(m_dataTable); |
|
63 | } | |
|
64 | else { | |
|
63 | } else { | |
|
65 | 64 | chart = new QChart(); |
|
66 | 65 | chart->setTitle(QObject::tr("Empty")); |
|
67 | 66 | } |
|
68 | ||
|
69 | 67 | m_gridLayout->addItem(chart, i / m_size, i % m_size); |
|
70 | 68 | m_chartHash[chart] = i; |
|
71 | 69 | } |
|
72 | } | |
|
73 | else { | |
|
74 | ||
|
70 | } else { | |
|
75 | 71 | int j = 0; |
|
76 | 72 | for (int i = 0; i < list.size(); ++i) { |
|
77 | 73 | Chart *chart = list.at(i); |
@@ -95,15 +91,14 void Grid::createCharts(const QString& category) | |||
|
95 | 91 | |
|
96 | 92 | void Grid::clear() |
|
97 | 93 | { |
|
98 |
for (int i = 0; i < m_gridLayout->count(); ++i) |
|
|
94 | for (int i = 0; i < m_gridLayout->count(); ++i) | |
|
99 | 95 | m_gridLayout->removeAt(i); |
|
100 | } | |
|
101 | 96 | |
|
102 | 97 | qDeleteAll(m_chartHash.keys()); |
|
103 | 98 | m_chartHash.clear(); |
|
104 | 99 | } |
|
105 | 100 | |
|
106 | QList<QChart*> Grid::charts() | |
|
101 | QList<QChart *> Grid::charts() | |
|
107 | 102 | { |
|
108 | 103 | return m_chartHash.keys(); |
|
109 | 104 | } |
@@ -115,19 +110,18 void Grid::setState(State state) | |||
|
115 | 110 | |
|
116 | 111 | void Grid::setSize(int size) |
|
117 | 112 | { |
|
118 | if(m_size !=size) | |
|
119 | { | |
|
120 | m_size = size; | |
|
121 | createCharts(m_category); | |
|
113 | if (m_size != size) { | |
|
114 | m_size = size; | |
|
115 | createCharts(m_category); | |
|
122 | 116 | } |
|
123 | 117 | } |
|
124 | 118 | |
|
125 |
void Grid::setRubberPen(const QPen& |
|
|
119 | void Grid::setRubberPen(const QPen &pen) | |
|
126 | 120 | { |
|
127 | 121 | m_rubberBand->setPen(pen); |
|
128 | 122 | } |
|
129 | 123 | |
|
130 |
void Grid::replaceChart(QChart* |
|
|
124 | void Grid::replaceChart(QChart *oldChart, Chart *newChart) | |
|
131 | 125 | { |
|
132 | 126 | int index = m_chartHash[oldChart]; |
|
133 | 127 | //not in 4.7.2 m_baseLayout->removeItem(qchart); |
@@ -152,7 +146,6 void Grid::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
152 | 146 | m_currentState = NoState; |
|
153 | 147 | |
|
154 | 148 | foreach (QChart *chart, charts()) { |
|
155 | ||
|
156 | 149 | QRectF geometryRect = chart->geometry(); |
|
157 | 150 | QRectF plotArea = chart->plotArea(); |
|
158 | 151 | plotArea.translate(geometryRect.topLeft()); |
@@ -181,11 +174,9 void Grid::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |||
|
181 | 174 | if (m_currentState != NoState) { |
|
182 | 175 | |
|
183 | 176 | foreach (QChart *chart, charts()) { |
|
184 | ||
|
185 | 177 | QRectF geometryRect = chart->geometry(); |
|
186 | 178 | QRectF plotArea = chart->plotArea(); |
|
187 | 179 | plotArea.translate(geometryRect.topLeft()); |
|
188 | ||
|
189 | 180 | if (plotArea.contains(m_origin)) { |
|
190 | 181 | if (m_currentState == ScrollState) { |
|
191 | 182 | QPointF delta = m_origin - event->pos(); |
@@ -209,11 +200,9 void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |||
|
209 | 200 | m_rubberBand->setVisible(false); |
|
210 | 201 | |
|
211 | 202 | foreach (QChart *chart, charts()) { |
|
212 | ||
|
213 | 203 | QRectF geometryRect = chart->geometry(); |
|
214 | 204 | QRectF plotArea = chart->plotArea(); |
|
215 | 205 | plotArea.translate(geometryRect.topLeft()); |
|
216 | ||
|
217 | 206 | if (plotArea.contains(m_origin)) { |
|
218 | 207 | QRectF rect = m_rubberBand->rect(); |
|
219 | 208 | rect.translate(-geometryRect.topLeft()); |
@@ -222,20 +211,16 void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |||
|
222 | 211 | } |
|
223 | 212 | } |
|
224 | 213 | } |
|
225 | ||
|
226 | 214 | m_currentState = NoState; |
|
227 | 215 | event->accept(); |
|
228 | 216 | } |
|
229 | 217 | |
|
230 | 218 | if (event->button() == Qt::RightButton) { |
|
231 | ||
|
232 | 219 | if (m_currentState == ZoomState) { |
|
233 | 220 | foreach (QChart *chart, charts()) { |
|
234 | ||
|
235 | 221 | QRectF geometryRect = chart->geometry(); |
|
236 | 222 | QRectF plotArea = chart->plotArea(); |
|
237 | 223 | plotArea.translate(geometryRect.topLeft()); |
|
238 | ||
|
239 | 224 | if (plotArea.contains(m_origin)) { |
|
240 | 225 | chart->zoomOut(); |
|
241 | 226 | break; |
@@ -39,24 +39,30 class Grid : public QGraphicsWidget | |||
|
39 | 39 | Q_OBJECT |
|
40 | 40 | public: |
|
41 | 41 | enum State { NoState = 0, ZoomState, ScrollState}; |
|
42 | Grid(int size , QGraphicsItem *parent = 0 ); | |
|
42 | ||
|
43 | Grid(int size, QGraphicsItem *parent = 0); | |
|
43 | 44 | ~Grid(); |
|
44 | QList<QChart*> charts(); | |
|
45 | void createCharts(const QString& category = QString()); | |
|
46 | void replaceChart(QChart* oldChart, Chart* newChart); | |
|
45 | ||
|
46 | QList<QChart *> charts(); | |
|
47 | void createCharts(const QString &category = QString()); | |
|
48 | void replaceChart(QChart *oldChart, Chart *newChart); | |
|
47 | 49 | void setState(State state); |
|
48 | 50 | State state() const { return m_state; }; |
|
49 |
void setRubberPen(const QPen& |
|
|
51 | void setRubberPen(const QPen &pen); | |
|
50 | 52 | void setSize(int size); |
|
51 | 53 | int size() const {return m_size;} |
|
52 | Q_SIGNAL | |
|
53 | void chartSelected(QChart* chart); | |
|
54 | ||
|
55 | Q_SIGNALS: | |
|
56 | void chartSelected(QChart *chart); | |
|
57 | ||
|
54 | 58 | protected: |
|
55 | 59 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
56 | 60 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
|
57 | 61 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
|
62 | ||
|
58 | 63 | private: |
|
59 | 64 | void clear(); |
|
65 | ||
|
60 | 66 | private: |
|
61 | 67 | int m_listCount; |
|
62 | 68 | int m_valueMax; |
@@ -68,7 +74,7 private: | |||
|
68 | 74 | State m_currentState; |
|
69 | 75 | QPointF m_origin; |
|
70 | 76 | QGraphicsRectItem *m_rubberBand; |
|
71 |
QGraphicsGridLayout* |
|
|
77 | QGraphicsGridLayout *m_gridLayout; | |
|
72 | 78 | QString m_category; |
|
73 | 79 | }; |
|
74 | 80 |
@@ -34,19 +34,17 QVariantHash parseArgs(QStringList args) | |||
|
34 | 34 | |
|
35 | 35 | if (args.isEmpty() || args.first().startsWith("--")) { |
|
36 | 36 | parameters[param] = true; |
|
37 | } | |
|
38 | else { | |
|
39 | ||
|
37 | } else { | |
|
40 | 38 | QString value = args.takeFirst(); |
|
41 | 39 | if (value == "true" || value == "on" || value == "enabled") { |
|
42 | 40 | parameters[param] = true; |
|
43 | } | |
|
44 | else if (value == "false" || value == "off" || value == "disable") { | |
|
41 | } else if (value == "false" || value == "off" || value == "disable") { | |
|
45 | 42 | parameters[param] = false; |
|
46 | } | |
|
47 | else { | |
|
48 |
|
|
|
49 |
if(value.startsWith( |
|
|
43 | } else { | |
|
44 | if (value.endsWith('"')) | |
|
45 | value.chop(1); | |
|
46 | if (value.startsWith('"')) | |
|
47 | value.remove(0, 1); | |
|
50 | 48 | parameters[param] = value; |
|
51 | 49 | } |
|
52 | 50 | } |
@@ -41,24 +41,24 | |||
|
41 | 41 | #include <QMenu> |
|
42 | 42 | #include <QPushButton> |
|
43 | 43 | |
|
44 |
Window::Window(const QVariantHash& |
|
|
45 | QMainWindow(parent), | |
|
46 | m_scene(new QGraphicsScene(this)), | |
|
47 | m_view(0), | |
|
48 | m_form(0), | |
|
49 | m_themeComboBox(0), | |
|
50 | m_antialiasCheckBox(0), | |
|
51 | m_animatedComboBox(0), | |
|
52 | m_legendComboBox(0), | |
|
53 | m_templateComboBox(0), | |
|
54 | m_viewComboBox(0), | |
|
55 | m_openGLCheckBox(0), | |
|
56 | m_zoomCheckBox(0), | |
|
57 | m_scrollCheckBox(0), | |
|
58 | m_baseLayout(new QGraphicsLinearLayout()), | |
|
59 | m_menu(createMenu()), | |
|
60 | m_template(0), | |
|
61 | m_grid(new Grid(1)) | |
|
44 | Window::Window(const QVariantHash ¶meters, QWidget *parent) | |
|
45 | : QMainWindow(parent), | |
|
46 | m_scene(new QGraphicsScene(this)), | |
|
47 | m_view(0), | |
|
48 | m_form(0), | |
|
49 | m_themeComboBox(0), | |
|
50 | m_antialiasCheckBox(0), | |
|
51 | m_animatedComboBox(0), | |
|
52 | m_legendComboBox(0), | |
|
53 | m_templateComboBox(0), | |
|
54 | m_viewComboBox(0), | |
|
55 | m_openGLCheckBox(0), | |
|
56 | m_zoomCheckBox(0), | |
|
57 | m_scrollCheckBox(0), | |
|
58 | m_baseLayout(new QGraphicsLinearLayout()), | |
|
59 | m_menu(createMenu()), | |
|
60 | m_template(0), | |
|
61 | m_grid(new Grid(1)) | |
|
62 | 62 | { |
|
63 | 63 | createProxyWidgets(); |
|
64 | 64 | // create layout |
@@ -121,7 +121,7 void Window::connectSignals() | |||
|
121 | 121 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
122 | 122 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
123 | 123 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
124 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)),this,SLOT(handleChartSelected(QChart*))); | |
|
124 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*))); | |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | void Window::createProxyWidgets() |
@@ -212,7 +212,7 QComboBox *Window::createTempleteBox() | |||
|
212 | 212 | return templateComboBox; |
|
213 | 213 | } |
|
214 | 214 | |
|
215 |
void Window::initializeFromParamaters(const QVariantHash& |
|
|
215 | void Window::initializeFromParamaters(const QVariantHash ¶meters) | |
|
216 | 216 | { |
|
217 | 217 | if (parameters.contains("template")) { |
|
218 | 218 | QString t = parameters["template"].toString(); |
@@ -255,15 +255,14 void Window::initializeFromParamaters(const QVariantHash& parameters) | |||
|
255 | 255 | } |
|
256 | 256 | } |
|
257 | 257 | if (parameters.contains("view")) { |
|
258 |
|
|
|
259 |
|
|
|
260 |
|
|
|
261 | ||
|
262 | m_viewComboBox->setCurrentIndex(i); | |
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 | } | |
|
258 | int t = parameters["view"].toInt(); | |
|
259 | for (int i = 0; i < m_viewComboBox->count(); ++i) { | |
|
260 | if (m_viewComboBox->itemData(i).toInt() == t) { | |
|
261 | m_viewComboBox->setCurrentIndex(i); | |
|
262 | break; | |
|
263 | } | |
|
264 | } | |
|
265 | } | |
|
267 | 266 | } |
|
268 | 267 | |
|
269 | 268 | void Window::updateUI() |
@@ -322,7 +321,7 void Window::checkAnimationOptions() | |||
|
322 | 321 | QChart::AnimationOptions options( |
|
323 | 322 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
324 | 323 | |
|
325 | QList<QChart*> charts = m_grid->charts(); | |
|
324 | QList<QChart *> charts = m_grid->charts(); | |
|
326 | 325 | |
|
327 | 326 | if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { |
|
328 | 327 | foreach (QChart *chart, charts) |
@@ -415,13 +414,14 void Window::comboBoxFocused(QComboBox *combobox) | |||
|
415 | 414 | |
|
416 | 415 | void Window::handleChartSelected(QChart *qchart) |
|
417 | 416 | { |
|
418 |
if(m_templateComboBox->currentIndex() != 0) |
|
|
417 | if (m_templateComboBox->currentIndex() != 0) | |
|
418 | return; | |
|
419 | 419 | |
|
420 | 420 | QAction *chosen = m_menu->exec(QCursor::pos()); |
|
421 | 421 | |
|
422 | 422 | if (chosen) { |
|
423 | 423 | Chart *chart = (Chart *) chosen->data().value<void *>(); |
|
424 | m_grid->replaceChart(qchart,chart); | |
|
424 | m_grid->replaceChart(qchart, chart); | |
|
425 | 425 | updateUI(); |
|
426 | 426 | } |
|
427 | 427 | } |
@@ -46,7 +46,7 class Window: public QMainWindow | |||
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | public: |
|
49 |
explicit Window(const QVariantHash& |
|
|
49 | explicit Window(const QVariantHash ¶meters, QWidget *parent = 0); | |
|
50 | 50 | ~Window(); |
|
51 | 51 | |
|
52 | 52 | private Q_SLOTS: |
@@ -71,7 +71,7 private: | |||
|
71 | 71 | inline void checkTemplate(); |
|
72 | 72 | QMenu *createMenu(); |
|
73 | 73 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); |
|
74 |
void initializeFromParamaters(const QVariantHash& |
|
|
74 | void initializeFromParamaters(const QVariantHash ¶meters); | |
|
75 | 75 | |
|
76 | 76 | private: |
|
77 | 77 | QGraphicsScene *m_scene; |
@@ -91,7 +91,7 private: | |||
|
91 | 91 | QGraphicsLinearLayout *m_baseLayout; |
|
92 | 92 | QMenu *m_menu; |
|
93 | 93 | int m_template; |
|
94 |
Grid* |
|
|
94 | Grid *m_grid; | |
|
95 | 95 | |
|
96 | 96 | friend class ComboBox; |
|
97 | 97 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now