Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monetary columns and locale sensitive number display #5794

Open
wants to merge 21 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
63eebd6
some rudimentary support for monetary columns
JorisGoosen Feb 11, 2025
5814d79
add support for formatting via locale
JorisGoosen Feb 12, 2025
318f956
numbers are translated through qt now, which avoids problems with str…
JorisGoosen Feb 12, 2025
c2f48a8
update double labels after language change
JorisGoosen Feb 12, 2025
74449bd
mention something about restarting jasp
JorisGoosen Feb 12, 2025
9e8db8a
fighting with some qml components...
JorisGoosen Feb 12, 2025
378d7cc
attempt to make all qml use localized doubles etc
JorisGoosen Feb 18, 2025
902b005
remove integer array thing from textinputbase and make it handle perc…
JorisGoosen Feb 19, 2025
fa56c01
rewrite the html js formatting code a bit
JorisGoosen Feb 19, 2025
b820dca
ok money now seems to respect locale
JorisGoosen Feb 19, 2025
6ecedcd
now the currency and some numbers are formatted correctly even on sta…
JorisGoosen Feb 19, 2025
39a0c22
all numbers in the table now seem to be localized
JorisGoosen Feb 19, 2025
6ff9056
latenight problems get latenight solutions
JorisGoosen Feb 19, 2025
fa6dd66
make a setting to switch back to the US setting
JorisGoosen Feb 19, 2025
9fa82f6
make sure comparing results uses english, us locale and doesnt ask fo…
JorisGoosen Feb 20, 2025
7501ae3
remove debug print from js
JorisGoosen Feb 20, 2025
d84f855
add #include <functional>
JorisGoosen Feb 20, 2025
13065b3
make sure all string -> double/int also uses locale
JorisGoosen Feb 20, 2025
72ca4dc
add support for choosing the locale you want instead of the one belon…
JorisGoosen Feb 26, 2025
2ef0ccd
sort on toLower to find things a bit easier
JorisGoosen Feb 26, 2025
f56b0ec
ah and also maybe store the changed settings...
JorisGoosen Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove integer array thing from textinputbase and make it handle perc…
…entages well

also make sure the doubles in the double array are not sperated by a comma :s
  • Loading branch information
JorisGoosen committed Feb 19, 2025
commit 902b005f2be2b2f153e4813a4573182a704c56db
92 changes: 31 additions & 61 deletions QMLComponents/controls/textinputbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,7 @@ QString TextInputBase::_getPercentValue(double dblVal)
doubleValue = std::max(0., std::min(100., doubleValue));

int decimals = property("decimals").toInt();
return QString::number(doubleValue, 'f', decimals);
}

QString TextInputBase::_getIntegerArrayValue(const std::vector<int>& intValues)
{
QString value;
bool first = true;
for (int intValue : intValues)
{
if (!first)
value += ",";
first = false;
value += QString::number(intValue);
}

return value;
return QColumnUtils::currentQLocale().toString(doubleValue, 'f', decimals);
}

QString TextInputBase::_getDoubleArrayValue(const std::vector<double>& doubleValues)
Expand All @@ -59,9 +44,9 @@ QString TextInputBase::_getDoubleArrayValue(const std::vector<double>& doubleVal
for (double doubleValue : doubleValues)
{
if (!first)
value += ",";
value += ";";
first = false;
value += QString::number(doubleValue);
value += QColumnUtils::doubleToString(doubleValue);
}

return value;
Expand All @@ -87,26 +72,17 @@ void TextInputBase::bindTo(const Json::Value& value)
double dblVal = 0;
if (value.isNumeric())
dblVal = value.asDouble();
else if (value.isString() && QColumnUtils::getDoubleValue(tq(value.asString()), dblVal))


else if (value.isString() && !QColumnUtils::getDoubleValue(tq(value.asString()), dblVal))
dblVal = NAN;

_value = _inputType == TextInputType::PercentIntputType ? _getPercentValue(dblVal): dblVal;
_value = dblVal; //Stored as the user enters (so 0-100), but sent in json / 100 through _getPercentValue
//This mean the "bound value" is 0...1 so:
if(_inputType == TextInputType::PercentIntputType)
_value = dblVal * 100.0;

break;
}
case TextInputType::IntegerArrayInputType:
{
std::vector<int> arrayVal;
if (value.isArray())
{
for (const Json::Value& oneValue : value)
if (oneValue.isNumeric())
arrayVal.push_back(oneValue.asInt());
}
_value = _getIntegerArrayValue(arrayVal);
break;
}
case TextInputType::DoubleArrayInputType:
{
std::vector<double> arrayVal;
Expand Down Expand Up @@ -188,10 +164,9 @@ bool TextInputBase::isJsonValid(const Json::Value &value) const
bool valid = false;
switch (_inputType)
{
case TextInputType::IntegerArrayInputType:
case TextInputType::DoubleArrayInputType:
case TextInputType::FormulaArrayType: valid = value.isArray(); break;
default: valid = value.isNumeric() || value.isString(); break;
case TextInputType::FormulaArrayType: valid = value.isArray(); break;
default: valid = value.isNumeric() || value.isString(); break;
}
return valid;
}
Expand All @@ -203,7 +178,6 @@ void TextInputBase::setUp()
if (type == "integer") _inputType = TextInputType::IntegerInputType;
else if (type == "number") _inputType = TextInputType::NumberInputType;
else if (type == "percent") _inputType = TextInputType::PercentIntputType;
else if (type == "integerArray") _inputType = TextInputType::IntegerArrayInputType;
else if (type == "doubleArray") _inputType = TextInputType::DoubleArrayInputType;
else if (type == "computedColumn") _inputType = TextInputType::ComputedColumnType;
else if (type == "checkColumn") _inputType = TextInputType::CheckColumnFreeOrMineType;
Expand All @@ -229,25 +203,26 @@ void TextInputBase::setUp()

void TextInputBase::setDisplayValue()
{
Json::Value valueJson = _getJsonValue(_value);

QString showThis = _value.toString();
switch(valueJson.type())
{
case Json::intValue:
showThis = QColumnUtils::currentQLocale().toString(valueJson.asInt());;
break;

case Json::realValue:
showThis = QColumnUtils::doubleToString(valueJson.asDouble());
break;
}
int valueInt;
double valueDbl;
bool isInt,
isDbl;

isInt = QColumnUtils::getIntValue( _value.toString(), valueInt);
isDbl = QColumnUtils::getDoubleValue( _value.toString(), valueDbl);

QString showThis = _value.toString();

if(showThis == "95.0")
1+2;
if(isInt)
showThis = QColumnUtils::currentQLocale().toString(valueInt);

else if(isDbl)
showThis = QColumnUtils::doubleToString(valueDbl);

if(showThis == "0,95")
1+2;

if(property("displayValue") != showThis)
setProperty("displayValue", showThis);
}
Expand Down Expand Up @@ -302,7 +277,6 @@ QString TextInputBase::friendlyName() const
case TextInputType::IntegerInputType: return tr("Integer Field");
case TextInputType::NumberInputType: return tr("Double Field");
case TextInputType::PercentIntputType: return tr("Percentage Field");
case TextInputType::IntegerArrayInputType: return tr("Integers Field");
case TextInputType::DoubleArrayInputType: return tr("Doubles Field");
case TextInputType::AddColumnType: return tr("Add Column Field");
case TextInputType::ComputedColumnType: return tr("Add Computed Column Field");
Expand Down Expand Up @@ -406,13 +380,12 @@ Json::Value TextInputBase::_getJsonValue(QVariant value) const
case TextInputType::IntegerInputType: return isInt ? valueInt : 0;
case TextInputType::NumberInputType: return isDbl ? valueDbl : 0;
case TextInputType::PercentIntputType: return std::min(std::max(isDbl ? valueDbl : 0, 0.0), 100.0) / 100;
case TextInputType::IntegerArrayInputType:
case TextInputType::DoubleArrayInputType:
{
QString str = value.toString();
str.replace(QString(" "), QString(":"));
str.replace(QString(" "), QString(";"));
Json::Value values(Json::arrayValue);
QStringList chunks = str.split(QChar(':'), Qt::SkipEmptyParts);
QStringList chunks = str.split(QChar(';'), Qt::SkipEmptyParts);

for (QString &chunk: chunks)
{
Expand Down Expand Up @@ -446,10 +419,7 @@ Json::Value TextInputBase::_getJsonValue(QVariant value) const
void TextInputBase::valueChangedSlot()
{
QVariant prop = property("displayValue");

if(prop.toString() == "95.0")
1+2;


setValue(prop);
}

Expand Down Expand Up @@ -480,8 +450,8 @@ void TextInputBase::setDefaultValue(QVariant value)
{
double valueDbl;
if(QColumnUtils::getDoubleValue(value.toString(), valueDbl))
value = valueDbl;

value = valueDbl;
bool hasChanged = _defaultValue != value,
curValIsDef = _defaultValue == _value;

Expand Down
3 changes: 1 addition & 2 deletions QMLComponents/controls/textinputbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TextInputBase : public JASPControl, public BoundControlBase
Q_PROPERTY( QVariant value READ value WRITE setValue NOTIFY valueChanged )

public:
enum TextInputType { IntegerInputType = 0, StringInputType, NumberInputType, PercentIntputType, IntegerArrayInputType, DoubleArrayInputType, ComputedColumnType, AddColumnType, CheckColumnFreeOrMineType, FormulaType, FormulaArrayType};
enum TextInputType { IntegerInputType = 0, StringInputType, NumberInputType, PercentIntputType, DoubleArrayInputType, ComputedColumnType, AddColumnType, CheckColumnFreeOrMineType, FormulaType, FormulaArrayType};

TextInputBase(QQuickItem* parent = nullptr);

Expand Down Expand Up @@ -82,7 +82,6 @@ private slots:
bool _formulaResultInBounds(double result);

QString _getPercentValue(double val);
QString _getIntegerArrayValue(const std::vector<int>& intValues);
QString _getDoubleArrayValue(const std::vector<double>& dblValues);

void _setBoundValue();
Expand Down