[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Thu Jan 27 18:54:09 CET 2011
SVN commit 1217508 by kuemmel:
use dot or comma as decimal separator, it isn't more complex
M +34 -5 asciiconfig.ui
M +1 -0 asciiplugin.cpp
M +2 -2 asciisource.cpp
M +1 -4 asciisourceconfig.cpp
M +0 -1 asciisourceconfig.h
M +24 -7 kst_atof.cpp
M +4 -2 kst_atof.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfig.ui #1217507:1217508
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>355</width>
- <height>509</height>
+ <height>532</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -317,16 +317,45 @@
</widget>
</item>
<item>
- <widget class="QCheckBox" name="_useDot">
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Decimal Separator</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QRadioButton" name="_useDot">
<property name="text">
- <string>Use '.' as decimal separator (ignore regional settings)</string>
+ <string>Dot</string>
</property>
<property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="_useComma">
+ <property name="text">
+ <string>Comma</string>
+ </property>
+ <property name="checked">
<bool>true</bool>
</property>
- <property name="tristate">
- <bool>false</bool>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>204</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
</widget>
</item>
<item>
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1217507:1217508
@@ -123,6 +123,7 @@
_readFields->setChecked(config._readFields);
_readUnits->setChecked(config._readUnits);
_useDot->setChecked(config._useDot);
+ _useComma->setChecked(!config._useDot);
_index_offset = 0;
_startLine->setMinimum(0);
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1217507:1217508
@@ -475,7 +475,7 @@
if (_config._columnType == AsciiSourceConfig::Fixed) {
LexicalCast lexc;
- lexc.setDecimalSeparator(_config._useDot, _config._localSeparator);
+ lexc.setDecimalSeparator(_config._useDot);
const char* col_start = &buffer[0] + _config._columnWidth * (col - 1);
for (int i = 0; i < n; ++i) {
/* Read appropriate column and convert to double
@@ -552,7 +552,7 @@
const ColumnWidthsAreConst& are_column_widths_const)
{
LexicalCast lexc;
- lexc.setDecimalSeparator(_config._useDot, _config._localSeparator);
+ lexc.setDecimalSeparator(_config._useDot);
const QString delimiters = _config._delimiters.value();
int col_start = -1;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisourceconfig.cpp #1217507:1217508
@@ -20,8 +20,6 @@
#include "asciisource.h"
-#include <QLocale>
-
//
// AsciiSourceConfig
//
@@ -77,8 +75,7 @@
_fieldsLine(0),
_unitsLine(0),
_useDot(true),
- _zeroStart(false),
- _localSeparator(QLocale().decimalPoint().toAscii())
+ _zeroStart(false)
{
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisourceconfig.h #1217507:1217508
@@ -86,7 +86,6 @@
NamedParameter<bool, Key_useDot, Tag_useDot> _useDot;
NamedParameter<bool, Key_zeroStart, Tag_zeroStart> _zeroStart;
- char _localSeparator;
private:
void save(QSettings& cfg);
--- branches/work/kst/portto4/kst/src/datasources/ascii/kst_atof.cpp #1217507:1217508
@@ -109,31 +109,48 @@
#endif
-LexicalCast::LexicalCast() : _useDot(false)
+LexicalCast::LexicalCast()
{
}
LexicalCast::~LexicalCast()
{
- if (_useDot) {
+ resetLocal();
+};
+
+
+void LexicalCast::resetLocal()
+{
+
+ if (!_originalLocal.isEmpty()) {
setlocale(LC_NUMERIC, _originalLocal.constData());
+ _originalLocal.clear();
}
}
-void LexicalCast::setDecimalSeparator(bool useDot, char separator)
+void LexicalCast::setDecimalSeparator(bool useDot)
{
- _useDot = useDot;
- if (_useDot) {
- _separator = '.';
+ useDot ? _separator = '.' : _separator = ',';
+
+ if (_separator != localSeparator()) {
_originalLocal = QByteArray((const char*) setlocale(LC_NUMERIC, 0));
+ if (useDot) {
setlocale(LC_NUMERIC, "C");
} else {
- _separator = separator;
+ setlocale(LC_NUMERIC, "de");
}
+ } else {
+ resetLocal();
}
+}
+char LexicalCast::localSeparator() const
+{
+ return *setlocale(LC_NUMERIC, 0);
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/datasources/ascii/kst_atof.h #1217507:1217508
@@ -10,8 +10,10 @@
LexicalCast();
~LexicalCast();
+ char localSeparator() const;
+
// use second parameter when useDot is false
- void setDecimalSeparator(bool useDot, char separator);
+ void setDecimalSeparator(bool useDot);
#ifdef KST_USE_KST_ATOF
double toDouble(const char* p) const;
@@ -20,9 +22,9 @@
#endif
private:
- bool _useDot;
char _separator;
QByteArray _originalLocal;
+ void resetLocal();
bool isDigit(const char) const;
};
More information about the Kst
mailing list