void cPlot2d::setup2dPlot()
{
int totalRowCount = model->rowCount();
bool select(false);
//If user selects any items this model contains it
QModelIndexList list = selection.indexes();
QList<QTableWidgetItem *> selected = this->mTableWidget->selectedItems();
//Number of items selected
int selectCount = list.count();
int numRowsSelected(0);
for(int i=0;i<selectCount;++i)
{
if(list[i].column()==0)
++numRowsSelected;
}
QwtArray<double> x;
QwtArray<double> y;
QwtArray<double> xSelect;
QwtArray<double> ySelect;
if(totalRowCount > 0)
{
//Have any items been selected
if(selectCount>0)
{
select = true;
int i(0);
foreach(item, selected)
{
bool ok;
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(list.at(i).column() == 0)
{
if(ok && !item->text().isEmpty())
xSelect.push_back(value);
}
else
{
if(ok && !item->text().isEmpty())
ySelect.push_back(value);
}
++i;
}
// }
}
//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(model->data(index.sibling(i,0)).toDouble());
y.push_back(model->data(index.sibling(i,1)).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
if(select)
{
//User selected data to plot
curve->setData(xSelect, ySelect);
}
else
{
//Plot entire table
curve->setData(x, y);
}
// pen
// style
plot->replot();
cMainWindow::getInstance()->mWorkspace->addWindow(plot)->show();
}
else
{
cout << " NO DATA TO PLOT!! " << endl;
return;
}
} // cPlot2d::setup2dPlot