QProxySortFilterModel very slow
-
I have a QsortFilterProxyModel that it has to sort more than 1000 flights. It is very slow, Does anyone know any solution for faster sorting?
I show the code (model and QSortFilterProxyModel).
flightsModel = new LroOptimalDelayedFlightPlansModel(); sortModel = new QSortFilterProxyModel(this); sortModel->setSourceModel(flightsModel); ui->tableViewFlightPlans->setModel(sortModel); QVariant LroDelayedFlightPlansModel::data(const QModelIndex &index, int role) const { if ((!index.isValid()) || (index.row() >= rowCount(index))) { return QVariant(); } if (role == Qt::DisplayRole) { if (index.column() == 0) { return QString::fromStdString(fp.getFPs(index.row()).getCallsign()); } else if (index.column() == 1) { return QString::fromStdString(fp.getFPs(index.row()).getOpType()); } else if (index.column() == 2) { if (fp.getFPs(index.row()).getOpType() == "DEP") { return QString::fromStdString( fp.getFPs(index.row()).getDepartureTimes().getItot()); } else { return QString::fromStdString( fp.getFPs(index.row()).getArrivalTimes().getIldt()); } } else if (index.column() == 3) { if (fp.getFPs(index.row()).getOpType() == "DEP") { return QString::fromStdString( fp.getFPs(index.row()).getDepartureTimes().getStot()); } else { return QString::fromStdString( fp.getFPs(index.row()).getArrivalTimes().getSldt()); } } else if (index.column() == 4) { if (fp.getFPs(index.row()).getOpType() == "DEP") { return QString::fromStdString( fp.getFPs(index.row()).getDepartureTimes().getFtot()); } else { return QString::fromStdString( fp.getFPs(index.row()).getArrivalTimes().getFldt()); } } else if (index.column() == 5) { return QVariant(fp.getFPs(index.row()).getForecastDelay()); } else if (index.column() == 6) { return QVariant(fp.getFPs(index.row()).getPunctualityDelay()); } else if (index.column() == 7) { return QString::fromStdString( fp.getFPs(index.row()).getAssignedRunway()); } return QVariant(); } else if (role == Qt::TextAlignmentRole) { return Qt::AlignCenter; } else if (role == Qt::BackgroundRole) { if (index.column() == 0) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorCallsing())); } else if (index.column() == 1) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorType())); } else if (index.column() == 2) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorItotIldt())); } else if (index.column() == 3) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorStotSldt())); } else if (index.column() == 4) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorFtotFldt())); } else if (index.column() == 5) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorForecastedDelay())); } else if (index.column() == 6) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorPunctualityDelay())); } else if (index.column() == 7) { return QColor(QString::fromStdString( LrbConfigurationHmiParameters::GetInstance()->getConfigurationHmiParameters().getFlightTabColors().getColorRwyAllocated())); } } return QVariant(); }
-
Does anybody know any solution?
-
Hi,
Did you try to benchmark your model ? You might be requesting lots of data just to get a few bits
-
@SGaist I do not understand what you mean with benchmark . Can you explain it a little better?
-
I mean check the performance of your model.
e.g. you call fp.getFPs several time in the same scope, so why not just retrieve the object once and then call the other getters on it ?
Also, how long take the getDeparture/ArrivalTimes call ?
etc.