hml
15th March 2010, 19:28
Hello,
I have this abstract table model
class log_q_item_model : public QAbstractTableModel {
Q_OBJECT
public:
log_q_item_model(const log_ptr& log) /// log_ptr is boost:;shared_ptr< std::vector< std::pair<date, double> > >
: log_(log)
{}
int rowCount(const QModelIndex&) const
{
return log_->size();
}
int columnCount(const QModelIndex&) const
{
return 2;
}
QVariant 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_t& e = (*log_)[index.row()];
return (index.column()==0)?
QString(boost::gregorian::to_simple_string(e.first ).c_str()):
QString::number(e.second,'f',2);
}
return QVariant();
}
QVariant headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return tr("Date");
case 1:
return tr("Logname");
default:
return QVariant();
}
}
return QVariant();
}
private:
const log_ptr log_;
};
that use with a QTableView to display about 10 000 entries.
It is a bit slow to display? I know because I filled up the log vector before without displaying it and the GUI was faster.
I would appreciate any hints as to where to optimize this class?
Regards,
I have this abstract table model
class log_q_item_model : public QAbstractTableModel {
Q_OBJECT
public:
log_q_item_model(const log_ptr& log) /// log_ptr is boost:;shared_ptr< std::vector< std::pair<date, double> > >
: log_(log)
{}
int rowCount(const QModelIndex&) const
{
return log_->size();
}
int columnCount(const QModelIndex&) const
{
return 2;
}
QVariant 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_t& e = (*log_)[index.row()];
return (index.column()==0)?
QString(boost::gregorian::to_simple_string(e.first ).c_str()):
QString::number(e.second,'f',2);
}
return QVariant();
}
QVariant headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case 0:
return tr("Date");
case 1:
return tr("Logname");
default:
return QVariant();
}
}
return QVariant();
}
private:
const log_ptr log_;
};
that use with a QTableView to display about 10 000 entries.
It is a bit slow to display? I know because I filled up the log vector before without displaying it and the GUI was faster.
I would appreciate any hints as to where to optimize this class?
Regards,