WSJT-X/widgets/LettersSpinBox.cpp
Bill Somerville 947b429723 Start implememntation of database based Fox log model and a new Fox log window widget
This change incorporates a reorganization of the GUI code with
widgets, validators, models, and item delegates being moved to
sub-directories.

Relax  the   requirements  of   the  ForeignKeyDelegate   and  related
CandidateKeyFilter classes to  allow them to work  with constant model
pointers for both referenced and referencing models.
2018-11-07 17:49:45 +00:00

26 lines
562 B
C++

#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;
}