Hi and thank you for your answer,
In fact reset is called only 3 times for this table:
1-when the table is initialized and empty
2-when the table is refreshed to display only 20 lines
3-when the table is refreshed to display all lines (this is the case with bad performances.
All other calls are for other tables containing around 10 lines.
So, I can't reduce the number of call to reset.
Here is the code:
{
if (!index.
isValid()) return QVariant();
_SKGTRACEIN(10, "SKGObjectModelBase::data");
SKGObjectBase* obj = (SKGObjectBase*) index.internalPointer();
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
case Qt::UserRole: {
QString att
=listAttibutes
[index.
column()];
QString val
=obj
->getAttribute
(att
);
if (att.startsWith("f_")) {
double dval=SKGServices::stringToDouble(val);
return dval;
} else if (att.startsWith("i_")) {
return SKGServices::stringToInt(val);
} else if (att.startsWith("d_")) {
QDate dval
=SKGServices
::stringToTime(val
).
date();
if (role == Qt::DisplayRole) {
return KGlobal::locale()->formatDate (dval, KLocale::FancyShortDate);
} else {
return dval;
}
} else if (getRealTable()=="doctransaction" && att=="t_savestep") return "";
return val;
}
case Qt::TextColorRole: {
//Text color
QString att
=listAttibutes
[index.
column()];
if (att.startsWith("f_")) {
QVariant value_displayed
= SKGObjectModelBase
::data(index, Qt
::UserRole);
bool ok=false;
double value_double=value_displayed.toDouble(&ok);
if (ok
&& value_double<
0) return qVariantFromValue
(QColor(Qt
::red));
}
break;
}
case Qt::TextAlignmentRole: {
//Text alignment
QString att
=listAttibutes
[index.
column()];
return (int)(Qt::AlignVCenter|(att.startsWith("f_") || att.startsWith("i_") ? Qt::AlignRight : Qt::AlignLeft));
}
case Qt::DecorationRole: {
//Decoration
if (index.column() == 0 && getRealTable()=="node") {
SKGNodeObject node =*obj;
QStringList data
=SKGServices
::splitCSVLine(node.
getData());
if (data.
count()>
2) return qVariantFromValue
((QIcon) KIcon
(data.
at(2)));
else {
return qVariantFromValue
((QIcon) KIcon
(node.
getName()==i18n
("autostart") ?
"folder-bookmarks" : "folder"));
}
} else if (index.column() == 0 && getRealTable()=="doctransaction") {
return qVariantFromValue
((QIcon) KIcon
(obj
->getAttribute
("t_mode")=="U" ?
"edit-undo" :"edit-redo"));
} else if (getRealTable()=="doctransaction" && listAttibutes[index.column()]=="t_savestep") {
if (obj
->getAttribute
("t_savestep")=="Y") return qVariantFromValue
((QIcon) KIcon
("document-save"));
}
break;
}
case Qt::ToolTipRole: {
//Tooltip
if (getRealTable()=="doctransaction") {
document->getMessages(obj->getID(), msg);
int nbMessages=msg.count();
if (nbMessages) {
for (int i=0; i<nbMessages; ++i) {
if (i!=0) message+='\n';
message+=msg.at(i);
}
return message;
}
}
break;
}
default : {
}
}
}
QVariant SKGObjectModelBase::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
_SKGTRACEIN(10, "SKGObjectModelBase::data");
SKGObjectBase* obj = (SKGObjectBase*) index.internalPointer();
switch ( role ) {
case Qt::DisplayRole:
case Qt::EditRole:
case Qt::UserRole: {
QString att=listAttibutes[index.column()];
QString val=obj->getAttribute(att);
if (att.startsWith("f_")) {
double dval=SKGServices::stringToDouble(val);
return dval;
} else if (att.startsWith("i_")) {
return SKGServices::stringToInt(val);
} else if (att.startsWith("d_")) {
QDate dval=SKGServices::stringToTime(val).date();
if (role == Qt::DisplayRole) {
return KGlobal::locale()->formatDate (dval, KLocale::FancyShortDate);
} else {
return dval;
}
} else if (getRealTable()=="doctransaction" && att=="t_savestep") return "";
return val;
}
case Qt::TextColorRole: {
//Text color
QString att=listAttibutes[index.column()];
if (att.startsWith("f_")) {
QVariant value_displayed = SKGObjectModelBase::data(index, Qt::UserRole);
bool ok=false;
double value_double=value_displayed.toDouble(&ok);
if (ok && value_double<0) return qVariantFromValue(QColor(Qt::red));
}
break;
}
case Qt::TextAlignmentRole: {
//Text alignment
QString att=listAttibutes[index.column()];
return (int)(Qt::AlignVCenter|(att.startsWith("f_") || att.startsWith("i_") ? Qt::AlignRight : Qt::AlignLeft));
}
case Qt::DecorationRole: {
//Decoration
if (index.column() == 0 && getRealTable()=="node") {
SKGNodeObject node =*obj;
QStringList data=SKGServices::splitCSVLine(node.getData());
if (data.count()>2) return qVariantFromValue((QIcon) KIcon(data.at(2)));
else {
return qVariantFromValue((QIcon) KIcon(node.getName()==i18n("autostart") ? "folder-bookmarks" : "folder"));
}
} else if (index.column() == 0 && getRealTable()=="doctransaction") {
return qVariantFromValue((QIcon) KIcon(obj->getAttribute("t_mode")=="U" ? "edit-undo" :"edit-redo"));
} else if (getRealTable()=="doctransaction" && listAttibutes[index.column()]=="t_savestep") {
if (obj->getAttribute("t_savestep")=="Y") return qVariantFromValue((QIcon) KIcon("document-save"));
}
break;
}
case Qt::ToolTipRole: {
//Tooltip
if (getRealTable()=="doctransaction") {
QStringList msg;
document->getMessages(obj->getID(), msg);
int nbMessages=msg.count();
if (nbMessages) {
QString message;
for (int i=0; i<nbMessages; ++i) {
if (i!=0) message+='\n';
message+=msg.at(i);
}
return message;
}
}
break;
}
default : {
}
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
Bookmarks