|
|
A collapsible treelist widget.
1. Introduction 2. Features 3. Installation 4. Public interface
1. Introduction ================================================================================
KTreeList is a class inherited from QTableView in the Qt user interface library. It provides a way to display hierarchical data in a single-inheritance tree, similar to tree controls in Microsoft Windows and other GUI's. It is most suitable for directory trees or outlines, but I'm sure other uses will come to mind. Frankly, it was designed mostly with the above two functions in mind, but I have tried to make it as flexible as I know how to make it easy to adapt to other uses.
In case of problems, I encourage you to read all of the other documentation files in this package before contacting me as you may find the answer to your question in one of them. Also read the source code if you have time. I have tried to comment it adequately and make the source understandable.
2. Features ================================================================================
Displays both text and optional pixmap supplied by the programmer. A support class, KTreeListItem, can be inherited and modified to draw items as needed by the programmer.
The list items can be returned by index or logical path and the tree navigated by parent, child or sibling references contained in them. Also, item information such as text, pixmap, branch level can be obtained.
Items can be inserted, changed and removed either by index in the visible structure, or by logical paths through the tree hierarchy.
The logical path through the tree for any item can be obtained with the index of the item.
Tree structure display and expanding/collapsing of sub-trees is handled with no intervention from the programmer.
entire tree can be expanded or collapsed to a specified sub-level (handy for outline views)
Configuration as follows:
enable/disable item text display (if you only want to display pixmaps)
enable/disable drawing of expand/collapse button
enable/disable drawing of tree structure
Keyboard support as follows:
up/down arrows move the highlight appropriately and scroll the list an item at a time, if necessary
pgup/pgdn move the highlight a 'page' up or down as applicable and scroll the view
+/- keys expand/collapse the highlighted item if it appropriate
enter key selects the highlighted item
Mouse support as follows:
left click on item highlights it
left click on an item "hot button" expands or collapses its sub-tree, as applicable
double click on item selects it
normal scrolling functions in conjunction with scrollbars if present
2nd scrolling with the middle mouse button: pressing MMB inserts a rubberband, showing which part of the whole tree is currently visible. moving the mouse will scroll the visible part
Signals/Slots
signal void highlighted(int) - emitted when an item in the tree is highlighted; sends the index of the item
signal void selected(int) - emitted when an item in the tree is selected; sends the index of the item
signal void expanded(int) - emitted when an item in the tree is expanded; sends the index of the item
signal void collpased(int) - emitted when an item in the tree is collapsed; sends the index of the item
KTreeList (QWidget *parent = 0, const char *name = 0, WFlags f = 0) |
Widget contructor. Passes all parameters on to base QTableView, and does not use them directly. Does internal initialization, sets the current item to -1, and sets default values for scroll bars (both auto) and grid snap (snap to grid vertically).
void addChildItem (const char *theText, const QPixmap *thePixmap, int index) |
Adds a new item to the tree with the given text and pixmap as a child of the item currently at the given index. If the current item already has children, the new item is appended below them.
void addChildItem (const char *theText, const QPixmap *thePixmap, const KPath *thePath) |
Same as above except parent item is specified by path.
void addChildItem (KTreeListItem *newItem, int index) |
Adds the given item as a child of the item currently at the given index. If the current item already has children, the new item is appended below them.
void addChildItem (KTreeListItem *newItem, const KPath *thePath) |
Same as above except parent item is specified by path.
bool autoBottomScrollBar () |
Returns a bool value indicating whether the list will display a horizontal scrollbar if one of the displayed items is wider than can be displayed at the current width of the view.
bool autoScrollBar () |
Returns a bool value indicating whether the list will display a vertical scrollbar if the number of displayed items is more than can be displayed at the current height of the view.
bool autoUpdate () |
Returns a bool value indicating whether the list will update immediately on changing the state of the widget in some way.
Reimplemented from QTableView
bool bottomScrollBar () |
Returns a bool value indicating whether the list has currently has a horizontal scroll bar.
void changeItem (const char *newText, const QPixmap *newPixmap, int index) |
Changes the text and/or pixmap of the given item at the specified index to the given values and updates the display if auto update enabled. If changing only the text or pixmap, set the other parameter to 0.
void changeItem (const char *newText, const QPixmap *newPixmap, const KPath *thePath) |
Same as above function, except item to change is specified by a path through the tree.
void clear () |
Removes all items from the tree.
uint count () |
Returns the total number of items in the tree, whether visible (expanded sub-trees) or not (collapsed).
int currentItem () |
Returns the index of the current (highlighted) item. If no current item, returns -1.
void collapseItem (int index) |
Collapses the sub-tree at the specified index.
void expandItem (int index) |
Expands the sub-tree at the specified index.
int expandLevel () |
Returns the depth to which all parent items are automatically expanded.
void expandOrCollapseItem (int index) |
Same as above functions combined into one. If sub-tree is expanded, collapses it, if it is collapsed, it expands it.
void forEveryItem (KForEvery func, void *user) |
Iterates every item in the tree, visible or not, and applies the function func with a pointer to each item and user data supplied as parameters. KForEveryFunc is defined as:
typedef void (*KForEveryFunc)(KTreeListItem *, void *);
That is, a function that returns void and takes a pointer to a KTreeListItem and pointer to void as parameters.
void forEveryVisibleItem (KForEvery func, void *user) |
Same as above, but only iterates visible items, in order.
KTreeListItem * getCurrentItem () |
Returns a pointer to the current item if there is one, or 0.
int indentSpacing () |
Returns the number of pixels an item is indented for each level.
void insertItem (const char *theText, const QPixmap *thePixmap, int index = -1, bool prefix = TRUE) |
Inserts an item into the tree with the given text and pixmap either before or after the item currently at the given index, depending on the value of prefix. The new item is added to the same branch as the reference item. If index is -1, the item is simply appended to the tree at the root level. The item text must not be null.
void insertItem (const char *theText, const QPixmap *thePixmap, const KPath *thePath, bool prefix = TRUE) |
Same as above, but uses a path through the tree to reference the insert position.
void insertItem (KTreeListItem *newItem, int index = -1, bool prefix = TRUE) |
Inserts the given item into the tree either before or after the item currently at the given index, depending on the value of prefix. The new item is add to the same branch as the reference item. If index is -1, the item is simply appended to the tree at the root level. The item text must not be null.
void insertItem (KTreeListItem *newItem, const KPath *thePath, bool prefix = TRUE) |
Same as above, but uses a path through the tree to reference the insert position.
KTreeListItem * itemAt (int index) |
Returns a pointer to the item at index.
KTreeListItem * itemAt (const KPath *path) |
Returns a pointer ot the item at the end of thePath.
int itemIndex (KTreeListItem *item) |
Returns the index of the given item in the visible tree or -1 if not found.
KPath * itemPath (int index) |
Returns a pointer to the logical path to the item at the specified index. The return KPath object must be deleted by the caller. Any strings still contained in the stack will be automatically deleted, but any popped from the path must also be deleted by the caller.
void join (int index) |
Outdents the item at the given index one level so that it becomes a sibling of its parent.
void join (const KPath *path) |
void lowerItem (int index) |
Moves the item at the specified index down one slot in its current branch.
void lowerItem (const KPath *path) |
Same as above but uses a path to specify the item.
void raiseItem (int index) |
Moves the item at the specified index up one slot in its current branch.
void raiseItem (const KPath *path) |
Same as above but uses a path to specify the item.
void removeItem (int index) |
Removes the item at the specified index.
void removeItem (const KPath *thePath) |
Same as above except uses path through the tree to find the item.
bool scrollBar () |
Returns bool value indicating whether the list currently displays a vertical scroll bar.
void setAutoUpdate (bool enable) |
If enable is TRUE (default), enables auto update, else disables it.
Reimplemented from QTableView
void setBottomScrollBar (bool enable) |
If enable is TRUE, displays a horizontal scroll bar, else hides it.
void setCurrentItem (int index) |
Makes the item at index current and highlights it.
void setScrollBar (bool enable) |
If enable is TRUE, displays a vertical scroll bar, else hides it.
void setShowItemText (bool enable) |
If enable is TRUE (default), item text will be displayed, otherwise it will not, and no highlight will be shown in the default widget.
void setSmoothScrolling (bool enable) |
If enable is TRUE, enables smooth scrolling, else disables it (default).
void setTreeDrawing (bool enable) |
If enable is TRUE (default), lines depicting the structure of the tree will be drawn, otherwise they will not.
bool showItemText () |
Indicates whether item text is displayed.
bool smoothScrolling () |
Returns a bool value indicating whether smooth scrolling is enabled.
void split (int index) |
Indents the item at the specified index, creating a new branch.
void split (const KPath *path) |
Same as above but uses a path to specify the item.
KTreeListItem * takeItem (int index) |
Removes the item at the given index from the tree, but does not delete it, returning a pointer to the removed item.
KTreeListItem * takeItem (const KPath *path) |
Same as above but uses a path to specify the item to take.
bool treeDrawing () |
Indicates whether the tree structure is drawn.
int visibleCount () |
Returns the number of items that are visible (their parents are expanded).
Generated by: root@jedi.mandrakesoft.com on Sat Dec 25 21:35:43 199. |