filters
cell.cpp
00001 /* Swinder - Portable library for spreadsheet 00002 Copyright (C) 2003 Ariya Hidayat <ariya@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA 00018 */ 00019 00020 #include "cell.h" 00021 00022 #include "ustring.h" 00023 #include "format.h" 00024 #include "value.h" 00025 00026 #include <iostream> 00027 00028 namespace Swinder 00029 { 00030 00031 class Cell::Private 00032 { 00033 public: 00034 Sheet* sheet; 00035 unsigned row; 00036 unsigned column; 00037 Value value; 00038 UString formula; 00039 Format format; 00040 unsigned columnSpan; 00041 unsigned rowSpan; 00042 }; 00043 00044 } 00045 00046 using namespace Swinder; 00047 00048 Cell::Cell( Sheet* sheet, unsigned column, unsigned row ) 00049 { 00050 d = new Cell::Private(); 00051 d->sheet = sheet; 00052 d->column = column; 00053 d->row = row; 00054 d->value = Value::empty(); 00055 d->columnSpan = 1; 00056 d->rowSpan = 1; 00057 } 00058 00059 Cell::~Cell() 00060 { 00061 delete d; 00062 } 00063 00064 Sheet* Cell::sheet() 00065 { 00066 return d->sheet; 00067 } 00068 00069 unsigned Cell::column() const 00070 { 00071 return d->column; 00072 } 00073 00074 unsigned Cell::row() const 00075 { 00076 return d->row; 00077 } 00078 00079 UString Cell::name() const 00080 { 00081 return name( column(), row() ); 00082 } 00083 00084 UString Cell::name( unsigned column, unsigned row ) 00085 { 00086 return columnLabel( column ) + UString::from( row ); 00087 } 00088 00089 UString Cell::columnLabel() const 00090 { 00091 return columnLabel( column() ); 00092 } 00093 00094 // FIXME be careful for integer overflow 00095 UString Cell::columnLabel( unsigned column ) 00096 { 00097 UString str; 00098 unsigned digits = 1; 00099 unsigned offset = 0; 00100 00101 for( unsigned limit = 26; column >= limit+offset; limit *= 26, digits++ ) 00102 offset += limit; 00103 00104 for( unsigned c = column - offset; digits; --digits, c/=26 ) 00105 str = UString( UChar( 'A' + (c%26) ) ) + str; 00106 00107 return str; 00108 } 00109 00110 Value Cell::value() const 00111 { 00112 return d->value; 00113 } 00114 00115 void Cell::setValue( const Value& value ) 00116 { 00117 d->value = value; 00118 } 00119 00120 UString Cell::formula() const 00121 { 00122 return d->formula; 00123 } 00124 00125 void Cell::setFormula( const UString& formula ) 00126 { 00127 d->formula = formula; 00128 } 00129 00130 Format Cell::format() const 00131 { 00132 return d->format; 00133 } 00134 00135 void Cell::setFormat( const Format& format ) 00136 { 00137 d->format = format; 00138 } 00139 00140 unsigned Cell::columnSpan() const 00141 { 00142 return d->columnSpan; 00143 } 00144 00145 void Cell::setColumnSpan( unsigned span ) 00146 { 00147 if( span < 1 ) return; 00148 d->columnSpan = span; 00149 } 00150 00151 unsigned Cell::rowSpan() const 00152 { 00153 return d->rowSpan; 00154 } 00155 00156 void Cell::setRowSpan( unsigned span ) 00157 { 00158 if( span < 1 ) return; 00159 d->rowSpan = span; 00160 }