mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
Amelioration de la classe DiagramContent
Modifications pour corriger quelques regressions git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@212 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
15
diagram.cpp
15
diagram.cpp
@@ -618,10 +618,25 @@ DiagramContent Diagram::content() const {
|
|||||||
@return le contenu selectionne du schema.
|
@return le contenu selectionne du schema.
|
||||||
*/
|
*/
|
||||||
DiagramContent Diagram::selectedContent() {
|
DiagramContent Diagram::selectedContent() {
|
||||||
|
invalidateMovedElements();
|
||||||
DiagramContent dc;
|
DiagramContent dc;
|
||||||
dc.elements = elementsToMove().toList();
|
dc.elements = elementsToMove().toList();
|
||||||
dc.textFields = textsToMove().toList();
|
dc.textFields = textsToMove().toList();
|
||||||
dc.conductorsToMove = conductorsToMove().toList();
|
dc.conductorsToMove = conductorsToMove().toList();
|
||||||
dc.conductorsToUpdate = conductorsToUpdate();
|
dc.conductorsToUpdate = conductorsToUpdate();
|
||||||
|
|
||||||
|
// recupere les conducteurs selectionnes isoles (= non deplacables mais supprimables)
|
||||||
|
foreach(QGraphicsItem *qgi, items()) {
|
||||||
|
if (Conductor *c = qgraphicsitem_cast<Conductor *>(qgi)) {
|
||||||
|
if (
|
||||||
|
c -> isSelected() &&\
|
||||||
|
!c -> terminal1 -> parentItem() -> isSelected() &&\
|
||||||
|
!c -> terminal2 -> parentItem() -> isSelected()
|
||||||
|
) {
|
||||||
|
dc.otherConductors << c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
invalidateMovedElements();
|
||||||
return(dc);
|
return(dc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,13 +124,13 @@ DeleteElementsCommand::DeleteElementsCommand(
|
|||||||
removed_content(content),
|
removed_content(content),
|
||||||
diagram(dia)
|
diagram(dia)
|
||||||
{
|
{
|
||||||
setText(QObject::tr("supprimer ") + removed_content.sentence(true));
|
setText(QObject::tr("supprimer ") + removed_content.sentence(DiagramContent::All));
|
||||||
diagram -> qgiManager().manage(removed_content.items());
|
diagram -> qgiManager().manage(removed_content.items(DiagramContent::All));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
DeleteElementsCommand::~DeleteElementsCommand() {
|
DeleteElementsCommand::~DeleteElementsCommand() {
|
||||||
diagram -> qgiManager().release(removed_content.items());
|
diagram -> qgiManager().release(removed_content.items(DiagramContent::All));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// annule les suppressions
|
/// annule les suppressions
|
||||||
@@ -141,7 +141,7 @@ void DeleteElementsCommand::undo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remet les conducteurs
|
// remet les conducteurs
|
||||||
foreach(Conductor *c, removed_content.conductors()) {
|
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||||
diagram -> addItem(c);
|
diagram -> addItem(c);
|
||||||
c -> terminal1 -> addConductor(c);
|
c -> terminal1 -> addConductor(c);
|
||||||
c -> terminal2 -> addConductor(c);
|
c -> terminal2 -> addConductor(c);
|
||||||
@@ -156,7 +156,7 @@ void DeleteElementsCommand::undo() {
|
|||||||
/// refait les suppressions
|
/// refait les suppressions
|
||||||
void DeleteElementsCommand::redo() {
|
void DeleteElementsCommand::redo() {
|
||||||
// enleve les conducteurs
|
// enleve les conducteurs
|
||||||
foreach(Conductor *c, removed_content.conductors()) {
|
foreach(Conductor *c, removed_content.conductors(DiagramContent::AnyConductor)) {
|
||||||
c -> terminal1 -> removeConductor(c);
|
c -> terminal1 -> removeConductor(c);
|
||||||
c -> terminal2 -> removeConductor(c);
|
c -> terminal2 -> removeConductor(c);
|
||||||
diagram -> removeItem(c);
|
diagram -> removeItem(c);
|
||||||
@@ -189,15 +189,17 @@ PasteDiagramCommand::PasteDiagramCommand(
|
|||||||
QUndoCommand(parent),
|
QUndoCommand(parent),
|
||||||
content(c),
|
content(c),
|
||||||
diagram(dia),
|
diagram(dia),
|
||||||
|
filter(DiagramContent::Elements|DiagramContent::TextFields|DiagramContent::ConductorsToMove),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
setText(QObject::tr("coller ") + content.sentence());
|
|
||||||
diagram -> qgiManager().manage(content.items());
|
setText(QObject::tr("coller ") + content.sentence(filter));
|
||||||
|
diagram -> qgiManager().manage(content.items(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
PasteDiagramCommand::~PasteDiagramCommand() {
|
PasteDiagramCommand::~PasteDiagramCommand() {
|
||||||
diagram -> qgiManager().release(content.items());
|
diagram -> qgiManager().release(content.items(filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// annule le coller
|
/// annule le coller
|
||||||
@@ -251,7 +253,7 @@ CutDiagramCommand::CutDiagramCommand(
|
|||||||
) :
|
) :
|
||||||
DeleteElementsCommand(dia, content, parent)
|
DeleteElementsCommand(dia, content, parent)
|
||||||
{
|
{
|
||||||
setText(QObject::tr("couper ") + content.sentence(true));
|
setText(QObject::tr("couper ") + content.sentence(DiagramContent::All));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -277,7 +279,7 @@ MoveElementsCommand::MoveElementsCommand(
|
|||||||
movement(m),
|
movement(m),
|
||||||
first_redo(true)
|
first_redo(true)
|
||||||
{
|
{
|
||||||
setText(QObject::tr("d\351placer ") + content_to_move.sentence());
|
setText(QObject::tr("d\351placer ") + content_to_move.sentence(DiagramContent::Elements|DiagramContent::TextFields|DiagramContent::ConductorsToUpdate|DiagramContent::ConductorsToMove));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ class PasteDiagramCommand : public QUndoCommand {
|
|||||||
DiagramContent content;
|
DiagramContent content;
|
||||||
/// schema sur lequel on colle les elements et conducteurs
|
/// schema sur lequel on colle les elements et conducteurs
|
||||||
Diagram *diagram;
|
Diagram *diagram;
|
||||||
|
/// entien pour filtrer le contenu du schema
|
||||||
|
int filter;
|
||||||
/// booleen pour empecher le premier appel a redo
|
/// booleen pour empecher le premier appel a redo
|
||||||
bool first_redo;
|
bool first_redo;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ DiagramContent::DiagramContent(const DiagramContent &other) :
|
|||||||
elements(other.elements),
|
elements(other.elements),
|
||||||
textFields(other.textFields),
|
textFields(other.textFields),
|
||||||
conductorsToUpdate(other.conductorsToUpdate),
|
conductorsToUpdate(other.conductorsToUpdate),
|
||||||
conductorsToMove(other.conductorsToMove)
|
conductorsToMove(other.conductorsToMove),
|
||||||
|
otherConductors(other.otherConductors)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,10 +29,15 @@ DiagramContent::~DiagramContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@param filter Types de conducteurs desires
|
||||||
@return tous les conducteurs
|
@return tous les conducteurs
|
||||||
*/
|
*/
|
||||||
QList<Conductor *> DiagramContent::conductors() const {
|
QList<Conductor *> DiagramContent::conductors(int filter) const {
|
||||||
return(conductorsToMove + conductorsToUpdate.keys());
|
QList<Conductor *> result;
|
||||||
|
if (filter & ConductorsToMove) result += conductorsToMove;
|
||||||
|
if (filter & ConductorsToUpdate) result += conductorsToUpdate.keys();
|
||||||
|
if (filter & OtherConductors) result += otherConductors;
|
||||||
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,50 +48,66 @@ void DiagramContent::clear() {
|
|||||||
textFields.clear();
|
textFields.clear();
|
||||||
conductorsToUpdate.clear();
|
conductorsToUpdate.clear();
|
||||||
conductorsToMove.clear();
|
conductorsToMove.clear();
|
||||||
|
otherConductors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@param filter Types desires
|
||||||
@return la liste des items formant le contenu du schema
|
@return la liste des items formant le contenu du schema
|
||||||
*/
|
*/
|
||||||
QList<QGraphicsItem *> DiagramContent::items() const {
|
QList<QGraphicsItem *> DiagramContent::items(int filter) const {
|
||||||
QList<QGraphicsItem *> items_list;
|
QList<QGraphicsItem *> items_list;
|
||||||
foreach(QGraphicsItem *qgi, conductors()) items_list << qgi;
|
foreach(QGraphicsItem *qgi, conductors(filter)) items_list << qgi;
|
||||||
foreach(QGraphicsItem *qgi, elements) items_list << qgi;
|
if (filter & Elements) foreach(QGraphicsItem *qgi, elements) items_list << qgi;
|
||||||
foreach(QGraphicsItem *qgi, textFields) items_list << qgi;
|
if (filter & TextFields) foreach(QGraphicsItem *qgi, textFields) items_list << qgi;
|
||||||
return(items_list);
|
return(items_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param include_updated_conductors true pour compter les conducteurs mis a jour, false sinon
|
@param filter Types desires
|
||||||
@return le nombre d'items formant le contenu du schema
|
@return le nombre d'items formant le contenu du schema
|
||||||
*/
|
*/
|
||||||
int DiagramContent::count(bool include_updated_conductors) const {
|
int DiagramContent::count(int filter) const {
|
||||||
int conductors_count = conductorsToMove.count();
|
int count = 0;
|
||||||
if (include_updated_conductors) conductors_count += conductorsToUpdate.count();
|
if (filter & Elements) count += elements.count();
|
||||||
|
if (filter & TextFields) count += textFields.count();
|
||||||
return(
|
if (filter & ConductorsToMove) count += conductorsToMove.count();
|
||||||
elements.count()
|
if (filter & ConductorsToUpdate) count += conductorsToUpdate.count();
|
||||||
+ textFields.count()
|
if (filter & OtherConductors) count += otherConductors.count();
|
||||||
+ conductors_count
|
return(count);
|
||||||
+ conductorsToUpdate.count()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Permet de composer rapidement la proposition "x elements, y conducteurs et
|
Permet de composer rapidement la proposition "x elements, y conducteurs et
|
||||||
z champs de texte".
|
z champs de texte".
|
||||||
@param include_updated_conductors true pour compter les conducteurs mis a jour, false sinon
|
@param filter Types desires
|
||||||
@return la proposition decrivant le contenu.
|
@return la proposition decrivant le contenu.
|
||||||
*/
|
*/
|
||||||
QString DiagramContent::sentence(bool include_updated_conductors) const {
|
QString DiagramContent::sentence(int filter) const {
|
||||||
int conductors_count = conductorsToMove.count();
|
int elements_count = (filter & Elements) ? elements.count() : 0;
|
||||||
if (include_updated_conductors) conductors_count += conductorsToUpdate.count();
|
int conductors_count = conductors(filter).count();
|
||||||
|
int textfields_count = (filter & TextFields) ? textFields.count() : 0;
|
||||||
|
|
||||||
return(
|
return(
|
||||||
QET::ElementsAndConductorsSentence(
|
QET::ElementsAndConductorsSentence(
|
||||||
elements.count(),
|
elements_count,
|
||||||
conductors_count,
|
conductors_count,
|
||||||
textFields.count()
|
textfields_count
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Permet de debugger un contenu de schema
|
||||||
|
@param d Object QDebug a utiliser pour l'affichage des informations de debug
|
||||||
|
@param c Contenu de schema a debugger
|
||||||
|
*/
|
||||||
|
QDebug &operator<<(QDebug d, DiagramContent &c) {
|
||||||
|
d << "DiagramContent {" << "\n";
|
||||||
|
d << " elements :" << c.elements << "\n";
|
||||||
|
d << " conductorsToUpdate :" << c.conductorsToUpdate.keys() << "\n";
|
||||||
|
d << " conductorsToMove :" << c.conductorsToMove << "\n";
|
||||||
|
d << " otherConductors :" << c.otherConductors << "\n";
|
||||||
|
d << "}";
|
||||||
|
return(d.space());
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,17 @@ class DiagramContent {
|
|||||||
DiagramContent(const DiagramContent &);
|
DiagramContent(const DiagramContent &);
|
||||||
~DiagramContent();
|
~DiagramContent();
|
||||||
|
|
||||||
|
/// Permet de filtrer facilement les differentes parties d'un schema
|
||||||
|
enum Filter {
|
||||||
|
Elements = 1,
|
||||||
|
TextFields = 2,
|
||||||
|
ConductorsToMove = 4,
|
||||||
|
ConductorsToUpdate = 8,
|
||||||
|
OtherConductors = 16,
|
||||||
|
AnyConductor = 28,
|
||||||
|
All = 31
|
||||||
|
};
|
||||||
|
|
||||||
/// Elements de texte du schema
|
/// Elements de texte du schema
|
||||||
QList<Element *> elements;
|
QList<Element *> elements;
|
||||||
/// Champs de texte du schema
|
/// Champs de texte du schema
|
||||||
@@ -29,11 +40,14 @@ class DiagramContent {
|
|||||||
QHash<Conductor *, Terminal *> conductorsToUpdate;
|
QHash<Conductor *, Terminal *> conductorsToUpdate;
|
||||||
/// Conducteurs a deplacer du schema
|
/// Conducteurs a deplacer du schema
|
||||||
QList<Conductor *> conductorsToMove;
|
QList<Conductor *> conductorsToMove;
|
||||||
|
/// Conducteurs isoles (ni a deplacer, ni a mettre a jour)
|
||||||
|
QList<Conductor *> otherConductors;
|
||||||
|
|
||||||
QList<Conductor *> conductors() const;
|
QList<Conductor *> conductors(int = AnyConductor) const;
|
||||||
QList<QGraphicsItem *> items() const;
|
QList<QGraphicsItem *> items(int = All) const;
|
||||||
QString sentence(bool = false) const;
|
QString sentence(int = All) const;
|
||||||
int count(bool = false) const;
|
int count(int = All) const;
|
||||||
void clear();
|
void clear();
|
||||||
};
|
};
|
||||||
|
QDebug &operator<<(QDebug, DiagramContent &);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -76,11 +76,6 @@ void DiagramView::selectInvert() {
|
|||||||
Supprime les composants selectionnes
|
Supprime les composants selectionnes
|
||||||
*/
|
*/
|
||||||
void DiagramView::deleteSelection() {
|
void DiagramView::deleteSelection() {
|
||||||
// si un item a le focus et que ce slot est appele, c'est sans doute parce
|
|
||||||
// que la touche suppr a ete enfoncee pour effacer une lettre et non la
|
|
||||||
// selection
|
|
||||||
if (scene -> focusItem()) return;
|
|
||||||
|
|
||||||
DiagramContent removed_content = scene -> selectedContent();
|
DiagramContent removed_content = scene -> selectedContent();
|
||||||
scene -> clearSelection();
|
scene -> clearSelection();
|
||||||
scene -> undoStack().push(new DeleteElementsCommand(scene, removed_content));
|
scene -> undoStack().push(new DeleteElementsCommand(scene, removed_content));
|
||||||
@@ -197,9 +192,9 @@ void DiagramView::zoomReset() {
|
|||||||
*/
|
*/
|
||||||
void DiagramView::cut() {
|
void DiagramView::cut() {
|
||||||
copy();
|
copy();
|
||||||
DiagramContent removed_content = scene -> selectedContent();
|
DiagramContent cut_content = scene -> selectedContent();
|
||||||
scene -> clearSelection();
|
scene -> clearSelection();
|
||||||
scene -> undoStack().push(new CutDiagramCommand(scene, scene -> selectedContent()));
|
scene -> undoStack().push(new CutDiagramCommand(scene, cut_content));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user