sptk2 logo
SPTK Home Page
Public Member Functions | Static Public Member Functions | List of all members
sptk::CDBListView Class Reference

List view widget with extended database support. More...

#include <CDBListView.h>

Inheritance diagram for sptk::CDBListView:
sptk::CListView sptk::CControl sptk::CLayoutClient sptk::CDBDropDownListView

Public Member Functions

 CDBListView (const char *label=nullptr, int layoutSize=20, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
 
 ~CDBListView () override
 
void database (PoolDatabaseConnection *db)
 
PoolDatabaseConnectiondatabase () const
 
void sql (const String &sql, const String &recordCountSql="", const String &fastRefreshSQL="")
 
String sql ()
 
QueryParameterparam (const char *paramName, CRefreshKind refreshKind=CRefreshKind::LV_REFRESH_FULL)
 
void keyField (const String &fieldName)
 
String keyField () const
 
void setup (PoolDatabaseConnection *db, const String &sql, const String &keyField)
 
void refreshData (CRefreshKind refreshKind=CRefreshKind::LV_REFRESH_FULL)
 
DateTime lastRefresh () const
 
void maxRecords (uint32_t mr)
 
uint32_t maxRecords () const
 
bool recordsLimited () const
 
- Public Member Functions inherited from sptk::CListView
 CListView (const char *label=nullptr, int layoutSize=20, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
 Constructor in SPTK style. More...
 
 ~CListView () override
 Destructor.
 
int handle (int) override
 Overwritten handle()
 
void resize (int x, int y, int w, int h) override
 Resizes the control and inside widgets. More...
 
virtual void removeRow (uint32_t index)
 Removes row. More...
 
virtual void addRow (CPackedStrings *row)
 Adds new row. More...
 
virtual void addRow (int ident, const Strings &row)
 Adds new row. More...
 
virtual void insertRow (uint32_t position, const Strings &row, int ident)
 Inserts new row. More...
 
virtual void updateRow (uint32_t position, CPackedStrings *row)
 Updates a row. More...
 
virtual void updateRow (uint32_t position, const Strings &row, int ident=0)
 Updates a row. Optional row argument may be defined inside row parameter. More...
 
virtual void clear ()
 Removes all the rows.
 
virtual uint32_t size () const
 Returns the row count.
 
virtual int top () const
 Returns the scroll position.
 
virtual void top (int index)
 Sets the scroll position. More...
 
int selected (int index) const
 
void show (int index)
 
void show () override
 
void hide (int index)
 
void hide () override
 
int visible (int index) const
 
int visible () const
 
std::string textValue () const
 
void textValue (const std::string &text)
 
void dataMode (CListViewDataMode dm)
 
CListViewDataMode dataMode () const
 
Variant data () const override
 
void data (const Variant &v) override
 
CPackedStringsrow (uint32_t index) const
 
const CSelectionselection () const
 
CPackedStringsselectedRow () const
 
int selectedIndex () const
 
bool selectRow (uint32_t index, bool sel=true)
 
bool displayed (uint32_t index) const
 
virtual void displayRow (uint32_t index)
 
void redrawRow (uint32_t index)
 
void columns (const CColumnList &columns)
 Sets a new column list. More...
 
CColumnListcolumns ()
 Returns column list.
 
CColumncolumn (uint32_t col)
 Returns column informartion. More...
 
CColumncolumn (const char *colname)
 Returns column informartion. More...
 
void addColumn (const CColumn &column)
 Adds a new column as a copy of column. More...
 
void addColumn (const String &colname, VariantDataType type, uint32_t cwidth=100, bool cvisible=true)
 Adds a new column as a copy of column. More...
 
CControlKind kind () const override
 SPTK RTTI information. More...
 
bool autoRowHeight () const
 Returns auto row height mode as true/false.
 
void autoRowHeight (bool arh)
 Sets auto row height mode as true/false.
 
Fl_Font textFont () const override
 Returns text font type. More...
 
void textFont (Fl_Font f) override
 Sets text font type. More...
 
uchar textSize () const override
 
void textSize (uchar s) override
 Sets text font size. More...
 
Fl_Color textColor () const override
 Returns text color. More...
 
void textColor (Fl_Color n) override
 Sets text color. More...
 
bool showGrid () const
 Returns show grid mode.
 
void showGrid (bool flag)
 Sets show grid mode.
 
bool showStripes () const
 Returns show stripes.
 
void showStripes (bool flag)
 Sets show stripes mode.
 
bool showSelection () const
 Returns show selection mode.
 
void showSelection (bool flag)
 Sets show selection mode.
 
bool multiSelect () const
 Returns multiple selection enabled or disabled.
 
void multiSelect (bool ms)
 Sets multiple selection enabled or disabled.
 
void getSelections (std::vector< uint64_t > &selection) const
 Returns a selected rows ID list.
 
void setSelections (const std::vector< uint64_t > &selection)
 Sets a selected rows ID list.
 
CPackedStringsfindCaption (const String &caption)
 Finds an item with the caption (a string in the first column). More...
 
CPackedStringsfindKey (int keyValue)
 Finds an item with the key (an integer associated with the item - argument()). More...
 
uint32_t fullWidth () const
 Returns maximum width of all items including the header row.
 
uint32_t fullHeight () const
 Returns summary height of all items including the header row.
 
virtual int findString (const std::string &str, bool select=true, uint32_t startRow=0, uint32_t endRow=0)
 Finds a string in the sort column of list view defined with sortColumn() More...
 
String sortColumnName () const
 Returns sort column name.
 
void sortColumn (int column, bool sortNow)
 Sets the sort column. More...
 
int sortColumn () const
 Returns the sort column number.
 
bool sortAscending () const
 Returns the sort direction - ascending/descending.
 
void sortAscending (bool ascending, bool sortNow)
 Sets the sort direction - ascending/descending. More...
 
void sort ()
 Sorts ListView rows using existing information about sort column and direction.
 
void fill (DataSource &ds, const String &keyFieldName="", uint32_t recordsLimit=0, uint32_t recordsEstimated=0, CRefreshKind refreshKind=CRefreshKind::LV_REFRESH_FULL)
 Fills the list view with the data from datasource. More...
 
void loadList (const xdoc::SNode &node)
 Fills the list with the data from XML node. More...
 
void saveList (const xdoc::SNode &node) const
 Saves the list data into XML node. More...
 
bool preferredSize (int &w, int &h) override
 Computes the optimal widgets size. More...
 
uint32_t headerHeight () const
 Returns header height.
 
void headerHeight (uint32_t hh)
 Sets the header height, 0 to hide headers.
 
uint32_t activeRow () const
 Returns the currently active row.
 
bool capitalizeColumnNames () const
 Returns true if column names are auto-capitilized.
 
void capitalizeColumnNames (bool ccn)
 Defines if column names should be auto-capitilized. More...
 
void terminateFill ()
 Terminate the current fill() operation (if in progress)
 
String className () const override
 Returns widget class name (internal SPTK RTTI). More...
 
void imageCollection (Strings &iconNames)
 Sets the images that may be referred from items. More...
 
- Public Member Functions inherited from sptk::CControl
 CControl (const char *label, int layoutSize=20, CLayoutAlign layoutAlign=CLayoutAlign::TOP)
 Constructor in SPTK style. More...
 
void resize (int x, int y, int w, int h) override
 Resizes the control and inside widgets. More...
 
void draw () override
 Draws the control.
 
virtual int tag () const
 Returns the control's user data tag.
 
virtual void tag (int t)
 Sets the control's user data tag.
 
virtual Fl_Font textFont () const
 Returns the control's text font. More...
 
virtual void textFont (Fl_Font)
 Sets the control's text font. More...
 
virtual uchar textSize () const
 Returns the control's text font size. More...
 
virtual void textSize (uchar)
 Sets the control's text font size. More...
 
virtual Fl_Color textColor () const
 Returns the control's text color. More...
 
virtual void textColor (Fl_Color)
 Sets the control's text color. More...
 
virtual Fl_Color labelColor () const
 Returns the control's label color.
 
virtual void labelColor (Fl_Color)
 Sets the control's label color.
 
virtual Fl_Color color () const
 Returns the control's background color.
 
virtual void color (Fl_Color)
 Sets the control's background color.
 
uint32_t flags () const
 Returns the control's flags.
 
void flags (uint32_t flags)
 Sets the control's flags.
 
Fl_Widget * control () const
 Returns main widget inside the container.
 
const Stringlabel () const override
 Returns control's label. More...
 
void label (const String &) override
 Sets control's label. More...
 
Fl_Menu_ * menu () const
 Returns control's menu.
 
void menu (const Fl_Menu_Item *)
 Sets control's menu.
 
Fl_Font labelFont () const
 Returns control's label font.
 
void labelSize (Fl_Font f)
 Sets control's label font.
 
uchar labelSize () const
 Returns control's label font size.
 
void labelSize (uchar)
 Sets control's label font size.
 
uint32_t labelWidth () const
 Returns control's label width.
 
void labelWidth (uint32_t)
 Sets control's label width.
 
void hint (const String &str)
 Sets control's hint (tooltip) More...
 
String hint () const
 Returns control's hint (tooltip)
 
virtual int maxLength () const
 Returns control's max input length, if applicable. More...
 
virtual void maxLength (int)
 Sets control's max input length, if applicable. More...
 
virtual const StringfieldName () const
 Returns control's field name for universal data connection.
 
virtual void fieldName (const String &)
 Sets control's field name for universal data connection.
 
virtual CControlKind kind () const =0
 Returns control's kind (internal SPTK RTTI). More...
 
String className () const override
 Returns control's class name (internal SPTK RTTI). More...
 
virtual void reset ()
 Sets the control to empty text (for the input entries) More...
 
virtual void load (Query *)
 Loads control data from query fields. More...
 
virtual void save (Query *)
 Saves control data to query params. More...
 
void load (const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
 Loads control data from XML. More...
 
void load (const xdoc::SNode &node) override
 Loads control data from XML. More...
 
void save (const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
 Saves control data to XML. More...
 
virtual void save (const xdoc::SNode &node) const
 Saves control data to XML. More...
 
virtual bool valid () const =0
 Returns true if the control state is valid, and the data is inside the limits (if applicable) More...
 
virtual Variant data () const
 The universal data connector. More...
 
virtual void data (const Variant &v)
 The universal data connector, sets control data. More...
 
void fireEvent (CEvent ev, int32_t arg)
 Fires the event generated by this control.
 
const CEventInfoevent () const
 Returns the last event fired by this control.
 
CEvent eventType () const
 Returns the event type for the last fired by this control.
 
int eventArgument () const
 Returns the event argument for the last fired by this control.
 
CControloperator= (const String &str)
 Control data assignment.
 
CControloperator= (const char *str)
 Control data assignment.
 
CControloperator= (int32_t v)
 Control data assignment.
 
CControloperator= (uint32_t v)
 Control data assignment.
 
CControloperator= (int64_t v)
 Control data assignment.
 
CControloperator= (float v)
 Control data assignment.
 
CControloperator= (double v)
 Control data assignment.
 
CControloperator= (const DateTime &dt)
 Control data assignment.
 
CControloperator= (const Field &fld)
 Control data assignment.
 
 operator String () const
 Control data conversion.
 
 operator int32_t () const
 Control data conversion.
 
 operator uint32_t () const
 Control data conversion.
 
 operator int64_t () const
 Control data conversion.
 
 operator uint64_t () const
 Control data conversion.
 
 operator float () const
 Control data conversion.
 
 operator double () const
 Control data conversion.
 
 operator DateTime () const
 Control data conversion.
 
- Public Member Functions inherited from sptk::CLayoutClient
 CLayoutClient (Fl_Widget *widget, int layoutSize, CLayoutAlign ca)
 
virtual ~CLayoutClient ()
 
CLayoutAlign layoutAlign () const
 
void layoutAlign (CLayoutAlign al)
 
int layoutSize () const
 
void layoutSize (int ls)
 
virtual void label (const String &l)
 
virtual const Stringlabel () const
 
void name (const char *aname)
 
void name (const String &aname)
 
const Stringname () const
 
virtual bool preferredSize (int &w, int &h)
 
virtual bool computeSize (int &w, int &h)
 
virtual String className () const
 
Fl_Widget * widget () const
 
virtual void load (const xdoc::SNode &node, CLayoutXMLmode xmlMode)
 
virtual void load (const std::shared_ptr< xdoc::Node > &node)
 
virtual void save (const std::shared_ptr< xdoc::Node > &node, CLayoutXMLmode xmlMode) const
 

Static Public Member Functions

static CLayoutClientcreator (const xdoc::SNode &node)
 Creates a widget based on the XML node information. More...
 
- Static Public Member Functions inherited from sptk::CControl
static CControlKind controlNameToType (const String &typeName, int &maxLength, const String &values="")
 Converts control name to control kind.
 
static void defaultControlMenuCopy (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Copy'.
 
static void defaultControlMenuCut (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Delete'.
 
static void defaultControlMenuPaste (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Paste'.
 
static void defaultControlMenuClear (Fl_Widget *, void *)
 Default callback function to support CControl default menu item 'Clear'.
 

Additional Inherited Members

- Static Public Attributes inherited from sptk::CControl
static const Fl_Menu_Item defaultControlMenu []
 CControl default menu.
 
- Protected Member Functions inherited from sptk::CListView
int columnAt (int x)
 Computes which column contains x-coordinate. More...
 
int find_item (int y)
 Finds an item in vertical position y. More...
 
void bbox (int &X, int &Y, int &W, int &H) const
 Returns the actual size of the drawing area (internal) More...
 
int hposition () const
 Returns horizontal position of the scroll.
 
void hposition (int hpos)
 Sets horizontal position of the scroll. More...
 
int find_id (int id) const
 Finds item with ID. More...
 
virtual int get_focus ()
 Get focus callback (internal)
 
virtual bool item_selected (uint32_t index) const
 Returns true if item is selected. More...
 
virtual void item_select (uint32_t index, bool select)
 Selects or deselects the item. More...
 
virtual int item_compute_height_all ()
 Recomputes all items height.
 
virtual int item_compute_height (CPackedStrings *rowData)
 Recomputes items height. More...
 
virtual int item_height (uint32_t index) const
 Recomputes items height. More...
 
virtual int item_width (uint32_t index) const
 Returns item width. More...
 
virtual void item_draw (uint32_t index, const CPackedStrings *rowData, int x, int y, int w, int h, int focusMode, int verticalAlign, bool paintBackground) const
 Draws a row in coordinates (internal) More...
 
virtual void item_clicked (int mouse_btn)
 
virtual Fl_Color item_color (int column, const CPackedStrings &rowData) const
 The function that allows to overwrite the default text color for the cell. More...
 
virtual void header_draw (int x, int y, int hh) const
 Draws header (internal) More...
 
virtual void header_clicked (int x)
 Header clicked mouse callback. More...
 
virtual bool header_drag_position (int x)
 Returns true if x is the drag-sensitive area.
 
virtual void header_dragged (int x)
 Header dragged to position x notification. More...
 
virtual void header_released (int x)
 Header released in position x notification. More...
 
void redraw_line (uint32_t index)
 Request to redraw line index. More...
 
void redraw_lines ()
 Redraw all the lines.
 
void draw () override
 General draw function. Draws everything.
 
void key_changed (uint32_t index)
 Internal callback if selected another item with the different user _data (key).
 
void load (Query *) override
 Loads the key value from the query. More...
 
void save (Query *) override
 Saves the key value from the query. More...
 
void load (const xdoc::SNode &node, CLayoutXMLmode xmlMode) override
 Loads control data from XML. More...
 
void save (const xdoc::SNode &node, CLayoutXMLmode xmlMode) const override
 Saves control data to XML. More...
 
bool valid () const override
 True if the data is valid. More...
 
virtual uint32_t cellBorderWidth () const
 Returns the cell border width.
 
bool select (uint32_t index, bool sel=true, int docallbacks=false)
 Selects the row. Internal. More...
 
bool select_only (uint32_t index, bool docallbacks=false)
 Selects the only row. Internal. More...
 
bool activate_row (uint32_t index)
 Selects the row. Executes the callbacks. Internal. More...
 
bool select_first ()
 Selects the first row. Executes the callbacks. Internal. More...
 
bool select_last ()
 Selects the last row. Executes the callbacks. Internal. More...
 
bool select_next ()
 Selects the next row. Executes the callbacks. Internal. More...
 
bool select_prior ()
 Selects the prior row. Executes the callbacks. Internal. More...
 
bool select_next_page ()
 Selects the next page row. Executes the callbacks. Internal. More...
 
bool select_prior_page ()
 Selects the prior page row. Executes the callbacks. Internal. More...
 
- Protected Member Functions inherited from sptk::CControl
bool containsFocus () const
 Does the control contain focus?
 
void notifyFocus (bool gotFocus=true)
 Internal focus notification on focus change.
 
virtual void onEnter ()
 Internal focus notification on focus change.
 
virtual void onExit ()
 Internal focus notification on focus change. More...
 
uint32_t labelHeight () const
 Computes the label height based on the labelFont() and labelWidth()
 
int handle (int) override
 Special handle() method.
 
- Protected Member Functions inherited from sptk::CLayoutClient
int lastPreferredH () const
 
int lastPreferredW () const
 
void lastPreferredH (int height)
 
void lastPreferredW (int width)
 
- Static Protected Member Functions inherited from sptk::CListView
static void scrollbar_callback (Fl_Widget *s, void *)
 Internal vertical scrollback callback.
 
static void hscrollbar_callback (Fl_Widget *s, void *)
 Internal horizontal scrollback callback.
 
static void scrollbar_width (int b)
 Changes the default scrollbar width for the class. More...
 
static int scrollbar_width ()
 Returns the default scrollbar width for the class.
 
- Static Protected Member Functions inherited from sptk::CControl
static void internalCallback (Fl_Widget *internalWidget, void *data)
 Internal callback function.
 
- Protected Attributes inherited from sptk::CListView
bool m_capitalizeColumnNames {false}
 
bool m_multipleSelection {false}
 
int m_horizPosition {0}
 
int m_realHorizPosition {0}
 
int m_maxWidth {0}
 
int m_redraw1 {0}
 
int m_redraw2 {0}
 
uint32_t m_top {0}
 
int m_currentTextFont {0}
 
int m_currentTextSize {0}
 
Strings m_iconNames
 
CListViewDataMode m_dataMode {CListViewDataMode::LV_DATA_UNDEFINED}
 Data mode Defines the kind of data to work through data() method. More...
 
int m_mousePressedX {0}
 
CSelection m_selection
 
std::string m_searchPhrase
 
uint32_t m_activeRow {0}
 
uint32_t m_headerHeight {0}
 
CListViewRows m_rows
 
CColumnList m_columnList
 
int m_draggingColumn {0}
 
int m_draggingStarted {0}
 
Fl_Font m_textFont {0}
 
uchar m_textSize {0}
 
Fl_Color m_textColor {0}
 
bool m_showStripes {false}
 
bool m_showGrid {false}
 
bool m_showSelection {false}
 
bool m_autoRowHeight {false}
 
CScrollBar scrollbar {0, 0, 0, 0}
 Vertical scrollback.
 
CScrollBar hscrollbar {0, 0, 0, 0}
 Horizontal scrollbar.
 
- Protected Attributes inherited from sptk::CControl
bool m_limited {false}
 
uint32_t m_labelWidth {0}
 
Fl_Color m_labelColor
 
Fl_Color m_textColor
 
Fl_Font m_textFont
 
uchar m_textSize {0}
 
String m_fieldName
 
String m_hint
 
Fl_Widget * m_control {nullptr}
 
int m_tag {0}
 
uint32_t m_controlFlags {0}
 Control's special flags (a bit combination of InputEntryFlags). More...
 
Fl_Menu_Button * m_menuButton {nullptr}
 
CEventInfo m_event
 
bool m_hasFocus {false}
 
- Protected Attributes inherited from sptk::CLayoutClient
Fl_Widget * m_widget
 
String m_name
 
String m_label
 
CLayoutAlign m_layoutAlign
 
- Static Protected Attributes inherited from sptk::CListView
static int m_scrollbarWidth
 

Detailed Description

List view widget with extended database support.

Constructor & Destructor Documentation

◆ CDBListView()

sptk::CDBListView::CDBListView ( const char *  label = nullptr,
int  layoutSize = 20,
CLayoutAlign  layoutAlign = CLayoutAlign::TOP 
)

Constructor in SPTK style

Parameters
labelconst char *, label
layoutSizeint, widget align in layout
layoutAlignCLayoutAlign, widget align in layout

◆ ~CDBListView()

sptk::CDBListView::~CDBListView ( )
override

Destructor

Member Function Documentation

◆ creator()

static CLayoutClient * sptk::CDBListView::creator ( const xdoc::SNode &  node)
static

Creates a widget based on the XML node information.

Parameters
nodexml::Node*, an XML node with widget information

◆ database() [1/2]

PoolDatabaseConnection * sptk::CDBListView::database ( ) const

Returns the database connection

◆ database() [2/2]

void sptk::CDBListView::database ( PoolDatabaseConnection db)

Sets the database connection

◆ keyField() [1/2]

String sptk::CDBListView::keyField ( ) const
inline

Returns key field name

◆ keyField() [2/2]

void sptk::CDBListView::keyField ( const String fieldName)

Defines the key field name. This field name should be a part of the SQL query and contain the unique integer values so the row could be identified by that value.

Parameters
fieldNameThe name of the field

◆ lastRefresh()

DateTime sptk::CDBListView::lastRefresh ( ) const
inline

Returns the date and time of the last data refresh

◆ maxRecords() [1/2]

uint32_t sptk::CDBListView::maxRecords ( ) const
inline

Returns the maximum record number to fetch from the database

◆ maxRecords() [2/2]

void sptk::CDBListView::maxRecords ( uint32_t  mr)
inline

Sets the maximum record number to fetch from the database

◆ param()

QueryParameter & sptk::CDBListView::param ( const char *  paramName,
CRefreshKind  refreshKind = CRefreshKind::LV_REFRESH_FULL 
)

Sets the query parameter

Parameters
paramNameThe parameter Name
refreshKindThe query it belongs to (full or fast refresh)

◆ recordsLimited()

bool sptk::CDBListView::recordsLimited ( ) const
inline

Returns the records limited flag. The flag is set if the query returned more records than records limit.

◆ refreshData()

void sptk::CDBListView::refreshData ( CRefreshKind  refreshKind = CRefreshKind::LV_REFRESH_FULL)

Refreshes the data with full or fast method

Parameters
refreshKindCRefreshKind, the type of refresh

◆ setup()

void sptk::CDBListView::setup ( PoolDatabaseConnection db,
const String sql,
const String keyField 
)

Fast setup of the database connection

Parameters
dbThe database connection
sqlThe full refresh SQL query text
keyFieldTthe name of the key field

◆ sql() [1/2]

String sptk::CDBListView::sql ( )

Return the SQL query text

◆ sql() [2/2]

void sptk::CDBListView::sql ( const String sql,
const String recordCountSql = "",
const String fastRefreshSQL = "" 
)

Sets the SQL queries. Both full and fast refresh queries should return the same set of fields. The record count query should return only number of record.

Parameters
sqlThe SQL query for full data refresh
recordCountSqlThe SQL query for obtaining record count
fastRefreshSQLThe SQL query for retrieving only records changed since last refresh

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

Fri Oct 14 2022 09:58:35: SPTK 5.4.1