QElectroTech  0.8-dev
diagramview.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef DIAGRAMVIEW_H
19 #define DIAGRAMVIEW_H
20 
21 #include <QGraphicsView>
22 #include <QClipboard>
23 #include "elementslocation.h"
24 #include "templatelocation.h"
25 
26 class Conductor;
27 class Diagram;
28 class QETDiagramEditor;
29 class DVEventInterface;
30 class QInputEvent;
31 class QGestureEvent;
32 
37 class DiagramView : public QGraphicsView
38 {
39  Q_OBJECT
40 
41  // constructors, destructor
42  public:
43  DiagramView(Diagram *diagram, QWidget * = nullptr);
44  ~DiagramView() override;
45 
46  private:
48 
49  // attributes
50 
51  Diagram *m_diagram = nullptr;
53  QAction *m_paste_here = nullptr;
54  QAction *m_multi_paste = nullptr;
56  QPointF m_drag_last_pos;
59  QList<QAction *> m_separators;
60  QPolygonF m_free_rubberband;
61  bool m_free_rubberbanding = false;
62 
63 
64  public:
65  QString title() const;
66  void editDiagramProperties();
67  Diagram *diagram() { return(m_diagram); }
69  void editSelection();
70  void setEventInterface (DVEventInterface *event_interface);
71  QList<QAction *> contextMenuActions() const;
72 
73  protected:
74  void mouseDoubleClickEvent(QMouseEvent *) override;
75  void contextMenuEvent(QContextMenuEvent *) override;
76  void wheelEvent(QWheelEvent *) override;
77  void focusInEvent(QFocusEvent *) override;
78  void keyPressEvent(QKeyEvent *) override;
79  void keyReleaseEvent(QKeyEvent *) override;
80  bool event(QEvent *) override;
81  void paintEvent(QPaintEvent *event) override;
82  void mousePressEvent(QMouseEvent *) override;
83  void mouseMoveEvent(QMouseEvent *) override;
84  void mouseReleaseEvent(QMouseEvent *) override;
85  void dragEnterEvent(QDragEnterEvent *) override;
86  void dragMoveEvent(QDragMoveEvent *) override;
87  void dropEvent(QDropEvent *) override;
88 
89  virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e);
90  virtual bool switchToSelectionModeIfNeeded(QInputEvent *e);
91  virtual bool isCtrlShifting(QInputEvent *);
92  virtual bool selectedItemHasFocus();
93 
94  private:
95  void handleElementDrop(QDropEvent *);
96  void handleTitleBlockDrop(QDropEvent *);
97  void handleTextDrop(QDropEvent *);
98  void scrollOnMovement(QKeyEvent *);
99  bool gestureEvent(QGestureEvent *event);
100  QRectF viewedSceneRect() const;
102  bool gestures() const;
103 
104  signals:
106  void modeChanged();
108  void titleChanged(DiagramView *, const QString &);
117  void freeRubberBandChanged(QPolygonF polygon);
118 
119  public slots:
120  void selectNothing();
121  void selectAll();
122  void selectInvert();
123  void setVisualisationMode();
124  void setSelectionMode();
125  void zoom(const qreal zoom_factor);
126  void zoomFit();
127  void zoomContent();
128  void zoomReset();
129  void cut();
130  void copy();
131  void paste(const QPointF & = QPointF(), QClipboard::Mode = QClipboard::Clipboard);
132  void pasteHere();
133  void adjustSceneRect();
134  void updateWindowTitle();
137  void resetConductors();
138 
139  private slots:
140  void adjustGridToZoom();
141  void applyReadOnly();
142 };
143 #endif
DiagramView::mustIntegrateTitleBlockTemplate
bool mustIntegrateTitleBlockTemplate(const TitleBlockTemplateLocation &) const
Definition: diagramview.cpp:896
DVEventInterface::KeyReleaseEvent
virtual bool KeyReleaseEvent(QKeyEvent *event)
Definition: dveventinterface.cpp:78
ElementsLocation::exist
bool exist() const
ElementsLocation::exist.
Definition: elementslocation.cpp:472
DiagramView::editSelection
void editSelection()
DiagramView::editSelection Edit the selected item if he can be edited and if only one item is selecte...
Definition: diagramview.cpp:1118
DVEventInterface::mouseMoveEvent
virtual bool mouseMoveEvent(QMouseEvent *event)
Definition: dveventinterface.cpp:44
DiagramView::selectAll
void selectAll()
Definition: diagramview.cpp:122
Diagram::clipboardMayContainDiagram
static bool clipboardMayContainDiagram()
Diagram::clipboardMayContainDiagram.
Definition: diagram.cpp:2312
DiagramView::applyReadOnly
void applyReadOnly()
Definition: diagramview.cpp:908
DiagramView::setVisualisationMode
void setVisualisationMode()
Definition: diagramview.cpp:270
ChangeTitleBlockCommand
The ChangeTitleBlockCommand class This command changes the title block properties for a particular di...
Definition: changetitleblockcommand.h:31
Diagram::setEventInterface
void setEventInterface(DiagramEventInterface *event_interface)
Diagram::setEventInterface Set event_interface has current interface. Diagram become the ownership of...
Definition: diagram.cpp:531
DiagramContent::AnyConductor
@ AnyConductor
Definition: diagramcontent.h:61
ConductorProperties::color
QColor color
Definition: conductorproperties.h:85
DiagramView::gestures
bool gestures() const
DiagramView::gestures.
Definition: diagramview.cpp:570
QetGraphicsItem
Definition: qetgraphicsitem.h:27
QETProject::integrateTitleBlockTemplate
QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler)
QETProject::integrateTitleBlockTemplate Integrate a title block template into this project.
Definition: qetproject.cpp:1065
IntegrationMoveTitleBlockTemplatesHandler
Definition: integrationmovetemplateshandler.h:27
DiagramView::scrollOnMovement
void scrollOnMovement(QKeyEvent *)
Definition: diagramview.cpp:746
DiagramView::focusInEvent
void focusInEvent(QFocusEvent *) override
Definition: diagramview.cpp:637
diagramcommands.h
Diagram::adjustSceneRect
void adjustSceneRect()
Diagram::adjustSceneRect Recalcul and adjust the size of the scene.
Definition: diagram.cpp:2166
Diagram::fromXml
bool fromXml(QDomDocument &, QPointF=QPointF(), bool=true, DiagramContent *=nullptr)
Diagram::fromXml Imports the described schema into an XML document. If a position is specified,...
Definition: diagram.cpp:1029
DiagramView::modeChanged
void modeChanged()
Signal emitted after the selection mode changed.
DiagramView::adjustSceneRect
void adjustSceneRect()
DiagramView::adjustSceneRect Calcul and set the area of the scene visualized by this view.
Definition: diagramview.cpp:837
DiagramView::editSelectedConductorColor
void editSelectedConductorColor()
DiagramView::editSelectedConductorColor Edit the color of the selected conductor; does nothing if mul...
Definition: diagramview.cpp:920
conductor.h
ProjectView::changeLastTab
void changeLastTab()
change current diagramview to last tab
Definition: projectview.cpp:175
DiagramContent::hasTextEditing
bool hasTextEditing()
DiagramContent::hasTextEditing.
Definition: diagramcontent.cpp:358
diagramposition.h
DiagramView::m_free_rubberbanding
bool m_free_rubberbanding
Definition: diagramview.h:61
conductortextitem.h
DiagramView::editElementRequired
void editElementRequired(const ElementsLocation &)
Signal emitted when users wish to edit an element from the diagram.
projectview.h
DiagramView::paste
void paste(const QPointF &=QPointF(), QClipboard::Mode=QClipboard::Clipboard)
DiagramView::paste Import the element stored in the clipboard to the diagram.
Definition: diagramview.cpp:366
DiagramView::handleTitleBlockDrop
void handleTitleBlockDrop(QDropEvent *)
DiagramView::handleTitleBlockDrop Handle the dropEvent that contain data of a titleblock.
Definition: diagramview.cpp:206
DVEventInterface::mousePressEvent
virtual bool mousePressEvent(QMouseEvent *event)
Definition: dveventinterface.cpp:39
DVEventInterface::mouseReleaseEvent
virtual bool mouseReleaseEvent(QMouseEvent *event)
Definition: dveventinterface.cpp:49
DiagramView::setEventInterface
void setEventInterface(DVEventInterface *event_interface)
DiagramView::setEventInterface Set an event interface to diagram view. If diagram view already have a...
Definition: diagramview.cpp:1140
ProjectView::changeFirstTab
void changeFirstTab()
change current diagramview to first tab
Definition: projectview.cpp:190
multipastedialog.h
DiagramContent
Definition: diagramcontent.h:46
diagrampropertiesdialog.h
DiagramEventAddElement
The DiagramEventAddElement class This diagram event add a new element, for each left click button at ...
Definition: diagrameventaddelement.h:32
Diagram::isEmpty
bool isEmpty() const
Diagram::isEmpty An empty schema contains no element, conductor, or text field.
Definition: diagram.cpp:680
ResetConductorCommand
The ResetConductorCommand class This command resets conductor paths.
Definition: diagramcommands.h:278
qetmessagebox.h
ProjectView::changeTabDown
void changeTabDown()
change current diagramview to next folio
Definition: projectview.cpp:129
DiagramView::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *) override
Definition: diagramview.cpp:144
DiagramView::viewedSceneRect
QRectF viewedSceneRect() const
Definition: diagramview.cpp:875
DiagramView::diagramEditor
QETDiagramEditor * diagramEditor() const
Definition: diagramview.cpp:1228
DiagramView::editConductorColor
void editConductorColor(Conductor *)
Definition: diagramview.cpp:936
BorderTitleBlock::rowsRect
QRectF rowsRect() const
BorderTitleBlock::rowsRect.
Definition: bordertitleblock.cpp:157
DiagramContent::conductors
QList< Conductor * > conductors(int=AnyConductor) const
DiagramContent::conductors.
Definition: diagramcontent.cpp:167
DiagramView::editDiagramProperties
void editDiagramProperties()
DiagramView::editDiagramProperties Edit the properties of the viewed digram.
Definition: diagramview.cpp:829
DiagramView::mousePressEvent
void mousePressEvent(QMouseEvent *) override
Definition: diagramview.cpp:398
DiagramView::m_drag_last_pos
QPointF m_drag_last_pos
Definition: diagramview.h:56
DiagramView::resetConductors
void resetConductors()
Definition: diagramview.cpp:973
Diagram::border_and_titleblock
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition: diagram.h:83
DiagramView::selectNothing
void selectNothing()
Definition: diagramview.cpp:129
Diagram::project
QETProject * project() const
Diagram::project.
Definition: diagram.cpp:2326
DiagramView::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *) override
Definition: diagramview.cpp:734
Diagram::loadCndFolioSeq
void loadCndFolioSeq()
Diagram::loadCndFolioSeq This class loads all conductor folio sequential variables related to the cur...
Definition: diagram.cpp:1942
ElementsLocation::isElement
bool isElement() const
ElementsLocation::isElement.
Definition: elementslocation.cpp:412
conductorcreator.h
Diagram
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition: diagram.h:56
DiagramView::DiagramView
DiagramView(const DiagramView &)
changetitleblockcommand.h
qeticons.h
DiagramView::keyPressEvent
void keyPressEvent(QKeyEvent *) override
DiagramView::keyPressEvent Handles "key press" events. Reimplemented here to switch to visualisation ...
Definition: diagramview.cpp:649
DiagramView::m_fresh_focus_in
bool m_fresh_focus_in
Definition: diagramview.h:57
TitleBlockTemplateLocation::parentProject
QETProject * parentProject() const
Definition: templatelocation.cpp:116
DiagramView::switchToSelectionModeIfNeeded
virtual bool switchToSelectionModeIfNeeded(QInputEvent *e)
Definition: diagramview.cpp:1076
TitleBlockProperties
Definition: titleblockproperties.h:29
DiagramView::selectedItemHasFocus
virtual bool selectedItemHasFocus()
Definition: diagramview.cpp:1106
diagramview.h
DiagramView::paintEvent
void paintEvent(QPaintEvent *event) override
DiagramView::paintEvent Reimplemented from QGraphicsView.
Definition: diagramview.cpp:1037
DiagramView::selectInvert
void selectInvert()
Definition: diagramview.cpp:136
DiagramView::isCtrlShifting
virtual bool isCtrlShifting(QInputEvent *)
Definition: diagramview.cpp:1087
DiagramView::pasteHere
void pasteHere()
Definition: diagramview.cpp:390
DiagramView::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *) override
DiagramView::mouseDoubleClickEvent.
Definition: diagramview.cpp:1242
elementslocation.h
TitleBlockTemplateLocation::isValid
bool isValid() const
Definition: templatelocation.cpp:87
DiagramView::setSelectionMode
void setSelectionMode()
Definition: diagramview.cpp:280
TitleBlockTemplateLocation
Definition: templatelocation.h:29
BorderTitleBlock::exportTitleBlock
TitleBlockProperties exportTitleBlock()
BorderTitleBlock::exportTitleBlock.
Definition: bordertitleblock.cpp:279
ConductorProfilesGroup
QHash< Qt::Corner, ConductorProfile > ConductorProfilesGroup
Definition: conductor.h:37
DiagramView::cut
void cut()
Definition: diagramview.cpp:343
DiagramView::handleTextDrop
void handleTextDrop(QDropEvent *)
Definition: diagramview.cpp:255
AddItemCommand
The AddItemCommand class This command add an item in a diagram The item to add is template,...
Definition: diagramcommands.h:42
DiagramView::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *) override
DiagramView::mouseMoveEvent Manage the event move mouse.
Definition: diagramview.cpp:455
DiagramView::m_event_interface
DVEventInterface * m_event_interface
Definition: diagramview.h:52
DiagramView::adjustGridToZoom
void adjustGridToZoom()
Definition: diagramview.cpp:864
DiagramView::m_free_rubberband
QPolygonF m_free_rubberband
Definition: diagramview.h:60
qpropertyundocommand.h
DiagramView::zoom
void zoom(const qreal zoom_factor)
DiagramView::zoom Zomm the view. A zoom_factor > 1 zoom in. A zoom_factor < 1 zoom out.
Definition: diagramview.cpp:294
ConductorCreator::create
static void create(Diagram *d, const QPolygonF &polygon)
ConductorCreator::create Create an electrical potential between the terminals of the diagram d,...
Definition: conductorcreator.cpp:77
DiagramView::zoomReset
void zoomReset()
Definition: diagramview.cpp:335
Diagram::undoStack
QUndoStack & undoStack()
Diagram::undoStack.
Definition: diagram.h:397
DiagramView::freeRubberBandChanged
void freeRubberBandChanged(QPolygonF polygon)
DiagramView::dropEvent
void dropEvent(QDropEvent *) override
Definition: diagramview.cpp:169
QET::Icons::QETLogo
QIcon QETLogo
Definition: qeticons.cpp:151
dveventinterface.h
DVEventInterface::finish
void finish()
finish emited when the interface finish is work
DVEventInterface::keyPressEvent
virtual bool keyPressEvent(QKeyEvent *event)
DVEventInterface::keyPressEvent By default, press escape key abort the curent action....
Definition: dveventinterface.cpp:66
qetproject.h
DiagramContent::count
int count(int=All) const
DiagramContent::count.
Definition: diagramcontent.cpp:401
Diagram::margin
static const qreal margin
margin around the diagram
Definition: diagram.h:97
DiagramView::m_separators
QList< QAction * > m_separators
Definition: diagramview.h:59
Diagram::loadElmtFolioSeq
void loadElmtFolioSeq()
Diagram::loadElmtFolioSeq This class loads all folio sequential variables related to the current auto...
Definition: diagram.cpp:1857
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
DiagramPropertiesDialog::diagramPropertiesDialog
static void diagramPropertiesDialog(Diagram *diagram, QWidget *parent=nullptr)
DiagramPropertiesDialog::diagramPropertiesDialog Static method to get a DiagramPropertiesDialog.
Definition: diagrampropertiesdialog.cpp:129
DiagramView::showDiagram
void showDiagram(Diagram *)
Signal emmitted when diagram must be show.
independenttextitem.h
BorderTitleBlock::titleBlockRect
QRectF titleBlockRect() const
BorderTitleBlock::titleBlockRect.
Definition: bordertitleblock.cpp:81
DiagramContent::All
@ All
Definition: diagramcontent.h:65
QETProject
Definition: qetproject.h:51
BorderTitleBlock::columnsRect
QRectF columnsRect() const
BorderTitleBlock::columnsRect.
Definition: bordertitleblock.cpp:143
DiagramView::zoomContent
void zoomContent()
Definition: diagramview.cpp:327
DiagramView::updateWindowTitle
void updateWindowTitle()
Definition: diagramview.cpp:857
ProjectView
The ProjectView class This class provides a widget displaying the diagrams of a particular project us...
Definition: projectview.h:79
DiagramView::diagram
Diagram * diagram()
Definition: diagramview.h:67
DiagramView::titleChanged
void titleChanged(DiagramView *, const QString &)
Signal emitted after the diagram title changed.
DiagramContent::SelectedOnly
@ SelectedOnly
Definition: diagramcontent.h:66
QETDiagramEditor
Definition: qetdiagrameditor.h:51
DiagramView::m_paste_here
QAction * m_paste_here
Definition: diagramview.h:53
elementfactory.h
DiagramView::title
QString title() const
Definition: diagramview.cpp:814
DiagramView::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *) override
DiagramView::contextMenuEvent.
Definition: diagramview.cpp:1194
integrationmovetemplateshandler.h
DiagramView::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *) override
DiagramView::mouseReleaseEvent Manage event release click mouse.
Definition: diagramview.cpp:516
ProjectView::changeTabUp
void changeTabUp()
change current diagramview to previous tab
Definition: projectview.cpp:152
BorderTitleBlock
The BorderTitleBlock class This class represents the border and the titleblock which frame a particul...
Definition: bordertitleblock.h:37
DiagramView::m_multi_paste
QAction * m_multi_paste
Definition: diagramview.h:54
DiagramContent::selectedTexts
QList< DiagramTextItem * > selectedTexts() const
DiagramContent::selectedTexts.
Definition: diagramcontent.cpp:130
ConductorProperties
The ConductorProperties class This class represents the functional properties of a particular conduct...
Definition: conductorproperties.h:68
QET::Icons::EditPaste
QIcon EditPaste
Definition: qeticons.cpp:67
MultiPasteDialog
Definition: multipastedialog.h:32
IndependentTextItem
Definition: independenttextitem.h:28
TitleBlockTemplateLocation::fromString
void fromString(const QString &)
Definition: templatelocation.cpp:94
CutDiagramCommand
The CutDiagramCommand class This command cuts content from a particular diagram.
Definition: diagramcommands.h:118
qetdiagrameditor.h
PasteDiagramCommand
The PasteDiagramCommand class This command pastes some content onto a particular diagram.
Definition: diagramcommands.h:88
DiagramContent::items
QList< QGraphicsItem * > items(int=All) const
DiagramContent::items.
Definition: diagramcontent.cpp:374
TitleBlockProperties::template_name
QString template_name
Name of the template used to render the title block - an empty string means "the default template pro...
Definition: titleblockproperties.h:65
DiagramView::m_diagram
Diagram * m_diagram
Definition: diagramview.h:51
qetshapeitem.h
DiagramView::handleElementDrop
void handleElementDrop(QDropEvent *)
DiagramView::handleElementDrop Handle the drop of an element.
Definition: diagramview.cpp:185
DiagramView::gestureEvent
bool gestureEvent(QGestureEvent *event)
DiagramView::gestureEvent Use the pinch of the trackpad for zoom.
Definition: diagramview.cpp:616
dynamicelementtextitem.h
DVEventInterface
The DVEventInterface class This class is the main interface for manage event of a Diagram View....
Definition: dveventinterface.h:43
DiagramView
Definition: diagramview.h:38
templatelocation.h
Diagram::setDisplayGrid
void setDisplayGrid(bool)
Diagram::setDisplayGrid Set whether the diagram grid should be drawn.
Definition: diagram.h:333
DiagramView::findElementRequired
void findElementRequired(const ElementsLocation &)
Signal emitted when users wish to locate an element from the diagram within elements collection.
Conductor
Definition: conductor.h:43
diagrameventaddelement.h
DiagramView::DiagramView
DiagramView(Diagram *diagram, QWidget *=nullptr)
Definition: diagramview.cpp:54
DiagramView::~DiagramView
~DiagramView() override
Definition: diagramview.cpp:116
DiagramView::wheelEvent
void wheelEvent(QWheelEvent *) override
DiagramView::wheelEvent Manage wheel event of mouse.
Definition: diagramview.cpp:581
conductorpropertieswidget.h
QPropertyUndoCommand
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
Definition: qpropertyundocommand.h:34
DiagramView::zoomFit
void zoomFit()
Definition: diagramview.cpp:318
deleteqgraphicsitemcommand.h
DiagramView::copy
void copy()
Definition: diagramview.cpp:353
DVEventInterface::wheelEvent
virtual bool wheelEvent(QWheelEvent *event)
Definition: dveventinterface.cpp:54
diagramimageitem.h
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
DiagramView::contextMenuActions
QList< QAction * > contextMenuActions() const
DiagramView::contextMenuActions.
Definition: diagramview.cpp:1152
QETDiagramEditor::currentProjectView
ProjectView * currentProjectView() const
Definition: qetdiagrameditor.cpp:1129
DiagramView::switchToVisualisationModeIfNeeded
virtual bool switchToVisualisationModeIfNeeded(QInputEvent *e)
Definition: diagramview.cpp:1061
diagram.h
DiagramView::event
bool event(QEvent *) override
DiagramView::event Manage the event on this diagram view. -At first activation (QEvent::WindowActivat...
Definition: diagramview.cpp:1006
TitleBlockTemplateLocation::name
QString name() const
Definition: templatelocation.cpp:73
DiagramView::m_paste_here_pos
QPoint m_paste_here_pos
Definition: diagramview.h:55
DiagramView::dragMoveEvent
void dragMoveEvent(QDragMoveEvent *) override
Definition: diagramview.cpp:160
DiagramView::m_first_activation
bool m_first_activation
Definition: diagramview.h:58