- 
    Bug 
- 
    Resolution: Done
- 
    P2: Important 
- 
    5.15.6, 6.2.0
- 
    None
- 
        
- 
        9beae46b599be011aab9f44efc92d49309b72da3 (qt/qtbase/dev) 011118521b4fa3072bb2b118ab624228778c29a0 (qt/qtbase/6.2) 62aab2b89ded0ca906606c2975358b1b6fc771f6 (qt/tqtc-qtbase/5.15)
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.
| For Gerrit Dashboard: QTBUG-97727 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V | 
| 378336,2 | Fix treemodelcompleter example | dev | qt/qtbase | Status: MERGED | +2 | 0 | 
| 378751,2 | Fix treemodelcompleter example | 6.2 | qt/qtbase | Status: MERGED | +2 | 0 | 
| 378753,2 | Fix treemodelcompleter example | tqtc/lts-5.15 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 | 

