TreeWidgetBuilder< _ElementT > Struct Template Reference

A class to efficiently build and maintain sorted items of QTreeWidget or QTreeWidgetItem based on a sorted container matching the intended structure. More...

#include <RobotAPI/libraries/armem_gui/util/TreeWidgetBuilder.h>

Public Types

using CompareFn = std::function<int(const ElementT& element, QTreeWidgetItem* item)>
 Return < 0 if element < item, 0 if element == item, and > 0 if element > item.
 
using ElementT = _ElementT
 
using MakeItemFn = std::function<QTreeWidgetItem*(const ElementT& element)>
 
using NameFn = std::function<std::string(const ElementT& element)>
 
using UpdateItemFn = std::function<bool(const ElementT& element, QTreeWidgetItem* item)>
 

Public Member Functions

void setCompareFn (CompareFn compareFn)
 
void setExpand (bool expand)
 
void setMakeItemFn (MakeItemFn makeItemFn)
 
void setNameFn (NameFn nameFn, int nameColumn=0)
 
void setUpdateItemFn (UpdateItemFn updateItemFn)
 
 TreeWidgetBuilder ()=default
 
 TreeWidgetBuilder (CompareFn compareFn, MakeItemFn makeItemFn, UpdateItemFn updateItemFn=NoUpdate)
 
 TreeWidgetBuilder (const ElementT &)
 Constructor to automatically derive the template argument.
 
 TreeWidgetBuilder (NameFn nameFn, MakeItemFn makeItemFn, UpdateItemFn updateItemFn=NoUpdate, int nameColumn=0)
 
template<class ParentT, class ContainerT>
void updateTreeWithContainer (ParentT *parent, const ContainerT &elements)
 Update the tree with the iterable container.
 
template<class ParentT, class IteratorFn>
void updateTreeWithIterator (ParentT *parent, IteratorFn &&iteratorFn)
 Update the tree according to the elements iterated over by iteratorFn.
 

Static Public Member Functions

static CompareFn MakeCompareNameFn (NameFn nameFn, int nameColumn)
 Uses the name for comparison.
 
static bool NoUpdate (const ElementT &element, QTreeWidgetItem *item)
 No update function (default).
 

Detailed Description

template<class _ElementT>
struct armarx::TreeWidgetBuilder< _ElementT >

A class to efficiently build and maintain sorted items of QTreeWidget or QTreeWidgetItem based on a sorted container matching the intended structure.

Definition at line 19 of file TreeWidgetBuilder.h.

Member Typedef Documentation

◆ CompareFn

template<class _ElementT>
using CompareFn = std::function<int(const ElementT& element, QTreeWidgetItem* item)>

Return < 0 if element < item, 0 if element == item, and > 0 if element > item.

Definition at line 24 of file TreeWidgetBuilder.h.

◆ ElementT

template<class _ElementT>
using ElementT = _ElementT

Definition at line 21 of file TreeWidgetBuilder.h.

◆ MakeItemFn

template<class _ElementT>
using MakeItemFn = std::function<QTreeWidgetItem*(const ElementT& element)>

Definition at line 26 of file TreeWidgetBuilder.h.

◆ NameFn

template<class _ElementT>
using NameFn = std::function<std::string(const ElementT& element)>

Definition at line 25 of file TreeWidgetBuilder.h.

◆ UpdateItemFn

template<class _ElementT>
using UpdateItemFn = std::function<bool(const ElementT& element, QTreeWidgetItem* item)>

Definition at line 27 of file TreeWidgetBuilder.h.

Constructor & Destructor Documentation

◆ TreeWidgetBuilder() [1/4]

template<class _ElementT>
TreeWidgetBuilder ( )
default

◆ TreeWidgetBuilder() [2/4]

template<class _ElementT>
TreeWidgetBuilder ( const ElementT & )
inline

Constructor to automatically derive the template argument.

Definition at line 33 of file TreeWidgetBuilder.h.

◆ TreeWidgetBuilder() [3/4]

template<class _ElementT>
TreeWidgetBuilder ( CompareFn compareFn,
MakeItemFn makeItemFn,
UpdateItemFn updateItemFn = NoUpdate )
inline

Definition at line 37 of file TreeWidgetBuilder.h.

◆ TreeWidgetBuilder() [4/4]

template<class _ElementT>
TreeWidgetBuilder ( NameFn nameFn,
MakeItemFn makeItemFn,
UpdateItemFn updateItemFn = NoUpdate,
int nameColumn = 0 )
inline

Definition at line 44 of file TreeWidgetBuilder.h.

Member Function Documentation

◆ MakeCompareNameFn()

template<class ElementT>
auto MakeCompareNameFn ( NameFn nameFn,
int nameColumn )
static

Uses the name for comparison.

Definition at line 346 of file TreeWidgetBuilder.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NoUpdate()

template<class _ElementT>
static bool NoUpdate ( const ElementT & element,
QTreeWidgetItem * item )
inlinestatic

No update function (default).

Definition at line 113 of file TreeWidgetBuilder.h.

◆ setCompareFn()

template<class _ElementT>
void setCompareFn ( CompareFn compareFn)
inline

Definition at line 55 of file TreeWidgetBuilder.h.

+ Here is the caller graph for this function:

◆ setExpand()

template<class _ElementT>
void setExpand ( bool expand)
inline

Definition at line 79 of file TreeWidgetBuilder.h.

◆ setMakeItemFn()

template<class _ElementT>
void setMakeItemFn ( MakeItemFn makeItemFn)
inline

Definition at line 67 of file TreeWidgetBuilder.h.

+ Here is the caller graph for this function:

◆ setNameFn()

template<class _ElementT>
void setNameFn ( NameFn nameFn,
int nameColumn = 0 )
inline

Definition at line 61 of file TreeWidgetBuilder.h.

+ Here is the caller graph for this function:

◆ setUpdateItemFn()

template<class _ElementT>
void setUpdateItemFn ( UpdateItemFn updateItemFn)
inline

Definition at line 73 of file TreeWidgetBuilder.h.

+ Here is the caller graph for this function:

◆ updateTreeWithContainer()

template<class ElementT>
template<class ParentT, class ContainerT>
void updateTreeWithContainer ( ParentT * parent,
const ContainerT & elements )

Update the tree with the iterable container.

Parameters
parentThe parent, i.e. the tree widget or a tree widget item.
iteratorFnFunction taking a function bool fn(const ElementT& element) and calling it for each element in the underlying container, i.e. like: void iteratorFn(bool (*elementFn)(const ElementT& element));

Definition at line 355 of file TreeWidgetBuilder.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateTreeWithIterator()

template<class ElementT>
template<class ParentT, class IteratorFn>
void updateTreeWithIterator ( ParentT * parent,
IteratorFn && iteratorFn )

Update the tree according to the elements iterated over by iteratorFn.

Parameters
parentThe parent, i.e. the tree widget or a tree widget item.
iteratorFnFunction taking a function bool fn(const ElementT& element) and calling it for each element in the underlying container, i.e. like: void iteratorFn(bool (*elementFn)(const ElementT& element));

Definition at line 374 of file TreeWidgetBuilder.h.

+ Here is the caller graph for this function:

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