SciDAVis
1.D4
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
scidavis
src
future
core
datatypes
String2DoubleFilter.h
Go to the documentation of this file.
1
/***************************************************************************
2
File : String2DoubleFilter.h
3
Project : SciDAVis
4
--------------------------------------------------------------------
5
Copyright : (C) 2007 by Knut Franke
6
Email (use @ for *) : knut.franke*gmx.de
7
Description : Locale-aware conversion filter QString -> double.
8
9
***************************************************************************/
10
11
/***************************************************************************
12
* *
13
* This program is free software; you can redistribute it and/or modify *
14
* it under the terms of the GNU General Public License as published by *
15
* the Free Software Foundation; either version 2 of the License, or *
16
* (at your option) any later version. *
17
* *
18
* This program is distributed in the hope that it will be useful, *
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
* GNU General Public License for more details. *
22
* *
23
* You should have received a copy of the GNU General Public License *
24
* along with this program; if not, write to the Free Software *
25
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26
* Boston, MA 02110-1301 USA *
27
* *
28
***************************************************************************/
29
#ifndef STRING2DOUBLE_FILTER_H
30
#define STRING2DOUBLE_FILTER_H
31
32
#include "../AbstractSimpleFilter.h"
33
#include <QLocale>
34
#include "
lib/XmlStreamReader.h
"
35
#include <QXmlStreamWriter>
36
#include <QtDebug>
37
39
class
String2DoubleFilter
:
public
AbstractSimpleFilter
40
{
41
Q_OBJECT
42
43
public
:
44
String2DoubleFilter
() :
d_use_default_locale
(true) {}
45
void
setNumericLocale
(QLocale locale) {
d_numeric_locale
= locale;
d_use_default_locale
=
false
; }
46
void
setNumericLocaleToDefault
() {
d_use_default_locale
=
true
; }
47
48
virtual
double
valueAt
(
int
row)
const
{
49
if
(!
d_inputs
.value(0))
return
0;
50
if
(
d_use_default_locale
)
// we need a new QLocale instance here in case the default changed since the last call
51
return
QLocale().toDouble(
d_inputs
.value(0)->textAt(row));
52
return
d_numeric_locale
.toDouble(
d_inputs
.value(0)->textAt(row));
53
}
54
virtual
bool
isInvalid
(
int
row)
const
{
55
if
(!
d_inputs
.value(0))
return
false
;
56
bool
ok;
57
if
(
d_use_default_locale
)
58
QLocale().toDouble(
d_inputs
.value(0)->textAt(row), &ok);
59
else
60
d_numeric_locale
.toDouble(
d_inputs
.value(0)->textAt(row), &ok);
61
return
!ok;
62
}
63
virtual
bool
isInvalid
(
Interval<int>
i)
const
{
64
if
(!
d_inputs
.value(0))
return
false
;
65
QLocale locale;
66
if
(!
d_use_default_locale
)
67
locale =
d_numeric_locale
;
68
for
(
int
row = i.
start
(); row <= i.
end
(); row++) {
69
bool
ok;
70
locale.toDouble(
d_inputs
.value(0)->textAt(row), &ok);
71
if
(ok)
72
return
false
;
73
}
74
return
true
;
75
}
76
virtual
QList< Interval<int> >
invalidIntervals
()
const
77
{
78
IntervalAttribute<bool>
validity;
79
if
(
d_inputs
.value(0)) {
80
int
rows =
d_inputs
.value(0)->rowCount();
81
for
(
int
i=0; i<rows; i++)
82
validity.
setValue
(i,
isInvalid
(i));
83
}
84
return
validity.
intervals
();
85
}
86
87
89
virtual
SciDAVis::ColumnDataType
dataType
()
const
{
return
SciDAVis::TypeDouble
; }
90
91
protected
:
93
virtual
bool
inputAcceptable
(
int
,
const
AbstractColumn
*source) {
94
return
source->
dataType
() ==
SciDAVis::TypeQString
;
95
}
96
97
private
:
98
QLocale
d_numeric_locale
;
99
bool
d_use_default_locale
;
100
};
101
102
#endif // ifndef STRING2DOUBLE_FILTER_H
103
Generated by
1.8.1