Simplification des mecanismes internes de selection sur les schemas.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@594 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2009-04-18 15:30:44 +00:00
parent 4fea5dee44
commit f23c1b1d93
5 changed files with 44 additions and 35 deletions

View File

@@ -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());
}
/**

View File

@@ -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);
};

View File

@@ -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();
}
/**

View File

@@ -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");
}

View File

@@ -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 *)));