[qet] qet/qet: [4753] Minor : imrpove method |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4753
Author: blacksun
Date: 2016-10-20 19:48:10 +0200 (Thu, 20 Oct 2016)
Log Message:
-----------
Minor : imrpove method
Modified Paths:
--------------
trunk/sources/diagramview.cpp
trunk/sources/diagramview.h
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2016-10-20 12:35:44 UTC (rev 4752)
+++ trunk/sources/diagramview.cpp 2016-10-20 17:48:10 UTC (rev 4753)
@@ -97,11 +97,6 @@
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 @@
}
/**
- 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 @@
}
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();
-}
Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h 2016-10-20 12:35:44 UTC (rev 4752)
+++ trunk/sources/diagramview.h 2016-10-20 17:48:10 UTC (rev 4753)
@@ -58,98 +58,93 @@
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