# HG changeset patch # User Andre Heinecke # Date 1460366657 -7200 # Node ID e5c5ebfa4205afb7a87353dfaaf8ce2362a2437d # Parent 1470cb8a00a84c22029138b3a9215f720c3dfe96 Refactor to centralise html tags diff -r 1470cb8a00a8 -r e5c5ebfa4205 src/converter.cpp --- a/src/converter.cpp Mon Apr 11 11:00:59 2016 +0200 +++ b/src/converter.cpp Mon Apr 11 11:24:17 2016 +0200 @@ -34,7 +34,6 @@ mTitleFmt.setFontBold(true); mTitleFmt.setVerticalAlignment(Format::AlignTop); - mTitleStyle = QStringLiteral("style='vertical-align: top;font-weight: bold;font-size:18; text-decoration: underline;'"); mQuestionFmt.setFontSize(11); mQuestionFmt.setFontName("Calibri"); @@ -42,30 +41,44 @@ mQuestionFmt.setTopBorderStyle(Format::BorderThin); mQuestionFmt.setBottomBorderStyle(Format::BorderThin); mQuestionFmt.setTextWarp(true); - mQuestionStyle = QStringLiteral("style='border-bottom: 1pt solid black;border-top: 1pt solid black;font-weight: bold;font-size:11;'"); mAnswerChoiceFmt.setFontSize(11); mAnswerChoiceFmt.setFontName("Calibri"); mAnswerChoiceFmt.setHorizontalAlignment(Format::AlignLeft); mAnswerChoiceFmt.setTextWarp(true); - mAnswerChoiceStyle= QStringLiteral("style='text-align: left;font-size:11;'"); mChoiceTextFmt = mAnswerChoiceFmt; mChoiceTextFmt.setVerticalAlignment(Format::AlignVCenter); - mChoiceTextStyle= QStringLiteral("style='text-align: right;vertical-algin: center; font-size:11;'"); mChoiceVotesFmt = mChoiceTextFmt; mChoiceVotesFmt.setFontSize(10); - mChoiceVotesStyle = QStringLiteral("style='text-align: left;vertical-algin: center; font-size:10;'"); mFreeTextFmt = mQuestionFmt; mFreeTextFmt.setFontBold(false); - mFreeTextStyle = QStringLiteral("style='border-bottom: 1pt solid black;border-top: 1pt solid black;font-size:11;'"); mAnswerTextFmt = mQuestionFmt; mAnswerTextFmt.setVerticalAlignment(Format::AlignVCenter); mAnswerTextFmt.setHorizontalAlignment(Format::AlignLeft); - mAnswerTextStyle = QStringLiteral("style='text-align: left;font-weight: bold;vertical-algin: center; border-bottom: 1pt solid black;border-top: 1pt solid black;font-size:11;'"); + + mTitleStyle = QStringLiteral("%1"); + const QString questionBorders = QStringLiteral("style='border-bottom: 1pt solid black;" + "border-top: 1pt solid black;font-weight:" + "bold;font-size:11;'"); + mQuestionStyle = QStringLiteral("%1") + + QStringLiteral("").arg(questionBorders) + + QStringLiteral("").arg(questionBorders); + mAnswerChoiceStyle= QStringLiteral("Answer"); + mChoiceTextStyle= QStringLiteral("%1"); + mChoiceVotesStyle = QStringLiteral("%1"); + mAnswerTextStyle = QStringLiteral("Answer"); + mFreeTextStyle = QStringLiteral("%1"); + mEmptyRow = QStringLiteral("").arg(CHOICE_ROW_HEIGHT); } void Converter::run() @@ -102,6 +115,13 @@ convertToXSLX(instream, outfile); } +static void makeBar(QTextStream &html, double percent, QTextDocument &doc, bool forPDF) +{ + html << QStringLiteral("").arg(percent); + return; +} + void Converter::convertToXSLX(QTextStream& instream, QFile &output) { Document xlsx; @@ -138,11 +158,10 @@ html << ""; html << ""; html << ""; - html << ""; const QString title = mTitle.isEmpty() ? DEFAULT_TITLE : mTitle; // Set the title of the Questionaire xlsx.write(row++, 1, title, mTitleFmt); - html << title.toHtmlEscaped() << ""; + html << mTitleStyle.arg(title.toHtmlEscaped()); xlsx.mergeCells("A1:C1"); xlsx.setRowHeight(1, TITLE_ROW_HEIGHT); @@ -169,15 +188,13 @@ xlsx.write(row, 2, QString(" "), mQuestionFmt); xlsx.write(row, 3, QString(" "), mQuestionFmt); xlsx.write(row++, 1, question, mQuestionFmt); - html << "" << question.toHtmlEscaped() << "" - "" - ""; + html << mQuestionStyle.arg(question.toHtmlEscaped()); if (answerLine == QStringLiteral(CHOICE_IDENTIFIER)) { QRegularExpressionMatch choiceMatch = choiceEx.match(input, cursor); xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT); xlsx.write(row++, 1, "Answer", mAnswerChoiceFmt); - html << "" << "Answer" << ""; + html << mAnswerChoiceStyle; int firstChoiceRow = row; int lastChoiceRow = row; while (choiceMatch.hasMatch() && choiceMatch.capturedStart() == cursor + 1) { @@ -192,19 +209,17 @@ choiceName = " " + choiceName; } xlsx.write(row, 1, choiceName, mChoiceTextFmt); - html << "" << choiceName.toHtmlEscaped() << ""; + html << mChoiceTextStyle.arg(choiceName.toHtmlEscaped()); bool ok; double percent = choiceMatch.captured(3).toDouble(&ok); if (!ok) { mErrors << "Unparsable number in string: " + choiceMatch.captured(); } - html << QStringLiteral("").arg(percent); - html << ""; + makeBar(html, percent, doc, mFmt == Format_PDF); xlsx.write(row, 2, percent); const QString numVotesString = QString("%1% | %2 Number of votes"). arg(choiceMatch.captured(3)).arg(choiceMatch.captured(2)); - html << "" << numVotesString.toHtmlEscaped() << ""; + html << mChoiceVotesStyle.arg(numVotesString.toHtmlEscaped()); xlsx.write(row, 3, numVotesString, mChoiceVotesFmt); xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT); /* As long as we can match a choice which is either before the next question @@ -219,7 +234,7 @@ QRegularExpressionMatch textMatch = freetxtEx.match(input, cursor); xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT); xlsx.write(row++, 1, "Answer", mAnswerTextFmt); - html << "" << "Answer" << ""; + html << mAnswerTextStyle; /* To handle the workaround for quotes in answers we store * the number of rows and only afterwards create the html rows. */ @@ -280,16 +295,14 @@ textMatch = freetxtEx.match(input, cursor); } for (int i = firstFreeRow; i < row; i++) { - html << ""; - html << xlsx.read(i, 1).toString().toHtmlEscaped(); - html << ""; + html << mFreeTextStyle.arg(xlsx.read(i, 1).toString().toHtmlEscaped()); } } /* Insert Empty row. */ xlsx.setRowHeight(row++, CHOICE_ROW_HEIGHT); match = questionEx.match(input, cursor); cursor = match.capturedEnd(); - html << QStringLiteral("").arg(CHOICE_ROW_HEIGHT); + html << mEmptyRow; } xlsx.addConditionalFormatting(bars); diff -r 1470cb8a00a8 -r e5c5ebfa4205 src/converter.h --- a/src/converter.h Mon Apr 11 11:00:59 2016 +0200 +++ b/src/converter.h Mon Apr 11 11:24:17 2016 +0200 @@ -82,7 +82,8 @@ mAnswerTextStyle, mFreeTextStyle, mChoiceTextStyle, - mChoiceVotesStyle; + mChoiceVotesStyle, + mEmptyRow; }; #endif // CONVERTER_H diff -r 1470cb8a00a8 -r e5c5ebfa4205 src/l10n/main_de_DE.ts --- a/src/l10n/main_de_DE.ts Mon Apr 11 11:00:59 2016 +0200 +++ b/src/l10n/main_de_DE.ts Mon Apr 11 11:24:17 2016 +0200 @@ -4,32 +4,32 @@ Converter - + Failed to open standard input and no input file provided. Öffnen des Eingabekanals Fehlgeschlagen und keine Eingabedatei übergeben. - + Failed to open %1 for reading. Die Datei "%1" konnte nicht gelesen werden. - + Failed to open standard output and no output file provided. Öffnen des Ausgabekanals Fehlgeschlagen und keine Ausgabedatei übergeben. - + Failed to open %1 for writing. Die Datei "%1" konnte nicht geöffnet werden. - + Failed to parse input document. Fehler bei der verarbeitung des Eingabedokuments. - + Saving the XLSX document failed. Das erstellen des XLSX Dokuments ist fehlgeschlagen.