##// END OF EJS Templates
combined clicked and rightclicked events of legend to one event with parameter
combined clicked and rightclicked events of legend to one event with parameter

File last commit:

r546:3faf122e2566
r567:17f0257049a1
Show More
tablewidget.cpp
121 lines | 3.6 KiB | text/x-c | CppLexer
Marek Rosa
Table model data example
r519 #include "tablewidget.h"
#include <QGridLayout>
#include <QTableView>
#include <QStyledItemDelegate>
#include "qlineseries.h"
#include "qsplineseries.h"
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 #include "qscatterseries.h"
Marek Rosa
Table model data example
r519 #include "customtablemodel.h"
#include "qpieseries.h"
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 #include <QPushButton>
#include <QRadioButton>
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
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;
tableView = new QTableView;
tableView->setModel(m_model);
Marek Rosa
Table model data example
r519 tableView->setMinimumSize(340, 480);
// tableView->setItemDelegate(new QStyledItemDelegate);
Marek Rosa
Model data example updated
r546 chartView = new QChartView(this);
Marek Rosa
Table model data example
r519 chartView->setMinimumSize(640, 480);
// create
// QLineSeries* series = new QLineSeries;
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 // QSplineSeries* series = new QSplineSeries;
// QScatterSeries* series = new QScatterSeries;
// series->setModel(m_model);
// series->setModelMapping(0,1, Qt::Vertical);
Marek Rosa
Table model data example
r519
// QPieSeries* pieSeries = new QPieSeries;
// pieSeries->setModel(model);
// pieSeries
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 // chartView->addSeries(series);
// 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()));
// buttons layout
QVBoxLayout* buttonsLayout = new QVBoxLayout;
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
lineRadioButton = new QRadioButton("Line");
splineRadioButton = new QRadioButton("Spline");
scatterRadioButton = new QRadioButton("Scatter");
connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
lineRadioButton->setChecked(true);
// radio buttons layout
QHBoxLayout* radioLayout = new QHBoxLayout;
radioLayout->addWidget(lineRadioButton);
radioLayout->addWidget(splineRadioButton);
radioLayout->addWidget(scatterRadioButton);
Marek Rosa
Table model data example
r519
// create main layout
QGridLayout* mainLayout = new QGridLayout;
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 mainLayout->addLayout(buttonsLayout, 0, 1);
mainLayout->addLayout(radioLayout, 0, 2);
Marek Rosa
Table model data example
r519 mainLayout->addWidget(tableView, 1, 1);
mainLayout->addWidget(chartView, 1, 2);
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 setLayout(mainLayout);
}
Marek Rosa
Model data example updated
r546 void TableWidget::addRowAbove()
{
// m_model->insertRow(m_model->rowCount());
m_model->insertRow(tableView->currentIndex().row());
}
void TableWidget::addRowBelow()
Marek Rosa
Added support for adding and removing data with model. Updated the example
r545 {
// m_model->insertRow(m_model->rowCount());
m_model->insertRow(tableView->currentIndex().row() + 1);
}
void TableWidget::removeRow()
{
// m_model->removeRow(m_model->rowCount() - 1);
m_model->removeRow(tableView->currentIndex().row());
}
void TableWidget::updateChartType()
{
chartView->removeAllSeries();
if (lineRadioButton->isChecked())
series = new QLineSeries;
else if (splineRadioButton->isChecked())
series = new QSplineSeries;
else
series = new QScatterSeries;
series->setModel(m_model);
series->setModelMapping(0,1, Qt::Vertical);
chartView->addSeries(series);
Marek Rosa
Table model data example
r519 }
TableWidget::~TableWidget()
{
}