IisCell Class Reference

#include <iiscell.h>

List of all members.

Public Types

typedef void(IisCell::* member )()

Public Member Functions

void mark_recalc ()
bool needs_user_input ()
void mark_allow_ui ()
 IisCell (QTable *table, EditType et)
virtual void setText (const QString &str)
void recalc ()
bool can_be_calculated_now ()
QString getFormuleTextForCell (int x, int y)
QWidget * createEditor () const
void rowsInserted (int row, int nr)
void colsInserted (int col, int nr)
virtual void paint (QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected)
Data saveFile (QString prefix)
void load (Data data)

Protected Member Functions

bool will_influence (IisCell *)
bool will_loop ()

Private Member Functions

void link (AbstractPlace &, member)
void queueCall (CallMember *m)
void flushCalls ()
void image_changed ()
void show_changed ()
void visual_changed ()
void show_value ()
void gather_inputs (Value *v)
void add_listener (IisCell *who)
void del_listener (IisCell *who)
void mark_inputs (bool add)
void clear_inputs ()
void set_inputs ()
void updated ()
void value_changed ()
void formule_changed ()
void show_status_changed ()
void recalc_changed ()
void entered_changed ()
Valueevaluate (Value *what)
Valuelookup (Reference *var)
Valuelookup (Range *var)
Valuefetch_value ()
Valueapply (Expression *what)

Private Attributes

Place< QString > entered
Place< Value * > formule
Place< Value * > value
Place< QImage > image
Place< bool > show_status
Place< QString > show
int scale_xs
int scale_ys
QImage scaled
list< IisCell * > listeners
list< IisCell * > inputs
Place< bool > needs_recalculation
bool user_input_allowed

Friends

class CallMember


Detailed Description

The IisCell class represents one specific cell in a spreadsheet. A cell does have a list of listeners to which notifications of its calculated value are notified. Cells works asynchrnously: they report request for calculation towards the spreadsheet who will come back with a recalc order somewhere in the future. The typical workflow of a spreadcell is a) entereing of a formule (the entered place). b) parsing the formule (the formule place). c) queueing a recalculation request. d) recalculating the variable and updating the value (the value place). e) updating the visualisation and informing all listeners)

Definition at line 25 of file iiscell.h.


Member Typedef Documentation

typedef void(IisCell::* IisCell::member)()
 

Definition at line 29 of file iiscell.h.


Constructor & Destructor Documentation

IisCell::IisCell QTable *  table,
EditType  et
 

Initializes the IisCell into the table entered is set to "", the formule and value are NULL, the needs_recalculation flag and user_input_allowed flags are false. The original and scaled images are empty and the show_status flag is true. Worwrapping is set on.

Definition at line 102 of file iiscell.cpp.

References entered, entered_changed(), flushCalls(), formule, formule_changed(), image, image_changed(), link(), needs_recalculation, recalc_changed(), scale_xs, scale_ys, scaled, show, show_changed(), show_status, show_status_changed(), user_input_allowed, value, value_changed(), and visual_changed().

00102                                             :
00103   QTableItem(table,et)
00104 {
00105   link(entered,     &IisCell::entered_changed);
00106   link(value,       &IisCell::value_changed);
00107   link(formule,     &IisCell::formule_changed);
00108   link(image,       &IisCell::image_changed);
00109   link(show,        &IisCell::show_changed);
00110   link(needs_recalculation,&IisCell::recalc_changed);
00111 
00112   link(entered,     &IisCell::show_status_changed);
00113   link(show_status, &IisCell::show_status_changed);
00114 
00115   link(image,       &IisCell::visual_changed);
00116   link(show,        &IisCell::visual_changed);
00117   link(needs_recalculation,&IisCell::visual_changed);
00118   
00119   entered = "";
00120   formule = NULL;
00121   value = NULL;
00122   needs_recalculation = false;
00123   user_input_allowed  = false;
00124   image = QImage();
00125   scaled = QImage();
00126   scale_xs = 0;
00127   scale_ys = 0;
00128   setWordWrap(true);
00129   show_status = true;
00130   
00131   flushCalls();
00132 };


Member Function Documentation

void IisCell::add_listener IisCell who  )  [private]
 

To attach a new listener to this cell

Definition at line 172 of file iiscell.cpp.

References listeners.

00173 {
00174   for(list<IisCell*>::iterator it=listeners.begin() ; it!=listeners.end() ; it++)
00175     {
00176       IisCell * c = *it;
00177       if (c==who) return;
00178     }
00179   listeners.push_back(who);
00180 }

Value * IisCell::apply Expression what  )  [private]
 

The applciation step in the evaluator

Definition at line 670 of file iiscell.cpp.

References Runtime::apply(), Expression::argc(), Expression::argv(), evaluate(), Expression::op(), and runtime.

Referenced by evaluate().

00671 {
00672   assert(app);
00673   // evaluate arguments
00674   vector<Value*> evaluated;
00675   for(int i = 0 ; i < app->argc() ; i++)
00676     evaluated.push_back(evaluate(app->argv(i)));
00677   // check operator
00678   return runtime.apply(app->op(),evaluated);
00679 }

bool IisCell::can_be_calculated_now  ) 
 

returns true if all the inputs provide a good value and none of them are scheduled for recalculation. For cells that require user_input in a situation where it is not allowed, this function returns false.

Definition at line 544 of file iiscell.cpp.

References inputs.

00545 {
00546   // printf("Can cell %d,%d be recalculated ?\n",col(),row());
00547   for (list<IisCell*>::iterator it = inputs.begin();
00548        it!=inputs.end() ; it++)
00549     {
00550       bool nr = (*it)->needs_recalculation;
00551       // printf("  Input %d,%d: %d\n",(*it)->col(),(*it)->row(),nr);
00552       if ((*it)->needs_recalculation) 
00553         return false;
00554     }
00555   if (user_input_allowed) return true;
00556   return (!needs_user_input());
00557 }

void IisCell::clear_inputs  )  [private]
 

Will remove all the cells to which we are listening now

Definition at line 484 of file iiscell.cpp.

References inputs, and mark_inputs().

Referenced by formule_changed().

00485 {
00486   mark_inputs(false);
00487   inputs.clear();
00488 }

void IisCell::colsInserted int  col,
int  nr
 

When columns are inserted, the spreadtable will move them around. Afterwards all cells will be notified of the change and can change their formules as necessary.

Definition at line 258 of file iiscell.cpp.

References ValueCopier::copy(), and formule.

00259 {
00260   if (formule)
00261     {
00262       CellRightShifter shifter(col,nr);
00263       shifter.copy(formule);
00264     }
00265 }

QWidget * IisCell::createEditor  )  const
 

Creates the editor when text is entered. Closely related to Qt functionality. (See over there)

Definition at line 164 of file iiscell.cpp.

References entered.

00165 {
00166   QWidget * res = QTableItem::createEditor();
00167   QLineEdit * le = (QLineEdit*)(void*)res;
00168   le->setText(entered);
00169   return le;
00170 };

void IisCell::del_listener IisCell who  )  [private]
 

To delete a listener from this cell

Definition at line 203 of file iiscell.cpp.

References listeners.

00204 {
00205   for(list<IisCell*>::iterator it=listeners.begin() ; it!=listeners.end() ; it++)
00206     if ((*it)==who) 
00207       {
00208         listeners.erase(it);
00209         return;
00210       }
00211 }

void IisCell::entered_changed  )  [private]
 

Will try to set the formule according to the entered text. A parse error will propagate as error value.

Definition at line 296 of file iiscell.cpp.

References entered, ParseText::expr(), formule, and value.

Referenced by IisCell().

00297 {
00298   QString e = entered;
00299   if (e.isEmpty())
00300     formule = NULL;
00301   else
00302     {
00303       try
00304         {
00305           ParseText p(e);
00306           formule = p.expr();
00307         }
00308       catch (Error * p)
00309         {
00310           formule = NULL;
00311           value = p;
00312         }
00313     }
00314 }

Value * IisCell::evaluate Value what  )  [private]
 

evaluates the given expression, recursively, taking into account the user_input_allowed variable.

Definition at line 651 of file iiscell.cpp.

References apply(), and lookup().

Referenced by apply(), and recalc().

00652 {
00653   if (!what) throw new Error("Empty formule");
00654   if (typeid(*what)==typeid(TextValue))
00655     return what;
00656   if (typeid(*what)==typeid(ImageValue))
00657     return what;
00658   //  if (typeid(*what)==typeid(VarValue))
00659   //    return lookup((VarValue*)what);
00660   if (typeid(*what)==typeid(Reference))
00661     return lookup((Reference*)what);
00662   if (typeid(*what)==typeid(Range))
00663     return lookup((Range*)what);
00664   if (typeid(*what)==typeid(Expression))
00665     return apply((Expression*)what);
00666   assert(0);
00667   return NULL;
00668 }

Value * IisCell::fetch_value  )  [private]
 

the routine other cells use to obtain a value out of this cell. It returns NULL whenever the cell requires recalculation, or whenever the cell is showing an error value. Otherwise it returns the content of the value place.

Definition at line 337 of file iiscell.cpp.

References needs_recalculation, and value.

Referenced by lookup().

00338 {
00339   if (needs_recalculation) return NULL;
00340   Value * v = value;
00341   if (v &&
00342       (typeid(*v) == typeid(Status)
00343        || typeid(*v) == typeid(Error)
00344        || typeid(*v) == typeid(ParseError)))
00345     return NULL;
00346   return v;
00347 }

void IisCell::flushCalls  )  [private]
 

Definition at line 84 of file iiscell.cpp.

References queued_calls.

Referenced by IisCell(), load(), mark_recalc(), recalc(), and setText().

00085 {
00086   static bool flushing = false;
00087   if (flushing) return;
00088   flushing = true;
00089   while(queued_calls.size())
00090     {
00091       CallMember * m = queued_calls.front();
00092       queued_calls.erase(queued_calls.begin());
00093       m->clearChanged();
00094       m->execute();
00095     };
00096   flushing = false;
00097 }

void IisCell::formule_changed  )  [private]
 

If the formule changes, we clear all the old inputs, set all the new inputs. Try to figure out whether we will loop (if we do we set an error value). If we don't loop we request a recalculation of this cell, using mark_recalc.

Definition at line 316 of file iiscell.cpp.

References clear_inputs(), entered, formule, mark_recalc(), set_inputs(), Value::toString(), value, and will_loop().

Referenced by IisCell().

00317 {
00318   clear_inputs();
00319   set_inputs();
00320   if (will_loop())
00321     {
00322       clear_inputs(); 
00323       value = new Error("<loop>");
00324       formule = NULL;
00325       return;
00326     }
00327   //  value = NULL;
00328   mark_recalc();
00329   
00330   // backward, when the formule updates, the entered formule
00331   // should be updated as well
00332   Value * F = formule;
00333   if (F) 
00334     entered = F->toString();
00335 }

void IisCell::gather_inputs Value v  )  [private]
 

This routine will find all the cells refered to directly or indirectly in v and add them to the inputs variable. This function does not clear the old inputs set.

Definition at line 496 of file iiscell.cpp.

References Expression::argc(), Expression::argv(), Reference::column, SpreadSheetTable::findItem(), Range::from, inputs, and Reference::row.

Referenced by set_inputs().

00497 {
00498   if (!v) return;
00499   if (typeid(*v)==typeid(TextValue)) return;
00500   if (typeid(*v)==typeid(ImageValue)) return;
00501   if (typeid(*v)==typeid(Reference))
00502     {
00503       // check position
00504       Reference *vv = (Reference*)v;
00505       assert(vv);
00506       SpreadSheetTable * ss = (SpreadSheetTable*)table();
00507       assert(ss);
00508       IisCell * sc = ss->findItem(vv->row,vv->column);
00509       assert(sc);
00510       inputs.push_back(sc);
00511       return;
00512     }
00513   if (typeid(*v)==typeid(Range))
00514     {
00515       // check position
00516       Range * r = (Range*)v;
00517       SpreadSheetTable * ss = (SpreadSheetTable*)table();
00518       assert(ss);
00519       for(int x = r->from->column ; x <= r->to->column ; x++)
00520         for(int y = r->from->row ; y <= r->to->row ; y++)
00521           {
00522             IisCell * sc = ss->findItem(y,x);
00523             assert(sc);
00524             inputs.push_back(sc);
00525           }
00526       return;
00527     }
00528   if (typeid(*v)==typeid(Expression))
00529     {
00530       Expression * e = (Expression*)v;
00531       for(int i = 0 ; i < e->argc() ; i++)
00532         gather_inputs(e->argv(i));
00533       return;
00534     }
00535   assert(0);
00536 }

QString IisCell::getFormuleTextForCell int  x,
int  y
 

returns the pretty-print version of the formule. This is necessary when shifting cells around.

Definition at line 283 of file iiscell.cpp.

References ValueCopier::copy(), formule, and Value::toString().

00284 {
00285   if (!formule) return "";
00286   RelativeShifter shifter(x-col(),y-row());
00287   return shifter.copy(formule)->toString();
00288 }

void IisCell::image_changed  )  [private]
 

If the image changes then the scaled image will be cleared. If the new image is non empty then the show place is set to zero.

Definition at line 182 of file iiscell.cpp.

References image, scaled, and show.

Referenced by IisCell().

00183 {
00184   QImage I = image;
00185   scaled = QImage();
00186   if (!I.isNull())
00187     show = NULL;
00188 }

void IisCell::link AbstractPlace &  ,
member 
[private]
 

Some variables in this class are 'places'. A place will automatically call a specific member when its value changes (and only when its value changes). This function provides the link between the place and the member call.

Definition at line 70 of file iiscell.cpp.

References CallMember.

Referenced by IisCell().

00071 {
00072   CallMember * em;
00073   em = new CallMember(*this,m);
00074   l.notify(em);
00075 };

void IisCell::load Data  data  ) 
 

Takes all information from the data field. All references to files are read as well.

Definition at line 134 of file iiscell.cpp.

References entered, flushCalls(), formule, Value::load(), set_inputs(), and value.

Referenced by SpreadSheetTable::loadFile().

00135 {
00136   Token content = initfrom;
00137   String E = content["entered"];
00138   entered = E;
00139   Data F = content["formule"];
00140   if (!F.isNull())
00141     formule = Value::load(F);
00142   Data R = content["result"];
00143   if (!R.isNull())
00144     value = Value::load(R);
00145   // connect to the right cells
00146   set_inputs();
00147 
00148   flushCalls();
00149 };

Value * IisCell::lookup Range var  )  [private]
 

looks up a range of cells referenced by var. All the values are sequentially placed into a ValueArray.

Definition at line 630 of file iiscell.cpp.

References Reference::column, fetch_value(), Range::from, Reference::row, ValueArray::set(), and Range::to.

00631 {
00632   if (!var) return NULL;
00633   SpreadSheetTable * ss = (SpreadSheetTable*)table();
00634   int mx = var->from->column;
00635   int my = var->from->row;
00636   ValueArray * result = new ValueArray(var->to->column - var->from->column + 1,
00637                                        var->to->row    - var->from->row    + 1);
00638   for(int x = mx ; x <= var->to->column ; x++)
00639     for(int y = my ; y <= var->to->row ; y++)
00640       {
00641         Value * val;
00642         IisCell * i = (IisCell*)(ss->item(y,x));
00643         if (!i) val = new TextValue("");
00644         else val = i->fetch_value();
00645         if (!val) return NULL;
00646         result->set(x-mx,y-my,val);
00647       }
00648   return result;
00649 }

Value * IisCell::lookup Reference var  )  [private]
 

looks up a value in the cell references to by var.

Definition at line 621 of file iiscell.cpp.

References Reference::column, fetch_value(), and Reference::row.

Referenced by evaluate().

00622 {
00623   if (!var) return NULL;
00624   SpreadSheetTable * ss = (SpreadSheetTable*)table();
00625   IisCell * i = (IisCell*)(ss->item(var->row,var->column));
00626   if (!i) return new TextValue("");
00627   return i->fetch_value();
00628 }

void IisCell::mark_allow_ui  ) 
 

sets the user_input_allowed flag to true

Definition at line 478 of file iiscell.cpp.

References needs_user_input(), and user_input_allowed.

Referenced by SpreadSheetTable::status_selection().

00479 {
00480   if (needs_user_input())
00481     user_input_allowed=true;
00482 }

void IisCell::mark_inputs bool  add  )  [private]
 

This function will go through all the cells from which we would like to have notification and either request those cells to add or remove ourselve from the notification list. The add field determines whether it is add or delete

Definition at line 559 of file iiscell.cpp.

References inputs.

Referenced by clear_inputs(), and set_inputs().

00560 {
00561   for (list<IisCell*>::iterator it = inputs.begin() ; 
00562        it!=inputs.end() ; it++)
00563     {
00564       IisCell * sc = *it;
00565       if (add) 
00566         sc->add_listener(this);
00567       else
00568         sc->del_listener(this);
00569     }
00570 }

void IisCell::mark_recalc  ) 
 

Called from our notifying cells when a change to their value occurs. Internally called when the formule changed.

Definition at line 472 of file iiscell.cpp.

References flushCalls(), and needs_recalculation.

Referenced by formule_changed(), and SpreadSheetTable::status_selection().

00473 {
00474   needs_recalculation = true;
00475   flushCalls();
00476 }

bool IisCell::needs_user_input  ) 
 

determines whether user input is necessary for this cell

Definition at line 539 of file iiscell.cpp.

References formule, Runtime::requires_user_input(), and runtime.

Referenced by mark_allow_ui(), and paint().

00540 {
00541   return runtime.requires_user_input(formule);
00542 }

void IisCell::paint QPainter *  p,
const QColorGroup &  cg,
const QRect &  cr,
bool  selected
[virtual]
 

paints the cell either using the image, or using the text. if the text is used, the standard QTableItem is used to draw the text, if the image should be shown, we do it ourselve by either retrieving the scaled image, or, if it does not exist, creating the scaled image. The image is scaled such that its aspect ratio is preserved but that it will always fit entirely into the cell. The sides of the cell are colored using the current status information. deep red is a parse error, light red is an evaluation error, orange is a cell the rquires user input and does not have a value, yellow is a cell that requires user input and does have a avlue. Grey is for cells that show either the entered text or are recalculation at the moment. Green cells are ceel that require user input and do not have any value but are allowed to take input.

Definition at line 391 of file iiscell.cpp.

References image, needs_recalculation, needs_user_input(), show_status, user_input_allowed, and value.

00392 {
00393   // determine color
00394   QColorGroup ncg(cg);
00395   Value * v = value;
00396   if (v && typeid(*v)==typeid(ParseError))
00397     ncg.setColor(QColorGroup::Base,QColor(255,0,0));
00398   else if (v && typeid(*v)==typeid(Error))
00399     ncg.setColor(QColorGroup::Base,QColor(255,192,192));
00400   else if (user_input_allowed)
00401     ncg.setColor(QColorGroup::Base,QColor(128,255,128));
00402   else if (needs_user_input())
00403     {
00404       if (needs_recalculation || show_status)
00405         ncg.setColor(QColorGroup::Base,QColor(255,192,128));
00406       else
00407         ncg.setColor(QColorGroup::Base,QColor(255,255,128));
00408     }
00409   else if (needs_recalculation || show_status)
00410     ncg.setColor(QColorGroup::Base,QColor(192,192,192));
00411 
00412   // paint text
00413   QImage I = image;
00414   if (I.isNull())
00415     {
00416       QTableItem::paint(p,ncg,cr,selected);
00417       return;
00418     }
00419 
00420   // if we have a pixmap we draw the content ourselves
00421   int height = table()->rowHeight(row());
00422   int width = table()->columnWidth(col());
00423   if (scaled.isNull() ||
00424       width!=scale_xs || 
00425       height!=scale_ys ||
00426       scaled.isNull())
00427     {
00428       scale_xs = width;
00429       scale_ys = height;
00430       scaled = I.smoothScale(scale_xs,scale_ys,QImage::ScaleMin);
00431 
00432       // draw the coordinate system
00433       if (value)
00434         {
00435           Value * v = value;
00436           if (typeid(*v)==typeid(ImageValue))
00437             {
00438               ImageValue* V = (ImageValue*)v;
00439               V->drawAxes(&scaled);
00440             }
00441         }
00442    }
00443   int xs = scaled.width();
00444   int ys = scaled.height();
00445   // top left corner
00446   int xl = (width - xs) / 2;
00447   int xr = xl + xs;
00448   int yt = (height - ys) / 2;
00449   int yb = yt + ys;
00450   QBrush b(ncg.color(QColorGroup::Base));
00451   p->fillRect(0,0,xl,height,b);
00452   p->fillRect(xr,0,width-xr+1,height,b);
00453   p->fillRect(xl,0,xs,yt,b);
00454   p->fillRect(xl,yb,xs,height-yb+1,b);
00455   p->drawImage(xl,yt,scaled);
00456 };

void IisCell::queueCall CallMember m  )  [private]
 

Definition at line 79 of file iiscell.cpp.

References queued_calls.

Referenced by CallMember::setChanged().

00080 {
00081   queued_calls.push_back(m);
00082 }

void IisCell::recalc  ) 
 

recalc will evaluate the formule (if there is one) and set the value place (this can be an Error value as well). show_status is reset to false. This function should never be called directly. Instead use mark_recalc.

Definition at line 597 of file iiscell.cpp.

References evaluate(), flushCalls(), formule, needs_recalculation, show_status, user_input_allowed, and value.

00598 {
00599   needs_recalculation = false;
00600   user_input_allowed = false;
00601   printf("Recalcing %d,%d\n",col(),row());
00602   if (formule != NULL)
00603     {
00604       try
00605         {
00606           value = evaluate(formule);
00607         }
00608       catch (Error * e)
00609         {
00610           value = e;
00611         }
00612     }
00613   else
00614     {
00615       value = NULL;
00616     }
00617   show_status = false;
00618   flushCalls();
00619 }

void IisCell::recalc_changed  )  [private]
 

When there is a need for recalculation (the needs_recalculation place set to true), then this function will set show_status to true (during recalculation we want to show the formule being calculated) and request the table to recalculate this cell somewhere later on. The actual recalculation occurs in recalc().

Definition at line 458 of file iiscell.cpp.

References needs_recalculation, SpreadSheetTable::queue_recalculation(), show_status, updated(), and value.

Referenced by IisCell().

00459 {
00460   if (needs_recalculation)
00461     {
00462       value = NULL;
00463       show_status = true;
00464       SpreadSheetTable * ss = (SpreadSheetTable*)table();
00465       assert(ss);
00466       printf("      Queueing recalc at %d,%d\n",col(),row());
00467       ss->queue_recalculation(this);
00468       updated();
00469     }
00470 }

void IisCell::rowsInserted int  row,
int  nr
 

When a rows are inserted, the spreadtable will move them around. Afterwards all cells will be notified of the change and can change their formules as necessary.

Definition at line 249 of file iiscell.cpp.

References ValueCopier::copy(), and formule.

00250 {
00251   if (formule)
00252     {
00253       CellDownShifter shifter(row,nr);
00254       shifter.copy(formule);
00255     }
00256 }

Data IisCell::saveFile QString  prefix  ) 
 

Returns a data representation of this cell. Image information will be stored in a seperate file prefixed with the prefix string. The prefix should be a path ending with "/"

Definition at line 151 of file iiscell.cpp.

References entered, formule, Value::getSaveDescription(), and value.

Referenced by SpreadSheetTable::saveFile().

00152 {
00153   Token content;
00154   content["entered"]=String(entered);
00155   Value * F = formule;
00156   if (F)
00157     content["formule"]=F->getSaveDescription(prefix);
00158   Value * result = value;
00159   if (result)
00160     content["result"]=result->getSaveDescription(prefix);
00161   return content;
00162 }

void IisCell::set_inputs  )  [private]
 

Will gather all the inputs in the current formule and subscribe to all the cells we are taking values from

Definition at line 490 of file iiscell.cpp.

References formule, gather_inputs(), and mark_inputs().

Referenced by formule_changed(), and load().

00491 {
00492   gather_inputs(formule);
00493   mark_inputs(true);
00494 };

void IisCell::setText const QString &  str  )  [virtual]
 

Sets the entered place to the given string

Definition at line 290 of file iiscell.cpp.

References entered, and flushCalls().

00291 {
00292   entered = str;
00293   flushCalls();
00294 }

void IisCell::show_changed  )  [private]
 

If the show place changes, then the underlying QTableItem is updated to reflect the new string. If the string is non-empty, then the image is cleared.

Definition at line 190 of file iiscell.cpp.

References image, and show.

Referenced by IisCell().

00191 {
00192   QString S = show;
00193   QTableItem::setText(S);
00194   if (!S.isEmpty())
00195     image = QImage();
00196 }

void IisCell::show_status_changed  )  [private]
 

If the show_status place changes, we either update the show palce to reflect the entered text, or call show_value() to present the previous calculated value.

Definition at line 383 of file iiscell.cpp.

References entered, show, show_status, and show_value().

Referenced by IisCell().

00384 {
00385   if (show_status)
00386     show = entered;
00387   else
00388     show_value();
00389 }

void IisCell::show_value  )  [private]
 

If the value is zero, we reset show_status to true. Otherwise we figure out whether we should set the image place (when the value is an image) or the show place (when the value can be presented textual).

Definition at line 367 of file iiscell.cpp.

References image, show, show_status, and value.

Referenced by show_status_changed(), and value_changed().

00368 {
00369   Value * result = value;
00370   if (!result)
00371     {
00372       show_status = true; 
00373     }
00374   else
00375     {
00376       if (typeid(*result)==typeid(ImageValue))
00377         image = ((ImageValue*)result)->getQImage(true);
00378       else 
00379         show = result->toString();
00380     }
00381 }

void IisCell::updated  )  [private]
 

Will notify to all our listeners that we provide a new value. All subscribed listeners are contacted with mark_recalc()

Definition at line 349 of file iiscell.cpp.

References listeners.

Referenced by recalc_changed(), and value_changed().

00350 {
00351   printf("  Updated cell %d,%d\n",col(),row());
00352   for(list<IisCell*>::iterator it=listeners.begin(); it!=listeners.end(); it++)
00353     {
00354       assert(*it);
00355       printf("    Marking recalc at %d,%d\n",(*it)->col(),(*it)->row());
00356       (*it)->mark_recalc();
00357     }
00358 }

void IisCell::value_changed  )  [private]
 

When a value changes, we update the visualized information through a call to show_value. Afterwards we call updated to notify all interested cells.

Definition at line 360 of file iiscell.cpp.

References show_status, show_value(), and updated().

Referenced by IisCell().

00361 {
00362   if (!show_status)
00363     show_value();
00364   updated();
00365 }

void IisCell::visual_changed  )  [private]
 

This function will ask the table to repaint this cell.

Definition at line 198 of file iiscell.cpp.

Referenced by IisCell().

00199 {
00200   table()->updateCell(row(),col());
00201 }

bool IisCell::will_influence IisCell  )  [protected]
 

part of the loop detection routine

Definition at line 584 of file iiscell.cpp.

References listeners.

00585 {
00586   if (this == target) return true;
00587   for (list<IisCell*>::iterator it = listeners.begin() ; 
00588        it!=listeners.end() ; it++)
00589     {
00590       IisCell * sc = *it;
00591       assert(sc);
00592       if (sc->will_influence(target)) return true;
00593     }
00594   return false;
00595 }

bool IisCell::will_loop  )  [protected]
 

part of the loop detection routine

Definition at line 572 of file iiscell.cpp.

References listeners.

Referenced by formule_changed().

00573 {
00574   for (list<IisCell*>::iterator it = listeners.begin() ; 
00575        it!=listeners.end() ; it++)
00576     {
00577       IisCell * sc = *it;
00578       assert(sc);
00579       if (sc->will_influence(this)) return true;
00580     }
00581   return false;
00582 };


Friends And Related Function Documentation

friend class CallMember [friend]
 

Definition at line 27 of file iiscell.h.

Referenced by link().


Member Data Documentation

Place<QString> IisCell::entered [private]
 

The text entered by the user. When this value changes show_status_changed and entered_changed will be called

Definition at line 44 of file iiscell.h.

Referenced by createEditor(), entered_changed(), formule_changed(), IisCell(), load(), saveFile(), setText(), and show_status_changed().

Place<Value*> IisCell::formule [private]
 

When entered text is parsed properly. The formule will hold the parse tree. A change to the formule induces a call to formule_changed

Definition at line 51 of file iiscell.h.

Referenced by colsInserted(), entered_changed(), formule_changed(), getFormuleTextForCell(), IisCell(), load(), needs_user_input(), recalc(), rowsInserted(), saveFile(), and set_inputs().

Place<QImage> IisCell::image [private]
 

When a value is available that is an image, then the converted QImage of that value. This image is not scaled to the requested resolution. Whenever the image changes, the image_changed routine will be called and clear the shown place automatically. Furthermore visual_changed will be called as well.

Definition at line 69 of file iiscell.h.

Referenced by IisCell(), image_changed(), paint(), show_changed(), and show_value().

list<IisCell*> IisCell::inputs [private]
 

A list of cells from which we hope to receive notifications

Definition at line 151 of file iiscell.h.

Referenced by can_be_calculated_now(), clear_inputs(), gather_inputs(), and mark_inputs().

list<IisCell*> IisCell::listeners [private]
 

A list of listeners to this cell. Listeners will be notified whenever a change in our value occurs.

Definition at line 146 of file iiscell.h.

Referenced by add_listener(), del_listener(), updated(), will_influence(), and will_loop().

Place<bool> IisCell::needs_recalculation [private]
 

The needs recalcualtion flag is set from mark_recalc. When changed it will automatically call recalc_changed and visual_changed.

Definition at line 221 of file iiscell.h.

Referenced by fetch_value(), IisCell(), mark_recalc(), paint(), recalc(), and recalc_changed().

int IisCell::scale_xs [private]
 

scale_xs holds the size of the resized image (the scaled attribute) for visualisation in the size of the spreadcell.

Definition at line 121 of file iiscell.h.

Referenced by IisCell().

int IisCell::scale_ys [private]
 

scale_ys holds the size of the resized image (the scaled attribute) for visualisation in the size of the spreadcell.

Definition at line 127 of file iiscell.h.

Referenced by IisCell().

QImage IisCell::scaled [private]
 

The scaled image is a smoothly resized image of the full resolution image. Its size is not necessarily the same as scale_xs and scale_ys. Those two variables define the box in which the scaled image should fit, without changing the aspect ratio. As soon as the size of the spreadcell changes will we update this field. This happens in the repaint operation. The scaled image (contrary to the original image) also includes the visualized coordinate system.

Definition at line 138 of file iiscell.h.

Referenced by IisCell(), and image_changed().

Place<QString> IisCell::show [private]
 

Show contains the string that should be shown in the spreadcell either as value (show_status == false) or as original entered text (show_status == true). If the show place is changed, then the image value will be cleared automatically (unless the show string becomes NULL, then the image place is not touched). Furthermore a call to visual_changed will take palce.

Definition at line 89 of file iiscell.h.

Referenced by IisCell(), image_changed(), show_changed(), show_status_changed(), and show_value().

Place<bool> IisCell::show_status [private]
 

Sometimes the status must be shown such as during calculation, when no decent value can be shown (e.g: NULL), or whenever the cell is not allowed to ask questions to the user. show_status is true whenever the original entered formule should be shown, otherwise it is false. A change to the show_status induces a call to show_status_changed.

Definition at line 79 of file iiscell.h.

Referenced by IisCell(), paint(), recalc(), recalc_changed(), show_status_changed(), show_value(), and value_changed().

bool IisCell::user_input_allowed [private]
 

This bariable is set whener the evaluator can present pop up boxes of all kinds to the user. Normally this is disabled as to not interrupt the user.

Definition at line 243 of file iiscell.h.

Referenced by IisCell(), mark_allow_ui(), paint(), and recalc().

Place<Value*> IisCell::value [private]
 

When the formule is evaluated, the value place will hold the resulting value. A change to this palce results in calls to value_changed. Whenever the value changes all listeners are informed.

Definition at line 59 of file iiscell.h.

Referenced by entered_changed(), fetch_value(), formule_changed(), IisCell(), load(), paint(), recalc(), recalc_changed(), saveFile(), and show_value().


The documentation for this class was generated from the following files:
Generated on Mon Jun 5 22:08:43 2006 for iis by  doxygen 1.4.6