tablewidget.cpp
585 lines
| 22.7 KiB
| text/x-c
|
CppLexer
|
r830 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r519 | #include "tablewidget.h" | ||
#include <QGridLayout> | ||||
#include <QTableView> | ||||
|
r1056 | #include <QChart> | ||
|
r519 | #include <QStyledItemDelegate> | ||
|
r849 | #include <QLineSeries> | ||
#include <QSplineSeries> | ||||
#include <QScatterSeries> | ||||
|
r1256 | #include <QVXYModelMapper> | ||
|
r1310 | #include <QHXYModelMapper> | ||
|
r519 | #include "customtablemodel.h" | ||
|
r849 | #include <QPieSeries> | ||
|
r1237 | #include <QVPieModelMapper> | ||
|
r849 | #include <QPieSlice> | ||
#include <QAreaSeries> | ||||
#include <QBarSeries> | ||||
|
r1171 | #include <QGroupedBarSeries> | ||
|
r849 | #include <QBarSet> | ||
|
r1294 | #include <QVBarModelMapper> | ||
|
r545 | #include <QPushButton> | ||
#include <QRadioButton> | ||||
|
r878 | #include <QLabel> | ||
|
r735 | #include <QSpinBox> | ||
|
r630 | #include <QTime> | ||
|
r1097 | #include <QHeaderView> | ||
|
r519 | |||
TableWidget::TableWidget(QWidget *parent) | ||||
|
r1294 | : QWidget(parent), | ||
m_series(0), | ||||
m_mapper(0), | ||||
m_model(0), | ||||
m_pieMapper(0), | ||||
m_pieMapper2(0) | ||||
|
r1090 | // specialPie(0) | ||
|
r519 | { | ||
|
r1056 | setGeometry(1900, 100, 1000, 600); | ||
|
r630 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | ||
|
r519 | // create simple model for storing data | ||
// user's table data model | ||||
|
r545 | m_model = new CustomTableModel; | ||
|
r833 | m_tableView = new QTableView; | ||
m_tableView->setModel(m_model); | ||||
|
r1164 | // m_tableView->setMinimumHeight(300); | ||
|
r1097 | m_tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); | ||
m_tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch); | ||||
|
r833 | m_chart = new QChart; | ||
|
r1012 | m_chart->legend()->setVisible(true); | ||
|
r1164 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | ||
|
r833 | m_chartView = new QChartView(m_chart); | ||
m_chartView->setRenderHint(QPainter::Antialiasing); | ||||
m_chartView->setMinimumSize(640, 480); | ||||
|
r519 | |||
|
r545 | // add, remove data buttons | ||
|
r546 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | ||
connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | ||||
QPushButton* addRowBelowButton = new QPushButton("Add row below"); | ||||
connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | ||||
|
r545 | |||
QPushButton* removeRowButton = new QPushButton("Remove row"); | ||||
connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | ||||
|
r1090 | QPushButton* addColumnRightButton = new QPushButton("Add column to the right"); | ||
|
r1081 | connect(addColumnRightButton, SIGNAL(clicked()), this, SLOT(addColumnRight())); | ||
QPushButton* removeColumnButton = new QPushButton("Remove column"); | ||||
connect(removeColumnButton, SIGNAL(clicked()), this, SLOT(removeColumn())); | ||||
|
r1251 | QPushButton* specialPieButton = new QPushButton("Add slices using series API"); | ||
|
r1056 | connect(specialPieButton, SIGNAL(clicked()), this, SLOT(testPie())); | ||
|
r1251 | QPushButton* specialPieButton2 = new QPushButton("Remove slices using series API"); | ||
|
r1231 | connect(specialPieButton2, SIGNAL(clicked()), this, SLOT(testPie2())); | ||
|
r1251 | QPushButton* specialPieButton3 = new QPushButton("Modify slices using series API"); | ||
|
r1236 | connect(specialPieButton3, SIGNAL(clicked()), this, SLOT(testPie3())); | ||
|
r1262 | QPushButton* xyTestButton = new QPushButton("Append XY point"); | ||
connect(xyTestButton, SIGNAL(clicked()), this, SLOT(testXY())); | ||||
|
r1056 | |||
|
r1256 | QLabel *spinBoxLabel = new QLabel("Rows affected:"); | ||
|
r878 | |||
|
r877 | // spin box for setting number of affected items (add, remove) | ||
|
r833 | m_linesCountSpinBox = new QSpinBox; | ||
m_linesCountSpinBox->setRange(1, 10); | ||||
m_linesCountSpinBox->setValue(1); | ||||
|
r735 | |||
|
r545 | // buttons layout | ||
QVBoxLayout* buttonsLayout = new QVBoxLayout; | ||||
|
r1256 | buttonsLayout->addWidget(spinBoxLabel); | ||
buttonsLayout->addWidget(m_linesCountSpinBox); | ||||
|
r1164 | // buttonsLayout->addWidget(addRowAboveButton); | ||
|
r546 | buttonsLayout->addWidget(addRowBelowButton); | ||
|
r545 | buttonsLayout->addWidget(removeRowButton); | ||
|
r1164 | // buttonsLayout->addWidget(addColumnRightButton); | ||
// buttonsLayout->addWidget(removeColumnButton); | ||||
|
r1230 | buttonsLayout->addWidget(specialPieButton); | ||
|
r1231 | buttonsLayout->addWidget(specialPieButton2); | ||
|
r1236 | buttonsLayout->addWidget(specialPieButton3); | ||
|
r1262 | buttonsLayout->addWidget(xyTestButton); | ||
|
r545 | buttonsLayout->addStretch(); | ||
// chart type radio buttons | ||||
|
r833 | m_lineRadioButton = new QRadioButton("Line"); | ||
m_splineRadioButton = new QRadioButton("Spline"); | ||||
m_scatterRadioButton = new QRadioButton("Scatter"); | ||||
m_pieRadioButton = new QRadioButton("Pie"); | ||||
m_areaRadioButton = new QRadioButton("Area"); | ||||
m_barRadioButton = new QRadioButton("Bar"); | ||||
|
r878 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | ||
connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | ||||
connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | ||||
connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | ||||
connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | ||||
connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType(bool))); | ||||
|
r1331 | m_barRadioButton->setChecked(true); | ||
|
r545 | |||
// radio buttons layout | ||||
|
r630 | QVBoxLayout* radioLayout = new QVBoxLayout; | ||
|
r833 | radioLayout->addWidget(m_lineRadioButton); | ||
|
r1230 | radioLayout->addWidget(m_splineRadioButton); | ||
|
r1294 | radioLayout->addWidget(m_scatterRadioButton); | ||
|
r833 | radioLayout->addWidget(m_pieRadioButton); | ||
|
r1164 | // radioLayout->addWidget(m_areaRadioButton); | ||
|
r833 | radioLayout->addWidget(m_barRadioButton); | ||
|
r630 | radioLayout->addStretch(); | ||
|
r519 | |||
// create main layout | ||||
QGridLayout* mainLayout = new QGridLayout; | ||||
|
r1097 | mainLayout->addLayout(buttonsLayout, 2, 0); | ||
|
r1230 | mainLayout->addLayout(radioLayout, 3, 0); | ||
|
r833 | mainLayout->addWidget(m_tableView, 1, 0); | ||
|
r1097 | mainLayout->addWidget(m_chartView, 1, 1, 2, 1); | ||
|
r849 | setLayout(mainLayout); | ||
|
r833 | m_lineRadioButton->setFocus(); | ||
|
r545 | } | ||
|
r546 | void TableWidget::addRowAbove() | ||
{ | ||||
|
r833 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | ||
|
r546 | |||
} | ||||
void TableWidget::addRowBelow() | ||||
|
r545 | { | ||
|
r833 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | ||
|
r545 | |||
} | ||||
void TableWidget::removeRow() | ||||
{ | ||||
|
r833 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | ||
|
r545 | } | ||
|
r1081 | void TableWidget::addColumnRight() | ||
{ | ||||
m_model->insertColumns(m_tableView->currentIndex().column() + 1, m_linesCountSpinBox->value()); | ||||
} | ||||
void TableWidget::removeColumn() | ||||
{ | ||||
m_model->removeColumns(m_tableView->currentIndex().column(), qMin(m_model->columnCount() - m_tableView->currentIndex().column(), m_linesCountSpinBox->value())); | ||||
} | ||||
|
r878 | void TableWidget::updateChartType(bool toggle) | ||
|
r545 | { | ||
|
r878 | // this if is needed, so that the function is only called once. | ||
// For the radioButton that was enabled. | ||||
if (toggle) { | ||||
|
r1090 | // specialPie = 0; | ||
|
r1056 | m_chart->removeAllSeries(); | ||
|
r1294 | m_series = 0; | ||
|
r1230 | // m_chart->axisX()->setNiceNumbersEnabled(false); | ||
// m_chart->axisY()->setNiceNumbersEnabled(false); | ||||
|
r1294 | if (m_mapper) { | ||
m_mapper->deleteLater(); | ||||
m_mapper = 0; | ||||
} | ||||
if (m_pieMapper) { | ||||
m_pieMapper->deleteLater(); | ||||
m_pieMapper = 0; | ||||
} | ||||
if (m_pieMapper2) { | ||||
m_pieMapper2->deleteLater(); | ||||
m_pieMapper2 = 0; | ||||
} | ||||
// if (m_series) { | ||||
// delete m_series; | ||||
// m_series = 0; | ||||
// } | ||||
|
r878 | |||
|
r1256 | // renable axes of the chart (pie hides them) | ||
// x axis | ||||
QAxis *axis = m_chart->axisX(); | ||||
axis->setAxisVisible(true); | ||||
axis->setGridLineVisible(true); | ||||
axis->setLabelsVisible(true); | ||||
|
r878 | |||
|
r1256 | // y axis | ||
axis = m_chart->axisY(); | ||||
axis->setAxisVisible(true); | ||||
axis->setGridLineVisible(true); | ||||
axis->setLabelsVisible(true); | ||||
|
r878 | |||
|
r1256 | m_model->clearMapping(); | ||
|
r878 | |||
QString seriesColorHex = "#000000"; | ||||
|
r1230 | // QPen pen; | ||
// pen.setWidth(2); | ||||
|
r878 | |||
if (m_lineRadioButton->isChecked()) | ||||
{ | ||||
|
r1317 | // m_chart->setAnimationOptions(QChart::NoAnimation); | ||
|
r1230 | |||
|
r1256 | // series 1 | ||
|
r1294 | m_series = new QLineSeries; | ||
|
r1230 | |||
|
r1317 | // m_mapper = new QHXYModelMapper; | ||
|
r1310 | // m_mapper->setModel(m_model); | ||
// m_mapper->setSeries(m_series); | ||||
|
r1317 | // m_mapper->setXRow(0); | ||
// m_mapper->setYRow(1); | ||||
|
r1310 | // m_mapper->setFirst(3); | ||
// m_mapper->setCount(4); | ||||
|
r1317 | m_mapper = new QVXYModelMapper; | ||
m_mapper->setModel(m_model); | ||||
m_mapper->setSeries(m_series); | ||||
m_mapper->setXColumn(0); | ||||
m_mapper->setYColumn(1); | ||||
m_mapper->setFirst(3); | ||||
// m_mapper->setCount(4); | ||||
|
r1256 | // m_series->setModelMapping(0,1, Qt::Vertical); | ||
// m_series->setModelMappingRange(3, 4); | ||||
m_chart->addSeries(m_series); | ||||
seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | ||||
m_model->addMapping(seriesColorHex, QRect(0, 3, 2, 4)); | ||||
|
r1230 | |||
// // series 2 | ||||
// m_series = new QLineSeries; | ||||
// m_series->setModel(m_model); | ||||
// mapper = new QXYModelMapper; | ||||
// mapper->setMapX(3); | ||||
// mapper->setMapY(4); | ||||
// // mapper->setFirst(3); | ||||
// // mapper->setCount(4); | ||||
// m_series->setModelMapper(mapper); | ||||
// // m_series->setModelMapping(2,3, Qt::Vertical); | ||||
// m_chart->addSeries(m_series); | ||||
// seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(3, 0, 2, 1000)); | ||||
// // series 3 | ||||
// m_series = new QLineSeries; | ||||
// m_series->setModel(m_model); | ||||
// mapper = new QXYModelMapper; | ||||
// mapper->setMapX(5); | ||||
// mapper->setMapY(6); | ||||
// mapper->setFirst(2); | ||||
// mapper->setCount(-1); | ||||
// m_series->setModelMapper(mapper); | ||||
// // m_series->setModelMapping(4,5, Qt::Vertical); | ||||
// // m_series->setModelMappingRange(2, -1); | ||||
// m_chart->addSeries(m_series); | ||||
// seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(5, 2, 2, 1000)); | ||||
|
r878 | } | ||
else if (m_splineRadioButton->isChecked()) | ||||
{ | ||||
|
r1275 | m_chart->setAnimationOptions(QChart::NoAnimation); | ||
|
r1091 | |||
|
r1275 | // series 1 | ||
m_series = new QSplineSeries; | ||||
|
r1294 | // m_series->setModel(m_model); | ||
|
r1164 | |||
|
r1310 | // m_mapper = new QVXYModelMapper; | ||
// m_mapper->setSeries(m_series); | ||||
// m_mapper->setModel(m_model); | ||||
// m_mapper->setXColumn(0); | ||||
// m_mapper->setYColumn(1); | ||||
// m_mapper->setFirst(0); | ||||
// m_mapper->setCount(-1); | ||||
|
r1164 | |||
|
r1294 | // m_series->setModelMapper(mapper); | ||
|
r1164 | |||
|
r1275 | m_chart->addSeries(m_series); | ||
seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | ||||
m_model->addMapping(seriesColorHex, QRect(0, 0, 2, 1000)); | ||||
|
r878 | |||
|
r1230 | // // series 2 | ||
// m_series = new QSplineSeries; | ||||
// m_series->setModel(m_model); | ||||
|
r1164 | |||
|
r1230 | // mapper = new QXYModelMapper; | ||
// mapper->setMapX(2); | ||||
// mapper->setMapY(3); | ||||
// mapper->setFirst(2); | ||||
// mapper->setCount(4); | ||||
|
r1164 | |||
|
r1230 | // m_series->setModelMapper(mapper); | ||
|
r1164 | |||
|
r1230 | // m_chart->addSeries(m_series); | ||
// seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(2, 2, 2, 4)); | ||||
|
r878 | |||
|
r1230 | // // series 3 | ||
// m_series = new QSplineSeries; | ||||
// m_series->setModel(m_model); | ||||
|
r1091 | |||
|
r1230 | // mapper = new QXYModelMapper; | ||
// mapper->setMapX(4); | ||||
// mapper->setMapY(5); | ||||
// mapper->setFirst(2); | ||||
// mapper->setCount(-1); | ||||
|
r878 | |||
|
r1230 | // m_series->setModelMapper(mapper); | ||
|
r878 | |||
|
r1230 | // m_chart->addSeries(m_series); | ||
// seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | ||||
|
r1294 | } else if (m_scatterRadioButton->isChecked()) | ||
|
r1230 | { | ||
|
r1294 | m_chart->setAnimationOptions(QChart::NoAnimation); | ||
// series 1 | ||||
m_series = new QScatterSeries; | ||||
|
r1310 | // m_mapper = new QVXYModelMapper; | ||
// m_mapper->setSeries(m_series); | ||||
// m_mapper->setModel(m_model); | ||||
// m_mapper->setXColumn(0); | ||||
// m_mapper->setYColumn(1); | ||||
// m_mapper->setFirst(0); | ||||
// m_mapper->setCount(-1); | ||||
|
r1294 | |||
m_chart->addSeries(m_series); | ||||
seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | ||||
m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | ||||
// // series 2 | ||||
// m_series = new QScatterSeries; | ||||
// m_series->setModel(m_model); | ||||
// m_series->setModelMapping(2,3, Qt::Vertical); | ||||
// // m_series->setModelMappingRange(1, 6); | ||||
// // series->setModelMapping(2,3, Qt::Horizontal); | ||||
// m_chart->addSeries(m_series); | ||||
// seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | ||||
// // series 3 | ||||
// m_series = new QScatterSeries; | ||||
// m_series->setModel(m_model); | ||||
// m_series->setModelMapping(4,5, Qt::Vertical); | ||||
// // series->setModelMapping(4,5, Qt::Horizontal); | ||||
// m_chart->addSeries(m_series); | ||||
// seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | ||||
} else if (m_pieRadioButton->isChecked()) { | ||||
|
r1230 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | ||
// pie 1 | ||||
|
r1231 | m_pieSeries = new QPieSeries; | ||
|
r1230 | |||
|
r1237 | m_pieMapper = new QVPieModelMapper; | ||
m_pieMapper->setValuesColumn(1); | ||||
m_pieMapper->setLabelsColumn(7); | ||||
|
r1231 | m_pieMapper->setSeries(m_pieSeries); | ||
|
r1230 | m_pieMapper->setModel(m_model); | ||
|
r1262 | m_pieMapper->setFirst(2); | ||
|
r1251 | // m_pieMapper->setCount(5); | ||
|
r1230 | // pieSeries->setModelMapper(mapper); | ||
|
r1231 | m_pieSeries->setLabelsVisible(true); | ||
|
r1251 | m_pieSeries->setPieSize(0.35); | ||
m_pieSeries->setHorizontalPosition(0.25); | ||||
m_pieSeries->setVerticalPosition(0.35); | ||||
|
r1230 | |||
|
r1231 | m_chart->addSeries(m_pieSeries); | ||
seriesColorHex = "#" + QString::number(m_pieSeries->slices().at(m_pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | ||||
|
r1251 | m_model->addMapping(seriesColorHex, QRect(1, 2, 1, 50)); | ||
|
r1230 | |||
// pieSeries->slices().at(0)->setValue(400); | ||||
// pieSeries->slices().at(0)->setLabel(QString("36")); | ||||
|
r1251 | // pie 2 | ||
m_pieSeries2 = new QPieSeries; | ||||
|
r1230 | |||
|
r1294 | m_pieMapper2 = new QVPieModelMapper; | ||
m_pieMapper2->setValuesColumn(0); | ||||
m_pieMapper2->setLabelsColumn(7); | ||||
m_pieMapper2->setModel(m_model); | ||||
m_pieMapper2->setSeries(m_pieSeries2); | ||||
m_pieMapper2->setFirst(2); | ||||
|
r1251 | |||
m_pieSeries2->setLabelsVisible(true); | ||||
m_pieSeries2->setPieSize(0.35); | ||||
m_pieSeries2->setHorizontalPosition(0.75); | ||||
m_pieSeries2->setVerticalPosition(0.65); | ||||
m_chart->addSeries(m_pieSeries2); | ||||
seriesColorHex = "#" + QString::number(m_pieSeries2->slices().at(m_pieSeries2->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | ||||
m_model->addMapping(seriesColorHex, QRect(0, 2, 1, 1000)); | ||||
|
r1230 | |||
// // pie 3 | ||||
// pieSeries = new QPieSeries; | ||||
// pieSeries->setModel(m_model); | ||||
// pieSeries->setModelMapping(2,2, Qt::Vertical); | ||||
// pieSeries->setLabelsVisible(true); | ||||
// pieSeries->setPieSize(0.35); | ||||
// pieSeries->setHorizontalPosition(0.5); | ||||
// pieSeries->setVerticalPosition(0.75); | ||||
// m_chart->addSeries(pieSeries); | ||||
// seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | ||||
// // special pie | ||||
// specialPie = new QPieSeries; | ||||
// specialPie->append(17, "1"); | ||||
// specialPie->append(45, "2"); | ||||
// specialPie->append(77, "3"); | ||||
// specialPie->append(37, "4"); | ||||
// specialPie->append(27, "5"); | ||||
// specialPie->append(47, "6"); | ||||
// specialPie->setPieSize(0.35); | ||||
// specialPie->setHorizontalPosition(0.8); | ||||
// specialPie->setVerticalPosition(0.75); | ||||
// specialPie->setLabelsVisible(true); | ||||
// m_chart->addSeries(specialPie); | ||||
} | ||||
|
r1164 | // else if (m_areaRadioButton->isChecked()) | ||
// { | ||||
// m_chart->setAnimationOptions(QChart::NoAnimation); | ||||
// QLineSeries* upperLineSeries = new QLineSeries; | ||||
// upperLineSeries->setModel(m_model); | ||||
// upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | ||||
// // upperLineSeries->setModelMappingRange(1, 5); | ||||
// QLineSeries* lowerLineSeries = new QLineSeries; | ||||
// lowerLineSeries->setModel(m_model); | ||||
// lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | ||||
// QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | ||||
// m_chart->addSeries(areaSeries); | ||||
// seriesColorHex = "#" + QString::number(areaSeries->brush().color().rgb(), 16).right(6).toUpper(); | ||||
// m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 5)); | ||||
// m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | ||||
// } | ||||
|
r1230 | else if (m_barRadioButton->isChecked()) | ||
{ | ||||
|
r1294 | m_chart->setAnimationOptions(QChart::SeriesAnimations); | ||
QGroupedBarSeries* barSeries = new QGroupedBarSeries(); | ||||
|
r1331 | |||
|
r1294 | int first = 3; | ||
|
r1331 | int count = 6; | ||
|
r1294 | QVBarModelMapper *mapper = new QVBarModelMapper; | ||
|
r1331 | mapper->setFirstBarSetColumn(2); | ||
mapper->setLastBarSetColumn(4); | ||||
|
r1294 | mapper->setFirst(first); | ||
|
r1331 | mapper->setCount(count); | ||
|
r1294 | mapper->setSeries(barSeries); | ||
mapper->setModel(m_model); | ||||
// barSeries->setModelMapper(mapper); | ||||
m_chart->addSeries(barSeries); | ||||
|
r1331 | |||
|
r1354 | QStringList categories; | ||
categories << "June" << "July" << "August" << "September" << "October" << "November"; | ||||
m_chart->axisX()->categories()->insert(categories); | ||||
|
r1294 | QList<QBarSet*> barsets = barSeries->barSets(); | ||
for (int i = 0; i < barsets.count(); i++) { | ||||
seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper(); | ||||
|
r1295 | m_model->addMapping(seriesColorHex, QRect(2 + i, first, 1, barsets.at(i)->count())); | ||
|
r1294 | } | ||
|
r1331 | |||
|
r1230 | } | ||
if (!m_barRadioButton->isChecked()) { | ||||
|
r1317 | // m_chart->axisX()->setRange(0, 500); | ||
// m_chart->axisY()->setRange(0, 220); | ||||
|
r1230 | } | ||
|
r1012 | m_chart->legend()->setVisible(true); | ||
|
r861 | |||
|
r878 | // repaint table view colors | ||
m_tableView->repaint(); | ||||
m_tableView->setFocus(); | ||||
} | ||||
|
r519 | } | ||
|
r1056 | void TableWidget::testPie() | ||
{ | ||||
|
r1231 | // m_pieMapper->setCount(-1); | ||
QPieSlice *slice = new QPieSlice("Hehe", 145); | ||||
slice->setLabelVisible(); | ||||
m_pieSeries->append(slice); | ||||
slice = new QPieSlice("Hoho", 34); | ||||
slice->setLabelVisible(); | ||||
m_pieSeries->append(slice); | ||||
|
r1230 | // m_series->modelMapper()->setMapX(4); | ||
// m_tableView->setColumnWidth(10, 250); | ||||
|
r1090 | // if (specialPie) { | ||
// specialPie->remove(specialPie->slices().at(2)); | ||||
// // specialPie->insert(4, new QPieSlice(45, "Hello"));//specialPie->slices.at(2)); | ||||
// specialPie->append(4, "heloo"); | ||||
// } | ||||
|
r1056 | } | ||
|
r1231 | void TableWidget::testPie2() | ||
{ | ||||
QPieSlice *slice; | ||||
if (m_pieSeries->count() > 0) { | ||||
slice = m_pieSeries->slices().last(); | ||||
m_pieSeries->remove(slice); | ||||
} | ||||
if (m_pieSeries->count() > 0) { | ||||
slice = m_pieSeries->slices().first(); | ||||
m_pieSeries->remove(slice); | ||||
} | ||||
} | ||||
|
r1236 | void TableWidget::testPie3() | ||
{ | ||||
QPieSlice *slice; | ||||
if (m_pieSeries->count() > 0) { | ||||
slice = m_pieSeries->slices().last(); | ||||
slice->setLabel("Dalej"); | ||||
slice->setValue(222); | ||||
} | ||||
if (m_pieSeries->count() > 0) { | ||||
slice = m_pieSeries->slices().first(); | ||||
slice->setLabel("Prawie"); | ||||
slice->setValue(111); | ||||
} | ||||
} | ||||
|
r1262 | void TableWidget::testXY() | ||
{ | ||||
|
r1275 | // if (m_series->type() != QAbstractSeries::SeriesTypeLine) { | ||
// m_series->append(QPointF(150, 75)); | ||||
// } | ||||
|
r1262 | |||
if (m_series->count() > 0) { | ||||
m_series->remove(m_series->points().last()); | ||||
} | ||||
} | ||||
|
r519 | TableWidget::~TableWidget() | ||
{ | ||||
|
r1006 | |||
|
r519 | } | ||