I Need advice on Drag And Drop

I've a parent Component with small components inside, (like a stack of components)
These small component can be dragged to change the order, and can be deleted by dragging outside the parent.

class ParentComponent    : public Component, 
                           public DragAndDropTarget, 
                           public DragAndDropContainer
class ChildComponent : public Component 

void mouseDrag (const MouseEvent& e) 
    DragAndDropContainer* dragContainer = DragAndDropContainer::findParentDragContainerFor (this); 

    if (!dragContainer->isDragAndDropActive()) 
        dragContainer->startDragging("childComponent", this, Image::null, true); 


To delete a child component

    void ParentComponent::itemDragExit (const SourceDetails& dragSourceDetails)

        // Component* toDelete member
        toDelete = dragSourceDetails.sourceComponent.get(); 
        toMove = nullptr;

    void ParentComponent::dragOperationEnded()
        if (toDelete != nullptr)
            removeChildComponent (toDelete);
            items.removeObject (dynamic_cast <ModuleGui*> (toDelete));

I'm going in the right direction?

I was thinking to do it this way may be unsafe, What if two elements move at the same time? the above code will not work


what kind of drag-and-drop "stack" do you want exactly? Maybe in your case it would be easier to work with something like a ListBox?

Hi timur, 

I've solved it, I remove dragged components from container/target.

It is a audio plugin that host other plugins (using dynalicLibrary), the plugins only process audio. For the gui the plugin returns a const char* xml with the gui info. the pluginHost generates the gui for the plugin. 

The pluginHost shows the plugin gui inside a ModuleGuiComponent. To change the plugin order or delete instances, you can drag the plugin gui.