Minsky
minsky::GodleyTableEditor Class Reference

#include <godleyTableWindow.h>

Inheritance diagram for minsky::GodleyTableEditor:
Inheritance graph
Collaboration diagram for minsky::GodleyTableEditor:
Collaboration graph

Public Types

enum  ClickType {
  background, row0, col0, internal,
  importStock, rowWidget, colWidget
}
 
- Public Types inherited from minsky::ButtonWidgetEnums
enum  RowCol { row, col }
 
enum  Pos {
  first, second, middle, last,
  firstAndLast
}
 
- Public Types inherited from minsky::GodleyAssetClass
enum  AssetClass { noAssetClass, asset, liability, equity }
 
enum  DisplayStyle { DRCR, sign }
 

Public Member Functions

GodleyIcongodleyIcon ()
 
const GodleyIcongodleyIcon () const
 
void disableButtons ()
 
void enableButtons ()
 
bool selectedCellInTable () const
 
 GodleyTableEditor (GodleyIcon &g)
 
void draw (cairo_t *cairo)
 
double width () const
 
double height () const
 
void mouseDown (double x, double y)
 event handling More...
 
void mouseUp (double x, double y)
 
void mouseMoveB1 (double x, double y)
 mouse motion with button 1 pressed More...
 
void mouseMove (double x, double y)
 
void keyPress (int keySym, const std::string &utf8)
 
ClickType clickTypeZoomed (double x, double y) const
 returns the clickType in zoomed coordinates More...
 
void addStockVar (double x)
 add/delete rows/columns at x,y More...
 
void addStockVarByCol (int c)
 
void importStockVar (const std::string &name, double x)
 
void importStockVarByCol (const std::string &name, int c)
 
void deleteStockVar (double x)
 
void deleteStockVarByCol (int c)
 
void addFlow (double y)
 
void addFlowByRow (int r)
 
void deleteFlow (double y)
 
void deleteFlowByRow (int r)
 
int colXZoomed (double x) const
 
int rowYZoomed (double y) const
 
std::string moveAssetClass (double x, double y)
 
std::string swapAssetClass (double x, double y)
 
void highlightColumn (cairo_t *cairo, unsigned col)
 
void highlightRow (cairo_t *cairo, unsigned row)
 
void highlightCell (cairo_t *cairo, unsigned row, unsigned col)
 
void delSelection ()
 
void cut ()
 
void copy ()
 
void paste ()
 
int textIdx (double x) const
 
void pushHistory ()
 
void undo (int changes)
 restore to state changes ago More...
 
void adjustWidgets ()
 ensure button widgets are synced with current table data More...
 
void update ()
 update canvas godleyIcon, and any related godley icons. Can throw More...
 
ClickType clickType (double x, double y) const
 
std::set< string > matchingTableColumns (double x)
 return list of matching table columns for column at x More...
 
std::set< string > matchingTableColumnsByCol (int c)
 
void navigateRight ()
 move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col More...
 
void navigateLeft ()
 move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col More...
 
void navigateUp ()
 move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col More...
 
void navigateDown ()
 move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col More...
 

Public Attributes

double leftTableOffset =4*ButtonWidget<col>::buttonSpacing
 offset of the table within the window More...
 
double topTableOffset =30
 
bool drawButtons =true
 whether to draw row/column buttons More...
 
unsigned scrollRowStart =1
 starting row/col number of the scrolling region More...
 
unsigned scrollColStart =1
 
int selectedRow =-1
 which cell is active, none initially More...
 
int selectedCol =-1
 
int srcRow =-1
 src cell in the event of a move More...
 
int srcCol =-1
 
int hoverRow =-1
 
int hoverCol =-1
 
std::vector< double > colLeftMargin
 computed positions of the table columns More...
 
double rowHeight =0
 computed height of each row More...
 
unsigned insertIdx =0
 location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) More...
 
unsigned selectIdx =0
 
double zoomFactor =1
 zoom the display More...
 
std::size_t maxHistory {100}
 maximum no. of history states to save More...
 
std::size_t historyPtr =0
 

Static Public Attributes

static constexpr double columnButtonsOffset =12
 
static constexpr double pulldownHot =12
 space for ▼ in stackVar cells minimum column width (for eg empty columns) More...
 
static constexpr double minColumnWidth =4*ButtonWidget<col>::buttonSpacing
 

Protected Member Functions

int colX (double x) const
 column at x in unzoomed coordinates More...
 
int rowY (double y) const
 row at y in unzoomed coordinates More...
 
void checkCell00 ()
 check if cell (0,0) is selected, and deselect if so handle delete or backspace. Cell assumed selected More...
 
void handleBackspace ()
 
void handleDelete ()
 
virtual void requestRedrawCanvas ()
 

Protected Attributes

std::vector< ButtonWidget< row > > rowWidgets
 
std::vector< ButtonWidget< col > > colWidgets
 
int motionRow =-1
 
int motionCol =-1
 current cell under mouse motion More...
 
std::deque< GodleyTablehistory
 

Private Member Functions

 CLASSDESC_ACCESS (GodleyTableEditor)
 
void m_enableButtons ()
 

Private Attributes

GodleyIconm_godleyIcon
 Godley icon that owns this. More...
 
bool button1 =false
 mouse button pressed More...
 

Detailed Description

Definition at line 77 of file godleyTableWindow.h.

Member Enumeration Documentation

◆ ClickType

Constructor & Destructor Documentation

◆ GodleyTableEditor()

minsky::GodleyTableEditor::GodleyTableEditor ( GodleyIcon g)
inline

Definition at line 120 of file godleyTableWindow.h.

References adjustWidgets(), and m_enableButtons().

120  : m_godleyIcon(g)
void adjustWidgets()
ensure button widgets are synced with current table data
GodleyIcon & m_godleyIcon
Godley icon that owns this.
Here is the call graph for this function:

Member Function Documentation

◆ addFlow()

void minsky::GodleyTableEditor::addFlow ( double  y)

Definition at line 891 of file godleyTableWindow.cc.

892  {
893  const int r=rowYZoomed(y);
894  addFlowByRow(r);
895  }
int rowYZoomed(double y) const

◆ addFlowByRow()

void minsky::GodleyTableEditor::addFlowByRow ( int  r)

Definition at line 897 of file godleyTableWindow.cc.

898  {
899  if (r>0)
901  }
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void insertRow(unsigned row)
insert row at row
Definition: godleyTable.cc:59
GodleyIcon & m_godleyIcon
Godley icon that owns this.

◆ addStockVar()

void minsky::GodleyTableEditor::addStockVar ( double  x)

add/delete rows/columns at x,y

Definition at line 851 of file godleyTableWindow.cc.

852  {
853  const int c=colXZoomed(x);
854  addStockVarByCol(c);
855  }
int colXZoomed(double x) const

◆ addStockVarByCol()

void minsky::GodleyTableEditor::addStockVarByCol ( int  c)

Definition at line 857 of file godleyTableWindow.cc.

858  {
859  if (c>0) m_godleyIcon.table.insertCol(c+1);
860  }
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
GodleyIcon & m_godleyIcon
Godley icon that owns this.
void insertCol(unsigned col)
insert col at col
Definition: godleyTable.cc:68

◆ adjustWidgets()

void minsky::GodleyTableEditor::adjustWidgets ( )

ensure button widgets are synced with current table data

Definition at line 1037 of file godleyTableWindow.cc.

Referenced by minsky::GodleyIcon::adjustPopupWidgets(), minsky::GodleyIcon::GodleyIcon(), GodleyTableEditor(), and m_enableButtons().

1038  {
1039  rowWidgets.clear();
1040  for (size_t i=0; i<m_godleyIcon.table.rows(); ++i)
1041  rowWidgets.emplace_back(m_godleyIcon, i);
1042  colWidgets.clear();
1043  for (size_t i=0; i<m_godleyIcon.table.cols(); ++i)
1044  colWidgets.emplace_back(m_godleyIcon, i);
1045  // nb first column/row is actually 1 - 0th element actually
1046  // just ignored
1047  if (rowWidgets.size()==2)
1048  rowWidgets[1].pos=firstAndLast;
1049  else if (rowWidgets.size()==3)
1050  {
1051  rowWidgets[1].pos=first;
1052  rowWidgets.back().pos=second; // Position to avoid Initial Conditions row from being moved. For ticket 1064
1053  }
1054  else if (rowWidgets.size()>3)
1055  {
1056  rowWidgets[1].pos=first;
1057  rowWidgets[2].pos=second; // Position to avoid Initial Conditions row from being moved. For ticket 1064
1058  rowWidgets.back().pos=last;
1059  }
1060  if (colWidgets.size()==2)
1061  colWidgets[1].pos=firstAndLast;
1062  else if (colWidgets.size()>2)
1063  {
1064  colWidgets[1].pos=first;
1065  colWidgets.back().pos=last;
1066  }
1067  }
std::size_t cols() const
Definition: godleyTable.h:115
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::vector< ButtonWidget< row > > rowWidgets
GodleyIcon & m_godleyIcon
Godley icon that owns this.
std::vector< ButtonWidget< col > > colWidgets
Here is the caller graph for this function:

◆ checkCell00()

void minsky::GodleyTableEditor::checkCell00 ( )
protected

check if cell (0,0) is selected, and deselect if so handle delete or backspace. Cell assumed selected

Definition at line 1110 of file godleyTableWindow.cc.

1111  {
1112  if (selectedCol==0 && (selectedRow==0 || selectedRow ==1))
1113  // (0,0) cell not editable
1114  {
1115  selectedCol=-1;
1116  selectedRow=-1;
1117  }
1118  }
int selectedRow
which cell is active, none initially

◆ CLASSDESC_ACCESS()

minsky::GodleyTableEditor::CLASSDESC_ACCESS ( GodleyTableEditor  )
private

◆ clickType()

GodleyTableEditor::ClickType minsky::GodleyTableEditor::clickType ( double  x,
double  y 
) const

Definition at line 814 of file godleyTableWindow.cc.

Referenced by clickTypeZoomed().

815  {
816  const int c=colX(x), r=rowY(y);
817 
818  if (x<leftTableOffset && r>0)
819  return rowWidget;
820  if (y<topTableOffset && y>columnButtonsOffset && c>0)
821  return colWidget;
822 
823  if (r==0)
824  {
825  if (colLeftMargin[c+1]-x < pulldownHot)
826  return importStock;
827  return row0;
828  }
829  if (c==0)
830  return col0;
831 
832  if (c>0 && c<int(m_godleyIcon.table.cols()))
833  if (r>0 && r<int(m_godleyIcon.table.rows()))
834  return internal;
835 
836  return background;
837  }
int rowY(double y) const
row at y in unzoomed coordinates
std::size_t cols() const
Definition: godleyTable.h:115
static constexpr double pulldownHot
space for ▼ in stackVar cells minimum column width (for eg empty columns)
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::vector< double > colLeftMargin
computed positions of the table columns
int colX(double x) const
column at x in unzoomed coordinates
GodleyIcon & m_godleyIcon
Godley icon that owns this.
static constexpr double columnButtonsOffset
Here is the caller graph for this function:

◆ clickTypeZoomed()

ClickType minsky::GodleyTableEditor::clickTypeZoomed ( double  x,
double  y 
) const
inline

returns the clickType in zoomed coordinates

Definition at line 138 of file godleyTableWindow.h.

References clickType(), and zoomFactor.

138 {return clickType(x/zoomFactor, y/zoomFactor);}
ClickType clickType(double x, double y) const
double zoomFactor
zoom the display
Here is the call graph for this function:

◆ colX()

int minsky::GodleyTableEditor::colX ( double  x) const
protected

column at x in unzoomed coordinates

Definition at line 443 of file godleyTableWindow.cc.

Referenced by colXZoomed().

444  {
445  if (colLeftMargin.size()<2 || x<colLeftMargin[0]) return -1;
446  if (x<colLeftMargin[1]) return 0;
447  auto p=std::upper_bound(colLeftMargin.begin(), colLeftMargin.end(), x);
448  size_t r=p-colLeftMargin.begin()-2+scrollColStart;
449  if (r>m_godleyIcon.table.cols()-1) r=-1; // out of bounds, invalidate. Also exclude A-L-E column. For ticket 1163.
450  return r;
451  }
std::size_t cols() const
Definition: godleyTable.h:115
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::vector< double > colLeftMargin
computed positions of the table columns
GodleyIcon & m_godleyIcon
Godley icon that owns this.
Here is the caller graph for this function:

◆ colXZoomed()

int minsky::GodleyTableEditor::colXZoomed ( double  x) const
inline

Definition at line 153 of file godleyTableWindow.h.

References colX(), and zoomFactor.

153 {return colX(x/zoomFactor);}
double zoomFactor
zoom the display
int colX(double x) const
column at x in unzoomed coordinates
Here is the call graph for this function:

◆ copy()

void minsky::GodleyTableEditor::copy ( )

Definition at line 788 of file godleyTableWindow.cc.

References minsky::cminsky(), and minsky::str().

789  {
790  if (!selectedCellInTable()) return;
792  if (selectIdx!=insertIdx)
793  cminsky().clipboard.putClipboard
794  (str.substr(min(selectIdx,insertIdx), abs(int(selectIdx)-int(insertIdx))));
795  else
796  cminsky().clipboard.putClipboard(str);
797  }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
Here is the call graph for this function:

◆ cut()

void minsky::GodleyTableEditor::cut ( )

Definition at line 776 of file godleyTableWindow.cc.

777  {
778  if (!selectedCellInTable()) return;
779  copy();
780  if (selectIdx==insertIdx)
781  // delete entire cell
783  else
784  delSelection();
786  }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
GodleyIcon & m_godleyIcon
Godley icon that owns this.
virtual void requestRedrawCanvas()
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...

◆ deleteFlow()

void minsky::GodleyTableEditor::deleteFlow ( double  y)

Definition at line 903 of file godleyTableWindow.cc.

904  {
905  const int r=rowYZoomed(y);
906  deleteFlowByRow(r);
907  }
int rowYZoomed(double y) const

◆ deleteFlowByRow()

void minsky::GodleyTableEditor::deleteFlowByRow ( int  r)

Definition at line 909 of file godleyTableWindow.cc.

910  {
911  if (r>1) // Cannot delete flow in Initial Conditions row. For ticket 1064
912  m_godleyIcon.deleteRow(r+1);
913  }
GodleyIcon & m_godleyIcon
Godley icon that owns this.
void deleteRow(unsigned row)
delete row before row
Definition: godleyIcon.cc:225

◆ deleteStockVar()

void minsky::GodleyTableEditor::deleteStockVar ( double  x)

Definition at line 879 of file godleyTableWindow.cc.

880  {
881  const int c=colXZoomed(x);
883  }
int colXZoomed(double x) const

◆ deleteStockVarByCol()

void minsky::GodleyTableEditor::deleteStockVarByCol ( int  c)

Definition at line 885 of file godleyTableWindow.cc.

886  {
887  if (c>=0)
889  }
void deleteCol(unsigned col)
delete col before col
Definition: godleyTable.cc:83
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
GodleyIcon & m_godleyIcon
Godley icon that owns this.

◆ delSelection()

void minsky::GodleyTableEditor::delSelection ( )

Definition at line 739 of file godleyTableWindow.cc.

References minsky::str().

740  {
742  {
744  str.erase(min(insertIdx,selectIdx),abs(int(insertIdx)-int(selectIdx)));
746  }
747  }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
Here is the call graph for this function:

◆ disableButtons()

void minsky::GodleyTableEditor::disableButtons ( )
inline

Definition at line 100 of file godleyTableWindow.h.

References drawButtons, leftTableOffset, requestRedrawCanvas(), and topTableOffset.

Referenced by minsky::GodleyIcon::GodleyIcon().

double leftTableOffset
offset of the table within the window
bool drawButtons
whether to draw row/column buttons
virtual void requestRedrawCanvas()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw()

void minsky::GodleyTableEditor::draw ( cairo_t *  cairo)

Definition at line 156 of file godleyTableWindow.cc.

References anonymous_namespace{godleyTableWindow.cc}::capitalise(), minsky::cminsky(), minsky::FlowCoef::coef, minsky::defang(), minsky::Minsky::displayValues, minsky::engExp(), minsky::expMultiplier(), minsky::latexToPango(), minsky::mantissa(), minsky::FlowCoef::name, anonymous_namespace{godleyTableWindow.cc}::showAsset(), minsky::FlowCoef::str(), minsky::valueId(), and minsky::Minsky::variableValues.

157  {
158  const CairoSave cs(cairo);
159  cairo_scale(cairo,zoomFactor,zoomFactor);
160  Pango pango(cairo);
161  pango.setMarkup("Flows ↓ / Stock Vars →");
162  rowHeight=pango.height()+2;
163  const double tableHeight=(m_godleyIcon.table.rows()-scrollRowStart+1)*rowHeight;
164  double x=leftTableOffset;
165  double lastAssetBoundary=x;
166  auto assetClass=GodleyAssetClass::noAssetClass;
167  // only recalculate colmn widths when no cell is selected.
168  const bool resizeGrid=selectedCol<0 || selectedRow<0 || motionRow>=0 || motionCol>=0;
169  if (resizeGrid)
170  colLeftMargin.clear();
171 
172  for (unsigned col=0; col<m_godleyIcon.table.cols(); ++col)
173  {
174  // omit stock columns less than scrollColStart
175  if (col>0 && col<scrollColStart) continue;
176  // vertical lines & asset type tag
177  if (assetClass!=m_godleyIcon.table._assetClass(col))
178  {
179  if (assetClass!=GodleyAssetClass::noAssetClass)
180  {
181  pango.setMarkup(capitalise(enumKey<GodleyAssetClass::AssetClass>(assetClass)));
182  // increase column by enough to fit asset class label
183  if (x < pango.width()+lastAssetBoundary+3)
184  x=pango.width()+lastAssetBoundary+3;
185  cairo_move_to(cairo,0.5*(x+lastAssetBoundary-pango.width()),0);
186  showAsset(pango, cairo, assetClass);
187  }
188  lastAssetBoundary=x;
189 
190  assetClass=m_godleyIcon.table._assetClass(col);
191  cairo_move_to(cairo,x+3,topTableOffset);
192  cairo_rel_line_to(cairo,0,tableHeight);
193  }
194  cairo_move_to(cairo,x,topTableOffset);
195  cairo_rel_line_to(cairo,0,tableHeight);
196  cairo_set_line_width(cairo,0.5);
197  cairo_stroke(cairo);
198 
199  if (drawButtons && col>0 && col<colWidgets.size())
200  {
201  const CairoSave cs(cairo);
202  cairo_move_to(cairo, x, columnButtonsOffset);
203  colWidgets[col].draw(cairo);
204  }
205 
206  if (col>1)
207  {
208  cairo_move_to(cairo,x-pulldownHot,topTableOffset);
209  pango.setMarkup("▼");
210  pango.show();
211  }
212 
213  double y=topTableOffset;
214  double colWidth=minColumnWidth;
215  for (unsigned row=0; row<m_godleyIcon.table.rows(); ++row)
216  {
217  if (row>0 && row<scrollRowStart) continue;
218 
219  if (drawButtons && col==0 && row>0 && row<rowWidgets.size())
220  {
221  const CairoSave cs(cairo);
222  cairo_move_to(cairo, 0, y);
223  rowWidgets[row].draw(cairo);
224  }
225 
226  const CairoSave cs(cairo);
227  if (row!=0 || col!=0)
228  {
229  // Make sure non-utf8 chars converted to utf8 as far as possible. for ticket 1166.
230  string text=utf_to_utf<char>(m_godleyIcon.table.cell(row,col));
231  if (!text.empty())
232  {
233  string value;
234  FlowCoef fc(text);
235  if (cminsky().displayValues && col!=0) // Do not add value "= 0.0" to first column. For tickets 1064/1274
236  try
237  {
238  auto vv=cminsky().variableValues
239  [valueId(m_godleyIcon.group.lock(),utf_to_utf<char>(fc.name))];
240  if (vv->idx()>=0)
241  {
242  const double val=fc.coef*vv->value();
243  auto ee=engExp(val);
244  if (ee.engExp==-3) ee.engExp=0;
245  value=" = "+mantissa(val,ee)+expMultiplier(ee.engExp);
246  }
247  }
248  catch (const std::exception& ex)
249  {
250  value=string("= Err: ")+ex.what();
251  // highlight error in red
252  cairo_set_source_rgb(cairo,1,0,0);
253  }
254 
255  // the active cell renders as bare LaTeX code for
256  // editing, all other cells rendered as LaTeX
258  {
259  if (row>0 && col>0)
260  { // handle DR/CR mode and colouring of text
261  if (fc.coef<0)
262  cairo_set_source_rgb(cairo,1,0,0);
263  if (cminsky().displayStyle==GodleyTable::DRCR)
264  {
265  if (assetClass==GodleyAssetClass::asset ||
266  assetClass==GodleyAssetClass::noAssetClass)
267  text = (fc.coef<0)?"CR ":"DR ";
268  else
269  text = (fc.coef<0)?"DR ":"CR ";
270  fc.coef=abs(fc.coef);
271  text+=latexToPango(fc.str());
272  }
273  else
274  text = latexToPango(text);
275  }
276  else // is flow tag, stock var or initial condition
277  text = latexToPango(text);
278  text+=value;
279  }
280  else
281  //Display values of parameters used as initial conditions in Godley tables. for ticket 1126.
283  else text=defang(text);
284  }
285  pango.setMarkup(text);
286  }
287  // allow extra space for the ▼ in row 0
288  colWidth=max(colWidth,pango.width() + (row==0? pulldownHot:0));
289  cairo_move_to(cairo,x+3,y);
290  pango.show();
291  y+=rowHeight;
292  }
293  colWidth+=5;
294 
295  if (resizeGrid)
296  {
297  colLeftMargin.push_back(x);
298  x+=colWidth;
299  }
300  else if (col+1<colLeftMargin.size())
301  x=colLeftMargin[col+1];
302  }
303 
304  // display pulldown for last column
305  cairo_move_to(cairo,x-pulldownHot,topTableOffset);
306  pango.setMarkup("▼");
307  pango.show();
308 
309 
310  pango.setMarkup
311  (capitalise(enumKey<GodleyAssetClass::AssetClass>(assetClass)));
312  // increase column by enough to fit asset class label
313  if (x < pango.width()+lastAssetBoundary+3)
314  x=pango.width()+lastAssetBoundary+3;
315  cairo_move_to(cairo,0.5*(x+lastAssetBoundary-pango.width()),0);
316  showAsset(pango, cairo, assetClass);
317  // final column vertical line
318  colLeftMargin.push_back(x);
319  cairo_move_to(cairo,x,topTableOffset);
320  cairo_rel_line_to(cairo,0,tableHeight);
321  cairo_move_to(cairo,x+3,topTableOffset);
322  cairo_rel_line_to(cairo,0,tableHeight);
323  cairo_set_line_width(cairo,0.5);
324  cairo_stroke(cairo);
325 
326  cairo_move_to(cairo,x-pulldownHot,topTableOffset);
327 
328  // now row sum column
329  x+=3;
330  double y=topTableOffset;
331  cairo_move_to(cairo,x,0); // display A-L-E above the final column. for ticket 1285
332  pango.setMarkup("A-L-E");
333  pango.show();
334  double colWidth=pango.width();
335 
336  for (unsigned row=0; row<m_godleyIcon.table.rows(); ++row) // perform row sum on stock var heading column too. for ticket 1285
337  {
338  if (row >0 && row<scrollRowStart) continue;
339  pango.setMarkup(latexToPango(m_godleyIcon.rowSum(row)));
340  colWidth=max(colWidth,pango.width());
341  cairo_move_to(cairo,x,y);
342  pango.show();
343  y+=rowHeight;
344  }
345 
346  x+=colWidth;
347  y=topTableOffset;
348  for (unsigned row=0; row<=m_godleyIcon.table.rows(); ++row)
349  {
350  // horizontal lines
351  if (row>0 && row<scrollRowStart) continue;
352  cairo_move_to(cairo,leftTableOffset,y);
353  cairo_line_to(cairo,x,y);
354  cairo_set_line_width(cairo,0.5);
355  cairo_stroke(cairo);
356  y+=rowHeight;
357  }
358 
359  // final vertical line
360  colLeftMargin.push_back(x);
361  cairo_move_to(cairo,x,topTableOffset);
362  cairo_rel_line_to(cairo,0,tableHeight);
363  cairo_set_line_width(cairo,0.5);
364  cairo_stroke(cairo);
365 
366  // indicate cell mouse is hovering over
367  if ((hoverRow>0 || hoverCol>0) &&
368  size_t(hoverRow)<m_godleyIcon.table.rows() &&
369  size_t(hoverCol)<m_godleyIcon.table.cols())
370  {
371  const CairoSave cs(cairo);
372  cairo_rectangle(cairo,
375  cairo_set_line_width(cairo,1);
376  cairo_stroke(cairo);
377  }
378 
379  // indicate selected cells
380  {
381  const CairoSave cs(cairo);
383  {
384  size_t i=0, j=0;
386 
387  if (motionCol>=0 && selectedRow==0 && selectedCol>0) // whole col being moved
388  {
390  highlightColumn(cairo,motionCol);
391  }
392  else if (motionRow>=0 && selectedCol==0 && selectedRow>0) // whole Row being moved
393  {
394  highlightRow(cairo,selectedRow);
395  highlightRow(cairo,motionRow);
396  }
397  else if (selectedCol==0 || /* selecting individual cell */
399  {
400  if ((selectedRow>1 || selectedRow <0) || selectedCol!=0) // can't select flows/stockVars or Initial Conditions labels
401  {
403  const double xx=colLeftMargin[i], yy=j*rowHeight+topTableOffset;
404  {
405  const cairo::CairoSave cs(cairo);
406  cairo_set_source_rgba(cairo,1,1,1,1);
407  cairo_rectangle(cairo,xx,yy,colLeftMargin[i+1]-xx,rowHeight);
408  cairo_fill_preserve(cairo);
409  cairo_set_source_rgba(cairo,1,.55,0,1);
410  cairo_set_line_width(cairo,2);
411  cairo_stroke(cairo);
412  }
414  cairo_move_to(cairo,xx,yy);
415  pango.show();
416 
417  // show insertion cursor
418  cairo_move_to(cairo,xx+pango.idxToPos(insertIdx),yy);
419  cairo_rel_line_to(cairo,0,rowHeight);
420  cairo_set_line_width(cairo,1);
421  cairo_stroke(cairo);
422  if (motionRow>0 && motionCol>0)
424  if (selectIdx!=insertIdx)
425  {
426  // indicate some text has been selected
427  cairo_rectangle(cairo,xx+pango.idxToPos(insertIdx),yy,
428  pango.idxToPos(selectIdx)-pango.idxToPos(insertIdx),rowHeight);
429  cairo_set_source_rgba(cairo,0.5,0.5,0.5,0.5);
430  cairo_fill(cairo);
431  }
432  }
433  }
434  }
435  }
436  }
double leftTableOffset
offset of the table within the window
std::string expMultiplier(int exp)
string defang(char c)
Definition: latexMarkup.cc:842
std::size_t cols() const
Definition: godleyTable.h:115
static constexpr double pulldownHot
space for ▼ in stackVar cells minimum column width (for eg empty columns)
std::string latexToPango(const char *s)
Definition: latexMarkup.h:30
EngNotation engExp(double value)
return formatted mantissa and exponent in engineering format
bool drawButtons
whether to draw row/column buttons
VariableValues variableValues
Definition: minsky.h:200
bool displayValues
Definition: minsky.h:431
static constexpr double minColumnWidth
double zoomFactor
zoom the display
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
std::string rowSum(int row) const
return the A-L-E row sum for row
Definition: godleyIcon.cc:522
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
string valueId(const string &name)
construct a valueId from fully qualified name @ name should not be canonicalised
Definition: valueId.cc:75
void highlightCell(cairo_t *cairo, unsigned row, unsigned col)
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
double rowHeight
computed height of each row
std::vector< ButtonWidget< row > > rowWidgets
void highlightColumn(cairo_t *cairo, unsigned col)
std::vector< double > colLeftMargin
computed positions of the table columns
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
std::string mantissa(double value, const EngNotation &, int digits=3)
GodleyIcon & m_godleyIcon
Godley icon that owns this.
void showAsset(Pango &pango, cairo_t *cairo, GodleyAssetClass::AssetClass assetClass)
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
const vector< AssetClass > & _assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:78
int selectedRow
which cell is active, none initially
void highlightRow(cairo_t *cairo, unsigned row)
unsigned scrollRowStart
starting row/col number of the scrolling region
int motionCol
current cell under mouse motion
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
std::vector< ButtonWidget< col > > colWidgets
static constexpr double columnButtonsOffset
Here is the call graph for this function:

◆ enableButtons()

void minsky::GodleyTableEditor::enableButtons ( )
inline

Definition at line 101 of file godleyTableWindow.h.

References m_enableButtons(), and requestRedrawCanvas().

Here is the call graph for this function:

◆ godleyIcon() [1/2]

GodleyIcon& minsky::GodleyTableEditor::godleyIcon ( )
inline

Definition at line 96 of file godleyTableWindow.h.

References m_godleyIcon.

96 {return m_godleyIcon;}
GodleyIcon & m_godleyIcon
Godley icon that owns this.

◆ godleyIcon() [2/2]

const GodleyIcon& minsky::GodleyTableEditor::godleyIcon ( ) const
inline

Definition at line 97 of file godleyTableWindow.h.

References m_godleyIcon.

97 {return m_godleyIcon;}
GodleyIcon & m_godleyIcon
Godley icon that owns this.

◆ handleBackspace()

void minsky::GodleyTableEditor::handleBackspace ( )
protected

Definition at line 749 of file godleyTableWindow.cc.

References minsky::numBytes(), minsky::prevIndex(), and minsky::str().

750  {
751  if (!selectedCellInTable()) return;
752  auto& table=m_godleyIcon.table;
753  auto& str=table.cell(selectedRow,selectedCol);
754  if (insertIdx!=selectIdx)
755  delSelection();
756  else if (insertIdx>0 && insertIdx<=str.length())
757  {
760  }
762  }
unsigned numBytes(unsigned char x)
a wrapper around std::ofstream that checks the write succeeded, throwing an exception if not ...
Definition: str.h:100
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
size_t prevIndex(const std::string &str, size_t index)
return index of previous character to index
Definition: str.h:112
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
Here is the call graph for this function:

◆ handleDelete()

void minsky::GodleyTableEditor::handleDelete ( )
protected

Definition at line 764 of file godleyTableWindow.cc.

References minsky::numBytes(), and minsky::str().

765  {
766  if (!selectedCellInTable()) return;
767  auto& table=m_godleyIcon.table;
768  auto& str=table.cell(selectedRow,selectedCol);
769  if (insertIdx!=selectIdx)
770  delSelection();
771  else if (insertIdx<str.length())
774  }
unsigned numBytes(unsigned char x)
a wrapper around std::ofstream that checks the write succeeded, throwing an exception if not ...
Definition: str.h:100
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
Here is the call graph for this function:

◆ height()

double minsky::GodleyTableEditor::height ( ) const

Definition at line 438 of file godleyTableWindow.cc.

439  {
440  return godleyIcon().table.rows()*rowHeight;
441  }
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
double rowHeight
computed height of each row

◆ highlightCell()

void minsky::GodleyTableEditor::highlightCell ( cairo_t *  cairo,
unsigned  row,
unsigned  col 
)

Definition at line 1002 of file godleyTableWindow.cc.

1003  {
1004  if (row<scrollRowStart || col<scrollColStart) return;
1005  const double x=colLeftMargin[col-scrollColStart+1];
1006  const double width=colLeftMargin[col-scrollColStart+2]-x;
1007  const double y=(row-scrollRowStart+1)*rowHeight+topTableOffset;
1008  cairo_rectangle(cairo,x,y,width,rowHeight);
1009  cairo_set_source_rgba(cairo,1,1,1,0.5);
1010  cairo_fill(cairo);
1011  }
double rowHeight
computed height of each row
std::vector< double > colLeftMargin
computed positions of the table columns
unsigned scrollRowStart
starting row/col number of the scrolling region

◆ highlightColumn()

void minsky::GodleyTableEditor::highlightColumn ( cairo_t *  cairo,
unsigned  col 
)

Definition at line 982 of file godleyTableWindow.cc.

983  {
984  if (col<scrollColStart) return;
985  const double x=colLeftMargin[col-scrollColStart+1];
986  const double width=colLeftMargin[col-scrollColStart+2]-x;
987  const double tableHeight=(m_godleyIcon.table.rows()-scrollRowStart+1)*rowHeight;
988  cairo_rectangle(cairo,x,topTableOffset,width,tableHeight);
989  cairo_set_source_rgba(cairo,1,1,1,0.5);
990  cairo_fill(cairo);
991  }
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
double rowHeight
computed height of each row
std::vector< double > colLeftMargin
computed positions of the table columns
GodleyIcon & m_godleyIcon
Godley icon that owns this.
unsigned scrollRowStart
starting row/col number of the scrolling region

◆ highlightRow()

void minsky::GodleyTableEditor::highlightRow ( cairo_t *  cairo,
unsigned  row 
)

Definition at line 993 of file godleyTableWindow.cc.

994  {
995  if (row<scrollRowStart) return;
996  const double y=(row-scrollRowStart+1)*rowHeight+topTableOffset;
997  cairo_rectangle(cairo,leftTableOffset,y,colLeftMargin.back()-leftTableOffset,rowHeight);
998  cairo_set_source_rgba(cairo,1,1,1,0.5);
999  cairo_fill(cairo);
1000  }
double leftTableOffset
offset of the table within the window
double rowHeight
computed height of each row
std::vector< double > colLeftMargin
computed positions of the table columns
unsigned scrollRowStart
starting row/col number of the scrolling region

◆ importStockVar()

void minsky::GodleyTableEditor::importStockVar ( const std::string &  name,
double  x 
)

Definition at line 862 of file godleyTableWindow.cc.

863  {
864  const int c=colXZoomed(x);
865  importStockVarByCol(name, c);
866  }
void importStockVarByCol(const std::string &name, int c)
int colXZoomed(double x) const

◆ importStockVarByCol()

void minsky::GodleyTableEditor::importStockVarByCol ( const std::string &  name,
int  c 
)

Definition at line 868 of file godleyTableWindow.cc.

References minsky::Minsky::importDuplicateColumn(), and pyminsky::minsky.

869  {
870  if (c>0 && size_t(c)<m_godleyIcon.table.cols())
871  {
872  m_godleyIcon.table.cell(0,c)=name;
874  adjustWidgets();
875  update(); //TODO I don't know why this is insufficient to update icon on canvas
876  }
877  }
void importDuplicateColumn(GodleyTable &srcTable, int srcCol)
find any duplicate column, and use it as a source column for balanceDuplicateColumns ...
Definition: minsky.cc:618
std::size_t cols() const
Definition: godleyTable.h:115
void update()
update canvas godleyIcon, and any related godley icons. Can throw
void adjustWidgets()
ensure button widgets are synced with current table data
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
GodleyIcon & m_godleyIcon
Godley icon that owns this.
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ keyPress()

void minsky::GodleyTableEditor::keyPress ( int  keySym,
const std::string &  utf8 
)

Definition at line 633 of file godleyTableWindow.cc.

References minsky::control(), cut(), minsky::numBytes(), minsky::prevIndex(), and minsky::str().

Referenced by minsky::GodleyTableWindow::keyPress().

634  {
635 
636  auto& table=m_godleyIcon.table;
637  if (selectedCellInTable() && (selectedCol!=0 || selectedRow!=1)) // Cell (1,0) is off-limits. For ticket 1064
638  {
639  auto& str=table.cell(selectedRow,selectedCol);
640  str=utf_to_utf<char>(str);
641  if (utf8.length() && (keySym<0x7f || (0xffaa <= keySym && keySym <= 0xffbf))) // Enable numeric keypad key presses. For ticket 1136
642  // all printing and control characters have keysym
643  // <0x80. But some keys (eg tab, backspace and escape
644  // are mapped to control characters
645  if (unsigned(utf8[0])>=' ' && utf8[0]!=0x7f)
646  {
647  delSelection();
648  if (insertIdx>=str.length()) insertIdx=str.length();
649  str.insert(insertIdx,utf8);
650  selectIdx=insertIdx+=utf8.length();
651  }
652  else
653  {
654  switch (utf8[0]) // process control characters
655  {
656  case control('x'):
657  cut();
658  break;
659  case control('c'):
660  copy();
661  break;
662  case control('v'):
663  paste();
664  break;
665  case control('h'): case 0x7f:
666  handleDelete();
667  break;
668  }
669  }
670  else
671  {
672  switch (keySym)
673  {
674  case 0xff08: // backspace
675  handleBackspace();
676  break;
677  case 0xffff: // delete
678  handleDelete();
679  break;
680  case 0xff1b: // escape
681  if (selectedRow>=0 && size_t(selectedRow)<=table.rows() &&
682  selectedCol>=0 && size_t(selectedCol)<=table.cols())
683  table.cell(selectedRow, selectedCol)=table.savedText;
685  break;
686  case 0xff0d: //return
687  case 0xff8d: //enter added for ticket 1122
688  update();
690  break;
691  case 0xff51: //left arrow
693  else navigateLeft();
694  break;
695  case 0xff53: //right arrow
696  if (insertIdx<str.length()) insertIdx+=numBytes(str[insertIdx]);
697  else navigateRight();
698  break;
699  case 0xff09: // tab
700  navigateRight();
701  break;
702  case 0xfe20: // back tab
703  navigateLeft();
704  break;
705  case 0xff54: // down
706  navigateDown();
707  break;
708  case 0xff52: // up
709  navigateUp();
710  break;
711  default:
712  return; // key not handled, just return without resetting selection
713  }
715  }
716  }
717  else // nothing selected
718  {
719  // if one of the navigation keys pressed, move to the first/last etc cell
720  switch (keySym)
721  {
722  case 0xff09: case 0xff53: // tab, right
723  selectedRow=0; selectedCol=1; break;
724  case 0xfe20: // back tab
725  selectedRow=table.rows()-1; selectedCol=table.cols()-1; break;
726  case 0xff51: //left arrow
727  selectedRow=0; selectedCol=table.cols()-1; break;
728  case 0xff54: // down
729  selectedRow=2; selectedCol=0; break; // Start from second row because Initial Conditions cell (1,0) can no longer be selected. For ticket 1064
730  case 0xff52: // up
731  selectedRow=table.rows()-1; selectedCol=0; break;
732  default:
733  return; // early return, no need to redraw
734  }
735  }
737  }
void update()
update canvas godleyIcon, and any related godley icons. Can throw
void navigateDown()
move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col ...
unsigned numBytes(unsigned char x)
a wrapper around std::ofstream that checks the write succeeded, throwing an exception if not ...
Definition: str.h:100
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
size_t prevIndex(const std::string &str, size_t index)
return index of previous character to index
Definition: str.h:112
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
void navigateUp()
move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col ...
GodleyIcon & m_godleyIcon
Godley icon that owns this.
virtual void requestRedrawCanvas()
constexpr char control(char x)
int selectedRow
which cell is active, none initially
void navigateLeft()
move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col ...
void navigateRight()
move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col ...
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ m_enableButtons()

void minsky::GodleyTableEditor::m_enableButtons ( )
inlineprivate

Definition at line 83 of file godleyTableWindow.h.

References adjustWidgets(), drawButtons, leftTableOffset, and topTableOffset.

Referenced by enableButtons(), and GodleyTableEditor().

83  {
86  }
double leftTableOffset
offset of the table within the window
void adjustWidgets()
ensure button widgets are synced with current table data
bool drawButtons
whether to draw row/column buttons
static constexpr double buttonSpacing
Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchingTableColumns()

std::set< string > minsky::GodleyTableEditor::matchingTableColumns ( double  x)

return list of matching table columns for column at x

Definition at line 839 of file godleyTableWindow.cc.

840  {
841  const int col=colXZoomed(x);
843  }
std::set< string > matchingTableColumnsByCol(int c)
int colXZoomed(double x) const

◆ matchingTableColumnsByCol()

std::set< string > minsky::GodleyTableEditor::matchingTableColumnsByCol ( int  c)

Definition at line 845 of file godleyTableWindow.cc.

References minsky::Minsky::matchingTableColumns(), and pyminsky::minsky.

846  {
847  if (col<0||col>=static_cast<int>(godleyIcon().table.cols())) return {};
848  return minsky().matchingTableColumns(godleyIcon(), godleyIcon().table._assetClass(col));
849  }
std::set< string > matchingTableColumns(const GodleyIcon &currTable, GodleyAssetClass::AssetClass ac)
Definition: minsky.cc:567
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
Here is the call graph for this function:

◆ mouseDown()

void minsky::GodleyTableEditor::mouseDown ( double  x,
double  y 
)

event handling

Definition at line 485 of file godleyTableWindow.cc.

References minsky::str().

Referenced by minsky::GodleyTableWindow::mouseDown().

486  {
487  // catch exception, as the intention here is to allow the user to fix a problem
488  try {update();}
489  catch (...) {}
490  button1=true;
491  x/=zoomFactor;
492  y/=zoomFactor;
494  switch (clickType(x,y))
495  {
496  case rowWidget:
497  {
498  const unsigned r=rowY(y);
499  if (r<rowWidgets.size())
500  {
501  rowWidgets[r].invoke(x);
502  adjustWidgets();
504  }
505  return;
506  }
507  case colWidget:
508  {
509  const unsigned c=colX(x);
510  const unsigned visibleCol=c-scrollColStart+1;
511  if (c<colWidgets.size() && visibleCol < colLeftMargin.size())
512  {
513  colWidgets[c].invoke(x-colLeftMargin[visibleCol]);
514  adjustWidgets();
516  }
517  return;
518  }
519  case background:
522  break;
523  default:
524  if (selectedRow>=0 && selectedCol>=0)
525  { // if cell already selected, deselect to allow the chance to redraw
527  break;
528  }
529  selectedCol=colX(x);
530  selectedRow=rowY(y);
531  if (selectedCellInTable() && (selectedRow!=1 || selectedCol!=0)) // Cannot save text in cell(1,0). For ticket 1064
532  {
533  // Make sure non-utf8 chars converted to utf8 as far as possible. for ticket 1166.
535  str=utf_to_utf<char>(str);
538  }
539  else
541  break;
542  }
543  }
int rowY(double y) const
row at y in unzoomed coordinates
ClickType clickType(double x, double y) const
void update()
update canvas godleyIcon, and any related godley icons. Can throw
void adjustWidgets()
ensure button widgets are synced with current table data
double zoomFactor
zoom the display
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::vector< ButtonWidget< row > > rowWidgets
std::vector< double > colLeftMargin
computed positions of the table columns
int colX(double x) const
column at x in unzoomed coordinates
bool button1
mouse button pressed
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
GodleyIcon & m_godleyIcon
Godley icon that owns this.
virtual void requestRedrawCanvas()
int selectedRow
which cell is active, none initially
std::string savedText
save text in currently highlighted column heading for renaming all variable instances and to enable u...
Definition: godleyTable.h:177
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
std::vector< ButtonWidget< col > > colWidgets
int textIdx(double x) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseMove()

void minsky::GodleyTableEditor::mouseMove ( double  x,
double  y 
)

Definition at line 589 of file godleyTableWindow.cc.

Referenced by minsky::GodleyTableWindow::mouseMove().

590  {
591  if (button1)
592  {
593  mouseMoveB1(x,y);
594  return;
595  }
596  x/=zoomFactor;
597  y/=zoomFactor;
598  // clear any existing marks
599  for (auto& i: rowWidgets) i.hover(-1);
600  for (auto& i: colWidgets) i.hover(-1);
601  hoverRow=hoverCol=-1;
602  switch (clickType(x,y))
603  {
604  case rowWidget:
605  {
606  const unsigned r=rowY(y);
607  if (r<rowWidgets.size())
608  rowWidgets[r].hover(x);
610  break;
611  }
612  case colWidget:
613  {
614  const unsigned c=colX(x);
615  if (c<colWidgets.size())
616  colWidgets[c].hover(x-colLeftMargin[c]);
618  break;
619  }
620  case background:
621  break;
622  default:
623  hoverRow=rowY(y);
624  if (hoverRow>0) hoverRow-=scrollRowStart-1;
625  hoverCol=colX(x);
626  if (hoverCol>0) hoverCol-=scrollColStart-1;
627  break;
628  }
629  }
int rowY(double y) const
row at y in unzoomed coordinates
ClickType clickType(double x, double y) const
void mouseMoveB1(double x, double y)
mouse motion with button 1 pressed
double zoomFactor
zoom the display
std::vector< ButtonWidget< row > > rowWidgets
std::vector< double > colLeftMargin
computed positions of the table columns
int colX(double x) const
column at x in unzoomed coordinates
bool button1
mouse button pressed
virtual void requestRedrawCanvas()
unsigned scrollRowStart
starting row/col number of the scrolling region
std::vector< ButtonWidget< col > > colWidgets
Here is the caller graph for this function:

◆ mouseMoveB1()

void minsky::GodleyTableEditor::mouseMoveB1 ( double  x,
double  y 
)

mouse motion with button 1 pressed

Definition at line 579 of file godleyTableWindow.cc.

580  {
581  x/=zoomFactor;
582  y/=zoomFactor;
583  motionCol=colX(x), motionRow=rowY(y);
585  selectIdx=textIdx(x);
587  }
int rowY(double y) const
row at y in unzoomed coordinates
double zoomFactor
zoom the display
int colX(double x) const
column at x in unzoomed coordinates
virtual void requestRedrawCanvas()
int selectedRow
which cell is active, none initially
int motionCol
current cell under mouse motion
int textIdx(double x) const

◆ mouseUp()

void minsky::GodleyTableEditor::mouseUp ( double  x,
double  y 
)

Definition at line 545 of file godleyTableWindow.cc.

References minsky::Minsky::balanceDuplicateColumns(), and pyminsky::minsky.

Referenced by minsky::GodleyTableWindow::mouseUp().

546  {
547  button1=false;
548  x/=zoomFactor;
549  y/=zoomFactor;
550  const int c=colX(x), r=rowY(y);
551  motionRow=motionCol=-1;
552  // Cannot swap cell(1,0) with another. For ticket 1064. Also cannot move cells outside an existing Godley table to create new rows or columns. For ticket 1066.
553  if ((selectedCol==0 && selectedRow==1) || (c==0 && r==1) || size_t(selectedRow)>=(m_godleyIcon.table.rows()) || size_t(r)>=(m_godleyIcon.table.rows()) || size_t(c)>=(m_godleyIcon.table.cols()) || size_t(selectedCol)>=(m_godleyIcon.table.cols()))
554  return;
555  if (selectedRow==0)
556  {
557  // Disallow moving flow labels column and prevent columns from moving when import stockvar dropdown button is pressed in empty column. For tickets 1053/1064/1066
558  if (c>0 && size_t(c)<m_godleyIcon.table.cols() && selectedCol>0 && size_t(selectedCol)<m_godleyIcon.table.cols() && c!=selectedCol && !(colLeftMargin[c+1]-x < pulldownHot))
560  }
561  else if (r>0 && selectedCol==0)
562  {
563  if (r!=selectedRow && !m_godleyIcon.table.initialConditionRow(selectedRow) && !m_godleyIcon.table.initialConditionRow(r)) // Cannot move Intitial Conditions row. For ticket 1064.
565  }
566  else if ((c!=selectedCol || r!=selectedRow) && c>0 && r>0)
567  {
571  selectedCol=-1;
572  selectedRow=-1;
573  }
574  else if (selectIdx!=insertIdx)
575  copy();
577  }
int rowY(double y) const
row at y in unzoomed coordinates
std::size_t cols() const
Definition: godleyTable.h:115
static constexpr double pulldownHot
space for ▼ in stackVar cells minimum column width (for eg empty columns)
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:753
void moveCol(int col, int n)
Definition: godleyTable.cc:109
double zoomFactor
zoom the display
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void moveRow(int row, int n)
move row row down by n places (up if -ve)
Definition: godleyTable.cc:98
std::vector< double > colLeftMargin
computed positions of the table columns
int colX(double x) const
column at x in unzoomed coordinates
bool button1
mouse button pressed
GodleyIcon & m_godleyIcon
Godley icon that owns this.
virtual void requestRedrawCanvas()
int selectedRow
which cell is active, none initially
int motionCol
current cell under mouse motion
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveAssetClass()

string minsky::GodleyTableEditor::moveAssetClass ( double  x,
double  y 
)

Definition at line 923 of file godleyTableWindow.cc.

References minsky::anonymous_namespace{godleyTableWindow.cc}::constructMessage().

924  {
925  x/=zoomFactor;
926  y/=zoomFactor;
927  const unsigned c=colX(x);
928  string tmpStr;
929  if (c>=m_godleyIcon.table.cols()) return tmpStr;
930  if (clickType(x,y)==colWidget) {
931  const unsigned visibleCol=c-scrollColStart+1;
932  if (c<colWidgets.size() && visibleCol < colLeftMargin.size())
933  {
934  auto moveVar=m_godleyIcon.table.cell(0,c);
935  auto oldAssetClass=m_godleyIcon.table._assetClass(c);
936  auto targetAssetClassPlus=m_godleyIcon.table._assetClass(c+1);
937  auto targetAssetClassMinus=m_godleyIcon.table._assetClass(c-1);
938  if (colWidgets[c].button(x-colLeftMargin[visibleCol])==3 && oldAssetClass!=GodleyAssetClass::equity) {
939  if (targetAssetClassPlus!=oldAssetClass && !moveVar.empty() && targetAssetClassPlus!=GodleyAssetClass::equity && targetAssetClassPlus!=GodleyAssetClass::noAssetClass)
940  tmpStr=constructMessage(targetAssetClassPlus,oldAssetClass,moveVar);
941  else if (targetAssetClassPlus==GodleyAssetClass::noAssetClass && !moveVar.empty())
942  tmpStr="Cannot convert stock variable to an equity class";
943  }
944  else if (colWidgets[c].button(x-colLeftMargin[visibleCol])==2 && oldAssetClass==GodleyAssetClass::asset && oldAssetClass!=GodleyAssetClass::equity && targetAssetClassMinus!=GodleyAssetClass::asset) {
945  if (targetAssetClassPlus!=oldAssetClass && !moveVar.empty() && targetAssetClassPlus!=GodleyAssetClass::equity && targetAssetClassPlus!=GodleyAssetClass::noAssetClass)
946  tmpStr=constructMessage(targetAssetClassPlus,oldAssetClass,moveVar);
947  else if ((targetAssetClassPlus==GodleyAssetClass::equity || targetAssetClassPlus==GodleyAssetClass::noAssetClass) && !moveVar.empty())
948  tmpStr="Cannot convert stock variable to an equity class";
949  }
950  else if (colWidgets[c].button(x-colLeftMargin[visibleCol])==2 && oldAssetClass!=GodleyAssetClass::equity) {
951  if (targetAssetClassMinus!=oldAssetClass && !moveVar.empty())
952  tmpStr=constructMessage(targetAssetClassMinus,oldAssetClass,moveVar);
953  }
954  }
955  }
956  return tmpStr;
957  }
ClickType clickType(double x, double y) const
std::size_t cols() const
Definition: godleyTable.h:115
string constructMessage(GodleyAssetClass::AssetClass &targetAC, GodleyAssetClass::AssetClass &oldAC, string &var)
double zoomFactor
zoom the display
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::vector< double > colLeftMargin
computed positions of the table columns
int colX(double x) const
column at x in unzoomed coordinates
GodleyIcon & m_godleyIcon
Godley icon that owns this.
const vector< AssetClass > & _assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:78
std::vector< ButtonWidget< col > > colWidgets
Here is the call graph for this function:

◆ navigateDown()

void minsky::GodleyTableEditor::navigateDown ( )

move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col

Definition at line 1162 of file godleyTableWindow.cc.

1163  {
1164  update();
1165  if (selectedRow>=0)
1167  checkCell00();
1168  }
void update()
update canvas godleyIcon, and any related godley icons. Can throw
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void checkCell00()
check if cell (0,0) is selected, and deselect if so handle delete or backspace. Cell assumed selected...
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially

◆ navigateLeft()

void minsky::GodleyTableEditor::navigateLeft ( )

move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col

Definition at line 1137 of file godleyTableWindow.cc.

1138  {
1139  if (selectedCol>=0)
1140  {
1141  update();
1142  selectedCol--;
1143  if (selectedCol<0)
1144  {
1146  navigateUp();
1147  }
1148  checkCell00();
1150  godleyIcon().table.cell(selectedRow, selectedCol).length(): 0;
1151  }
1152  }
std::size_t cols() const
Definition: godleyTable.h:115
bool cellInTable(int row, int col) const
Definition: godleyTable.h:155
void update()
update canvas godleyIcon, and any related godley icons. Can throw
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void checkCell00()
check if cell (0,0) is selected, and deselect if so handle delete or backspace. Cell assumed selected...
void navigateUp()
move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col ...
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...

◆ navigateRight()

void minsky::GodleyTableEditor::navigateRight ( )

move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col

Definition at line 1120 of file godleyTableWindow.cc.

1121  {
1122  if (selectedCol>=0)
1123  {
1124  update();
1125  selectedCol++;
1126  insertIdx=0;
1127  if (selectedCol>=int(m_godleyIcon.table.cols()))
1128  {
1129  if (selectedRow>0) selectedCol=0; // Minor fix: Make sure tabbing and right arrow traverse all editable cells.
1130  else selectedCol=1;
1131  navigateDown();
1132  }
1133  checkCell00();
1134  }
1135  }
std::size_t cols() const
Definition: godleyTable.h:115
void update()
update canvas godleyIcon, and any related godley icons. Can throw
void navigateDown()
move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col ...
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void checkCell00()
check if cell (0,0) is selected, and deselect if so handle delete or backspace. Cell assumed selected...
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...

◆ navigateUp()

void minsky::GodleyTableEditor::navigateUp ( )

move selected cell right, left, up or down, moving to next line and wrapping if at end of row or col

Definition at line 1154 of file godleyTableWindow.cc.

1155  {
1156  update();
1157  if (selectedRow>=0)
1159  checkCell00();
1160  }
void update()
update canvas godleyIcon, and any related godley icons. Can throw
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void checkCell00()
check if cell (0,0) is selected, and deselect if so handle delete or backspace. Cell assumed selected...
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially

◆ paste()

void minsky::GodleyTableEditor::paste ( )

Definition at line 799 of file godleyTableWindow.cc.

References minsky::cminsky(), and minsky::str().

800  {
801  if (!selectedCellInTable()) return;
802  delSelection();
804  auto stringToInsert=cminsky().clipboard.getClipboard();
805  // only insert first line
806  auto p=stringToInsert.find('\n');
807  if (p!=string::npos)
808  stringToInsert=stringToInsert.substr(0,p-1);
809  str.insert(insertIdx,stringToInsert);
810  selectIdx=insertIdx+=stringToInsert.length();
812  }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:549
GodleyIcon & m_godleyIcon
Godley icon that owns this.
virtual void requestRedrawCanvas()
int selectedRow
which cell is active, none initially
unsigned insertIdx
location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped) ...
Here is the call graph for this function:

◆ pushHistory()

void minsky::GodleyTableEditor::pushHistory ( )

Definition at line 1013 of file godleyTableWindow.cc.

1014  {
1015  while (history.size()>maxHistory) history.pop_front();
1016  // Perform deep comparison of Godley tables in history to avoid spurious noAssetClass columns from arising during undo. For ticket 1118.
1017  if (history.empty() || !(history.back()==m_godleyIcon.table)) {
1018  history.push_back(m_godleyIcon.table);
1019  }
1020  historyPtr=history.size();
1021  }
std::deque< GodleyTable > history
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::size_t maxHistory
maximum no. of history states to save
GodleyIcon & m_godleyIcon
Godley icon that owns this.

◆ requestRedrawCanvas()

virtual void minsky::GodleyTableEditor::requestRedrawCanvas ( )
inlineprotectedvirtual

Reimplemented in minsky::GodleyTableWindow.

Definition at line 213 of file godleyTableWindow.h.

Referenced by disableButtons(), and enableButtons().

213 {} // request redraw of canvas if a canvas
Here is the caller graph for this function:

◆ rowY()

int minsky::GodleyTableEditor::rowY ( double  y) const
protected

row at y in unzoomed coordinates

Definition at line 453 of file godleyTableWindow.cc.

Referenced by rowYZoomed().

454  {
455  int c=(y-topTableOffset)/rowHeight;
456  if (c>0) c+=scrollRowStart-1;
457  if (c<0 || size_t(c)>m_godleyIcon.table.rows()) c=-1; // out of bounds, invalidate
458  return c;
459  }
std::size_t rows() const
Definition: godleyTable.h:114
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
double rowHeight
computed height of each row
GodleyIcon & m_godleyIcon
Godley icon that owns this.
unsigned scrollRowStart
starting row/col number of the scrolling region
Here is the caller graph for this function:

◆ rowYZoomed()

int minsky::GodleyTableEditor::rowYZoomed ( double  y) const
inline

Definition at line 154 of file godleyTableWindow.h.

References rowY(), and zoomFactor.

154 {return rowY(y/zoomFactor);}
int rowY(double y) const
row at y in unzoomed coordinates
double zoomFactor
zoom the display
Here is the call graph for this function:

◆ selectedCellInTable()

bool minsky::GodleyTableEditor::selectedCellInTable ( ) const

Definition at line 151 of file godleyTableWindow.cc.

152  {
154  }
bool cellInTable(int row, int col) const
Definition: godleyTable.h:155
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially

◆ swapAssetClass()

string minsky::GodleyTableEditor::swapAssetClass ( double  x,
double  y 
)

Definition at line 959 of file godleyTableWindow.cc.

References minsky::anonymous_namespace{godleyTableWindow.cc}::constructMessage().

960  {
961  x/=zoomFactor;
962  const int c=colX(x);
963  string tmpStr;
964  if (selectedRow==0 && size_t(selectedCol)<m_godleyIcon.table.cols())
965  {
966  // clickType triggers pango error which causes this condition to be skipped and thus column gets moved to Equity, which should not be the case
967  if (c>0 && selectedCol>0 && c!=selectedCol) {
968  auto swapVar=m_godleyIcon.table.cell(0,selectedCol);
969  auto oldAssetClass=m_godleyIcon.table._assetClass(selectedCol);
970  auto targetAssetClass=m_godleyIcon.table._assetClass(c);
971  if (!swapVar.empty() && !(colLeftMargin[c+1]-x < pulldownHot)) { // ImportVar dropdown button should not trigger this condition. For ticket 1162
972  if (targetAssetClass!=oldAssetClass && targetAssetClass!=GodleyAssetClass::equity && targetAssetClass!=GodleyAssetClass::noAssetClass)
973  tmpStr=constructMessage(targetAssetClass,oldAssetClass,swapVar);
974  else if ((targetAssetClass==GodleyAssetClass::equity || targetAssetClass==GodleyAssetClass::noAssetClass) || oldAssetClass==GodleyAssetClass::noAssetClass)
975  tmpStr="Cannot convert stock variable to an equity class";
976  }
977  }
978  }
979  return tmpStr;
980  }
std::size_t cols() const
Definition: godleyTable.h:115
static constexpr double pulldownHot
space for ▼ in stackVar cells minimum column width (for eg empty columns)
string constructMessage(GodleyAssetClass::AssetClass &targetAC, GodleyAssetClass::AssetClass &oldAC, string &var)
double zoomFactor
zoom the display
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::vector< double > colLeftMargin
computed positions of the table columns
int colX(double x) const
column at x in unzoomed coordinates
GodleyIcon & m_godleyIcon
Godley icon that owns this.
const vector< AssetClass > & _assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:78
int selectedRow
which cell is active, none initially
Here is the call graph for this function:

◆ textIdx()

int minsky::GodleyTableEditor::textIdx ( double  x) const

Definition at line 461 of file godleyTableWindow.cc.

References minsky::defang(), minsky::numBytes(), and minsky::str().

462  {
463  const cairo::Surface surf(cairo_recording_surface_create(CAIRO_CONTENT_COLOR,NULL));
464  Pango pango(surf.cairo());
465  if (selectedCellInTable() && (selectedRow!=1 || selectedCol!=0)) // No text index needed for a cell that is immutable. For ticket 1064
466  {
467  // Make sure non-utf8 chars converted to utf8 as far as possible. for ticket 1166.
469  str=utf_to_utf<char>(str);
470  pango.setMarkup(defang(str));
471  int j=0;
473  x-=colLeftMargin[j]+2;
474  x*=zoomFactor;
475  if (x>0 && str.length())
476  {
477  auto p=pango.posToIdx(x);
478  if (p<str.length())
479  return p+numBytes(str[p]);
480  }
481  }
482  return 0;
483  }
string defang(char c)
Definition: latexMarkup.cc:842
unsigned numBytes(unsigned char x)
a wrapper around std::ofstream that checks the write succeeded, throwing an exception if not ...
Definition: str.h:100
double zoomFactor
zoom the display
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
std::vector< double > colLeftMargin
computed positions of the table columns
std::string str(T x)
utility function to create a string representation of a numeric type
Definition: str.h:33
GodleyIcon & m_godleyIcon
Godley icon that owns this.
int selectedRow
which cell is active, none initially
Here is the call graph for this function:

◆ undo()

void minsky::GodleyTableEditor::undo ( int  changes)

restore to state changes ago

Definition at line 1023 of file godleyTableWindow.cc.

1024  {
1025  if (historyPtr==history.size())
1026  pushHistory();
1027  historyPtr-=changes;
1028  if (historyPtr > 0 && historyPtr <= history.size())
1029  {
1030  auto& d=history[historyPtr-1];
1031  // Perform deep comparison of Godley tables in history to avoid spurious noAssetClass columns from arising during undo. For ticket 1118.
1032  if (d.getData().empty()) return; // should not happen
1033  m_godleyIcon.table=d;
1034  }
1035  }
std::deque< GodleyTable > history
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
GodleyIcon & m_godleyIcon
Godley icon that owns this.

◆ update()

void minsky::GodleyTableEditor::update ( )

update canvas godleyIcon, and any related godley icons. Can throw

Definition at line 1069 of file godleyTableWindow.cc.

References minsky::Minsky::balanceDuplicateColumns(), minsky::Minsky::canvas, minsky::Minsky::importDuplicateColumn(), minsky::Canvas::item, pyminsky::minsky, minsky::Minsky::model, minsky::Minsky::redrawAllGodleyTables(), minsky::Canvas::renameAllInstances(), and minsky::Canvas::requestRedraw().

1070  {
1071  if (selectedCol>0 && selectedCol<int(m_godleyIcon.table.cols()))
1072  {
1073  if (selectedRow==0)
1074  {
1075  // rename all instances of the stock variable if updated. For ticket #956
1076  // find stock variable if it exists
1077  for (const auto& sv: m_godleyIcon.stockVars())
1078  if (sv->valueId()==m_godleyIcon.valueId(m_godleyIcon.table.savedText))
1079  {
1080  auto savedItem=minsky().canvas.item;
1081  minsky().canvas.item=sv;
1082  auto newName=utf_to_utf<char>(m_godleyIcon.table.cell(selectedRow,selectedCol));
1083  if (!newName.empty())
1084  minsky().canvas.renameAllInstances(newName);
1085  savedItem.swap(minsky().canvas.item);
1086  }
1088  }
1089  else
1090  {
1092  {
1093  // if the contents of the cell are cleared, set the cell to "0". For #1181
1096  }
1098  }
1099  // get list of GodleyIcons first, rather than doing recursiveDo, as update munges the items vectors
1100  auto godleyTables=minsky().model->findItems
1101  ([](const ItemPtr& i){return dynamic_cast<GodleyIcon*>(i.get());});
1102  for (auto& i: godleyTables)
1103  if (auto* g=dynamic_cast<GodleyIcon*>(i.get()))
1104  g->update();
1105  }
1108  }
void importDuplicateColumn(GodleyTable &srcTable, int srcCol)
find any duplicate column, and use it as a source column for balanceDuplicateColumns ...
Definition: minsky.cc:618
std::size_t cols() const
Definition: godleyTable.h:115
void balanceDuplicateColumns(const GodleyIcon &srcTable, int srcCol)
makes all duplicated columns consistent with srcTable, srcCol
Definition: minsky.cc:753
void redrawAllGodleyTables()
request all Godley table windows to redraw
Definition: minsky.cc:1703
std::shared_ptr< Item > ItemPtr
Definition: item.h:57
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:144
GodleyTable table
table data. Must be declared before editor
Definition: godleyIcon.h:80
void renameAllInstances(const std::string &newName)
rename all instances of variable as item to newName
Definition: canvas.cc:555
std::string valueId(const std::string &x) const
returns valueid for variable reference in table
Definition: godleyIcon.h:142
Canvas canvas
Definition: minsky.h:256
GodleyIcon & m_godleyIcon
Godley icon that owns this.
void requestRedraw()
request a redraw on the screen
Definition: canvas.h:292
const Variables & stockVars() const
Definition: godleyIcon.h:113
int selectedRow
which cell is active, none initially
std::string savedText
save text in currently highlighted column heading for renaming all variable instances and to enable u...
Definition: godleyTable.h:177
GroupPtr model
Definition: minsky.h:255
Minsky & minsky()
global minsky object
Definition: minskyTCL.cc:51
ItemPtr item
item or wire obtained by get*At() calls
Definition: canvas.h:175
Here is the call graph for this function:

◆ width()

double minsky::GodleyTableEditor::width ( ) const
inline

Definition at line 125 of file godleyTableWindow.h.

References colLeftMargin.

125 {return colLeftMargin.empty()? 0: colLeftMargin.back();}
std::vector< double > colLeftMargin
computed positions of the table columns

Member Data Documentation

◆ button1

bool minsky::GodleyTableEditor::button1 =false
private

mouse button pressed

Definition at line 82 of file godleyTableWindow.h.

◆ colLeftMargin

std::vector<double> minsky::GodleyTableEditor::colLeftMargin

computed positions of the table columns

Definition at line 112 of file godleyTableWindow.h.

Referenced by width().

◆ columnButtonsOffset

constexpr double minsky::GodleyTableEditor::columnButtonsOffset =12
static

Definition at line 88 of file godleyTableWindow.h.

◆ colWidgets

std::vector<ButtonWidget<col> > minsky::GodleyTableEditor::colWidgets
protected

Definition at line 201 of file godleyTableWindow.h.

◆ drawButtons

bool minsky::GodleyTableEditor::drawButtons =true

whether to draw row/column buttons

Definition at line 99 of file godleyTableWindow.h.

Referenced by disableButtons(), and m_enableButtons().

◆ history

std::deque<GodleyTable> minsky::GodleyTableEditor::history
protected

Definition at line 208 of file godleyTableWindow.h.

◆ historyPtr

std::size_t minsky::GodleyTableEditor::historyPtr =0

Definition at line 174 of file godleyTableWindow.h.

◆ hoverCol

int minsky::GodleyTableEditor::hoverCol =-1

Definition at line 110 of file godleyTableWindow.h.

◆ hoverRow

int minsky::GodleyTableEditor::hoverRow =-1

Definition at line 110 of file godleyTableWindow.h.

◆ insertIdx

unsigned minsky::GodleyTableEditor::insertIdx =0

location of insertion pointer in selected cell, as well as other end of selection (if mouse-swiped)

Definition at line 117 of file godleyTableWindow.h.

◆ leftTableOffset

double minsky::GodleyTableEditor::leftTableOffset =4*ButtonWidget<col>::buttonSpacing

offset of the table within the window

Definition at line 90 of file godleyTableWindow.h.

Referenced by disableButtons(), and m_enableButtons().

◆ m_godleyIcon

GodleyIcon& minsky::GodleyTableEditor::m_godleyIcon
private

Godley icon that owns this.

Definition at line 81 of file godleyTableWindow.h.

Referenced by godleyIcon().

◆ maxHistory

std::size_t minsky::GodleyTableEditor::maxHistory {100}

maximum no. of history states to save

Definition at line 173 of file godleyTableWindow.h.

◆ minColumnWidth

constexpr double minsky::GodleyTableEditor::minColumnWidth =4*ButtonWidget<col>::buttonSpacing
static

Definition at line 94 of file godleyTableWindow.h.

◆ motionCol

int minsky::GodleyTableEditor::motionCol =-1
protected

current cell under mouse motion

Definition at line 206 of file godleyTableWindow.h.

◆ motionRow

int minsky::GodleyTableEditor::motionRow =-1
protected

Definition at line 206 of file godleyTableWindow.h.

◆ pulldownHot

constexpr double minsky::GodleyTableEditor::pulldownHot =12
static

space for ▼ in stackVar cells minimum column width (for eg empty columns)

Definition at line 92 of file godleyTableWindow.h.

◆ rowHeight

double minsky::GodleyTableEditor::rowHeight =0

computed height of each row

Definition at line 114 of file godleyTableWindow.h.

◆ rowWidgets

std::vector<ButtonWidget<row> > minsky::GodleyTableEditor::rowWidgets
protected

Definition at line 200 of file godleyTableWindow.h.

◆ scrollColStart

unsigned minsky::GodleyTableEditor::scrollColStart =1

Definition at line 104 of file godleyTableWindow.h.

◆ scrollRowStart

unsigned minsky::GodleyTableEditor::scrollRowStart =1

starting row/col number of the scrolling region

Definition at line 104 of file godleyTableWindow.h.

◆ selectedCol

int minsky::GodleyTableEditor::selectedCol =-1

Definition at line 106 of file godleyTableWindow.h.

◆ selectedRow

int minsky::GodleyTableEditor::selectedRow =-1

which cell is active, none initially

Definition at line 106 of file godleyTableWindow.h.

◆ selectIdx

unsigned minsky::GodleyTableEditor::selectIdx =0

Definition at line 117 of file godleyTableWindow.h.

◆ srcCol

int minsky::GodleyTableEditor::srcCol =-1

Definition at line 108 of file godleyTableWindow.h.

◆ srcRow

int minsky::GodleyTableEditor::srcRow =-1

src cell in the event of a move

Definition at line 108 of file godleyTableWindow.h.

◆ topTableOffset

double minsky::GodleyTableEditor::topTableOffset =30

Definition at line 91 of file godleyTableWindow.h.

Referenced by disableButtons(), and m_enableButtons().

◆ zoomFactor

double minsky::GodleyTableEditor::zoomFactor =1

The documentation for this class was generated from the following files: