JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::TreeViewItem Class Referenceabstract

An item in a treeview. More...

#include <juce_Doxygen_notes.h>

Collaboration diagram for juce::TreeViewItem:

Classes

class  OpennessRestorer
 This handy class takes a copy of a TreeViewItem's openness when you create it, and restores that openness state when its destructor is called. More...
 

Public Types

enum  Openness {
  opennessDefault = 0,
  opennessClosed = 1,
  opennessOpen = 2
}
 An enum of states to describe the explicit or implicit openness of an item. More...
 

Public Member Functions

 TreeViewItem ()
 Constructor. More...
 
virtual ~TreeViewItem ()
 Destructor. More...
 
void addSubItem (TreeViewItem *newItem, int insertPosition=-1)
 Adds a sub-item. More...
 
template<class ElementComparator >
void addSubItemSorted (ElementComparator &comparator, TreeViewItem *newItem)
 Adds a sub-item with a sort-comparator, assuming that the existing items are already sorted. More...
 
bool areAllParentsOpen () const noexcept
 Returns true if all the item's parent nodes are open. More...
 
virtual bool canBeSelected () const
 You can override this method to return false if you don't want to allow the user to select this item. More...
 
void clearSubItems ()
 Removes any sub-items. More...
 
virtual ComponentcreateItemComponent ()
 Creates a component that will be used to represent this item. More...
 
virtual void filesDropped (const StringArray &files, int insertIndex)
 When files are dropped into this item, this callback is invoked. More...
 
virtual var getDragSourceDescription ()
 To allow items from your treeview to be dragged-and-dropped, implement this method. More...
 
int getIndexInParent () const noexcept
 Returns the index of this item in its parent's sub-items. More...
 
virtual int getItemHeight () const
 Must return the height required by this item. More...
 
String getItemIdentifierString () const
 Creates a string that can be used to uniquely retrieve this item in the tree. More...
 
Rectangle< intgetItemPosition (bool relativeToTreeViewTopLeft) const noexcept
 Returns the rectangle that this item occupies. More...
 
virtual int getItemWidth () const
 Must return the width required by this item. More...
 
int getNumSubItems () const noexcept
 Returns the number of sub-items that have been added to this item. More...
 
Openness getOpenness () const noexcept
 Returns the openness state of this item. More...
 
XmlElementgetOpennessState () const
 Saves the current state of open/closed nodes so it can be restored later. More...
 
TreeViewgetOwnerView () const noexcept
 Returns the TreeView to which this item belongs. More...
 
TreeViewItemgetParentItem () const noexcept
 Returns the item within which this item is contained. More...
 
int getRowNumberInTree () const noexcept
 Returns the row number of this item in the tree. More...
 
TreeViewItemgetSubItem (int index) const noexcept
 Returns one of the item's sub-items. More...
 
virtual String getTooltip ()
 The item can return a tool tip string here if it wants to. More...
 
virtual String getUniqueName () const
 Returns a string to uniquely identify this item. More...
 
virtual bool isInterestedInDragSource (const DragAndDropTarget::SourceDetails &dragSourceDetails)
 If you want your item to act as a DragAndDropTarget, implement this method and return true. More...
 
virtual bool isInterestedInFileDrag (const StringArray &files)
 If you want your item to be able to have files drag-and-dropped onto it, implement this method and return true. More...
 
bool isLastOfSiblings () const noexcept
 Returns true if this item is the last of its parent's sub-itens. More...
 
bool isOpen () const noexcept
 True if this item is currently open in the treeview. More...
 
bool isSelected () const noexcept
 True if this item is currently selected. More...
 
virtual void itemClicked (const MouseEvent &)
 Called when the user clicks on this item. More...
 
virtual void itemDoubleClicked (const MouseEvent &)
 Called when the user double-clicks on this item. More...
 
virtual void itemDropped (const DragAndDropTarget::SourceDetails &dragSourceDetails, int insertIndex)
 When a things are dropped into this item, this callback is invoked. More...
 
virtual void itemOpennessChanged (bool isNowOpen)
 Called when an item is opened or closed. More...
 
virtual void itemSelectionChanged (bool isNowSelected)
 Called when the item is selected or deselected. More...
 
virtual bool mightContainSubItems ()=0
 Tells the tree whether this item can potentially be opened. More...
 
virtual void ownerViewChanged (TreeView *newOwner)
 Called when the owner view changes. More...
 
virtual void paintHorizontalConnectingLine (Graphics &, const Line< float > &line)
 Draws the line that connects this item to the vertical line extending below its parent. More...
 
virtual void paintItem (Graphics &g, int width, int height)
 Draws the item's contents. More...
 
virtual void paintOpenCloseButton (Graphics &, const Rectangle< float > &area, Colour backgroundColour, bool isMouseOver)
 Draws the item's open/close button. More...
 
virtual void paintVerticalConnectingLine (Graphics &, const Line< float > &line)
 Draws the line that extends vertically up towards one of its parents, or down to one of its children. More...
 
void removeSubItem (int index, bool deleteItem=true)
 Removes one of the sub-items. More...
 
void repaintItem () const
 Sends a repaint message to redraw just this item. More...
 
void restoreOpennessState (const XmlElement &xml)
 Restores the openness of this item and all its sub-items from a saved state. More...
 
void setDrawsInLeftMargin (bool canDrawInLeftMargin) noexcept
 Sets a flag to indicate that the item wants to be allowed to draw all the way across to the left edge of the treeview. More...
 
void setDrawsInRightMargin (bool canDrawInRightMargin) noexcept
 Sets a flag to indicate that the item wants to be allowed to draw all the way across to the right edge of the treeview. More...
 
void setLinesDrawnForSubItems (bool shouldDrawLines) noexcept
 Changes whether lines are drawn to connect any sub-items to this item. More...
 
void setOpen (bool shouldBeOpen)
 Opens or closes the item. More...
 
void setOpenness (Openness newOpenness)
 Opens or closes the item. More...
 
void setSelected (bool shouldBeSelected, bool deselectOtherItemsFirst, NotificationType shouldNotify=sendNotification)
 Selects or deselects the item. More...
 
template<class ElementComparator >
void sortSubItems (ElementComparator &comparator)
 Sorts the list of sub-items using a standard array comparator. More...
 
void treeHasChanged () const noexcept
 Sends a signal to the treeview to make it refresh itself. More...
 

Private Member Functions

bool areLinesDrawn () const
 
int countSelectedItemsRecursively (int depth) const noexcept
 
void deselectAllRecursively (TreeViewItem *itemToIgnore)
 
TreeViewItemfindItemFromIdentifierString (const String &)
 
TreeViewItemfindItemRecursively (int y) noexcept
 
TreeViewItemgetDeepestOpenParentItem () noexcept
 
int getIndentX () const noexcept
 
TreeViewItemgetItemOnRow (int index) noexcept
 
TreeViewItemgetNextVisibleItem (bool recurse) const noexcept
 
int getNumRows () const noexcept
 
XmlElementgetOpennessState (bool canReturnNull) const
 
TreeViewItemgetSelectedItemWithIndex (int index) noexcept
 
TreeViewItemgetTopLevelItem () noexcept
 
bool isFullyOpen () const noexcept
 
void paintRecursively (Graphics &, int width)
 
void removeAllSubItemsFromList ()
 
bool removeSubItemFromList (int index, bool deleteItem)
 
void restoreToDefaultOpenness ()
 
void setOwnerView (TreeView *) noexcept
 
void updatePositions (int newY)
 

Private Attributes

bool drawLinesInside: 1
 
bool drawLinesSet: 1
 
bool drawsInLeftMargin: 1
 
bool drawsInRightMargin: 1
 
int itemHeight = 0
 
int itemWidth = 0
 
unsigned int openness: 2
 
TreeViewownerView = nullptr
 
TreeViewItemparentItem = nullptr
 
bool redrawNeeded: 1
 
bool selected: 1
 
OwnedArray< TreeViewItemsubItems
 
int totalHeight = 0
 
int totalWidth = 0
 
int uid = 0
 
int y = 0
 

Friends

class TreeView
 

Detailed Description

An item in a treeview.

A TreeViewItem can either be a leaf-node in the tree, or it can contain its own sub-items.

To implement an item that contains sub-items, override the itemOpennessChanged() method so that when it is opened, it adds the new sub-items to itself using the addSubItem method. Depending on the nature of the item it might choose to only do this the first time it's opened, or it might want to refresh itself each time. It also has the option of deleting its sub-items when it is closed, or leaving them in place.

{GUI}

TreeView.png
Example of a juce::DocumentWindow with a juce::TreeView component and several objects that inherit from juce::TreeViewItem.

Member Enumeration Documentation

◆ Openness

An enum of states to describe the explicit or implicit openness of an item.

Enumerator
opennessDefault 
opennessClosed 
opennessOpen 

Constructor & Destructor Documentation

◆ TreeViewItem()

juce::TreeViewItem::TreeViewItem ( )

Constructor.

◆ ~TreeViewItem()

virtual juce::TreeViewItem::~TreeViewItem ( )
virtual

Destructor.

Member Function Documentation

◆ addSubItem()

void juce::TreeViewItem::addSubItem ( TreeViewItem newItem,
int  insertPosition = -1 
)

Adds a sub-item.

Parameters
newItemthe object to add to the item's sub-item list. Once added, these can be found using getSubItem(). When the items are later removed with removeSubItem() (or when this item is deleted), they will be deleted.
insertPositionthe index which the new item should have when it's added. If this value is less than 0, the item will be added to the end of the list.

◆ addSubItemSorted()

template<class ElementComparator >
void juce::TreeViewItem::addSubItemSorted ( ElementComparator &  comparator,
TreeViewItem newItem 
)
inline

Adds a sub-item with a sort-comparator, assuming that the existing items are already sorted.

Parameters
comparatorthe comparator object for sorting - see sortSubItems() for details about the methods this class must provide.
newItemthe object to add to the item's sub-item list. Once added, these can be found using getSubItem(). When the items are later removed with removeSubItem() (or when this item is deleted), they will be deleted.

References juce::findInsertIndexInSortedArray().

◆ areAllParentsOpen()

bool juce::TreeViewItem::areAllParentsOpen ( ) const
noexcept

Returns true if all the item's parent nodes are open.

This is useful to check whether the item might actually be visible or not.

◆ areLinesDrawn()

bool juce::TreeViewItem::areLinesDrawn ( ) const
private

◆ canBeSelected()

virtual bool juce::TreeViewItem::canBeSelected ( ) const
inlinevirtual

You can override this method to return false if you don't want to allow the user to select this item.

◆ clearSubItems()

void juce::TreeViewItem::clearSubItems ( )

Removes any sub-items.

◆ countSelectedItemsRecursively()

int juce::TreeViewItem::countSelectedItemsRecursively ( int  depth) const
privatenoexcept

◆ createItemComponent()

virtual Component* juce::TreeViewItem::createItemComponent ( )
inlinevirtual

Creates a component that will be used to represent this item.

You don't have to implement this method - if it returns nullptr then no component will be used for the item, and you can just draw it using the paintItem() callback. But if you do return a component, it will be positioned in the treeview so that it can be used to represent this item.

The component returned will be managed by the treeview, so always return a new component, and don't keep a reference to it, as the treeview will delete it later when it goes off the screen or is no longer needed. Also bear in mind that if the component keeps a reference to the item that created it, that item could be deleted before the component. Its position and size will be completely managed by the tree, so don't attempt to move it around.

Something you may want to do with your component is to give it a pointer to the TreeView that created it. This is perfectly safe, and there's no danger of it becoming a dangling pointer because the TreeView will always delete the component before it is itself deleted.

As long as you stick to these rules you can return whatever kind of component you like. It's most useful if you're doing things like drag-and-drop of items, or want to use a Label component to edit item names, etc.

◆ deselectAllRecursively()

void juce::TreeViewItem::deselectAllRecursively ( TreeViewItem itemToIgnore)
private

◆ filesDropped()

virtual void juce::TreeViewItem::filesDropped ( const StringArray files,
int  insertIndex 
)
virtual

When files are dropped into this item, this callback is invoked.

For this to work, you'll need to have also implemented isInterestedInFileDrag(). The insertIndex value indicates where in the list of sub-items the files were dropped. If files are dropped onto an area of the tree where there are no visible items, this method is called on the root item of the tree, with an insert index of 0.

See also
FileDragAndDropTarget::filesDropped, isInterestedInFileDrag

◆ findItemFromIdentifierString()

TreeViewItem* juce::TreeViewItem::findItemFromIdentifierString ( const String )
private

◆ findItemRecursively()

TreeViewItem* juce::TreeViewItem::findItemRecursively ( int  y)
privatenoexcept

◆ getDeepestOpenParentItem()

TreeViewItem* juce::TreeViewItem::getDeepestOpenParentItem ( )
privatenoexcept

◆ getDragSourceDescription()

virtual var juce::TreeViewItem::getDragSourceDescription ( )
virtual

To allow items from your treeview to be dragged-and-dropped, implement this method.

If this returns a non-null variant then when the user drags an item, the treeview will try to find a DragAndDropContainer in its parent hierarchy, and will use it to trigger a drag-and-drop operation, using this string as the source description, with the treeview itself as the source component.

If you need more complex drag-and-drop behaviour, you can use custom components for the items, and use those to trigger the drag.

To accept drag-and-drop in your tree, see isInterestedInDragSource(), isInterestedInFileDrag(), etc.

See also
DragAndDropContainer::startDragging

◆ getIndentX()

int juce::TreeViewItem::getIndentX ( ) const
privatenoexcept

◆ getIndexInParent()

int juce::TreeViewItem::getIndexInParent ( ) const
noexcept

Returns the index of this item in its parent's sub-items.

◆ getItemHeight()

virtual int juce::TreeViewItem::getItemHeight ( ) const
inlinevirtual

Must return the height required by this item.

This is the height in pixels that the item will take up. Items in the tree can be different heights, but if they change height, you should call treeHasChanged() to update the tree.

◆ getItemIdentifierString()

String juce::TreeViewItem::getItemIdentifierString ( ) const

Creates a string that can be used to uniquely retrieve this item in the tree.

The string that is returned can be passed to TreeView::findItemFromIdentifierString(). The string takes the form of a path, constructed from the getUniqueName() of this item and all its parents, so these must all be correctly implemented for it to work.

See also
TreeView::findItemFromIdentifierString, getUniqueName

◆ getItemOnRow()

TreeViewItem* juce::TreeViewItem::getItemOnRow ( int  index)
privatenoexcept

◆ getItemPosition()

Rectangle<int> juce::TreeViewItem::getItemPosition ( bool  relativeToTreeViewTopLeft) const
noexcept

Returns the rectangle that this item occupies.

If relativeToTreeViewTopLeft is true, the coordinates are relative to the top-left of the TreeView comp, so this will depend on the scroll-position of the tree. If false, it is relative to the top-left of the topmost item in the tree (so this would be unaffected by scrolling the view).

◆ getItemWidth()

virtual int juce::TreeViewItem::getItemWidth ( ) const
inlinevirtual

Must return the width required by this item.

If your item needs to have a particular width in pixels, return that value; if you'd rather have it just fill whatever space is available in the treeview, return -1.

If all your items return -1, no horizontal scrollbar will be shown, but if any items have fixed widths and extend beyond the width of the treeview, a scrollbar will appear.

Each item can be a different width, but if they change width, you should call treeHasChanged() to update the tree.

◆ getNextVisibleItem()

TreeViewItem* juce::TreeViewItem::getNextVisibleItem ( bool  recurse) const
privatenoexcept

◆ getNumRows()

int juce::TreeViewItem::getNumRows ( ) const
privatenoexcept

◆ getNumSubItems()

int juce::TreeViewItem::getNumSubItems ( ) const
noexcept

Returns the number of sub-items that have been added to this item.

Note that this doesn't mean much if the node isn't open.

See also
getSubItem, mightContainSubItems, addSubItem

◆ getOpenness()

Openness juce::TreeViewItem::getOpenness ( ) const
noexcept

Returns the openness state of this item.

See also
isOpen

◆ getOpennessState() [1/2]

XmlElement* juce::TreeViewItem::getOpennessState ( ) const

Saves the current state of open/closed nodes so it can be restored later.

This takes a snapshot of which sub-nodes have been explicitly opened or closed, and records it as XML. To identify node objects it uses the TreeViewItem::getUniqueName() method to create named paths. This means that the same state of open/closed nodes can be restored to a completely different instance of the tree, as long as it contains nodes whose unique names are the same.

You'd normally want to use TreeView::getOpennessState() rather than call it for a specific item, but this can be handy if you need to briefly save the state for a section of the tree.

The caller is responsible for deleting the object that is returned.

Note that if all nodes of the tree are in their default state, then this may return a nullptr.

See also
TreeView::getOpennessState, restoreOpennessState

◆ getOpennessState() [2/2]

XmlElement* juce::TreeViewItem::getOpennessState ( bool  canReturnNull) const
private

◆ getOwnerView()

TreeView* juce::TreeViewItem::getOwnerView ( ) const
inlinenoexcept

Returns the TreeView to which this item belongs.

◆ getParentItem()

TreeViewItem* juce::TreeViewItem::getParentItem ( ) const
inlinenoexcept

Returns the item within which this item is contained.

◆ getRowNumberInTree()

int juce::TreeViewItem::getRowNumberInTree ( ) const
noexcept

Returns the row number of this item in the tree.

The row number of an item will change according to which items are open.

See also
TreeView::getNumRowsInTree(), TreeView::getItemOnRow()

◆ getSelectedItemWithIndex()

TreeViewItem* juce::TreeViewItem::getSelectedItemWithIndex ( int  index)
privatenoexcept

◆ getSubItem()

TreeViewItem* juce::TreeViewItem::getSubItem ( int  index) const
noexcept

Returns one of the item's sub-items.

Remember that the object returned might get deleted at any time when its parent item is closed or refreshed, depending on the nature of the items you're using.

See also
getNumSubItems

◆ getTooltip()

virtual String juce::TreeViewItem::getTooltip ( )
virtual

The item can return a tool tip string here if it wants to.

See also
TooltipClient

◆ getTopLevelItem()

TreeViewItem* juce::TreeViewItem::getTopLevelItem ( )
privatenoexcept

◆ getUniqueName()

virtual String juce::TreeViewItem::getUniqueName ( ) const
virtual

Returns a string to uniquely identify this item.

If you're planning on using the TreeView::getOpennessState() method, then these strings will be used to identify which nodes are open. The string should be unique amongst the item's sibling items, but it's ok for there to be duplicates at other levels of the tree.

If you're not going to store the state, then it's ok not to bother implementing this method.

◆ isFullyOpen()

bool juce::TreeViewItem::isFullyOpen ( ) const
privatenoexcept

◆ isInterestedInDragSource()

virtual bool juce::TreeViewItem::isInterestedInDragSource ( const DragAndDropTarget::SourceDetails dragSourceDetails)
virtual

If you want your item to act as a DragAndDropTarget, implement this method and return true.

If you implement this method, you'll also need to implement itemDropped() in order to handle the items when they are dropped. To respond to drag-and-drop of files from external applications, see isInterestedInFileDrag().

See also
DragAndDropTarget::isInterestedInDragSource, itemDropped

◆ isInterestedInFileDrag()

virtual bool juce::TreeViewItem::isInterestedInFileDrag ( const StringArray files)
virtual

If you want your item to be able to have files drag-and-dropped onto it, implement this method and return true.

If you return true and allow some files to be dropped, you'll also need to implement the filesDropped() method to do something with them.

Note that this will be called often, so make your implementation very quick! There's certainly no time to try opening the files and having a think about what's inside them!

For responding to internal drag-and-drop of other types of object, see isInterestedInDragSource().

See also
FileDragAndDropTarget::isInterestedInFileDrag, isInterestedInDragSource

◆ isLastOfSiblings()

bool juce::TreeViewItem::isLastOfSiblings ( ) const
noexcept

Returns true if this item is the last of its parent's sub-itens.

◆ isOpen()

bool juce::TreeViewItem::isOpen ( ) const
noexcept

True if this item is currently open in the treeview.

See also
getOpenness

◆ isSelected()

bool juce::TreeViewItem::isSelected ( ) const
noexcept

True if this item is currently selected.

Use this when painting the node, to decide whether to draw it as selected or not.

◆ itemClicked()

virtual void juce::TreeViewItem::itemClicked ( const MouseEvent )
virtual

Called when the user clicks on this item.

If you're using createItemComponent() to create a custom component for the item, the mouse-clicks might not make it through to the treeview, but this is how you find out about clicks when just drawing each item individually.

The associated mouse-event details are passed in, so you can find out about which button, where it was, etc.

See also
itemDoubleClicked

◆ itemDoubleClicked()

virtual void juce::TreeViewItem::itemDoubleClicked ( const MouseEvent )
virtual

Called when the user double-clicks on this item.

If you're using createItemComponent() to create a custom component for the item, the mouse-clicks might not make it through to the treeview, but this is how you find out about clicks when just drawing each item individually.

The associated mouse-event details are passed in, so you can find out about which button, where it was, etc.

If not overridden, the base class method here will open or close the item as if the 'plus' button had been clicked.

See also
itemClicked

◆ itemDropped()

virtual void juce::TreeViewItem::itemDropped ( const DragAndDropTarget::SourceDetails dragSourceDetails,
int  insertIndex 
)
virtual

When a things are dropped into this item, this callback is invoked.

For this to work, you need to have also implemented isInterestedInDragSource(). The insertIndex value indicates where in the list of sub-items the new items should be placed. If files are dropped onto an area of the tree where there are no visible items, this method is called on the root item of the tree, with an insert index of 0.

See also
isInterestedInDragSource, DragAndDropTarget::itemDropped

◆ itemOpennessChanged()

virtual void juce::TreeViewItem::itemOpennessChanged ( bool  isNowOpen)
virtual

Called when an item is opened or closed.

When setOpen() is called and the item has specified that it might have sub-items with the mightContainSubItems() method, this method is called to let the item create or manage its sub-items.

So when this is called with isNowOpen set to true (i.e. when the item is being opened), a subclass might choose to use clearSubItems() and addSubItem() to refresh its sub-item list.

When this is called with isNowOpen set to false, the subclass might want to use clearSubItems() to save on space, or it might choose to leave them, depending on the nature of the tree.

You could also use this callback as a trigger to start a background process which asynchronously creates sub-items and adds them, if that's more appropriate for the task in hand.

See also
mightContainSubItems

◆ itemSelectionChanged()

virtual void juce::TreeViewItem::itemSelectionChanged ( bool  isNowSelected)
virtual

Called when the item is selected or deselected.

Use this if you want to do something special when the item's selectedness changes. By default it'll get repainted when this happens.

◆ mightContainSubItems()

virtual bool juce::TreeViewItem::mightContainSubItems ( )
pure virtual

Tells the tree whether this item can potentially be opened.

If your item could contain sub-items, this should return true; if it returns false then the tree will not try to open the item. This determines whether or not the item will be drawn with a 'plus' button next to it.

◆ ownerViewChanged()

virtual void juce::TreeViewItem::ownerViewChanged ( TreeView newOwner)
virtual

Called when the owner view changes.

◆ paintHorizontalConnectingLine()

virtual void juce::TreeViewItem::paintHorizontalConnectingLine ( Graphics ,
const Line< float > &  line 
)
virtual

Draws the line that connects this item to the vertical line extending below its parent.

◆ paintItem()

virtual void juce::TreeViewItem::paintItem ( Graphics g,
int  width,
int  height 
)
virtual

Draws the item's contents.

You can choose to either implement this method and draw each item, or you can use createItemComponent() to create a component that will represent the item.

If all you need in your tree is to be able to draw the items and detect when the user selects or double-clicks one of them, it's probably enough to use paintItem(), itemClicked() and itemDoubleClicked(). If you need more complicated interactions, you may need to use createItemComponent() instead.

Parameters
gthe graphics context to draw into
widththe width of the area available for drawing
heightthe height of the area available for drawing

◆ paintOpenCloseButton()

virtual void juce::TreeViewItem::paintOpenCloseButton ( Graphics ,
const Rectangle< float > &  area,
Colour  backgroundColour,
bool  isMouseOver 
)
virtual

Draws the item's open/close button.

If you don't implement this method, the default behaviour is to call LookAndFeel::drawTreeviewPlusMinusBox(), but you can override it for custom effects. You may want to override it and call the base-class implementation with a different backgroundColour parameter, if your implementation has a background colour other than the default (white).

◆ paintRecursively()

void juce::TreeViewItem::paintRecursively ( Graphics ,
int  width 
)
private

◆ paintVerticalConnectingLine()

virtual void juce::TreeViewItem::paintVerticalConnectingLine ( Graphics ,
const Line< float > &  line 
)
virtual

Draws the line that extends vertically up towards one of its parents, or down to one of its children.

◆ removeAllSubItemsFromList()

void juce::TreeViewItem::removeAllSubItemsFromList ( )
private

◆ removeSubItem()

void juce::TreeViewItem::removeSubItem ( int  index,
bool  deleteItem = true 
)

Removes one of the sub-items.

Parameters
indexthe item to remove
deleteItemif true, the item that is removed will also be deleted.

◆ removeSubItemFromList()

bool juce::TreeViewItem::removeSubItemFromList ( int  index,
bool  deleteItem 
)
private

◆ repaintItem()

void juce::TreeViewItem::repaintItem ( ) const

Sends a repaint message to redraw just this item.

Note that you should only call this if you want to repaint a superficial change. If you're altering the tree's nodes, you should instead call treeHasChanged().

◆ restoreOpennessState()

void juce::TreeViewItem::restoreOpennessState ( const XmlElement xml)

Restores the openness of this item and all its sub-items from a saved state.

See TreeView::restoreOpennessState for more details.

You'd normally want to use TreeView::restoreOpennessState() rather than call it for a specific item, but this can be handy if you need to briefly save the state for a section of the tree.

See also
TreeView::restoreOpennessState, getOpennessState

◆ restoreToDefaultOpenness()

void juce::TreeViewItem::restoreToDefaultOpenness ( )
private

◆ setDrawsInLeftMargin()

void juce::TreeViewItem::setDrawsInLeftMargin ( bool  canDrawInLeftMargin)
noexcept

Sets a flag to indicate that the item wants to be allowed to draw all the way across to the left edge of the treeview.

By default this is false, which means that when the paintItem() method is called, its graphics context is clipped to only allow drawing within the item's rectangle. If this flag is set to true, then the graphics context isn't clipped on its left side, so it can draw all the way across to the left margin. Note that the context will still have its origin in the same place though, so the coordinates of anything to its left will be negative. It's mostly useful if you want to draw a wider bar behind the highlighted item.

◆ setDrawsInRightMargin()

void juce::TreeViewItem::setDrawsInRightMargin ( bool  canDrawInRightMargin)
noexcept

Sets a flag to indicate that the item wants to be allowed to draw all the way across to the right edge of the treeview.

Similar to setDrawsInLeftMargin: when this flag is set to true, then the graphics context isn't clipped on the right side. Unlike setDrawsInLeftMargin, you will very rarely need to use this function, as this method won't clip the right margin unless your TreeViewItem overrides getItemWidth to return a positive value.

See also
setDrawsInLeftMargin, getItemWidth

◆ setLinesDrawnForSubItems()

void juce::TreeViewItem::setLinesDrawnForSubItems ( bool  shouldDrawLines)
noexcept

Changes whether lines are drawn to connect any sub-items to this item.

By default, line-drawing is turned on according to LookAndFeel::areLinesDrawnForTreeView().

◆ setOpen()

void juce::TreeViewItem::setOpen ( bool  shouldBeOpen)

Opens or closes the item.

When opened or closed, the item's itemOpennessChanged() method will be called, and a subclass should use this callback to create and add any sub-items that it needs to.

Note that if this is called when the item is in its default openness state, and this call would not change whether it's open or closed, then no change will be stored. If you want to explicitly set the openness state to be non-default then you should use setOpenness instead.

See also
setOpenness, itemOpennessChanged, mightContainSubItems

◆ setOpenness()

void juce::TreeViewItem::setOpenness ( Openness  newOpenness)

Opens or closes the item.

If this causes the value of isOpen() to change, then the item's itemOpennessChanged() method will be called, and a subclass should use this callback to create and add any sub-items that it needs to.

See also
setOpen

◆ setOwnerView()

void juce::TreeViewItem::setOwnerView ( TreeView )
privatenoexcept

◆ setSelected()

void juce::TreeViewItem::setSelected ( bool  shouldBeSelected,
bool  deselectOtherItemsFirst,
NotificationType  shouldNotify = sendNotification 
)

Selects or deselects the item.

If shouldNotify == sendNotification, then a callback will be made to itemSelectionChanged() if the item's selection has changed.

◆ sortSubItems()

template<class ElementComparator >
void juce::TreeViewItem::sortSubItems ( ElementComparator &  comparator)
inline

Sorts the list of sub-items using a standard array comparator.

This will use a comparator object to sort the elements into order. The comparator object must have a method of the form:

int compareElements (TreeViewItem* first, TreeViewItem* second);

..and this method must return:

  • a value of < 0 if the first comes before the second
  • a value of 0 if the two objects are equivalent
  • a value of > 0 if the second comes before the first

To improve performance, the compareElements() method can be declared as static or const.

◆ treeHasChanged()

void juce::TreeViewItem::treeHasChanged ( ) const
noexcept

Sends a signal to the treeview to make it refresh itself.

Call this if your items have changed and you want the tree to update to reflect this.

◆ updatePositions()

void juce::TreeViewItem::updatePositions ( int  newY)
private

Friends And Related Function Documentation

◆ TreeView

friend class TreeView
friend

Member Data Documentation

◆ drawLinesInside

bool juce::TreeViewItem::drawLinesInside
private

◆ drawLinesSet

bool juce::TreeViewItem::drawLinesSet
private

◆ drawsInLeftMargin

bool juce::TreeViewItem::drawsInLeftMargin
private

◆ drawsInRightMargin

bool juce::TreeViewItem::drawsInRightMargin
private

◆ itemHeight

int juce::TreeViewItem::itemHeight = 0
private

◆ itemWidth

int juce::TreeViewItem::itemWidth = 0
private

◆ openness

unsigned int juce::TreeViewItem::openness
private

◆ ownerView

TreeView* juce::TreeViewItem::ownerView = nullptr
private

◆ parentItem

TreeViewItem* juce::TreeViewItem::parentItem = nullptr
private

◆ redrawNeeded

bool juce::TreeViewItem::redrawNeeded
private

◆ selected

bool juce::TreeViewItem::selected
private

◆ subItems

OwnedArray<TreeViewItem> juce::TreeViewItem::subItems
private

◆ totalHeight

int juce::TreeViewItem::totalHeight = 0
private

◆ totalWidth

int juce::TreeViewItem::totalWidth = 0
private

◆ uid

int juce::TreeViewItem::uid = 0
private

◆ y

int juce::TreeViewItem::y = 0
private

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