00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "krs_cell.h"
00021
00022 #include "manipulator.h"
00023 #include "manipulator_data.h"
00024
00025 namespace Kross { namespace KSpreadCore {
00026
00027 Cell::Cell(KSpread::Cell* cell, KSpread::Sheet* sheet, uint col, uint row)
00028 : Kross::Api::Class<Cell>("KSpreadCell"), m_cell(cell), m_sheet(sheet), m_col(col), m_row(row)
00029 {
00030 this->addFunction0< Kross::Api::Variant >("value", this, &Cell::value);
00031 this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("setValue", this, &Cell::setValue);
00032
00033 this->addFunction0< Kross::Api::Variant >("column", this, &Cell::column);
00034 this->addFunction0< Kross::Api::Variant >("row", this, &Cell::row);
00035
00036 this->addFunction0< Cell >("previousCell", this, &Cell::previousCell);
00037 this->addFunction0< Cell >("nextCell", this, &Cell::nextCell);
00038 this->addFunction1< void, Cell >("setPreviousCell", this, &Cell::setPreviousCell);
00039 this->addFunction1< void, Cell >("setNextCell", this, &Cell::setNextCell);
00040
00041 this->addFunction0< Kross::Api::Variant >("name", this, &Cell::name);
00042 this->addFunction0< Kross::Api::Variant >("fullName", this, &Cell::fullName);
00043
00044 this->addFunction0< Kross::Api::Variant >("comment", this, &Cell::comment);
00045 this->addFunction1< void, Kross::Api::Variant >("setComment", this, &Cell::setComment);
00046
00047 this->addFunction0< Kross::Api::Variant >("getFormatString", this, &Cell::getFormatString);
00048 this->addFunction1< void, Kross::Api::Variant >("setFormatString", this, &Cell::setFormatString);
00049
00050 this->addFunction0< Kross::Api::Variant >("text", this, &Cell::text);
00051 this->addFunction1< void, Kross::Api::Variant >("setText", this, &Cell::setText);
00052
00053 this->addFunction0< Kross::Api::Variant >("textColor", this, &Cell::textColor);
00054 this->addFunction1< void, Kross::Api::Variant >("setTextColor", this, &Cell::setTextColor);
00055 this->addFunction0< Kross::Api::Variant >("backgroundColor", this, &Cell::backgroundColor);
00056 this->addFunction1< void, Kross::Api::Variant >("setBackgroundColor", this, &Cell::setBackgroundColor);
00057 }
00058
00059 Cell::~Cell() {
00060 }
00061
00062 const QString Cell::getClassName() const {
00063 return "Kross::KSpreadCore::KSpreadCell";
00064 }
00065
00066 QVariant Cell::toVariant(const KSpread::Value& value) const
00067 {
00068
00069
00070
00071 switch(value.type()) {
00072 case KSpread::Value::Empty:
00073 return QVariant();
00074 case KSpread::Value::Boolean:
00075 return QVariant( value.asBoolean() );
00076 case KSpread::Value::Integer:
00077 return static_cast<Q_LLONG>(value.asInteger());
00078 case KSpread::Value::Float:
00079 return (float)value.asFloat();
00080 case KSpread::Value::String:
00081 return value.asString();
00082 case KSpread::Value::Array: {
00083 QValueList<QVariant> colarray;
00084 for(uint j = 0; j < value.rows(); j++) {
00085 QValueList<QVariant> rowarray;
00086 for( uint i = 0; i < value.columns(); i++) {
00087 KSpread::Value v = value.element(i,j);
00088 rowarray.append( toVariant(v) );
00089 }
00090 colarray.append(rowarray);
00091 }
00092 return colarray;
00093 } break;
00094 case KSpread::Value::CellRange:
00095
00096 return QVariant();
00097 case KSpread::Value::Error:
00098 return QVariant();
00099 }
00100 return QVariant();
00101 }
00102
00103 QVariant Cell::value() const {
00104 return toVariant( m_cell->value() );
00105 }
00106
00107 bool Cell::setValue(const QVariant& value) {
00108 KSpread::Value v = m_cell->value();
00109 switch(value.type()) {
00110 case QVariant::Bool: v.setValue( value.toBool() ); break;
00111 case QVariant::ULongLong: v.setValue( (long)value.toLongLong() ); break;
00112 case QVariant::Int: v.setValue( value.toInt() ); break;
00113 case QVariant::Double: v.setValue( value.toDouble() ); break;
00114 case QVariant::String: v.setValue( value.toString() ); break;
00115 case QVariant::Date: v.setValue( value.toDate() ); break;
00116 case QVariant::Time: v.setValue( value.toTime() ); break;
00117 case QVariant::DateTime: v.setValue( value.toDateTime() ); break;
00118 default: return false;
00119 }
00120 return true;
00121 }
00122
00123 int Cell::column() const {
00124 return m_cell->column();
00125 }
00126
00127 int Cell::row() const {
00128 return m_cell->row();
00129 }
00130
00131 Cell* Cell::previousCell() const {
00132 KSpread::Cell* c = m_cell->previousCell();
00133 return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
00134 }
00135
00136 Cell* Cell::nextCell() const {
00137 KSpread::Cell* c = m_cell->nextCell();
00138 return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
00139 }
00140
00141 void Cell::setPreviousCell(Cell* c) {
00142 return m_cell->setPreviousCell(c->m_cell);
00143 }
00144
00145 void Cell::setNextCell(Cell* c) {
00146 return m_cell->setNextCell(c->m_cell);
00147 }
00148
00149 const QString Cell::name() const {
00150 return m_cell->name();
00151 }
00152
00153 const QString Cell::fullName() const {
00154 return m_cell->fullName();
00155 }
00156
00157 const QString Cell::comment() const {
00158 return m_cell->format()->comment(m_col, m_row);
00159 }
00160
00161 void Cell::setComment(const QString& c) {
00162 return m_cell->format()->setComment(c);
00163 }
00164
00165 const QString Cell::getFormatString() const {
00166 return m_cell->format()->getFormatString(m_col, m_row);
00167 }
00168
00169 void Cell::setFormatString(const QString& format) {
00170 m_cell->format()->setFormatString(format);
00171 }
00172
00173 const QString Cell::text() const {
00174 return m_cell->text();
00175 }
00176
00177 bool Cell::setText(const QString& text, bool asString) {
00178
00179
00180
00181
00182
00183 KSpread::ProtectedCheck prot;
00184 prot.setSheet (m_sheet);
00185 prot.add (QPoint (m_col, m_row));
00186 if (prot.check())
00187 return false;
00188
00189 KSpread::DataManipulator *dm = new KSpread::DataManipulator ();
00190 dm->setSheet (m_sheet);
00191 dm->setValue (text);
00192 dm->setParsing (!asString);
00193 dm->add (QPoint (m_col, m_row));
00194 dm->execute ();
00195
00196 return true;
00197 }
00198
00199 const QString Cell::textColor() {
00200 return m_cell->format()->textColor(m_col, m_row).name();
00201 }
00202
00203 void Cell::setTextColor(const QString& textcolor) {
00204 m_cell->format()->setTextColor( QColor(textcolor) );
00205 }
00206
00207 const QString Cell::backgroundColor() {
00208 return m_cell->format()->bgColor(m_col, m_row).name();
00209 }
00210
00211 void Cell::setBackgroundColor(const QString& backgroundcolor) {
00212 m_cell->format()->setBgColor( QColor(backgroundcolor) );
00213 }
00214
00215 }
00216 }