diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 44168f307..5f45f923b 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -54,7 +54,6 @@ Diagram::Diagram(QObject *parent) : t.setStyle(Qt::DashLine); conductor_setter -> setPen(t); conductor_setter -> setLine(QLineF(QPointF(0.0, 0.0), QPointF(0.0, 0.0))); - connect(this, SIGNAL(selectionChanged()), this, SLOT(slot_checkSelectionEmptinessChange())); } /** @@ -533,7 +532,7 @@ bool Diagram::fromXml(QDomElement &document, QPointF position, bool consider_inf content_ptr -> textFields = added_texts; } - write(document); + write(); return(true); } @@ -705,17 +704,36 @@ void Diagram::diagramTextChanged(DiagramTextItem *text_item, const QString &old_ } /** - Verifie si la selection est passe d'un etat ou elle est vide a un etat ou - elle ne l'est pas, et inversement. Si c'est le cas, le signal - EmptinessChanged() est emis. + Selectionne tous les objets du schema */ -void Diagram::slot_checkSelectionEmptinessChange() { - static bool selection_was_empty = true; - bool selection_is_empty = selectedItems().isEmpty(); - if (selection_was_empty != selection_is_empty) { - emit(selectionEmptinessChanged()); - selection_was_empty = selection_is_empty; - } +void Diagram::selectAll() { + if (items().isEmpty()) return; + + blockSignals(true); + foreach(QGraphicsItem *qgi, items()) qgi -> setSelected(true); + blockSignals(false); + emit(selectionChanged()); +} + +/** + Deslectionne tous les objets selectionnes +*/ +void Diagram::deselectAll() { + if (items().isEmpty()) return; + + clearSelection(); +} + +/** + Inverse l'etat de selection de tous les objets du schema +*/ +void Diagram::invertSelection() { + if (items().isEmpty()) return; + + blockSignals(true); + foreach (QGraphicsItem *item, items()) item -> setSelected(!item -> isSelected()); + blockSignals(false); + emit(selectionChanged()); } /** diff --git a/sources/diagram.h b/sources/diagram.h index 364035ebc..0d02e663a 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -161,16 +161,12 @@ class Diagram : public QGraphicsScene { public slots: void diagramTextChanged(DiagramTextItem *, const QString &, const QString &); - private slots: - void slot_checkSelectionEmptinessChange(); + // fonctions relative a la selection sur le schema + void selectAll(); + void deselectAll(); + void invertSelection(); signals: - /** - Ce signal est emis lorsque la selection passe de l'etat rempli (par un - nombre quelconque d'elements et conducteurs) a l'etat vide et - vice-versa. - */ - void selectionEmptinessChanged(); void written(); void readOnlyChanged(bool); }; diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 93b7ec480..13e8498a8 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -57,7 +57,7 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(pare paste_here = new QAction(QIcon(":/ico/paste.png"), tr("Coller ici", "context menu action"), this); connect(paste_here, SIGNAL(triggered()), this, SLOT(pasteHere())); - connect(scene, SIGNAL(selectionEmptinessChanged()), this, SIGNAL(selectionChanged())); + connect(scene, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); connect(scene, SIGNAL(readOnlyChanged(bool)), this, SLOT(applyReadOnly())); connect(&(scene -> border_and_inset), SIGNAL(borderChanged(QRectF, QRectF)), this, SLOT(adjustSceneRect())); connect(&(scene -> border_and_inset), SIGNAL(displayChanged()), this, SLOT(adjustSceneRect())); @@ -74,29 +74,24 @@ DiagramView::~DiagramView() { } /** - Appelle la methode select sur tous les elements de la liste d'elements + Selectionne tous les objets du schema */ void DiagramView::selectAll() { - if (scene -> items().isEmpty()) return; - QPainterPath path; - path.addRect(scene -> itemsBoundingRect()); - scene -> setSelectionArea(path); + scene -> selectAll(); } /** - appelle la methode deselect sur tous les elements de la liste d'elements + Deslectionne tous les objets selectionnes */ void DiagramView::selectNothing() { - if (scene -> items().isEmpty()) return; - scene -> clearSelection(); + scene -> deselectAll(); } /** - Inverse l'etat de selection de tous les elements de la liste d'elements - */ + Inverse l'etat de selection de tous les objets du schema +*/ void DiagramView::selectInvert() { - if (scene -> items().isEmpty()) return; - foreach (QGraphicsItem *item, scene -> items()) item -> setSelected(!item -> isSelected()); + scene -> invertSelection(); } /** diff --git a/sources/elementtextitem.cpp b/sources/elementtextitem.cpp index 5fa479bc7..d121953e6 100644 --- a/sources/elementtextitem.cpp +++ b/sources/elementtextitem.cpp @@ -86,7 +86,7 @@ QPointF ElementTextItem::pos() const { */ void ElementTextItem::fromXml(const QDomElement &e) { QPointF _pos = pos(); - if (e.attribute("x").toDouble() == _pos.x() && e.attribute("y").toDouble() == _pos.y()) { + if (qFuzzyCompare(e.attribute("x").toDouble(), _pos.x()) && qFuzzyCompare(e.attribute("y").toDouble(), _pos.y())) { setPlainText(e.attribute("text")); previous_text = e.attribute("text"); } diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index f84f8effb..4833004d0 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1628,7 +1628,7 @@ void QETDiagramEditor::removeDiagramFromProject() { void QETDiagramEditor::diagramWasAdded(DiagramView *dv) { // quand on change qqc a l'interieur d'un schema, on met a jour les menus undo_group.addStack(&(dv -> diagram() -> undoStack())); - connect(dv -> diagram(), SIGNAL(selectionChanged()), this, SLOT(slot_updateComplexActions())); + connect(dv, SIGNAL(selectionChanged()), this, SLOT(slot_updateComplexActions())); connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions())); connect(dv, SIGNAL(textAdded(bool)), add_text, SLOT(setChecked(bool))); connect(dv, SIGNAL(titleChanged(DiagramView *, const QString &)), this, SLOT(diagramTitleChanged(DiagramView *)));