##// END OF EJS Templates
Some more work on mapping with limits
Some more work on mapping with limits

File last commit:

r692:339ba14ee2ea
r735:8b3d19ded350
Show More
mainwidget.cpp
333 lines | 11.9 KiB | text/x-c | CppLexer
Tero Ahola
New features like chart type to the test app
r5 #include "mainwidget.h"
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 #include "dataseriedialog.h"
Tero Ahola
Line and area series in chartwidgettest
r468 #include <qpieseries.h>
#include <qscatterseries.h>
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 #include <qlineseries.h>
Tero Ahola
Line and area series in chartwidgettest
r468 #include <qareaseries.h>
#include <qsplineseries.h>
sauimone
Barset and barcategory implememtation. Updated test application
r171 #include <qbarset.h>
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 #include <qbarseries.h>
#include <qstackedbarseries.h>
#include <qpercentbarseries.h>
Tero Ahola
New features like chart type to the test app
r5 #include <QPushButton>
#include <QComboBox>
#include <QSpinBox>
Tero Ahola
Added auto scaling option to test app
r6 #include <QCheckBox>
Tero Ahola
New features like chart type to the test app
r5 #include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QSpacerItem>
#include <QMessageBox>
Tero Ahola
Scatter data point now shown using a picture
r13 #include <cmath>
Tero Ahola
New features like chart type to the test app
r5 #include <QDebug>
sauimone
Added bar chart example
r78 #include <QStandardItemModel>
Tero Ahola
New features like chart type to the test app
r5
Tero Ahola
Renamed to QtCommercialChart
r30 QTCOMMERCIALCHART_USE_NAMESPACE
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19
Tero Ahola
New features like chart type to the test app
r5 MainWidget::MainWidget(QWidget *parent) :
Tero Ahola
Add dialog of chartwidgettest now remembers selections
r376 QWidget(parent),
m_addSerieDialog(0),
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 m_chartView(0)
Tero Ahola
New features like chart type to the test app
r5 {
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 m_chartView = new QChartView(this);
m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand);
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77
Tero Ahola
Scaling for scatter series
r111 // Grid layout for the controls for configuring the chart widget
Tero Ahola
Refactored the test app
r110 QGridLayout *grid = new QGridLayout();
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 QPushButton *addSeriesButton = new QPushButton("Add series");
connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
Tero Ahola
Refactored the test app
r110 grid->addWidget(addSeriesButton, 0, 1);
initBackroundCombo(grid);
initScaleControls(grid);
initThemeCombo(grid);
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 initCheckboxes(grid);
Tero Ahola
Refactored the test app
r110 // add row with empty label to make all the other rows static
grid->addWidget(new QLabel(""), grid->rowCount(), 0);
grid->setRowStretch(grid->rowCount() - 1, 1);
Tero Ahola
Scaling for scatter series
r111
// Another grid layout as a main layout
QGridLayout *mainLayout = new QGridLayout();
Tero Ahola
Refactored the test app
r110 mainLayout->addLayout(grid, 0, 0);
// Add layouts and the chart widget to the main layout
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
Tero Ahola
Refactored the test app
r110 setLayout(mainLayout);
}
Tero Ahola
New features like chart type to the test app
r5
Tero Ahola
Refactored the test app
r110 // Combo box for selecting the chart's background
void MainWidget::initBackroundCombo(QGridLayout *grid)
{
Tero Ahola
New features like chart type to the test app
r5 QComboBox *backgroundCombo = new QComboBox(this);
Tero Ahola
Theme now affects background, enabled zoom by default in QChartWidget
r77 backgroundCombo->addItem("Color");
backgroundCombo->addItem("Gradient");
backgroundCombo->addItem("Image");
Tero Ahola
New features like chart type to the test app
r5 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
this, SLOT(backgroundChanged(int)));
Tero Ahola
Refactored the test app
r110 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
}
// Scale related controls (auto-scale vs. manual min-max values)
void MainWidget::initScaleControls(QGridLayout *grid)
{
Tero Ahola
Drafting scatter type plotting...
r8 m_autoScaleCheck = new QCheckBox("Automatic scaling");
connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
Tero Ahola
New features like chart type to the test app
r5 // Allow setting also non-sense values (like -2147483648 and 2147483647)
Tero Ahola
Added auto scaling option to test app
r6 m_xMinSpin = new QSpinBox();
m_xMinSpin->setMinimum(INT_MIN);
m_xMinSpin->setMaximum(INT_MAX);
m_xMinSpin->setValue(0);
connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
m_xMaxSpin = new QSpinBox();
m_xMaxSpin->setMinimum(INT_MIN);
m_xMaxSpin->setMaximum(INT_MAX);
m_xMaxSpin->setValue(10);
connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
m_yMinSpin = new QSpinBox();
m_yMinSpin->setMinimum(INT_MIN);
m_yMinSpin->setMaximum(INT_MAX);
m_yMinSpin->setValue(0);
connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
m_yMaxSpin = new QSpinBox();
m_yMaxSpin->setMinimum(INT_MIN);
m_yMaxSpin->setMaximum(INT_MAX);
m_yMaxSpin->setValue(10);
connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
Tero Ahola
New features like chart type to the test app
r5
Tero Ahola
Refactored the test app
r110 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
m_autoScaleCheck->setChecked(true);
}
// Combo box for selecting theme
void MainWidget::initThemeCombo(QGridLayout *grid)
{
Tero Ahola
Draft implementation for setting color themes for a chart
r64 QComboBox *chartTheme = new QComboBox();
Tero Ahola
Added theme named 'default'
r81 chartTheme->addItem("Default");
Tero Ahola
Default theme background, removed extra themes
r692 chartTheme->addItem("Light");
chartTheme->addItem("Blue Cerulean");
chartTheme->addItem("Dark");
chartTheme->addItem("Brown Sand");
chartTheme->addItem("Blue NCS");
Tero Ahola
Draft implementation for setting color themes for a chart
r64 chartTheme->addItem("Icy");
Tero Ahola
tuning theme colors
r125 chartTheme->addItem("Scientific");
Tero Ahola
Draft implementation for setting color themes for a chart
r64 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
this, SLOT(changeChartTheme(int)));
grid->addWidget(new QLabel("Chart theme:"), 8, 0);
grid->addWidget(chartTheme, 8, 1);
Tero Ahola
Refactored the test app
r110 }
Tero Ahola
Added size factor property to pie
r60
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 // Different check boxes for customizing chart
void MainWidget::initCheckboxes(QGridLayout *grid)
{
// TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
zoomCheckBox->setChecked(true);
grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
aliasCheckBox->setChecked(false);
grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
}
void MainWidget::antiAliasToggled(bool enabled)
{
m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
}
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 void MainWidget::addSeries()
{
Tero Ahola
Add dialog of chartwidgettest now remembers selections
r376 if (!m_addSerieDialog) {
m_addSerieDialog = new DataSerieDialog(this);
connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
this, SLOT(addSeries(QString, int, int, QString, bool)));
}
m_addSerieDialog->exec();
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 }
Tero Ahola
Refactored chartwidgettest test data impl
r278 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
Tero Ahola
Started to refactor the API to allow integrating different plot types
r19 {
Tero Ahola
Refactored chartwidgettest test data impl
r278 // TODO: dataCharacteristics
QList<RealList> testData;
for (int j(0); j < columnCount; j++) {
QList <qreal> newColumn;
for (int i(0); i < rowCount; i++) {
if (dataCharacteristics == "Sin") {
newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
} else if (dataCharacteristics == "Sin + random") {
newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
} else if (dataCharacteristics == "Random") {
Tero Ahola
Pie pen now uses gradient start color
r510 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
Tero Ahola
Refactored chartwidgettest test data impl
r278 } else if (dataCharacteristics == "Linear") {
//newColumn.append(i * (j + 1.0));
// TODO: temporary hack to make pie work; prevent zero values:
newColumn.append(i * (j + 1.0) + 0.1);
} else { // "constant"
newColumn.append((j + 1.0));
}
}
testData.append(newColumn);
}
return testData;
}
Tero Ahola
Test app now adds n data series of different type
r20
Tero Ahola
Refactored chartwidgettest test data impl
r278 QStringList MainWidget::generateLabels(int count)
{
QStringList result;
for (int i(0); i < count; i++)
result.append("label" + QString::number(i));
return result;
}
sauimone
bug fix in bar charts. Crashed, if layout was set before data. Also integrated to test app.
r165
Tero Ahola
Refactored chartwidgettest test data impl
r278 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
{
qDebug() << "addSeries: " << seriesName
<< " columnCount: " << columnCount
<< " rowCount: " << rowCount
<< " dataCharacteristics: " << dataCharacteristics
<< " labels enabled: " << labelsEnabled;
m_defaultSeriesName = seriesName;
QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
// Line series and scatter series use similar data
Tero Ahola
Line and area series in chartwidgettest
r468 if (seriesName == "Line") {
Tero Ahola
Refactored chartwidgettest test data impl
r278 for (int j(0); j < data.count(); j ++) {
QList<qreal> column = data.at(j);
Michal Klocek
Rename QLineChartSeries to QLineSeries
r349 QLineSeries *series = new QLineSeries();
Tero Ahola
Refactored chartwidgettest test data impl
r278 for (int i(0); i < column.count(); i++) {
series->add(i, column.at(i));
}
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 m_chartView->addSeries(series);
Tero Ahola
Integrated scatter type series...
r42 }
Tero Ahola
Fixed area series handling in chartwidgettest
r517 } else if (seriesName == "Area") {
Tero Ahola
Line and area series in chartwidgettest
r468 // TODO: lower series for the area?
for (int j(0); j < data.count(); j ++) {
QList<qreal> column = data.at(j);
QLineSeries *lineSeries = new QLineSeries();
for (int i(0); i < column.count(); i++) {
lineSeries->add(i, column.at(i));
}
QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
m_chartView->addSeries(areaSeries);
}
} else if (seriesName == "Scatter") {
Tero Ahola
Refactored chartwidgettest test data impl
r278 for (int j(0); j < data.count(); j++) {
QList<qreal> column = data.at(j);
QScatterSeries *series = new QScatterSeries();
for (int i(0); i < column.count(); i++) {
Marek Rosa
Some spline fixes
r455 (*series) << QPointF(i, column.at(i));
Tero Ahola
Refactored chartwidgettest test data impl
r278 }
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 m_chartView->addSeries(series);
Tero Ahola
Integrated scatter type series...
r42 }
Tero Ahola
Line and area series in chartwidgettest
r468 } else if (seriesName == "Pie") {
Tero Ahola
Refactored chartwidgettest test data impl
r278 QStringList labels = generateLabels(rowCount);
for (int j(0); j < data.count(); j++) {
QPieSeries *series = new QPieSeries();
QList<qreal> column = data.at(j);
for (int i(0); i < column.count(); i++) {
series->add(column.at(i), labels.at(i));
}
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 m_chartView->addSeries(series);
Tero Ahola
Test app now adds n data series of different type
r20 }
Tero Ahola
Fixed compilation of example apps with QBarSets
r284 } else if (seriesName == "Bar"
|| seriesName == "Stacked bar"
|| seriesName == "Percent bar") {
sauimone
replaced qbarcategory with qstringlist
r377 QStringList category;
Tero Ahola
Restored bar series in chartwidgettest
r279 QStringList labels = generateLabels(rowCount);
foreach(QString label, labels)
sauimone
replaced qbarcategory with qstringlist
r377 category << label;
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 QBarSeries* series = 0;
Tero Ahola
Fixed compilation of example apps with QBarSets
r284 if (seriesName == "Bar")
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 series = new QBarSeries(category, this);
Tero Ahola
Fixed compilation of example apps with QBarSets
r284 else if (seriesName == "Stacked bar")
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 series = new QStackedBarSeries(category, this);
Tero Ahola
Fixed compilation of example apps with QBarSets
r284 else
sauimone
Naming convention change for barcharts. QBarChartSeries is now QBarSeries etc.
r338 series = new QPercentBarSeries(category, this);
Tero Ahola
Restored bar series in chartwidgettest
r279
for (int j(0); j < data.count(); j++) {
QList<qreal> column = data.at(j);
Tero Ahola
Fixed compilation of example apps with QBarSets
r284 QBarSet *set = new QBarSet("set" + QString::number(j));
Tero Ahola
Restored bar series in chartwidgettest
r279 for (int i(0); i < column.count(); i++) {
*set << column.at(i);
}
series->addBarSet(set);
}
Marek Rosa
Some spline fixes
r455
sauimone
Better way to enable features to user. Do less, but expose signals to user and allow user to descide what to do.
r425 // TODO: new implementation of setFloatingValuesEnabled with signals
//series->setFloatingValuesEnabled(true);
sauimone
review fixes. countCategories() -> categoryCount(). countSets -> barsetCount()
r366 series->setToolTipEnabled(true);
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 m_chartView->addSeries(series);
Tero Ahola
Line and area series in chartwidgettest
r468 } else if (seriesName == "Spline") {
Marek Rosa
Some spline fixes
r455 for (int j(0); j < data.count(); j ++) {
QList<qreal> column = data.at(j);
QSplineSeries *series = new QSplineSeries();
for (int i(0); i < column.count(); i++) {
series->add(i, column.at(i));
}
m_chartView->addSeries(series);
Tero Ahola
added stream operator to scatter series
r180 }
Tero Ahola
Scatter data point now shown using a picture
r13 }
Tero Ahola
New features like chart type to the test app
r5 }
void MainWidget::backgroundChanged(int itemIndex)
{
qDebug() << "backgroundChanged: " << itemIndex;
}
Tero Ahola
Added auto scaling option to test app
r6 void MainWidget::autoScaleChanged(int value)
{
Tero Ahola
Drafting scatter type plotting...
r8 if (value) {
// TODO: enable auto scaling
} else {
// TODO: set scaling manually (and disable auto scaling)
Tero Ahola
Added auto scaling option to test app
r6 }
Tero Ahola
Drafting scatter type plotting...
r8 m_xMinSpin->setEnabled(!value);
m_xMaxSpin->setEnabled(!value);
m_yMinSpin->setEnabled(!value);
m_yMaxSpin->setEnabled(!value);
Tero Ahola
Added auto scaling option to test app
r6 }
Tero Ahola
New features like chart type to the test app
r5 void MainWidget::xMinChanged(int value)
{
qDebug() << "xMinChanged: " << value;
}
void MainWidget::xMaxChanged(int value)
{
qDebug() << "xMaxChanged: " << value;
}
void MainWidget::yMinChanged(int value)
{
qDebug() << "yMinChanged: " << value;
}
void MainWidget::yMaxChanged(int value)
{
qDebug() << "yMaxChanged: " << value;
}
Tero Ahola
Added size factor property to pie
r60
Tero Ahola
Draft implementation for setting color themes for a chart
r64 void MainWidget::changeChartTheme(int themeIndex)
{
qDebug() << "changeChartTheme: " << themeIndex;
Tero Ahola
Checkbox for anti-alias to chartwidgettest
r379 m_chartView->setChartTheme((QChart::ChartTheme) themeIndex);
sauimone
added labels to series, intergrated with test app. minor hack to test app
r167 //TODO: remove this hack. This is just to make it so that theme change is seen immediately.
QSize s = size();
s.setWidth(s.width()+1);
resize(s);
Tero Ahola
Draft implementation for setting color themes for a chart
r64 }