File: QTreeView.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 80,296 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (223 lines) | stat: -rw-r--r-- 4,670 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
TreeView : View {
	var <itemPressedAction;
	var <onItemChanged;

	*qtClass { ^'QcTreeWidget' }

	columns_ { arg labels; this.setProperty( \columns, labels ); }
	columns { ^this.getProperty( \columns ); }
	numColumns { ^this.getProperty( \columnCount ); }

	addItem { arg strings;
		^this.invokeMethod( \addItem, [TreeViewItem(),strings] ).prValidItem(this);
	}

	insertItem { arg index, strings;
		^this.invokeMethod( \insertItem, [TreeViewItem(),index, strings] ).prValidItem(this);
	}

	removeItem { arg item; this.invokeMethod( \removeItem, item ); }

	numItems { ^this.getProperty( \topLevelItemCount ); }

	clear { this.invokeMethod(\clear); }

	currentItem {
		^this.getProperty( \currentItem ).prValidItem(this);
	}

	currentItem_ { arg item;
		this.setProperty( \currentItem, item ? TreeViewItem() );
	}

	itemAt { arg index;
		^this.invokeMethod( \item, [TreeViewItem(), index] ).prValidItem(this);
	}

	canSort { ^this.getProperty( \sortingEnabled ) }
	canSort_ { arg bool; this.setProperty( \sortingEnabled, bool ) }

	sort { arg column, descending = false;
		this.invokeMethod( \sort, [column, descending] )
	}

	columnWidth { arg column;
		^this.invokeMethod( \columnWidth, [column] )
	}

	setColumnWidth { arg column, width;
		this.invokeMethod( \setColumnWidth, [column, width] )
	}

	itemPressedAction_ { arg action;
		if(itemPressedAction.notNil) {
			this.disconnectFunction( 'itemPressedAction()', itemPressedAction );
		};
		if(action.notNil) {
			this.connectFunction( 'itemPressedAction()', action );
		};
		itemPressedAction = action;
	}

	onItemChanged_ { arg hook;
		if(onItemChanged.notNil) {
			this.disconnectFunction( 'currentItemChanged()', onItemChanged );
		};
		if(hook.notNil) {
			this.connectFunction( 'currentItemChanged()', hook );
		};
		onItemChanged = hook;
	}

	/*
	NOTE:
	These methods can only operate on top level items
	Should we include them?

	value {
	var i = this.currentItem.index;
	if( i < 0 ) { ^nil } { ^i };
	}

	value_ { arg index;
	var item;
	if( index.notNil ) {
	this.currentItem = this.itemAt(index);
	} {
	this.currentItem = nil;
	};
	}
	*/

	background { ^this.palette.base; }
	background_ { arg color; this.palette = this.palette.base_(color) }

	// For compatibility with methods from TreeViewItem

	addChild { arg strings;
		^this.addItem(strings);
	}

	insertChild { arg index, strings;
		^this.insertItem(index, strings);
	}

	childAt { arg index;
		^this.itemAt(index);
	}

	/////////// PRIVATE:

	prForEachColumnDataPair { arg data, func;
		var n = this.numColumns;
		var i = 0;
		var d = [] ++ data;
		var nd = d.size - 1;
		var id;
		if( nd >= 0 ) {
			while { i < n } {
				id = i.wrap(0,nd);
				func.value( i, d[id] );
				i = i + 1;
			};
		};
	}

	// dummy for convenience in case tree view is invalid
	prValidItem {
		^nil;
	}
}

TreeViewItem {
	var qtObject;
	var <id;
	var finalizer;
	var <treeView;

	== { arg other;
		^ other.class == TreeViewItem and: {id == other.id}
	}

	isNull { ^ id.isNil }

	parent {
		^treeView.invokeMethod( \parentItem, this ).prValidItem(treeView);
	}

	index {
		var i = treeView.invokeMethod( \indexOfItem, this );
		if(i.isInteger) {^i} {^-1};
	}

	childAt { arg index;
		^treeView.invokeMethod( \item, [this, index] ).prValidItem(treeView);
	}

	addChild { arg strings;
		^treeView.invokeMethod( \addItem, [this,strings] ).prValidItem(treeView);
	}

	insertChild { arg index, strings;
		^treeView.invokeMethod( \insertItem, [this,index,strings] ).prValidItem(treeView);
	}

	strings {
		^treeView.invokeMethod( \strings, this );
	}

	strings_ { arg strings;
		strings.do { |string, column| this.setString(column,string) };
	}

	setString { arg column, string;
		treeView.invokeMethod( \setText, [this,column,string] );
	}

	colors_ { arg colors;
		treeView.prForEachColumnDataPair( colors, {
			|column,color| this.setColor(column,color);
		} );
	}

	setColor { arg column, color;
		treeView.invokeMethod( \setColor, [this,column,color] );
	}

	textColors_ { arg textColors;
		treeView.prForEachColumnDataPair( textColors, {
			|column,color| this.setTextColor(column,color);
		} );
	}

	setTextColor { arg column, color;
		treeView.invokeMethod( \setTextColor, [this,column,color] );
	}

	setView { arg column, view;
		if( view.notNil ) {
			treeView.invokeMethod( \setItemWidget, [this, column, view] );
		} {
			this.removeView( column );
		};
	}

	removeView { arg column;
		treeView.invokeMethod( \removeItemWidget, [this, column] );
	}

	view { arg column;
		^treeView.invokeMethod( \itemWidget, [this,column] );
	}

	/////// PRIVATE:

	prValidItem { arg treeView_;
		if( qtObject.notNil ) {
			treeView = treeView_;
			^this;
		} {
			^nil
		};
	}
}