Skip to content

Commit 349ea62

Browse files
authored
Fix comma sensitivity (#5368)
* update debug.csv change separator to ';' and add to entries with a comma as decimal to detect problems like jasp-stats/jasp-issues#2499 * Fix comma import from csv/ods/etc Partial fix for jasp-stats/jasp-issues#2499 * add some 123.456.789,000 dots combined with commas to the debug dataset * the event can just be aware of when it ought to be readonly
1 parent 3a5d2b8 commit 349ea62

File tree

9 files changed

+133
-134
lines changed

9 files changed

+133
-134
lines changed

CommonData/column.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1622,18 +1622,18 @@ bool Column::convertValueToIntForImport(const std::string &strValue, int &intVal
16221622
return ColumnUtils::getIntValue(strValue, intValue);
16231623
}
16241624

1625+
/// There is a ColumnUtils::convertValueToDoubleForImport that is used during import from readstat and which only looks at workspace empty values
16251626
bool Column::convertValueToDoubleForImport(const std::string & strValue, double & doubleValue) const
16261627
{
1627-
std::string v = strValue;
1628-
ColumnUtils::deEuropeaniseForImport(v);
1628+
std::string v = ColumnUtils::deEuropeaniseForImport(strValue);
16291629

16301630
if(isEmptyValue(v))
16311631
{
16321632
doubleValue = NAN;
16331633
return true;
16341634
}
16351635

1636-
return ColumnUtils::getDoubleValue(strValue, doubleValue);
1636+
return ColumnUtils::getDoubleValue(v, doubleValue);
16371637
}
16381638

16391639

CommonData/columnutils.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool ColumnUtils::isDoubleValue(const string &value)
8888
}
8989

9090

91-
void ColumnUtils::deEuropeaniseForImport(std::string & value)
91+
std::string ColumnUtils::deEuropeaniseForImport(std::string value)
9292
{
9393
int dots = 0,
9494
commas = 0;
@@ -102,7 +102,7 @@ void ColumnUtils::deEuropeaniseForImport(std::string & value)
102102
if(k == ',')
103103
{
104104
k = '.';
105-
return;
105+
return value;
106106
}
107107

108108
if (commas > 0)
@@ -133,6 +133,8 @@ void ColumnUtils::deEuropeaniseForImport(std::string & value)
133133

134134
value = uneurope;
135135
}
136+
137+
return value;
136138
}
137139

138140
bool ColumnUtils::convertValueToIntForImport(const std::string &strValue, int &intValue)
@@ -152,8 +154,7 @@ bool ColumnUtils::convertValueToIntForImport(const std::string &strValue, int &i
152154

153155
bool ColumnUtils::convertValueToDoubleForImport(const std::string & strValue, double & doubleValue)
154156
{
155-
std::string v = strValue;
156-
deEuropeaniseForImport(v);
157+
std::string v = deEuropeaniseForImport(strValue);
157158

158159
if(isEmptyValue(v, EmptyValues::singleton()->workspaceEmptyValues()))
159160
doubleValue = NAN;

CommonData/columnutils.h

+13-14
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ class ColumnUtils
1414

1515
static std::string emptyValue;
1616

17-
static bool getIntValue( const std::string & value, int & intValue);
18-
static bool getIntValue( const double & value, int & intValue);
19-
static bool getDoubleValue( const std::string & value, double & doubleValue);
20-
21-
static bool isIntValue( const std::string & value);
22-
static bool isDoubleValue( const std::string & value);
23-
24-
static bool convertValueToIntForImport( const std::string & strValue, int & intValue);
25-
static bool convertValueToDoubleForImport( const std::string & strValue, double & doubleValue);
26-
static bool isEmptyValue( const std::string & val, const stringset & emptyValues);
27-
static bool isEmptyValue( const double val, const doubleset & doubleEmptyValues);
28-
static void convertEscapedUnicodeToUTF8( std::string & inputStr);
29-
static void deEuropeaniseForImport( std::string & value);
30-
17+
static bool getIntValue( const std::string & value, int & intValue);
18+
static bool getIntValue( const double & value, int & intValue);
19+
static bool getDoubleValue( const std::string & value, double & doubleValue);
20+
21+
static bool isIntValue( const std::string & value);
22+
static bool isDoubleValue( const std::string & value);
23+
24+
static bool convertValueToIntForImport( const std::string & strValue, int & intValue);
25+
static bool convertValueToDoubleForImport( const std::string & strValue, double & doubleValue);
26+
static bool isEmptyValue( const std::string & val, const stringset & emptyValues);
27+
static bool isEmptyValue( const double val, const doubleset & doubleEmptyValues);
28+
static void convertEscapedUnicodeToUTF8( std::string & inputStr);
29+
static std::string deEuropeaniseForImport( std::string value);
3130
static std::string doubleToString( double dbl, int precision = 10);
3231

3332
private:

Desktop/analysis/analysis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Analysis : public AnalysisBase
178178
void requestComputedColumnDestruction( const std::string & columnName);
179179

180180
void refreshTableViewModels();
181-
Q_INVOKABLE void expandAnalysis();
181+
void expandAnalysis();
182182
void emptyQMLCache();
183183

184184
void createFormWhenYouHaveAMoment(QQuickItem* parent = nullptr);

Desktop/data/fileevent.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
#include "exporters/jaspexporter.h"
2323

2424
#include <QTimer>
25-
#include "utilities/qutils.h"
26-
#include "log.h"
25+
#include "utilities/appdirs.h"
2726

2827
FileEvent::FileEvent(QObject *parent, FileEvent::FileMode fileMode)
2928
: QObject(parent), _operation(fileMode)
@@ -51,8 +50,6 @@ void FileEvent::setDataFilePath(const QString & path)
5150

5251
void FileEvent::setDatabase(const Json::Value & dbInfo)
5352
{
54-
setReadOnly();
55-
5653
_database = dbInfo;
5754
}
5855

@@ -110,6 +107,11 @@ void FileEvent::chain(FileEvent *event)
110107
connect(event, &FileEvent::completed, this, &FileEvent::chainedComplete);
111108
}
112109

110+
bool FileEvent::isExample() const
111+
{
112+
return path().startsWith(AppDirs::examples());
113+
}
114+
113115
const std::string FileEvent::databaseStr() const
114116
{
115117
return _database.toStyledString();

Desktop/data/fileevent.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ class FileEvent : public QObject
4747
void setComplete(bool success = true, const QString &message = "");
4848
void chain(FileEvent *event);
4949

50-
void setReadOnly() { _readOnly = true; }
51-
5250
bool isDatabase() const { return _database != Json::nullValue; }
5351
bool isOnlineNode() const { return _path.startsWith("http"); }
54-
bool isReadOnly() const { return _readOnly; }
52+
bool isExample() const;
53+
bool isReadOnly() const { return isExample() || isDatabase(); }
5554
bool isCompleted() const { return _completed; }
5655
bool isSuccessful() const { return _success; }
5756

@@ -83,8 +82,7 @@ private slots:
8382
_dataFilePath,
8483
_last_error = "Unknown error",
8584
_message;
86-
bool _readOnly = false,
87-
_completed = false,
85+
bool _completed = false,
8886
_success = false;
8987
FileEvent * _chainedTo = nullptr;
9088
Exporter * _exporter = nullptr;

Desktop/widgets/filemenu/datalibrarylistmodel.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ void DataLibraryListModel::openFile(const QString &path)
5252
{
5353
FileEvent *event = new FileEvent(this->parent(), FileEvent::FileOpen);
5454
event->setPath(path);
55-
event->setReadOnly(); // A file from the Data Library should be read only, also csv file so that its path is not added in the recent list
5655

5756
emit openFileEvent(event);
5857

Desktop/widgets/filemenu/filemenu.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void FileMenu::dataSetIOCompleted(FileEvent *event)
260260
if (!event->isDatabase())
261261
{
262262
_recentFiles->pushRecentFilePath(event->path());
263-
if (!event->path().startsWith(AppDirs::examples()))
263+
if (!event->isExample())
264264
_computer->addRecentFolder(event->path());
265265
}
266266

0 commit comments

Comments
 (0)