@@ -564,7 +564,8 @@ QString confirmText(const Question &q, bool yes)
564564 const QString label = yes ? q.yesLabel : q.noLabel ;
565565 if (label.isEmpty () || label.compare (plain, Qt::CaseInsensitive) == 0 )
566566 return plain;
567- return QStringLiteral (" %1 (%2)" ).arg (label, plain);
567+ // "value (label)", like choices: the overview shows what is in brackets.
568+ return QStringLiteral (" %1 (%2)" ).arg (plain, label);
568569}
569570
570571QString quoted (const QString &text)
@@ -1040,6 +1041,75 @@ QJsonObject elicitationContent(const Spec &spec, const QVector<Answer> &answers)
10401041 return content;
10411042}
10421043
1044+ namespace {
1045+
1046+ // "value (label)" -> "label"; quoted free text -> unquoted.
1047+ QString displayItem (QString item)
1048+ {
1049+ item = item.trimmed ();
1050+ if (item.startsWith (QLatin1String (" other: " )))
1051+ return QStringLiteral (" other: " ) + displayItem (item.mid (7 ));
1052+ if (item.size () >= 2 && item.startsWith (QLatin1Char (' "' )) && item.endsWith (QLatin1Char (' "' )))
1053+ return item.mid (1 , item.size () - 2 );
1054+ if (item.endsWith (QLatin1Char (' )' ))) {
1055+ const qsizetype open = item.indexOf (QLatin1String (" (" ));
1056+ if (open > 0 )
1057+ return item.mid (open + 2 , item.size () - open - 3 );
1058+ }
1059+ return item;
1060+ }
1061+
1062+ } // namespace
1063+
1064+ QStringList answerOverview (const QString &text, int maxAnswerChars)
1065+ {
1066+ QStringList out;
1067+ if (!text.startsWith (QLatin1String (kAnswersHeader )))
1068+ return out;
1069+ static const QLatin1String kRecommended (" (recommended)" );
1070+ static const QString kChanged = QStringLiteral (" — changed (recommended: " );
1071+ const QStringList lines = text.split (QLatin1Char (' \n ' ));
1072+ for (int i = 1 ; i < lines.size (); ++i) {
1073+ const QString &line = lines.at (i);
1074+ if (line.isEmpty () || line.at (0 ).isSpace () || line.startsWith (QLatin1String (" Form: " )))
1075+ continue ;
1076+ const qsizetype space = line.indexOf (QLatin1Char (' ' ));
1077+ const qsizetype titleEnd = line.indexOf (QLatin1String (" \" : " ));
1078+ if (space <= 0 || titleEnd < space || line.at (space + 1 ) != QLatin1Char (' "' ))
1079+ continue ;
1080+ const QString id = line.left (space);
1081+ const QString title = line.mid (space + 2 , titleEnd - space - 2 );
1082+ QString answer = line.mid (titleEnd + 3 );
1083+ bool changed = false ;
1084+ if (answer.endsWith (kRecommended )) {
1085+ answer.chop (kRecommended .size ());
1086+ } else if (const qsizetype c = answer.indexOf (kChanged ); c >= 0 ) {
1087+ answer.truncate (c);
1088+ changed = true ;
1089+ }
1090+ if (answer.endsWith (QLatin1Char (' |' ))) {
1091+ // Multi-line text: its first line follows, indented.
1092+ const QString next = i + 1 < lines.size () ? lines.at (i + 1 ).trimmed () : QString ();
1093+ answer.chop (1 );
1094+ answer += next;
1095+ }
1096+ QString shown;
1097+ if (answer.startsWith (QLatin1Char (' "' )) || answer.startsWith (QLatin1String (" change requested: " ))) {
1098+ shown = answer.startsWith (QLatin1Char (' "' )) ? displayItem (answer) : answer;
1099+ } else {
1100+ QStringList items = answer.split (QStringLiteral (" , " ));
1101+ for (QString &item : items)
1102+ item = displayItem (item);
1103+ shown = items.join (QStringLiteral (" , " ));
1104+ }
1105+ if (maxAnswerChars > 1 && shown.size () > maxAnswerChars)
1106+ shown = shown.left (maxAnswerChars - 1 ) + QStringLiteral (" …" );
1107+ out.append (QStringLiteral (" %1 %2 → %3" ).arg (id, title, shown)
1108+ + (changed ? QStringLiteral (" · changed" ) : QString ()));
1109+ }
1110+ return out;
1111+ }
1112+
10431113QString dismissPrompt (const QString ¬e)
10441114{
10451115 QString out = QLatin1String (kAnswersHeader ) + QLatin1Char (' \n ' ) + QLatin1String (kDismissedLine );
0 commit comments