@@ -31,6 +31,8 Grid::Grid(int size,QGraphicsItem *parent):QGraphicsWidget(parent), | |||
|
31 | 31 | m_valueCount(7), |
|
32 | 32 | m_size(size), |
|
33 | 33 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), |
|
34 | m_state(NoState), | |
|
35 | m_currentState(NoState), | |
|
34 | 36 | m_rubberBand(new QGraphicsRectItem()), |
|
35 | 37 | m_gridLayout(new QGraphicsGridLayout()) |
|
36 | 38 | { |
@@ -45,28 +47,6 Grid::~Grid() | |||
|
45 | 47 | |
|
46 | 48 | } |
|
47 | 49 | |
|
48 | void Grid::createCharts() | |
|
49 | { | |
|
50 | clear(); | |
|
51 | ||
|
52 | Charts::ChartList list = Charts::chartList(); | |
|
53 | ||
|
54 | for (int i = 0; i < m_size * m_size; ++i) { | |
|
55 | QChart *chart = 0; | |
|
56 | if (i < list.size()) { | |
|
57 | chart = list.at(i)->createChart(m_dataTable); | |
|
58 | } | |
|
59 | else { | |
|
60 | chart = new QChart(); | |
|
61 | chart->setTitle(QObject::tr("Empty")); | |
|
62 | } | |
|
63 | ||
|
64 | m_gridLayout->addItem(chart, i / m_size, i % m_size); | |
|
65 | m_chartHash[chart] = i; | |
|
66 | } | |
|
67 | ||
|
68 | } | |
|
69 | ||
|
70 | 50 | void Grid::createCharts(const QString& category) |
|
71 | 51 | { |
|
72 | 52 | clear(); |
@@ -74,23 +54,42 void Grid::createCharts(const QString& category) | |||
|
74 | 54 | QChart *qchart(0); |
|
75 | 55 | Charts::ChartList list = Charts::chartList(); |
|
76 | 56 | |
|
77 | int j = 0; | |
|
78 | for (int i = 0; i < list.size(); ++i) { | |
|
79 | Chart *chart = list.at(i); | |
|
80 | if (chart->category() == category && j < m_size * m_size) { | |
|
81 | qchart = list.at(i)->createChart(m_dataTable); | |
|
57 | if (category.isEmpty()) { | |
|
58 | ||
|
59 | for (int i = 0; i < m_size * m_size; ++i) { | |
|
60 | QChart *chart = 0; | |
|
61 | if (i < list.size()) { | |
|
62 | chart = list.at(i)->createChart(m_dataTable); | |
|
63 | } | |
|
64 | else { | |
|
65 | chart = new QChart(); | |
|
66 | chart->setTitle(QObject::tr("Empty")); | |
|
67 | } | |
|
68 | ||
|
69 | m_gridLayout->addItem(chart, i / m_size, i % m_size); | |
|
70 | m_chartHash[chart] = i; | |
|
71 | } | |
|
72 | } | |
|
73 | else { | |
|
74 | ||
|
75 | int j = 0; | |
|
76 | for (int i = 0; i < list.size(); ++i) { | |
|
77 | Chart *chart = list.at(i); | |
|
78 | if (chart->category() == category && j < m_size * m_size) { | |
|
79 | qchart = list.at(i)->createChart(m_dataTable); | |
|
80 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |
|
81 | m_chartHash[qchart] = j; | |
|
82 | j++; | |
|
83 | } | |
|
84 | } | |
|
85 | for (; j < m_size * m_size; ++j) { | |
|
86 | qchart = new QChart(); | |
|
87 | qchart->setTitle(QObject::tr("Empty")); | |
|
82 | 88 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); |
|
83 | 89 | m_chartHash[qchart] = j; |
|
84 | j++; | |
|
85 | 90 | } |
|
86 | 91 | } |
|
87 | for (; j < m_size * m_size; ++j) { | |
|
88 | qchart = new QChart(); | |
|
89 | qchart->setTitle(QObject::tr("Empty")); | |
|
90 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |
|
91 | m_chartHash[qchart] = j; | |
|
92 | } | |
|
93 | ||
|
92 | m_category = category; | |
|
94 | 93 | m_gridLayout->activate(); |
|
95 | 94 | } |
|
96 | 95 | |
@@ -114,6 +113,15 void Grid::setState(State state) | |||
|
114 | 113 | m_state = state; |
|
115 | 114 | } |
|
116 | 115 | |
|
116 | void Grid::setSize(int size) | |
|
117 | { | |
|
118 | if(m_size !=size) | |
|
119 | { | |
|
120 | m_size = size; | |
|
121 | createCharts(m_category); | |
|
122 | } | |
|
123 | } | |
|
124 | ||
|
117 | 125 | void Grid::setRubberPen(const QPen& pen) |
|
118 | 126 | { |
|
119 | 127 | m_rubberBand->setPen(pen); |
@@ -26,7 +26,6 | |||
|
26 | 26 | #include <QChartGlobal> |
|
27 | 27 | |
|
28 | 28 | class QGraphicsGridLayout; |
|
29 | class GridControl; | |
|
30 | 29 | class Chart; |
|
31 | 30 | |
|
32 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
@@ -43,12 +42,13 public: | |||
|
43 | 42 | Grid(int size , QGraphicsItem *parent = 0 ); |
|
44 | 43 | ~Grid(); |
|
45 | 44 | QList<QChart*> charts(); |
|
46 | void createCharts(); | |
|
47 | void createCharts(const QString& category); | |
|
45 | void createCharts(const QString& category = QString()); | |
|
48 | 46 | void replaceChart(QChart* oldChart, Chart* newChart); |
|
49 | 47 | void setState(State state); |
|
50 | State state(){ return m_state; }; | |
|
48 | State state() const { return m_state; }; | |
|
51 | 49 | void setRubberPen(const QPen& pen); |
|
50 | void setSize(int size); | |
|
51 | int size() const {return m_size;} | |
|
52 | 52 | Q_SIGNAL |
|
53 | 53 | void chartSelected(QChart* chart); |
|
54 | 54 | protected: |
@@ -64,12 +64,12 private: | |||
|
64 | 64 | int m_size; |
|
65 | 65 | DataTable m_dataTable; |
|
66 | 66 | QHash<QChart *, int> m_chartHash; |
|
67 | GridControl* m_control; | |
|
68 | 67 | State m_state; |
|
69 | 68 | State m_currentState; |
|
70 | 69 | QPointF m_origin; |
|
71 | 70 | QGraphicsRectItem *m_rubberBand; |
|
72 | 71 | QGraphicsGridLayout* m_gridLayout; |
|
72 | QString m_category; | |
|
73 | 73 | }; |
|
74 | 74 | |
|
75 | 75 | #endif /* GRID_H_ */ |
@@ -39,6 +39,7 | |||
|
39 | 39 | #include <QApplication> |
|
40 | 40 | #include <QDebug> |
|
41 | 41 | #include <QMenu> |
|
42 | #include <QPushButton> | |
|
42 | 43 | |
|
43 | 44 | Window::Window(const QVariantHash& parameters,QWidget *parent) : |
|
44 | 45 | QMainWindow(parent), |
@@ -50,21 +51,25 Window::Window(const QVariantHash& parameters,QWidget *parent) : | |||
|
50 | 51 | m_animatedComboBox(0), |
|
51 | 52 | m_legendComboBox(0), |
|
52 | 53 | m_templateComboBox(0), |
|
54 | m_viewComboBox(0), | |
|
53 | 55 | m_openGLCheckBox(0), |
|
54 | 56 | m_zoomCheckBox(0), |
|
55 | 57 | m_scrollCheckBox(0), |
|
56 | 58 | m_baseLayout(new QGraphicsLinearLayout()), |
|
57 | 59 | m_menu(createMenu()), |
|
58 | 60 | m_template(0), |
|
59 |
m_grid(new Grid( |
|
|
61 | m_grid(new Grid(1)) | |
|
60 | 62 | { |
|
61 | 63 | createProxyWidgets(); |
|
62 | 64 | // create layout |
|
63 | 65 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); |
|
66 | ||
|
64 | 67 | settingsLayout->setOrientation(Qt::Vertical); |
|
65 | 68 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
66 | 69 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); |
|
67 | 70 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); |
|
71 | settingsLayout->addItem(m_widgetHash["viewLabel"]); | |
|
72 | settingsLayout->addItem(m_widgetHash["viewComboBox"]); | |
|
68 | 73 | settingsLayout->addItem(m_widgetHash["themeLabel"]); |
|
69 | 74 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); |
|
70 | 75 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); |
@@ -94,6 +99,7 Window::Window(const QVariantHash& parameters,QWidget *parent) : | |||
|
94 | 99 | m_antialiasCheckBox->setChecked(true); |
|
95 | 100 | initializeFromParamaters(parameters); |
|
96 | 101 | updateUI(); |
|
102 | handleGeometryChanged(); | |
|
97 | 103 | setCentralWidget(m_view); |
|
98 | 104 | |
|
99 | 105 | connectSignals(); |
@@ -106,6 +112,7 Window::~Window() | |||
|
106 | 112 | void Window::connectSignals() |
|
107 | 113 | { |
|
108 | 114 | QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); |
|
115 | QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
|
109 | 116 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
110 | 117 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
111 | 118 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
@@ -120,6 +127,7 void Window::connectSignals() | |||
|
120 | 127 | void Window::createProxyWidgets() |
|
121 | 128 | { |
|
122 | 129 | m_themeComboBox = createThemeBox(); |
|
130 | m_viewComboBox = createViewBox(); | |
|
123 | 131 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); |
|
124 | 132 | m_animatedComboBox = createAnimationBox(); |
|
125 | 133 | m_legendComboBox = createLegendBox(); |
@@ -127,6 +135,8 void Window::createProxyWidgets() | |||
|
127 | 135 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
|
128 | 136 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
|
129 | 137 | m_templateComboBox = createTempleteBox(); |
|
138 | m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); | |
|
139 | m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); | |
|
130 | 140 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
|
131 | 141 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
|
132 | 142 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
@@ -139,7 +149,6 void Window::createProxyWidgets() | |||
|
139 | 149 | m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); |
|
140 | 150 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); |
|
141 | 151 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); |
|
142 | ||
|
143 | 152 | } |
|
144 | 153 | |
|
145 | 154 | QComboBox *Window::createThemeBox() |
@@ -155,6 +164,16 QComboBox *Window::createThemeBox() | |||
|
155 | 164 | return themeComboBox; |
|
156 | 165 | } |
|
157 | 166 | |
|
167 | QComboBox *Window::createViewBox() | |
|
168 | { | |
|
169 | QComboBox *viewComboBox = new ComboBox(this); | |
|
170 | viewComboBox->addItem("1 chart", 1); | |
|
171 | viewComboBox->addItem("4 charts", 2); | |
|
172 | viewComboBox->addItem("9 charts", 3); | |
|
173 | viewComboBox->addItem("16 charts", 4); | |
|
174 | return viewComboBox; | |
|
175 | } | |
|
176 | ||
|
158 | 177 | QComboBox *Window::createAnimationBox() |
|
159 | 178 | { |
|
160 | 179 | QComboBox *animationComboBox = new ComboBox(this); |
@@ -235,11 +254,22 void Window::initializeFromParamaters(const QVariantHash& parameters) | |||
|
235 | 254 | } |
|
236 | 255 | } |
|
237 | 256 | } |
|
257 | if (parameters.contains("view")) { | |
|
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 | ||
|
262 | m_viewComboBox->setCurrentIndex(i); | |
|
263 | break; | |
|
264 | } | |
|
265 | } | |
|
266 | } | |
|
238 | 267 | } |
|
239 | 268 | |
|
240 | 269 | void Window::updateUI() |
|
241 | 270 | { |
|
242 | 271 | checkTemplate(); |
|
272 | checkView(); | |
|
243 | 273 | checkOpenGL(); |
|
244 | 274 | checkTheme(); |
|
245 | 275 | checkAnimationOptions(); |
@@ -247,6 +277,12 void Window::updateUI() | |||
|
247 | 277 | checkState(); |
|
248 | 278 | } |
|
249 | 279 | |
|
280 | void Window::checkView() | |
|
281 | { | |
|
282 | int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); | |
|
283 | m_grid->setSize(count); | |
|
284 | } | |
|
285 | ||
|
250 | 286 | void Window::checkLegend() |
|
251 | 287 | { |
|
252 | 288 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
@@ -33,6 +33,7 class View; | |||
|
33 | 33 | class QGraphicsLinearLayout; |
|
34 | 34 | class Chart; |
|
35 | 35 | class Grid; |
|
36 | class QPushButton; | |
|
36 | 37 | |
|
37 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 39 | class QChart; |
@@ -53,6 +54,7 private Q_SLOTS: | |||
|
53 | 54 | void handleGeometryChanged(); |
|
54 | 55 | void handleChartSelected(QChart *chart); |
|
55 | 56 | private: |
|
57 | QComboBox *createViewBox(); | |
|
56 | 58 | QComboBox *createThemeBox(); |
|
57 | 59 | QComboBox *createAnimationBox(); |
|
58 | 60 | QComboBox *createLegendBox(); |
@@ -61,6 +63,7 private: | |||
|
61 | 63 | void createProxyWidgets(); |
|
62 | 64 | void comboBoxFocused(QComboBox *combox); |
|
63 | 65 | inline void checkAnimationOptions(); |
|
66 | inline void checkView(); | |
|
64 | 67 | inline void checkLegend(); |
|
65 | 68 | inline void checkOpenGL(); |
|
66 | 69 | inline void checkTheme(); |
@@ -70,11 +73,6 private: | |||
|
70 | 73 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); |
|
71 | 74 | void initializeFromParamaters(const QVariantHash& parameters); |
|
72 | 75 | |
|
73 | protected: | |
|
74 | //void mousePressEvent(QMouseEvent *event); | |
|
75 | //void mouseMoveEvent(QMouseEvent *event); | |
|
76 | //void mouseReleaseEvent(QMouseEvent *event); | |
|
77 | ||
|
78 | 76 | private: |
|
79 | 77 | QGraphicsScene *m_scene; |
|
80 | 78 | View *m_view; |
@@ -86,6 +84,7 private: | |||
|
86 | 84 | QComboBox *m_animatedComboBox; |
|
87 | 85 | QComboBox *m_legendComboBox; |
|
88 | 86 | QComboBox *m_templateComboBox; |
|
87 | QComboBox *m_viewComboBox; | |
|
89 | 88 | QCheckBox *m_openGLCheckBox; |
|
90 | 89 | QCheckBox *m_zoomCheckBox; |
|
91 | 90 | QCheckBox *m_scrollCheckBox; |
General Comments 0
You need to be logged in to leave comments.
Login now