22#include "kspread_view.h"
23#include "kspread_events.h"
24#include "kspread_doc.h"
25#include "kspread_locale.h"
26#include "kspread_util.h"
27#include "kspread_map.h"
42K_EXPORT_COMPONENT_FACTORY( libkspreadcalc, CalcFactory )
44TDEInstance* CalcFactory::s_global = 0;
46CalcFactory::CalcFactory( TQObject* parent,
const char* name )
47 : KLibFactory( parent, name )
49 s_global =
new TDEInstance(
"kspreadcalc" );
52CalcFactory::~CalcFactory()
57TQObject* CalcFactory::createObject( TQObject* parent,
const char* name,
const char* ,
const TQStringList & )
59 if ( !parent->inherits(
"KSpread::View") )
61 kdError() <<
"CalcFactory: KSpread::View expected. Parent is " << parent->className() << endl;
65 TQObject *obj =
new Calculator( (View*)parent, name );
69TDEInstance* CalcFactory::global()
80Calculator::Calculator(
View* parent,
const char* name )
81 : KParts::Plugin( parent, name )
86 TDEGlobal::locale()->insertCatalogue(
"kspreadcalc_calc");
87 parent->installEventFilter(
this );
89 (void)
new TDEAction( i18n(
"Calculator"), SmallIcon(
"kcalc", CalcFactory::global()),
90 0,
this, TQ_SLOT( showCalculator() ), actionCollection(),
"kspreadcalc");
93void Calculator::showCalculator()
102 m_calc =
new TQtCalculator(
this, (View*)parent() );
103 m_calc->setFixedSize( 9 + 100 + 9 + 233 + 9, 239);
108Calculator::~Calculator()
112bool Calculator::eventFilter( TQObject*, TQEvent* ev )
117 if ( SelectionChanged::test( ev ) )
119 SelectionChanged*
event = (SelectionChanged*)ev;
122 if (!event->region().isValid())
125 Sheet* sheet = m_view->doc()->map()->
findSheet( event->sheet() );
130 if (event->region().isSingular())
132 Cell* cell = sheet->cellAt( event->rect().left(), event->rect().top(),
false );
141 m_calc->setValue( d );
147 m_calc->setData( event->rect(), event->sheet().latin1() );
148 TQString str = util_rangeName( sheet, event->rect() );
149 m_calc->setLabel( str.latin1() );
167void TQtCalculator::useData()
172 int len = ( sheet_range.right() - sheet_range.left() + 1 ) *
173 ( sheet_range.bottom() - sheet_range.top() + 1 );
175 double *v =
new double[ len ];
177 for(
int x = sheet_range.left(); x <= sheet_range.right(); x++ )
178 for(
int y = sheet_range.top(); y <= sheet_range.bottom(); y++ )
180 View* view = corba->view();
181 Sheet* sheet = view->doc()->map()->
findSheet( sheet_name );
184 Cell* cell = sheet->cellAt( x, y,
false );
191 for(
int i = 0; i < n; i++ )
192 stats.enterData( v[i] );
196 sheet_name = TQString();
const Value value() const
Returns the value that this cell holds.
bool isEmpty() const
Returns true if this cell has no content, i.e no text and no formula.
Sheet * findSheet(const TQString &_name)
searches for a sheet named _name
double asFloat() const
Returns the floating-point value of this value.
The View class displays a KSpread document.