From 537c0ad95a97a1b2a9a8fc3fbe1fdd58c711702f Mon Sep 17 00:00:00 2001 From: blacksun Date: Thu, 20 Oct 2016 17:48:10 +0000 Subject: [PATCH] Minor : imrpove method git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4753 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagramview.cpp | 86 +++++++++++----------- sources/diagramview.h | 159 +++++++++++++++++++--------------------- 2 files changed, 120 insertions(+), 125 deletions(-) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 94af0dc5d..e001e0cd2 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -97,11 +97,6 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : connect(diagram, SIGNAL(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation))); connect(diagram, SIGNAL(findElementRequired(ElementsLocation)), this, SIGNAL(findElementRequired(ElementsLocation))); - connect( - this, SIGNAL(aboutToSetDroppedTitleBlockTemplate(const TitleBlockTemplateLocation &)), - this, SLOT(setDroppedTitleBlockTemplate(const TitleBlockTemplateLocation &)), - Qt::QueuedConnection - ); QShortcut *edit_conductor_color_shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this); connect(edit_conductor_color_shortcut, SIGNAL(activated()), this, SLOT(editSelectedConductorColor())); } @@ -299,15 +294,51 @@ void DiagramView::handleElementDrop(QDropEvent *event) } /** - Handle the drop of an element. - @param e the QDropEvent describing the current drag'n drop -*/ + * @brief DiagramView::handleTitleBlockDrop + * Handle the dropEvent that contain data of a titleblock + * @param e + */ void DiagramView::handleTitleBlockDrop(QDropEvent *e) { - // fetch the title block template location from the drop event + // fetch the title block template location from the drop event TitleBlockTemplateLocation tbt_loc; - tbt_loc.fromString(e -> mimeData() -> text()); - if (tbt_loc.isValid()) { - emit(aboutToSetDroppedTitleBlockTemplate(tbt_loc)); + tbt_loc.fromString(e->mimeData()->text()); + + + if (tbt_loc.isValid()) + { + // fetch the current title block properties + TitleBlockProperties titleblock_properties_before = scene->border_and_titleblock.exportTitleBlock(); + + // check the provided template is not already applied + QETProject *tbt_parent_project = tbt_loc.parentProject(); + if (tbt_parent_project && tbt_parent_project == scene -> project()) + { + // same parent project and same name = same title block template + if (tbt_loc.name() == titleblock_properties_before.template_name) + return; + } + + // integrate the provided template into the project if needed + QString integrated_template_name = tbt_loc.name(); + if (mustIntegrateTitleBlockTemplate(tbt_loc)) + { + IntegrationMoveTitleBlockTemplatesHandler *handler = new IntegrationMoveTitleBlockTemplatesHandler(this); + //QString error_message; + integrated_template_name = scene->project()->integrateTitleBlockTemplate(tbt_loc, handler); + + if (integrated_template_name.isEmpty()) + return; + } + + // apply the provided title block template + if (titleblock_properties_before.template_name == integrated_template_name) + return; + + TitleBlockProperties titleblock_properties_after = titleblock_properties_before; + titleblock_properties_after.template_name = integrated_template_name; + scene->undoStack().push(new ChangeTitleBlockCommand(scene, titleblock_properties_before, titleblock_properties_after)); + + adjustSceneRect(); } } @@ -1250,34 +1281,3 @@ void DiagramView::mouseDoubleClickEvent(QMouseEvent *e) } QGraphicsView::mouseDoubleClickEvent(e); } - -/** - @param tbt TitleBlockTemplateLocation -*/ -void DiagramView::setDroppedTitleBlockTemplate(const TitleBlockTemplateLocation &tbt) { - // fetch the current title block properties - TitleBlockProperties titleblock_properties_before = scene -> border_and_titleblock.exportTitleBlock(); - - // check the provided template is not already applied - QETProject *tbt_parent_project = tbt.parentProject(); - if (tbt_parent_project && tbt_parent_project == scene -> project()) { - // same parent project and same name = same title block template - if (tbt.name() == titleblock_properties_before.template_name) return; - } - - // integrate the provided template into the project if needed - QString integrated_template_name = tbt.name(); - if (mustIntegrateTitleBlockTemplate(tbt)) { - IntegrationMoveTitleBlockTemplatesHandler *handler = new IntegrationMoveTitleBlockTemplatesHandler(this); - //QString error_message; - integrated_template_name = scene -> project() -> integrateTitleBlockTemplate(tbt, handler); - if (integrated_template_name.isEmpty()) return; - } - - // apply the provided title block template - if (titleblock_properties_before.template_name == integrated_template_name) return; - TitleBlockProperties titleblock_properties_after = titleblock_properties_before; - titleblock_properties_after.template_name = integrated_template_name; - scene -> undoStack().push(new ChangeTitleBlockCommand(scene, titleblock_properties_before, titleblock_properties_after)); - adjustSceneRect(); -} diff --git a/sources/diagramview.h b/sources/diagramview.h index 439bf7c2d..e281b5ea4 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -58,98 +58,93 @@ class DiagramView : public QGraphicsView bool fresh_focus_in_; ///< Indicate the focus was freshly gained bool m_first_activation; - - // methods public: - QString title() const; - void editDiagramProperties(); - void addColumn(); - void removeColumn(); - void addRow(); - void removeRow(); - /// @return the diagram rendered by this view - Diagram *diagram() { return(scene); } - QETDiagramEditor *diagramEditor() const; - bool hasSelectedItems(); - bool hasCopiableItems(); - bool hasTextItems(); - bool hasDeletableItems(); - void editSelection(); - void setEventInterface (DVEventInterface *event_interface); + QString title() const; + void editDiagramProperties(); + void addColumn(); + void removeColumn(); + void addRow(); + void removeRow(); + /// @return the diagram rendered by this view + Diagram *diagram() { return(scene); } + QETDiagramEditor *diagramEditor() const; + bool hasSelectedItems(); + bool hasCopiableItems(); + bool hasTextItems(); + bool hasDeletableItems(); + void editSelection(); + void setEventInterface (DVEventInterface *event_interface); protected: - virtual void mouseDoubleClickEvent(QMouseEvent *); - virtual void contextMenuEvent(QContextMenuEvent *); - virtual void wheelEvent(QWheelEvent *); - virtual void focusInEvent(QFocusEvent *); - virtual void keyPressEvent(QKeyEvent *); - virtual void keyReleaseEvent(QKeyEvent *); - virtual bool event(QEvent *); - virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e); - virtual bool switchToSelectionModeIfNeeded(QInputEvent *e); - virtual bool isCtrlShifting(QInputEvent *); - virtual bool selectedItemHasFocus(); + virtual void mouseDoubleClickEvent(QMouseEvent *); + virtual void contextMenuEvent(QContextMenuEvent *); + virtual void wheelEvent(QWheelEvent *); + virtual void focusInEvent(QFocusEvent *); + virtual void keyPressEvent(QKeyEvent *); + virtual void keyReleaseEvent(QKeyEvent *); + virtual bool event(QEvent *); + virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e); + virtual bool switchToSelectionModeIfNeeded(QInputEvent *e); + virtual bool isCtrlShifting(QInputEvent *); + virtual bool selectedItemHasFocus(); private: - void mousePressEvent(QMouseEvent *); - void mouseMoveEvent(QMouseEvent *); - void mouseReleaseEvent(QMouseEvent *); - void dragEnterEvent(QDragEnterEvent *); - void dragLeaveEvent(QDragLeaveEvent *); - void dragMoveEvent(QDragMoveEvent *); - void dropEvent(QDropEvent *); - void handleElementDrop(QDropEvent *); - void handleTitleBlockDrop(QDropEvent *); - void handleTextDrop(QDropEvent *); - void scrollOnMovement(QKeyEvent *); - bool gestureEvent(QGestureEvent *event); - QRectF viewedSceneRect() const; - bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const; - bool gestures() const; + void mousePressEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); + void dragEnterEvent(QDragEnterEvent *); + void dragLeaveEvent(QDragLeaveEvent *); + void dragMoveEvent(QDragMoveEvent *); + void dropEvent(QDropEvent *); + void handleElementDrop(QDropEvent *); + void handleTitleBlockDrop(QDropEvent *); + void handleTextDrop(QDropEvent *); + void scrollOnMovement(QKeyEvent *); + bool gestureEvent(QGestureEvent *event); + QRectF viewedSceneRect() const; + bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const; + bool gestures() const; signals: - /// Signal emitted after the selection changed - void selectionChanged(); - /// Signal emitted after the selection mode changed - void modeChanged(); - /// Signal emitted after the diagram title changed - void titleChanged(DiagramView *, const QString &); - /// Signal emitted before integrating a title block template - void aboutToSetDroppedTitleBlockTemplate(const TitleBlockTemplateLocation &); - /// Signal emitted when users wish to locate an element from the diagram within elements collection - void findElementRequired(const ElementsLocation &); - /// Signal emitted when users wish to edit an element from the diagram - void editElementRequired(const ElementsLocation &); - /// Signal emmitted when diagram must be show - void showDiagram (Diagram *); + /// Signal emitted after the selection changed + void selectionChanged(); + /// Signal emitted after the selection mode changed + void modeChanged(); + /// Signal emitted after the diagram title changed + void titleChanged(DiagramView *, const QString &); + /// Signal emitted when users wish to locate an element from the diagram within elements collection + void findElementRequired(const ElementsLocation &); + /// Signal emitted when users wish to edit an element from the diagram + void editElementRequired(const ElementsLocation &); + /// Signal emmitted when diagram must be show + void showDiagram (Diagram *); public slots: - void selectNothing(); - void selectAll(); - void selectInvert(); - void deleteSelection(); - void rotateSelection(); - void rotateTexts(); - void setVisualisationMode(); - void setSelectionMode(); - void zoom(const qreal zoom_factor); - void zoomFit(); - void zoomContent(); - void zoomReset(); - void cut(); - void copy(); - void paste(const QPointF & = QPointF(), QClipboard::Mode = QClipboard::Clipboard); - void pasteHere(); - void adjustSceneRect(); - void updateWindowTitle(); - void editSelectionProperties(); - void editSelectedConductorColor(); - void editConductorColor(Conductor *); - void resetConductors(); + void selectNothing(); + void selectAll(); + void selectInvert(); + void deleteSelection(); + void rotateSelection(); + void rotateTexts(); + void setVisualisationMode(); + void setSelectionMode(); + void zoom(const qreal zoom_factor); + void zoomFit(); + void zoomContent(); + void zoomReset(); + void cut(); + void copy(); + void paste(const QPointF & = QPointF(), QClipboard::Mode = QClipboard::Clipboard); + void pasteHere(); + void adjustSceneRect(); + void updateWindowTitle(); + void editSelectionProperties(); + void editSelectedConductorColor(); + void editConductorColor(Conductor *); + void resetConductors(); private slots: - void setDroppedTitleBlockTemplate(const TitleBlockTemplateLocation &); - void adjustGridToZoom(); - void applyReadOnly(); + void adjustGridToZoom(); + void applyReadOnly(); }; #endif