comparison src/converter.cpp @ 78:f230ed9022e0

Rework questions to new logic for multilne questions
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 05 Oct 2016 14:24:53 +0200
parents 1e6e7699f0b8
children a8cd9b27e3d5
comparison
equal deleted inserted replaced
77:9412d60c8ac1 78:f230ed9022e0
75 mChoiceTextStyle= QStringLiteral("<tr><td align='right' style='vertical-align: middle; font-size:11pt;'>%1</td>"); 75 mChoiceTextStyle= QStringLiteral("<tr><td align='right' style='vertical-align: middle; font-size:11pt;'>%1</td>");
76 mChoiceVotesStyle = QStringLiteral("<td style='text-align: left;vertical-algin: center;" 76 mChoiceVotesStyle = QStringLiteral("<td style='text-align: left;vertical-algin: center;"
77 "font-size:10pt;'</td>%1</td></tr>"); 77 "font-size:10pt;'</td>%1</td></tr>");
78 mAnswerTextStyle = QStringLiteral("<tr><td colspan='3' style='font-weight: bold;vertical-algin: middle;" 78 mAnswerTextStyle = QStringLiteral("<tr><td colspan='3' style='font-weight: bold;vertical-algin: middle;"
79 "font-size:11pt;'>Answer<hr/></td></tr>"); 79 "font-size:11pt;'>Answer<hr/></td></tr>");
80 mFreeTextStyle = QStringLiteral("<tr><td colspan='3'; font-size:11pt;'>%1<hr/></td></tr>"); 80 mFreeTextStyle = QStringLiteral("<tr><td colspan='3'; style='font-size:11pt;'>%1<hr/></td></tr>");
81 mEmptyRow = QStringLiteral("<tr style='height: %1px'/>").arg(CHOICE_ROW_HEIGHT); 81 mEmptyRow = QStringLiteral("<tr style='height: %1px'/>").arg(CHOICE_ROW_HEIGHT);
82 } 82 }
83 83
84 void Converter::run() 84 void Converter::run()
85 { 85 {
261 261
262 QRegularExpression questionEx(QUESTION_PATTERN); 262 QRegularExpression questionEx(QUESTION_PATTERN);
263 QRegularExpression choiceEx(CHOICE_PATTERN); 263 QRegularExpression choiceEx(CHOICE_PATTERN);
264 QRegularExpression choiceAltEx(CHOICE_UNFILLED_PATTERN); 264 QRegularExpression choiceAltEx(CHOICE_UNFILLED_PATTERN);
265 QRegularExpression freetxtEx(FREETXT_PATTERN); 265 QRegularExpression freetxtEx(FREETXT_PATTERN);
266 QRegularExpression firstQuestionEx(FIRST_QUESTION_PATTERN);
267 266
268 mErrors += sanitizeInput(input); 267 mErrors += sanitizeInput(input);
269 268
270 QRegularExpressionMatch match = firstQuestionEx.match(input); 269 QRegularExpressionMatch match = questionEx.match(input);
271 bool foundSomething = false; 270 bool foundSomething = false;
272 int cursor = match.capturedEnd(); 271 int cursor = match.capturedEnd();
273 while (match.hasMatch() && cursor != -1) { 272 while (match.hasMatch() && cursor != -1) {
274 /* We've matched a question pattern. With the answer 273 /* We've matched a question pattern. With the answer
275 line */ 274 line */
277 /* Should not happen without misconfiguration. */ 276 /* Should not happen without misconfiguration. */
278 mErrors << "Internal parser error."; 277 mErrors << "Internal parser error.";
279 return; 278 return;
280 } 279 }
281 foundSomething = true; 280 foundSomething = true;
282 /* For some reason the regular expression used is not 281 /* A question is everything until the last two newlines
283 * greedy enough if there are multiple question lines 282 * before an answer line.*/
284 * before the first Answer. */ 283 QString question;
285 QString question = input.left(match.capturedStart() + 284
286 match.captured(1).size()); 285 int lastBreaks = input.lastIndexOf(QStringLiteral("\n\n"), cursor);
287 unescapeString(question); 286 if (lastBreaks == -1) {
288 qDebug() << "First question: " << question; 287 /* First question */
289 const QString answerLine = match.captured(2).trimmed(); 288 lastBreaks = 0;
289 }
290
291 question = input.mid(lastBreaks, match.capturedStart() - lastBreaks);
292 qDebug() << "Found question: " << question;
293 const QString answerLine = match.captured(1).trimmed();
290 xlsx.write(row, 2, QString(" "), mQuestionFmt); 294 xlsx.write(row, 2, QString(" "), mQuestionFmt);
291 xlsx.write(row, 3, QString(" "), mQuestionFmt); 295 xlsx.write(row, 3, QString(" "), mQuestionFmt);
292 xlsEscape(question); 296 xlsEscape(question);
293 xlsx.write(row++, 1, question, mQuestionFmt); 297 xlsx.write(row++, 1, question, mQuestionFmt);
294 html << mQuestionStyle.arg(question.toHtmlEscaped()); 298 html << mQuestionStyle.arg(question.toHtmlEscaped());
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)