The TreeWidget class provides a scrollable tree view a la Windows Explorer. More...
#include <tree.h>
The TreeWidget class provides an area on the screen which contains a hierarchy of nodes. Each node consists of a text and an optional pixmap. Each node can be associated with a piece of data which can be requested later (see setNodeData()). The TreeWidget uses a pixmap buffer to ensure smooth updates. It comes with two scrollbars for x and y direction which become active automatically. Nodes in the tree can be highlighted by pressing the left mouse button. The right mouse button is used to pop up optional menus. The user can provide these menus in the form of QPopupMenu pointers.
Construct a TreeWidget. The parent and name arguments are sent to the QWidget constructor.
Destroy the TreeWidget.
Set the current node of the TreeWidget to the node identified by id. The new current node will be highlighted. If id is null, nothing will be selected.
Returns a TreeNode pointer to the root node of the TreeWidget.
Returns the TreeNode pointer of the currently selected node of the TreeWidget. If no node is selected, null is returned.
Returns a list of TreeNode pointers of all nodes in the tree. Example:
NodeList *list = myTree->nodes(); NodeListIt it(*list); TreeNode *curr; for(; it.current(); ++it) { .... } delete list;
Warning: Delete the list as soon as you are done. It is allocated specifically for you. If you don't delete it, you'l have a memory leak on your hands!
Adds a new node to the tree using txt as the node text and pic as the pixmap. The data parameter is an opaque container which is cast to (void *). This way you can store proprietary data along with the new node. You can later use the data() member function of the TreeNode to retrieve this data. The parent parameter is to locate the parent for the new tree node. If parent is 0, the new node will be used as the root node of the tree. Note that you can only have one root node. If a root node is present, you will need to delete it first using rmNode().
A pointer to the newly created TreeNode is returned. This pointer can be used as a reference later if you wish to retrieve information about the node.
Warning: The TreeWidget retains ownership of all the TreeNode-s in the tree. Do not ever attempt to delete a TreeNode!
Adds a new node to the tree. The node should be created by the user. It is placed in the tree as a child of the treenode pointed to by parent. The TreeWidget assumes ownership of the TreeNode after it has been added to the tree in this way. However, it does not own the data and pixmap members of the TreeNode. Freeing the storage related to those is up to the user.
Remove the tree node identified by target. The corresponding node and all it's children will be deleted.
Warning: If the TreeNode contains a pixmap or data, neither of these will be deleted! Whoever create the node with addNode() retains ownership of this memory and has the reponsibility to delete it.
Clear the whole TreeWidget. All nodes in the tree are deleted, including the root node.
Warning: If any of the TreeNodes contain pixmaps or data, neither of these will be deleted! Whoever create the node with addNode() retains ownership of this memory and has the reponsibility to delete it.
Specifies the popup menu that should be shown when the user right clicks on a selected node. By default, nothing hapens in this case. You can use this function to determine the operations that can be done on a node Example:
MyClass::MyClass(QWidget *parent, const char *name) : QWidget(parent, name) { TreeWidget *tree = new TreeWidget(this); tree->setGeometry(...); .... QPopupMenu *nodePopup = new QPopupMenu(0); nodePopup->insertItem("&Delete", this, SLOT(deleteNode()) ); nodePopup->insertItem("&Copy", this, SLOT(copyNode()) ); nodePopup->insertItem("&Edit", this, SLOT(editNode()) ); .... tree->setNodePopup(nodePopup); }
The deleteNode() SLOT could look like this:
void MyClass::deleteNode(void) { .... TreeNode *curr = tree->currentNode(); tree->rmNode(curr); .... }
Specifies the popup menu that should be shown when the user right clicks on a the background of the TreeWidget. By default, nothing hapens in this case. You can use this function to determine the operations that are available for the whole tree object. Example:
MyClass::MyClass(QWidget *parent, const char *name) : QWidget(parent, name) { TreeWidget *tree = new TreeWidget(this); tree->setGeometry(...); .... QPopupMenu *backPopup = new QPopupMenu(0); backPopup->insertItem("&Clear", this, SLOT(clearTree()) ); backPopup->insertItem("&Quit", this, SLOT(quit()) ); .... tree->setBackPopup(backPopup); }
[slot]
Force an update of the information in the tree. Call this function if you have updated the content of any of the TreeNode-s. If you don't call this function then you will have to wait until the next forced repaint.
[signal]
This signal is emitted when a new item has been highlighted by selecting it with the left mouse button.
[signal]
This signal is emitted when a new item is selected by double-clicking a tree node with the left mouse button.
[signal]
This signal is emitted when all selections are cancelled by clicking the left mouse button in the background of the TreeWidget.
[private]
Handles mouse click events. If the left mouse button is pressed inside the area used to draw a node, that node is selected. If the left mouse button is pressed in the background area which is not used to draw nodes on, all nodes are deselected and nothingSelected() is emitted. If the right mouse button is pressed on a node, the nodePopup menu is shown. If it is pressed in the background area, the backPopup menu is shown.
[private]
Handles mouse doubleclick events
[private]
Paints the buffer containing the pixmap pixture on the screen.
[private]
Handles resize events. Calls update() to ensure that the background buffer pixmap is appropriately resized and updated. This function also updates the range and value of the x- and y scrollbars
[private]
Paints the tree hierarchy into the background buffer.
Warning: This function \ul does not call update(). The content of the background buffer is not drawn on the screen!
[private, slot]
Handle movement of the x-scrollbar. Scroll the treewidget left and right.
[private, slot]
Handle movement of the y-scrollbar. Scroll the treewidget up and down.
[private]
The horizontal scrollbar
[private]
The vertical scrollbar
[private]
The root node of the tree
[private]
The currently selected node
[private]
A list of nodes in the tree
[private]
The background buffer used for flicker-free updates
[private]
The offset for drawing the (clipped) tree
[private]
The popup menu for the tree nodes
[private]
The popup menu for the tree background