Hi all,
I have my own model SettingsTreeModel (which is editable) and here is the part of my code:
{
StackTrace st("stm setdata");
if (role != Qt::EditRole)
return false;
SettingsNode *node = static_cast<SettingsNode *>(index.internalPointer());
switch(index.column()) {
case 0:
node->setName(value.toString());
break;
case 1:
node->setAttributeMap(AttributeMap(value.toString()));
break;
case 2:
beginInsertRows(index,0,0); //a new row may be prepended.
st.
addExtraInfo(QString("beginInsertRows(%1, %2, %3)").
arg(reinterpret_cast<unsigned>
(index.
internalPointer())).
arg(0).
arg(0));
node->setValue(value.toString());
endInsertRows(); //maybe?
break;
default:
return false;
}
emit dataChanged(index, index);
return true;
}
bool SettingsTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
StackTrace st("stm setdata");
if (role != Qt::EditRole)
return false;
SettingsNode *node = static_cast<SettingsNode *>(index.internalPointer());
QStringList attributeList;
switch(index.column()) {
case 0:
node->setName(value.toString());
break;
case 1:
node->setAttributeMap(AttributeMap(value.toString()));
break;
case 2:
beginInsertRows(index,0,0); //a new row may be prepended.
st.addExtraInfo(QString("beginInsertRows(%1, %2, %3)").arg(reinterpret_cast<unsigned>(index.internalPointer())).arg(0).arg(0));
node->setValue(value.toString());
endInsertRows(); //maybe?
break;
default:
return false;
}
emit dataChanged(index, index);
return true;
}
To copy to clipboard, switch view to plain text mode
Here the data is changed (new row is inserted) but view doesn't show it. why do u think?
btw, i tested my model againist qt labs' modeltest and there isn't any error.
Bookmarks