Cutting and pasting nodes in a TreeView control? - vb6

I'm looking to implement a cut and paste method to replace drag and drop in a TreeView control. Drag and drop no longer works in the TreeView, and I believe cut and paste will be easier for the people using it. In this TreeView, I will be working with cutting only the child nodes. This object has only parent and child nodes (parent being dates and child nodes being purchase orders.) I'm not sure if there is a cut property and/or paste property to use with treeview1.node.selected or whatever I need to use.

... upon clicking cut it copies the selected node to copynode. then remove the selected node.
so the node is stored in the copynode slot
This won't work as copynode is a reference to the thing you just removed (destroyed) so after removal copynode will point to Nothing.
Instead; when a cut event occurs store the key features of the cut node (text, key, icon index etc.) in to a module level user defined type (or delimited string/class/series of variables) and remove the node. You can then use this data as the basis to construct a new node when a paste event is raised.
(The cut/paste events are not bound to the windows clipboard, rather thay are your own inventions based upon a context menu/detection of ctrl+X/V)
im not sure how to check if the node has children when im pasting to it
if tv.SelectedItem.Children > 0 then
... got child nodes

Related

How to control which GTK widgets visible in an expanded row of a tree?

I'm building a tree store with GTK3 in C in which there are primary rows that are always displayed, and by clicking on the little triangle icon to the left of a primary row, additional secondary (child) rows expand below the primary. As an example, consider that the primary rows could be directories, and when they're expanded, rows below that show the files in those directories. I'm doing this to allow a user to select primary items to be deleted, while the secondary rows are just informational, telling, for example, what files are in the directory, so they'll know if they really want to delete the whole thing.
To enable selection for deletion, the first column contains a GTK_CELL_RENDERER_TOGGLE, and I have a callback associated with the checkbox toggle. Everything works nicely except for one thing. When the user clicks the little triangle item to expand a row, most of the content of the primary row does not appear in the secondary rows (this is expected and desired), but... the checkbox toggle does appear in the first column. Although in a directories/files example that might be meaningful, in my case it makes no sense to think of deleting the content of the secondary rows.
When building the secondary rows, I've tried things like just:
gtk_tree_store_set(TS,&J,2,"filename",-1);
or
gtk_tree_store_set(TS,&J,0,NULL,2,"filename",-1);
hoping that NULL would cause the toggle to be suppressed, but to no avail. GTK still displays a checkbox, probably just interpreting the NULL as a zero.
Is there a way to control (and in my case, suppress) display of the toggle? Or more generally, is there a clean way to control which columns are displayed in child rows? It seems to work with TEXT, but just not with TOGGLE.
A little later: There is a potentially useful function called gtk_cell_renderer_set_visible(), but it requires a reference to the cell renderer. How to acquire that on a per-row or per-cell basis when all I have during construction is the GtkTreeStore and a GtkTreeIter?
There are (at least) 2 solutions:
Base class GtkCellRenderer has visible property. You can add extra field to your model which indicates, whether Toggle should be visible for this row.
If there are other fields in you model which indicate whether it's a primary or secondary row but not directly you can use gtk_tree_view_column_set_cell_data_func to set a function to be called before rendering. There you can call gtk_cell_renderer_set_visible or any other function to set renderer's properties manually.

Keeping currently selected node at top of treeview

I have a treeview (TVWDB) which has several node, children and grandchildren. Depending on the user these can be shown as just the parent node, or with the children or even grandchildren displayed.
The user steps through this using a button which advances down the tree at the level they have selected (ie if a child is selected then it will step through each child).
Im looking for a way that when the selected item drops down that node is shown at the top of the tree (if there are parents then it should actually be the parent node which is shown.
I keep looking at .Ensurevisible and Getvisible count but this seems to work on the 1st attempt but then start jumping around on each subsequent advance.

p:tree ajax loading nodes does not display the expand icon

I'm trying to ajax load the p:tree component. The idea is to mimic the tree of a windows file system. When I click the expand icon of a node, I make a call to a service which returns list of directories under that directory node. I then simply add these new directories as child nodes of the node which was expanded. I can successfully add child nodes to a node, however, I need to see the expand icon beside every new node being added. This is not happening for me. Any child nodes I add render without the expand icon and thus I am unable to go deeper into the tree.
Furthermore, it seems that PF tree component will only display the expand icon it the node has one or more children. However, in my case, I don't know whether a node will have children or not until that node is expanded.
The source code is available at the PimeFaces forum, I am opening this question in the hopes of getting a few more eyes looking at it.
http://forum.primefaces.org/viewtopic.php?f=3&t=34819
I have managed to find a workaround for this.
Everytime I add a new node anywhere on the tree, add a 'dummy' node to it. This will ensure that every new node added will get the expand icon beside. Now, when clicking the expand icon on a node, the backing bean will remove all children and add the real nodes.
There is probably a better way of doing this so I am open to other suggestions but for the time being this will do its job.

Looking for a specific control (sketch included)

I am looking for a control many of us probably know, but I don't know it's name and don't have a real screenshot by hand, just this sketch:
In the left box one can select an operation or whatever, which then is moved to the right side. With the up/down arrows on the right, one can move this operation (or whatever kind of meaning the entry has) up or down in the order of execution.
How is this kind of control called? Or is it normally build by developers out of single controls? Is this control available in JavaFX 2? If not, I don't need exactly this control, but a control with the following features:
User can select multiple operations (duplicates allowed) out of all available operations
The user can arrange their order of execution
Thanks for any hint :-)
You need to use multiple controls to build up your interface. Use two ListViews with a MultipleSelectionModel for each (or at least the left one) and add a couple of buttons, that copy selected items from one list to the other and another couple of buttons which modify the position of selected items in the right list view by modifying the view's underlying item list.
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

How to make selection on QGraphicsScene?

I'm writing a diagram editor in Qt with Graphics View Framework.
Currently I'm just trying to create a simple Node (QGraphicsItem) on GraphScene (QGraphicsScene). I created a Canvas (QGraphicsView) and added a grid to it. I can even add Nodes and move them around on scene. My final goal is to have different working modes, editing and styling options, etc. For now I just want to know how can I setup selection for Nodes already present on scene. I tried doing it with mouse events but noticed that event calls for selection and Node insertion overlap... When I try to select something a new Node is created... This is my first Qt application so I don't fully understand how the functionality I want to achieve should be designed.
How the Selection Rectangle should be properly drawn?
How should I manage mouse events that conflict with each other?
You can use a checkable button/action(that's a QPushButton/QAction with a checkable property set to 'true) to switch between Edit & Insert mode. Then you check the state in your mouse event and insert a new item only if you're in Insertion mode.
You can also distinct between mouse buttons - insert item when dragged with the right button for example
Or use QKeyboardModifiers - for example: on drag + Ctrl - insert item.
Hope this helps.
In case of the overlapping mouse events, you should have a single place (like QGraphicsView to handle the mouse clicking/moving events) and create a state machine and then handle the events according to the state you are in. You need to plan your architecture well and that can be really complex task.
set your state enum/constants
refer to the current machine state in your events in your if conditions
keep your "business logic" on a single place
Like it's shown in these two NodeEditor tutorials #11 and #12: https://www.youtube.com/watch?v=pk4v2xuXlm4 and https://www.youtube.com/watch?v=-VYcQojkloE)
If you still want more in depth explanation of the functionality and events of Qt, here is a full list of tutorials with implementing all possible features like dragging edges to nodes, selecting them and deleting them, cutting edges, serialization, etc., you can have a look on the whole list of 50 tutorials I've recorded here: https://www.blenderfreak.com/tutorials/node-editor-tutorial-series/.
I'm putting a link to the whole list, since it's not possible to write all the code on this page...

Resources