summaryrefslogtreecommitdiff
path: root/widgets/LettersSpinBox.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2018-12-19 22:58:32 +0100
committerChristoph Berg <myon@debian.org>2018-12-19 22:58:32 +0100
commite0737c56c1e384e05064a0c6e1ac46979371041b (patch)
treea0123d694a2d36c43dabdf0a3907392fce11d457 /widgets/LettersSpinBox.cpp
parentb4aebf2d137b892f53503b13785ecae900062ff7 (diff)
New upstream version 2.0.0+repackupstream/2.0.0+repack
Diffstat (limited to 'widgets/LettersSpinBox.cpp')
-rw-r--r--widgets/LettersSpinBox.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/widgets/LettersSpinBox.cpp b/widgets/LettersSpinBox.cpp
new file mode 100644
index 00000000..9079d8d9
--- /dev/null
+++ b/widgets/LettersSpinBox.cpp
@@ -0,0 +1,25 @@
+#include "LettersSpinBox.hpp"
+
+#include <QString>
+#include "moc_LettersSpinBox.cpp"
+
+QString LettersSpinBox::textFromValue (int value) const
+{
+ QString text;
+ do {
+ auto digit = value % 26;
+ value /= 26;
+ text = QChar {lowercase_ ? 'a' + digit : 'A' + digit} + text;
+ } while (value);
+ return text;
+}
+
+int LettersSpinBox::valueFromText (QString const& text) const
+{
+ int value {0};
+ for (int index = text.size (); index > 0; --index)
+ {
+ value = value * 26 + text[index - 1].toLatin1 () - (lowercase_ ? 'a' : 'A');
+ }
+ return value;
+}