libyui-ncurses  2.57.2
NCTable Class Reference

A table with rows and columns. More...

#include <NCTable.h>

Inheritance diagram for NCTable:
Collaboration diagram for NCTable:

Public Member Functions

 NCTable (YWidget *parent, YTableHeader *tableHeader, bool multiSelection=false)
 
void setHeader (const std::vector< std::string > &head)
 Set the table header (the first line inside the table) as strings.
 
std::vector< std::string > getHeader () const
 Get the table headers (the first line inside the table) as strings. More...
 
virtual void addItems (const YItemCollection &itemCollection)
 Add items. More...
 
virtual void addItem (YItem *yitem)
 Add one item. More...
 
virtual void addItem (YItem *yitem, NCTableLine::STATE state)
 Add one item with the specified state and redraw the table. More...
 
virtual void deleteAllItems ()
 Delete all items and clear the pad. More...
 
virtual int getCurrentIndex () const
 Get the index of the current item (the item under the cursor) or -1 if there is none.
 
virtual int getCurrentItem () const
 Get the index of the current item (the item under the cursor) or -1 if there is none, i.e. More...
 
YItem * getCurrentItemPointer ()
 Return a pointer to the current item (the item under the cursor) or 0 if there is none, i.e. More...
 
virtual void setCurrentItem (int index)
 Set the current item to the specified index.
 
virtual void scrollToFirstItem ()
 Scroll to the first item.
 
virtual void selectItem (YItem *yitem, bool selected)
 Select or deselect an item. More...
 
void selectCurrentItem ()
 Select the current item (the item under the cursor). More...
 
virtual void deselectAllItems ()
 Deselect all items. More...
 
virtual NCursesEvent wHandleInput (wint_t key)
 Keyboard input handler. More...
 
virtual int preferredWidth ()
 libyui geometry management: Return the preferred width for this widget. More...
 
virtual int preferredHeight ()
 libyui geometry management: Return the preferred height for this widget. More...
 
virtual void setSize (int newWidth, int newHeight)
 libyui geometry management: Apply the width and height assigned from the parent layout widget. More...
 
virtual void setLabel (const std::string &nlabel)
 Set the label (the caption) above the table. More...
 
virtual void setEnabled (bool do_bv)
 Enable or disable this widget. More...
 
virtual bool setKeyboardFocus ()
 Set the keyboard focus to this widget. More...
 
bool setItemByKey (int key)
 Select an item by its hotkey. More...
 
void SetSepChar (const chtype colSepchar)
 Set the column separator character. More...
 
void SetSepWidth (const unsigned sepwidth)
 Set the separator width. More...
 
void SetHotCol (int hcol)
 Set the hotkey column (?). More...
 
bool bigList () const
 Flag: Is this a big list?
 
void setBigList (bool big)
 Set the "big list" flag.
 
void stripHotkeys ()
 Remove all hotkeys from the pad.
 
void setSortStrategy (NCTableSortStrategyBase *newStrategy)
 Set a sorting strategy. More...
 
NCTableSortStrategyBasesortStrategy () const
 Return the current sorting strategy.
 
- Public Member Functions inherited from NCPadWidget
 NCPadWidget (NCWidget *myparent=0)
 
 NCPadWidget (YWidget *parent)
 
size_t Columns ()
 
void setLabel (const NClabel &nlabel)
 
- Public Member Functions inherited from NCWidget
void grabSet (NCWidget *ngrab)
 
void grabRelease (NCWidget *ograb)
 
 NCWidget (NCWidget *myparent)
 
 NCWidget (YWidget *parent=0)
 
bool isValid () const
 
bool winExist () const
 
virtual const NCstyle::StylewStyle () const
 
const NCstyle::StWidgetwidgetStyle (bool nonactive=false) const
 
const NCstyle::StWidgetframeStyle () const
 
const NCstyle::StListlistStyle () const
 
wsze wGetDefsze () const
 
wrect wGetSize () const
 
void Update ()
 
void Redraw (bool sub=false)
 
void Recoded ()
 
NC::WState GetState () const
 
void SetState (const NC::WState newstate, bool force=false)
 
virtual bool HasHotkey (int key)
 
virtual bool HasFunctionHotkey (int key) const
 
virtual NCursesEvent wHandleHotkey (wint_t key)
 
void DumpOn (std::ostream &str, std::string prfx) const
 
- Public Member Functions inherited from tnode< NCWidget * >
 tnode (NCWidget * v, self *p=0, bool behind=true)
 New node, added as the last child by default (which is natural). More...
 
 tnode (NCWidget * v, self &p, bool behind=true)
 New node, added as the last child by default (which is natural). More...
 
 tnode (NCWidget * v, self &p, self &s, bool behind=true)
 New node under p, just after s (or before s if behind==false) More...
 
void Disconnect ()
 Disconnect from the parent and siblings, but keep children.
 
bool ReparentTo (self &p, bool behind=true)
 Disconnect from old parent, connect to new parent p. More...
 
bool ReparentTo (self &p, self &s, bool behind=true)
 Disconnect from old parent, connect to new parent p and sibling s. More...
 
NCWidget * & Value () const
 
NCWidget * & operator() () const
 Alias for Value.
 
selfParent ()
 
const selfParent () const
 
selfPsibling ()
 Previous sibling.
 
const selfPsibling () const
 Previous sibling.
 
selfNsibling ()
 Next sibling.
 
const selfNsibling () const
 Next sibling.
 
selfFchild ()
 First child.
 
const selfFchild () const
 First child.
 
selfLchild ()
 Last child.
 
const selfLchild () const
 Last child.
 
bool HasParent () const
 
bool HasSiblings () const
 
bool HasChildren () const
 
bool IsParentOf (const self &c) const
 
bool IsSiblingOf (const self &s) const
 
bool IsChildOf (const self &p) const
 
unsigned Depth () const
 Depth: zero if no parent, otherwise 1 + parent's depth.
 
bool IsDescendantOf (const self &n) const
 
bool IsDescendantOf (const self *n) const
 
selfTop ()
 Root of the tree.
 
const selfTop () const
 
selfNext (bool restart=false)
 Next node: depth first, pre-order. More...
 
selfNext (self *&c, bool restart=false)
 Return Next and assign it to c.
 
const selfNext (bool restart=false) const
 
const selfNext (const self *&c, bool restart=false) const
 
selfPrev (bool restart=false)
 
selfPrev (self *&c, bool restart=false)
 Return Prev and assign it to c.
 
const selfPrev (bool restart=false) const
 
const selfPrev (const self *&c, bool restart=false) const
 

Protected Member Functions

virtual const char * location () const
 Code location for logging. More...
 
virtual NCPadCreatePad ()
 Create an empty pad and set its background.
 
virtual NCTablePadmyPad () const
 Return the TreePad that belongs to this widget. More...
 
virtual void addItem (YItem *yitem, bool preventRedraw, NCTableLine::STATE state=NCTableLine::S_NORMAL)
 Internal overloaded version of addItem(). More...
 
virtual void addPadLine (NCTableLine *parentLine, YItem *yitem, bool preventRedraw, NCTableLine::STATE state=NCTableLine::S_NORMAL)
 Add a pad line (an NCTableLine) for 'yitem' and recurse into any of its children (and grandchildren etc.). More...
 
void rebuildPadLines ()
 Build or rebuild the pad lines: Clear the pad, iterate over all YItems and add a corresponding NCTableLine to the pad. More...
 
void rebuildHeaderLine ()
 Rebuild the table header line.
 
NCstring alignmentStr (int col)
 Return the NCurses alignment string for the alignment of the specified column: One of "L", "C", "R" (Left, Center, Right).
 
bool hasNestedItems (const YItemCollection &itemCollection) const
 Return 'true' if any item in the item collection has any children, 'false' otherwise.
 
bool hasNestedItems (YItemConstIterator begin, YItemConstIterator end) const
 
virtual void startMultipleChanges ()
 Optimization for NCurses from libyui: Notification that multiple changes are about to come. More...
 
virtual void doneMultipleChanges ()
 Optimization for NCurses from libyui: Notification that multiple changes are now finished. More...
 
void toggleCurrentItem ()
 Toggle the current item between selected and not selected.
 
void cellChanged (const YTableCell *cell)
 Notification that a cell has now changed content: Set that cell's content also in the corresponding table line.
 
void setCell (int index, int col, const std::string &newText)
 Change the cell with item index 'index' and column no. More...
 
void assignIndex (YItemConstIterator begin, YItemConstIterator end)
 Recursively iterate over items and assign each one a unique item index. More...
 
void assignIndex (YItem *item)
 Assign an item a unique index.
 
void interactiveSort ()
 Interactive sorting by a user-selected column: More...
 
void sortItems (int sortCol, bool reverse=false)
 Sort the items by column no. More...
 
void sortYItems (YItemIterator begin, YItemIterator end)
 Sort the YItems between 'begin' and 'end' using the current sort strategy.
 
- Protected Member Functions inherited from NCPadWidget
void startMultidraw ()
 
void stopMultidraw ()
 
bool inMultidraw () const
 
unsigned labelWidth () const
 
virtual void wCreate (const wrect &newrect)
 
virtual void wDelete ()
 
virtual void wRedraw ()
 
virtual void wRecoded ()
 
wsze defPadSze () const
 
virtual void DrawPad ()
 
void InitPad ()
 
void AdjustPad (wsze nsze)
 
void DelPad ()
 
virtual void HScroll (unsigned total, unsigned visible, unsigned start)
 
virtual void VScroll (unsigned total, unsigned visible, unsigned start)
 
virtual void ScrollHead (NCursesWindow &w, unsigned ccol)
 
virtual void AdjustPadSize (wsze &minsze)
 
virtual bool handleInput (wint_t key)
 
- Protected Member Functions inherited from NCWidget
virtual void PreDisconnect ()
 
virtual void PostDisconnect ()
 
virtual void PreReparent ()
 
virtual void PostReparent ()
 
NCursesWindowParentWin ()
 
bool grabFocus ()
 
virtual void grabNotify (NCWidget *)
 
virtual bool wantFocus (NCWidget &ngrab)
 
void wMoveChildTo (NCWidget &child, const wpos &newpos)
 
void wRelocate (const wrect &newrect)
 
void wRelocate (const wpos &newpos, const wsze &newsze)
 
virtual void wMoveTo (const wpos &newpos)
 
virtual void wUpdate (bool forced_br=false)
 
wpos ScreenPos () const
 
- Protected Member Functions inherited from NCursesError
 NCursesError (const char *msg="unknown error",...)
 
 NCursesError (int val, const char *msg="unknown error",...)
 
NCursesErrorNCError (const char *msg="unknown error",...)
 
NCursesErrorNCError (int val, const char *msg="unknown error",...)
 

Friends

std::ostream & operator<< (std::ostream &str, const NCTable &obj)
 

Additional Inherited Members

- Protected Types inherited from tnode< NCWidget * >
typedef tnode< NCWidget * > self
 
- Protected Attributes inherited from NCPadWidget
bool hasHeadline
 
bool activeLabelOnly
 
- Protected Attributes inherited from NCWidget
NCWidget *const grabedBy
 
NCursesWindowwin
 (owned)
 
wsze defsze
 
wrect framedim
 
wrect inparent
 
bool noUpdates
 
bool skipNoDimWin
 
NC::WState wstate
 
NClabelhotlabel
 
- Protected Attributes inherited from tnode< NCWidget * >
NCWidgetval
 
- Protected Attributes inherited from NCursesError
int errval_i
 
std::string errmsg_t
 

Detailed Description

A table with rows and columns.

Items may be nested.

See also https://github.com/libyui/libyui-ncurses/blob/master/doc/nctable-and-nctree.md

Definition at line 42 of file NCTable.h.

Member Function Documentation

◆ addItem() [1/3]

virtual void NCTable::addItem ( YItem *  yitem)
inlinevirtual

Add one item.

Implemented from YSelectionWidget.

Definition at line 77 of file NCTable.h.

◆ addItem() [2/3]

void NCTable::addItem ( YItem *  yitem,
bool  preventRedraw,
NCTableLine::STATE  state = NCTableLine::S_NORMAL 
)
protectedvirtual

Internal overloaded version of addItem().

This creates a visual representation of the new table line consisting of individual cells. If 'preventRedraw' is 'false', the table is redrawn; otherwise, it is up to the caller to redraw the table.

This is used in addItem( yitem ) and addItems( itemCollection ) in this class, but also in the derived NCFileSelection and NCPkgTable classes.

Definition at line 245 of file NCTable.cc.

◆ addItem() [3/3]

void NCTable::addItem ( YItem *  yitem,
NCTableLine::STATE  state 
)
virtual

Add one item with the specified state and redraw the table.

This overloaded version is first defined here and also used in NCPopupTable. Notice that this does not have a default value for the 'state' parameter to avoid clashing with the addItem( YItem * ) version inherited from YSelectionWidget which might be used from C++ applications using libyui.

Definition at line 232 of file NCTable.cc.

◆ addItems()

void NCTable::addItems ( const YItemCollection &  itemCollection)
virtual

Add items.

Reimplemented from YSelectionWidget to optimize sorting.

Definition at line 210 of file NCTable.cc.

◆ addPadLine()

void NCTable::addPadLine ( NCTableLine parentLine,
YItem *  yitem,
bool  preventRedraw,
NCTableLine::STATE  state = NCTableLine::S_NORMAL 
)
protectedvirtual

Add a pad line (an NCTableLine) for 'yitem' and recurse into any of its children (and grandchildren etc.).

Make sure to update _nestedItems (by iterating over all the YItems) before the first one is added so they will reserve some screen space for the tree hierarchy line graphics (using the prefix placeholder).

This can realistically only be done when bulk-adding all YItems at once. If they are added one by one, the first few may not have any children, so their corresponding pad lines will not reserve screen space for the prefix, leading to ugly results.

If there is no item nesting at all, this does not matter, of course.

Definition at line 259 of file NCTable.cc.

◆ assignIndex()

void NCTable::assignIndex ( YItemConstIterator  begin,
YItemConstIterator  end 
)
protected

Recursively iterate over items and assign each one a unique item index.

As long as the items don't have any child items, each one simply gets its initial position in the item collection. When there are children, however, there will be gaps between the index of one toplevel item and the next.

It is generally unsafe to make assumptions about the indices except that they are unique within one table, and an item will keep its initial index, no matter how the table is sorted.

The indices restart from 0 after the table has been cleared, i.e. after deleteAllItems() or at the start of setItems().

◆ deleteAllItems()

void NCTable::deleteAllItems ( )
virtual

Delete all items and clear the pad.

Implemented from YSelectionWidget.

Reimplemented in NCFileSelection.

Definition at line 353 of file NCTable.cc.

◆ deselectAllItems()

void NCTable::deselectAllItems ( )
virtual

Deselect all items.

Implemented from YSelectionWidget.

Definition at line 472 of file NCTable.cc.

◆ doneMultipleChanges()

virtual void NCTable::doneMultipleChanges ( )
inlineprotectedvirtual

Optimization for NCurses from libyui: Notification that multiple changes are now finished.

Implemented from YWidget.

Definition at line 370 of file NCTable.h.

◆ getCurrentItem()

int NCTable::getCurrentItem ( ) const
virtual

Get the index of the current item (the item under the cursor) or -1 if there is none, i.e.

the table is empty.

FIXME: This is a misnomer of epic proportions. This should be named getCurrentIndex(). A method called getCurrentItem() should return the item (i.e. a pointer or a reference), not an index! But since this is all over the place in derived classes and in libyui-ncurses-pkg as well, this is not a trivial thing to fix.

Definition at line 365 of file NCTable.cc.

◆ getCurrentItemPointer()

YItem * NCTable::getCurrentItemPointer ( )

Return a pointer to the current item (the item under the cursor) or 0 if there is none, i.e.

the table is empty.

FIXME: This is what getCurrentItem() should really be.

Definition at line 380 of file NCTable.cc.

Here is the call graph for this function:

◆ getHeader()

vector< string > NCTable::getHeader ( ) const

Get the table headers (the first line inside the table) as strings.

Alignment flags are removed.

Definition at line 196 of file NCTable.cc.

◆ interactiveSort()

void NCTable::interactiveSort ( )
protected

Interactive sorting by a user-selected column:

Open a popup with the (non-empty) column headers and let the user choose one for sorting.

Definition at line 639 of file NCTable.cc.

◆ location()

virtual const char* NCTable::location ( ) const
inlineprotectedvirtual

Code location for logging.

Implemented from NCWidget.

Reimplemented from NCPadWidget.

Definition at line 276 of file NCTable.h.

◆ myPad()

virtual NCTablePad* NCTable::myPad ( ) const
inlineprotectedvirtual

Return the TreePad that belongs to this widget.

Overloaded from NCPadWidget to narrow the type to the actual one used in this widget.

Reimplemented from NCPadWidget.

Definition at line 289 of file NCTable.h.

Here is the call graph for this function:

◆ preferredHeight()

int NCTable::preferredHeight ( )
virtual

libyui geometry management: Return the preferred height for this widget.

Implemented from YWidget.

Definition at line 507 of file NCTable.cc.

◆ preferredWidth()

int NCTable::preferredWidth ( )
virtual

libyui geometry management: Return the preferred width for this widget.

Implemented from YWidget.

Definition at line 500 of file NCTable.cc.

◆ rebuildPadLines()

void NCTable::rebuildPadLines ( )
protected

Build or rebuild the pad lines: Clear the pad, iterate over all YItems and add a corresponding NCTableLine to the pad.

This recurses into any child YItems.

This does not redraw the pad. Do that from the outside.

Definition at line 320 of file NCTable.cc.

◆ selectCurrentItem()

void NCTable::selectCurrentItem ( )

Select the current item (the item under the cursor).

Mark the currently highlighted table item as selected.

Yes, it is really already highlighted, so no need to selectItem() and setCurrentItem() here again. (bsc#493884)

Definition at line 463 of file NCTable.cc.

Here is the call graph for this function:

◆ selectItem()

void NCTable::selectItem ( YItem *  yitem,
bool  selected 
)
virtual

Select or deselect an item.

Implemented from YSelectionWidget.

Definition at line 412 of file NCTable.cc.

Here is the call graph for this function:

◆ setCell()

void NCTable::setCell ( int  index,
int  col,
const std::string &  newText 
)
protected

Change the cell with item index 'index' and column no.

'col' to 'newText'.

Definition at line 129 of file NCTable.cc.

Here is the call graph for this function:

◆ setEnabled()

void NCTable::setEnabled ( bool  do_bv)
virtual

Enable or disable this widget.

Implemented from YWidget.

Reimplemented from NCPadWidget.

Definition at line 527 of file NCTable.cc.

Here is the call graph for this function:

◆ SetHotCol()

void NCTable::SetHotCol ( int  hcol)
inline

Set the hotkey column (?).

Used only in NCPopupTable.

Definition at line 240 of file NCTable.h.

Here is the call graph for this function:

◆ setItemByKey()

bool NCTable::setItemByKey ( int  key)

Select an item by its hotkey.

Used only in NCPopupTable::wHandleHotkey().

Definition at line 534 of file NCTable.cc.

◆ setKeyboardFocus()

virtual bool NCTable::setKeyboardFocus ( )
inlinevirtual

Set the keyboard focus to this widget.

Implemented from YWidget.

Definition at line 208 of file NCTable.h.

◆ setLabel()

void NCTable::setLabel ( const std::string &  nlabel)
virtual

Set the label (the caption) above the table.

YTable does not specify a label because a table has a whole row of headers.

Definition at line 520 of file NCTable.cc.

◆ SetSepChar()

void NCTable::SetSepChar ( const chtype  colSepchar)
inline

Set the column separator character.

Used only in NCPopupTable and in NCFileSelection.

Definition at line 226 of file NCTable.h.

Here is the call graph for this function:

◆ SetSepWidth()

void NCTable::SetSepWidth ( const unsigned  sepwidth)
inline

Set the separator width.

Used only in NCPopupTable.

Definition at line 233 of file NCTable.h.

Here is the call graph for this function:

◆ setSize()

void NCTable::setSize ( int  newWidth,
int  newHeight 
)
virtual

libyui geometry management: Apply the width and height assigned from the parent layout widget.

Implemented from YWidget.

Definition at line 514 of file NCTable.cc.

◆ setSortStrategy()

void NCTable::setSortStrategy ( NCTableSortStrategyBase newStrategy)

Set a sorting strategy.

This class takes ownership.

Definition at line 750 of file NCTable.cc.

◆ sortItems()

void NCTable::sortItems ( int  sortCol,
bool  reverse = false 
)
protected

Sort the items by column no.

'sortCol' with the current sort strategy.

This sorts the YItems and recreates all NCTableLines. All YItem pointers remain valid, but the NCTableLines do not.

Definition at line 702 of file NCTable.cc.

◆ startMultipleChanges()

virtual void NCTable::startMultipleChanges ( )
inlineprotectedvirtual

Optimization for NCurses from libyui: Notification that multiple changes are about to come.

Implemented from YWidget.

Definition at line 362 of file NCTable.h.

◆ wHandleInput()

NCursesEvent NCTable::wHandleInput ( wint_t  key)
virtual

Keyboard input handler.

NCurses widget keyboard handler.

This is the starting point for handling key events. From here, key events are propagated to the pad and to the items.

Implemented from NCWidget.

This is the starting point for handling key events. From here, key events are propagated to the pad and to the items.

Reimplemented from NCWidget.

Reimplemented in NCDirectoryTable, and NCFileTable.

Definition at line 556 of file NCTable.cc.


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