espoSpinBox fixed behaviour when entering negative values

This commit is contained in:
Chris Esposito 2018-09-18 08:24:13 +10:00
parent 56468e9917
commit fa3d680c55
1 changed files with 5 additions and 8 deletions

View File

@ -7,36 +7,33 @@ espoSpinBox::espoSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
} }
QString espoSpinBox::textFromValue(double value) const{ QString espoSpinBox::textFromValue(double value) const{
if (value < 0)
return textFromValue(-value).prepend('-');
QString windowText; QString windowText;
if (value == 0){ if (value == 0){
QTextStream(&windowText) << value; QTextStream(&windowText) << value;
lastValidValue = value; lastValidValue = value;
return windowText; return windowText;
} }
if (value >= 1000000){ if (std::abs(value) >= 1000000){
QTextStream(&windowText) << value/1000000 << "M"; QTextStream(&windowText) << value/1000000 << "M";
lastValidValue = value; lastValidValue = value;
return windowText; return windowText;
} }
if (value >= 1000){ if (std::abs(value) >= 1000){
QTextStream(&windowText) << value/1000 << "k"; QTextStream(&windowText) << value/1000 << "k";
lastValidValue = value; lastValidValue = value;
return windowText; return windowText;
} }
if (value >= 1){ if (std::abs(value) >= 1){
QTextStream(&windowText) << value; QTextStream(&windowText) << value;
lastValidValue = value; lastValidValue = value;
return windowText; return windowText;
} }
if (value >= 1/1000){ if (std::abs(value) >= 1/1000){
QTextStream(&windowText) << value * 1000 << "m"; QTextStream(&windowText) << value * 1000 << "m";
lastValidValue = value; lastValidValue = value;
return windowText; return windowText;
} }
if (value >= 1/1000000){ if (std::abs(value) >= 1/1000000){
QTextStream(&windowText) << value * 1000000 << "u"; QTextStream(&windowText) << value * 1000000 << "u";
lastValidValue = value; lastValidValue = value;
return windowText; return windowText;