libyui-ncurses
Loading...
Searching...
No Matches
NCTable Class Reference

#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)
 
std::vector< std::string > getHeader () const
 
virtual void addItems (const YItemCollection &itemCollection)
 
virtual void addItem (YItem *yitem)
 
virtual void addItem (YItem *yitem, NCTableLine::STATE state)
 
virtual void deleteAllItems ()
 
virtual int getCurrentIndex () const
 
virtual int getCurrentItem () const
 
YItem * getCurrentItemPointer ()
 
virtual void setCurrentItem (int index)
 
virtual void scrollToFirstItem ()
 
virtual void selectItem (YItem *yitem, bool selected)
 
void selectCurrentItem ()
 
virtual void deselectAllItems ()
 
virtual NCursesEvent wHandleInput (wint_t key)
 
virtual int preferredWidth ()
 
virtual int preferredHeight ()
 
virtual void setSize (int newWidth, int newHeight)
 
virtual void setLabel (const std::string &nlabel)
 
virtual void setEnabled (bool do_bv)
 
virtual bool setKeyboardFocus ()
 
bool setItemByKey (int key)
 
void SetSepChar (const chtype colSepchar)
 
void SetSepWidth (const unsigned sepwidth)
 
void SetHotCol (int hcol)
 
bool bigList () const
 
void setBigList (bool big)
 
void stripHotkeys ()
 
void setSortStrategy (NCTableSortStrategyBase *newStrategy)
 
NCTableSortStrategyBasesortStrategy () const
 
- 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)
 
 tnode (NCWidget *v, self &p, bool behind=true)
 
 tnode (NCWidget *v, self &p, self &s, bool behind=true)
 
void Disconnect ()
 Disconnect from the parent and siblings, but keep children.
 
bool ReparentTo (self &p, bool behind=true)
 
bool ReparentTo (self &p, self &s, bool behind=true)
 
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)
 
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
 
virtual NCPadCreatePad ()
 
virtual NCTablePadmyPad () const
 
virtual void addItem (YItem *yitem, bool preventRedraw, NCTableLine::STATE state=NCTableLine::S_NORMAL)
 
virtual void addPadLine (NCTableLine *parentLine, YItem *yitem, bool preventRedraw, NCTableLine::STATE state=NCTableLine::S_NORMAL)
 
void rebuildPadLines ()
 
void rebuildHeaderLine ()
 
NCstring alignmentStr (int col)
 
bool hasNestedItems (const YItemCollection &itemCollection) const
 
bool hasNestedItems (YItemConstIterator begin, YItemConstIterator end) const
 
virtual void startMultipleChanges ()
 
virtual void doneMultipleChanges ()
 
void toggleCurrentItem ()
 
void cellChanged (const YTableCell *cell)
 
void setCell (int index, int col, const std::string &newText)
 
void assignIndex (YItemConstIterator begin, YItemConstIterator end)
 
void assignIndex (YItem *item)
 
void interactiveSort ()
 
void sortItems (int sortCol, bool reverse=false)
 
void sortYItems (YItemIterator begin, YItemIterator end)
 
- 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 tnode< NCWidget * >
- 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",...)
 
- Protected Member Functions inherited from NCSchrollCB

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

Member Function Documentation

◆ addItem() [1/3]

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

Add one item.

Implemented from YSelectionWidget.

◆ 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.

◆ 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.

◆ addItems()

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

Add items.

Reimplemented from YSelectionWidget to optimize sorting.

◆ 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.

◆ alignmentStr()

NCstring NCTable::alignmentStr ( int col)
protected

Return the NCurses alignment string for the alignment of the specified column: One of "L", "C", "R" (Left, Center, Right).

◆ assignIndex() [1/2]

void NCTable::assignIndex ( YItem * item)
protected

Assign an item a unique index.

◆ assignIndex() [2/2]

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().

◆ bigList()

bool NCTable::bigList ( ) const
inline

Flag: Is this a big list?

◆ cellChanged()

void NCTable::cellChanged ( const YTableCell * cell)
protected

Notification that a cell has now changed content: Set that cell's content also in the corresponding table line.

◆ CreatePad()

NCPad * NCTable::CreatePad ( )
protectedvirtual

Create an empty pad and set its background.

Reimplemented from NCPadWidget.

◆ deleteAllItems()

void NCTable::deleteAllItems ( )
virtual

Delete all items and clear the pad.

Implemented from YSelectionWidget.

Reimplemented in NCFileSelection.

◆ deselectAllItems()

void NCTable::deselectAllItems ( )
virtual

Deselect all items.

Implemented from YSelectionWidget.

◆ doneMultipleChanges()

virtual void NCTable::doneMultipleChanges ( )
inlineprotectedvirtual

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

Implemented from YWidget.

◆ getCurrentIndex()

int NCTable::getCurrentIndex ( ) const
virtual

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

◆ 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.

◆ 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.

◆ getHeader()

vector< string > NCTable::getHeader ( ) const

Get the table headers (the first line inside the table) as strings. Alignment flags are removed.

◆ hasNestedItems()

bool NCTable::hasNestedItems ( const YItemCollection & itemCollection) const
protected

Return 'true' if any item in the item collection has any children, 'false' otherwise.

◆ 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.

◆ location()

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

Code location for logging.

Implemented from NCWidget.

Reimplemented from NCPadWidget.

◆ 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.

◆ preferredHeight()

int NCTable::preferredHeight ( )
virtual

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

Implemented from YWidget.

◆ preferredWidth()

int NCTable::preferredWidth ( )
virtual

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

Implemented from YWidget.

◆ rebuildHeaderLine()

void NCTable::rebuildHeaderLine ( )
protected

Rebuild the table header line.

◆ 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.

◆ scrollToFirstItem()

void NCTable::scrollToFirstItem ( )
virtual

Scroll to the first item.

◆ 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)

◆ selectItem()

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

Select or deselect an item.

Implemented from YSelectionWidget.

◆ setBigList()

void NCTable::setBigList ( bool big)
inline

Set the "big list" flag.

◆ 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'.

◆ setCurrentItem()

void NCTable::setCurrentItem ( int index)
virtual

Set the current item to the specified index.

◆ setEnabled()

void NCTable::setEnabled ( bool do_bv)
virtual

Enable or disable this widget.

Implemented from YWidget.

Reimplemented from NCPadWidget.

◆ setHeader()

void NCTable::setHeader ( const std::vector< std::string > & head)

Set the table header (the first line inside the table) as strings.

◆ SetHotCol()

void NCTable::SetHotCol ( int hcol)
inline

Set the hotkey column (?). Used only in NCPopupTable.

◆ setItemByKey()

bool NCTable::setItemByKey ( int key)

Select an item by its hotkey. Used only in NCPopupTable::wHandleHotkey().

◆ setKeyboardFocus()

virtual bool NCTable::setKeyboardFocus ( )
inlinevirtual

Set the keyboard focus to this widget.

Implemented from YWidget.

◆ 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.

◆ SetSepChar()

void NCTable::SetSepChar ( const chtype colSepchar)
inline

Set the column separator character. Used only in NCPopupTable and in NCFileSelection.

◆ SetSepWidth()

void NCTable::SetSepWidth ( const unsigned sepwidth)
inline

Set the separator width. Used only in NCPopupTable.

◆ 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.

◆ setSortStrategy()

void NCTable::setSortStrategy ( NCTableSortStrategyBase * newStrategy)

Set a sorting strategy. This class takes ownership.

◆ 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.

◆ sortStrategy()

NCTableSortStrategyBase * NCTable::sortStrategy ( ) const
inline

Return the current sorting strategy.

◆ sortYItems()

void NCTable::sortYItems ( YItemIterator begin,
YItemIterator end )
protected

Sort the YItems between 'begin' and 'end' using the current sort strategy.

◆ startMultipleChanges()

virtual void NCTable::startMultipleChanges ( )
inlineprotectedvirtual

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

Implemented from YWidget.

◆ stripHotkeys()

void NCTable::stripHotkeys ( )
inline

Remove all hotkeys from the pad.

◆ toggleCurrentItem()

void NCTable::toggleCurrentItem ( )
protected

Toggle the current item between selected and not selected.

◆ wHandleInput()

NCursesEvent NCTable::wHandleInput ( wint_t key)
virtual

Keyboard input 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.

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.

Reimplemented from NCWidget.

Reimplemented in NCDirectoryTable, and NCFileTable.


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