libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
odscell.cpp
Go to the documentation of this file.
1/*
2 libodsstream is a library to read and write ODS documents as streams
3 Copyright (C) 2013 Olivier Langella <Olivier.Langella@moulon.inra.fr>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20#include <QDebug>
21#include "odscell.h"
22#include "../odsexception.h"
23
27
31
32void
33OdsCell::setOfficeValueType(const QString &type)
34{
35 // float
36 // percentage
37 // currency
38 // date
39 // time
40 // boolean
41 // string
42 if(type.isEmpty())
43 {
44 _is_empty = true;
45 qDebug() << "empty cell";
47 }
48 else
49 {
50 _is_empty = false;
51 _office_value_type = type;
52 }
53 _string_value = "";
54};
55void
56OdsCell::setDateValue(const QDateTime &date)
57{
58 // qDebug() << "setDateValue date.fromString " <<
59 // date.toString(Qt::ISODate);
60 _date_value = date;
61 _string_value = date.toString();
62};
63
64void
65OdsCell::setValueString(const QString &value)
66{
67 _string_value = value;
68};
69void
70OdsCell::setValueDouble(double value_num)
71{
72 _double_value = value_num;
73 _string_value.setNum(value_num);
74};
75void
77{
78 _bool_value = value_bool;
79 _string_value.setNum(value_bool);
80};
81
82const QString &
84{
85 // if (isDate()) return QString (_date_value.toString());
86 // if (isDouble()) return QString(""+_double_value);
87 return _string_value;
88};
89
90const QString &
95
96const QDateTime &
98{
99 if(isDate())
100 {
101 return _date_value;
102 }
103 else
104 {
105 throw OdsException(
106 QObject::tr("this cell is not a date :\n").append(toString()));
107 }
108};
109const QString &
111{
112 if(isString())
113 {
114 return _string_value;
115 }
116 else
117 {
118 throw OdsException(
119 QObject::tr("this cell is not a string :\n").append(toString()));
120 }
121};
122double
124{
125 if(isDouble())
126 {
127 return _double_value;
128 }
129 else
130 {
131 throw OdsException(
132 QObject::tr("this cell is not a double :\n").append(toString()));
133 }
134};
135bool
137{
138 if(isBoolean())
139 {
140 return _bool_value;
141 }
142 else
143 {
144 throw OdsException(
145 QObject::tr("this cell is not a boolean :\n").append(toString()));
146 }
147};
148bool
150{
151 return _is_empty;
152};
153bool
155{
156 if(_office_value_type == "date")
157 return true;
158 return false;
159};
160bool
162{
163 if(_office_value_type == "float")
164 return true;
165 return false;
166};
167bool
169{
170 if(isDate())
171 return false;
172 if(isDouble())
173 return false;
174 if(isBoolean())
175 return false;
176 if(isEmpty())
177 return false;
178 return true;
179};
180bool
182{
183 if(_office_value_type == "boolean")
184 return true;
185 return false;
186};
187
188
189void
191{
192 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
193 << value;
194 _office_value_type = "string";
195 _string_value = value;
196
197 // float
198 // percentage
199 // currency
200 // date
201 // time
202 // boolean
203 // string
204
205 bool ok;
206 _double_value = _string_value.toDouble(&ok);
207 if(ok)
208 {
209 _office_value_type = "float";
210 return;
211 }
212 else
213 {
214 // test for french decimal separator
215 _double_value = QString(_string_value).replace(",", ".").toDouble(&ok);
216 if(ok)
217 {
218 _office_value_type = "float";
219 _string_value = QString(_string_value).replace(",", ".");
220 return;
221 }
222 }
223 if((_string_value == "T") || (_string_value == "TRUE") ||
224 (_string_value == "VRAI"))
225 {
226 _bool_value = true;
227 _office_value_type = "boolean";
228 return;
229 }
230 if((_string_value == "F") || (_string_value == "FALSE") ||
231 (_string_value == "FAUX"))
232 {
233 _bool_value = false;
234 _office_value_type = "boolean";
235 return;
236 }
237 QDateTime date = QDateTime::fromString(_string_value, "yyyy-MM-ddThh:mm:ss");
238 if(date.isValid())
239 {
240 _date_value = date;
241 _office_value_type = "date";
242 return;
243 }
244 date = QDateTime::fromString(_string_value, "yyyy-MM-dd");
245 if(date.isValid())
246 {
247 _date_value = date;
248 _office_value_type = "date";
249 return;
250 }
251 if(!_string_value.isEmpty())
252 {
253 _is_empty = false;
254 }
255};
void setOfficeValueType(const QString &type)
Definition odscell.cpp:33
void setValueOfUndefinedType(const QString &value)
Definition odscell.cpp:190
QDateTime _date_value
Definition odscell.h:59
bool getBooleanValue() const
Definition odscell.cpp:136
bool _is_empty
Definition odscell.h:62
const QDateTime & getDateTimeValue() const
Definition odscell.cpp:97
void setValueString(const QString &value)
Definition odscell.cpp:65
bool _bool_value
Definition odscell.h:61
const QString & toString() const
Definition odscell.cpp:83
double getDoubleValue() const
Definition odscell.cpp:123
bool isBoolean() const
Definition odscell.cpp:181
bool isDate() const
Definition odscell.cpp:154
bool isString() const
Definition odscell.cpp:168
bool isEmpty() const
Definition odscell.cpp:149
virtual ~OdsCell()
Definition odscell.cpp:28
bool isDouble() const
Definition odscell.cpp:161
QString _office_value_type
Definition odscell.h:58
const QString & getStringValue() const
Definition odscell.cpp:110
void setValueBoolean(bool value_bool)
Definition odscell.cpp:76
void setValueDouble(double value_num)
Definition odscell.cpp:70
OdsCell()
Definition odscell.cpp:24
void setDateValue(const QDateTime &date)
Definition odscell.cpp:56
double _double_value
Definition odscell.h:60
const QString & getOfficeValueType() const
Definition odscell.cpp:91
QString _string_value
Definition odscell.h:57