connect(model, SIGNAL(itemChanged(QStandardItem *)), this, SLOT(updatePanel(QStandardItem*)));
To copy to clipboard, switch view to plain text mode
#include "plotpanel.h"
#include <QHBoxLayout>
#include <QDebug>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
PlotPanel
::PlotPanel(QWidget *parent
) :{
mainLayout->addWidget(plot);
this->setLayout(mainLayout);
}
{
plot
->setAxisScale
(QwtPlot::yLeft,
0.0,
10);
plot
->setAxisScale
(QwtPlot::xBottom,
0.0,
10);
curve->setTitle(tr("Points"));
curve
->setPen
(QPen(Qt
::blue,
4));
curve
->setRenderHint
(QwtPlotItem::RenderAntialiased,
true);
curve->setSymbol(symbol);
double x, y;
for (int row = 0; row < model->rowCount(); row++) {
x = model->data(index).toDouble();
index = model->index(row, 1);
y = model->data(index).toDouble();
}
curve->setSamples(points);
curve->attach(plot);
// this->update();
}
#include "plotpanel.h"
#include <QHBoxLayout>
#include <QDebug>
#include <qwt_plot_curve.h>
#include <qwt_symbol.h>
PlotPanel::PlotPanel(QWidget *parent) :
QDialog(parent)
{
plot = new QwtPlot;
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(plot);
this->setLayout(mainLayout);
}
void PlotPanel::updatePanel(QStandardItemModel *model)
{
plot->setAxisScale(QwtPlot::yLeft, 0.0, 10);
plot->setAxisScale(QwtPlot::xBottom, 0.0, 10);
QwtPlotCurve *curve = new QwtPlotCurve;
curve->setTitle(tr("Points"));
curve->setPen(QPen(Qt::blue, 4));
curve->setRenderHint(QwtPlotItem::RenderAntialiased, true);
QwtSymbol *symbol = new QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::yellow),
QPen(Qt::red, 2), QSize(8, 8));
curve->setSymbol(symbol);
QPolygonF points;
double x, y;
for (int row = 0; row < model->rowCount(); row++) {
QModelIndex index = model->index(row, 0);
x = model->data(index).toDouble();
index = model->index(row, 1);
y = model->data(index).toDouble();
points << QPointF(x, y);
}
curve->setSamples(points);
curve->attach(plot);
// this->update();
}
To copy to clipboard, switch view to plain text mode
Bookmarks