Place an element from the collection without dragging it

DiagramEventAddElement is already a good placement mode: the element
follows the cursor on the grid, a left click drops it, Space rotates it,
and it stays loaded for a run of the same symbol. Its only caller was
DiagramView::handleElementDrop(), so it could be reached only by
finishing a drag. Double-clicking a symbol in the Collections dock
opened the element editor instead.

- DiagramView::startElementPlacement() is split out of
  handleElementDrop(). defaultPlacementPos() uses the cursor when it is
  over the view and the centre of the visible area otherwise.

- ElementsCollectionWidget emits insertElementRequested() on double
  click, or Enter on the highlighted item. The host decides which view
  receives it, so the widget can later be reused outside the editor.

- When there is nowhere to place it (no folio open, read-only project),
  the element editor opens, as a double click did before.

- "Insérer le dernier élément" (Édition menu, default key A) places the
  last element again. DiagramView reports every placement it starts, so
  an element dropped by drag counts too. Macros are not remembered.

A rather than Space: Space rotates the pending element inside placement
mode and is bound three more times in this editor. The key is a
ShortcutManager default and can be changed in the Shortcuts page.

Double click placing is a behaviour change, so it has a preference,
"elementscollection/double-click-inserts" (default true), shown in
Configuration as an opt-out: "Double-cliquer dans la collection ouvre
l'éditeur d'élément au lieu de l'insérer".

Discussions #676 and #1033.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
ispyisail
2026-08-08 17:18:30 +12:00
parent 4cffdf93b6
commit e6291eb8e8
8 changed files with 259 additions and 23 deletions
+77
View File
@@ -226,6 +226,13 @@ void QETDiagramEditor::setUpElementsCollectionWidget()
m_qdw_elmt_collection->setWidget(m_element_collection_widget);
m_element_collection_widget->expandFirstItems();
//The widget does not know which view should receive the element -- it
//is also used by the picker popup, which has no editor ancestor -- so
//the host decides.
connect(m_element_collection_widget,
&ElementsCollectionWidget::insertElementRequested,
this, &QETDiagramEditor::insertElementFromCollection);
addDockWidget(Qt::RightDockWidgetArea, m_qdw_elmt_collection);
}
@@ -755,6 +762,26 @@ void QETDiagramEditor::setUpActions()
ShortcutManager::instance().registerAction(m_rotate_texts, "diagrameditor.rotate_texts", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_Space);
ShortcutManager::instance().registerAction(m_edit_selection, "diagrameditor.edit_selection", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_E);
//Re-enter placement mode with the element placed last. Bare A rather
//than Space: Space already rotates the pending element *inside*
//placement mode (diagrameventaddelement.cpp), and is taken three times
//over in this editor besides. A matches KiCad's add-symbol key and
//reads correctly in the source language ("Ajouter"). ShortcutManager
//makes it a default, not a commitment -- it appears in the Shortcuts
//preference page like every other binding.
m_insert_last_element = new QAction(QET::Icons::ElementNew,
tr("Insérer le dernier élément"), this);
m_insert_last_element->setStatusTip(
tr("Place à nouveau le dernier élément inséré", "status bar tip"));
m_insert_last_element->setData("insert_last_element");
m_insert_last_element->setEnabled(false);
ShortcutManager::instance().registerAction(
m_insert_last_element, "diagrameditor.insert_last_element",
tr("Éditeur de schémas"), Qt::Key_A);
connect(m_insert_last_element, &QAction::triggered,
this, &QETDiagramEditor::insertLastElement);
addAction(m_insert_last_element);
m_delete_selection->setStatusTip( tr("Enlève les éléments sélectionnés du folio", "status bar tip"));
m_rotate_selection->setStatusTip( tr("Pivote les éléments et textes sélectionnés", "status bar tip"));
m_rotate_group_selection->setStatusTip( tr("Pivote la sélection comme un groupe autour de son centre, au lieu de chaque élément sur place", "status bar tip"));
@@ -1038,6 +1065,7 @@ void QETDiagramEditor::setUpMenu()
menu_edition -> addAction(m_paste);
menu_edition -> addAction(m_duplicate);
menu_edition -> addAction(m_configure_duplicate);
menu_edition -> addAction(m_insert_last_element);
menu_edition -> addSeparator();
//The same actions the "Ajouter" toolbar holds. They were toolbar-only,
//which left them unreachable for anyone working without a mouse: a
@@ -1937,6 +1965,7 @@ void QETDiagramEditor::slot_updateActions()
m_zoom_actions_group. setEnabled(opened_diagram);
m_select_actions_group. setEnabled(opened_diagram);
m_add_item_actions_group. setEnabled(editable_project);
m_insert_last_element-> setEnabled(opened_diagram && editable_project && !m_last_inserted_element.isNull());
m_row_column_actions_group. setEnabled(editable_project);
m_background_color_button-> setEnabled(opened_diagram);
m_draw_grid-> setEnabled(opened_diagram);
@@ -2830,6 +2859,7 @@ void QETDiagramEditor::diagramWasAdded(DiagramView *dv)
&QETDiagramEditor::selectionChanged,
Qt::DirectConnection);
connect(dv, &DiagramView::modeChanged, this, &QETDiagramEditor::slot_updateModeActions);
connect(dv, &DiagramView::elementPlacementStarted, this, &QETDiagramEditor::rememberPlacedElement);
}
/**
@@ -2939,6 +2969,53 @@ void QETDiagramEditor::selectionChanged()
}
/**
@brief QETDiagramEditor::insertElementFromCollection
Place @a location on the current folio using the interactive placement
mode -- the same mode a drag and drop ends in, entered without the drag.
@param location
*/
void QETDiagramEditor::insertElementFromCollection(const ElementsLocation &location)
{
DiagramView *dv = currentDiagramView();
if (dv && dv->startElementPlacement(location, dv->defaultPlacementPos())) {
return;
}
//Nowhere to place it: no folio open, or a read-only project. Do what
//a double click did before it placed, rather than nothing.
m_element_collection_widget->editLocation(location);
}
/**
@brief QETDiagramEditor::rememberPlacedElement
Remember @a location for "insert last element". Connected to every view,
so an element placed by drag and drop counts as well as one placed from
the collection without a drag. Macros never reach here: the view does not
report them, since re-entering their placement mode from a shortcut has
not been thought through.
@param location
*/
void QETDiagramEditor::rememberPlacedElement(const ElementsLocation &location)
{
m_last_inserted_element = location;
m_insert_last_element->setEnabled(true);
}
/**
@brief QETDiagramEditor::insertLastElement
Re-enter placement mode with the element placed most recently, so a run of
the same symbol can be dropped without returning to the collection.
*/
void QETDiagramEditor::insertLastElement()
{
if (!m_last_inserted_element.isElement()
|| !m_last_inserted_element.exist()) {
return;
}
insertElementFromCollection(m_last_inserted_element);
}
/**
@brief QETDiagramEditor::generateTerminalBlock
*/