| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses |
| 5 |
|
| 6 |
#include "window.h" |
| 7 |
#include "view.h" |
| 8 |
#include "grid.h" |
| 9 |
#include "charts.h" |
| 10 |
#include <QtCharts/QChartView> |
| 11 |
#include <QtCharts/QAreaSeries> |
| 12 |
#include <QtCharts/QLegend> |
| 13 |
#include <QtCharts/QValueAxis> |
| 14 |
#include <QtWidgets/QGridLayout> |
| 15 |
#include <QtWidgets/QFormLayout> |
| 16 |
#include <QtWidgets/QComboBox> |
| 17 |
#include <QtWidgets/QSpinBox> |
| 18 |
#include <QtWidgets/QCheckBox> |
| 19 |
#include <QtWidgets/QGroupBox> |
| 20 |
#include <QtWidgets/QLabel> |
| 21 |
#include <QtWidgets/QGraphicsScene> |
| 22 |
#include <QtWidgets/QGraphicsLinearLayout> |
| 23 |
#include <QtWidgets/QGraphicsProxyWidget> |
| 24 |
#include <QtOpenGLWidgets/QOpenGLWidget> |
| 25 |
#include <QtWidgets/QApplication> |
| 26 |
#include <QtCore/QDebug> |
| 27 |
#include <QtCore/QRegularExpression> |
| 28 |
#include <QtWidgets/QMenu> |
| 29 |
#include <QtWidgets/QPushButton> |
| 30 |
|
| 31 |
Window::Window(const QVariantHash ¶meters, QWidget *parent) |
| 32 |
: QMainWindow(parent), |
| 33 |
m_scene(new QGraphicsScene(this)), |
| 34 |
m_view(0), |
| 35 |
m_form(0), |
| 36 |
m_themeComboBox(0), |
| 37 |
m_antialiasCheckBox(0), |
| 38 |
m_animatedComboBox(0), |
| 39 |
m_legendComboBox(0), |
| 40 |
m_templateComboBox(0), |
| 41 |
m_viewComboBox(0), |
| 42 |
m_xTickSpinBox(0), |
| 43 |
m_yTickSpinBox(0), |
| 44 |
m_minorXTickSpinBox(0), |
| 45 |
m_minorYTickSpinBox(0), |
| 46 |
m_openGLCheckBox(0), |
| 47 |
m_zoomCheckBox(0), |
| 48 |
m_scrollCheckBox(0), |
| 49 |
m_gridCheckBox(0), |
| 50 |
m_baseLayout(new QGraphicsLinearLayout()), |
| 51 |
m_menu(createMenu()), |
| 52 |
m_template(0), |
| 53 |
m_grid(new Grid(-1)) |
| 54 |
{ |
| 55 |
createProxyWidgets(); |
| 56 |
// create layout |
| 57 |
QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); |
| 58 |
|
| 59 |
settingsLayout->setOrientation(Qt::Vertical); |
| 60 |
settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
| 61 |
settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); |
| 62 |
settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); |
| 63 |
settingsLayout->addItem(m_widgetHash["viewLabel"]); |
| 64 |
settingsLayout->addItem(m_widgetHash["viewComboBox"]); |
| 65 |
settingsLayout->addItem(m_widgetHash["themeLabel"]); |
| 66 |
settingsLayout->addItem(m_widgetHash["themeComboBox"]); |
| 67 |
settingsLayout->addItem(m_widgetHash["animationsLabel"]); |
| 68 |
settingsLayout->addItem(m_widgetHash["animatedComboBox"]); |
| 69 |
settingsLayout->addItem(m_widgetHash["legendLabel"]); |
| 70 |
settingsLayout->addItem(m_widgetHash["legendComboBox"]); |
| 71 |
settingsLayout->addItem(m_widgetHash["templateLabel"]); |
| 72 |
settingsLayout->addItem(m_widgetHash["templateComboBox"]); |
| 73 |
settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); |
| 74 |
settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); |
| 75 |
settingsLayout->addItem(m_widgetHash["gridCheckBox"]); |
| 76 |
settingsLayout->addItem(m_widgetHash["xTickLabel"]); |
| 77 |
settingsLayout->addItem(m_widgetHash["xTickSpinBox"]); |
| 78 |
settingsLayout->addItem(m_widgetHash["yTickLabel"]); |
| 79 |
settingsLayout->addItem(m_widgetHash["yTickSpinBox"]); |
| 80 |
settingsLayout->addItem(m_widgetHash["minorXTickLabel"]); |
| 81 |
settingsLayout->addItem(m_widgetHash["minorXTickSpinBox"]); |
| 82 |
settingsLayout->addItem(m_widgetHash["minorYTickLabel"]); |
| 83 |
settingsLayout->addItem(m_widgetHash["minorYTickSpinBox"]); |
| 84 |
settingsLayout->addStretch(); |
| 85 |
|
| 86 |
m_baseLayout->setOrientation(Qt::Horizontal); |
| 87 |
m_baseLayout->addItem(m_grid); |
| 88 |
m_baseLayout->addItem(settingsLayout); |
| 89 |
|
| 90 |
m_form = new QGraphicsWidget(); |
| 91 |
m_form->setLayout(m_baseLayout); |
| 92 |
m_scene->addItem(m_form); |
| 93 |
|
| 94 |
m_view = new View(m_scene, m_form); |
| 95 |
m_view->setMinimumSize(m_form->minimumSize().toSize()); |
| 96 |
|
| 97 |
// Set defaults |
| 98 |
m_antialiasCheckBox->setChecked(true); |
| 99 |
initializeFromParamaters(parameters); |
| 100 |
updateUI(); |
| 101 |
if(!m_category.isEmpty() && !m_subcategory.isEmpty() && !m_name.isEmpty()) |
| 102 |
m_grid->createCharts(m_category,m_subcategory,m_name); |
| 103 |
|
| 104 |
|
| 105 |
handleGeometryChanged(); |
| 106 |
setCentralWidget(m_view); |
| 107 |
|
| 108 |
connectSignals(); |
| 109 |
} |
| 110 |
|
| 111 |
Window::~Window() |
| 112 |
{ |
| 113 |
} |
| 114 |
|
| 115 |
void Window::connectSignals() |
| 116 |
{ |
| 117 |
QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); |
| 118 |
QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
| 119 |
QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
| 120 |
QObject::connect(m_xTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); |
| 121 |
QObject::connect(m_yTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); |
| 122 |
QObject::connect(m_minorXTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); |
| 123 |
QObject::connect(m_minorYTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); |
| 124 |
QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
| 125 |
QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
| 126 |
QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
| 127 |
QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
| 128 |
QObject::connect(m_gridCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
| 129 |
QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
| 130 |
QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
| 131 |
QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
| 132 |
QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*))); |
| 133 |
} |
| 134 |
|
| 135 |
void Window::createProxyWidgets() |
| 136 |
{ |
| 137 |
m_themeComboBox = createThemeBox(); |
| 138 |
m_viewComboBox = createViewBox(); |
| 139 |
m_xTickSpinBox = new QSpinBox(); |
| 140 |
m_xTickSpinBox->setMinimum(2); |
| 141 |
m_xTickSpinBox->setValue(5); |
| 142 |
m_yTickSpinBox = new QSpinBox(); |
| 143 |
m_yTickSpinBox->setMinimum(2); |
| 144 |
m_yTickSpinBox->setValue(5); |
| 145 |
m_minorXTickSpinBox = new QSpinBox(); |
| 146 |
m_minorYTickSpinBox = new QSpinBox(); |
| 147 |
m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); |
| 148 |
m_animatedComboBox = createAnimationBox(); |
| 149 |
m_legendComboBox = createLegendBox(); |
| 150 |
m_openGLCheckBox = new QCheckBox(tr("OpenGL")); |
| 151 |
m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
| 152 |
m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
| 153 |
m_gridCheckBox = new QCheckBox(tr("Grid lines")); |
| 154 |
m_templateComboBox = createTempleteBox(); |
| 155 |
m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); |
| 156 |
m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); |
| 157 |
m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
| 158 |
m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
| 159 |
m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
| 160 |
m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); |
| 161 |
m_widgetHash["xTickLabel"] = m_scene->addWidget(new QLabel("X Tick")); |
| 162 |
m_widgetHash["xTickSpinBox"] = m_scene->addWidget(m_xTickSpinBox); |
| 163 |
m_widgetHash["yTickLabel"] = m_scene->addWidget(new QLabel("Y Tick")); |
| 164 |
m_widgetHash["yTickSpinBox"] = m_scene->addWidget(m_yTickSpinBox); |
| 165 |
m_widgetHash["minorXTickLabel"] = m_scene->addWidget(new QLabel("Minor X Tick")); |
| 166 |
m_widgetHash["minorXTickSpinBox"] = m_scene->addWidget(m_minorXTickSpinBox); |
| 167 |
m_widgetHash["minorYTickLabel"] = m_scene->addWidget(new QLabel("Minor Y Tick")); |
| 168 |
m_widgetHash["minorYTickSpinBox"] = m_scene->addWidget(m_minorYTickSpinBox); |
| 169 |
m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); |
| 170 |
m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); |
| 171 |
m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); |
| 172 |
m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); |
| 173 |
m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); |
| 174 |
m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); |
| 175 |
m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); |
| 176 |
m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); |
| 177 |
m_widgetHash["gridCheckBox"] = m_scene->addWidget(m_gridCheckBox); |
| 178 |
} |
| 179 |
|
| 180 |
QComboBox *Window::createThemeBox() |
| 181 |
{ |
| 182 |
QComboBox *themeComboBox = new ComboBox(this); |
| 183 |
themeComboBox->addItem("Light", QChart::ChartThemeLight); |
| 184 |
themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
| 185 |
themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
| 186 |
themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
| 187 |
themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
| 188 |
themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
| 189 |
themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
| 190 |
themeComboBox->addItem("Qt", QChart::ChartThemeQt); |
| 191 |
return themeComboBox; |
| 192 |
} |
| 193 |
|
| 194 |
QComboBox *Window::createViewBox() |
| 195 |
{ |
| 196 |
QComboBox *viewComboBox = new ComboBox(this); |
| 197 |
viewComboBox->addItem("1 chart", 1); |
| 198 |
viewComboBox->addItem("4 charts", 2); |
| 199 |
viewComboBox->addItem("9 charts", 3); |
| 200 |
viewComboBox->addItem("16 charts", 4); |
| 201 |
return viewComboBox; |
| 202 |
} |
| 203 |
|
| 204 |
QComboBox *Window::createAnimationBox() |
| 205 |
{ |
| 206 |
QComboBox *animationComboBox = new ComboBox(this); |
| 207 |
animationComboBox->addItem("No Animations", QChart::NoAnimation); |
| 208 |
animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
| 209 |
animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
| 210 |
animationComboBox->addItem("All Animations", QChart::AllAnimations); |
| 211 |
return animationComboBox; |
| 212 |
} |
| 213 |
|
| 214 |
QComboBox *Window::createLegendBox() |
| 215 |
{ |
| 216 |
QComboBox *legendComboBox = new ComboBox(this); |
| 217 |
legendComboBox->addItem("No Legend ", 0); |
| 218 |
legendComboBox->addItem("Legend Top", Qt::AlignTop); |
| 219 |
legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
| 220 |
legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
| 221 |
legendComboBox->addItem("Legend Right", Qt::AlignRight); |
| 222 |
return legendComboBox; |
| 223 |
} |
| 224 |
|
| 225 |
QComboBox *Window::createTempleteBox() |
| 226 |
{ |
| 227 |
QComboBox *templateComboBox = new ComboBox(this); |
| 228 |
templateComboBox->addItem("No Template", 0); |
| 229 |
|
| 230 |
Charts::ChartList list = Charts::chartList(); |
| 231 |
QMultiMap<QString, Chart *> categoryMap; |
| 232 |
|
| 233 |
foreach (Chart *chart, list) |
| 234 |
categoryMap.insert(chart->category(), chart); |
| 235 |
|
| 236 |
foreach (const QString &category, categoryMap.uniqueKeys()) |
| 237 |
templateComboBox->addItem(category, category); |
| 238 |
|
| 239 |
return templateComboBox; |
| 240 |
} |
| 241 |
|
| 242 |
void Window::initializeFromParamaters(const QVariantHash ¶meters) |
| 243 |
{ |
| 244 |
if (parameters.contains("view")) { |
| 245 |
int t = parameters["view"].toInt(); |
| 246 |
for (int i = 0; i < m_viewComboBox->count(); ++i) { |
| 247 |
if (m_viewComboBox->itemData(i).toInt() == t) { |
| 248 |
m_viewComboBox->setCurrentIndex(i); |
| 249 |
break; |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
if (parameters.contains("chart")) { |
| 255 |
QString t = parameters["chart"].toString(); |
| 256 |
|
| 257 |
QRegularExpression rx("([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)"); |
| 258 |
QRegularExpressionMatch rmatch; |
| 259 |
int pos = t.indexOf(rx, 0, &rmatch); |
| 260 |
|
| 261 |
if (pos > -1) { |
| 262 |
m_category = rmatch.captured(1); |
| 263 |
m_subcategory = rmatch.captured(2); |
| 264 |
m_name = rmatch.captured(3); |
| 265 |
m_templateComboBox->setCurrentIndex(0); |
| 266 |
} |
| 267 |
else { |
| 268 |
for (int i = 0; i < m_templateComboBox->count(); ++i) { |
| 269 |
if (m_templateComboBox->itemText(i) == t) { |
| 270 |
m_templateComboBox->setCurrentIndex(i); |
| 271 |
break; |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
if (parameters.contains("opengl")) { |
| 277 |
bool checked = parameters["opengl"].toBool(); |
| 278 |
m_openGLCheckBox->setChecked(checked); |
| 279 |
} |
| 280 |
if (parameters.contains("theme")) { |
| 281 |
QString t = parameters["theme"].toString(); |
| 282 |
for (int i = 0; i < m_themeComboBox->count(); ++i) { |
| 283 |
if (m_themeComboBox->itemText(i) == t) { |
| 284 |
m_themeComboBox->setCurrentIndex(i); |
| 285 |
break; |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
if (parameters.contains("animation")) { |
| 290 |
QString t = parameters["animation"].toString(); |
| 291 |
for (int i = 0; i < m_animatedComboBox->count(); ++i) { |
| 292 |
if (m_animatedComboBox->itemText(i) == t) { |
| 293 |
m_animatedComboBox->setCurrentIndex(i); |
| 294 |
break; |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
if (parameters.contains("legend")) { |
| 299 |
QString t = parameters["legend"].toString(); |
| 300 |
for (int i = 0; i < m_legendComboBox->count(); ++i) { |
| 301 |
if (m_legendComboBox->itemText(i) == t) { |
| 302 |
m_legendComboBox->setCurrentIndex(i); |
| 303 |
break; |
| 304 |
} |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
void Window::updateUI() |
| 310 |
{ |
| 311 |
checkView(); |
| 312 |
checkTemplate(); |
| 313 |
checkOpenGL(); |
| 314 |
checkTheme(); |
| 315 |
checkAnimationOptions(); |
| 316 |
checkLegend(); |
| 317 |
checkState(); |
| 318 |
checkXTick(); |
| 319 |
checkYTick(); |
| 320 |
checkMinorXTick(); |
| 321 |
checkMinorYTick(); |
| 322 |
} |
| 323 |
|
| 324 |
void Window::checkView() |
| 325 |
{ |
| 326 |
int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); |
| 327 |
if(m_grid->size()!=count){ |
| 328 |
m_grid->setSize(count); |
| 329 |
m_template = 0; |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
void Window::checkXTick() |
| 334 |
{ |
| 335 |
foreach (QChart *chart, m_grid->charts()) { |
| 336 |
if (qobject_cast<QValueAxis *>(chart->axisX())) { |
| 337 |
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisX()); |
| 338 |
valueAxis->setGridLineVisible(m_gridCheckBox->isChecked()); |
| 339 |
valueAxis->setTickCount(m_xTickSpinBox->value()); |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
void Window::checkYTick() |
| 345 |
{ |
| 346 |
foreach (QChart *chart, m_grid->charts()) { |
| 347 |
if (qobject_cast<QValueAxis *>(chart->axisY())) { |
| 348 |
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisY()); |
| 349 |
valueAxis->setGridLineVisible(m_gridCheckBox->isChecked()); |
| 350 |
valueAxis->setTickCount(m_yTickSpinBox->value()); |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
void Window::checkMinorXTick() |
| 356 |
{ |
| 357 |
foreach (QChart *chart, m_grid->charts()) { |
| 358 |
if (qobject_cast<QValueAxis *>(chart->axisX())) { |
| 359 |
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisX()); |
| 360 |
valueAxis->setMinorGridLineVisible(m_gridCheckBox->isChecked()); |
| 361 |
valueAxis->setGridLineVisible(m_gridCheckBox->isChecked()); |
| 362 |
valueAxis->setMinorTickCount(m_minorXTickSpinBox->value()); |
| 363 |
} |
| 364 |
} |
| 365 |
} |
| 366 |
|
| 367 |
void Window::checkMinorYTick() |
| 368 |
{ |
| 369 |
foreach (QChart *chart, m_grid->charts()) { |
| 370 |
if (qobject_cast<QValueAxis *>(chart->axisY())) { |
| 371 |
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisY()); |
| 372 |
valueAxis->setMinorGridLineVisible(m_gridCheckBox->isChecked()); |
| 373 |
valueAxis->setGridLineVisible(m_gridCheckBox->isChecked()); |
| 374 |
valueAxis->setMinorTickCount(m_minorYTickSpinBox->value()); |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
void Window::checkLegend() |
| 380 |
{ |
| 381 |
Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
| 382 |
|
| 383 |
if (!alignment) { |
| 384 |
foreach (QChart *chart, m_grid->charts()) |
| 385 |
chart->legend()->hide(); |
| 386 |
} else { |
| 387 |
foreach (QChart *chart, m_grid->charts()) { |
| 388 |
chart->legend()->setAlignment(alignment); |
| 389 |
chart->legend()->show(); |
| 390 |
} |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
void Window::checkOpenGL() |
| 395 |
{ |
| 396 |
bool opengl = m_openGLCheckBox->isChecked(); |
| 397 |
bool isOpengl = qobject_cast<QOpenGLWidget *>(m_view->viewport()); |
| 398 |
if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
| 399 |
m_view->deleteLater(); |
| 400 |
m_view = new View(m_scene, m_form); |
| 401 |
m_view->setViewport(!opengl ? new QWidget() : new QOpenGLWidget()); |
| 402 |
setCentralWidget(m_view); |
| 403 |
} |
| 404 |
|
| 405 |
bool antialias = m_antialiasCheckBox->isChecked(); |
| 406 |
|
| 407 |
m_view->setRenderHint(QPainter::Antialiasing, antialias); |
| 408 |
} |
| 409 |
|
| 410 |
void Window::checkAnimationOptions() |
| 411 |
{ |
| 412 |
QChart::AnimationOptions options( |
| 413 |
m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
| 414 |
|
| 415 |
QList<QChart *> charts = m_grid->charts(); |
| 416 |
|
| 417 |
if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { |
| 418 |
foreach (QChart *chart, charts) |
| 419 |
chart->setAnimationOptions(options); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
void Window::checkState() |
| 424 |
{ |
| 425 |
bool scroll = m_scrollCheckBox->isChecked(); |
| 426 |
|
| 427 |
|
| 428 |
if (m_grid->state() != Grid::ScrollState && scroll) { |
| 429 |
m_grid->setState(Grid::ScrollState); |
| 430 |
m_zoomCheckBox->setChecked(false); |
| 431 |
} else if (!scroll && m_grid->state() == Grid::ScrollState) { |
| 432 |
m_grid->setState(Grid::NoState); |
| 433 |
} |
| 434 |
|
| 435 |
bool zoom = m_zoomCheckBox->isChecked(); |
| 436 |
|
| 437 |
if (m_grid->state() != Grid::ZoomState && zoom) { |
| 438 |
m_grid->setState(Grid::ZoomState); |
| 439 |
m_scrollCheckBox->setChecked(false); |
| 440 |
} else if (!zoom && m_grid->state() == Grid::ZoomState) { |
| 441 |
m_grid->setState(Grid::NoState); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
void Window::checkTemplate() |
| 446 |
{ |
| 447 |
int index = m_templateComboBox->currentIndex(); |
| 448 |
if (m_template == index || index == 0) |
| 449 |
return; |
| 450 |
|
| 451 |
m_template = index; |
| 452 |
QString category = m_templateComboBox->itemData(index).toString(); |
| 453 |
m_grid->createCharts(category); |
| 454 |
} |
| 455 |
|
| 456 |
void Window::checkTheme() |
| 457 |
{ |
| 458 |
QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
| 459 |
m_themeComboBox->currentIndex()).toInt(); |
| 460 |
|
| 461 |
foreach (QChart *chart, m_grid->charts()) |
| 462 |
chart->setTheme(theme); |
| 463 |
|
| 464 |
QPalette pal = window()->palette(); |
| 465 |
if (theme == QChart::ChartThemeLight) { |
| 466 |
pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
| 467 |
pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
| 468 |
} else if (theme == QChart::ChartThemeDark) { |
| 469 |
pal.setColor(QPalette::Window, QRgb(0x121218)); |
| 470 |
pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
| 471 |
} else if (theme == QChart::ChartThemeBlueCerulean) { |
| 472 |
pal.setColor(QPalette::Window, QRgb(0x40434a)); |
| 473 |
pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
| 474 |
} else if (theme == QChart::ChartThemeBrownSand) { |
| 475 |
pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
| 476 |
pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
| 477 |
} else if (theme == QChart::ChartThemeBlueNcs) { |
| 478 |
pal.setColor(QPalette::Window, QRgb(0x018bba)); |
| 479 |
pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
| 480 |
} else if (theme == QChart::ChartThemeHighContrast) { |
| 481 |
pal.setColor(QPalette::Window, QRgb(0xffab03)); |
| 482 |
pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
| 483 |
} else if (theme == QChart::ChartThemeBlueIcy) { |
| 484 |
pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
| 485 |
pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
| 486 |
} else if (theme == QChart::ChartThemeQt) { |
| 487 |
pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
| 488 |
pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
| 489 |
} else { |
| 490 |
pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
| 491 |
pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
| 492 |
} |
| 493 |
foreach (QGraphicsProxyWidget *widget, m_widgetHash) |
| 494 |
widget->setPalette(pal); |
| 495 |
m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
| 496 |
m_grid->setRubberPen(pal.color((QPalette::WindowText))); |
| 497 |
} |
| 498 |
|
| 499 |
void Window::comboBoxFocused(QComboBox *combobox) |
| 500 |
{ |
| 501 |
foreach (QGraphicsProxyWidget *widget , m_widgetHash) { |
| 502 |
if (widget->widget() == combobox) |
| 503 |
widget->setZValue(2.0); |
| 504 |
else |
| 505 |
widget->setZValue(0.0); |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
void Window::handleChartSelected(QChart *qchart) |
| 510 |
{ |
| 511 |
if (m_templateComboBox->currentIndex() != 0) |
| 512 |
return; |
| 513 |
|
| 514 |
QAction *chosen = m_menu->exec(QCursor::pos()); |
| 515 |
|
| 516 |
if (chosen) { |
| 517 |
Chart *chart = (Chart *) chosen->data().value<void *>(); |
| 518 |
m_grid->replaceChart(qchart, chart); |
| 519 |
updateUI(); |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
QMenu *Window::createMenu() |
| 524 |
{ |
| 525 |
Charts::ChartList list = Charts::chartList(); |
| 526 |
QMultiMap<QString, Chart *> categoryMap; |
| 527 |
|
| 528 |
QMenu *result = new QMenu(this); |
| 529 |
|
| 530 |
foreach (Chart *chart, list) |
| 531 |
categoryMap.insert(chart->category(), chart); |
| 532 |
|
| 533 |
foreach (const QString &category, categoryMap.uniqueKeys()) { |
| 534 |
QMenu *menu(0); |
| 535 |
QMultiMap<QString, Chart *> subCategoryMap; |
| 536 |
if (category.isEmpty()) { |
| 537 |
menu = result; |
| 538 |
} else { |
| 539 |
menu = new QMenu(category, this); |
| 540 |
result->addMenu(menu); |
| 541 |
} |
| 542 |
|
| 543 |
foreach (Chart *chart, categoryMap.values(category)) |
| 544 |
subCategoryMap.insert(chart->subCategory(), chart); |
| 545 |
|
| 546 |
foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { |
| 547 |
QMenu *subMenu(0); |
| 548 |
if (subCategory.isEmpty()) { |
| 549 |
subMenu = menu; |
| 550 |
} else { |
| 551 |
subMenu = new QMenu(subCategory, this); |
| 552 |
menu->addMenu(subMenu); |
| 553 |
} |
| 554 |
|
| 555 |
foreach (Chart *chart, subCategoryMap.values(subCategory)) { |
| 556 |
createMenuAction(subMenu, QIcon(), chart->name(), |
| 557 |
QVariant::fromValue(static_cast<void *>(chart))); |
| 558 |
} |
| 559 |
} |
| 560 |
} |
| 561 |
return result; |
| 562 |
} |
| 563 |
|
| 564 |
QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, |
| 565 |
const QVariant &data) |
| 566 |
{ |
| 567 |
QAction *action = menu->addAction(icon, text); |
| 568 |
action->setCheckable(false); |
| 569 |
action->setData(data); |
| 570 |
return action; |
| 571 |
} |
| 572 |
|
| 573 |
void Window::handleGeometryChanged() |
| 574 |
{ |
| 575 |
QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); |
| 576 |
m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); |
| 577 |
m_view->setMinimumSize(size.toSize()); |
| 578 |
} |