From fb47a18b698fb15eba126d3942329467441c7100 Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 4 Apr 2018 11:02:40 +0000 Subject: [PATCH] Remove, move and clean some functions of diagram view, among other things because it is not the role of the diagram view to provide these functions. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5294 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagramcontent.cpp | 14 ++++++ sources/diagramcontent.h | 1 + sources/diagramview.cpp | 82 +----------------------------------- sources/diagramview.h | 6 --- sources/qetdiagrameditor.cpp | 18 +++++--- 5 files changed, 29 insertions(+), 92 deletions(-) diff --git a/sources/diagramcontent.cpp b/sources/diagramcontent.cpp index c6c9d6f56..e89d7a532 100644 --- a/sources/diagramcontent.cpp +++ b/sources/diagramcontent.cpp @@ -197,6 +197,20 @@ bool DiagramContent::hasDeletableItems() const return(false); } +/** + * @brief DiagramContent::hasCopiableItems + * @return true if this diagram content have copiable items. + */ +bool DiagramContent::hasCopiableItems() const +{ + if(!m_images.isEmpty()) return true; + if(!m_shapes.isEmpty()) return true; + if(!m_elements.isEmpty()) return true; + if(!m_text_fields.isEmpty()) return true; + + return false; +} + /** * @brief DiagramContent::clear * Remove all items from the diagram content diff --git a/sources/diagramcontent.h b/sources/diagramcontent.h index b560528e8..13409b28e 100644 --- a/sources/diagramcontent.h +++ b/sources/diagramcontent.h @@ -79,6 +79,7 @@ class DiagramContent QList selectedTextsGroup() const; QList conductors(int = AnyConductor) const; bool hasDeletableItems() const; + bool hasCopiableItems() const; QList items(int = All) const; QString sentence(int = All) const; int count(int = All) const; diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index f493d1a91..8c74501d1 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -539,7 +539,7 @@ void DiagramView::keyPressEvent(QKeyEvent *e) current_project->changeTabDown(); return; case Qt::Key_Home: - if (!hasTextItems()) { + if (dc.selectedTexts().isEmpty()) { if ( qgraphicsitem_cast(m_diagram->focusItem()) || qgraphicsitem_cast(m_diagram->focusItem()) || @@ -551,7 +551,7 @@ void DiagramView::keyPressEvent(QKeyEvent *e) } else break; case Qt::Key_End: - if (!hasTextItems()) { + if (dc.selectedTexts().isEmpty()) { if ( qgraphicsitem_cast(m_diagram->focusItem()) || qgraphicsitem_cast(m_diagram->focusItem()) || @@ -707,84 +707,6 @@ void DiagramView::editDiagramProperties() { DiagramPropertiesDialog::diagramPropertiesDialog(m_diagram, diagramEditor()); } -/** - @return true s'il y a des items selectionnes sur le schema et que ceux-ci - peuvent etre copies dans le presse-papier, false sinon -*/ -bool DiagramView::hasCopiableItems() { - foreach(QGraphicsItem *qgi, m_diagram -> selectedItems()) { - if ( - qgraphicsitem_cast(qgi) || - qgraphicsitem_cast(qgi) || - qgraphicsitem_cast(qgi) || - qgraphicsitem_cast(qgi) - ) { - return(true); - } - } - return(false); -} - -/** - @return true if there is any Text Item selected -*/ -bool DiagramView::hasTextItems() { - foreach(QGraphicsItem *qgi, m_diagram -> selectedItems()) { - if ( - qgraphicsitem_cast(qgi) || - qgraphicsitem_cast(qgi) || - qgraphicsitem_cast(qgi) - ) { - return(true); - } - } - return(false); -} - -/** - Ajoute une colonne au schema. -*/ -void DiagramView::addColumn() { - if (m_diagram -> isReadOnly()) return; - BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder(); - BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder(); - new_bp.columns_count += 1; - m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp)); -} - -/** - Enleve une colonne au schema. -*/ -void DiagramView::removeColumn() { - if (m_diagram -> isReadOnly()) return; - BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder(); - BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder(); - new_bp.columns_count -= 1; - m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp)); -} - -/** - Agrandit le schema en hauteur -*/ -void DiagramView::addRow() { - if (m_diagram -> isReadOnly()) return; - BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder(); - BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder(); - new_bp.rows_count += 1; - m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp)); -} - -/** - Retrecit le schema en hauteur -*/ -void DiagramView::removeRow() { - if (m_diagram -> isReadOnly()) return; - BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder(); - BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder(); - new_bp.rows_count -= 1; - m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp)); -} - /** * @brief DiagramView::adjustSceneRect * Calcul and set the area of the scene visualized by this view diff --git a/sources/diagramview.h b/sources/diagramview.h index 2f676ab6a..becc2b723 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -60,14 +60,8 @@ class DiagramView : public QGraphicsView public: QString title() const; void editDiagramProperties(); - void addColumn(); - void removeColumn(); - void addRow(); - void removeRow(); Diagram *diagram() { return(m_diagram); } QETDiagramEditor *diagramEditor() const; - bool hasCopiableItems(); - bool hasTextItems(); void editSelection(); void setEventInterface (DVEventInterface *event_interface); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 96fd8bb89..2351f1663 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1279,16 +1279,22 @@ void QETDiagramEditor::rowColumnGroupTriggered(QAction *action) QString value = action->data().toString(); DiagramView *dv = currentDiagram(); - if (!dv || value.isEmpty()) return; + if (!dv || value.isEmpty() || dv->diagram()->isReadOnly()) return; + Diagram *d = dv->diagram(); + BorderProperties old_bp = d->border_and_titleblock.exportBorder(); + BorderProperties new_bp = d->border_and_titleblock.exportBorder(); + if (value == "add_column") - dv->addColumn(); + new_bp.columns_count += 1; else if (value == "remove_column") - dv->removeColumn(); + new_bp.columns_count -= 1; else if (value == "add_row") - dv->addRow(); + new_bp.rows_count += 1; else if (value == "remove_row") - dv->removeRow(); + new_bp.rows_count -= 1; + + d->undoStack().push(new ChangeBorderCommand(d, old_bp, new_bp)); } /** @@ -1408,7 +1414,7 @@ void QETDiagramEditor::slot_updateComplexActions() m_find_element->setEnabled(selected_elements_count == 1); //Action that need items (elements, conductors, texts...) selected, to be enabled - bool copiable_items = dv->hasCopiableItems(); + bool copiable_items = dc.hasCopiableItems(); bool deletable_items = dc.hasDeletableItems(); m_cut -> setEnabled(!ro && copiable_items); m_copy -> setEnabled(copiable_items);