comparison src/converter.cpp @ 65:defd29b9f25a

Converter: Unescape IMG and Latex references
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 26 Aug 2016 15:26:17 +0200
parents 4d65e654abf7
children dab9c19252bd
comparison
equal deleted inserted replaced
64:94cac17fe5be 65:defd29b9f25a
134 QVariant(image)); 134 QVariant(image));
135 html << QStringLiteral("<td style='vertical-align: middle'><img src=\"internal://bar%1.png\"/></td>").arg((int)percent); 135 html << QStringLiteral("<td style='vertical-align: middle'><img src=\"internal://bar%1.png\"/></td>").arg((int)percent);
136 return; 136 return;
137 } 137 }
138 138
139 static void unescapeRegex(QString &str, const QRegularExpression &exp)
140 {
141 QRegularExpressionMatch match = exp.match(str);
142 while (match.hasMatch()) {
143 str.replace(match.capturedStart(), match.capturedLength(), match.captured(1));
144 match = exp.match(str);
145 }
146 }
147
148 static void unescapeString(QString &str)
149 {
150 static const QRegularExpression imgEx(IMAGE_PATTERN);
151 static const QRegularExpression texEx(LATEX_PATTERN);
152
153 unescapeRegex(str, imgEx);
154 unescapeRegex(str, texEx);
155 }
156
139 void Converter::convertToXSLX(QTextStream& instream, QList<QFile *>outputs) 157 void Converter::convertToXSLX(QTextStream& instream, QList<QFile *>outputs)
140 { 158 {
141 Document xlsx; 159 Document xlsx;
142 QTextDocument doc; 160 QTextDocument doc;
143 QString htmlString; 161 QString htmlString;
196 /* Should not happen without misconfiguration. */ 214 /* Should not happen without misconfiguration. */
197 mErrors << "Internal parser error."; 215 mErrors << "Internal parser error.";
198 return; 216 return;
199 } 217 }
200 foundSomething = true; 218 foundSomething = true;
201 const QString question = match.captured(1).trimmed(); 219 QString question = match.captured(1).trimmed();
220 unescapeString(question);
202 const QString answerLine = match.captured(2).trimmed(); 221 const QString answerLine = match.captured(2).trimmed();
203 xlsx.write(row, 2, QString(" "), mQuestionFmt); 222 xlsx.write(row, 2, QString(" "), mQuestionFmt);
204 xlsx.write(row, 3, QString(" "), mQuestionFmt); 223 xlsx.write(row, 3, QString(" "), mQuestionFmt);
205 xlsx.write(row++, 1, question, mQuestionFmt); 224 xlsx.write(row++, 1, question, mQuestionFmt);
206 html << mQuestionStyle.arg(question.toHtmlEscaped()); 225 html << mQuestionStyle.arg(question.toHtmlEscaped());
222 /* Write the values */ 241 /* Write the values */
223 QString choiceName = choiceMatch.captured(1).trimmed(); 242 QString choiceName = choiceMatch.captured(1).trimmed();
224 if (choiceName.startsWith("=")) { 243 if (choiceName.startsWith("=")) {
225 choiceName = " " + choiceName; 244 choiceName = " " + choiceName;
226 } 245 }
246 unescapeString(choiceName);
227 xlsx.write(row, 1, choiceName, mChoiceTextFmt); 247 xlsx.write(row, 1, choiceName, mChoiceTextFmt);
228 html << mChoiceTextStyle.arg(choiceName.toHtmlEscaped()); 248 html << mChoiceTextStyle.arg(choiceName.toHtmlEscaped());
229 qDebug() << "Captured for choice: " << choiceMatch.captured(0); 249 qDebug() << "Captured for choice: " << choiceMatch.captured(0);
230 bool ok; 250 bool ok;
231 QString percentStr = choiceMatch.captured("percent"); 251 QString percentStr = choiceMatch.captured("percent");
259 } 279 }
260 choiceMatch = choiceAltEx.match(input, cursor); 280 choiceMatch = choiceAltEx.match(input, cursor);
261 bool additionalFound = false; 281 bool additionalFound = false;
262 while (choiceMatch.hasMatch() && choiceMatch.capturedStart() <= cursor + 1) { 282 while (choiceMatch.hasMatch() && choiceMatch.capturedStart() <= cursor + 1) {
263 additionalFound = true; 283 additionalFound = true;
264 const QString choice = choiceMatch.captured(1); 284 QString choice = choiceMatch.captured(1);
265 cursor = choiceMatch.capturedEnd(); 285 cursor = choiceMatch.capturedEnd();
266 /* Alternative answer that is just a list of strings */ 286 /* Alternative answer that is just a list of strings */
287 unescapeString(choice);
267 qDebug() << "Caputured unfilled choice: " << choice; 288 qDebug() << "Caputured unfilled choice: " << choice;
268 html << mChoiceTextStyle.arg(choice.toHtmlEscaped()); 289 html << mChoiceTextStyle.arg(choice.toHtmlEscaped());
269 makeBar(html, 0, doc); 290 makeBar(html, 0, doc);
270 xlsx.write(row, 2, QVariant()); 291 xlsx.write(row, 2, QVariant());
271 const QString numVotesString = QStringLiteral("Keine eingegangenen Antworten"); 292 const QString numVotesString = QStringLiteral("Keine eingegangenen Antworten");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)