walberla::gui::PropertyTree Class Referenceabstract

Detailed Description

Interface for providing Key-Value pairs for Qt Tree/List Views.

Usage:

#include <PropertyTree.h>

Public Types

using ItemID = void *
 

Public Member Functions

 PropertyTree ()
 
virtual ~PropertyTree ()
 
void setBlock (IBlock *b)
 Updates Model, using given block. More...
 
QStandardItemModelgetModel ()
 Retrieves the Qt Model Data structure. More...
 
virtual const std::string getName ()=0
 Returns name/type of data of this model. More...
 
virtual shared_ptr< PropertyTreecreate () const =0
 Virtual constructor. More...
 

Protected Member Functions

virtual void fillTree (IBlock *b)=0
 Method to fill the tree. More...
 
virtual void clear ()=0
 Removes all data from the Property Tree. More...
 
template<typename T >
ItemID addItem (const std::string &name, const T &val, ItemID parent=nullptr)
 Adds property value pair to the tree. More...
 
ItemID addItem (const std::string &name, ItemID parent=nullptr)
 Convenience method, behaves like addItem above with no value -> empty second column. More...
 
template<typename T >
void modifyItem (const std::string &name, const T &val, ItemID id)
 Changes an existing item. More...
 
template<typename T >
void modifyItem (const T &val, ItemID id)
 Convenience method, behaves like modifyItem(string,T,ItemID) but does not change the first column. More...
 
void removeItem (ItemID id)
 Removes an item from the tree. More...
 

Private Attributes

QStandardItemModelmodel_
 
IBlocklastBlock_
 

Member Typedef Documentation

◆ ItemID

Constructor & Destructor Documentation

◆ PropertyTree()

walberla::gui::PropertyTree::PropertyTree ( )

◆ ~PropertyTree()

walberla::gui::PropertyTree::~PropertyTree ( )
virtualdefault

Member Function Documentation

◆ addItem() [1/2]

template<typename T >
PropertyTree::ItemID walberla::gui::PropertyTree::addItem ( const std::string &  name,
const T &  val,
ItemID  parent = nullptr 
)
protected

Adds property value pair to the tree.

Parameters
namethe string that appears in the first column of the treeView
valvalue that appears in the second column T can be every type that QString.arg() accepts i.e. all native data types and std::string;
parentkey-value pairs can be organized hierarchically, here an ItemID of another item can be specified, which is used as parent
Returns
identifier for this item which can be used to modify/remove this item or to add children

◆ addItem() [2/2]

PropertyTree::ItemID walberla::gui::PropertyTree::addItem ( const std::string &  name,
ItemID  parent = nullptr 
)
protected

Convenience method, behaves like addItem above with no value -> empty second column.

◆ clear()

virtual void walberla::gui::PropertyTree::clear ( )
protectedpure virtual

Removes all data from the Property Tree.

This method should restore the object to its initial state i.e. delete all stored data, usually the ItemID's see also fillTree()

◆ create()

virtual shared_ptr<PropertyTree> walberla::gui::PropertyTree::create ( ) const
pure virtual

Virtual constructor.

a new object has to be instantiated for each opened treeView that displays this model In the implementation just return "make_shared<YourDerivedClass>()"

◆ fillTree()

virtual void walberla::gui::PropertyTree::fillTree ( IBlock b)
protectedpure virtual

Method to fill the tree.

This method is called whenever the data in the block may have changed or the block itself has changed. The first time fillTree is called add your display data using addItem and store the ItemIDs. On the next call, change the value of the items using modifyItem If the block is not the same as on the last call, clear() is called between the two fillTree invocations. In the clear method the saved ItemID's can be deleted

◆ getModel()

QStandardItemModel* walberla::gui::PropertyTree::getModel ( )
inline

Retrieves the Qt Model Data structure.

used by gui, do not change in subclass

◆ getName()

virtual const std::string walberla::gui::PropertyTree::getName ( )
pure virtual

Returns name/type of data of this model.

When multiple PropertyTrees have been registered the user can choose which data to display using this name

◆ modifyItem() [1/2]

template<typename T >
void walberla::gui::PropertyTree::modifyItem ( const std::string &  name,
const T &  val,
ItemID  id 
)
protected

Changes an existing item.

Store the ItemID's between fillTree calls, to modify items instead of clearing and new adding, since otherwise the TreeView is reset after each timestep and expansion states etc. are lost

Parameters
namenew first column string for the item
valnew value for second column
idid returned by addItem to specify which item is modified

◆ modifyItem() [2/2]

template<typename T >
void walberla::gui::PropertyTree::modifyItem ( const T &  val,
ItemID  id 
)
protected

Convenience method, behaves like modifyItem(string,T,ItemID) but does not change the first column.

◆ removeItem()

void walberla::gui::PropertyTree::removeItem ( ItemID  id)
protected

Removes an item from the tree.

To remove all items, call clear() instead of this method

Parameters
iditem to remove

◆ setBlock()

void walberla::gui::PropertyTree::setBlock ( IBlock b)

Updates Model, using given block.

This method is called by gui when a different block should be displayed, or the data inside a block has changed. Should not be changed by subclasses

Member Data Documentation

◆ lastBlock_

IBlock* walberla::gui::PropertyTree::lastBlock_
private

◆ model_

QStandardItemModel* walberla::gui::PropertyTree::model_
private

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