changeset 55:aaaf8cdbc85c

Make percent string formatting more flexible It now also responds to .94 or something like that and is prepared for multiple numbers after the dot.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 20 Jul 2016 16:57:52 +0200
parents dcfb8e9d5ee9
children 5410f9f279ea
files src/constants.h src/converter.cpp
diffstat 2 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/constants.h	Wed Jul 20 16:56:54 2016 +0200
+++ b/src/constants.h	Wed Jul 20 16:57:52 2016 +0200
@@ -63,7 +63,7 @@
 
 /**
  * @brief The pattern used to match a multiple choice answer. */
-#define CHOICE_PATTERN "\"(.*)\",(?<num>\\d+)?,(?<percent>\\d+\\.?\\d+)?"
+#define CHOICE_PATTERN "\"(.*)\",(?<num>\\d+)?,(?<percent>\\d{0,3}\\.{0,1}\\d*)?"
 
 /**
  * @brief The pattern used to match an unfilled choice answer. */
--- a/src/converter.cpp	Wed Jul 20 16:56:54 2016 +0200
+++ b/src/converter.cpp	Wed Jul 20 16:57:52 2016 +0200
@@ -242,8 +242,8 @@
                 xlsx.write(row, 2, percent == 0 ? QVariant() : percent);
                 const QString numStr = choiceMatch.captured("num");
                 const QString numVotesString = QString("%1% | %2 Number of votes").
-                           arg(percentStr.isNull() ? QStringLiteral("0") : percentStr).
-                           arg(numStr.isNull() ? QStringLiteral("0") : numStr);
+                           arg(percentStr.isEmpty() ? QStringLiteral("0") : percentStr).
+                           arg(numStr.isEmpty() ? QStringLiteral("0") : numStr);
                 html << mChoiceVotesStyle.arg(numVotesString.toHtmlEscaped());
                 xlsx.write(row, 3, numVotesString, mChoiceVotesFmt);
                 xlsx.setRowHeight(row, CHOICE_ROW_HEIGHT);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)