Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProxySortFilterModel very slow
Forum Updated to NodeBB v4.3 + New Features

QProxySortFilterModel very slow

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cimer84
    wrote on last edited by
    #1

    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();
    }
    
    C 1 Reply Last reply
    0
    • C cimer84

      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();
      }
      
      C Offline
      C Offline
      cimer84
      wrote on last edited by
      #2

      Does anybody know any solution?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Did you try to benchmark your model ? You might be requesting lots of data just to get a few bits

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        C 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Did you try to benchmark your model ? You might be requesting lots of data just to get a few bits

          C Offline
          C Offline
          cimer84
          wrote on last edited by
          #4

          @SGaist I do not understand what you mean with benchmark . Can you explain it a little better?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved