mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Texts group can be removed with the delete key of keybord
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5142 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -174,6 +174,31 @@ QList<Conductor *> DiagramContent::conductors(int filter) const
|
||||
return(result.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramContent::hasDeletableItems
|
||||
* @return true if this diagram content have deletable item
|
||||
* The deletable items correspond to the selected items of diagram
|
||||
* at the moment of the creation of this DiagramContent,
|
||||
* with the constructor : DiagramContent::DiagramContent(Diagram *diagram)
|
||||
*/
|
||||
bool DiagramContent::hasDeletableItems() const
|
||||
{
|
||||
for(QGraphicsItem *qgi : m_selected_items)
|
||||
{
|
||||
if (qgi->type() == Element::Type ||
|
||||
qgi->type() == Conductor::Type ||
|
||||
qgi->type() == IndependentTextItem::Type ||
|
||||
qgi->type() == QetShapeItem::Type ||
|
||||
qgi->type() == DiagramImageItem::Type ||
|
||||
qgi->type() == DynamicElementTextItem::Type)
|
||||
return true;
|
||||
if(qgi->type() == QGraphicsItemGroup::Type)
|
||||
if(dynamic_cast<ElementTextItemGroup *>(qgi))
|
||||
return true;
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramContent::clear
|
||||
* Remove all items from the diagram content
|
||||
|
||||
@@ -79,6 +79,7 @@ class DiagramContent
|
||||
QList<DiagramTextItem *> selectedTexts() const;
|
||||
QList<ElementTextItemGroup *> selectedTextsGroup() const;
|
||||
QList<Conductor *> conductors(int = AnyConductor) const;
|
||||
bool hasDeletableItems() const;
|
||||
QList<QGraphicsItem *> items(int = All) const;
|
||||
QString sentence(int = All) const;
|
||||
int count(int = All) const;
|
||||
|
||||
@@ -126,20 +126,6 @@ void DiagramView::selectInvert() {
|
||||
m_diagram -> invertSelection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramView::deleteSelection
|
||||
* Delete the selected items
|
||||
*/
|
||||
void DiagramView::deleteSelection()
|
||||
{
|
||||
if (m_diagram -> isReadOnly())
|
||||
return;
|
||||
DiagramContent removed_content = DiagramContent(m_diagram);
|
||||
m_diagram->clearSelection();
|
||||
m_diagram->undoStack().push(new DeleteQGraphicsItemCommand(m_diagram, removed_content));
|
||||
adjustSceneRect();
|
||||
}
|
||||
|
||||
/**
|
||||
Accepte ou refuse le drag'n drop en fonction du type de donnees entrant
|
||||
@param e le QDragEnterEvent correspondant au drag'n drop tente
|
||||
@@ -750,25 +736,6 @@ bool DiagramView::hasTextItems() {
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DiagramView::hasDeletableItems
|
||||
* @return True if a least on of selected item can be deleted
|
||||
*/
|
||||
bool DiagramView::hasDeletableItems()
|
||||
{
|
||||
for(QGraphicsItem *qgi : m_diagram->selectedItems())
|
||||
{
|
||||
if (qgi->type() == Element::Type ||
|
||||
qgi->type() == Conductor::Type ||
|
||||
qgi->type() == IndependentTextItem::Type ||
|
||||
qgi->type() == QetShapeItem::Type ||
|
||||
qgi->type() == DiagramImageItem::Type ||
|
||||
qgi->type() == DynamicElementTextItem::Type)
|
||||
return true;
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
/**
|
||||
Ajoute une colonne au schema.
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,6 @@ class DiagramView : public QGraphicsView
|
||||
QETDiagramEditor *diagramEditor() const;
|
||||
bool hasCopiableItems();
|
||||
bool hasTextItems();
|
||||
bool hasDeletableItems();
|
||||
void editSelection();
|
||||
void setEventInterface (DVEventInterface *event_interface);
|
||||
|
||||
@@ -119,7 +118,6 @@ class DiagramView : public QGraphicsView
|
||||
void selectNothing();
|
||||
void selectAll();
|
||||
void selectInvert();
|
||||
void deleteSelection();
|
||||
void setVisualisationMode();
|
||||
void setSelectionMode();
|
||||
void zoom(const qreal zoom_factor);
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include "elementtextitem.h"
|
||||
#include "undocommand/rotateselectioncommand.h"
|
||||
#include "rotatetextscommand.h"
|
||||
#include "diagramcommands.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QStandardPaths>
|
||||
@@ -1261,23 +1262,25 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action)
|
||||
{
|
||||
QString value = action->data().toString();
|
||||
DiagramView *dv = currentDiagram();
|
||||
Diagram *diagram = dv->diagram();
|
||||
DiagramContent dc(diagram);
|
||||
|
||||
if (!dv || value.isEmpty()) return;
|
||||
|
||||
if (value == "delete_selection")
|
||||
dv->deleteSelection();
|
||||
{
|
||||
diagram->clearSelection();
|
||||
diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc));
|
||||
dv->adjustSceneRect();
|
||||
}
|
||||
else if (value == "rotate_selection")
|
||||
{
|
||||
Diagram *d = dv->diagram();
|
||||
RotateSelectionCommand *c = new RotateSelectionCommand(d);
|
||||
RotateSelectionCommand *c = new RotateSelectionCommand(diagram);
|
||||
if(c->isValid())
|
||||
d->undoStack().push(c);
|
||||
diagram->undoStack().push(c);
|
||||
}
|
||||
else if (value == "rotate_selected_text")
|
||||
{
|
||||
Diagram *d = dv->diagram();
|
||||
d->undoStack().push(new RotateTextsCommand(d));
|
||||
}
|
||||
diagram->undoStack().push(new RotateTextsCommand(diagram));
|
||||
else if (value == "find_selected_element" && currentCustomElement())
|
||||
findElementInPanel(currentCustomElement()->location());
|
||||
else if (value == "edit_selected_element")
|
||||
@@ -1427,7 +1430,7 @@ void QETDiagramEditor::slot_updateComplexActions()
|
||||
|
||||
//Action that need items (elements, conductors, texts...) selected, to be enabled
|
||||
bool copiable_items = dv->hasCopiableItems();
|
||||
bool deletable_items = dv->hasDeletableItems();
|
||||
bool deletable_items = dc.hasDeletableItems();
|
||||
m_cut -> setEnabled(!ro && copiable_items);
|
||||
m_copy -> setEnabled(copiable_items);
|
||||
m_delete_selection -> setEnabled(!ro && deletable_items);
|
||||
|
||||
@@ -452,7 +452,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
|
||||
quc->setText(tr("Modifier la couleur d'un texte d'élément"));
|
||||
}
|
||||
|
||||
bool frame = text_qsi->child(4,1)->checkState() == Qt::Checked? frame=true : frame=false;
|
||||
bool frame = text_qsi->child(4,1)->checkState() == Qt::Checked? true : false;
|
||||
if(frame != deti->frame())
|
||||
{
|
||||
QUndoCommand *quc = new QPropertyUndoCommand(deti, "frame", QVariant(deti->frame()), QVariant(frame), undo);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "conductor.h"
|
||||
#include "conductortextitem.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "addelementtextcommand.h"
|
||||
|
||||
/**
|
||||
* @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
|
||||
@@ -44,6 +45,8 @@ DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(Diagram *diagram, const D
|
||||
|
||||
}
|
||||
|
||||
//When remove a deti we must to know his parent item, for re-add deti as child of the parent
|
||||
//when undo this command
|
||||
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||
{
|
||||
if(deti->parentGroup())
|
||||
@@ -52,6 +55,21 @@ DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(Diagram *diagram, const D
|
||||
m_elmt_text_hash.insert(deti, deti->parentElement());
|
||||
}
|
||||
|
||||
//If parent element of ElementTextItemGroup is also in @m_removed_content,
|
||||
//we remove it, because when the element will be removed from the scene every child's will also be removed.
|
||||
const QSet<ElementTextItemGroup *> group_set = m_removed_contents.m_texts_groups;
|
||||
for(ElementTextItemGroup *group : group_set)
|
||||
{
|
||||
if(m_removed_contents.m_elements.contains(group->parentElement()))
|
||||
m_removed_contents.m_texts_groups.remove(group);
|
||||
}
|
||||
|
||||
//The deletion of the groups is not managed by this undo, but by a RemoveTextsGroupCommand
|
||||
for(ElementTextItemGroup *group : m_removed_contents.m_texts_groups) {
|
||||
new RemoveTextsGroupCommand(group->parentElement(), group, this);}
|
||||
|
||||
m_removed_contents.m_texts_groups.clear();
|
||||
|
||||
setText(QString(QObject::tr("supprimer %1", "undo caption - %1 is a sentence listing the removed content")).arg(m_removed_contents.sentence(DiagramContent::All)));
|
||||
m_diagram->qgiManager().manage(m_removed_contents.items(DiagramContent::All));
|
||||
}
|
||||
@@ -87,6 +105,8 @@ void DeleteQGraphicsItemCommand::undo()
|
||||
elmt->addTextToGroup(deti, m_grp_texts_hash.value(deti));
|
||||
}
|
||||
}
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,4 +151,6 @@ void DeleteQGraphicsItemCommand::redo()
|
||||
|
||||
for(QGraphicsItem *item : m_removed_contents.items())
|
||||
m_diagram->removeItem(item);
|
||||
|
||||
QUndoCommand::redo();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user