andre@1: /**************************************************************************** andre@1: ** Copyright (c) 2013-2014 Debao Zhang andre@1: ** All right reserved. andre@1: ** andre@1: ** Permission is hereby granted, free of charge, to any person obtaining andre@1: ** a copy of this software and associated documentation files (the andre@1: ** "Software"), to deal in the Software without restriction, including andre@1: ** without limitation the rights to use, copy, modify, merge, publish, andre@1: ** distribute, sublicense, and/or sell copies of the Software, and to andre@1: ** permit persons to whom the Software is furnished to do so, subject to andre@1: ** the following conditions: andre@1: ** andre@1: ** The above copyright notice and this permission notice shall be andre@1: ** included in all copies or substantial portions of the Software. andre@1: ** andre@1: ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, andre@1: ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF andre@1: ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND andre@1: ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE andre@1: ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION andre@1: ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION andre@1: ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. andre@1: ** andre@1: ****************************************************************************/ andre@1: #include "xlsxcell.h" andre@1: #include "xlsxcell_p.h" andre@1: #include "xlsxformat.h" andre@1: #include "xlsxformat_p.h" andre@1: #include "xlsxutility_p.h" andre@1: #include "xlsxworksheet.h" andre@1: #include "xlsxworkbook.h" andre@1: #include andre@1: andre@1: QT_BEGIN_NAMESPACE_XLSX andre@1: andre@1: CellPrivate::CellPrivate(Cell *p) : andre@1: q_ptr(p) andre@1: { andre@1: andre@1: } andre@1: andre@1: CellPrivate::CellPrivate(const CellPrivate * const cp) andre@1: : value(cp->value), formula(cp->formula), cellType(cp->cellType) andre@1: , format(cp->format), richString(cp->richString), parent(cp->parent) andre@1: { andre@1: andre@1: } andre@1: andre@1: /*! andre@1: \class Cell andre@1: \inmodule QtXlsx andre@1: \brief The Cell class provides a API that is used to handle the worksheet cell. andre@1: andre@1: */ andre@1: andre@1: /*! andre@1: \enum Cell::CellType andre@1: \value BooleanType Boolean type andre@1: \value NumberType Number type, can be blank or used with forumula andre@1: \value ErrorType Error type andre@1: \value SharedStringType Shared string type andre@1: \value StringType String type, can be used with forumula andre@1: \value InlineStringType Inline string type andre@1: */ andre@1: andre@1: /*! andre@1: * \internal andre@1: * Created by Worksheet only. andre@1: */ andre@1: Cell::Cell(const QVariant &data, CellType type, const Format &format, Worksheet *parent) : andre@1: d_ptr(new CellPrivate(this)) andre@1: { andre@1: d_ptr->value = data; andre@1: d_ptr->cellType = type; andre@1: d_ptr->format = format; andre@1: d_ptr->parent = parent; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: Cell::Cell(const Cell * const cell): andre@1: d_ptr(new CellPrivate(cell->d_ptr)) andre@1: { andre@1: d_ptr->q_ptr = this; andre@1: } andre@1: andre@1: /*! andre@1: * Destroys the Cell and cleans up. andre@1: */ andre@1: Cell::~Cell() andre@1: { andre@1: delete d_ptr; andre@1: } andre@1: andre@1: /*! andre@1: * Return the dataType of this Cell andre@1: */ andre@1: Cell::CellType Cell::cellType() const andre@1: { andre@1: Q_D(const Cell); andre@1: return d->cellType; andre@1: } andre@1: andre@1: /*! andre@1: * Return the data content of this Cell andre@1: */ andre@1: QVariant Cell::value() const andre@1: { andre@1: Q_D(const Cell); andre@1: return d->value; andre@1: } andre@1: andre@1: /*! andre@1: * Return the style used by this Cell. If no style used, 0 will be returned. andre@1: */ andre@1: Format Cell::format() const andre@1: { andre@1: Q_D(const Cell); andre@1: return d->format; andre@1: } andre@1: andre@1: /*! andre@1: * Returns true if the cell has one formula. andre@1: */ andre@1: bool Cell::hasFormula() const andre@1: { andre@1: Q_D(const Cell); andre@1: return d->formula.isValid(); andre@1: } andre@1: andre@1: /*! andre@1: * Return the formula contents if the dataType is Formula andre@1: */ andre@1: CellFormula Cell::formula() const andre@1: { andre@1: Q_D(const Cell); andre@1: return d->formula; andre@1: } andre@1: andre@1: /*! andre@1: * Returns whether the value is probably a dateTime or not andre@1: */ andre@1: bool Cell::isDateTime() const andre@1: { andre@1: Q_D(const Cell); andre@1: if (d->cellType == NumberType && d->value.toDouble() >=0 andre@1: && d->format.isValid() && d->format.isDateTimeFormat()) { andre@1: return true; andre@1: } andre@1: return false; andre@1: } andre@1: andre@1: /*! andre@1: * Return the data time value. andre@1: */ andre@1: QDateTime Cell::dateTime() const andre@1: { andre@1: Q_D(const Cell); andre@1: if (!isDateTime()) andre@1: return QDateTime(); andre@1: return datetimeFromNumber(d->value.toDouble(), d->parent->workbook()->isDate1904()); andre@1: } andre@1: andre@1: /*! andre@1: * Returns whether the cell is probably a rich string or not andre@1: */ andre@1: bool Cell::isRichString() const andre@1: { andre@1: Q_D(const Cell); andre@1: if (d->cellType != SharedStringType && d->cellType != InlineStringType andre@1: && d->cellType != StringType) andre@1: return false; andre@1: andre@1: return d->richString.isRichString(); andre@1: } andre@1: andre@1: QT_END_NAMESPACE_XLSX