QElectroTech  0.8-dev
templatescollection.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 TITLEBLOCK_SLASH_TEMPLATES_COLLECTION_H
19 #define TITLEBLOCK_SLASH_TEMPLATES_COLLECTION_H
20 #define TITLEBLOCKS_FILE_EXTENSION ".titleblock"
21 #include <QtCore>
22 #include <QtXml>
23 #include "templatelocation.h"
24 #include "qet.h"
25 class TitleBlockTemplate;
26 class QETProject;
27 
34 class TitleBlockTemplatesCollection : public QObject {
35  Q_OBJECT
36 
37  // Constructors, destructor
38  public:
39  TitleBlockTemplatesCollection(QObject *parent);
41  private:
43 
44  // methods
45  public:
46  virtual QStringList templates() = 0;
47  virtual TitleBlockTemplate *getTemplate(const QString &) = 0;
48  virtual QDomElement getTemplateXmlDescription(const QString &) = 0;
49  virtual bool setTemplateXmlDescription(const QString &, const QDomElement &) = 0;
50  virtual void removeTemplate(const QString &) = 0;
51  virtual TitleBlockTemplateLocation location(const QString & = QString()) = 0;
52  virtual bool hasFilePath() = 0;
53  virtual QString filePath() = 0;
54  virtual bool isReadOnly(const QString & = QString()) const = 0;
55  virtual QString title() const;
56  virtual void setTitle(const QString &);
57  virtual QString protocol() const;
58  virtual void setProtocol(const QString &);
59  virtual QET::QetCollection collection () const;
60  virtual void setCollection (QET::QetCollection);
61  virtual QETProject *parentProject();
62  virtual QList<TitleBlockTemplateLocation> templatesLocations();
63 
64  signals:
65  void changed(TitleBlockTemplatesCollection *, const QString & = QString());
66  void aboutToRemove(TitleBlockTemplatesCollection *, const QString &);
67 
68  // attributes
69  protected:
71  QString title_;
73  QString protocol_;
76  QHash<QString, TitleBlockTemplate *> titleblock_templates_;
77 };
78 
84  Q_OBJECT
85 
86  // Constructors, destructor
87  public:
88  TitleBlockTemplatesProjectCollection(QETProject *, QObject *parent = nullptr);
90  private:
92 
93  // methods
94  public:
95  QString title() const override;
96  QString protocol() const override;
97  QETProject *parentProject() override;
98  QStringList templates() override;
99  TitleBlockTemplate *getTemplate(const QString &) override;
100  QDomElement getTemplateXmlDescription(const QString &) override;
101  bool setTemplateXmlDescription(const QString &, const QDomElement &) override;
102  void removeTemplate(const QString &) override;
103  TitleBlockTemplateLocation location(const QString & = QString()) override;
104  bool hasFilePath() override;
105  QString filePath() override;
106  bool isReadOnly(const QString & = QString()) const override;
107  virtual void fromXml(const QDomElement &);
108  virtual void deleteUnusedTitleBlocKTemplates();
109 
110  // attributes
111  private:
115  QDomDocument xml_document_;
117  QHash<QString, QDomElement> titleblock_templates_xml_;
118 };
119 
125  Q_OBJECT
126 
127  // Constructors, destructor
128  public:
129  TitleBlockTemplatesFilesCollection(const QString &, QObject * = nullptr);
131  private:
133 
134  // methods
135  public:
136  QString path(const QString & = QString()) const;
137  QStringList templates() override;
138  TitleBlockTemplate *getTemplate(const QString &) override;
139  QDomElement getTemplateXmlDescription(const QString &) override;
140  bool setTemplateXmlDescription(const QString &, const QDomElement &) override;
141  void removeTemplate(const QString &) override;
142  TitleBlockTemplateLocation location(const QString & = QString()) override;
143  bool hasFilePath() override;
144  QString filePath() override;
145  bool isReadOnly(const QString & = QString()) const override;
146 
147  static QString toTemplateName(const QString &);
148  static QString toFileName(const QString &);
149 
150  private slots:
151  void fileSystemChanged(const QString &str);
152 
153  // attributes
154  private:
156  QFileSystemWatcher watcher_;
158  QDir dir_;
159 };
160 #endif
TitleBlockTemplatesProjectCollection::templates
QStringList templates() override
Definition: templatescollection.cpp:182
TitleBlockTemplatesProjectCollection::TitleBlockTemplatesProjectCollection
TitleBlockTemplatesProjectCollection(QETProject *, QObject *parent=nullptr)
Definition: templatescollection.cpp:113
TitleBlockTemplatesCollection::hasFilePath
virtual bool hasFilePath()=0
TitleBlockTemplatesProjectCollection::getTemplateXmlDescription
QDomElement getTemplateXmlDescription(const QString &) override
Definition: templatescollection.cpp:217
TitleBlockTemplatesCollection::filePath
virtual QString filePath()=0
TitleBlockTemplatesFilesCollection::watcher_
QFileSystemWatcher watcher_
File System Watcher object to track the files changes made outside the application.
Definition: templatescollection.h:156
TitleBlockTemplatesProjectCollection::setTemplateXmlDescription
bool setTemplateXmlDescription(const QString &, const QDomElement &) override
Definition: templatescollection.cpp:235
TitleBlockTemplatesCollection::collection
virtual QET::QetCollection collection() const
TitleBlockTemplatesCollection::collection.
Definition: templatescollection.cpp:74
TitleBlockTemplatesProjectCollection::~TitleBlockTemplatesProjectCollection
~TitleBlockTemplatesProjectCollection() override
Definition: templatescollection.cpp:123
TitleBlockTemplatesFilesCollection::TitleBlockTemplatesFilesCollection
TitleBlockTemplatesFilesCollection(const TitleBlockTemplatesFilesCollection &)
TitleBlockTemplatesFilesCollection::toFileName
static QString toFileName(const QString &)
Definition: templatescollection.cpp:535
TitleBlockTemplatesCollection::~TitleBlockTemplatesCollection
~TitleBlockTemplatesCollection() override
Definition: templatescollection.cpp:36
TitleBlockTemplatesProjectCollection::deleteUnusedTitleBlocKTemplates
virtual void deleteUnusedTitleBlocKTemplates()
Definition: templatescollection.cpp:341
TitleBlockTemplatesCollection::protocol
virtual QString protocol() const
Definition: templatescollection.cpp:58
TitleBlockTemplatesCollection::changed
void changed(TitleBlockTemplatesCollection *, const QString &=QString())
QET::QetCollection
QetCollection
Enum used to specify the origin of a collection of thing (title block, element etc....
Definition: qet.h:152
TitleBlockTemplatesCollection::TitleBlockTemplatesCollection
TitleBlockTemplatesCollection(QObject *parent)
Definition: templatescollection.cpp:27
TitleBlockTemplatesFilesCollection::location
TitleBlockTemplateLocation location(const QString &=QString()) override
Definition: templatescollection.cpp:487
TitleBlockTemplatesFilesCollection::dir_
QDir dir_
Collection real directory.
Definition: templatescollection.h:158
TitleBlockTemplatesCollection::m_collection
QET::QetCollection m_collection
Definition: templatescollection.h:74
TitleBlockTemplatesProjectCollection::getTemplate
TitleBlockTemplate * getTemplate(const QString &) override
Definition: templatescollection.cpp:191
TitleBlockTemplatesCollection::aboutToRemove
void aboutToRemove(TitleBlockTemplatesCollection *, const QString &)
TitleBlockTemplatesFilesCollection::~TitleBlockTemplatesFilesCollection
~TitleBlockTemplatesFilesCollection() override
Definition: templatescollection.cpp:374
TitleBlockTemplatesCollection::getTemplate
virtual TitleBlockTemplate * getTemplate(const QString &)=0
TitleBlockTemplatesProjectCollection::location
TitleBlockTemplateLocation location(const QString &=QString()) override
Definition: templatescollection.cpp:287
TitleBlockTemplatesProjectCollection::hasFilePath
bool hasFilePath() override
Definition: templatescollection.cpp:295
TitleBlockTemplatesFilesCollection::fileSystemChanged
void fileSystemChanged(const QString &str)
Definition: templatescollection.cpp:543
QET::findInDomElement
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
Definition: qet.cpp:333
TitleBlockTemplatesFilesCollection::removeTemplate
void removeTemplate(const QString &) override
Definition: templatescollection.cpp:470
TitleBlockTemplatesProjectCollection::titleblock_templates_xml_
QHash< QString, QDomElement > titleblock_templates_xml_
XML descriptions of embedded titleblock templates.
Definition: templatescollection.h:117
TitleBlockTemplatesProjectCollection::TitleBlockTemplatesProjectCollection
TitleBlockTemplatesProjectCollection(const TitleBlockTemplatesProjectCollection &)
qetapp.h
QET::TitleBlockTemplate
@ TitleBlockTemplate
Definition: qet.h:105
TitleBlockTemplatesFilesCollection::toTemplateName
static QString toTemplateName(const QString &)
Definition: templatescollection.cpp:525
TitleBlockTemplate
The TitleBlockTemplate class This class represents an title block template for an electric diagram....
Definition: titleblocktemplate.h:36
TitleBlockTemplatesFilesCollection
Definition: templatescollection.h:124
TitleBlockTemplatesProjectCollection::parentProject
QETProject * parentProject() override
Definition: templatescollection.cpp:175
TitleBlockTemplatesProjectCollection::removeTemplate
void removeTemplate(const QString &) override
Definition: templatescollection.cpp:272
qet.h
TitleBlockTemplatesCollection::parentProject
virtual QETProject * parentProject()
Definition: templatescollection.cpp:91
TitleBlockTemplatesFilesCollection::TitleBlockTemplatesFilesCollection
TitleBlockTemplatesFilesCollection(const QString &, QObject *=nullptr)
Definition: templatescollection.cpp:356
TitleBlockTemplatesCollection::TitleBlockTemplatesCollection
TitleBlockTemplatesCollection(const TitleBlockTemplatesCollection &)
TitleBlockTemplateLocation
Definition: templatelocation.h:29
TitleBlockTemplatesCollection::protocol_
QString protocol_
Protocol used to designate this collection.
Definition: templatescollection.h:73
templatescollection.h
TitleBlockTemplatesFilesCollection::setTemplateXmlDescription
bool setTemplateXmlDescription(const QString &, const QDomElement &) override
Definition: templatescollection.cpp:449
QETApp::projectId
static int projectId(const QETProject *)
QETApp::projectId.
Definition: qetapp.cpp:2433
QET::writeXmlFile
bool writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString *error_message=nullptr)
Definition: qet.cpp:584
TitleBlockTemplatesCollection::title
virtual QString title() const
Definition: templatescollection.cpp:42
qetproject.h
TitleBlockTemplatesCollection::templates
virtual QStringList templates()=0
TitleBlockTemplatesCollection::removeTemplate
virtual void removeTemplate(const QString &)=0
TitleBlockTemplatesProjectCollection::fromXml
virtual void fromXml(const QDomElement &)
Definition: templatescollection.cpp:323
TitleBlockTemplatesCollection::title_
QString title_
Human-readable title for this collection.
Definition: templatescollection.h:71
QETProject
Definition: qetproject.h:51
TitleBlockTemplatesCollection::templatesLocations
virtual QList< TitleBlockTemplateLocation > templatesLocations()
Definition: templatescollection.cpp:100
TitleBlockTemplatesCollection::setTitle
virtual void setTitle(const QString &)
TitleBlockTemplatesCollection::setTitle.
Definition: templatescollection.cpp:50
TitleBlockTemplatesFilesCollection::path
QString path(const QString &=QString()) const
Definition: templatescollection.cpp:380
TitleBlockTemplatesCollection::setProtocol
virtual void setProtocol(const QString &)
Definition: templatescollection.cpp:66
TitleBlockTemplatesProjectCollection::filePath
QString filePath() override
Definition: templatescollection.cpp:303
TitleBlockTemplatesCollection::getTemplateXmlDescription
virtual QDomElement getTemplateXmlDescription(const QString &)=0
TitleBlockTemplatesProjectCollection::title
QString title() const override
Definition: templatescollection.cpp:129
QET::Embedded
@ Embedded
From an embedded collection (a project for exemple)
Definition: qet.h:155
TitleBlockTemplatesFilesCollection::isReadOnly
bool isReadOnly(const QString &=QString()) const override
Definition: templatescollection.cpp:511
TitleBlockTemplatesCollection::setCollection
virtual void setCollection(QET::QetCollection)
TitleBlockTemplatesCollection::setCollection Set the storage of this collection.
Definition: templatescollection.cpp:83
TitleBlockTemplatesProjectCollection::isReadOnly
bool isReadOnly(const QString &=QString()) const override
Definition: templatescollection.cpp:312
TitleBlockTemplatesCollection
Definition: templatescollection.h:34
TitleBlockTemplatesCollection::setTemplateXmlDescription
virtual bool setTemplateXmlDescription(const QString &, const QDomElement &)=0
TitleBlockTemplatesFilesCollection::getTemplateXmlDescription
QDomElement getTemplateXmlDescription(const QString &) override
Definition: templatescollection.cpp:422
TitleBlockTemplatesProjectCollection::protocol
QString protocol() const override
Definition: templatescollection.cpp:161
templatelocation.h
TITLEBLOCKS_FILE_EXTENSION
#define TITLEBLOCKS_FILE_EXTENSION
Definition: templatescollection.h:20
TitleBlockTemplatesProjectCollection::xml_document_
QDomDocument xml_document_
Parent QDomDocument for stored QDomElements.
Definition: templatescollection.h:115
TitleBlockTemplatesFilesCollection::filePath
QString filePath() override
Definition: templatescollection.cpp:502
titleblocktemplate.h
TitleBlockTemplatesFilesCollection::getTemplate
TitleBlockTemplate * getTemplate(const QString &) override
Definition: templatescollection.cpp:404
TitleBlockTemplatesFilesCollection::hasFilePath
bool hasFilePath() override
Definition: templatescollection.cpp:495
TitleBlockTemplatesCollection::isReadOnly
virtual bool isReadOnly(const QString &=QString()) const =0
TitleBlockTemplatesProjectCollection::project_
QETProject * project_
Parent project.
Definition: templatescollection.h:113
TitleBlockTemplatesProjectCollection
Definition: templatescollection.h:83
QET::Icons::tr
QIcon tr
Definition: qeticons.cpp:206
TitleBlockTemplatesFilesCollection::templates
QStringList templates() override
Definition: templatescollection.cpp:391
TitleBlockTemplatesCollection::titleblock_templates_
QHash< QString, TitleBlockTemplate * > titleblock_templates_
Already parsed embedded titleblock templates.
Definition: templatescollection.h:76
TitleBlockTemplatesCollection::location
virtual TitleBlockTemplateLocation location(const QString &=QString())=0