Tree Widget



 Tree widget is a graphic object representing data as a form of list or tree.


                                         


   



Methods





Return Type

Method

Description


addChild( index, texts )

Add a child item to the parent item of tree widgets.


addData( texts )

Enter the data of tree widgets.


clear()

Delete the data of tree widgets and reset.


clearSelection()

Release all selection of tree widgets.


connect( eventName, func )        

Register an event receiving function. It receives when the selected row is changed

int

count()

Obtain the number of data values entered into tree widgets.

list[str]

currentData()

Obtain the data of the selected item.

 int

currentIndex()

Obtain the number of the selected item.

 list[str]

data( index )

Obtain the data of items.

str

data( row, column )

Obtain the display data of tree widget items.


expandItem( index, value )

If the child item exists, expand.


fitColumn()

Fit the size of items to the size of its text.


insertData( index, texts )

Insert the data of tree widgets.

variant

itemData( row, column )

Read the data set to tree widget items.


removeChild( index )

Remove the child item of tree widget items.


removeData( index )

Remove the item of tree widgets.


resizeSection( index, size )

Set the column width of tree widgets.


restoreHeader()

Set the size of columns to the size of the last practice.


setCurrentIndex( index )

Set the selected item of tree widgets.


setData( row, column, text )

Set the display String to the tree widget item.


setHeader( text )

Set the header of tree widgets.


setHeaderCount( index )

Set the number of headers.


setHeaders( texts )

Set multi headers of tree widgets.


setItemData( row, column, value )

Set the data of tree widget items.


setMaxDisplay( count )

Set the number of data to display on the tree widget.


  setHeaderCount( index:Header count )

 

  setHeaderCount sets the number of headers.


        ㆍ Headers are set as much as an index and the name of headers start from 1 and increments by 1.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       obj.setHeaderCount( 3 );  << Set the number of headers as 3.





                                         



  setHeader( text:Header name )

 

  setHeader sets the name of the header as text.

        ㆍ setHeader sets only one header.

        ㆍ If you set multi headers with setHeaderCount, setHeader changes only the first header.

        ㆍ If setHeaderCount is not used, only one header is created.

        ㆍ If you use setHeader several times, the last text would be the header.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       obj.setHeader('Header 1');  << Set the name of the header as 'Header 1'.





                                         



  setHeaders( texts:String list )

 

  setHeader sets the name of headers as texts.


        ㆍ Enter the String list to texts.

        ㆍ Headers are created based on the number of String lists, and the cell is separated.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       texts = ['헤더명 1', '헤더명 2', '헤더명 3'];

       obj.setHeaders( texts );  << Set the name of header as texts list.





                                         



  addData( texts:String list )

 

  addData enters texts(String list) to the tree widget.


        ㆍ addData enters the data from index 0.

        ㆍ If you use addData several times, the index increments by 1.

        ㆍ According to the number of headers, it is able to enter a String list.

        ㆍ If the String list exceeds the number of headers, it is invisible, but the data still exists.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.


       texts = ['헤더명 1', '헤더명 2', '헤더명 3'];

       obj.setHeaders( texts );  << Set the name of the header as texts list.


       texts2 = ['1', '2', '3'];

       obj.addData(texts2);  << Enter text2 to index 0


       texts2 = ['4', '5', '6'];

       obj.addData(texts2);  << Enter text2 to index 1


       texts2 = ['7', '8'];

       obj.addData(texts2);  << Enter text2 to index 2


       texts2 = ['', '9', '10'];

       obj.addData(texts2);  << Enter text2 to index 2





                                         



  insertData( index:Item position, texts:String list )

 

  insertData inserts texts(String list) at the index position of tree widgets.


        ㆍ index starts from 0 and increments by 1.

        ㆍ The existing index increments by 1.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain tree widget object.


       texts = ['헤더명 1', '헤더명 2', '헤더명 3'];

       obj.setHeaders( texts );  << Set the name of headers as texts list.


       texts2 = ['1', '2', '3'];

       obj.addData(texts2);  << Enter text2 to index 0.


       texts2 = ['4', '5', '6'];

       obj.addData(texts2);  << Enter text2 to index 1.


       texts2 = ['a', 'b', 'c'];

       obj.insertData( 0, texts2);  << Insert text2 to index 0.





                                         =



  addChild( index:Item position, texts:String list )

   

  addChild enters the child item to the index position of tree widgets.


        ㆍ index starts from 0 and increments by 1.

        ㆍ addChild registers the child item to the parent item which is entered by addData or insertData.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.


       texts = ['Header 1', 'Header 2', 'Header 3'];

       obj.setHeaders( texts );  << Set the name of header as texts list.


       texts2 = ['1', '2', '3'];

       obj.addData(texts2);  << Enter text2 to index 0.


       texts2 = ['4', '5', '6'];

       obj.addData(texts2);  << Enter text2 to index 1.


       texts2 = ['a', 'b', 'c'];

       obj.insertData( 0, texts2);  << Enter text2 to index 0.


       texts3 = ['d', 'e', 'f'];

       obj.addChild(0, texts3);  << Enter the child item to index 0.


       texts3 = ['g', 'h', 'i'];

       obj.addChild(0, texts3);  << Enter the child item to index 0.


       texts3 = ['j', 'k', 'l'];

       obj.addChild(2, texts3);  << Enter the child item to index 2.





                                         



  list[str] data( index:Item position )

 

  data returns the data of items which positioning on the index of tree widgets as texts(String list).


        ㆍ index starts from 0 and increments by 1.

        ㆍ data ignores an item added by addChild.

        ㆍ Choose an index of parent items(item entered by addData, insertData).



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.


       texts = ['Header 1', 'Header 2', 'Header 3'];

       obj.setHeaders( texts );  << Set the name of headers as texts list.


       texts2 = ['1', '2', '3'];

       obj.addData(texts2);  << Enter text2 to index 0.


       texts2 = ['4', '5', '6'];

       obj.addData(texts2);  << Enter text2 to index 1.


       texts2 = ['a', 'b', 'c'];

       obj.insertData( 0, texts2);  << Insert text2 to index 0.


       textsData = obj.data(2);  << Obtain the data of index 2.

       aa = '';

       for x in textsData:  << Obtain the String of textsData through a loop.

              aa = aa +x;


       app.messageBox(aa);





                                         



  removeData( index:Item position )

 

  removeData removes the data of the item located on the index.


        ㆍ The data after index, its index is decreased by 1.

        ㆍ If an item had child items, it removes all of it.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.


       texts = ['Header 1', 'Header 2', 'Header 3'];

       obj.setHeaders( texts );  << Set the name of headers as texts list.


       texts2 = ['1', '2', '3'];

       obj.addData(texts2);  << Enter text2 to index 0.


       texts2 = ['4', '5', '6'];

       obj.addData(texts2);  << Enter text2 to index 1.


       texts2 = ['a', 'b', 'c'];

       obj.insertData( 0, texts2);  << Insert text2 to index 0.


       obj.removeData(0);  << Remove the data of index 0.





                                         



  removeChild( index:Item position )

 

  removeData removes child data if an item has them.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.


       texts = ['Header 1', 'Header 2', 'Header 3'];

       obj.setHeaders( texts );  << Set the name of header as texts list.


       texts2 = ['1', '2', '3'];

       obj.addData(texts2);  << Enter text2 to index 0.


       texts2 = ['4', '5', '6'];

       obj.addData(texts2);  << Enter text2 to index 1.


       texts2 = ['a', 'b', 'c'];

       obj.insertData( 0, texts2);  << Insert text2 to index 0.


       texts3 = ['d', 'e', 'f'];

       obj.addChild(0, texts3);  << Insert the child item to index 0.


       texts3 = ['g', 'h', 'i'];

       obj.addChild(0, texts3);  << Insert the child item to index 0.


       texts3 = ['j', 'k', 'l'];

       obj.addChild(2, texts3);  << Insert the child item to index 2.


       obj.removeChild(0); << Remove the child item of index 0.





                                         



  clear()

 

  clear removes all data of the tree widget and resets it.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget objects.

       obj.clear();  << Remove all data of the tree widget and resets it.





                                         



  int currentIndex()


  currentIndex returns the number of items users currently selected.


        ㆍ When the user clicks the item of tree widgets, it indicates it is selected with a mark. (change its color to blue)

        ㆍ If an item has child items, when select child items and use currentIndex, it returns the index of parent items.


Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       val = obj.currentIndex();  << Return the number of items users currently selected.

       app.messageBox(val);





                                       



  list[str] currentData()

 

  currentData returns the data of items user currently selected as a String list.


        ㆍ When the user clicks the item of tree widgets, it indicates it is selected with a mark. (change its color to blue)

        ㆍ currentData also returns the data when selecting child items.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.


       val = obj.currentData();  << Return the data of tree widget items user currently selected as a String list.


       aa = '';

       for x in val:  << Obtain String of textsData by a loop.

              aa = aa +x;


       app.messageBox(aa);





                                         



  setCurrentIndex( index:Item position )

 

  setCurrentIndex allows users to select the index item.


        ㆍ When running PowerScene, tree widget had no selection before the mouse select of the user.

        ㆍ index is the index of parent items.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       obj.setCurrentIndex(0);  << Allow the 0th item of tree widgets to be selected.





                                         



  expandItem( index:Item position, value:0 or 1 )

 

  expandItem sets whether an item would be expanded if the parent item had child items.


        ㆍ It sets the item to index through value.

        ㆍ value 0 is an unexpanded state.

        ㆍ value 1 is an expanded state.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       obj.expandItem(0, 1);  << Set the item of position 1 as an expanded state.

       obj.expandItem(2, 1);  << Set the item of position 2 as an expanded state.





                                         



  restoreHeader()

 

  Set the size of columns as the size of the last practice.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       obj.restoreHeader()  << Set the size of tree widget columns as the size of the last practice.





  setItemData ( row, column, value )

 

  Set the data to the item of tree widgets.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       obj.setItemData(1, 1, 3)  << Set the data of the first row of the first column as 3.




 

         





  variant itemData( row, column )

 

  Read the data on tree widget items.



  Example)

   


       obj = canvas.getObject('TreeWidget');  << Obtain the tree widget object.

       var = obj.setItemData(1, 1)  << Read the data on the first row of the first column.




 

         



  fitColumn()

 

  Fit the size of tree widget items to the size of its text.



  Example)

   


       a = canvas.getObject('TreeWidget')  << Obtain the tree widget object.

       a.fitColumn()  << Fit the size of tree widget items to the size of its text.




 


         




  setMaxDisplay( count )

 

  Set the maximum number of data to display on the tree widget.



  Example)

   


       a = canvas.getObject('TreeWidget')  << Obtain the tree widget.

       a.setMaxDisplay(30)  << Display 30 items.






  int count()


 Read the number of items on the tree widget.


         



  Example)

   


       a = canvas.getObject('TreeWidget')  << Obtain the tree widget object.

       print a.count()  << Read the number of data to display on the tree widget.




Output)

   

       3




  str data( row, column )

 

  Read the displayed data of the tree widget.


         



  Example)

   


       a = canvas.getObject('TreeWidget')  << Obtain the tree widget object.

       print a.data(0,1)  << Read the data displayed on 0th row, 1st column.




  Output)

   

       군산




  setData( row, column, text )

 

  Change the text of tree widget items.



  Example)

   


       a = canvas.getObject('TreeWidget')  << Obtain the tree widget object.

       a.setData(0, 1, 'USA')  << Change the text of the 0th column, the 1st row to 'USA'.




   Results)

         



  connect( eventName:Event handler name, func:Receiving function )

 

  Receive an event of tree widgets. Tree widget generates 'Item change event' when changing the selected item, it is able to receive the changing in the tree widget by registering functions.



  Example)

   


       def indexChanged(index):  << Define the receiving function.

              print 'Item changed' , index

       

       obj = canvas.getObject('TreeWidget')  << Obtain the tree widget object.

       obj.connect('currentIndexChanged(int)', indexChanged)  << Register the receiving function.

 



  clearSelection()

 

  Cancel all items of the tree widgets.



  Example)

   


       a = canvas.getObject('TreeWidget')  << Obtain the tree widget object.

       a.clearSelection()  << Cancel all items of the tree widgets.




  Results)


         



  resizeSection( index :Column index, size : Width )


  Enter the column index of tree widgets to set the width of that column.



  Example)


   


       o = canvas.getObject('TreeWidget')  << Obtain the tree widget object.

       o.resizeSection(0, 100)  << Set the 0th column width of tree widgets as 100.




  Results)