1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/* This file is part of the KDE project
Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
Copyright 2004 Tomas Mecir <mecirt@gmail.com>
Copyright 1998,1999 Torben Weis <weis@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef CALLIGRA_SHEETS_VALUE_PARSER
#define CALLIGRA_SHEETS_VALUE_PARSER
#include <QDateTime>
#include "Format.h"
#include "Number.h"
#include "sheets_odf_export.h"
namespace Calligra
{
namespace Sheets
{
class CalculationSettings;
class Value;
/**
* \ingroup Value
* Generates a Value by parsing a user input text.
* Determines the most probable Value type, e.g. integer or date.
*/
class CALLIGRA_SHEETS_ODF_EXPORT ValueParser
{
public:
/**
* Constructor.
*/
explicit ValueParser(const CalculationSettings* settings);
/**
* Returns the calculation settings this ValueFormatter uses.
*/
const CalculationSettings* settings() const;
/**
* Parses the user input text \p str and tries to determine the correct
* value type for it.
*/
Value parse(const QString& str) const;
/**
* Tries for boolean type. If \p str can be interpreted as this
* type, \p ok is set to \c true and the corresponding value will
* be returned.
*/
Value tryParseBool(const QString& str, bool *ok = 0) const;
/**
* Tries for floating point, integer, complex (and percentage) type.
* If \p str can be interpreted as one of these types, \p ok is set to
* \c true and the corresponding value will be returned.
*/
Value tryParseNumber(const QString& str, bool *ok = 0) const;
/**
* Tries for date type. If \p str can be interpreted as this
* type, \p ok is set to \c true and the corresponding value will
* be returned.
*/
Value tryParseDate(const QString& str, bool *ok = 0) const;
/**
* Tries for time type. If \p str can be interpreted as this
* type, \p ok is set to \c true and the corresponding value will
* be returned.
*/
Value tryParseTime(const QString& str, bool *ok = 0) const;
protected:
/**
* Converts \p str to a date/time value.
*/
QDateTime readTime(const QString& str, bool withSeconds, bool *ok) const;
/**
* A helper function to read numbers and distinguish integers and FPs.
*/
Value readNumber(const QString &_str, bool* ok) const;
/**
* A helper function to read the imaginary part of a complex number.
*/
Number readImaginary(const QString& str, bool* ok) const;
/**
* A helper function to read integers.
* Used in the parsing process for date and time values.
*/
int readInt(const QString& str, uint& pos) const;
private:
const CalculationSettings* m_settings;
};
} // namespace Sheets
} // namespace Calligra
#endif //CALLIGRA_SHEETS_VALUE_PARSER
|