Re: Editable SqlQueryModel
You will have to reimplement the setData() function and store the edited data in your model subclass.
In data() you then need to check if you have local data for the respective cell and return it instead.
From you description I take that you have only one such column, so a simple mapping from inf (row) to QVariant (data) should do the trick for the local storage.
Cheers,
_
Re: Editable SqlQueryModel
Quote:
Originally Posted by
anda_skoa
You will have to reimplement the setData() function and store the edited data in your model subclass.
In data() you then need to check if you have local data for the respective cell and return it instead.
From you description I take that you have only one such column, so a simple mapping from inf (row) to QVariant (data) should do the trick for the local storage.
Cheers,
_
Thanks for the tip.. However, being a beginner, I can't wrap my head around it..
tried this and I know something is missing as setData is not calling Data()
Code:
QByteRef EditableSQLModel
::data(const QModelIndex &index,
int role
){
if (value!="")
return value.toByteArray();
else
return ArgsLength;
}
bool EditableSQLModel
::setData(const QModelIndex &index,
const QVariant &value,
int /* role */) {
if (index.column() !=1)
return false;
ArgsLength= value;
return 1;
}
Re: Editable SqlQueryModel
You would have something like this
Code:
{
private:
QHash<int, QVariant> m_localData;
};
In setData() you would store depending on row
Code:
if (index.column() == 1) {
m_localData.insert(index.row(), value);
}
in data() you would check if you have local data
Code:
if (index.column() == 1 && m_localData.contains(index.row()) {
return m_localData.value(index.row())
}
// else get value from base class
Cheers,
_
Re: Editable SqlQueryModel
Quote:
Originally Posted by
anda_skoa
You would have something like this
Code:
{
private:
QHash<int, QVariant> m_localData;
};
In setData() you would store depending on row
Code:
if (index.column() == 1) {
m_localData.insert(index.row(), value);
}
in data() you would check if you have local data
Code:
if (index.column() == 1 && m_localData.contains(index.row()) {
return m_localData.value(index.row())
}
// else get value from base class
Cheers,
_
Thanks a lot.. Now it makes sense :)