100 QList<TitleBlockTemplateLocation> locations;
101 foreach (QString template_name,
templates()) {
102 locations <<
location(template_name);
136 if (project_title.isEmpty()) {
137 final_title = QString(
139 "Cartouches du projet sans titre (id %1)",
140 "collection title when the parent project has an empty title -- %1 is the project internal id" 145 final_title = QString(
147 "Cartouches du projet \"%1\"",
148 "collection title when the project has a suitable title -- %1 is the project title" 151 final_title = final_title.arg(project_title);
163 if (project_id != -1) {
164 return(QString(
"project%1+embedtbt").arg(project_id));
205 return(titleblock_template);
220 return(QDomElement());
236 if (xml_elmt.tagName() !=
"titleblocktemplate") {
244 QDomElement
import =
xml_document_.importNode(xml_elmt,
true).toElement();
247 import.setAttribute(
"name", template_name);
252 if (!old_description.parentNode().isNull()) {
253 old_description.parentNode().replaceChild(
import, old_description);
261 emit(
changed(
this, template_name));
279 emit(
changed(
this, template_name));
312 Q_UNUSED(template_name)
323 foreach (QDomElement e,
QET::findInDomElement(xml_element,
"titleblocktemplates",
"titleblocktemplate")) {
325 if (!e.hasAttribute(
"name"))
continue;
326 QString titleblock_template_name = e.attribute(
"name");
343 foreach (QString template_name,
templates()) {
360 QDir::SortFlags(QDir::Name | QDir::IgnoreCase),
361 QDir::Readable | QDir::Files
380 if (template_name.isEmpty()) {
381 return(
dir_.canonicalPath());
391 QStringList templates_names;
393 foreach(QString name,
dir_.entryList()) {
394 templates_names << name.replace(replace_regexp,
"");
396 return(templates_names);
404 if (!
templates().contains(template_name))
return(
nullptr);
407 QString tbt_file_path =
path(template_name);
409 bool loading = tbtemplate -> loadFromXmlFile(tbt_file_path);
422 QString xml_file_path =
path(template_name);
424 QFileInfo xml_file_info(xml_file_path);
425 if (!xml_file_info.exists() || !xml_file_info.isReadable()) {
426 return(QDomElement());
429 QFile xml_file(xml_file_path);
430 if (!xml_file.open(QIODevice::ReadOnly)) {
431 return(QDomElement());
434 QDomDocument *xml_document =
new QDomDocument();
435 bool xml_parsing = xml_document -> setContent(&xml_file);
438 return(QDomElement());
440 return(xml_document -> documentElement());
449 if (template_name.isEmpty())
return(
false);
455 doc.appendChild(doc.importNode(xml_element,
true));
458 if (!writing)
return(
false);
462 emit(
changed(
this, template_name));
478 emit(
changed(
this, template_name));
502 return(
dir_.canonicalPath());
511 if (template_name.isEmpty()) {
512 QFileInfo info(
dir_.canonicalPath());
513 return(!info.isWritable());
516 return(!info.isWritable());
526 QString template_name(file_name);
527 return(template_name.replace(replace_regexp,
""));
QString title() const override
~TitleBlockTemplatesFilesCollection() override
virtual void setProtocol(const QString &)
virtual QETProject * parentProject()
QHash< QString, TitleBlockTemplate * > titleblock_templates_
Already parsed embedded titleblock templates.
QStringList templates() override
void changed(TitleBlockTemplatesCollection *, const QString &=QString())
From an embedded collection (a project for exemple)
QString protocol_
Protocol used to designate this collection.
TitleBlockTemplatesFilesCollection(const QString &, QObject *=nullptr)
void removeTemplate(const QString &) override
void fileSystemChanged(const QString &str)
QFileSystemWatcher watcher_
File System Watcher object to track the files changes made outside the application.
static QString toFileName(const QString &)
virtual QString protocol() const
QETProject * project_
Parent project.
virtual QStringList templates()=0
TitleBlockTemplateLocation location(const QString &=QString()) override
QDomDocument xml_document_
Parent QDomDocument for stored QDomElements.
QETProject * parentProject() override
void removeTemplate(const QString &) override
QetCollection
Enum used to specify the origin of a collection of thing (title block, element etc...)
static int projectId(const QETProject *)
bool hasFilePath() override
void aboutToRemove(TitleBlockTemplatesCollection *, const QString &)
TitleBlockTemplateLocation location(const QString &=QString()) override
TitleBlockTemplatesCollection(QObject *parent)
static QString toTemplateName(const QString &)
QString filePath() override
virtual void setCollection(QET::QetCollection)
TitleBlockTemplatesCollection::setCollection Set the storage of this collection.
QDomElement getTemplateXmlDescription(const QString &) override
~TitleBlockTemplatesCollection() override
virtual QET::QetCollection collection() const
TitleBlockTemplatesCollection::collection.
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
virtual void setTitle(const QString &)
bool writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString *error_message=nullptr)
virtual TitleBlockTemplateLocation location(const QString &=QString())=0
TitleBlockTemplate * getTemplate(const QString &) override
QString title_
Human-readable title for this collection.
QString protocol() const override
QString filePath() override
QHash< QString, QDomElement > titleblock_templates_xml_
XML descriptions of embedded titleblock templates.
TitleBlockTemplate * getTemplate(const QString &) override
#define TITLEBLOCKS_FILE_EXTENSION
~TitleBlockTemplatesProjectCollection() override
virtual void deleteUnusedTitleBlocKTemplates()
bool setTemplateXmlDescription(const QString &, const QDomElement &) override
QString path(const QString &=QString()) const
QDir dir_
Collection real directory.
virtual QList< TitleBlockTemplateLocation > templatesLocations()
QDomElement getTemplateXmlDescription(const QString &) override
bool isReadOnly(const QString &=QString()) const override
QET::QetCollection m_collection
bool isReadOnly(const QString &=QString()) const override
bool setTemplateXmlDescription(const QString &, const QDomElement &) override
bool hasFilePath() override
virtual QString title() const
QStringList templates() override
TitleBlockTemplatesProjectCollection(QETProject *, QObject *parent=nullptr)
virtual void fromXml(const QDomElement &)