LassoComponent doesn't call SelectedItemSet<>::itemSelected()

I'm using a LassoComponent<> and LassoSource<> to select and deselect components in a visual editor. The SelectedItemSet<> I'm providing has the virtuals itemSelected() and itemDeselected() overridden, but neither of them is called when I add something to the lasso selection.

If I use a ChangeListener, a change is broadcasted (so I'm sure the selection actually takes place).

Am I doing something wrong? I'd say this could be considered buggy behaviour.

Looking at SelectedItemSet, it clearly does call those functions all over the place whenever anything changes. Maybe you've not overidden the method correctly or something else is wrong?

I'm overriding the methods using c++11's override and final keywords, so I'm certain I'm using the correct functions.

Upon further inspection, you're not calling those functions in the copy assignment operator in SelectedItemSet<>:

void dragLasso (const MouseEvent& e)
    if (source != nullptr)
        setBounds (Rectangle<int> (dragStartPos, e.getPosition()));
        setVisible (true);
        Array<SelectableItemType> itemsInLasso;
        source->findLassoItemsInArea (itemsInLasso, getBounds());
        if (e.mods.isShiftDown())
            itemsInLasso.removeValuesIn (originalSelection); //  to avoid duplicates
            itemsInLasso.addArray (originalSelection);
        else if (e.mods.isCommandDown() || e.mods.isAltDown())
            Array<SelectableItemType> originalMinusNew (originalSelection);
            originalMinusNew.removeValuesIn (itemsInLasso);
            itemsInLasso.removeValuesIn (originalSelection);
            itemsInLasso.addArray (originalMinusNew);
        source->getLassoSelection() = SelectedItemSet<SelectableItemType> (itemsInLasso);

findLassoItemsInArea() is called (breakpoint), but then if I step further and get to the last line, it simply replaces the SelectedItemSet<> I provide using getLassoSelection() with a new one. Thát copy assignment operator doesn't call itemSelected() or itemDeselected(), but just the changebroadcaster callback.

Hmm, ok, thanks - we'll take a look at that..

ok.. give it a shot now!

I can see the change on GitHub. Shouldn't *e = other.selectedItems.begin() be .end()? Otherwise it never enters the for-loop.

if (selectedItems != other.selectedItems)
    for (int i = selectedItems.size(); --i >= 0;)
        if (! other.isSelected (selectedItems.getReference (i)))
            itemDeselected (selectedItems.remove (i));
    for (SelectableItemType* i = other.selectedItems.begin(), *e = other.selectedItems.begin(); i != e; ++i)
        if (! isSelected (*i))
            selectedItems.add (*i);
            itemSelected (*i);

Changed to .end() locally and works like a charm ;)

Damn. Yes, of course. Fixed now, many thanks!

No prob, you're welcome!