mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-19 01:59:59 +01:00
Fix deprecated QRegExp
Use QRegularExpression instead. https://doc.qt.io/qt-5/qregularexpression.html#notes-for-qregexp-users This function was introduced in Qt 5
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2006-2020 The QElectroTech Team
|
Copyright 2006-2020 The QElectroTech Team
|
||||||
This file is part of QElectroTech.
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
QElectroTech is free software: you can redistribute it and/or modify
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
QElectroTech is distributed in the hope that it will be useful,
|
QElectroTech is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
@@ -20,6 +20,8 @@
|
|||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
#include "qetproject.h"
|
#include "qetproject.h"
|
||||||
|
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructor
|
Constructor
|
||||||
@param parent Parent QObject
|
@param parent Parent QObject
|
||||||
@@ -136,7 +138,7 @@ TitleBlockTemplatesProjectCollection::~TitleBlockTemplatesProjectCollection()
|
|||||||
QString TitleBlockTemplatesProjectCollection::title() const
|
QString TitleBlockTemplatesProjectCollection::title() const
|
||||||
{
|
{
|
||||||
if (!title_.isEmpty()) return(title_);
|
if (!title_.isEmpty()) return(title_);
|
||||||
|
|
||||||
// if the title attribute is empty, we generate a suitable one using the
|
// if the title attribute is empty, we generate a suitable one using the
|
||||||
// parent project
|
// parent project
|
||||||
QString final_title;
|
QString final_title;
|
||||||
@@ -204,12 +206,12 @@ TitleBlockTemplate *TitleBlockTemplatesProjectCollection::getTemplate(const QStr
|
|||||||
if (titleblock_templates_.contains(template_name)) {
|
if (titleblock_templates_.contains(template_name)) {
|
||||||
return(titleblock_templates_[template_name]);
|
return(titleblock_templates_[template_name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No? Do we even know of it?
|
// No? Do we even know of it?
|
||||||
if (!titleblock_templates_xml_.contains(template_name)) {
|
if (!titleblock_templates_xml_.contains(template_name)) {
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ok, we have its XML description, we have to generate a TitleBlockTemplate object
|
// Ok, we have its XML description, we have to generate a TitleBlockTemplate object
|
||||||
TitleBlockTemplate *titleblock_template = new TitleBlockTemplate(this);
|
TitleBlockTemplate *titleblock_template = new TitleBlockTemplate(this);
|
||||||
if (titleblock_template -> loadFromXmlElement(titleblock_templates_xml_[template_name])) {
|
if (titleblock_template -> loadFromXmlElement(titleblock_templates_xml_[template_name])) {
|
||||||
@@ -248,16 +250,16 @@ bool TitleBlockTemplatesProjectCollection::setTemplateXmlDescription(const QStri
|
|||||||
if (xml_elmt.tagName() != "titleblocktemplate") {
|
if (xml_elmt.tagName() != "titleblocktemplate") {
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we *require* a project (at least for the moment...)
|
// we *require* a project (at least for the moment...)
|
||||||
if (!project_) return(false);
|
if (!project_) return(false);
|
||||||
|
|
||||||
// we import the provided XML element in the project document
|
// we import the provided XML element in the project document
|
||||||
QDomElement import = xml_document_.importNode(xml_elmt, true).toElement();
|
QDomElement import = xml_document_.importNode(xml_elmt, true).toElement();
|
||||||
|
|
||||||
// ensure the name stored in the XML description remains consistent with the provided template name
|
// ensure the name stored in the XML description remains consistent with the provided template name
|
||||||
import.setAttribute("name", template_name);
|
import.setAttribute("name", template_name);
|
||||||
|
|
||||||
// we either replace the previous description
|
// we either replace the previous description
|
||||||
if (titleblock_templates_xml_.contains(template_name)) {
|
if (titleblock_templates_xml_.contains(template_name)) {
|
||||||
QDomElement old_description = titleblock_templates_xml_[template_name];
|
QDomElement old_description = titleblock_templates_xml_[template_name];
|
||||||
@@ -266,12 +268,12 @@ bool TitleBlockTemplatesProjectCollection::setTemplateXmlDescription(const QStri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
titleblock_templates_xml_.insert(template_name, import);
|
titleblock_templates_xml_.insert(template_name, import);
|
||||||
|
|
||||||
if (titleblock_templates_.contains(template_name)) {
|
if (titleblock_templates_.contains(template_name)) {
|
||||||
titleblock_templates_[template_name] -> loadFromXmlElement(titleblock_templates_xml_[template_name]);
|
titleblock_templates_[template_name] -> loadFromXmlElement(titleblock_templates_xml_[template_name]);
|
||||||
}
|
}
|
||||||
emit(changed(this, template_name));
|
emit(changed(this, template_name));
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,11 +284,11 @@ bool TitleBlockTemplatesProjectCollection::setTemplateXmlDescription(const QStri
|
|||||||
*/
|
*/
|
||||||
void TitleBlockTemplatesProjectCollection::removeTemplate(const QString &template_name) {
|
void TitleBlockTemplatesProjectCollection::removeTemplate(const QString &template_name) {
|
||||||
emit(aboutToRemove(this, template_name));
|
emit(aboutToRemove(this, template_name));
|
||||||
|
|
||||||
// remove the template itself
|
// remove the template itself
|
||||||
titleblock_templates_xml_.remove(template_name);
|
titleblock_templates_xml_.remove(template_name);
|
||||||
titleblock_templates_.remove(template_name);
|
titleblock_templates_.remove(template_name);
|
||||||
|
|
||||||
// warn the rest of the world that the list of templates embedded within this project has changed
|
// warn the rest of the world that the list of templates embedded within this project has changed
|
||||||
emit(changed(this, template_name));
|
emit(changed(this, template_name));
|
||||||
}
|
}
|
||||||
@@ -339,10 +341,10 @@ void TitleBlockTemplatesProjectCollection::fromXml(const QDomElement &xml_elemen
|
|||||||
// each titleblock template must have a name
|
// each titleblock template must have a name
|
||||||
if (!e.hasAttribute("name")) continue;
|
if (!e.hasAttribute("name")) continue;
|
||||||
QString titleblock_template_name = e.attribute("name");
|
QString titleblock_template_name = e.attribute("name");
|
||||||
|
|
||||||
// if several templates have the same name, we keep the first one encountered
|
// if several templates have the same name, we keep the first one encountered
|
||||||
if (titleblock_templates_xml_.contains(titleblock_template_name)) continue;
|
if (titleblock_templates_xml_.contains(titleblock_template_name)) continue;
|
||||||
|
|
||||||
// we simply store the XML element describing the titleblock template,
|
// we simply store the XML element describing the titleblock template,
|
||||||
// without any further analysis for the moment
|
// without any further analysis for the moment
|
||||||
titleblock_templates_xml_.insert(titleblock_template_name, e);
|
titleblock_templates_xml_.insert(titleblock_template_name, e);
|
||||||
@@ -355,7 +357,7 @@ void TitleBlockTemplatesProjectCollection::fromXml(const QDomElement &xml_elemen
|
|||||||
void TitleBlockTemplatesProjectCollection::deleteUnusedTitleBlocKTemplates()
|
void TitleBlockTemplatesProjectCollection::deleteUnusedTitleBlocKTemplates()
|
||||||
{
|
{
|
||||||
if (!project_) return;
|
if (!project_) return;
|
||||||
|
|
||||||
foreach (QString template_name, templates()) {
|
foreach (QString template_name, templates()) {
|
||||||
if (!project_ -> usesTitleBlockTemplate(location(template_name))) {
|
if (!project_ -> usesTitleBlockTemplate(location(template_name))) {
|
||||||
removeTemplate(template_name);
|
removeTemplate(template_name);
|
||||||
@@ -408,7 +410,7 @@ QString TitleBlockTemplatesFilesCollection::path(const QString &template_name) c
|
|||||||
QStringList TitleBlockTemplatesFilesCollection::templates()
|
QStringList TitleBlockTemplatesFilesCollection::templates()
|
||||||
{
|
{
|
||||||
QStringList templates_names;
|
QStringList templates_names;
|
||||||
QRegExp replace_regexp(QString("%1$").arg(TITLEBLOCKS_FILE_EXTENSION));
|
QRegularExpression replace_regexp(QString("%1$").arg(TITLEBLOCKS_FILE_EXTENSION));
|
||||||
foreach(QString name, dir_.entryList()) {
|
foreach(QString name, dir_.entryList()) {
|
||||||
templates_names << name.replace(replace_regexp, "");
|
templates_names << name.replace(replace_regexp, "");
|
||||||
}
|
}
|
||||||
@@ -421,10 +423,10 @@ QStringList TitleBlockTemplatesFilesCollection::templates()
|
|||||||
*/
|
*/
|
||||||
TitleBlockTemplate *TitleBlockTemplatesFilesCollection::getTemplate(const QString &template_name) {
|
TitleBlockTemplate *TitleBlockTemplatesFilesCollection::getTemplate(const QString &template_name) {
|
||||||
if (!templates().contains(template_name)) return(nullptr);
|
if (!templates().contains(template_name)) return(nullptr);
|
||||||
|
|
||||||
TitleBlockTemplate *tbtemplate = new TitleBlockTemplate();
|
TitleBlockTemplate *tbtemplate = new TitleBlockTemplate();
|
||||||
QString tbt_file_path = path(template_name);
|
QString tbt_file_path = path(template_name);
|
||||||
|
|
||||||
bool loading = tbtemplate -> loadFromXmlFile(tbt_file_path);
|
bool loading = tbtemplate -> loadFromXmlFile(tbt_file_path);
|
||||||
if (!loading) {
|
if (!loading) {
|
||||||
delete tbtemplate;
|
delete tbtemplate;
|
||||||
@@ -439,17 +441,17 @@ TitleBlockTemplate *TitleBlockTemplatesFilesCollection::getTemplate(const QStrin
|
|||||||
*/
|
*/
|
||||||
QDomElement TitleBlockTemplatesFilesCollection::getTemplateXmlDescription(const QString &template_name) {
|
QDomElement TitleBlockTemplatesFilesCollection::getTemplateXmlDescription(const QString &template_name) {
|
||||||
QString xml_file_path = path(template_name);
|
QString xml_file_path = path(template_name);
|
||||||
|
|
||||||
QFileInfo xml_file_info(xml_file_path);
|
QFileInfo xml_file_info(xml_file_path);
|
||||||
if (!xml_file_info.exists() || !xml_file_info.isReadable()) {
|
if (!xml_file_info.exists() || !xml_file_info.isReadable()) {
|
||||||
return(QDomElement());
|
return(QDomElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile xml_file(xml_file_path);
|
QFile xml_file(xml_file_path);
|
||||||
if (!xml_file.open(QIODevice::ReadOnly)) {
|
if (!xml_file.open(QIODevice::ReadOnly)) {
|
||||||
return(QDomElement());
|
return(QDomElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
QDomDocument *xml_document = new QDomDocument();
|
QDomDocument *xml_document = new QDomDocument();
|
||||||
bool xml_parsing = xml_document -> setContent(&xml_file);
|
bool xml_parsing = xml_document -> setContent(&xml_file);
|
||||||
if (!xml_parsing) {
|
if (!xml_parsing) {
|
||||||
@@ -466,16 +468,16 @@ QDomElement TitleBlockTemplatesFilesCollection::getTemplateXmlDescription(const
|
|||||||
*/
|
*/
|
||||||
bool TitleBlockTemplatesFilesCollection::setTemplateXmlDescription(const QString &template_name, const QDomElement &xml_element) {
|
bool TitleBlockTemplatesFilesCollection::setTemplateXmlDescription(const QString &template_name, const QDomElement &xml_element) {
|
||||||
if (template_name.isEmpty()) return(false);
|
if (template_name.isEmpty()) return(false);
|
||||||
|
|
||||||
// prevent the watcher from emitting signals while we open and write to file
|
// prevent the watcher from emitting signals while we open and write to file
|
||||||
blockSignals(true);
|
blockSignals(true);
|
||||||
|
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
doc.appendChild(doc.importNode(xml_element, true));
|
doc.appendChild(doc.importNode(xml_element, true));
|
||||||
|
|
||||||
bool writing = QET::writeXmlFile(doc, path(template_name));
|
bool writing = QET::writeXmlFile(doc, path(template_name));
|
||||||
if (!writing) return(false);
|
if (!writing) return(false);
|
||||||
|
|
||||||
// emit a single signal for the change
|
// emit a single signal for the change
|
||||||
blockSignals(false);
|
blockSignals(false);
|
||||||
emit(changed(this, template_name));
|
emit(changed(this, template_name));
|
||||||
@@ -489,9 +491,9 @@ void TitleBlockTemplatesFilesCollection::removeTemplate(const QString &template_
|
|||||||
emit(aboutToRemove(this, template_name));
|
emit(aboutToRemove(this, template_name));
|
||||||
// prevent the watcher from emitting signals while we open and write to file
|
// prevent the watcher from emitting signals while we open and write to file
|
||||||
blockSignals(true);
|
blockSignals(true);
|
||||||
|
|
||||||
dir_.remove(toFileName(template_name));
|
dir_.remove(toFileName(template_name));
|
||||||
|
|
||||||
// emit a single signal for the removal
|
// emit a single signal for the removal
|
||||||
blockSignals(false);
|
blockSignals(false);
|
||||||
emit(changed(this, template_name));
|
emit(changed(this, template_name));
|
||||||
@@ -500,7 +502,7 @@ void TitleBlockTemplatesFilesCollection::removeTemplate(const QString &template_
|
|||||||
/**
|
/**
|
||||||
@param template_name Name of a template supposed to be contained within
|
@param template_name Name of a template supposed to be contained within
|
||||||
this collection.
|
this collection.
|
||||||
@return
|
@return
|
||||||
*/
|
*/
|
||||||
TitleBlockTemplateLocation TitleBlockTemplatesFilesCollection::location(const QString &template_name) {
|
TitleBlockTemplateLocation TitleBlockTemplatesFilesCollection::location(const QString &template_name) {
|
||||||
return(TitleBlockTemplateLocation(template_name, this));
|
return(TitleBlockTemplateLocation(template_name, this));
|
||||||
@@ -544,7 +546,7 @@ bool TitleBlockTemplatesFilesCollection::isReadOnly(const QString &template_name
|
|||||||
@return the template name for \a file_name
|
@return the template name for \a file_name
|
||||||
*/
|
*/
|
||||||
QString TitleBlockTemplatesFilesCollection::toTemplateName(const QString &file_name) {
|
QString TitleBlockTemplatesFilesCollection::toTemplateName(const QString &file_name) {
|
||||||
static QRegExp replace_regexp(QString("%1$").arg(TITLEBLOCKS_FILE_EXTENSION));
|
static QRegularExpression replace_regexp(QString("%1$").arg(TITLEBLOCKS_FILE_EXTENSION));
|
||||||
QString template_name(file_name);
|
QString template_name(file_name);
|
||||||
return(template_name.replace(replace_regexp, ""));
|
return(template_name.replace(replace_regexp, ""));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user