From fae3cf33bd633c7cb3ec064f35dde26ac6510e0f Mon Sep 17 00:00:00 2001 From: blacksun Date: Sat, 16 Mar 2019 11:34:52 +0000 Subject: [PATCH] Fix behavior when use arrow key with dynamic element text item and element text item group git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5789 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagramcommands.cpp | 5 +++-- sources/diagramcontent.cpp | 15 +++++++++++++++ sources/diagramcontent.h | 1 + sources/diagramview.cpp | 8 ++++---- sources/elementsmover.cpp | 30 ++++++++++++++++++++++++------ 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index 666ba277f..6b3879c56 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -191,7 +191,8 @@ MoveElementsCommand::MoveElementsCommand( DiagramContent::ConductorsToUpdate | DiagramContent::ConductorsToMove | DiagramContent::Images | - DiagramContent::Shapes + DiagramContent::Shapes | + DiagramContent::ElementTextFields ); setText( @@ -248,7 +249,7 @@ void MoveElementsCommand::move(const QPointF &actual_movement) typedef DiagramContent dc; //Move every movable items, except conductor - for (QGraphicsItem *qgi : content_to_move.items(dc::Elements | dc::TextFields | dc::Images | dc::Shapes | dc::TextGroup)) + for (QGraphicsItem *qgi : content_to_move.items(dc::Elements | dc::TextFields | dc::Images | dc::Shapes | dc::TextGroup | dc::ElementTextFields)) { //If curent item have parent, and parent item is in content_to_move //we don't apply movement to this item, because this item will be moved by is parent. diff --git a/sources/diagramcontent.cpp b/sources/diagramcontent.cpp index 141bb6f51..fbb876eb4 100644 --- a/sources/diagramcontent.cpp +++ b/sources/diagramcontent.cpp @@ -355,6 +355,21 @@ bool DiagramContent::potentialIsManaged(QList conductors) return b; } +/** + * @brief DiagramContent::hasTextEditing + * @return true if handle a text currently in editing intercation + */ +bool DiagramContent::hasTextEditing() +{ + for (DiagramTextItem *dti : selectedTexts()) { + if (dti->textInteractionFlags() == Qt::TextEditorInteraction) { + return true; + } + } + + return false; +} + /** * @brief DiagramContent::items * @param filter diff --git a/sources/diagramcontent.h b/sources/diagramcontent.h index adf068102..c4611da50 100644 --- a/sources/diagramcontent.h +++ b/sources/diagramcontent.h @@ -89,6 +89,7 @@ class DiagramContent DiagramContent& operator+=(const DiagramContent& other); bool potentialIsManaged(QListconductors); + bool hasTextEditing(); }; QDebug &operator<<(QDebug, DiagramContent &); #endif diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 5a6a5eff2..70434060c 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -703,22 +703,22 @@ void DiagramView::keyPressEvent(QKeyEvent *e) } break; case Qt::Key_Up: { - if(!(dc.items(DiagramContent::All).isEmpty())) + if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing()) scrollOnMovement(e); } break; case Qt::Key_Down: { - if(!(dc.items(DiagramContent::All).isEmpty())) + if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing()) scrollOnMovement(e); } break; case Qt::Key_Left: { - if(!(dc.items(DiagramContent::All).isEmpty())) + if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing()) scrollOnMovement(e); } break; case Qt::Key_Right: { - if(!(dc.items(DiagramContent::All).isEmpty())) + if(!dc.items(DiagramContent::All).isEmpty() && !dc.hasTextEditing()) scrollOnMovement(e); } break; diff --git a/sources/elementsmover.cpp b/sources/elementsmover.cpp index 83760a585..d584e0ef2 100644 --- a/sources/elementsmover.cpp +++ b/sources/elementsmover.cpp @@ -24,6 +24,8 @@ #include "independenttextitem.h" #include "diagramimageitem.h" #include "conductorautonumerotation.h" +#include "dynamicelementtextitem.h" +#include "elementtextitemgroup.h" /** * @brief ElementsMover::ElementsMover Constructor @@ -60,23 +62,39 @@ bool ElementsMover::isReady() const { * @param driver_item item moved by mouse and don't be moved by Element mover * @return the numbers of items to be moved or -1 if movement can't be init. */ -int ElementsMover::beginMovement(Diagram *diagram, QGraphicsItem *driver_item) { - // They must be no movement in progress +int ElementsMover::beginMovement(Diagram *diagram, QGraphicsItem *driver_item) +{ + // They must be no movement in progress if (movement_running_) return(-1); - // Be sure we have diagram to work + // Be sure we have diagram to work if (!diagram) return(-1); diagram_ = diagram; - // Take count of driver item + // Take count of driver item m_movement_driver = driver_item; - // At the beginning of movement, move is NULL + // At the beginning of movement, move is NULL current_movement_ = QPointF(0.0, 0.0); m_moved_content = DiagramContent(diagram); m_moved_content.removeNonMovableItems(); + //Remove element text, if the parent element is selected. + QList deti_list = m_moved_content.m_element_texts.toList(); + for(DynamicElementTextItem *deti : deti_list) { + if(m_moved_content.m_elements.contains(deti->parentElement())) { + m_moved_content.m_element_texts.remove(deti); + } + } + + QList etig_list = m_moved_content.m_texts_groups.toList(); + for(ElementTextItemGroup *etig : etig_list) { + if (m_moved_content.m_elements.contains(etig->parentElement())) { + m_moved_content.m_texts_groups.remove(etig); + } + } + if (!m_moved_content.count()) return(-1); /* At this point, we've got all info to manage movement. @@ -98,7 +116,7 @@ void ElementsMover::continueMovement(const QPointF &movement) { //Move every movable item, except conductor typedef DiagramContent dc; - for (QGraphicsItem *qgi : m_moved_content.items(dc::Elements | dc::TextFields | dc::Images | dc::Shapes)) + for (QGraphicsItem *qgi : m_moved_content.items(dc::Elements | dc::TextFields | dc::Images | dc::Shapes | dc::ElementTextFields | dc::TextGroup)) { if (qgi == m_movement_driver) continue;