mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Il est desormais possible d'annuler les couper et les coller
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@135 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
13
diagram.cpp
13
diagram.cpp
@@ -252,10 +252,16 @@ QDomDocument Diagram::toXml(bool diagram) {
|
|||||||
(le bounding rect) soit a cette position.
|
(le bounding rect) soit a cette position.
|
||||||
@param document Le document XML a analyser
|
@param document Le document XML a analyser
|
||||||
@param position La position du diagram importe
|
@param position La position du diagram importe
|
||||||
@param consider_informations Si vrai, les informations complementaires (auteur, titre, ...) seront prises en compte
|
@param consider_informations Si vrai, les informations complementaires
|
||||||
|
(auteur, titre, ...) seront prises en compte
|
||||||
|
@param added_elements si ce pointeur vers une liste d'elements n'est pas
|
||||||
|
NULL, il sera rempli avec les elements ajoutes au schema par le fromXml
|
||||||
|
@param added_elements si ce pointeur vers une liste de conducteurs n'est
|
||||||
|
pas NULL, il sera rempli avec les conducteurs ajoutes au schema par le
|
||||||
|
fromXml
|
||||||
@return true si l'import a reussi, false sinon
|
@return true si l'import a reussi, false sinon
|
||||||
*/
|
*/
|
||||||
bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_informations) {
|
bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_informations, QList<Element *> *added_elements, QList<Conducer *> *added_conducers) {
|
||||||
QDomElement racine = document.documentElement();
|
QDomElement racine = document.documentElement();
|
||||||
// le premier element doit etre un schema
|
// le premier element doit etre un schema
|
||||||
if (racine.tagName() != "diagram") return(false);
|
if (racine.tagName() != "diagram") return(false);
|
||||||
@@ -322,6 +328,8 @@ bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (added_elements) (*added_elements) << elements_ajoutes;
|
||||||
|
|
||||||
// aucun Element n'a ete ajoute - inutile de chercher des conducteurs - le chargement est fini
|
// aucun Element n'a ete ajoute - inutile de chercher des conducteurs - le chargement est fini
|
||||||
if (!elements_ajoutes.size()) return(true);
|
if (!elements_ajoutes.size()) return(true);
|
||||||
|
|
||||||
@@ -374,6 +382,7 @@ bool Diagram::fromXml(QDomDocument &document, QPointF position, bool consider_in
|
|||||||
if (peut_poser_conducer) {
|
if (peut_poser_conducer) {
|
||||||
Conducer *c = new Conducer(table_adr_id.value(id_p1), table_adr_id.value(id_p2), 0, this);
|
Conducer *c = new Conducer(table_adr_id.value(id_p1), table_adr_id.value(id_p2), 0, this);
|
||||||
c -> fromXml(f);
|
c -> fromXml(f);
|
||||||
|
if (added_conducers) (*added_conducers) << c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else qDebug() << "Le chargement du conducer" << id_p1 << id_p2 << "a echoue";
|
} else qDebug() << "Le chargement du conducer" << id_p1 << id_p2 << "a echoue";
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class Diagram : public QGraphicsScene {
|
|||||||
|
|
||||||
// fonctions relatives a l'import / export XML
|
// fonctions relatives a l'import / export XML
|
||||||
QDomDocument toXml(bool = true);
|
QDomDocument toXml(bool = true);
|
||||||
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true);
|
bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, QList<Element *> * = NULL, QList<Conducer *> * = NULL);
|
||||||
|
|
||||||
// fonctions relatives aux options graphiques
|
// fonctions relatives aux options graphiques
|
||||||
void setDisplayGrid(bool);
|
void setDisplayGrid(bool);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ AddElementCommand::AddElementCommand(
|
|||||||
const QPointF &p,
|
const QPointF &p,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("ajout ") + elmt -> nom(), parent),
|
QUndoCommand(QObject::tr("ajouter 1 ") + elmt -> nom(), parent),
|
||||||
element(elmt),
|
element(elmt),
|
||||||
diagram(d),
|
diagram(d),
|
||||||
position(p)
|
position(p)
|
||||||
@@ -52,7 +52,7 @@ AddConducerCommand::AddConducerCommand(
|
|||||||
Conducer *c,
|
Conducer *c,
|
||||||
QUndoCommand *parent
|
QUndoCommand *parent
|
||||||
) :
|
) :
|
||||||
QUndoCommand(QObject::tr("ajout conducteur"), parent),
|
QUndoCommand(QObject::tr("ajouter un conducteur"), parent),
|
||||||
conducer(c),
|
conducer(c),
|
||||||
diagram(d)
|
diagram(d)
|
||||||
{
|
{
|
||||||
@@ -79,6 +79,10 @@ void AddConducerCommand::redo() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
|
@param dia Schema dont on supprime des elements et conducteurs
|
||||||
|
@param elements Elements supprimes
|
||||||
|
@param conducers Conducteurs supprimes
|
||||||
|
@param parent QUndoCommand parent
|
||||||
*/
|
*/
|
||||||
DeleteElementsCommand::DeleteElementsCommand(
|
DeleteElementsCommand::DeleteElementsCommand(
|
||||||
Diagram *dia,
|
Diagram *dia,
|
||||||
@@ -91,6 +95,7 @@ DeleteElementsCommand::DeleteElementsCommand(
|
|||||||
removed_conducers(conducers),
|
removed_conducers(conducers),
|
||||||
diagram(dia)
|
diagram(dia)
|
||||||
{
|
{
|
||||||
|
setText(QObject::tr("supprimer ") + QET::ElementsAndConducersSentence(removed_elements.count(), removed_conducers.count()));
|
||||||
foreach(QGraphicsItem *qgi, removed_elements) diagram -> qgiManager().manage(qgi);
|
foreach(QGraphicsItem *qgi, removed_elements) diagram -> qgiManager().manage(qgi);
|
||||||
foreach(QGraphicsItem *qgi, removed_conducers) diagram -> qgiManager().manage(qgi);
|
foreach(QGraphicsItem *qgi, removed_conducers) diagram -> qgiManager().manage(qgi);
|
||||||
}
|
}
|
||||||
@@ -130,3 +135,86 @@ void DeleteElementsCommand::redo() {
|
|||||||
diagram -> removeItem(e);
|
diagram -> removeItem(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param dia Schema sur lequel on colle les elements et conducteurs
|
||||||
|
@param e Elements colles sur le schema
|
||||||
|
@param c Conducteurs colles sur le schema
|
||||||
|
@param parent QUndoCommand parent
|
||||||
|
*/
|
||||||
|
PasteDiagramCommand::PasteDiagramCommand(
|
||||||
|
Diagram *dia,
|
||||||
|
const QList<Element *> &e,
|
||||||
|
const QList<Conducer *> &c,
|
||||||
|
QUndoCommand *parent
|
||||||
|
) :
|
||||||
|
QUndoCommand(parent),
|
||||||
|
elements(e),
|
||||||
|
conducers(c),
|
||||||
|
diagram(dia),
|
||||||
|
first_redo(true)
|
||||||
|
{
|
||||||
|
setText(QObject::tr("coller ") + QET::ElementsAndConducersSentence(elements.count(), conducers.count()));
|
||||||
|
foreach(QGraphicsItem *qgi, elements) diagram -> qgiManager().manage(qgi);
|
||||||
|
foreach(QGraphicsItem *qgi, conducers) diagram -> qgiManager().manage(qgi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
PasteDiagramCommand::~PasteDiagramCommand() {
|
||||||
|
foreach(QGraphicsItem *qgi, elements) diagram -> qgiManager().release(qgi);
|
||||||
|
foreach(QGraphicsItem *qgi, conducers) diagram -> qgiManager().release(qgi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// annule le coller
|
||||||
|
void PasteDiagramCommand::undo() {
|
||||||
|
// enleve les conducteurs
|
||||||
|
foreach(Conducer *c, conducers) {
|
||||||
|
c -> terminal1 -> removeConducer(c);
|
||||||
|
c -> terminal2 -> removeConducer(c);
|
||||||
|
diagram -> removeItem(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// enleve les elements
|
||||||
|
foreach(Element *e, elements) diagram -> removeItem(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// refait le coller
|
||||||
|
void PasteDiagramCommand::redo() {
|
||||||
|
if (first_redo) first_redo = false;
|
||||||
|
else {
|
||||||
|
// pose les elements
|
||||||
|
foreach(Element *e, elements) diagram -> addItem(e);
|
||||||
|
|
||||||
|
// pose les conducteurs
|
||||||
|
foreach(Conducer *c, conducers) {
|
||||||
|
diagram -> addItem(c);
|
||||||
|
c -> terminal1 -> addConducer(c);
|
||||||
|
c -> terminal2 -> addConducer(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach(Element *e, elements) e -> setSelected(true);
|
||||||
|
foreach(Conducer *c, conducers) c -> setSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur
|
||||||
|
@param dia Schema dont on supprime des elements et conducteurs
|
||||||
|
@param elements Elements supprimes
|
||||||
|
@param conducers Conducteurs supprimes
|
||||||
|
@param parent QUndoCommand parent
|
||||||
|
*/
|
||||||
|
CutDiagramCommand::CutDiagramCommand(
|
||||||
|
Diagram *dia,
|
||||||
|
QSet<Element *> elements,
|
||||||
|
QSet<Conducer *> conducers,
|
||||||
|
QUndoCommand *parent
|
||||||
|
) :
|
||||||
|
DeleteElementsCommand(dia, elements, conducers, parent)
|
||||||
|
{
|
||||||
|
setText(QObject::tr("couper ") + QET::ElementsAndConducersSentence(elements.count(), conducers.count()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Destructeur
|
||||||
|
CutDiagramCommand::~CutDiagramCommand() {
|
||||||
|
}
|
||||||
|
|||||||
@@ -76,4 +76,44 @@ class DeleteElementsCommand : public QUndoCommand {
|
|||||||
Diagram *diagram;
|
Diagram *diagram;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cette classe represente l'action de coller quelque chose sur un schema
|
||||||
|
*/
|
||||||
|
class PasteDiagramCommand : public QUndoCommand {
|
||||||
|
// constructeurs, destructeur
|
||||||
|
public:
|
||||||
|
PasteDiagramCommand(Diagram *, const QList<Element *> &, const QList<Conducer *> &, QUndoCommand * = 0);
|
||||||
|
virtual ~PasteDiagramCommand();
|
||||||
|
private:
|
||||||
|
PasteDiagramCommand(const PasteDiagramCommand &);
|
||||||
|
|
||||||
|
// methodes
|
||||||
|
virtual void undo();
|
||||||
|
virtual void redo();
|
||||||
|
|
||||||
|
// attributs
|
||||||
|
private:
|
||||||
|
/// Elements ajoutes
|
||||||
|
QList<Element *> elements;
|
||||||
|
/// conducteurs ajoutes
|
||||||
|
QList<Conducer *> conducers;
|
||||||
|
/// schema sur lequel on colle les elements et conducteurs
|
||||||
|
Diagram *diagram;
|
||||||
|
/// booleen pour empecher le premier appel a redo
|
||||||
|
bool first_redo;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Cette classe represente l'action de supprimer des elements et / ou
|
||||||
|
conducteurs d'un schema
|
||||||
|
*/
|
||||||
|
class CutDiagramCommand : public DeleteElementsCommand {
|
||||||
|
// constructeurs, destructeur
|
||||||
|
public:
|
||||||
|
CutDiagramCommand(Diagram *, QSet<Element *>, QSet<Conducer *>, QUndoCommand * = 0);
|
||||||
|
virtual ~CutDiagramCommand();
|
||||||
|
private:
|
||||||
|
CutDiagramCommand(const CutDiagramCommand &);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -213,7 +213,23 @@ void DiagramView::zoomReset() {
|
|||||||
*/
|
*/
|
||||||
void DiagramView::couper() {
|
void DiagramView::couper() {
|
||||||
copier();
|
copier();
|
||||||
supprimer();
|
QSet<Element *> cut_elmt;
|
||||||
|
QSet<Conducer *> cut_conducers;
|
||||||
|
|
||||||
|
// creation de deux listes : une pour les conducteurs, une pour les elements
|
||||||
|
foreach (QGraphicsItem *qgi, scene -> selectedItems()) {
|
||||||
|
// pour chaque qgi selectionne, il s'agit soit d'un element soit d'un conducteur
|
||||||
|
if (Conducer * c = qgraphicsitem_cast<Conducer *>(qgi)) {
|
||||||
|
// s'il s'agit d'un conducteur, on le met dans la liste des conducteurs
|
||||||
|
cut_conducers << c;
|
||||||
|
} else if (Element *e = qgraphicsitem_cast<Element *>(qgi)) {
|
||||||
|
cut_elmt << e;
|
||||||
|
// s'il s'agit d'un element, on veille a enlever ses conducteurs
|
||||||
|
cut_conducers += e -> conducers().toSet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scene -> clearSelection();
|
||||||
|
scene -> undoStack().push(new CutDiagramCommand(scene, cut_elmt, cut_conducers));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,7 +250,17 @@ void DiagramView::coller() {
|
|||||||
QDomDocument document_xml;
|
QDomDocument document_xml;
|
||||||
if ((texte_presse_papier = QApplication::clipboard() -> text()) == QString()) return;
|
if ((texte_presse_papier = QApplication::clipboard() -> text()) == QString()) return;
|
||||||
if (!document_xml.setContent(texte_presse_papier)) return;
|
if (!document_xml.setContent(texte_presse_papier)) return;
|
||||||
scene -> fromXml(document_xml, QPointF(), false);
|
|
||||||
|
// listes pour recupere les elements et conducteurs ajoutes au schema par le coller
|
||||||
|
QList<Element *> elements_pasted;
|
||||||
|
QList<Conducer *> conducers_pasted;
|
||||||
|
scene -> fromXml(document_xml, QPointF(), false, &elements_pasted, &conducers_pasted);
|
||||||
|
|
||||||
|
// si quelque chose a effectivement ete ajoute au schema, on cree
|
||||||
|
if (elements_pasted.count() || conducers_pasted.count()) {
|
||||||
|
scene -> clearSelection();
|
||||||
|
scene -> undoStack().push(new PasteDiagramCommand(scene, elements_pasted, conducers_pasted));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,9 +272,20 @@ void DiagramView::mousePressEvent(QMouseEvent *e) {
|
|||||||
QDomDocument document_xml;
|
QDomDocument document_xml;
|
||||||
if ((texte_presse_papier = QApplication::clipboard() -> text(QClipboard::Selection)) == QString()) return;
|
if ((texte_presse_papier = QApplication::clipboard() -> text(QClipboard::Selection)) == QString()) return;
|
||||||
if (!document_xml.setContent(texte_presse_papier)) return;
|
if (!document_xml.setContent(texte_presse_papier)) return;
|
||||||
scene -> fromXml(document_xml, mapToScene(e -> pos()), false);
|
|
||||||
|
// listes pour recupere les elements et conducteurs ajoutes au schema par le coller
|
||||||
|
QList<Element *> elements_pasted;
|
||||||
|
QList<Conducer *> conducers_pasted;
|
||||||
|
scene -> fromXml(document_xml, mapToScene(e -> pos()), false, &elements_pasted, &conducers_pasted);
|
||||||
|
|
||||||
|
// si quelque chose a effectivement ete ajoute au schema, on cree
|
||||||
|
if (elements_pasted.count() || conducers_pasted.count()) {
|
||||||
|
scene -> clearSelection();
|
||||||
|
scene -> undoStack().push(new PasteDiagramCommand(scene, elements_pasted, conducers_pasted));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QGraphicsView::mousePressEvent(e);
|
||||||
}
|
}
|
||||||
QGraphicsView::mousePressEvent(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -123,3 +123,23 @@ bool QET::attributeIsAReal(const QDomElement &e, QString nom_attribut, double *r
|
|||||||
if (reel != NULL) *reel = tmp;
|
if (reel != NULL) *reel = tmp;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Permet de composer rapidement la proposition "x elements et y conducteurs"
|
||||||
|
@param elements_count nombre d élements
|
||||||
|
@param conducers_count nombre de conducteurs
|
||||||
|
@return la proposition decrivant le nombre d'elements et de conducteurs
|
||||||
|
*/
|
||||||
|
QString QET::ElementsAndConducersSentence(int elements_count, int conducers_count) {
|
||||||
|
QString text;
|
||||||
|
if (elements_count) {
|
||||||
|
text += QString::number(elements_count) + " ";
|
||||||
|
text += elements_count > 1 ? QObject::tr("\351l\351ments") : QObject::tr("\351l\351ment");
|
||||||
|
if (conducers_count) text += QObject::tr(" et ");
|
||||||
|
}
|
||||||
|
if (conducers_count) {
|
||||||
|
text += QString::number(conducers_count) + " ";
|
||||||
|
text += conducers_count > 1 ? QObject::tr("conducteurs") : QObject::tr("conducteur");
|
||||||
|
}
|
||||||
|
return(text);
|
||||||
|
}
|
||||||
|
|||||||
1
qet.h
1
qet.h
@@ -18,5 +18,6 @@ namespace QET {
|
|||||||
bool estVerticale(QET::Orientation);
|
bool estVerticale(QET::Orientation);
|
||||||
bool attributeIsAnInteger(const QDomElement &, QString , int * = NULL);
|
bool attributeIsAnInteger(const QDomElement &, QString , int * = NULL);
|
||||||
bool attributeIsAReal(const QDomElement &, QString , double * = NULL);
|
bool attributeIsAReal(const QDomElement &, QString , double * = NULL);
|
||||||
|
QString ElementsAndConducersSentence(int, int);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user