kspread

krs_cell.cpp
1/*
2 * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
3 * Copyright (c) 2006 Isaac Clerencia <isaac@warp.es>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published by
7 * the Free Software Foundation; either version 2 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 Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "krs_cell.h"
21
22#include "manipulator.h"
23#include "manipulator_data.h"
24
25namespace Kross { namespace KSpreadCore {
26
27Cell::Cell(KSpread::Cell* cell, KSpread::Sheet* sheet, uint col, uint row)
28 : Kross::Api::Class<Cell>("KSpreadCell"), m_cell(cell), m_sheet(sheet), m_col(col), m_row(row)
29{
30 this->addFunction0< Kross::Api::Variant >("value", this, &Cell::value);
31 this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("setValue", this, &Cell::setValue);
32
33 this->addFunction0< Kross::Api::Variant >("column", this, &Cell::column);
34 this->addFunction0< Kross::Api::Variant >("row", this, &Cell::row);
35
36 this->addFunction0< Cell >("previousCell", this, &Cell::previousCell);
37 this->addFunction0< Cell >("nextCell", this, &Cell::nextCell);
38 this->addFunction1< void, Cell >("setPreviousCell", this, &Cell::setPreviousCell);
39 this->addFunction1< void, Cell >("setNextCell", this, &Cell::setNextCell);
40
41 this->addFunction0< Kross::Api::Variant >("name", this, &Cell::name);
42 this->addFunction0< Kross::Api::Variant >("fullName", this, &Cell::fullName);
43
44 this->addFunction0< Kross::Api::Variant >("comment", this, &Cell::comment);
45 this->addFunction1< void, Kross::Api::Variant >("setComment", this, &Cell::setComment);
46
47 this->addFunction0< Kross::Api::Variant >("getFormatString", this, &Cell::getFormatString);
48 this->addFunction1< void, Kross::Api::Variant >("setFormatString", this, &Cell::setFormatString);
49
50 this->addFunction0< Kross::Api::Variant >("text", this, &Cell::text);
51 this->addFunction1< void, Kross::Api::Variant >("setText", this, &Cell::setText);
52
53 this->addFunction0< Kross::Api::Variant >("textColor", this, &Cell::textColor);
54 this->addFunction1< void, Kross::Api::Variant >("setTextColor", this, &Cell::setTextColor);
55 this->addFunction0< Kross::Api::Variant >("backgroundColor", this, &Cell::backgroundColor);
56 this->addFunction1< void, Kross::Api::Variant >("setBackgroundColor", this, &Cell::setBackgroundColor);
57}
58
59Cell::~Cell() {
60}
61
62const TQString Cell::getClassName() const {
63 return "Kross::KSpreadCore::KSpreadCell";
64}
65
66TQVariant Cell::toVariant(const KSpread::Value& value) const
67{
68 //Should we use following value-format enums here?
69 //fmt_None, fmt_Boolean, fmt_Number, fmt_Percent, fmt_Money, fmt_DateTime, fmt_Date, fmt_Time, fmt_String
70
71 switch(value.type()) {
72 case KSpread::Value::Empty:
73 return TQVariant();
74 case KSpread::Value::Boolean:
75 return TQVariant( value.asBoolean() );
76 case KSpread::Value::Integer:
77 return static_cast<TQ_LLONG>(value.asInteger());
78 case KSpread::Value::Float:
79 return (float)value.asFloat();
80 case KSpread::Value::String:
81 return value.asString();
82 case KSpread::Value::Array: {
83 TQValueList<TQVariant> colarray;
84 for(uint j = 0; j < value.rows(); j++) {
85 TQValueList<TQVariant> rowarray;
86 for( uint i = 0; i < value.columns(); i++) {
87 KSpread::Value v = value.element(i,j);
88 rowarray.append( toVariant(v) );
89 }
90 colarray.append(rowarray);
91 }
92 return colarray;
93 } break;
94 case KSpread::Value::CellRange:
95 //FIXME: not yet used
96 return TQVariant();
97 case KSpread::Value::Error:
98 return TQVariant();
99 }
100 return TQVariant();
101}
102
103TQVariant Cell::value() const {
104 return toVariant( m_cell->value() );
105}
106
107bool Cell::setValue(const TQVariant& value) {
108 KSpread::Value v = m_cell->value();
109 switch(value.type()) {
110 case TQVariant::Bool: v.setValue( value.toBool() ); break;
111 case TQVariant::ULongLong: v.setValue( (long)value.toLongLong() ); break;
112 case TQVariant::Int: v.setValue( value.toInt() ); break;
113 case TQVariant::Double: v.setValue( value.toDouble() ); break;
114 case TQVariant::String: v.setValue( value.toString() ); break;
115 case TQVariant::Date: v.setValue( value.toDate() ); break;
116 case TQVariant::Time: v.setValue( value.toTime() ); break;
117 case TQVariant::DateTime: v.setValue( value.toDateTime() ); break;
118 default: return false;
119 }
120 return true;
121}
122
123int Cell::column() const {
124 return m_cell->column();
125}
126
127int Cell::row() const {
128 return m_cell->row();
129}
130
131Cell* Cell::previousCell() const {
132 KSpread::Cell* c = m_cell->previousCell();
133 return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
134}
135
136Cell* Cell::nextCell() const {
137 KSpread::Cell* c = m_cell->nextCell();
138 return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
139}
140
141void Cell::setPreviousCell(Cell* c) {
142 return m_cell->setPreviousCell(c->m_cell);
143}
144
145void Cell::setNextCell(Cell* c) {
146 return m_cell->setNextCell(c->m_cell);
147}
148
149const TQString Cell::name() const {
150 return m_cell->name();
151}
152
153const TQString Cell::fullName() const {
154 return m_cell->fullName();
155}
156
157const TQString Cell::comment() const {
158 return m_cell->format()->comment(m_col, m_row);
159}
160
161void Cell::setComment(const TQString& c) {
162 return m_cell->format()->setComment(c);
163}
164
165const TQString Cell::getFormatString() const {
166 return m_cell->format()->getFormatString(m_col, m_row);
167}
168
169void Cell::setFormatString(const TQString& format) {
170 m_cell->format()->setFormatString(format);
171}
172
173const TQString Cell::text() const {
174 return m_cell->text();
175}
176
177bool Cell::setText(const TQString& text) {
179 prot.setSheet (m_sheet);
180 prot.add (TQPoint (m_col, m_row));
181 if (prot.check())
182 return false;
183
185 dm->setSheet (m_sheet);
186 dm->setValue (text);
187 dm->setParsing (true);
188 dm->add (TQPoint (m_col, m_row));
189 dm->execute ();
190
191 return true;
192}
193
194const TQString Cell::textColor() {
195 return m_cell->format()->textColor(m_col, m_row).name();
196}
197
198void Cell::setTextColor(const TQString& textcolor) {
199 m_cell->format()->setTextColor( TQColor(textcolor) );
200}
201
202const TQString Cell::backgroundColor() {
203 return m_cell->format()->bgColor(m_col, m_row).name();
204}
205
206void Cell::setBackgroundColor(const TQString& backgroundcolor) {
207 m_cell->format()->setBgColor( TQColor(backgroundcolor) );
208}
209
210}
211}
For every cell in the spread sheet there is a Cell object.
int row() const
Returns the cell's row.
Sheet * sheet() const
Returns the worksheet which owns this cell.
int column() const
Returns the cell's column.
DataManipulator - allows setting values on one range.
void setValue(Value val)
set the values for the range.
class ProtectedCheck can be used to check, whether a particular range is protected or not
Element * add(const TQPoint &point, Sheet *sheet=0)
Adds the point point to this region.
Definition region.cpp:245
Provides a wrapper for cell value.
unsigned columns() const
If this value is an array, return the number of columns.
Value element(unsigned column, unsigned row) const
Return an element in the array value.
void setValue(const Value &v)
Sets this value to another value.
unsigned rows() const
If this value is an array, return the number of rows.
Type type() const
Returns the type of the value.
double asFloat() const
Returns the floating-point value of this value.
long asInteger() const
Returns the integer value of this value.
TQString asString() const
Returns the string value of this value.
bool asBoolean() const
Returns the boolean value of this value.
For every cell in the spread sheet there is a Cell object.
Definition krs_cell.h:51