QDataWidgetMapper setting own model index
Hi,
I have a SQL table model that maps RFID EPC codes to table indexes like this:
Code:
enum
{
RFID_ID = 0,
RFID_EPC = 1,
RFID_Name = 2,
};
{
Q_OBJECT
public:
RfidTagForm
(int id,
QWidget* parent
= 0);
private slots:
void addTag();
void deleteTag();
private:
[...]
};
Code:
{
[...]
mTableModel->setTable("rfidtags");
mTableModel->setSort(RFID_ID, Qt::AscendingOrder);
mTableModel->select();
mMapper->setModel(mTableModel);
mMapper->addMapping(mEPCEdit, RFID_EPC);
mMapper->addMapping(mNameEdit, RFID_Name);
[...]
if (id != -1)
{
for (int row = 0; row < mTableModel->rowCount(); ++row)
{
if (record.value(RFID_ID).toInt() == id)
{
mMapper->setCurrentIndex(row);
}
}
}
else
{
mMapper->toFirst();
}
connect(mFirstButton, SIGNAL(clicked()), mMapper, SLOT(toFirst()));
connect(mPreviousButton, SIGNAL(clicked()), mMapper, SLOT(toPrevious)));
connect(mNextButton, SIGNAL(clicked()), mMapper, SLOT(toNext()));
connect(mLastButton, SIGNAL(clicked()), mMapper, SLOT(toLast()));
connect(mAddButton, SIGNAL(clicked()), this, SLOT(addTag()));
connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(deleteTag()));
[...]
// set up the UI stuff...
}
void RfidTagForm::addTag()
{
int row = mMapper->currentIndex();
mMapper->submit();
mTableModel->insertRow(row);
mMapper->setCurrentIndex(row);
mEPCEdit->clear();
mNameEdit->clear();
}
void RfidTagForm::deleteTag()
{
int row = mMapper->currentIndex();
mTableModel->removeRow(row);
mMapper->submit();
mMapper->setCurrentIndex(qMin(row, mTableModel->rowCount() - 1));
}
If the user now edits a new tag data and inserts a new RFID EPC Hex code (EPC is a long hex number to identify the tag) this should be converted to integer and taken as the record's ID for the table. But as far as I understand, QDataWidgetMapper sets the index automatically if it is set to AutoSubmit.
So is there any possibility to take influence on the data record ID when adding/deleting data records from the table? Or do I have to make this submit manual (ie set ManualSubmit and implement the slots for QDataWidgetMapper myself), but this does not solve my problem that I don't know the data record's index before the user has not edited the EPC line edit so that I can calculate the hex to integer record ID.
Thanks for any hint on this,
AlGaN