void cPlot2d::setup2dPlot()
{
int totalRowCount = this->mTableWidget->rowCount();
QList<QTableWidgetItem *> selected = this->mTableWidget->selectedItems();
QwtArray<double> x;
QwtArray<double> y;
if(totalRowCount > 0)
{
//Have any items been selected
if(selected.count() > 0)
{
foreach(item, selected)
{
bool ok = false;
double value = item->text().toDouble(&ok);
//For MVC, get the data out of the model
//Data is stored contiguously in list, so got to figure out what column data is in
//x=0 y=1
if(item->column() == 0)
{
if(ok && !item->text().isEmpty())
x.push_back(value);
}
else
{
if(ok && !item->text().isEmpty())
y.push_back(value);
}
}
}
//No items selected, load up entire table
else
{
for(int i=0; i<totalRowCount; ++i)
{
//For MVC, get the data out of the model
x.push_back(item0->text().toDouble());
y.push_back(item1->text().toDouble());
}
}
// Set up Qwt Plot stuff
plot->setTitle("2D Plot");
// axis titles
plot
->setAxisTitle
(QwtPlot::xBottom,
"x");
plot
->setAxisTitle
(QwtPlot::yLeft,
"y");
// curve
curve->attach(plot);
// data
curve->setData(x, y);
// pen
// style
plot->replot();
cMainWindow::getInstance()->mWorkspace->addWindow(plot)->show();
}
else
{
cout << " NO DATA TO PLOT!! " << endl;
return;
}
} // cPlot2d::setup2dPlot
void cPlot2d::setup2dPlot()
{
int totalRowCount = this->mTableWidget->rowCount();
QList<QTableWidgetItem *> selected = this->mTableWidget->selectedItems();
QTableWidgetItem *item;
QwtArray<double> x;
QwtArray<double> y;
if(totalRowCount > 0)
{
//Have any items been selected
if(selected.count() > 0)
{
foreach(item, selected)
{
bool ok = false;
double value = item->text().toDouble(&ok);
//For MVC, get the data out of the model
//Data is stored contiguously in list, so got to figure out what column data is in
//x=0 y=1
if(item->column() == 0)
{
if(ok && !item->text().isEmpty())
x.push_back(value);
}
else
{
if(ok && !item->text().isEmpty())
y.push_back(value);
}
}
}
//No items selected, load up entire table
else
{
for(int i=0; i<totalRowCount; ++i)
{
//For MVC, get the data out of the model
QTableWidgetItem* item0 = mTableWidget->item(i,0);
QTableWidgetItem* item1 = mTableWidget->item(i,1);
x.push_back(item0->text().toDouble());
y.push_back(item1->text().toDouble());
}
}
// Set up Qwt Plot stuff
QwtPlot * plot(new QwtPlot(this));
plot->setTitle("2D Plot");
// axis titles
plot->setAxisTitle(QwtPlot::xBottom, "x");
plot->setAxisTitle(QwtPlot::yLeft, "y");
// curve
QwtPlotCurve * curve(new QwtPlotCurve("Curve 1"));
curve->attach(plot);
// data
curve->setData(x, y);
// pen
curve->setPen(QPen(QColor(0, 0, 200)));
// style
curve->setStyle(QwtPlotCurve::Lines);
plot->replot();
cMainWindow::getInstance()->mWorkspace->addWindow(plot)->show();
}
else
{
cout << " NO DATA TO PLOT!! " << endl;
return;
}
} // cPlot2d::setup2dPlot
To copy to clipboard, switch view to plain text mode
Bookmarks