Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-97727

Tree Model Completer Example: tree model is broken due to bugs in MainWindow::modelFromFile

    XMLWordPrintable

Details

    • All
    • 9beae46b599be011aab9f44efc92d49309b72da3 (qt/qtbase/dev) 011118521b4fa3072bb2b118ab624228778c29a0 (qt/qtbase/6.2) 62aab2b89ded0ca906606c2975358b1b6fc771f6 (qt/tqtc-qtbase/5.15)

    Description

      commit 3fede6cb547b783377e833c9b269d4cecfe47e61 introduced bugs into Tree Model Completer Example:

      -        QString line = file.readLine();
      +        const QString line = QString::fromUtf8(file.readLine()).trimmed();
      

      Extra trimming here breaks everything because later we count whitespaces in the beginning of line to calculate item level in tree model:

      QRegularExpression re("^\\s+");
      const QRegularExpressionMatch match = re.match(line);
      -            if (line.startsWith("\t")) {
      -                level = match.capturedLength();
      -            } else {
      -                level = match.capturedLength()/4;
      -            }
      +            const int capLen = match.capturedLength();
      +            level = line.startsWith(QLatin1Char('\t')) ? capLen / 4 : capLen;
      

      Which is another bug: last line should be

      level = line.startsWith(QLatin1Char('\t')) ? capLen : capLen / 4;
      

      Or just

      level = capLen / 4;
      

      because treemodel.txt in resources is indented with spaces not tabs

      With trimming all nodes become 0-level nodes:

      But they should have different levels:

      Patch in attachement.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            jbornema Joerg Bornemann
            mugiseyebrows Stanislav Doronin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes