Mercurial > clickerconvert
annotate src/converter.cpp @ 69:dab9c19252bd
Set wordwrap exiplicitly for multiple choice answers
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 29 Sep 2016 14:40:06 +0200 |
parents | defd29b9f25a |
children | 3438f5cce8cc |
rev | line source |
---|---|
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2016 by ETH Zürich |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 * |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=2) |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 * See LICENSE.txt for details. |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include "converter.h" |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 #include <QDebug> |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 #include <QRegularExpression> |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 #include <QRegularExpressionMatch> |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
13 #include <QTextDocument> |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
14 #include <QPrinter> |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
15 #include <QImage> |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
16 #include <QPainter> |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 #include "xlsxdocument.h" |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 #include "xlsxconditionalformatting.h" |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 #include "constants.h" |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 QTXLSX_USE_NAMESPACE |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
25 Converter::Converter(const QString &input, const QStringList &outputs, |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
26 const QString &title): |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 QThread(Q_NULLPTR), |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 mInput(input), |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
29 mOutputs(outputs), |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 mTitle(title) |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 mTitleFmt.setFontUnderline(Format::FontUnderlineSingle); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 mTitleFmt.setFontSize(18); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 mTitleFmt.setFontName("Calibri"); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 mTitleFmt.setFontBold(true); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 mTitleFmt.setVerticalAlignment(Format::AlignTop); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
38 |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 mQuestionFmt.setFontSize(11); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 mQuestionFmt.setFontName("Calibri"); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 mQuestionFmt.setFontBold(true); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 mQuestionFmt.setTopBorderStyle(Format::BorderThin); |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
43 mQuestionFmt.setBottomBorderStyle(Format::BorderThin); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 mQuestionFmt.setTextWarp(true); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 mAnswerChoiceFmt.setFontSize(11); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 mAnswerChoiceFmt.setFontName("Calibri"); |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
48 mAnswerChoiceFmt.setHorizontalAlignment(Format::AlignLeft); |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
49 mAnswerChoiceFmt.setTextWarp(true); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 mChoiceTextFmt = mAnswerChoiceFmt; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 mChoiceTextFmt.setVerticalAlignment(Format::AlignVCenter); |
69
dab9c19252bd
Set wordwrap exiplicitly for multiple choice answers
Andre Heinecke <andre.heinecke@intevation.de>
parents:
65
diff
changeset
|
53 mChoiceTextFmt.setTextWarp(true); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 |
15
03dad1cff5b9
Minor layout fixes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
13
diff
changeset
|
55 mChoiceVotesFmt = mChoiceTextFmt; |
03dad1cff5b9
Minor layout fixes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
13
diff
changeset
|
56 mChoiceVotesFmt.setFontSize(10); |
03dad1cff5b9
Minor layout fixes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
13
diff
changeset
|
57 |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
58 mFreeTextFmt = mQuestionFmt; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
59 mFreeTextFmt.setFontBold(false); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
61 mAnswerTextFmt = mQuestionFmt; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
62 mAnswerTextFmt.setVerticalAlignment(Format::AlignVCenter); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
63 mAnswerTextFmt.setHorizontalAlignment(Format::AlignLeft); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
64 |
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
65 mTitleStyle = QStringLiteral("<tr><td colspan='3' style='vertical-align: top;" |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
66 "font-weight: bold; text-decoration:underline; font-size: 18pt;'>" |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
67 "%1</td></tr><tr/>"); |
32
ad54c98cb8d8
Minor layout fixes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
26
diff
changeset
|
68 mQuestionStyle = QStringLiteral("<tr><td colspan='3' style='font-size: 11pt;font-weight: bold;'" |
ad54c98cb8d8
Minor layout fixes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
26
diff
changeset
|
69 "><hr/>%1<hr/></td></tr>"); |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
70 mAnswerChoiceStyle= QStringLiteral("<tr><td colspan='3' style='text-align: left; font-size: 11pt;'>Answer</td></tr>"); |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
71 mChoiceTextStyle= QStringLiteral("<tr><td align='right' style='vertical-align: middle; font-size:11pt;'>%1</td>"); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
72 mChoiceVotesStyle = QStringLiteral("<td style='text-align: left;vertical-algin: center;" |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
73 "font-size:10pt;'</td>%1</td></tr>"); |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
74 mAnswerTextStyle = QStringLiteral("<tr><td colspan='3' style='font-weight: bold;vertical-algin: middle;" |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
75 "font-size:11pt;'>Answer<hr/></td></tr>"); |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
76 mFreeTextStyle = QStringLiteral("<tr><td colspan='3'; font-size:11pt;'>%1<hr/></td></tr>"); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
77 mEmptyRow = QStringLiteral("<tr style='height: %1px'/>").arg(CHOICE_ROW_HEIGHT); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 void Converter::run() |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 QFile infile; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 if (mInput.isEmpty()) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 if (!infile.open(stdin, QIODevice::ReadOnly)) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 mErrors << tr("Failed to open standard input and no input file provided."); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 return; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 } else { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 infile.setFileName(mInput); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 if (!infile.open(QIODevice::ReadOnly)) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 mErrors << tr("Failed to open %1 for reading.").arg(mInput); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 return; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 QTextStream instream(&infile); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
98 QList<QFile*> outfiles; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
99 |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
100 if (mOutputs.isEmpty()) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
101 QFile *outfile = new QFile(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
102 if (!outfile->open(stdout, QIODevice::WriteOnly)) { |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 mErrors << tr("Failed to open standard output and no output file provided."); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 return; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 } |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
106 outfiles << outfile; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
107 } |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
108 foreach (const QString &fileName, mOutputs) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
109 QFile *outfile = new QFile(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
110 outfile->setFileName(fileName); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
111 if (!outfile->open(QIODevice::WriteOnly)) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
112 mErrors << tr("Failed to open %1 for writing.").arg(fileName); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 return; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 } |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
115 outfiles << outfile; |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 } |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
117 convertToXSLX(instream, outfiles); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
120 static void makeBar(QTextStream &html, double percent, QTextDocument &doc) |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
121 { |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
122 QImage image(QSize(IMAGE_WIDTH, 25), QImage::Format_RGB32); |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
123 QPainter painter(&image); |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
124 QRect rect = image.rect(); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
125 if (percent) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
126 rect.setRight(rect.right() / (100. / percent)); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
127 painter.fillRect(rect, QColor(BAR_COLOR)); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
128 rect.setLeft(rect.right()); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
129 } |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
130 qDebug() << "Filled " << rect << " with color"; |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
131 rect.setRight(IMAGE_WIDTH); |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
132 painter.fillRect(rect, Qt::white); |
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
133 qDebug() << "Filled " << rect << " with white"; |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
134 doc.addResource(QTextDocument::ImageResource, QUrl(QStringLiteral("internal://bar%1.png").arg((int)percent)), |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
135 QVariant(image)); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
136 html << QStringLiteral("<td style='vertical-align: middle'><img src=\"internal://bar%1.png\"/></td>").arg((int)percent); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
137 return; |
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
138 } |
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
139 |
65
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
140 static void unescapeRegex(QString &str, const QRegularExpression &exp) |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
141 { |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
142 QRegularExpressionMatch match = exp.match(str); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
143 while (match.hasMatch()) { |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
144 str.replace(match.capturedStart(), match.capturedLength(), match.captured(1)); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
145 match = exp.match(str); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
146 } |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
147 } |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
148 |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
149 static void unescapeString(QString &str) |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
150 { |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
151 static const QRegularExpression imgEx(IMAGE_PATTERN); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
152 static const QRegularExpression texEx(LATEX_PATTERN); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
153 |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
154 unescapeRegex(str, imgEx); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
155 unescapeRegex(str, texEx); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
156 } |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
157 |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
158 void Converter::convertToXSLX(QTextStream& instream, QList<QFile *>outputs) |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
160 Document xlsx; |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
161 QTextDocument doc; |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
162 QString htmlString; |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
163 QTextStream html (&htmlString); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
164 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 ConditionalFormatting bars; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
167 bars.addDataBarRule(QColor(0xFF, 0x99, 0x33), ConditionalFormatting::VOT_Num, |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
168 "0", ConditionalFormatting::VOT_Num, "100", false); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
169 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
170 const double colWidth[] = COLUMN_WIDTHS; |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
171 double sum = 0; |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
172 |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
173 for (int i = 1; i <= COLUMN_CNT; i++) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
174 xlsx.setColumnWidth(i, colWidth[i-1]); |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
175 sum += colWidth[i-1]; |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
176 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
177 |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
178 /* For the merged cell wordwrap trick. */ |
15
03dad1cff5b9
Minor layout fixes
Andre Heinecke <andre.heinecke@intevation.de>
parents:
13
diff
changeset
|
179 xlsx.setColumnWidth(26, sum + 1); |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
180 xlsx.setColumnHidden(26, true); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
181 |
26
5acd601356ba
Make HTML work for QTextDocument
Andre Heinecke <andre.heinecke@intevation.de>
parents:
25
diff
changeset
|
182 int row = 1; |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
183 html << "<html><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
184 "<body><table border=\"0\" width:\"100%\">"; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
185 html << QStringLiteral("<tr><th width=\"%1%\"></th>").arg(HTML_COL1_PERCENT); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
186 html << QStringLiteral("<th width=\"%1%\"></th>").arg(HTML_COL2_PERCENT); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
187 html << QStringLiteral("<th width=\"%1%\"></th>").arg(HTML_COL3_PERCENT); |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
188 |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
189 const QString title = mTitle.isEmpty() ? DEFAULT_TITLE : mTitle; |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
190 // Set the title of the Questionaire |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
191 xlsx.write(row++, 1, title, mTitleFmt); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
192 html << mTitleStyle.arg(title.toHtmlEscaped()); |
20
df7936065450
Add default title
Andre Heinecke <andre.heinecke@intevation.de>
parents:
15
diff
changeset
|
193 xlsx.mergeCells("A1:C1"); |
df7936065450
Add default title
Andre Heinecke <andre.heinecke@intevation.de>
parents:
15
diff
changeset
|
194 xlsx.setRowHeight(1, TITLE_ROW_HEIGHT); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
195 |
43
f9a0b2b6832e
Sanitize input and unify Lineendings
Andre Heinecke <andre.heinecke@intevation.de>
parents:
41
diff
changeset
|
196 QString input = instream.readAll(); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
197 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
198 QRegularExpression questionEx(QUESTION_PATTERN); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
199 QRegularExpression choiceEx(CHOICE_PATTERN); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
200 QRegularExpression choiceAltEx(CHOICE_UNFILLED_PATTERN); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
201 QRegularExpression freetxtEx(FREETXT_PATTERN); |
56
5410f9f279ea
Redefine question pattern to be more robust
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
202 QRegularExpression firstQuestionEx(FIRST_QUESTION_PATTERN); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
203 |
43
f9a0b2b6832e
Sanitize input and unify Lineendings
Andre Heinecke <andre.heinecke@intevation.de>
parents:
41
diff
changeset
|
204 input.replace("\r\n", "\n"); |
f9a0b2b6832e
Sanitize input and unify Lineendings
Andre Heinecke <andre.heinecke@intevation.de>
parents:
41
diff
changeset
|
205 input.replace("\n\r", "\n"); |
f9a0b2b6832e
Sanitize input and unify Lineendings
Andre Heinecke <andre.heinecke@intevation.de>
parents:
41
diff
changeset
|
206 input.replace("#NAME?\n", ""); |
f9a0b2b6832e
Sanitize input and unify Lineendings
Andre Heinecke <andre.heinecke@intevation.de>
parents:
41
diff
changeset
|
207 |
56
5410f9f279ea
Redefine question pattern to be more robust
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
208 QRegularExpressionMatch match = firstQuestionEx.match(input); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
209 bool foundSomething = false; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
210 int cursor = match.capturedEnd(); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
211 while (match.hasMatch() && cursor != -1) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
212 /* We've matched a question pattern. With the answer |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
213 line */ |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
214 if (!match.lastCapturedIndex() == 2) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
215 /* Should not happen without misconfiguration. */ |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
216 mErrors << "Internal parser error."; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
217 return; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
218 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
219 foundSomething = true; |
65
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
220 QString question = match.captured(1).trimmed(); |
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
221 unescapeString(question); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
222 const QString answerLine = match.captured(2).trimmed(); |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
223 xlsx.write(row, 2, QString(" "), mQuestionFmt); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
224 xlsx.write(row, 3, QString(" "), mQuestionFmt); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
225 xlsx.write(row++, 1, question, mQuestionFmt); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
226 html << mQuestionStyle.arg(question.toHtmlEscaped()); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
227 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
228 if (answerLine == QStringLiteral(CHOICE_IDENTIFIER)) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
229 xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT); |
21
0b66b10a287d
Add german translation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
20
diff
changeset
|
230 xlsx.write(row++, 1, "Answer", mAnswerChoiceFmt); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
231 html << mAnswerChoiceStyle; |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
232 int firstChoiceRow = row; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
233 int lastChoiceRow = row; |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
234 repeat: |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
235 QRegularExpressionMatch choiceMatch = choiceEx.match(input, cursor); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
236 while (choiceMatch.hasMatch() && choiceMatch.capturedStart() == cursor + 1) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
237 /* We use the cursor here to keep track of the state. Only if an answer |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
238 follows immediately behind the last answer we treat it as valid as |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
239 otherwise we can't figure out when the next question begins. */ |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
240 cursor = choiceMatch.capturedEnd(); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
241 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
242 /* Write the values */ |
12
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
243 QString choiceName = choiceMatch.captured(1).trimmed(); |
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
244 if (choiceName.startsWith("=")) { |
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
245 choiceName = " " + choiceName; |
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
246 } |
65
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
247 unescapeString(choiceName); |
12
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
248 xlsx.write(row, 1, choiceName, mChoiceTextFmt); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
249 html << mChoiceTextStyle.arg(choiceName.toHtmlEscaped()); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
250 qDebug() << "Captured for choice: " << choiceMatch.captured(0); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
251 bool ok; |
56
5410f9f279ea
Redefine question pattern to be more robust
Andre Heinecke <andre.heinecke@intevation.de>
parents:
55
diff
changeset
|
252 QString percentStr = choiceMatch.captured("percent"); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
253 double percent; |
63
4d65e654abf7
Converter: Handle empty percent strings again
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
254 if (percentStr.isEmpty()) { |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
255 percent = 0; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
256 ok = true; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
257 } else { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
258 percent = percentStr.toDouble(&ok); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
259 } |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
260 if (!ok) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
261 mErrors << "Unparsable number in string: " + choiceMatch.captured(); |
63
4d65e654abf7
Converter: Handle empty percent strings again
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
262 percent = 0; |
4d65e654abf7
Converter: Handle empty percent strings again
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
263 percentStr = QString(); |
4d65e654abf7
Converter: Handle empty percent strings again
Andre Heinecke <andre.heinecke@intevation.de>
parents:
56
diff
changeset
|
264 /* PercentStr was not a number. */ |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
265 } |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
266 makeBar(html, percent, doc); |
39
41cd27a64365
Write empty columns for XSLX to avoid strange 0 formatting
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
267 xlsx.write(row, 2, percent == 0 ? QVariant() : percent); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
268 const QString numStr = choiceMatch.captured("num"); |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
269 const QString numVotesString = QString("%1% | %2 Number of votes"). |
55
aaaf8cdbc85c
Make percent string formatting more flexible
Andre Heinecke <andre.heinecke@intevation.de>
parents:
43
diff
changeset
|
270 arg(percentStr.isEmpty() ? QStringLiteral("0") : percentStr). |
aaaf8cdbc85c
Make percent string formatting more flexible
Andre Heinecke <andre.heinecke@intevation.de>
parents:
43
diff
changeset
|
271 arg(numStr.isEmpty() ? QStringLiteral("0") : numStr); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
272 html << mChoiceVotesStyle.arg(numVotesString.toHtmlEscaped()); |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
273 xlsx.write(row, 3, numVotesString, mChoiceVotesFmt); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
274 xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
275 /* As long as we can match a choice which is either before the next question |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
276 or before the end of the document */ |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
277 choiceMatch = choiceEx.match(input, cursor); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
278 row++; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
279 lastChoiceRow++; |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
280 } |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
281 choiceMatch = choiceAltEx.match(input, cursor); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
282 bool additionalFound = false; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
283 while (choiceMatch.hasMatch() && choiceMatch.capturedStart() <= cursor + 1) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
284 additionalFound = true; |
65
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
285 QString choice = choiceMatch.captured(1); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
286 cursor = choiceMatch.capturedEnd(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
287 /* Alternative answer that is just a list of strings */ |
65
defd29b9f25a
Converter: Unescape IMG and Latex references
Andre Heinecke <andre.heinecke@intevation.de>
parents:
63
diff
changeset
|
288 unescapeString(choice); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
289 qDebug() << "Caputured unfilled choice: " << choice; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
290 html << mChoiceTextStyle.arg(choice.toHtmlEscaped()); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
291 makeBar(html, 0, doc); |
39
41cd27a64365
Write empty columns for XSLX to avoid strange 0 formatting
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
292 xlsx.write(row, 2, QVariant()); |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
293 const QString numVotesString = QStringLiteral("Keine eingegangenen Antworten"); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
294 html << mChoiceVotesStyle.arg(numVotesString.toHtmlEscaped()); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
295 xlsx.write(row, 3, numVotesString, mChoiceVotesFmt); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
296 xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
297 row++; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
298 lastChoiceRow++; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
299 choiceMatch = choiceAltEx.match(input, cursor); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
300 QRegularExpressionMatch realMatch = choiceEx.match(input, cursor); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
301 if (choiceMatch.hasMatch() && choiceMatch.capturedStart() == realMatch.capturedStart()) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
302 /* We have a real match so back to the other pattern. */ |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
303 break; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
304 } |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
305 } |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
306 if (additionalFound) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
307 goto repeat; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
308 } |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
309 bars.addRange(QString("B%1:B%2").arg(firstChoiceRow).arg(lastChoiceRow)); |
13
101ee762f021
Add commented out Grouping
Andre Heinecke <andre.heinecke@intevation.de>
parents:
12
diff
changeset
|
310 // xlsx.groupRows(firstChoiceRow - 2, lastChoiceRow - 1, false); |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
311 } else if (answerLine == QStringLiteral(TEXT_IDENTIFIER)) { |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
312 QRegularExpressionMatch textMatch = freetxtEx.match(input, cursor); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
313 xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT); |
21
0b66b10a287d
Add german translation
Andre Heinecke <andre.heinecke@intevation.de>
parents:
20
diff
changeset
|
314 xlsx.write(row++, 1, "Answer", mAnswerTextFmt); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
315 html << mAnswerTextStyle; |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
316 |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
317 /* To handle the workaround for quotes in answers we store |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
318 * the number of rows and only afterwards create the html rows. */ |
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
319 int firstFreeRow = row; |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
320 while (textMatch.hasMatch()) { |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
321 if (textMatch.capturedStart() != cursor + 1) { |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
322 /* The format allows unescaped quotes in the text. |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
323 This makes a workaround neccessary. If we have |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
324 an Unquoted string between the next quoted string |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
325 and that Unquoted string is before the next question |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
326 we append the unquoted string and the next quoted string |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
327 with Quotes in the Row.*/ |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
328 QRegularExpressionMatch nextQuestion = questionEx.match(input, cursor); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
329 if (nextQuestion.hasMatch() && |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
330 nextQuestion.capturedStart() < textMatch.capturedEnd()) { |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
331 /* The next question comes before the textMatch so we really have |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
332 a new question. */ |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
333 break; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
334 } |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
335 const QString lastRow = xlsx.read(row - 1, 26).toString(); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
336 int unquotedLen = textMatch.capturedStart() - cursor; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
337 const QString unquoted = input.mid(cursor, unquotedLen); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
338 qDebug() << "Found inner quoted string: " << unquoted; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
339 /* Now combine */ |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
340 const QString combined = QString("%1\"%2\"%3").arg(lastRow). |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
341 arg(unquoted). |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
342 arg(textMatch.captured(1).trimmed()); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
343 qDebug() << "Last row: " << lastRow; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
344 qDebug() << "Next Question is at: " << nextQuestion.capturedStart(); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
345 qDebug() << "Text match is: " << textMatch.captured(1).trimmed(); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
346 qDebug() << "cursor is at: " << cursor; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
347 qDebug() << "text match starts at: " << textMatch.capturedStart(); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
348 xlsx.write(row - 1, 26, combined, mFreeTextFmt); |
12
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
349 xlsx.write(row - 1, 1, combined, mFreeTextFmt); |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
350 cursor = textMatch.capturedEnd(); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
351 textMatch = freetxtEx.match(input, cursor); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
352 continue; |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
353 } |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
354 cursor = textMatch.capturedEnd(); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
355 |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
356 QString text = textMatch.captured(1).trimmed(); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
357 qDebug() << "Found free text: " << text; |
12
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
358 if (text.startsWith("=")) { |
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
359 text = " " + text; |
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
360 } |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
361 |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
362 /* Merge the cells */ |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
363 xlsx.mergeCells(QString("A%1:C%1").arg(row), mFreeTextFmt); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
364 |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
365 /* Merged cells ignore wordwrap the following trick is based on: |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
366 http://excel.tips.net/T003207_Automatic_Row_Height_For_Merged_Cells_with_Text_Wrap.html |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
367 */ |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
368 /* Write the values */ |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
369 xlsx.write(QString("Z%1").arg(row), text, mFreeTextFmt); |
12
21f11f988115
Make sure strings don't start with = and duplicate text instead of formula
Andre Heinecke <andre.heinecke@intevation.de>
parents:
6
diff
changeset
|
370 xlsx.write(row, 1, text, mFreeTextFmt); |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
371 row++; |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
372 |
6
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
373 textMatch = freetxtEx.match(input, cursor); |
a10425e7ef98
Add free text handling
Andre Heinecke <andre.heinecke@intevation.de>
parents:
3
diff
changeset
|
374 } |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
375 for (int i = firstFreeRow; i < row; i++) { |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
376 html << mFreeTextStyle.arg(xlsx.read(i, 1).toString().toHtmlEscaped()); |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
377 } |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
378 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
379 /* Insert Empty row. */ |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
380 xlsx.setRowHeight(row++, CHOICE_ROW_HEIGHT); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
381 match = questionEx.match(input, cursor); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
382 cursor = match.capturedEnd(); |
25
e5c5ebfa4205
Refactor to centralise html tags
Andre Heinecke <andre.heinecke@intevation.de>
parents:
23
diff
changeset
|
383 html << mEmptyRow; |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
384 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
385 xlsx.addConditionalFormatting(bars); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
386 |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
387 if (!foundSomething) { |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
388 mErrors << tr("Failed to parse input document."); |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
389 } |
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
390 |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
391 html << "</table></body></html>"; |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
392 doc.setHtml(htmlString); |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
393 |
38
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
394 /* Fixup images for html */ |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
395 QRegularExpression htmlRe = QRegularExpression("<td style='vertical-align: middle'><img src=\"internal://bar(\\d+).png\"/></td>"); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
396 htmlString.replace(htmlRe, QStringLiteral("<td style='background:linear-gradient(to right," |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
397 BAR_COLOR ", " BAR_COLOR " \\1%, #ffffff \\1%)'></td>")); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
398 |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
399 foreach (QFile *output, outputs) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
400 const QString fName = output->fileName().toLower(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
401 if (fName.endsWith(".html")) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
402 QTextStream outstream(output); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
403 outstream << htmlString; |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
404 output->close(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
405 } else if (fName.endsWith(".pdf")) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
406 output->close(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
407 QPrinter printer(QPrinter::PrinterResolution); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
408 printer.setOutputFormat(QPrinter::PdfFormat); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
409 printer.setPaperSize(QPrinter::A4); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
410 printer.setOutputFileName(output->fileName()); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
411 /* |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
412 QPageLayout layout = printer.pageLayout(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
413 layout.setUnits(QPageLayout::Millimeter); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
414 layout.setMargins(QMarginsF(20, 20, 20, 20)); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
415 printer.setPageLayout(layout); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
416 doc.setPageSize(printer.pageRect().size()); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
417 */ |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
418 doc.print(&printer); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
419 } else { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
420 if (!xlsx.saveAs(output)) { |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
421 mErrors << tr("Saving the XLSX document failed."); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
422 } |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
423 output->close(); |
5354cbda7188
Fix HTML Layout. Support multiple formats at once. More handling.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
35
diff
changeset
|
424 } |
23
927794e3cc52
Add HTML output and some pdf support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
21
diff
changeset
|
425 } |
3
8b4c49c92451
Add initial implementation that handles choices
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
426 } |