Selecting Matching Selectors when Objects are Selected

This post explains selection of treeview rows when objects belonging to that selector row are selected.

First, the objects in the desktop selection are obtained. Next the treeview’s rows are iterated and each row’s column _colObj is obtained as:
std::vector<spobject *> objVec = row[_mColumns._colObj];

The selected object’s ID is compared with each object’s ID in objVec. If the comparison returns true, then the row whose objVec had matching objects is added to treeview selection as:

By default, only the parent rows are iterated. So a check is also performed on child rows to see if IDs match with them. Also if there is a prior selection and the current object selected does not belong to any selector, then the treeview selection is cleared using _unselect_all() function of Gtk::TreeSelection.

Screenshot from 2016-07-27 13:50:02
In the above screenshot, the object associated with second child row is selected which in turn selects the row in treeview.

Selection of Objects when Style Dialog Row is Selected

Whenever any row in Style Dialog is selected, the corresponding objects in the drawing must be selected. This was implemented quickly. First the selection prior to selecting any row is cleared. Next it is made sure that the objects are selected only when the tree column corresponding to selector label is clicked. First column with ‘+’ is avoided because it is used to add objects to selector.

Next _colObj, i.e. the column referring to corresponding objects of the selected row is used to get the objects to be added to selection.


obj is the object in the objVec returned by _colObj. Thus objects are added to selection. Besides it is also checked, if the row selected in the Style Dialog is a parent row or a child row. For the former case, its child rows are also iterated and those objects are also added to selection.

Case 1: When parent row is selected and it has children
Screenshot from 2016-07-27 12:58:52

Case 2: When child row is selected
Screenshot from 2016-07-27 12:59:09

There will be another case in selection when matching selector rows should be seleted when objects in the drawing are selected, which will be discussed in next post.

The two ways of window selection

Ever tried on LibreCAD or AutoCAD? And then played with the selection using mouse drag in the drawing area. This feature is agile and it requires a little attention to catch the difference when selecting in increasing and decreasing values of x-axis.

The logic of this feature’s implementation in eCAD was clearly associated with the intersection of bounding rectangles of items being selected and the rubber band drag window/widget. The two different cases that had to be deployed included:

  • With increase in values of x, an entity is selected if the entity lies completely inside the selection area. See figure 1 below.
  • Mouse is dragged from top left to bottom right to select but it is not selected

    Entity not selected when a portion of it is in selection rectangle

    Mouse is dragged from top left to bottom right to select and it is selected since it lies entirely in the selection box.

    Mouse is dragged from top left to bottom right to select and it is selected since it lies entirely in the selection box.

  • With decrease in values of x, an entity is selected if a portion of the entity lies inside the selection area,
  • Mouse is dragged from bottomright to topleft corner and item is selected even when a portion of entity lies inside the selection box.

    Mouse is dragged from bottomright to topleft corner and item is selected even when a portion of entity lies inside the selection box.

Now I will be moving onto Deselect Window and selection of intersected entities.

Undo/Redo for deletion && updating selection

Today we implemented undo/redo for delete operation. Likewise, we proceeded with undo/redo for move operation. Successfully implemented it for point entity. Saving the file also showed the updated coordinates of point. Moving the other entities resulted in inconsistent pushing of positions to the undo stack. Since the other entities need more information to be pushed to the stack, not figured this out yet.

Another issue came by. An item if deleted from the scene got saved because the list being iterated in the writeStream() method keeps a record of all the entities that were once added to the scene. Getting surprises daily. 😉

Also the entities’ properties have been set while one or more of them is selected. The points’ color is changed when selected. A dotted pattern has been implemented showing the selection of other entities accompanied by a change in the color of the points associated with the same entity, say center point for circle, likewise for line and ellipse too.

Selection in action

Though saving for all entities has been done yesterday but no ids were assigned to any of the saved entities. Continuing it, we have assigned a unique id(duh 😉 ) to each entity in the scene. Pre-increment came into action.

Then we started with selection and moving of entities. It worked decently for point but lost its expected behavior with other entities. Considering line say, it is constructed using two points and a path joining them. If the mouse click was on path say, or any of the one points, voila only the path or the point selected moved and the remaining part of the entity did not bother to accompany. And we laughed!

Learnt another element of Qt namely QGraphicsItemGroup. We created groups for each of the entities. Added the entities’ different parts to this group and then this group was added to the scene just like single QGraphicsItem was done. Got the selection accomplished. The issue of overlapping entities is also solved to an acceptable level according to me but not Gurjot. 😀 We are trying to minimize the bounding rectangle for the entities, considering shape() to be of some convenience.