QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
diagram.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 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
21#include "bordertitleblock.h"
22#include "conductorproperties.h"
23#include "elementsmover.h"
24#include "elementtextsmover.h"
25#include "exportproperties.h"
27#include "qetproject.h"
28#include "qgimanager.h"
29
30#include <QHash>
31#include <QUuid>
32#include <QtWidgets>
33#include <QtXml>
34
35class Conductor;
36class CustomElement;
37class DiagramContent;
38class DiagramPosition;
39class DiagramTextItem;
40class Element;
42class QETProject;
43class Terminal;
46class DiagramFolioList;
47class QETProject;
48
55class Diagram : public QGraphicsScene
56{
58 friend QETProject;
59
60 Q_OBJECT
61
62 // constructors, destructor
63 private:
65 ~Diagram() override;
66 Diagram(const Diagram &diagram);
67
68 // ATTRIBUTES
69 public:
85 static int xGrid;
87 static int yGrid;
89 static int xKeyGrid;
91 static int yKeyGrid;
93 static int xKeyGridFine;
95 static int yKeyGridFine;
97 static const qreal margin;
99 static QColor background_color;
101 QHash <QString, QStringList> m_elmt_unitfolio_max;
102 QHash <QString, QStringList> m_elmt_tenfolio_max;
103 QHash <QString, QStringList> m_elmt_hundredfolio_max;
105 QHash <QString, QStringList> m_cnd_unitfolio_max;
106 QHash <QString, QStringList> m_cnd_tenfolio_max;
107 QHash <QString, QStringList> m_cnd_hundredfolio_max;
108
109 private:
110 QGraphicsLineItem *conductor_setter_;
115
116 QDomDocument xml_document_;
117
119
124
127
130 QUuid m_uuid = QUuid::createUuid();
131
132 // METHODS
133 protected:
134 void drawBackground(QPainter *, const QRectF &) override;
135
137 QGraphicsSceneMouseEvent *event) override;
138 void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
139 void mouseMoveEvent (QGraphicsSceneMouseEvent *event) override;
140 void mouseReleaseEvent (
141 QGraphicsSceneMouseEvent *event) override;
142 void wheelEvent (QGraphicsSceneWheelEvent *event) override;
143 void keyPressEvent (QKeyEvent *event) override;
144 void keyReleaseEvent (QKeyEvent *) override;
145
146 public:
147 QUuid uuid();
148 void setEventInterface (DiagramEventInterface *event_interface);
149 void clearEventInterface();
150
151 //methods related to autonum
152 QString conductorsAutonumName() const;
153 void setConductorsAutonumName(const QString &name);
154
155 static bool clipboardMayContainDiagram();
156
157 // methods related to parent project
158 QETProject *project() const;
159 int folioIndex() const;
160 void showMe() {emit showDiagram(this);}
161 bool isReadOnly() const;
162
163 // methods related to conductor creation
164 void setConductor(bool);
165 void setConductorStart (QPointF);
166 void setConductorStop(QPointF);
167 QList < QSet <Conductor *> > potentials();
168
169 // methods related to XML import/export
170 QDomDocument toXml(bool = true);
171 bool initFromXml(QDomElement &,
172 QPointF = QPointF(),
173 bool = true,
174 DiagramContent * = nullptr);
175 bool fromXml(QDomDocument &,
176 QPointF = QPointF(),
177 bool = true,
178 DiagramContent * = nullptr);
179 bool fromXml(QDomElement &,
180 QPointF = QPointF(),
181 bool = true,
182 DiagramContent * = nullptr);
183 void folioSequentialsToXml(QHash<QString,
184 QStringList>*,
185 QDomElement *,
186 const QString&,
187 const QString&,
188 QDomDocument *);
189 void folioSequentialsFromXml(const QDomElement&,
190 QHash<QString,
191 QStringList>*,
192 const QString&,
193 const QString&,
194 const QString&,
195 const QString&);
196
197 void refreshContents();
198
199 // methods related to graphics items addition/removal on the diagram
200 virtual void addItem (QGraphicsItem *item);
201 virtual void removeItem (QGraphicsItem *item);
202
203 // methods related to graphics options
205 void setDisplayGrid(bool);
206 bool displayGrid();
207 void setUseBorder(bool);
208 bool useBorder();
211 DiagramPosition convertPosition(const QPointF &);
212 static QPointF snapToGrid(const QPointF &p);
213
214 bool drawTerminals() const;
215 void setDrawTerminals(bool);
216 bool drawColoredConductors() const;
217 void setDrawColoredConductors(bool);
218
219 QString title() const;
220 bool toPaintDevice(QPaintDevice &, int = -1, int = -1,
221 Qt::AspectRatioMode = Qt::KeepAspectRatio);
222 QSize imageSize() const;
223
224 bool isEmpty() const;
225
226 QList<Element *> elements() const;
227 QList<Conductor *> conductors() const;
228 QSet<Conductor *> selectedConductors() const;
229 DiagramContent content() const;
230 bool canRotateSelection() const;
233 bool usesElement(const ElementsLocation &);
234 bool usesTitleBlockTemplate(const QString &);
235
236 QUndoStack &undoStack();
238
239 //methods related to element label Update Policy
240 void freezeElements(bool freeze);
241 void unfreezeElements();
242 void setFreezeNewElements(bool);
243 bool freezeNewElements();
244
245 //methods related to conductor label Update Policy
246 void freezeConductors(bool freeze);
247 void setFreezeNewConductors(bool);
248 bool freezeNewConductors();
249
250 //methods related to insertion and loading of folio sequential
251 void insertFolioSeqHash (QHash<QString, QStringList> *hash,
252 const QString& title,
253 const QString& seq,
255 void loadFolioSeqHash (QHash<QString, QStringList> *hash,
256 const QString& title, const QString& seq,
258 void changeZValue(QET::DepthOption option);
259
260 public slots:
261 void adjustSceneRect ();
262 void titleChanged();
263 void titleBlockTemplateChanged(const QString &);
264 void titleBlockTemplateRemoved(const QString &,
265 const QString & = QString());
266 void setTitleBlockTemplate(const QString &);
267 void loadElmtFolioSeq();
268 void loadCndFolioSeq();
269
270 // methods related to graphics items selection
271 void selectAll();
272 void deselectAll();
273 void invertSelection();
274
275 signals:
277 void usedTitleBlockTemplateChanged(const QString &);
279
283
286};
288
289
296inline void Diagram::setConductor(bool adding) {
297 if (adding) {
298 if (!conductor_setter_ -> scene()) addItem(conductor_setter_);
299 } else {
300 if (conductor_setter_ -> scene()) removeItem(conductor_setter_);
301 }
302}
303
310inline void Diagram::setConductorStart(QPointF start) {
311 conductor_setter_ -> setLine(QLineF(start, conductor_setter_ -> line().p2()));
312}
313
320inline void Diagram::setConductorStop(QPointF end) {
321 conductor_setter_ -> setLine(QLineF(conductor_setter_ -> line().p1(), end));
322}
323
329inline void Diagram::setDisplayGrid(bool dg) {
330 draw_grid_ = dg;
331}
332
337inline bool Diagram::displayGrid() {
338 return(draw_grid_);
339}
340
349inline void Diagram::setUseBorder(bool ub) {
350 use_border_ = ub;
351}
352
358inline bool Diagram::useBorder() {
359 return(use_border_);
360}
361
374
381 BorderOptions options = EmptyBorder;
383 options = (BorderOptions)(options|TitleBlock);
385 options = (BorderOptions)(options|Columns);
386 return(options);
387}
388
393inline QUndoStack &Diagram::undoStack() {
394 return *(project()->undoStack());
395}
396
402 return(*qgi_manager_);
403}
404
409inline bool Diagram::drawTerminals() const
410{
411 return(draw_terminals_);
412}
413
419{
421}
422
423#endif
The BorderTitleBlock class This class represents the border and the titleblock which frame a particul...
Definition bordertitleblock.h:38
bool titleBlockIsDisplayed() const
Definition bordertitleblock.h:139
void displayColumns(bool)
BorderTitleBlock::displayColumns.
Definition bordertitleblock.cpp:459
void displayTitleBlock(bool)
BorderTitleBlock::displayTitleBlock.
Definition bordertitleblock.cpp:448
bool columnsAreDisplayed() const
Definition bordertitleblock.h:143
void displayBorder(bool)
BorderTitleBlock::displayBorder.
Definition bordertitleblock.cpp:485
Definition conductor.h:43
The ConductorProperties class This class represents the functional properties of a particular conduct...
Definition conductorproperties.h:68
Definition diagramcontent.h:47
The DiagramEventInterface class isRunning() return true if action is running (do something)....
Definition diagrameventinterface.h:47
The Diagram class This class represents an electric diagram. It manages its various child elements,...
Definition diagram.h:56
DiagramPosition convertPosition(const QPointF &)
Diagram::convertPosition.
Definition diagram.cpp:2277
void setDisplayGrid(bool)
Diagram::setDisplayGrid Set whether the diagram grid should be drawn.
Definition diagram.h:329
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:1804
bool draw_colored_conductors_
Definition diagram.h:123
ElementTextsMover m_element_texts_mover
Definition diagram.h:112
void unfreezeElements()
Diagram::unfreezeElements Unfreeze every existent element label.
Definition diagram.cpp:2165
static bool clipboardMayContainDiagram()
Diagram::clipboardMayContainDiagram.
Definition diagram.cpp:2367
QSize imageSize() const
Diagram::imageSize Allows you to know the dimensions that the image generated by the toImage() method...
Definition diagram.cpp:674
QDomDocument xml_document_
Definition diagram.h:116
virtual void removeItem(QGraphicsItem *item)
Diagram::removeItem Reimplemented from QGraphicsScene::removeItem(QGraphicsItem *item) Do some specif...
Definition diagram.cpp:1617
void freezeElements(bool freeze)
Diagram::freezeElements Freeze every existent element label.
Definition diagram.cpp:2155
void drawBackground(QPainter *, const QRectF &) override
Diagram::drawBackground Draw the background of the diagram, ie the grid.
Definition diagram.cpp:172
bool freezeNewConductors()
Diagram::freezeNewConductors.
Definition diagram.cpp:2211
ElementsMover m_elements_mover
Definition diagram.h:111
void freezeConductors(bool freeze)
Diagram::freezeConductors Freeze every existent conductor label.
Definition diagram.cpp:2193
friend QETProject
Definition diagram.h:58
bool displayGrid()
Diagram::displayGrid.
Definition diagram.h:337
void setConductorStop(QPointF)
Diagram::setConductorStop Set the end point of the conductor setter.
Definition diagram.h:320
QSet< Conductor * > selectedConductors() const
Diagram::selectedConductors.
Definition diagram.cpp:2351
void keyPressEvent(QKeyEvent *event) override
Diagram::keyPressEvent This event is managed by diagram event interface if any. Else move selected el...
Definition diagram.cpp:338
QHash< QString, QStringList > m_elmt_unitfolio_max
Hash containing max values for folio sequential autonums in this diagram.
Definition diagram.h:101
void keyReleaseEvent(QKeyEvent *) override
Diagram::keyReleaseEvent This event is managed by diagram event interface if any. Else move selected ...
Definition diagram.cpp:500
void setFreezeNewConductors(bool)
Diagram::setfreezeNewConductors Set new conductor label to be frozen.
Definition diagram.cpp:2203
DiagramEventInterface * m_event_interface
Definition diagram.h:126
void setBorderOptions(BorderOptions)
Diagram::setBorderOptions Set the rendering options for the diagram border (including rows/columns he...
Definition diagram.h:369
void setDrawTerminals(bool)
Diagram::setDrawTerminals Defines whether or not to display the terminals.
Definition diagram.cpp:2325
bool draw_grid_
Definition diagram.h:120
void setDrawColoredConductors(bool)
Diagram::setDrawColoredConductors Defines whether or not to respect the colors of the conductors....
Definition diagram.cpp:2342
void folioSequentialsToXml(QHash< QString, QStringList > *, QDomElement *, const QString &, const QString &, QDomDocument *)
Diagram::folioSequentialsToXml Add folio sequential to QDomElement.
Definition diagram.cpp:1017
void titleChanged()
Diagram::titleChanged emit(diagramTitleChanged(this, title));.
Definition diagram.cpp:1647
void diagramActivated()
bool useBorder()
Diagram::useBorder.
Definition diagram.h:358
void showDiagram(Diagram *)
BorderOptions borderOptions()
Diagram::borderOptions.
Definition diagram.h:380
bool canRotateSelection() const
Diagram::canRotateSelection.
Definition diagram.cpp:2436
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mouseDoubleClickEvent This event is managed by diagram event interface if any.
Definition diagram.cpp:242
bool m_freeze_new_conductors_
Definition diagram.h:129
bool drawTerminals() const
Diagram::drawTerminals.
Definition diagram.h:409
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:1522
void clearEventInterface()
Diagram::clearEventInterface Clear the current event interface.
Definition diagram.cpp:573
void loadElmtFolioSeq()
Diagram::loadElmtFolioSeq This class loads all folio sequential variables related to the current auto...
Definition diagram.cpp:1901
bool toPaintDevice(QPaintDevice &, int=-1, int=-1, Qt::AspectRatioMode=Qt::KeepAspectRatio)
Definition diagram.cpp:603
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:1070
void deselectAll()
Diagram::deselectAll Deselects all selected objects.
Definition diagram.cpp:1729
QDomDocument toXml(bool=true)
Diagram::toXml Exports all or part of the schema.
Definition diagram.cpp:747
void setUseBorder(bool)
Diagram::setUseBorder Set whether the diagram border (including rows/columns headers and the title bl...
Definition diagram.h:349
QETProject * m_project
Definition diagram.h:114
void invertSelection()
Diagram::invertSelection Reverses the selection state of all schema objects Inverse l'etat de selecti...
Definition diagram.cpp:1741
NumerotationType
Represents available option of Numerotation type.
Definition diagram.h:79
@ Conductors
Definition diagram.h:79
bool drawColoredConductors() const
Diagram::drawColoredConductors.
Definition diagram.h:418
bool usesTitleBlockTemplate(const QString &)
Diagram::usesTitleBlockTemplate.
Definition diagram.cpp:2147
static int xKeyGrid
Key grid x step size.
Definition diagram.h:89
BorderOptions
The BorderOptions enum Represents available options when rendering a particular diagram: EmptyBorder:...
Definition diagram.h:77
@ TitleBlock
Definition diagram.h:77
@ EmptyBorder
Definition diagram.h:77
@ Columns
Definition diagram.h:77
ConductorProperties defaultConductorProperties
Default properties for new conductors.
Definition diagram.h:81
void adjustSceneRect()
Diagram::adjustSceneRect Recalcul and adjust the size of the scene.
Definition diagram.cpp:2220
QList< QSet< Conductor * > > potentials()
Diagram::potential.
Definition diagram.cpp:715
QList< Conductor * > conductors() const
Diagram::conductors.
Definition diagram.cpp:2092
bool initFromXml(QDomElement &, QPointF=QPointF(), bool=true, DiagramContent *=nullptr)
Diagram::initFromXml Imports the described schema in an XML element. This method delegates its work t...
Definition diagram.cpp:1108
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mousePressEvent This event is managed by diagram event interface if any.
Definition diagram.cpp:261
int folioIndex() const
Diagram::folioIndex.
Definition diagram.cpp:2392
static int xKeyGridFine
Key grid fine x step size.
Definition diagram.h:93
void changeZValue(QET::DepthOption option)
Diagram::changeZValue Change the Z value of the current selected item, according to option.
Definition diagram.cpp:1828
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:1777
void setEventInterface(DiagramEventInterface *event_interface)
Diagram::setEventInterface Set event_interface has current interface. Diagram become the ownership of...
Definition diagram.cpp:553
ExportProperties applyProperties(const ExportProperties &)
Diagram::applyProperties This method allows you to apply new rendering options while accessing the cu...
Definition diagram.cpp:2240
qreal diagram_qet_version_
Definition diagram.h:118
QString m_conductors_autonum_name
Definition diagram.h:125
QString conductorsAutonumName() const
Diagram::conductorsAutonumName.
Definition diagram.cpp:586
void wheelEvent(QGraphicsSceneWheelEvent *event) override
Diagram::wheelEvent This event is managed by diagram event interface if any.
Definition diagram.cpp:318
QHash< QString, QStringList > m_cnd_tenfolio_max
Definition diagram.h:106
QETProject * project() const
Diagram::project.
Definition diagram.cpp:2382
void titleBlockTemplateChanged(const QString &)
Diagram::titleBlockTemplateChanged This slot may be used to inform the diagram object that the given ...
Definition diagram.cpp:1658
static int xGrid
abscissa grid step size
Definition diagram.h:85
void loadCndFolioSeq()
Diagram::loadCndFolioSeq This class loads all conductor folio sequential variables related to the cur...
Definition diagram.cpp:1987
void findElementRequired(const ElementsLocation &)
QHash< QString, QStringList > m_cnd_unitfolio_max
Hash containing max values for folio sequential autonums in this diagram.
Definition diagram.h:105
bool freezeNewElements()
Diagram::freezeNewElements.
Definition diagram.cpp:2184
DiagramContent content() const
Diagram::content.
Definition diagram.cpp:2415
void setFreezeNewElements(bool)
Diagram::freezeNewElements Set new element label to be frozen.
Definition diagram.cpp:2176
QGraphicsLineItem * conductor_setter_
Definition diagram.h:110
QGIManager * qgi_manager_
Definition diagram.h:113
QUndoStack & undoStack()
Diagram::undoStack.
Definition diagram.h:393
QUuid m_uuid
Definition diagram.h:130
void titleBlockTemplateRemoved(const QString &, const QString &=QString())
Diagram::titleBlockTemplateRemoved This slot has to be be used to inform this class that the given ti...
Definition diagram.cpp:1675
QHash< QString, QStringList > m_elmt_hundredfolio_max
Definition diagram.h:103
bool m_freeze_new_elements
Definition diagram.h:128
bool isReadOnly() const
Diagram::isReadOnly.
Definition diagram.cpp:2403
void diagramTitleChanged(Diagram *)
QUuid uuid()
Diagram::uuid.
Definition diagram.cpp:540
bool draw_terminals_
Definition diagram.h:122
static int yKeyGrid
Key grid y step size.
Definition diagram.h:91
static int yGrid
ordinate grid step size
Definition diagram.h:87
ElementsMover & elementsMover()
Diagram::elementsMover.
Definition diagram.cpp:2106
QGIManager & qgiManager()
Diagram::qgiManager.
Definition diagram.h:401
virtual void addItem(QGraphicsItem *item)
Diagram::addItem Réimplemented from QGraphicsScene::addItem(QGraphicsItem *item) Do some specific ope...
Definition diagram.cpp:1586
static QPointF snapToGrid(const QPointF &p)
Diagram::snapToGrid Return a nearest snap point of p.
Definition diagram.cpp:2294
void setConductorStart(QPointF)
Diagram::setConductorStart Set the start point of the conductor setter.
Definition diagram.h:310
BorderTitleBlock border_and_titleblock
Diagram dimensions and title block.
Definition diagram.h:83
bool isEmpty() const
Diagram::isEmpty An empty schema contains no element, conductor, or text field.
Definition diagram.cpp:704
static QColor background_color
background color of diagram
Definition diagram.h:99
friend DiagramFolioList
Definition diagram.h:57
void setConductorsAutonumName(const QString &name)
Diagram::setConductorsAutonumName.
Definition diagram.cpp:595
QHash< QString, QStringList > m_cnd_hundredfolio_max
Definition diagram.h:107
ElementTextsMover & elementTextsMover()
Diagram::elementTextsMover.
Definition diagram.cpp:2115
void setConductor(bool)
Diagram::setConductor Display or hide the conductor setter, i.e. a dashed conductor stub which appear...
Definition diagram.h:296
bool use_border_
Definition diagram.h:121
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mouseMoveEvent This event is managed by diagram event interface if any.
Definition diagram.cpp:280
QHash< QString, QStringList > m_elmt_tenfolio_max
Definition diagram.h:102
void refreshContents()
Diagram::refreshContents refresh all content of diagram.
Definition diagram.cpp:1557
void usedTitleBlockTemplateChanged(const QString &)
QString title() const
Diagram::title.
Definition diagram.cpp:2069
QList< Element * > elements() const
Diagram::elements.
Definition diagram.cpp:2078
Diagram(const Diagram &diagram)
void showMe()
Definition diagram.h:160
~Diagram() override
Diagram::~Diagram Destructor.
Definition diagram.cpp:129
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
Diagram::mouseReleaseEvent This event is managed by diagram event interface if any.
Definition diagram.cpp:299
void setTitleBlockTemplate(const QString &)
Diagram::setTitleBlockTemplate Set the template to use to render the title block of this diagram.
Definition diagram.cpp:1692
static int yKeyGridFine
Key grid fine y step size.
Definition diagram.h:95
static const qreal margin
margin around the diagram
Definition diagram.h:97
void diagramInformationChanged()
void selectAll()
Diagram::selectAll Select all schema objects.
Definition diagram.cpp:1714
bool usesElement(const ElementsLocation &)
Diagram::usesElement Used to find out if an element is used on a schema.
Definition diagram.cpp:2131
Definition diagramimageitem.h:31
Definition diagramposition.h:28
Definition diagramtextitem.h:34
Definition element.h:43
Definition elementtextsmover.h:36
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition elementslocation.h:47
Definition elementsmover.h:41
Definition exportproperties.h:27
Definition numerotationcontext.h:31
Definition qetproject.h:62
QUndoStack * undoStack()
Definition qetproject.h:183
Definition qgimanager.h:30
The Terminal class This class represents a terminal of an electrical element, i.e....
Definition terminal.h:36
Q_DECLARE_METATYPE(NamesList)
DepthOption
List the various kind of changes for the zValue.
Definition qet.h:41