PDA

View Full Version : setData()



starcontrol
22nd April 2008, 16:48
Hey,
I am not sure how to use the setData() method in my custom model. It seems to be, that the data is changed well, but the view is not updated since i clicked with the mouse on some other widgets. I am not sure how to handle the emit dataChanged() OR reset() methods...
Anyone who can help me ?



bool SchulungsplanModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == StartKursRole)
{
int puVectorIndex = findKursByRowValue(index.row()).at(0);
int kurseVectorIndex = findKursByRowValue(index.row()).at(1);

QDate myCurrentCellDate = whereInTheDateAmI(index.column() );
QDate startKursDate = m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].getStartKursDatum();
QDate endKursDate = m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].getEndKursDatum();

bool dateBetweenCourseDate = isTheDateBetween( myCurrentCellDate, startKursDate, endKursDate);

if (dateBetweenCourseDate == true)
{
qDebug() << "startKursDatum: value.toDate().toString(): " << value.toDate().toString("dd.MM.yyyy");
m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].setStartKursDatum(value.toDate());
qDebug() << "startKursDatum changed in:" << m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].getStartKursDatum().toString("dd.MM.yyyy");
}
emit dataChanged(index, index);
//reset();
return true;
}

jacek
1st May 2008, 22:10
m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].setStartKursDatum(value.toDate());
Are you sure that getPU*() methods and [] operators don't return copies of your data?


emit dataChanged(index, index);
//reset();
return true;
This is OK.

You can try Modeltest (http://labs.trolltech.com/page/Projects/Itemview/Modeltest) to see whether your model is OK.

starcontrol
2nd May 2008, 09:54
oh yes, .... it returned copies instead of references - aua :-/