Details
-
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)
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.