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());
|
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
|
* @brief DiagramContent::clear
|
||||||
* Remove all items from the diagram content
|
* Remove all items from the diagram content
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class DiagramContent
|
|||||||
QList<DiagramTextItem *> selectedTexts() const;
|
QList<DiagramTextItem *> selectedTexts() const;
|
||||||
QList<ElementTextItemGroup *> selectedTextsGroup() const;
|
QList<ElementTextItemGroup *> selectedTextsGroup() const;
|
||||||
QList<Conductor *> conductors(int = AnyConductor) const;
|
QList<Conductor *> conductors(int = AnyConductor) const;
|
||||||
|
bool hasDeletableItems() const;
|
||||||
QList<QGraphicsItem *> items(int = All) const;
|
QList<QGraphicsItem *> items(int = All) const;
|
||||||
QString sentence(int = All) const;
|
QString sentence(int = All) const;
|
||||||
int count(int = All) const;
|
int count(int = All) const;
|
||||||
|
|||||||
@@ -126,20 +126,6 @@ void DiagramView::selectInvert() {
|
|||||||
m_diagram -> invertSelection();
|
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
|
Accepte ou refuse le drag'n drop en fonction du type de donnees entrant
|
||||||
@param e le QDragEnterEvent correspondant au drag'n drop tente
|
@param e le QDragEnterEvent correspondant au drag'n drop tente
|
||||||
@@ -750,25 +736,6 @@ bool DiagramView::hasTextItems() {
|
|||||||
return(false);
|
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.
|
Ajoute une colonne au schema.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ class DiagramView : public QGraphicsView
|
|||||||
QETDiagramEditor *diagramEditor() const;
|
QETDiagramEditor *diagramEditor() const;
|
||||||
bool hasCopiableItems();
|
bool hasCopiableItems();
|
||||||
bool hasTextItems();
|
bool hasTextItems();
|
||||||
bool hasDeletableItems();
|
|
||||||
void editSelection();
|
void editSelection();
|
||||||
void setEventInterface (DVEventInterface *event_interface);
|
void setEventInterface (DVEventInterface *event_interface);
|
||||||
|
|
||||||
@@ -119,7 +118,6 @@ class DiagramView : public QGraphicsView
|
|||||||
void selectNothing();
|
void selectNothing();
|
||||||
void selectAll();
|
void selectAll();
|
||||||
void selectInvert();
|
void selectInvert();
|
||||||
void deleteSelection();
|
|
||||||
void setVisualisationMode();
|
void setVisualisationMode();
|
||||||
void setSelectionMode();
|
void setSelectionMode();
|
||||||
void zoom(const qreal zoom_factor);
|
void zoom(const qreal zoom_factor);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include "elementtextitem.h"
|
#include "elementtextitem.h"
|
||||||
#include "undocommand/rotateselectioncommand.h"
|
#include "undocommand/rotateselectioncommand.h"
|
||||||
#include "rotatetextscommand.h"
|
#include "rotatetextscommand.h"
|
||||||
|
#include "diagramcommands.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
@@ -1261,23 +1262,25 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action)
|
|||||||
{
|
{
|
||||||
QString value = action->data().toString();
|
QString value = action->data().toString();
|
||||||
DiagramView *dv = currentDiagram();
|
DiagramView *dv = currentDiagram();
|
||||||
|
Diagram *diagram = dv->diagram();
|
||||||
|
DiagramContent dc(diagram);
|
||||||
|
|
||||||
if (!dv || value.isEmpty()) return;
|
if (!dv || value.isEmpty()) return;
|
||||||
|
|
||||||
if (value == "delete_selection")
|
if (value == "delete_selection")
|
||||||
dv->deleteSelection();
|
{
|
||||||
|
diagram->clearSelection();
|
||||||
|
diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc));
|
||||||
|
dv->adjustSceneRect();
|
||||||
|
}
|
||||||
else if (value == "rotate_selection")
|
else if (value == "rotate_selection")
|
||||||
{
|
{
|
||||||
Diagram *d = dv->diagram();
|
RotateSelectionCommand *c = new RotateSelectionCommand(diagram);
|
||||||
RotateSelectionCommand *c = new RotateSelectionCommand(d);
|
|
||||||
if(c->isValid())
|
if(c->isValid())
|
||||||
d->undoStack().push(c);
|
diagram->undoStack().push(c);
|
||||||
}
|
}
|
||||||
else if (value == "rotate_selected_text")
|
else if (value == "rotate_selected_text")
|
||||||
{
|
diagram->undoStack().push(new RotateTextsCommand(diagram));
|
||||||
Diagram *d = dv->diagram();
|
|
||||||
d->undoStack().push(new RotateTextsCommand(d));
|
|
||||||
}
|
|
||||||
else if (value == "find_selected_element" && currentCustomElement())
|
else if (value == "find_selected_element" && currentCustomElement())
|
||||||
findElementInPanel(currentCustomElement()->location());
|
findElementInPanel(currentCustomElement()->location());
|
||||||
else if (value == "edit_selected_element")
|
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
|
//Action that need items (elements, conductors, texts...) selected, to be enabled
|
||||||
bool copiable_items = dv->hasCopiableItems();
|
bool copiable_items = dv->hasCopiableItems();
|
||||||
bool deletable_items = dv->hasDeletableItems();
|
bool deletable_items = dc.hasDeletableItems();
|
||||||
m_cut -> setEnabled(!ro && copiable_items);
|
m_cut -> setEnabled(!ro && copiable_items);
|
||||||
m_copy -> setEnabled(copiable_items);
|
m_copy -> setEnabled(copiable_items);
|
||||||
m_delete_selection -> setEnabled(!ro && deletable_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"));
|
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())
|
if(frame != deti->frame())
|
||||||
{
|
{
|
||||||
QUndoCommand *quc = new QPropertyUndoCommand(deti, "frame", QVariant(deti->frame()), QVariant(frame), undo);
|
QUndoCommand *quc = new QPropertyUndoCommand(deti, "frame", QVariant(deti->frame()), QVariant(frame), undo);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "conductortextitem.h"
|
#include "conductortextitem.h"
|
||||||
#include "elementtextitemgroup.h"
|
#include "elementtextitemgroup.h"
|
||||||
|
#include "addelementtextcommand.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
|
* @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)
|
for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
|
||||||
{
|
{
|
||||||
if(deti->parentGroup())
|
if(deti->parentGroup())
|
||||||
@@ -52,6 +55,21 @@ DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand(Diagram *diagram, const D
|
|||||||
m_elmt_text_hash.insert(deti, deti->parentElement());
|
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)));
|
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));
|
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));
|
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())
|
for(QGraphicsItem *item : m_removed_contents.items())
|
||||||
m_diagram->removeItem(item);
|
m_diagram->removeItem(item);
|
||||||
|
|
||||||
|
QUndoCommand::redo();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user