window.cpp
585 lines
| 20.8 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r1746 | /**************************************************************************** | ||
** | ||||
Titta Heikkala
|
r2776 | ** Copyright (C) 2015 The Qt Company Ltd | ||
Michal Klocek
|
r1746 | ** All rights reserved. | ||
Titta Heikkala
|
r2776 | ** For any questions to The Qt Company, please use contact form at http://qt.io | ||
Michal Klocek
|
r1746 | ** | ||
Titta Heikkala
|
r2740 | ** This file is part of the Qt Charts module. | ||
Michal Klocek
|
r1746 | ** | ||
Titta Heikkala
|
r2740 | ** Licensees holding valid commercial license for Qt may use this file in | ||
** accordance with the Qt License Agreement provided with the Software | ||||
** or, alternatively, in accordance with the terms contained in a written | ||||
Titta Heikkala
|
r2776 | ** agreement between you and The Qt Company. | ||
Michal Klocek
|
r1746 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
Titta Heikkala
|
r2740 | ** contact form at http://qt.io | ||
Michal Klocek
|
r1746 | ** | ||
****************************************************************************/ | ||||
Michal Klocek
|
r1748 | #include "window.h" | ||
#include "view.h" | ||||
Michal Klocek
|
r2127 | #include "grid.h" | ||
Michal Klocek
|
r1753 | #include "charts.h" | ||
Titta Heikkala
|
r2714 | #include <QtCharts/QChartView> | ||
#include <QtCharts/QAreaSeries> | ||||
#include <QtCharts/QLegend> | ||||
Titta Heikkala
|
r2795 | #include <QtCharts/QValueAxis> | ||
Titta Heikkala
|
r2714 | #include <QtWidgets/QGridLayout> | ||
#include <QtWidgets/QFormLayout> | ||||
#include <QtWidgets/QComboBox> | ||||
#include <QtWidgets/QSpinBox> | ||||
#include <QtWidgets/QCheckBox> | ||||
#include <QtWidgets/QGroupBox> | ||||
#include <QtWidgets/QLabel> | ||||
#include <QtWidgets/QGraphicsScene> | ||||
#include <QtWidgets/QGraphicsLinearLayout> | ||||
#include <QtWidgets/QGraphicsProxyWidget> | ||||
Miikka Heikkinen
|
r2828 | #include <QtWidgets/QOpenGLWidget> | ||
Titta Heikkala
|
r2714 | #include <QtWidgets/QApplication> | ||
#include <QtCore/QDebug> | ||||
#include <QtWidgets/QMenu> | ||||
#include <QtWidgets/QPushButton> | ||||
Michal Klocek
|
r1746 | |||
Jani Honkonen
|
r2130 | Window::Window(const QVariantHash ¶meters, QWidget *parent) | ||
: QMainWindow(parent), | ||||
m_scene(new QGraphicsScene(this)), | ||||
m_view(0), | ||||
m_form(0), | ||||
m_themeComboBox(0), | ||||
m_antialiasCheckBox(0), | ||||
m_animatedComboBox(0), | ||||
m_legendComboBox(0), | ||||
m_templateComboBox(0), | ||||
m_viewComboBox(0), | ||||
Titta Heikkala
|
r2795 | m_xTickSpinBox(0), | ||
m_yTickSpinBox(0), | ||||
m_minorXTickSpinBox(0), | ||||
m_minorYTickSpinBox(0), | ||||
Jani Honkonen
|
r2130 | m_openGLCheckBox(0), | ||
m_zoomCheckBox(0), | ||||
m_scrollCheckBox(0), | ||||
m_baseLayout(new QGraphicsLinearLayout()), | ||||
m_menu(createMenu()), | ||||
m_template(0), | ||||
Michal Klocek
|
r2135 | m_grid(new Grid(-1)) | ||
Michal Klocek
|
r1746 | { | ||
createProxyWidgets(); | ||||
// create layout | ||||
QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); | ||||
Michal Klocek
|
r2128 | |||
Michal Klocek
|
r1746 | settingsLayout->setOrientation(Qt::Vertical); | ||
settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | ||||
settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); | ||||
settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); | ||||
Michal Klocek
|
r2128 | settingsLayout->addItem(m_widgetHash["viewLabel"]); | ||
settingsLayout->addItem(m_widgetHash["viewComboBox"]); | ||||
Michal Klocek
|
r1746 | settingsLayout->addItem(m_widgetHash["themeLabel"]); | ||
settingsLayout->addItem(m_widgetHash["themeComboBox"]); | ||||
settingsLayout->addItem(m_widgetHash["animationsLabel"]); | ||||
settingsLayout->addItem(m_widgetHash["animatedComboBox"]); | ||||
settingsLayout->addItem(m_widgetHash["legendLabel"]); | ||||
settingsLayout->addItem(m_widgetHash["legendComboBox"]); | ||||
Michal Klocek
|
r1864 | settingsLayout->addItem(m_widgetHash["templateLabel"]); | ||
settingsLayout->addItem(m_widgetHash["templateComboBox"]); | ||||
Michal Klocek
|
r1748 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); | ||
settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); | ||||
Titta Heikkala
|
r2795 | settingsLayout->addItem(m_widgetHash["xTickLabel"]); | ||
settingsLayout->addItem(m_widgetHash["xTickSpinBox"]); | ||||
settingsLayout->addItem(m_widgetHash["yTickLabel"]); | ||||
settingsLayout->addItem(m_widgetHash["yTickSpinBox"]); | ||||
settingsLayout->addItem(m_widgetHash["minorXTickLabel"]); | ||||
settingsLayout->addItem(m_widgetHash["minorXTickSpinBox"]); | ||||
settingsLayout->addItem(m_widgetHash["minorYTickLabel"]); | ||||
settingsLayout->addItem(m_widgetHash["minorYTickSpinBox"]); | ||||
Michal Klocek
|
r1746 | settingsLayout->addStretch(); | ||
Michal Klocek
|
r1840 | |||
Michal Klocek
|
r2127 | m_baseLayout->setOrientation(Qt::Horizontal); | ||
m_baseLayout->addItem(m_grid); | ||||
m_baseLayout->addItem(settingsLayout); | ||||
Michal Klocek
|
r1840 | |||
Michal Klocek
|
r1746 | m_form = new QGraphicsWidget(); | ||
Michal Klocek
|
r1840 | m_form->setLayout(m_baseLayout); | ||
Michal Klocek
|
r1746 | m_scene->addItem(m_form); | ||
Michal Klocek
|
r1748 | m_view = new View(m_scene, m_form); | ||
Michal Klocek
|
r1964 | m_view->setMinimumSize(m_form->minimumSize().toSize()); | ||
Michal Klocek
|
r1746 | |||
Michal Klocek
|
r1748 | // Set defaults | ||
m_antialiasCheckBox->setChecked(true); | ||||
Michal Klocek
|
r2119 | initializeFromParamaters(parameters); | ||
Michal Klocek
|
r1746 | updateUI(); | ||
Michal Klocek
|
r2135 | if(!m_category.isEmpty() && !m_subcategory.isEmpty() && !m_name.isEmpty()) | ||
m_grid->createCharts(m_category,m_subcategory,m_name); | ||||
Michal Klocek
|
r2128 | handleGeometryChanged(); | ||
Michal Klocek
|
r1746 | setCentralWidget(m_view); | ||
Michal Klocek
|
r1964 | |||
connectSignals(); | ||||
Michal Klocek
|
r1746 | } | ||
Michal Klocek
|
r1748 | Window::~Window() | ||
Michal Klocek
|
r1746 | { | ||
} | ||||
Michal Klocek
|
r1748 | void Window::connectSignals() | ||
Michal Klocek
|
r1746 | { | ||
Jani Honkonen
|
r2099 | QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); | ||
Michal Klocek
|
r2128 | QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | ||
Michal Klocek
|
r1754 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | ||
Titta Heikkala
|
r2795 | QObject::connect(m_xTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); | ||
QObject::connect(m_yTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); | ||||
QObject::connect(m_minorXTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); | ||||
QObject::connect(m_minorYTickSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateUI())); | ||||
Michal Klocek
|
r1754 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | ||
QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | ||||
QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | ||||
QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | ||||
QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | ||||
QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | ||||
Michal Klocek
|
r1864 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | ||
Jani Honkonen
|
r2130 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*))); | ||
Michal Klocek
|
r1746 | } | ||
Michal Klocek
|
r1748 | void Window::createProxyWidgets() | ||
Michal Klocek
|
r1746 | { | ||
m_themeComboBox = createThemeBox(); | ||||
Michal Klocek
|
r2128 | m_viewComboBox = createViewBox(); | ||
Titta Heikkala
|
r2795 | m_xTickSpinBox = new QSpinBox(); | ||
m_xTickSpinBox->setMinimum(2); | ||||
m_xTickSpinBox->setValue(5); | ||||
m_yTickSpinBox = new QSpinBox(); | ||||
m_yTickSpinBox->setMinimum(2); | ||||
m_yTickSpinBox->setValue(5); | ||||
m_minorXTickSpinBox = new QSpinBox(); | ||||
m_minorYTickSpinBox = new QSpinBox(); | ||||
Michal Klocek
|
r1746 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); | ||
m_animatedComboBox = createAnimationBox(); | ||||
m_legendComboBox = createLegendBox(); | ||||
m_openGLCheckBox = new QCheckBox(tr("OpenGL")); | ||||
Michal Klocek
|
r1748 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); | ||
m_scrollCheckBox = new QCheckBox(tr("Scroll")); | ||||
Jani Honkonen
|
r2099 | m_templateComboBox = createTempleteBox(); | ||
Michal Klocek
|
r2128 | m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); | ||
m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); | ||||
Michal Klocek
|
r1746 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); | ||
m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); | ||||
m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); | ||||
m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); | ||||
Titta Heikkala
|
r2795 | m_widgetHash["xTickLabel"] = m_scene->addWidget(new QLabel("X Tick")); | ||
m_widgetHash["xTickSpinBox"] = m_scene->addWidget(m_xTickSpinBox); | ||||
m_widgetHash["yTickLabel"] = m_scene->addWidget(new QLabel("Y Tick")); | ||||
m_widgetHash["yTickSpinBox"] = m_scene->addWidget(m_yTickSpinBox); | ||||
m_widgetHash["minorXTickLabel"] = m_scene->addWidget(new QLabel("Minor X Tick")); | ||||
m_widgetHash["minorXTickSpinBox"] = m_scene->addWidget(m_minorXTickSpinBox); | ||||
m_widgetHash["minorYTickLabel"] = m_scene->addWidget(new QLabel("Minor Y Tick")); | ||||
m_widgetHash["minorYTickSpinBox"] = m_scene->addWidget(m_minorYTickSpinBox); | ||||
Michal Klocek
|
r1746 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); | ||
m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); | ||||
m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); | ||||
m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); | ||||
Michal Klocek
|
r1864 | m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); | ||
m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); | ||||
Michal Klocek
|
r1748 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); | ||
m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); | ||||
Michal Klocek
|
r1746 | } | ||
Jani Honkonen
|
r2099 | QComboBox *Window::createThemeBox() | ||
Michal Klocek
|
r1746 | { | ||
Jani Honkonen
|
r2099 | QComboBox *themeComboBox = new ComboBox(this); | ||
Michal Klocek
|
r1746 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | ||
themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | ||||
themeComboBox->addItem("Dark", QChart::ChartThemeDark); | ||||
themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | ||||
themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | ||||
themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | ||||
themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | ||||
Titta Heikkala
|
r2625 | themeComboBox->addItem("Qt", QChart::ChartThemeQt); | ||
Michal Klocek
|
r1746 | return themeComboBox; | ||
} | ||||
Michal Klocek
|
r2128 | QComboBox *Window::createViewBox() | ||
{ | ||||
QComboBox *viewComboBox = new ComboBox(this); | ||||
viewComboBox->addItem("1 chart", 1); | ||||
viewComboBox->addItem("4 charts", 2); | ||||
viewComboBox->addItem("9 charts", 3); | ||||
viewComboBox->addItem("16 charts", 4); | ||||
return viewComboBox; | ||||
} | ||||
Jani Honkonen
|
r2099 | QComboBox *Window::createAnimationBox() | ||
Michal Klocek
|
r1746 | { | ||
Jani Honkonen
|
r2099 | QComboBox *animationComboBox = new ComboBox(this); | ||
Michal Klocek
|
r1746 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | ||
animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | ||||
animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | ||||
animationComboBox->addItem("All Animations", QChart::AllAnimations); | ||||
return animationComboBox; | ||||
} | ||||
Jani Honkonen
|
r2099 | QComboBox *Window::createLegendBox() | ||
Michal Klocek
|
r1746 | { | ||
Jani Honkonen
|
r2099 | QComboBox *legendComboBox = new ComboBox(this); | ||
Michal Klocek
|
r1746 | legendComboBox->addItem("No Legend ", 0); | ||
legendComboBox->addItem("Legend Top", Qt::AlignTop); | ||||
legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | ||||
legendComboBox->addItem("Legend Left", Qt::AlignLeft); | ||||
legendComboBox->addItem("Legend Right", Qt::AlignRight); | ||||
return legendComboBox; | ||||
} | ||||
Jani Honkonen
|
r2099 | QComboBox *Window::createTempleteBox() | ||
Michal Klocek
|
r1864 | { | ||
Jani Honkonen
|
r2099 | QComboBox *templateComboBox = new ComboBox(this); | ||
Michal Klocek
|
r1864 | templateComboBox->addItem("No Template", 0); | ||
Charts::ChartList list = Charts::chartList(); | ||||
Jani Honkonen
|
r2099 | QMultiMap<QString, Chart *> categoryMap; | ||
Michal Klocek
|
r1864 | |||
Jani Honkonen
|
r2099 | foreach (Chart *chart, list) | ||
categoryMap.insertMulti(chart->category(), chart); | ||||
foreach (const QString &category, categoryMap.uniqueKeys()) | ||||
Michal Klocek
|
r1864 | templateComboBox->addItem(category, category); | ||
Jani Honkonen
|
r2099 | |||
Michal Klocek
|
r1864 | return templateComboBox; | ||
} | ||||
Jani Honkonen
|
r2130 | void Window::initializeFromParamaters(const QVariantHash ¶meters) | ||
Michal Klocek
|
r2119 | { | ||
Michal Klocek
|
r2135 | if (parameters.contains("view")) { | ||
int t = parameters["view"].toInt(); | ||||
for (int i = 0; i < m_viewComboBox->count(); ++i) { | ||||
if (m_viewComboBox->itemData(i).toInt() == t) { | ||||
m_viewComboBox->setCurrentIndex(i); | ||||
break; | ||||
} | ||||
} | ||||
} | ||||
Michal Klocek
|
r2134 | if (parameters.contains("chart")) { | ||
QString t = parameters["chart"].toString(); | ||||
Michal Klocek
|
r2135 | |||
QRegExp rx("([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)"); | ||||
int pos = rx.indexIn(t); | ||||
if (pos > -1) { | ||||
m_category = rx.cap(1); | ||||
m_subcategory = rx.cap(2); | ||||
m_name = rx.cap(3); | ||||
m_templateComboBox->setCurrentIndex(0); | ||||
} | ||||
else { | ||||
for (int i = 0; i < m_templateComboBox->count(); ++i) { | ||||
if (m_templateComboBox->itemText(i) == t) { | ||||
m_templateComboBox->setCurrentIndex(i); | ||||
break; | ||||
} | ||||
Michal Klocek
|
r2119 | } | ||
} | ||||
} | ||||
if (parameters.contains("opengl")) { | ||||
bool checked = parameters["opengl"].toBool(); | ||||
m_openGLCheckBox->setChecked(checked); | ||||
} | ||||
if (parameters.contains("theme")) { | ||||
QString t = parameters["theme"].toString(); | ||||
for (int i = 0; i < m_themeComboBox->count(); ++i) { | ||||
if (m_themeComboBox->itemText(i) == t) { | ||||
m_themeComboBox->setCurrentIndex(i); | ||||
break; | ||||
} | ||||
} | ||||
} | ||||
if (parameters.contains("animation")) { | ||||
QString t = parameters["animation"].toString(); | ||||
for (int i = 0; i < m_animatedComboBox->count(); ++i) { | ||||
if (m_animatedComboBox->itemText(i) == t) { | ||||
m_animatedComboBox->setCurrentIndex(i); | ||||
break; | ||||
} | ||||
} | ||||
} | ||||
if (parameters.contains("legend")) { | ||||
QString t = parameters["legend"].toString(); | ||||
for (int i = 0; i < m_legendComboBox->count(); ++i) { | ||||
if (m_legendComboBox->itemText(i) == t) { | ||||
m_legendComboBox->setCurrentIndex(i); | ||||
break; | ||||
} | ||||
} | ||||
} | ||||
} | ||||
Michal Klocek
|
r1864 | |||
Michal Klocek
|
r1748 | void Window::updateUI() | ||
Michal Klocek
|
r1840 | { | ||
Michal Klocek
|
r2128 | checkView(); | ||
Michal Klocek
|
r2135 | checkTemplate(); | ||
Michal Klocek
|
r1840 | checkOpenGL(); | ||
checkTheme(); | ||||
checkAnimationOptions(); | ||||
checkLegend(); | ||||
checkState(); | ||||
Titta Heikkala
|
r2795 | checkXTick(); | ||
checkYTick(); | ||||
checkMinorXTick(); | ||||
checkMinorYTick(); | ||||
Michal Klocek
|
r1840 | } | ||
Michal Klocek
|
r2128 | void Window::checkView() | ||
{ | ||||
int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); | ||||
Michal Klocek
|
r2135 | if(m_grid->size()!=count){ | ||
m_grid->setSize(count); | ||||
m_template = 0; | ||||
} | ||||
Michal Klocek
|
r2128 | } | ||
Titta Heikkala
|
r2795 | void Window::checkXTick() | ||
{ | ||||
foreach (QChart *chart, m_grid->charts()) { | ||||
if (qobject_cast<QValueAxis *>(chart->axisX())) { | ||||
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisX()); | ||||
valueAxis->setGridLineVisible(); | ||||
valueAxis->setTickCount(m_xTickSpinBox->value()); | ||||
} | ||||
} | ||||
} | ||||
void Window::checkYTick() | ||||
{ | ||||
foreach (QChart *chart, m_grid->charts()) { | ||||
if (qobject_cast<QValueAxis *>(chart->axisY())) { | ||||
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisY()); | ||||
valueAxis->setGridLineVisible(); | ||||
valueAxis->setTickCount(m_yTickSpinBox->value()); | ||||
} | ||||
} | ||||
} | ||||
void Window::checkMinorXTick() | ||||
{ | ||||
foreach (QChart *chart, m_grid->charts()) { | ||||
if (qobject_cast<QValueAxis *>(chart->axisX())) { | ||||
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisX()); | ||||
valueAxis->setMinorGridLineVisible(); | ||||
valueAxis->setMinorTickCount(m_minorXTickSpinBox->value()); | ||||
} | ||||
} | ||||
} | ||||
void Window::checkMinorYTick() | ||||
{ | ||||
foreach (QChart *chart, m_grid->charts()) { | ||||
if (qobject_cast<QValueAxis *>(chart->axisY())) { | ||||
QValueAxis *valueAxis = qobject_cast<QValueAxis *>(chart->axisY()); | ||||
valueAxis->setMinorGridLineVisible(); | ||||
valueAxis->setMinorTickCount(m_minorYTickSpinBox->value()); | ||||
} | ||||
} | ||||
} | ||||
Michal Klocek
|
r1840 | void Window::checkLegend() | ||
{ | ||||
Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | ||||
if (!alignment) { | ||||
Michal Klocek
|
r2127 | foreach (QChart *chart, m_grid->charts()) | ||
Michal Klocek
|
r1840 | chart->legend()->hide(); | ||
Jani Honkonen
|
r2099 | } else { | ||
Michal Klocek
|
r2127 | foreach (QChart *chart, m_grid->charts()) { | ||
Michal Klocek
|
r1840 | chart->legend()->setAlignment(alignment); | ||
chart->legend()->show(); | ||||
} | ||||
} | ||||
} | ||||
void Window::checkOpenGL() | ||||
Michal Klocek
|
r1746 | { | ||
bool opengl = m_openGLCheckBox->isChecked(); | ||||
Miikka Heikkinen
|
r2828 | bool isOpengl = qobject_cast<QOpenGLWidget *>(m_view->viewport()); | ||
Michal Klocek
|
r1746 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { | ||
m_view->deleteLater(); | ||||
Michal Klocek
|
r1748 | m_view = new View(m_scene, m_form); | ||
Miikka Heikkinen
|
r2828 | m_view->setViewport(!opengl ? new QWidget() : new QOpenGLWidget()); | ||
Michal Klocek
|
r1746 | setCentralWidget(m_view); | ||
} | ||||
Michal Klocek
|
r1840 | bool antialias = m_antialiasCheckBox->isChecked(); | ||
Jani Honkonen
|
r2099 | if (opengl) | ||
m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); | ||||
else | ||||
m_view->setRenderHint(QPainter::Antialiasing, antialias); | ||||
Michal Klocek
|
r1840 | } | ||
void Window::checkAnimationOptions() | ||||
{ | ||||
QChart::AnimationOptions options( | ||||
Jani Honkonen
|
r2099 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | ||
Jani Honkonen
|
r2130 | QList<QChart *> charts = m_grid->charts(); | ||
Michal Klocek
|
r2127 | |||
if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { | ||||
foreach (QChart *chart, charts) | ||||
Jani Honkonen
|
r2099 | chart->setAnimationOptions(options); | ||
} | ||||
Michal Klocek
|
r1840 | } | ||
void Window::checkState() | ||||
{ | ||||
bool scroll = m_scrollCheckBox->isChecked(); | ||||
Michal Klocek
|
r2127 | |||
if (m_grid->state() != Grid::ScrollState && scroll) { | ||||
m_grid->setState(Grid::ScrollState); | ||||
Michal Klocek
|
r1840 | m_zoomCheckBox->setChecked(false); | ||
Michal Klocek
|
r2127 | } else if (!scroll && m_grid->state() == Grid::ScrollState) { | ||
m_grid->setState(Grid::NoState); | ||||
Michal Klocek
|
r1840 | } | ||
bool zoom = m_zoomCheckBox->isChecked(); | ||||
Michal Klocek
|
r2127 | if (m_grid->state() != Grid::ZoomState && zoom) { | ||
m_grid->setState(Grid::ZoomState); | ||||
Michal Klocek
|
r1840 | m_scrollCheckBox->setChecked(false); | ||
Michal Klocek
|
r2127 | } else if (!zoom && m_grid->state() == Grid::ZoomState) { | ||
m_grid->setState(Grid::NoState); | ||||
Michal Klocek
|
r1840 | } | ||
} | ||||
Michal Klocek
|
r1864 | void Window::checkTemplate() | ||
{ | ||||
int index = m_templateComboBox->currentIndex(); | ||||
if (m_template == index || index == 0) | ||||
return; | ||||
Michal Klocek
|
r1865 | m_template = index; | ||
Michal Klocek
|
r1864 | QString category = m_templateComboBox->itemData(index).toString(); | ||
Michal Klocek
|
r2127 | m_grid->createCharts(category); | ||
Michal Klocek
|
r1864 | } | ||
Michal Klocek
|
r1840 | void Window::checkTheme() | ||
{ | ||||
Michal Klocek
|
r1746 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( | ||
Jani Honkonen
|
r2099 | m_themeComboBox->currentIndex()).toInt(); | ||
Michal Klocek
|
r1746 | |||
Michal Klocek
|
r2127 | foreach (QChart *chart, m_grid->charts()) | ||
Michal Klocek
|
r1746 | chart->setTheme(theme); | ||
QPalette pal = window()->palette(); | ||||
if (theme == QChart::ChartThemeLight) { | ||||
pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | ||||
pal.setColor(QPalette::WindowText, QRgb(0x404044)); | ||||
Jani Honkonen
|
r2099 | } else if (theme == QChart::ChartThemeDark) { | ||
Michal Klocek
|
r1746 | pal.setColor(QPalette::Window, QRgb(0x121218)); | ||
pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | ||||
Jani Honkonen
|
r2099 | } else if (theme == QChart::ChartThemeBlueCerulean) { | ||
Michal Klocek
|
r1746 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | ||
pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | ||||
Jani Honkonen
|
r2099 | } else if (theme == QChart::ChartThemeBrownSand) { | ||
Michal Klocek
|
r1746 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | ||
pal.setColor(QPalette::WindowText, QRgb(0x404044)); | ||||
Jani Honkonen
|
r2099 | } else if (theme == QChart::ChartThemeBlueNcs) { | ||
Michal Klocek
|
r1746 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | ||
pal.setColor(QPalette::WindowText, QRgb(0x404044)); | ||||
Jani Honkonen
|
r2099 | } else if (theme == QChart::ChartThemeHighContrast) { | ||
Michal Klocek
|
r1746 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | ||
pal.setColor(QPalette::WindowText, QRgb(0x181818)); | ||||
Jani Honkonen
|
r2099 | } else if (theme == QChart::ChartThemeBlueIcy) { | ||
Michal Klocek
|
r1746 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | ||
pal.setColor(QPalette::WindowText, QRgb(0x404044)); | ||||
Titta Heikkala
|
r2625 | } else if (theme == QChart::ChartThemeQt) { | ||
pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | ||||
pal.setColor(QPalette::WindowText, QRgb(0x404044)); | ||||
Jani Honkonen
|
r2099 | } else { | ||
Michal Klocek
|
r1746 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | ||
pal.setColor(QPalette::WindowText, QRgb(0x404044)); | ||||
} | ||||
Jani Honkonen
|
r2099 | foreach (QGraphicsProxyWidget *widget, m_widgetHash) | ||
Michal Klocek
|
r1746 | widget->setPalette(pal); | ||
m_view->setBackgroundBrush(pal.color((QPalette::Window))); | ||||
Michal Klocek
|
r2127 | m_grid->setRubberPen(pal.color((QPalette::WindowText))); | ||
Michal Klocek
|
r1748 | } | ||
Michal Klocek
|
r1754 | |||
void Window::comboBoxFocused(QComboBox *combobox) | ||||
{ | ||||
Jani Honkonen
|
r2099 | foreach (QGraphicsProxyWidget *widget , m_widgetHash) { | ||
if (widget->widget() == combobox) | ||||
widget->setZValue(2.0); | ||||
else | ||||
widget->setZValue(0.0); | ||||
Michal Klocek
|
r1754 | } | ||
} | ||||
Michal Klocek
|
r1840 | |||
Michal Klocek
|
r2127 | void Window::handleChartSelected(QChart *qchart) | ||
Michal Klocek
|
r1840 | { | ||
Jani Honkonen
|
r2130 | if (m_templateComboBox->currentIndex() != 0) | ||
return; | ||||
Michal Klocek
|
r2127 | |||
Michal Klocek
|
r1840 | QAction *chosen = m_menu->exec(QCursor::pos()); | ||
if (chosen) { | ||||
Jani Honkonen
|
r2099 | Chart *chart = (Chart *) chosen->data().value<void *>(); | ||
Jani Honkonen
|
r2130 | m_grid->replaceChart(qchart, chart); | ||
Michal Klocek
|
r1840 | updateUI(); | ||
} | ||||
} | ||||
Jani Honkonen
|
r2099 | QMenu *Window::createMenu() | ||
Michal Klocek
|
r1864 | { | ||
Charts::ChartList list = Charts::chartList(); | ||||
Jani Honkonen
|
r2099 | QMultiMap<QString, Chart *> categoryMap; | ||
Michal Klocek
|
r1864 | |||
Jani Honkonen
|
r2099 | QMenu *result = new QMenu(this); | ||
Michal Klocek
|
r1864 | |||
Jani Honkonen
|
r2099 | foreach (Chart *chart, list) | ||
Michal Klocek
|
r1864 | categoryMap.insertMulti(chart->category(), chart); | ||
Jani Honkonen
|
r2099 | foreach (const QString &category, categoryMap.uniqueKeys()) { | ||
QMenu *menu(0); | ||||
QMultiMap<QString, Chart *> subCategoryMap; | ||||
Michal Klocek
|
r1864 | if (category.isEmpty()) { | ||
menu = result; | ||||
Jani Honkonen
|
r2099 | } else { | ||
Michal Klocek
|
r1864 | menu = new QMenu(category, this); | ||
result->addMenu(menu); | ||||
} | ||||
Jani Honkonen
|
r2099 | foreach (Chart *chart, categoryMap.values(category)) | ||
Michal Klocek
|
r1864 | subCategoryMap.insert(chart->subCategory(), chart); | ||
Jani Honkonen
|
r2099 | foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { | ||
QMenu *subMenu(0); | ||||
Michal Klocek
|
r1864 | if (subCategory.isEmpty()) { | ||
subMenu = menu; | ||||
Jani Honkonen
|
r2099 | } else { | ||
Michal Klocek
|
r1864 | subMenu = new QMenu(subCategory, this); | ||
menu->addMenu(subMenu); | ||||
} | ||||
Jani Honkonen
|
r2102 | foreach (Chart *chart, subCategoryMap.values(subCategory)) { | ||
Michal Klocek
|
r1864 | createMenuAction(subMenu, QIcon(), chart->name(), | ||
Jani Honkonen
|
r2099 | qVariantFromValue((void *) chart)); | ||
Michal Klocek
|
r1864 | } | ||
} | ||||
} | ||||
return result; | ||||
} | ||||
Jani Honkonen
|
r2099 | QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, | ||
const QVariant &data) | ||||
Michal Klocek
|
r1840 | { | ||
QAction *action = menu->addAction(icon, text); | ||||
action->setCheckable(false); | ||||
action->setData(data); | ||||
return action; | ||||
} | ||||
Michal Klocek
|
r1964 | |||
void Window::handleGeometryChanged() | ||||
{ | ||||
Jani Honkonen
|
r2099 | QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); | ||
m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); | ||||
m_view->setMinimumSize(size.toSize()); | ||||
Michal Klocek
|
r1964 | } | ||