QElectroTech  0.70
qetproject.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 QET_PROJECT_H
19 #define QET_PROJECT_H
20 
21 #include "nameslist.h"
22 #include "elementslocation.h"
23 #include "borderproperties.h"
24 #include "conductorproperties.h"
25 #include "titleblockproperties.h"
26 #include "templatescollection.h"
28 
29 class Diagram;
30 class ElementsLocation;
31 class QETResult;
32 class TitleBlockTemplate;
35 class QUndoStack;
37 class QTimer;
38 class KAutoSaveFile;
39 
46 class QETProject : public QObject
47 {
48  Q_OBJECT
49  public :
50  //This enum lists possible states for a particular project.
51  enum ProjectState {
52  Ok = 0,
58  };
59 
60  Q_PROPERTY(bool autoConductor READ autoConductor WRITE setAutoConductor)
61 
62  // constructors, destructor
63  public:
64  QETProject (QObject *parent = nullptr);
65  QETProject (const QString &path, QObject * = nullptr);
66  QETProject (KAutoSaveFile *backup, QObject *parent=nullptr);
67  ~QETProject() override;
68 
69  private:
70  QETProject(const QETProject &);
71 
72  // methods
73  public:
74  ProjectState state() const;
75  QList<Diagram *> diagrams() const;
76  int getFolioSheetsQuantity() const;
77  void setFolioSheetsQuantity(int);
78  int folioIndex(const Diagram *) const;
81  QString filePath();
82  void setFilePath(const QString &);
83  QString currentDir() const;
84  QString pathNameTitle() const;
85  QString title() const;
87  void setTitle(const QString &);
88 
92 
95 
98 
99  QString defaultReportProperties() const;
100  void setDefaultReportProperties (const QString &properties);
101 
102  XRefProperties defaultXRefProperties (const QString &type) const {return m_default_xref_properties[type];}
103  QHash <QString, XRefProperties> defaultXRefProperties() const {return m_default_xref_properties;}
104  void setDefaultXRefProperties(const QString& type, const XRefProperties &properties);
105  void setDefaultXRefProperties(QHash <QString, XRefProperties> hash);
106 
107  QHash <QString, NumerotationContext> conductorAutoNum() const;
108  QHash <QString, NumerotationContext> elementAutoNum() const;
109  QHash <QString, NumerotationContext> folioAutoNum() const;
110  void addConductorAutoNum (const QString& key, const NumerotationContext& context);
111  void addElementAutoNum (const QString& key, const NumerotationContext& context);
112  void addFolioAutoNum (const QString& key, const NumerotationContext& context);
113  void removeConductorAutoNum (const QString& key);
114  void removeElementAutoNum (const QString& key);
115  void removeFolioAutoNum (const QString& key);
116  NumerotationContext conductorAutoNum(const QString &key) const;
117  NumerotationContext folioAutoNum(const QString &key) const;
118  NumerotationContext elementAutoNum(const QString &key);
119 
120  QString conductorAutoNumFormula(const QString& key) const; //returns Formula
121  QString conductorCurrentAutoNum() const;
122  void setCurrentConductorAutoNum(QString autoNum);
123 
124  QString elementAutoNumFormula(const QString& key) const;
125  QString elementAutoNumCurrentFormula() const;
126  QString elementCurrentAutoNum() const;
127  void setCurrrentElementAutonum(QString autoNum);
128 
129  //Element
130  void freezeExistentElementLabel(bool freeze, int from, int to);
131  void freezeNewElementLabel(bool freeze, int from, int to);
132  bool isFreezeNewElements();
133  void setFreezeNewElements(bool);
134 
135  //Conductor
136  void freezeExistentConductorLabel(bool freeze, int from, int to);
137  void freezeNewConductorLabel(bool freeze, int from, int to);
138  bool isFreezeNewConductors();
139  void setFreezeNewConductors(bool);
140 
141  bool autoConductor () const;
142  bool autoElement () const;
143  bool autoFolio () const;
144  void setAutoConductor (bool ac);
145  void setAutoElement (bool ae);
147  void autoFolioNumberingSelectedFolios(int, int, const QString&);
148 
149  QDomDocument toXml();
150  bool close();
151  QETResult write();
152  bool isReadOnly() const;
153  void setReadOnly(bool);
154  bool isEmpty() const;
157  bool usesElement(const ElementsLocation &) const;
158  QList <ElementsLocation> unusedElements() const;
160  bool projectWasModified();
163  void setProjectProperties(const DiagramContext &);
164  QUndoStack* undoStack() {return m_undo_stack;}
165 
166  public slots:
168  QList <Diagram *> addNewDiagramFolioList();
169  void removeDiagram(Diagram *);
170  void diagramOrderChanged(int, int);
171  void setModified(bool);
172 
173  signals:
174  void projectFilePathChanged(QETProject *, const QString &);
175  void projectTitleChanged(QETProject *, const QString &);
177  void diagramAdded(QETProject *, Diagram *);
178  void diagramRemoved(QETProject *, Diagram *);
179  void projectModified(QETProject *, bool);
180  void projectDiagramsOrderChanged(QETProject *, int, int);
181  void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &);
182  void readOnlyChanged(QETProject *, bool);
183  void reportPropertiesChanged(const QString &old_str, const QString &new_str);
184  void XRefPropertiesChanged ();
185  void addAutoNumDiagram();
186  void elementAutoNumAdded(QString name);
187  void elementAutoNumRemoved(QString name);
188  void conductorAutoNumAdded();
190  void folioAutoNumAdded();
191  void folioAutoNumRemoved();
192  void folioAutoNumChanged(QString);
195 
196  private slots:
200  void usedTitleBlockTemplateChanged(const QString &);
201  void undoStackChanged (bool a) {if (!a) setModified(true);}
202 
203  private:
204  void readProjectXml(QDomDocument &xml_project);
205  void readDiagramsXml(QDomDocument &xml_project);
206  void readElementsCollectionXml(QDomDocument &xml_project);
207  void readProjectPropertiesXml(QDomDocument &xml_project);
208  void readDefaultPropertiesXml(QDomDocument &xml_project);
209 
210  void writeProjectPropertiesXml(QDomElement &);
211  void writeDefaultPropertiesXml(QDomElement &);
212  void addDiagram(Diagram *);
214  void writeBackup();
215  void init();
216  ProjectState openFile(QFile *file);
217 
218  // attributes
219  private:
221  QString m_file_path;
225  QList<Diagram *> m_diagrams_list;
227  QString project_title_;
231  bool m_modified = false;
233  bool m_read_only = false;
245  QHash <QString, XRefProperties> m_default_xref_properties;
251  QUndoStack *m_undo_stack;
253  QHash <QString, NumerotationContext> m_conductor_autonum;//Title and NumContext hash
256  QHash <QString, NumerotationContext> m_folio_autonum;
258  QHash <QString, NumerotationContext> m_element_autonum; //Title and NumContext hash
262  bool m_auto_conductor = true;
264  bool m_freeze_new_elements = false;
268  KAutoSaveFile *m_backup_file = nullptr;
269 };
270 
272 #endif
ProjectState m_state
Current state of the project.
Definition: qetproject.h:223
bool autoConductor() const
ElementsLocation importElement(ElementsLocation &location)
QETProject::importElement Import the element represented by to the embbeded collection of this proje...
Definition: qetproject.cpp:962
QString conductorCurrentAutoNum() const
QETProject::conductorCurrentAutoNum.
Definition: qetproject.cpp:561
bool m_freeze_new_elements
Definition: qetproject.h:264
QString title() const
Definition: qetproject.cpp:365
void setTitle(const QString &)
Definition: qetproject.cpp:381
QList< Diagram * > m_diagrams_list
Diagrams carried by the project.
Definition: qetproject.h:225
void setModified(bool)
bool m_read_only
Whether the project is read only.
Definition: qetproject.h:233
QList< Diagram * > diagrams() const
Definition: qetproject.cpp:210
bool isEmpty() const
Definition: qetproject.cpp:941
TitleBlockProperties defaultTitleBlockProperties() const
Definition: qetproject.cpp:415
int m_folio_sheets_quantity
Folio List Sheets quantity for this project.
Definition: qetproject.h:261
void usedTitleBlockTemplateChanged(const QString &)
ConductorProperties defaultConductorProperties() const
Definition: qetproject.cpp:455
QList< ElementsLocation > unusedElements() const
QETProject::unusedElements.
void addFolioAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addFolioAutoNum Add a new folio numerotation context. If key already exist, replace old context by the new context.
Definition: qetproject.cpp:612
void removeDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &)
bool isReadOnly() const
Definition: qetproject.cpp:915
void setDefaultTitleBlockProperties(const TitleBlockProperties &)
QETProject::setDefaultTitleBlockProperties Specify the title block to be used at the creation of a ne...
Definition: qetproject.cpp:424
void conductorAutoNumAdded()
void folioAutoNumRemoved()
void removeConductorAutoNum(const QString &key)
QETProject::removeConductorAutoNum Remove Conductor Numerotation Context stored with key...
Definition: qetproject.cpp:621
void conductorAutoNumRemoved()
void autoFolioNumberingSelectedFolios(int, int, const QString &)
QETProject::autoFolioNumberingNewFolios.
Definition: qetproject.cpp:794
void writeDefaultPropertiesXml(QDomElement &)
QETProject::writeDefaultPropertiesXml Export all defaults properties used by a new diagram and his co...
QHash< QString, NumerotationContext > conductorAutoNum() const
QETProject::conductorAutoNum.
Definition: qetproject.cpp:494
bool isFreezeNewConductors()
QETProject::isFreezeNewConductors.
Definition: qetproject.cpp:706
void setCurrrentElementAutonum(QString autoNum)
QETProject::setCurrrentElementAutonum.
Definition: qetproject.cpp:540
QString m_file_path
File path this project is saved to.
Definition: qetproject.h:221
The XRefProperties class this class store properties used by XrefItem.
void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &)
void freezeNewElementLabel(bool freeze, int from, int to)
QETProject::freezeNewElementLabel Freeze New Elements in the selected folios.
Definition: qetproject.cpp:736
QHash< QString, NumerotationContext > m_folio_autonum
Folio auto numbering.
Definition: qetproject.h:256
void projectInformationsChanged(QETProject *)
QUndoStack * undoStack()
Definition: qetproject.h:164
void removeElementAutoNum(const QString &key)
QETProject::removeElementAutonum Remove Element Numerotation Context stored with key.
Definition: qetproject.cpp:630
KAutoSaveFile * m_backup_file
Definition: qetproject.h:268
void setDefaultReportProperties(const QString &properties)
Definition: qetproject.cpp:471
void undoStackChanged(bool a)
Definition: qetproject.h:201
void writeProjectPropertiesXml(QDomElement &)
void autoFolioNumberingNewFolios()
QETProject::autoFolioNumberingNewFolios emit Signal to add new Diagram with autonum properties...
Definition: qetproject.cpp:785
void addDiagram(Diagram *)
QETProject::addDiagram Add a diagram in this project.
void setProjectProperties(const DiagramContext &)
void setAutoElement(bool ae)
TitleBlockProperties default_titleblock_properties_
Default title block properties for new diagrams created within the project.
Definition: qetproject.h:241
QString m_current_conductor_autonum
Definition: qetproject.h:254
void readProjectPropertiesXml(QDomDocument &xml_project)
QETProject::readProjectPropertiesXml Load project properties from the XML description of the project...
QHash< QString, NumerotationContext > folioAutoNum() const
QETProject::folioAutoNum.
Definition: qetproject.cpp:577
void removeFolioAutoNum(const QString &key)
QETProject::removeFolioAutonum Remove Folio Numerotation Context stored with key. ...
Definition: qetproject.cpp:641
QETResult write()
QETProject::write Save the project in a file.
Definition: qetproject.cpp:882
void setFilePath(const QString &)
QETProject::setFilePath Set the filepath of this project file Set a file path also create a backup fi...
Definition: qetproject.cpp:255
void updateDiagramsTitleBlockTemplate(TitleBlockTemplatesCollection *, const QString &)
void setCurrentConductorAutoNum(QString autoNum)
QETProject::setCurrentConductorAutoNum.
Definition: qetproject.cpp:569
void reportPropertiesChanged(const QString &old_str, const QString &new_str)
~QETProject() override
QETProject::~QETProject Destructor.
Definition: qetproject.cpp:111
int folioIndex(const Diagram *) const
set the folio sheets quantity for this project
Definition: qetproject.cpp:220
bool close()
Definition: qetproject.cpp:871
XmlElementCollection * m_elements_collection
Definition: qetproject.h:263
void addAutoNumDiagram()
int getFolioSheetsQuantity() const
Definition: qetproject.cpp:195
ConductorProperties default_conductor_properties_
Default conductor properties for new diagrams created within the project.
Definition: qetproject.h:239
void diagramAdded(QETProject *, Diagram *)
XmlElementCollection * embeddedElementCollection() const
QETProject::embeddedCollection.
Definition: qetproject.cpp:229
void readProjectXml(QDomDocument &xml_project)
QETProject::readProjectXml Read and make the project from an xml description.
bool m_freeze_new_conductors
Definition: qetproject.h:265
void setDefaultBorderProperties(const BorderProperties &)
Definition: qetproject.cpp:407
QString pathNameTitle() const
Definition: qetproject.cpp:316
QString read_only_file_path_
Filepath for which this project is considered read only.
Definition: qetproject.h:235
void setFolioSheetsQuantity(int)
get the folio sheets quantity for this project
Definition: qetproject.cpp:203
void folioAutoNumAdded()
qreal m_project_qet_version
QElectroTech version declared in the XML document at opening time.
Definition: qetproject.h:229
void diagramOrderChanged(int, int)
void projectFilePathChanged(QETProject *, const QString &)
DiagramContext projectProperties()
BorderProperties defaultBorderProperties() const
DEFAULT PROPERTIES.
Definition: qetproject.cpp:398
QString defaultReportProperties() const
Definition: qetproject.cpp:467
QString elementAutoNumCurrentFormula() const
QETProject::elementAutoNumCurrentFormula.
Definition: qetproject.cpp:524
QHash< QString, XRefProperties > defaultXRefProperties() const
Definition: qetproject.h:103
void setFreezeNewElements(bool)
QETProject::setfreezeNewElements Set Project Wide freeze new elements.
Definition: qetproject.cpp:754
QString conductorAutoNumFormula(const QString &key) const
QETProject::conductorAutoNumFormula.
Definition: qetproject.cpp:549
void projectModified(QETProject *, bool)
void addConductorAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addConductorAutoNum Add a new conductor numerotation context. If key already exist...
Definition: qetproject.cpp:588
void freezeNewConductorLabel(bool freeze, int from, int to)
QETProject::freezeNewConductorLabel Freeze New Conductors in the selected folios. ...
Definition: qetproject.cpp:696
QString m_current_element_autonum
Definition: qetproject.h:259
bool usesElement(const ElementsLocation &) const
ProjectState state() const
Definition: qetproject.cpp:187
void updateDiagramsFolioData()
void setFreezeNewConductors(bool)
QETProject::setfreezeNewConductors Set Project Wide freeze new conductors.
Definition: qetproject.cpp:714
void elementAutoNumRemoved(QString name)
void elementAutoNumAdded(QString name)
QDomDocument toXml()
Definition: qetproject.cpp:811
QUndoStack * m_undo_stack
undo stack for this project
Definition: qetproject.h:251
void readElementsCollectionXml(QDomDocument &xml_project)
QETProject::readElementsCollectionXml Load the diagrams from the xml description of the project...
QString elementAutoNumFormula(const QString &key) const
QETProject::elementAutoNumFormula.
Definition: qetproject.cpp:511
void readDefaultPropertiesXml(QDomDocument &xml_project)
QETProject::readDefaultPropertiesXml load default properties for new diagram, found in the xml of thi...
void freezeExistentConductorLabel(bool freeze, int from, int to)
QETProject::freezeExistentConductorLabel Freeze Existent Conductors in the selected folios...
Definition: qetproject.cpp:684
DiagramContext m_project_properties
project-wide variables that will be made available to child diagrams
Definition: qetproject.h:249
bool autoFolio() const
qreal declaredQElectroTechVersion()
Definition: qetproject.cpp:374
QString filePath()
Definition: qetproject.cpp:243
void writeBackup()
QETProject::writeBackup Write a backup file of this project, in the case that QET crash...
void readDiagramsXml(QDomDocument &xml_project)
QETProject::readDiagramsXml Load the diagrams from the xml description of the project. Note a project can have 0 diagram.
QString integrateTitleBlockTemplate(const TitleBlockTemplateLocation &, MoveTitleBlockTemplatesHandler *handler)
void projectDiagramsOrderChanged(QETProject *, int, int)
bool autoElement() const
QString elementCurrentAutoNum() const
QETProject::elementCurrentAutoNum.
Definition: qetproject.cpp:532
void setReadOnly(bool)
QETProject::setReadOnly Set this project to read only if = true.
Definition: qetproject.cpp:924
void freezeExistentElementLabel(bool freeze, int from, int to)
QETProject::freezeExistentElementLabel Freeze Existent Elements in the selected folios.
Definition: qetproject.cpp:724
bool projectOptionsWereModified()
NamesList namesListForIntegrationCategory()
bool m_modified
Whether options were modified.
Definition: qetproject.h:231
void conductorAutoNumChanged()
QHash< QString, NumerotationContext > m_element_autonum
Element Auto Numbering.
Definition: qetproject.h:258
QETProject(QObject *parent=nullptr)
QETProject::QETProject Create a empty project.
Definition: qetproject.cpp:47
void setAutoConductor(bool ac)
QETProject::setAutoConductor.
Definition: qetproject.cpp:774
void folioAutoNumChanged(QString)
the XML content is currently being processed
Definition: qetproject.h:56
void readOnlyChanged(QETProject *, bool)
QString m_default_report_properties
Default report properties.
Definition: qetproject.h:243
file opening failed
Definition: qetproject.h:54
QHash< QString, XRefProperties > m_default_xref_properties
Default xref properties.
Definition: qetproject.h:245
void setDefaultXRefProperties(const QString &type, const XRefProperties &properties)
Definition: qetproject.cpp:479
BorderProperties default_border_properties_
Default dimensions and properties for new diagrams created within the project.
Definition: qetproject.h:237
XRefProperties defaultXRefProperties(const QString &type) const
Definition: qetproject.h:102
void removeDiagram(Diagram *)
QString project_title_
Project title.
Definition: qetproject.h:227
bool usesTitleBlockTemplate(const TitleBlockTemplateLocation &)
void addElementAutoNum(const QString &key, const NumerotationContext &context)
QETProject::addElementAutoNum Add a new element numerotation context. If key already exist...
Definition: qetproject.cpp:599
the parsing of the XML content failed
Definition: qetproject.h:57
QTimer m_save_backup_timer
Definition: qetproject.h:266
Q_DECLARE_METATYPE(NamesList)
QString currentDir() const
Definition: qetproject.cpp:297
bool projectWasModified()
void setDefaultConductorProperties(const ConductorProperties &)
Definition: qetproject.cpp:463
bool isFreezeNewElements()
QETProject::freezeNewElements.
Definition: qetproject.cpp:746
void XRefPropertiesChanged()
QTimer m_autosave_timer
Definition: qetproject.h:266
QHash< QString, NumerotationContext > elementAutoNum() const
QETProject::elementAutoNum.
Definition: qetproject.cpp:502
TitleBlockTemplatesProjectCollection * embeddedTitleBlockTemplatesCollection()
Definition: qetproject.cpp:236
ProjectState openFile(QFile *file)
QETProject::openFile.
Definition: qetproject.cpp:151
QList< Diagram * > addNewDiagramFolioList()
QETProject::addNewDiagramFolioList Add new diagram folio list.
XML parsing failed.
Definition: qetproject.h:55
void defaultTitleBlockPropertiesChanged()
bool m_auto_conductor
Definition: qetproject.h:262
QHash< QString, NumerotationContext > m_conductor_autonum
Conductor auto numerotation.
Definition: qetproject.h:253
TitleBlockTemplatesProjectCollection m_titleblocks_collection
Embedded title block templates collection.
Definition: qetproject.h:247
void diagramRemoved(QETProject *, Diagram *)
void init()
QETProject::init.
Definition: qetproject.cpp:118
void projectTitleChanged(QETProject *, const QString &)
Diagram * addNewDiagram()
The XmlElementCollection class This class represent a collection of elements stored to xml...