Recent Changes - Search:

TreeVsTreeView

(:toc:)

TreeView vs tree

The interfaces of tree and the TreeView widget have intentionally been made very similar. This page discusses differences and issues.

Columns vs Keys

A TreeView maps keys to columns and can insert key/values only if a column is defined for given each key.

This means that TreeView is more designed for uses where each node has homogenous or fixed sets of keys.

Tree on the other hand, is designed to work with heterogenous or varying sets of keys. Each node can have entirely different sets of keys.

Get

Tree get returns the data for one or all keys.

TreeView get returns the Tree label. When TreeView has -allowduplicates=0 (the default), then insert uses the Tree label as a key to enforce uniqueness within a parent. See Key Field Access below for accessing data.

Insert

The insert command takes different arguments and does different things in tree vs TreeView. In tree the first arguement is a node while in TreeView it is a position within the root.

Thus in tree we do:

  set t [tree create]
  set i [$t insert end -label Parent]
  $t insert $i -label Child

But the same thing in TreeView requires:

  treeview .t
  set i [.t insert end Parent]
  .t insert -at $i end Child

Moreover, the label in TreeView is actually a list which uniquely identifies the node in the parent (unless -allowduplicates=1 or -separator=none).

Thus by default to insert a label with spaces:

  set i1 [$t insert end -label "The Parent"]
  set i2 [.t insert end [list "The Parent"]]

and to insert a child with spaces:

  $t insert $i1 -label "The Child"
  .t insert end [list "The Parent" "The Child"]
  # or
  .t insert -at $i2 [list "The Child"]

Multiple Inserts

In Tree only one node can be inserted at a time.

TreeView lets you insert multiple entries in one statement, with options following the elements.

  .t insert end   A B C
  .t insert end   e -label E   f -label F

Note that tags are a tree attribute, not an entry option so we use:

  $t insert end -label A -tags mytag
  .t insert -tags mytag end A

Duplicate Checking

Tree attaches no significance to a label. But the TreeView insert by default enforce unique tree labels at each node level (ie. -allowduplicates=0). This makes it convenient for use in problems requiring sets of label-unique entities (like mapping directories of files).

The downside is that loading can be slow when tens of thousands of entries are involved. Fortunately, there is a workaround: either use a tree to load the data, or set -allowduplicates=1.

Node Addressing

Tree supports addressing via labels.

  $t index 0->Parent
  $t index 0->Parent->Child
  $t index {root->"The Parent"}

This is not available in TreeView.

Array Key Addressing

TreeView does not support addressing key array elements like tree does, eg:

   set i [$t insert end -data { Class "A 1 B 2 C 3" }]
   $t incr $i  Class(A)

Key Field Access

TreeView has only two ways to set/get key data fields:

  • set/get individual keys with entry set NODE KEY VALUE
  • set all key values with entry conf -data

The config command takes a tag, but entry set does not.

By comparison tree has many more options:

  • tag-ranging commands, eg. set, modify and incri.
  • modify-only commands, eg: update, incr, append.
  • a with command for accessing all keys efficiently.

Tree Command In TreeView

A TreeView always uses a tree internally. However, this tree is not available as a command. To change that use:

  treeview .t -tree [tree create]

However, it is up to the user to delete the tree at the end.

Edit - History - Print - Recent Changes - Search
Page last modified on January 23, 2010, at 08:43 AM