Ok, figured it out... For anyone else who might be experiencing similar issues the fix that I am using is:
void employeeForm::go2First()
{
int row = mapper->currentIndex();
if(! mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertAll();
}
mapper->toFirst();
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
void employeeForm::go2Prev()
{
int row = mapper->currentIndex();
if(! mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertRow(row);
}
if(row > 0)
row--;
mapper->setCurrentIndex(row);
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
void employeeForm::go2Next()
{
int row = mapper->currentIndex();
if(!mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertRow(row);
row--;
}
mapper->setCurrentIndex(row);
mapper->toNext();
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
void employeeForm::go2Last()
{
int row = mapper->currentIndex();
if(!mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertRow(row);
row--;
}
mapper->setCurrentIndex(row);
mapper->toLast();
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
void employeeForm::go2First()
{
int row = mapper->currentIndex();
if(! mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertAll();
}
mapper->toFirst();
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
void employeeForm::go2Prev()
{
int row = mapper->currentIndex();
if(! mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertRow(row);
}
if(row > 0)
row--;
mapper->setCurrentIndex(row);
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
void employeeForm::go2Next()
{
int row = mapper->currentIndex();
if(!mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertRow(row);
row--;
}
mapper->setCurrentIndex(row);
mapper->toNext();
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
void employeeForm::go2Last()
{
int row = mapper->currentIndex();
if(!mapper->submit())
{
qDebug()<<"lasterror:"<<tableModel->lastError().text();
tableModel->revertRow(row);
row--;
}
mapper->setCurrentIndex(row);
mapper->toLast();
nav->setCurrentRec(mapper->currentIndex()+1);
nav->setTotalRec(tableModel->rowCount());
}
To copy to clipboard, switch view to plain text mode
Basically, just check if the submit failed, if it did, revert the row changes and update the index counter to match... Then just handle the mapper and anything else!
AlphaWolfXV
Bookmarks