mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Element editor : improve code
Better use of signal partsAdded and partsRemoved
This commit is contained in:
@@ -119,7 +119,6 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
if (m_event_interface->isFinish()) {
|
||||
delete m_event_interface;
|
||||
m_event_interface = nullptr;
|
||||
emit(partsAdded());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -151,7 +150,6 @@ void ElementScene::mousePressEvent(QGraphicsSceneMouseEvent *e)
|
||||
if (m_event_interface->isFinish()) {
|
||||
delete m_event_interface;
|
||||
m_event_interface = nullptr;
|
||||
emit(partsAdded());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -171,7 +169,6 @@ void ElementScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
|
||||
if (m_event_interface->isFinish()) {
|
||||
delete m_event_interface;
|
||||
m_event_interface = nullptr;
|
||||
emit(partsAdded());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -199,7 +196,6 @@ void ElementScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
if (m_event_interface->isFinish()) {
|
||||
delete m_event_interface;
|
||||
m_event_interface = nullptr;
|
||||
emit(partsAdded());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -223,7 +219,6 @@ void ElementScene::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
delete m_event_interface;
|
||||
m_event_interface = nullptr;
|
||||
emit(partsAdded());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -725,6 +720,38 @@ QETElementEditor* ElementScene::editor() const
|
||||
return m_element_editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementScene::addItems
|
||||
* Add items to the scene and emit partsAdded.
|
||||
* Prefer always use this method instead of QGraphicsScene::addItem
|
||||
* even if you want to add one item, for gain the signal emission
|
||||
* @param items
|
||||
*/
|
||||
void ElementScene::addItems(QVector<QGraphicsItem *> items)
|
||||
{
|
||||
for (const auto &item : items) {
|
||||
addItem(item);
|
||||
}
|
||||
|
||||
emit partsAdded();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementScene::removeItems
|
||||
* Remove items from the scene and emit partsRemoved.
|
||||
* Prefer always use this method instead of QGraphicsScene::removeItem
|
||||
* even if you want to remove one item, for gain the signal emission
|
||||
* @param items
|
||||
*/
|
||||
void ElementScene::removeItems(QVector<QGraphicsItem *> items)
|
||||
{
|
||||
for (const auto &item : items) {
|
||||
removeItem(item);
|
||||
}
|
||||
|
||||
emit partsRemoved();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ElementScene::slot_select
|
||||
Select the item in content,
|
||||
@@ -806,8 +833,7 @@ void ElementScene::slot_delete()
|
||||
m_undo_stack.push(new DeletePartsCommand(this, selected_items));
|
||||
|
||||
// removing items does not trigger QGraphicsScene::selectionChanged()
|
||||
emit(partsRemoved());
|
||||
emit(selectionChanged());
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user