##// END OF EJS Templates
tablemodelchart: added coloring to TableView
tablemodelchart: added coloring to TableView

File last commit:

r849:52126f8b50e7
r849:52126f8b50e7
Show More
tablewidget.cpp
306 lines | 11.7 KiB | text/x-c | CppLexer
Jani Honkonen
Add/modify license headers
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$
**
****************************************************************************/
Marek Rosa
Table model data example
r519 #include "tablewidget.h"
#include <QGridLayout>
#include <QTableView>
#include <QStyledItemDelegate>
Marek Rosa
tablemodelchart: added coloring to TableView
r849 #include <QLineSeries>
#include <QSplineSeries>
#include <QScatterSeries>
Marek Rosa
Table model data example
r519 #include "customtablemodel.h"
Marek Rosa
tablemodelchart: added coloring to TableView
r849 #include <QPieSeries>
#include <QPieSlice>
#include <QAreaSeries>
#include <QBarSeries>
#include <QBarSet>
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 #include <QPushButton>
#include <QRadioButton>
Marek Rosa
Some more work on mapping with limits
r735 #include <QSpinBox>
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 #include <QTime>
Marek Rosa
Table model data example
r519
TableWidget::TableWidget(QWidget *parent)
: QWidget(parent)
{
Marek Rosa
Model data example updated
r546 setGeometry(100, 100, 1000, 600);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
Marek Rosa
Table model data example
r519 // create simple model for storing data
// user's table data model
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 m_model = new CustomTableModel;
Marek Rosa
XYSeries model with limits working.
r833 m_tableView = new QTableView;
m_tableView->setModel(m_model);
m_tableView->setMinimumHeight(240);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 // tableView->setMinimumSize(340, 480);
// tableView->setItemDelegate(new QStyledItemDelegate);
Marek Rosa
XYSeries model with limits working.
r833 m_chart = new QChart;
m_chartView = new QChartView(m_chart);
m_chartView->setRenderHint(QPainter::Antialiasing);
m_chartView->setMinimumSize(640, 480);
Marek Rosa
Table model data example
r519
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 // add, remove data buttons
Marek Rosa
Model data example updated
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()));
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545
QPushButton* removeRowButton = new QPushButton("Remove row");
connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
Marek Rosa
XYSeries model with limits working.
r833 m_linesCountSpinBox = new QSpinBox;
m_linesCountSpinBox->setRange(1, 10);
m_linesCountSpinBox->setValue(1);
Marek Rosa
Some more work on mapping with limits
r735
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 // buttons layout
QVBoxLayout* buttonsLayout = new QVBoxLayout;
Marek Rosa
XYSeries model with limits working.
r833 buttonsLayout->addWidget(m_linesCountSpinBox);
Marek Rosa
Model data example updated
r546 buttonsLayout->addWidget(addRowAboveButton);
buttonsLayout->addWidget(addRowBelowButton);
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 buttonsLayout->addWidget(removeRowButton);
buttonsLayout->addStretch();
// chart type radio buttons
Marek Rosa
XYSeries model with limits working.
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");
connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
m_lineRadioButton->setChecked(true);
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545
// radio buttons layout
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 QVBoxLayout* radioLayout = new QVBoxLayout;
Marek Rosa
XYSeries model with limits working.
r833 radioLayout->addWidget(m_lineRadioButton);
radioLayout->addWidget(m_splineRadioButton);
radioLayout->addWidget(m_scatterRadioButton);
radioLayout->addWidget(m_pieRadioButton);
radioLayout->addWidget(m_areaRadioButton);
radioLayout->addWidget(m_barRadioButton);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 radioLayout->addStretch();
Marek Rosa
Table model data example
r519
// create main layout
QGridLayout* mainLayout = new QGridLayout;
Marek Rosa
XYSeries model with limits working.
r833 mainLayout->addLayout(buttonsLayout, 1, 1);
mainLayout->addLayout(radioLayout, 2, 1);
mainLayout->addWidget(m_tableView, 1, 0);
mainLayout->addWidget(m_chartView, 2, 0);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 setLayout(mainLayout);
Marek Rosa
XYSeries model with limits working.
r833 m_lineRadioButton->setFocus();
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 }
Marek Rosa
Model data example updated
r546 void TableWidget::addRowAbove()
{
Marek Rosa
XYSeries model with limits working.
r833 m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value());
Marek Rosa
Model data example updated
r546
}
void TableWidget::addRowBelow()
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 {
Marek Rosa
XYSeries model with limits working.
r833 m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value());
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545
}
void TableWidget::removeRow()
{
Marek Rosa
XYSeries model with limits working.
r833 m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value()));
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 }
void TableWidget::updateChartType()
{
Marek Rosa
XYSeries model with limits working.
r833 m_chart->removeAllSeries();
Marek Rosa
tablemodelchart: added coloring to TableView
r849 m_model->clearMapping();
QString seriesColorHex = "#000000";
QPen pen;
pen.setWidth(2);
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545
Marek Rosa
XYSeries model with limits working.
r833 if (m_lineRadioButton->isChecked())
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 {
Marek Rosa
Some more work on mapping with limits
r735
Marek Rosa
tablemodelchart: added coloring to TableView
r849 m_chart->axisX()->setRange(0, 500);
m_chart->axisY()->setRange(0, 120);
Marek Rosa
Some more work on mapping with limits
r735
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 // series 1
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QLineSeries;
m_series->setModel(m_model);
m_series->setModelMapping(0,1, Qt::Vertical);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 m_series->setModelMappingShift(1, 4);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(m_series);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630
// series 2
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QLineSeries;
m_series->setModel(m_model);
m_series->setModelMapping(2,3, Qt::Vertical);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 m_chart->addSeries(m_series);
seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
Marek Rosa
Some more work on mapping with limits
r735
Marek Rosa
tablemodelchart: added coloring to TableView
r849 // series 3
m_series = new QLineSeries;
m_series->setModel(m_model);
m_series->setModelMapping(4,5, Qt::Vertical);
m_series->setModelMappingShift(2, 0);
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));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 }
Marek Rosa
XYSeries model with limits working.
r833 else if (m_splineRadioButton->isChecked())
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 {
// series 1
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QSplineSeries;
m_series->setModel(m_model);
m_series->setModelMapping(0,1, Qt::Vertical);
m_series->setModelMappingShift(1, 4);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 // series->setModelMapping(0,1, Qt::Horizontal);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(m_series);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630
// series 2
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QSplineSeries;
m_series->setModel(m_model);
m_series->setModelMapping(2,3, Qt::Vertical);
m_series->setModelMappingShift(0, 0);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 // series->setModelMapping(2,3, Qt::Horizontal);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(m_series);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630
// series 3
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QSplineSeries;
m_series->setModel(m_model);
m_series->setModelMapping(4,5, Qt::Vertical);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 m_series->setModelMappingShift(2, 0);
// series->setModelMapping(4,5, Qt::Horizontal);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(m_series);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 }
Marek Rosa
XYSeries model with limits working.
r833 else if (m_scatterRadioButton->isChecked())
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 {
// series 1
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QScatterSeries;
m_series->setModel(m_model);
m_series->setModelMapping(0,1, Qt::Vertical);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 m_series->setModelMappingShift(2, 0);
// series->setModelMapping(0,1, Qt::Horizontal);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(m_series);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 // series 2
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QScatterSeries;
m_series->setModel(m_model);
m_series->setModelMapping(2,3, Qt::Vertical);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 m_series->setModelMappingShift(1, 6);
// series->setModelMapping(2,3, Qt::Horizontal);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(m_series);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 // series 3
Marek Rosa
XYSeries model with limits working.
r833 m_series = new QScatterSeries;
m_series->setModel(m_model);
m_series->setModelMapping(4,5, Qt::Vertical);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 // series->setModelMapping(4,5, Qt::Horizontal);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(m_series);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 }
Marek Rosa
XYSeries model with limits working.
r833 else if (m_pieRadioButton->isChecked())
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 {
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 // pie 1
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 QPieSeries* pieSeries = new QPieSeries;
pieSeries->setModel(m_model);
Marek Rosa
Barchart updates on BarSet->SetValue now
r655 pieSeries->setModelMapping(0,0, Qt::Vertical);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 pieSeries->setLabelsVisible(true);
pieSeries->setPieSize(0.4);
pieSeries->setPiePosition(0.2, 0.35);
Marek Rosa
tablemodelchart: added coloring to TableView
r849
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(pieSeries);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630
// pie 2
pieSeries = new QPieSeries;
pieSeries->setModel(m_model);
Marek Rosa
Barchart updates on BarSet->SetValue now
r655 pieSeries->setModelMapping(1,1, Qt::Vertical);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 pieSeries->setLabelsVisible(true);
pieSeries->setPieSize(0.4);
pieSeries->setPiePosition(0.8, 0.35);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(pieSeries);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630
// pie 3
pieSeries = new QPieSeries;
pieSeries->setModel(m_model);
Marek Rosa
Barchart updates on BarSet->SetValue now
r655 pieSeries->setModelMapping(2,2, Qt::Vertical);
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 pieSeries->setLabelsVisible(true);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 pieSeries->setPieSize(0.4);
pieSeries->setPiePosition(0.5, 0.65);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(pieSeries);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 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));
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 }
Marek Rosa
XYSeries model with limits working.
r833 else if (m_areaRadioButton->isChecked())
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 {
QLineSeries* upperLineSeries = new QLineSeries;
upperLineSeries->setModel(m_model);
upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
QLineSeries* lowerLineSeries = new QLineSeries;
lowerLineSeries->setModel(m_model);
lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(areaSeries);
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 }
Marek Rosa
XYSeries model with limits working.
r833 else if (m_barRadioButton->isChecked())
Marek Rosa
Added support for data from model to QBarSeries. Various fixes and small modifications to data from model support to other series
r630 {
QBarSeries* barSeries = new QBarSeries(QStringList());
barSeries->setModel(m_model);
barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
barSeries->setToolTipEnabled(true);
Marek Rosa
XYSeries model with limits working.
r833 m_chart->addSeries(barSeries);
Marek Rosa
tablemodelchart: added coloring to TableView
r849 for (int i = 0; i < barSeries->barsetCount(); i++) {
seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper();
m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000));
}
Marek Rosa
Added data from model support to QPieSeries(modify, remove). Data from model example updated
r597 }
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545
Marek Rosa
tablemodelchart: added coloring to TableView
r849 // repaint table view colors
m_tableView->repaint();
m_tableView->setFocus();
Marek Rosa
Table model data example
r519 }
TableWidget::~TableWidget()
{
}