Hi,
I have a QTableView with over 10000 entries.
I have derived from QAbstractTableModel a custom model with this data() member function
QVariant log_q_item_model
::data(const QModelIndex
& index,
int role
) const {
if (index.isValid() && index.row()>=0 && static_cast<size_t>(index.row())<log_->size() && role==Qt::DisplayRole) {
const logentry& e = (*log_)[index.row()];
return (index.column()==0)?
QString(boost
::gregorian::to_simple_string(e.
get_date()).
c_str()): QString::number(e.
get_total(),
'f',
2);
}
}
QVariant log_q_item_model::data(const QModelIndex& index, int role) const
{
if (index.isValid() && index.row()>=0 && static_cast<size_t>(index.row())<log_->size() && role==Qt::DisplayRole) {
const logentry& e = (*log_)[index.row()];
return (index.column()==0)?
QString(boost::gregorian::to_simple_string(e.get_date()).c_str()):
QString::number(e.get_total(),'f',2);
}
return QVariant();
}
To copy to clipboard, switch view to plain text mode
The model has a private
shared_ptr< vector<logentry> >
shared_ptr< vector<logentry> >
To copy to clipboard, switch view to plain text mode
which points to a vector of
logentry
logentry
To copy to clipboard, switch view to plain text mode
.
The
get_date()
get_date()
To copy to clipboard, switch view to plain text mode
and
get_total()
get_total()
To copy to clipboard, switch view to plain text mode
are inline functions that return members of logentry.
I have commented out the implementation of the
data()
data()
To copy to clipboard, switch view to plain text mode
function and the display of the TableView widget (all blanks) takes now half a second, instead of 5 seconds.
My bottleneck is definitely here.
I have replaced the return statement by
return QString::number(e.
get_total(),
'f',
2);
return QString::number(e.get_total(),'f',2);
To copy to clipboard, switch view to plain text mode
and it takes half the time roughly.
It seems the QString functions are in my case quite slow.
Ideas for speeding this up are appreciated?
Regards,
Bookmarks