Here is the code for the tableView that is in reverse order and not highlighted correctly:
dlgprint.cpp
@void DlgPrint::createReportTable(QStringList stringList) //strinLlist is used elsewhere
{
printModel= new QSqlRelationalTableModel (this);
printModel-> setEditStrategy(QSqlTableModel::OnManualSubmit);
printModel-> setTable (mTableName); //string identified through assessor function
printModel-> setRelation (2, QSqlRelation("student", "id", "LName"));
printModel-> setRelation (3, QSqlRelation("testNum", "id", "Test"));
printModel->setFilter(mFilterString);
printModel->select();
proxy = new MyProxyModel(this);
proxy->setSourceModel(printModel);
ui->printView->setModel(proxy);
connect(this,SIGNAL(sendRows(int, int, int, int)),
proxy, SLOT(getRows(int, int, int, int)));
ui->printView->setItemDelegate(new QSqlRelationalDelegate(this));
ui->printView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->printView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->printView->setColumnHidden(0,true);//id
ui->printView->resizeColumnsToContents();
printModel->setHeaderData (2, Qt::Horizontal, "Score");
ui->printView->setSortingEnabled(true);
ui->printView->resizeColumnsToContents () ;
ui->printView->horizontalHeader()->setStretchLastSection(true);
highlightCells();
printModel->select();
}
void DlgPrint::highlightCells()
{
float highScore= FLT_MIN;
float lowScore= FLT_MAX;
float fastReactionTime=FLT_MAX;
float slowReactionTime=FLT_MIN;
int rowHigh=0;
int rowLow=0;
int rowFastReact=0;
int rowSlowReact=0;
float totalTime =0;
float totalReactTime=0;
float averageScore =0;
float averageReact=0;
int totalRows = 0;
float currentScore;
float currentReactTime;
QString string;
int numRows =proxy->rowCount();
for (int r=0; r<numRows; r++ )
{
currentscore = proxy->index(r,2).data(Qt::DisplayRole).toFloat();
currentReactTime = proxy->index(r,3).data(Qt::DisplayRole).toFloat();
//something here to mapToSource??
if (currentScore > highScore)
{
highScore = currentScore;
rowHigh = r;
}
if (currentScore < lowScore)
{
lowScore = currentScore;
rowLow = r;
}
totalRows++;
totalScore += currentScore;
if (currentReactTime < fastReactionTime)
{
fastReactionTime = currentReactTime;
rowFastReact = r;
}
if (currentReactTime > slowReactionTime)
{
slowReactionTime = currentReactTime;
rowSlowReact = r;
}
totalReactTime += currentReactTime;
}
}
if (totalRows !=0)
{
averageScore=totalScore/totalRows;
averageReact=totalReactTime/totalRows;
}
emit sendRows (rowSlow, rowFast,rowSlowReact, rowFastReact);
}@
I tried to eliminate the code that was irrelevant to the table creation. Hopefully I didn't forget something. What is wrong here?