kspread

Cell.h

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright 2006-2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00003    Copyright 2004 Tomas Mecir <mecirt@gmail.com>
00004    Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
00005    Copyright 2002,2004 Ariya Hidayat <ariya@kde.org>
00006    Copyright 2002-2003 Norbert Andres <nandres@web.de>
00007    Copyright 2003 Stefan Hetzl <shetzl@chello.at>
00008    Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
00009    Copyright 2002 Harri Porten <porten@kde.org>
00010    Copyright 2002 John Dailey <dailey@vt.edu>
00011    Copyright 1999-2001 David Faure <faure@kde.org>
00012    Copyright 2000-2001 Werner Trobin <trobin@kde.org>
00013    Copyright 2000 Simon Hausmann <hausmann@kde.org
00014    Copyright 1998-1999 Torben Weis <weis@kde.org>
00015    Copyright 1999 Michael Reiher <michael.reiher@gmx.de>
00016    Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
00017 
00018    This library is free software; you can redistribute it and/or
00019    modify it under the terms of the GNU Library General Public
00020    License as published by the Free Software Foundation; either
00021    version 2 of the License, or (at your option) any later version.
00022 
00023    This library is distributed in the hope that it will be useful,
00024    but WITHOUT ANY WARRANTY; without even the implied warranty of
00025    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026    Library General Public License for more details.
00027 
00028    You should have received a copy of the GNU Library General Public License
00029    along with this library; see the file COPYING.LIB.  If not, write to
00030    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00031    Boston, MA 02110-1301, USA.
00032 */
00033 
00034 #ifndef KSPREAD_CELL
00035 #define KSPREAD_CELL
00036 
00037 #include <QDate>
00038 #include <QSharedDataPointer>
00039 
00040 #include "Condition.h"
00041 #include "Global.h"
00042 #include "Format.h"
00043 
00044 #include "database/Database.h"
00045 
00046 class QDomElement;
00047 class QDomDocument;
00048 class QFont;
00049 class QRect;
00050 class QPoint;
00051 
00052 class KLocale;
00053 class KoXmlWriter;
00054 class KoGenStyles;
00055 class KoGenStyle;
00056 class KoOdfLoadingContext;
00057 
00058 namespace KSpread
00059 {
00060 class Doc;
00061 class Formula;
00062 class OdfLoadingContext;
00063 class OdfSavingContext;
00064 class Sheet;
00065 class Validity;
00066 class Value;
00067 
00074 class KSPREAD_EXPORT Cell
00075 {
00076 public:
00083     Cell();
00084 
00089     Cell( const Sheet* sheet, int column, int row );
00090 
00095     Cell( const Sheet* sheet, const QPoint& pos );
00096 
00100     Cell( const Cell& other );
00101 
00105     ~Cell();
00106 
00110     Sheet* sheet() const;
00111 
00115     KLocale* locale() const;
00116 
00121     bool isDefault() const;
00122 
00126     bool isEmpty() const;
00127 
00131     bool isNull() const;
00132 
00136     bool isFormula() const;
00137 
00141     int column() const;
00142 
00146     int row() const;
00147 
00152     QString name() const;
00153 
00158     QString fullName() const;
00159 
00163     QString columnName() const;
00164 
00169     static QString name( int col, int row );
00170 
00175     static QString fullName( const Sheet *s, int col, int row );
00176 
00181     static QString columnName( uint column );
00182 
00186     QString displayText() const;
00187 
00191     QString comment() const;
00192 
00193     void setComment( const QString& comment );
00194 
00198     Conditions conditions() const;
00199 
00200     void setConditions( const Conditions& conditions );
00201 
00205     Database database() const;
00206 
00211     Formula formula() const;
00212 
00216     void setFormula( const Formula& formula );
00217 
00222     QString link() const;
00223 
00230     void setLink( const QString& link );
00231 
00235     Style style() const;
00236 
00241     Style effectiveStyle() const;
00242 
00243     void setStyle( const Style& style );
00244 
00248     Validity validity() const;
00249 
00250     void setValidity( Validity validity );
00251 
00256     const Value value() const;
00257 
00267     void setValue( const Value& value );
00268 
00273     QString userInput() const;
00274 
00282     void setUserInput( const QString& text );
00283 
00293     void parseUserInput( const QString& text );
00294 
00298     bool load( const KoXmlElement& cell,
00299                int _xshift, int _yshift,
00300                Paste::Mode pm = Paste::Normal,
00301                Paste::Operation op = Paste::OverWrite,
00302                bool paste = false );
00303 
00314     QDomElement save(QDomDocument& doc, int xOffset = 0, int yOffset = 0, bool era = false);
00315 
00320     QTime toTime(const KoXmlElement &element);
00321 
00326     QDate toDate(const KoXmlElement &element);
00327 
00334     bool loadOdf(const KoXmlElement& element, OdfLoadingContext& tableContext);
00335 
00339     bool saveOdf( KoXmlWriter& xmlwriter, KoGenStyles& mainStyles,
00340                     int row, int column, int &repeated,
00341                    OdfSavingContext& savingContext);
00342 
00348     void copyFormat( const Cell& cell );
00349 
00355     void copyContent( const Cell& cell );
00356 
00363     void copyAll( const Cell& cell);
00364 
00368     double width() const;
00369 
00373     double height() const;
00374 
00378     QPoint cellPosition() const;
00379 
00387     bool needsPrinting() const;
00388 
00389     //
00390     //END
00391     //
00393     //
00394     //BEGIN Merging
00395     //
00396 
00403     bool isPartOfMerged() const;
00404 
00408     Cell masterCell() const;
00409 
00421     void mergeCells( int _col, int _row, int _x, int _y );
00422 
00426     bool doesMergeCells() const;
00427 
00432     int mergedXCells() const;
00433 
00438     int mergedYCells() const;
00439 
00440     //
00441     //END Merging
00442     //
00444     //
00445     //BEGIN Matrix locking
00446     //
00447 
00448     bool isLocked() const;
00449     QRect lockedCells() const;
00450 
00451     //
00452     //END Matrix locking
00453     //
00455     //
00456     //BEGIN Cut & paste
00457     //
00458 
00467     QString encodeFormula(bool fixedReferences = false) const;
00468 
00474     QString decodeFormula(const QString& text) const;
00475 
00485     QString pasteOperation( const QString &new_text, const QString &old_text, Paste::Operation op );
00486 
00487     //
00488     //END Cut & paste
00489     //
00491     //
00492     //BEGIN
00493     //
00494 
00499     bool makeFormula();
00500 
00501     //
00502     //END
00503     //
00505     //
00506     //BEGIN Effective style attributes
00507     //
00508 
00510     int effectiveAlignX() const;
00512     bool isDate() const;
00514     bool isTime() const;
00516     bool isText() const;
00517 
00518     //
00519     //END Effective style attributes
00520     //
00522     //
00523     //BEGIN Operators
00524     //
00525 
00529     Cell& operator=( const Cell& other );
00530 
00536     bool operator<( const Cell& other ) const;
00537 
00543     bool operator==( const Cell& other ) const;
00544 
00548     bool operator!() const;
00549 
00550     //
00551     //END Operators
00552     //
00554     //
00555     //BEGIN
00556     //
00557 
00561     bool compareData( const Cell& other ) const;
00562 
00563 protected:
00569     void loadOdfCellText( const KoXmlElement& parent );
00570 
00574     void loadOdfObjects( const KoXmlElement& e, KoOdfLoadingContext& odfContext );
00575 
00579     void saveOdfAnnotation( KoXmlWriter &xmlwriter );
00580 
00581 private:
00582     class Private;
00583     QSharedDataPointer<Private> d;
00584 
00588     bool loadCellData(const KoXmlElement &text, Paste::Operation op);
00589 
00593     bool saveCellResult( QDomDocument& doc, QDomElement& result, QString str );
00594 
00598     void saveOdfValue (KoXmlWriter &xmlWriter);
00599 
00604     QString saveOdfCellStyle( KoGenStyle &currentCellStyle, KoGenStyles &mainStyles );
00605 };
00606 
00607 inline uint qHash( const Cell& cell )
00608 {
00609     return ( static_cast<uint>( cell.column() ) << 16 ) + static_cast<uint>( cell.row() );
00610 }
00611 
00612 } // namespace KSpread
00613 
00614 Q_DECLARE_TYPEINFO( KSpread::Cell, Q_MOVABLE_TYPE );
00615 
00616 
00617 /***************************************************************************
00618   kDebug support
00619 ****************************************************************************/
00620 
00621 inline kdbgstream operator<<(kdbgstream str, const KSpread::Cell& cell)
00622 {
00623     return str << qPrintable(KSpread::Cell::columnName(cell.column()) + QString::number(cell.row()));
00624 }
00625 
00626 #endif  // KSPREAD_CELL