QElectroTech  0.70
diagram.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 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 DIAGRAM_H
19 #define DIAGRAM_H
20 #include <QtWidgets>
21 #include <QtXml>
22 #include <QHash>
23 #include "bordertitleblock.h"
24 #include "conductorproperties.h"
25 #include "exportproperties.h"
26 #include "qgimanager.h"
27 #include "numerotationcontext.h"
28 #include "qetproject.h"
30 #include "elementsmover.h"
31 #include "elementtextsmover.h"
32 
33 class Conductor;
34 class CustomElement;
35 class DiagramContent;
36 class DiagramPosition;
37 class DiagramTextItem;
38 class Element;
39 class ElementsLocation;
40 class QETProject;
41 class Terminal;
42 class DiagramImageItem;
44 
49 class Diagram : public QGraphicsScene
50 {
51  Q_OBJECT
52 
53  // constructors, destructor
54  public:
56  ~Diagram() override;
57  private:
58  Diagram(const Diagram &diagram);
59 
60  // ATTRIBUTES
61  public:
76  static int xGrid;
78  static int yGrid;
80  static int xKeyGrid;
82  static int yKeyGrid;
84  static int xKeyGridFine;
86  static int yKeyGridFine;
88  static const qreal margin;
90 
91  static QColor background_color;
93  QHash <QString, QStringList> m_elmt_unitfolio_max;
94  QHash <QString, QStringList> m_elmt_tenfolio_max;
95  QHash <QString, QStringList> m_elmt_hundredfolio_max;
97  QHash <QString, QStringList> m_cnd_unitfolio_max;
98  QHash <QString, QStringList> m_cnd_tenfolio_max;
99  QHash <QString, QStringList> m_cnd_hundredfolio_max;
100 
101  private:
102  QGraphicsLineItem *conductor_setter_;
107 
108  QDomDocument xml_document_;
109 
111 
116 
119 
122 
123  // METHODS
124  protected:
125  void drawBackground(QPainter *, const QRectF &) override;
126 
127  void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *event) override;
128  void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
129  void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
130  void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) override;
131  void wheelEvent (QGraphicsSceneWheelEvent *event) override;
132  void keyPressEvent (QKeyEvent *event) override;
133  void keyReleaseEvent (QKeyEvent *) override;
134 
135  public:
136  void setEventInterface (DiagramEventInterface *event_interface);
137  void clearEventInterface();
138 
139  //methods related to autonum
140  QString conductorsAutonumName() const;
141  void setConductorsAutonumName(const QString &name);
142 
143  static bool clipboardMayContainDiagram();
144 
145  // methods related to parent project
146  QETProject *project() const;
147  void setProject(QETProject *);
148  int folioIndex() const;
149  qreal declaredQElectroTechVersion(bool = true) const;
150  void showMe() {emit showDiagram(this);}
151  bool isReadOnly() const;
152 
153  // methods related to conductor creation
154  void setConductor(bool);
155  void setConductorStart (QPointF);
156  void setConductorStop(QPointF);
157  QList < QSet <Conductor *> > potentials();
158 
159  // methods related to XML import/export
160  QDomDocument toXml(bool = true);
161  bool initFromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = nullptr);
162  bool fromXml(QDomDocument &, QPointF = QPointF(), bool = true, DiagramContent * = nullptr);
163  bool fromXml(QDomElement &, QPointF = QPointF(), bool = true, DiagramContent * = nullptr);
164  void folioSequentialsToXml(QHash<QString, QStringList>*, QDomElement *, const QString&, const QString&, QDomDocument *);
165  void folioSequentialsFromXml(const QDomElement&, QHash<QString, QStringList>*, const QString&, const QString&, const QString&, const QString&);
166 
167  void refreshContents();
168 
169  // methods related to graphics items addition/removal on the diagram
170  virtual void addItem (QGraphicsItem *item);
171  virtual void removeItem (QGraphicsItem *item);
172 
173  // methods related to graphics options
175  void setDisplayGrid(bool);
176  bool displayGrid();
177  void setUseBorder(bool);
178  bool useBorder();
181  DiagramPosition convertPosition(const QPointF &);
182  static QPointF snapToGrid(const QPointF &p);
183 
184  bool drawTerminals() const;
185  void setDrawTerminals(bool);
186  bool drawColoredConductors() const;
187  void setDrawColoredConductors(bool);
188 
189  QString title() const;
190  bool toPaintDevice(QPaintDevice &, int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio);
191  QSize imageSize() const;
192 
193  bool isEmpty() const;
194 
195  QList<Element *> elements() const;
196  QList<Conductor *> conductors() const;
197  QSet<Conductor *> selectedConductors() const;
198  DiagramContent content() const;
199  bool canRotateSelection() const;
202  bool usesElement(const ElementsLocation &);
203  bool usesTitleBlockTemplate(const QString &);
204 
205  QUndoStack &undoStack();
207 
208  //methods related to element label Update Policy
209  void freezeElements(bool freeze);
210  void unfreezeElements();
211  void setFreezeNewElements(bool);
212  bool freezeNewElements();
213 
214  //methods related to conductor label Update Policy
215  void freezeConductors(bool freeze);
216  void setFreezeNewConductors(bool);
217  bool freezeNewConductors();
218 
219  //methods related to insertion and loading of folio sequential
220  void insertFolioSeqHash (QHash<QString, QStringList> *hash, const QString& title, const QString& seq, NumerotationContext *nc);
221  void loadFolioSeqHash (QHash<QString, QStringList> *hash, const QString& title, const QString& seq, NumerotationContext *nc);
222  void changeZValue(QET::DepthOption option);
223 
224  public slots:
225  void adjustSceneRect ();
226  void titleChanged(const QString &);
227  void titleBlockTemplateChanged(const QString &);
228  void titleBlockTemplateRemoved(const QString &, const QString & = QString());
229  void setTitleBlockTemplate(const QString &);
230  void updateLabels();
231  void loadElmtFolioSeq();
232  void loadCndFolioSeq();
233 
234  // methods related to graphics items selection
235  void selectAll();
236  void deselectAll();
237  void invertSelection();
238 
239  signals:
240  void showDiagram (Diagram *);
241  void usedTitleBlockTemplateChanged(const QString &);
242  void diagramTitleChanged(Diagram *, const QString &);
243  void findElementRequired(const ElementsLocation &);
244  void editElementRequired(const ElementsLocation &);
245  void diagramActivated();
246 };
248 
249 
253 inline void Diagram::setConductor(bool adding) {
254  if (adding) {
255  if (!conductor_setter_ -> scene()) addItem(conductor_setter_);
256  } else {
257  if (conductor_setter_ -> scene()) removeItem(conductor_setter_);
258  }
259 }
260 
266 inline void Diagram::setConductorStart(QPointF start) {
267  conductor_setter_ -> setLine(QLineF(start, conductor_setter_ -> line().p2()));
268 }
269 
275 inline void Diagram::setConductorStop(QPointF end) {
276  conductor_setter_ -> setLine(QLineF(conductor_setter_ -> line().p1(), end));
277 }
278 
283 inline void Diagram::setDisplayGrid(bool dg) {
284  draw_grid_ = dg;
285 }
286 
290 inline bool Diagram::displayGrid() {
291  return(draw_grid_);
292 }
293 
301 inline void Diagram::setUseBorder(bool ub) {
302  use_border_ = ub;
303 }
304 
309 inline bool Diagram::useBorder() {
310  return(use_border_);
311 }
312 
323 }
324 
330  BorderOptions options = EmptyBorder;
333  return(options);
334 }
335 
337 inline QUndoStack &Diagram::undoStack() {
338  return *(project()->undoStack());
339 }
340 
343  return(*qgi_manager_);
344 }
345 
347 inline bool Diagram::drawTerminals() const {
348  return(draw_terminals_);
349 }
350 
352 inline bool Diagram::drawColoredConductors() const {
353  return(draw_colored_conductors_);
354 }
355 
356 #endif
void setTitleBlockTemplate(const QString &)
Definition: diagram.cpp:1195
void setConductor(bool)
Definition: diagram.h:253
void showDiagram(Diagram *)
static int yGrid
ordinate grid step size
Definition: diagram.h:78
void setDisplayGrid(bool)
Definition: diagram.h:283
void setProject(QETProject *)
Diagram::setProject Set parent project of this diagram, project also become the parent QObject of thi...
Definition: diagram.cpp:1725
bool useBorder()
Definition: diagram.h:309
void changeZValue(QET::DepthOption option)
Diagram::changeZValue Change the Z value of the current selected item, according to ...
Definition: diagram.cpp:1300
bool draw_grid_
Definition: diagram.h:112
void insertFolioSeqHash(QHash< QString, QStringList > *hash, const QString &title, const QString &seq, NumerotationContext *nc)
Diagram::insertFolioSeqHash This class inserts a stringlist containing all sequential variables relat...
Definition: diagram.cpp:1263
ElementTextsMover m_element_texts_mover
Definition: diagram.h:104
void adjustSceneRect()
Diagram::adjustSceneRect Recalcul and adjust the size of the scene.
Definition: diagram.cpp:1597
void setConductorsAutonumName(const QString &name)
Diagram::setConductorsAutonumName.
Definition: diagram.cpp:496
QHash< QString, QStringList > m_cnd_unitfolio_max
Hash containing max values for folio sequential autonums in this diagram.
Definition: diagram.h:97
void folioSequentialsToXml(QHash< QString, QStringList > *, QDomElement *, const QString &, const QString &, QDomDocument *)
Diagram::folioSequentialsToXml.
Definition: diagram.cpp:779
static const qreal margin
margin around the diagram
Definition: diagram.h:88
void invertSelection()
Definition: diagram.cpp:1231
void diagramActivated()
Signal emitted when users wish to edit an element from the diagram.
bool m_freeze_new_elements
Definition: diagram.h:120
bool usesTitleBlockTemplate(const QString &)
Definition: diagram.cpp:1527
QHash< QString, QStringList > m_cnd_hundredfolio_max
Definition: diagram.h:99
QETProject * m_project
Definition: diagram.h:106
int folioIndex() const
Definition: diagram.cpp:1738
void titleChanged(const QString &)
Definition: diagram.cpp:1158
QSet< Conductor * > selectedConductors() const
Definition: diagram.cpp:1695
QHash< QString, QStringList > m_cnd_tenfolio_max
Definition: diagram.h:98
void setUseBorder(bool)
Definition: diagram.h:301
QSize imageSize() const
Definition: diagram.cpp:551
QUndoStack * undoStack()
Definition: qetproject.h:164
void setDrawTerminals(bool)
Definition: diagram.cpp:1675
QHash< QString, QStringList > m_elmt_unitfolio_max
Hash containing max values for folio sequential autonums in this diagram.
Definition: diagram.h:93
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mouseMoveEvent This event is managed by diagram event interface if any.
Definition: diagram.cpp:227
static int yKeyGridFine
Key grid fine y step size.
Definition: diagram.h:86
bool isReadOnly() const
Diagram::isReadOnly.
Definition: diagram.cpp:1764
NumerotationType
Represents available option of Numerotation type.
Definition: diagram.h:70
void freezeElements(bool freeze)
Diagram::freezeElements Freeze every existent element label.
Definition: diagram.cpp:1535
void displayTitleBlock(bool)
QList< Conductor * > conductors() const
Diagram::conductors Return the list containing all conductors.
Definition: diagram.cpp:1490
qreal diagram_qet_version_
Definition: diagram.h:110
Diagram(QETProject *project)
Diagram::Diagram Constructor.
Definition: diagram.cpp:57
void editElementRequired(const ElementsLocation &)
Signal emitted when users wish to locate an element from the diagram within elements collection...
bool draw_colored_conductors_
Definition: diagram.h:115
BorderOptions borderOptions()
Definition: diagram.h:329
static int xGrid
abscissa grid step size
Definition: diagram.h:76
QList< QSet< Conductor * > > potentials()
Diagram::potential.
Definition: diagram.cpp:583
bool drawTerminals() const
Definition: diagram.h:347
QDomDocument toXml(bool=true)
Definition: diagram.cpp:604
void usedTitleBlockTemplateChanged(const QString &)
DiagramEventInterface * m_event_interface
Definition: diagram.h:118
ElementsMover & elementsMover()
Definition: diagram.cpp:1499
ElementTextsMover & elementTextsMover()
Definition: diagram.cpp:1503
void titleBlockTemplateChanged(const QString &)
Definition: diagram.cpp:1168
void setConductorStop(QPointF)
Definition: diagram.h:275
virtual void removeItem(QGraphicsItem *item)
Diagram::removeItem Réimplemented from QGraphicsScene::removeItem(QGraphicsItem *item) Do some specif...
Definition: diagram.cpp:1133
QString title() const
Definition: diagram.cpp:1473
bool initFromXml(QDomElement &, QPointF=QPointF(), bool=true, DiagramContent *=nullptr)
Definition: diagram.cpp:824
static int xKeyGridFine
Key grid fine x step size.
Definition: diagram.h:84
QString conductorsAutonumName() const
Diagram::conductorsAutonumName.
Definition: diagram.cpp:488
qreal declaredQElectroTechVersion(bool=true) const
Definition: diagram.cpp:1749
BorderOptions
Definition: diagram.h:68
bool columnsAreDisplayed() const
bool freezeNewConductors()
Diagram::freezeNewConductors.
Definition: diagram.cpp:1589
bool isEmpty() const
Definition: diagram.cpp:574
ExportProperties applyProperties(const ExportProperties &)
Definition: diagram.cpp:1610
QGIManager & qgiManager()
Definition: diagram.h:342
QGraphicsLineItem * conductor_setter_
Definition: diagram.h:102
bool toPaintDevice(QPaintDevice &, int=-1, int=-1, Qt::AspectRatioMode=Qt::KeepAspectRatio)
Definition: diagram.cpp:504
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mouseReleaseEvent This event is managed by diagram event interface if any.
Definition: diagram.cpp:246
DepthOption
List the various kind of changes for the zValue.
Definition: qet.h:43
static int yKeyGrid
Key grid y step size.
Definition: diagram.h:82
void setEventInterface(DiagramEventInterface *event_interface)
Diagram::setEventInterface Set event_interface has current interface. Diagram become the ownership of...
Definition: diagram.cpp:455
DiagramContent content() const
Definition: diagram.cpp:1773
DiagramPosition convertPosition(const QPointF &)
Definition: diagram.cpp:1637
void updateLabels()
Diagram::updateLabels Update elements and conductors that reference folio field in their labels...
Definition: diagram.cpp:1245
bool drawColoredConductors() const
Definition: diagram.h:352
void freezeConductors(bool freeze)
Diagram::freezeConductors Freeze every existent conductor label.
Definition: diagram.cpp:1571
bool titleBlockIsDisplayed() const
void keyReleaseEvent(QKeyEvent *) override
Diagram::keyReleaseEvent This event is managed by diagram event interface if any. Else move selected ...
Definition: diagram.cpp:418
void keyPressEvent(QKeyEvent *event) override
Diagram::keyPressEvent This event is managed by diagram event interface if any. Else move selected el...
Definition: diagram.cpp:285
void deselectAll()
Definition: diagram.cpp:1222
bool displayGrid()
Definition: diagram.h:290
void setDrawColoredConductors(bool)
Definition: diagram.cpp:1688
QString m_conductors_autonum_name
Definition: diagram.h:117
static QColor background_color
background color of diagram
Definition: diagram.h:91
void drawBackground(QPainter *, const QRectF &) override
Definition: diagram.cpp:131
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mouseDoubleClickEvent This event is managed by diagram event interface if any...
Definition: diagram.cpp:189
bool fromXml(QDomDocument &, QPointF=QPointF(), bool=true, DiagramContent *=nullptr)
Definition: diagram.cpp:804
bool freezeNewElements()
Diagram::freezeNewElements.
Definition: diagram.cpp:1563
QHash< QString, QStringList > m_elmt_hundredfolio_max
Definition: diagram.h:95
void loadFolioSeqHash(QHash< QString, QStringList > *hash, const QString &title, const QString &seq, NumerotationContext *nc)
Diagram::loadFolioSeqHash This class loads all folio sequential variables related to the current auto...
Definition: diagram.cpp:1284
bool m_freeze_new_conductors_
Definition: diagram.h:121
static QPointF snapToGrid(const QPointF &p)
Diagram::snapToGrid Return a nearest snap point of p.
Definition: diagram.cpp:1653
QUndoStack & undoStack()
Definition: diagram.h:337
QGIManager * qgi_manager_
Definition: diagram.h:105
QHash< QString, QStringList > m_elmt_tenfolio_max
Definition: diagram.h:94
static bool clipboardMayContainDiagram()
Definition: diagram.cpp:1706
void unfreezeElements()
Diagram::unfreezeElements Unfreeze every existent element label.
Definition: diagram.cpp:1545
void diagramTitleChanged(Diagram *, const QString &)
static int xKeyGrid
Key grid x step size.
Definition: diagram.h:80
void setFreezeNewElements(bool)
Diagram::freezeNewElements Set new element label to be frozen.
Definition: diagram.cpp:1555
ElementsMover m_elements_mover
Definition: diagram.h:103
The DiagramEventInterface class isRunning() return true if action is running (do something). By default return false.
void loadCndFolioSeq()
Diagram::loadCndFolioSeq This class loads all conductor folio sequential variables related to the cur...
Definition: diagram.cpp:1415
void selectAll()
Definition: diagram.cpp:1210
QList< Element * > elements() const
Definition: diagram.cpp:1477
void findElementRequired(const ElementsLocation &)
void setConductorStart(QPointF)
Definition: diagram.h:266
void loadElmtFolioSeq()
Diagram::loadElmtFolioSeq This class loads all folio sequential variables related to the current auto...
Definition: diagram.cpp:1357
void setBorderOptions(BorderOptions)
Definition: diagram.h:319
void setFreezeNewConductors(bool)
Diagram::setfreezeNewConductors Set new conductor label to be frozen.
Definition: diagram.cpp:1581
virtual void addItem(QGraphicsItem *item)
Diagram::addItem Réimplemented from QGraphicsScene::addItem(QGraphicsItem *item) Do some specific ope...
Definition: diagram.cpp:1108
QDomDocument xml_document_
Definition: diagram.h:108
~Diagram() override
Diagram::~Diagram Destructor.
Definition: diagram.cpp:100
Q_DECLARE_METATYPE(NamesList)
void refreshContents()
Diagram::refreshContents refresh all content of diagram.
Definition: diagram.cpp:1089
void clearEventInterface()
Diagram::clearEventInterface Clear the current event interface.
Definition: diagram.cpp:475
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition: diagram.h:74
void titleBlockTemplateRemoved(const QString &, const QString &=QString())
Definition: diagram.cpp:1183
QETProject * project() const
Definition: diagram.cpp:1716
void folioSequentialsFromXml(const QDomElement &, QHash< QString, QStringList > *, const QString &, const QString &, const QString &, const QString &)
Diagram::folioSequentialsFromXml Load folio sequential from QDomElement.
Definition: diagram.cpp:1067
bool canRotateSelection() const
Diagram::canRotateSelection.
Definition: diagram.cpp:1791
bool draw_terminals_
Definition: diagram.h:114
ConductorProperties defaultConductorProperties
Default properties for new conductors.
Definition: diagram.h:72
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mousePressEvent This event is managed by diagram event interface if any. ...
Definition: diagram.cpp:208
void wheelEvent(QGraphicsSceneWheelEvent *event) override
Diagram::wheelEvent This event is managed by diagram event interface if any.
Definition: diagram.cpp:265
void showMe()
Definition: diagram.h:150
bool use_border_
Definition: diagram.h:113
bool usesElement(const ElementsLocation &)
Definition: diagram.cpp:1512