Fix indentation code

This commit is contained in:
Laurent Trinques 2020-07-15 23:00:21 +02:00
parent b9ce532db7
commit 68116f4664
6 changed files with 803 additions and 803 deletions

View File

@ -26,8 +26,8 @@
/******************************************************/
ECHStrategy::ECHStrategy(ElementsLocation &source, ElementsLocation &destination) :
m_source(source),
m_destination (destination)
m_source(source),
m_destination (destination)
{}
ECHStrategy::~ECHStrategy() {}
@ -35,12 +35,12 @@ ECHStrategy::~ECHStrategy() {}
/******************************************************/
ECHSFileToFile::ECHSFileToFile(ElementsLocation &source, ElementsLocation &destination) :
ECHStrategy(source, destination)
ECHStrategy(source, destination)
{}
ElementsLocation ECHSFileToFile::copy()
{
//Check if the destination already have an item with the same name of the item to copy
//Check if the destination already have an item with the same name of the item to copy
ElementsLocation location(m_destination.fileSystemPath() + "/" + m_source.fileName());
QString rename;
if (location.exist())
@ -69,32 +69,32 @@ ElementsLocation ECHSFileToFile::copy()
else
return ElementsLocation();
}
if (m_source.isElement())
return copyElement(m_source, m_destination, rename);
else
else
return copyDirectory(m_source, m_destination, rename);
}
ElementsLocation ECHSFileToFile::copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString& rename)
{
QDir source_dir(source.fileSystemPath());
QDir destination_dir(destination.fileSystemPath());
QDir source_dir(source.fileSystemPath());
QDir destination_dir(destination.fileSystemPath());
if (!source_dir.exists() || !destination_dir.exists()) return ElementsLocation();
QString new_dir_name = rename.isEmpty() ? source_dir.dirName() : rename;
//Create a new dir
if (destination_dir.mkdir(new_dir_name))
{
//The new created directory
QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name);
//Copy the qet_directory file
QFile::copy(source_dir.canonicalPath() + "/qet_directory", created_dir.canonicalPath() + "/qet_directory");
//Copy all dirs found in source_dir to destination_dir
QString new_dir_name = rename.isEmpty() ? source_dir.dirName() : rename;
//Create a new dir
if (destination_dir.mkdir(new_dir_name))
{
//The new created directory
QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name);
//Copy the qet_directory file
QFile::copy(source_dir.canonicalPath() + "/qet_directory", created_dir.canonicalPath() + "/qet_directory");
//Copy all dirs found in source_dir to destination_dir
ElementsLocation created_location(created_dir.canonicalPath());
//Used this bool when user drop a folder into itself to avoid infinite recursive creation of the dropped dir
bool copy_itself = false;
@ -116,30 +116,30 @@ ElementsLocation ECHSFileToFile::copyDirectory(ElementsLocation &source, Element
copyDirectory(sub_source, created_location);
}
//Copy all elements found in source_dir to destination_dir
source_dir.setNameFilters(QStringList() << "*.elmt");
foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
{
//Copy all elements found in source_dir to destination_dir
source_dir.setNameFilters(QStringList() << "*.elmt");
foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name))
{
ElementsLocation sub_source(source.fileSystemPath() + "/" + str);
copyElement(sub_source, created_location);
}
return created_location;
}
copyElement(sub_source, created_location);
}
return created_location;
}
return ElementsLocation();
}
ElementsLocation ECHSFileToFile::copyElement(ElementsLocation &source, ElementsLocation &destination, const QString& rename)
{
QString new_elmt_name = rename.isEmpty() ? source.fileName() : rename;
bool rb = QFile::copy(source.fileSystemPath(), destination.fileSystemPath() + "/" + new_elmt_name);
if (rb)
QString new_elmt_name = rename.isEmpty() ? source.fileName() : rename;
bool rb = QFile::copy(source.fileSystemPath(), destination.fileSystemPath() + "/" + new_elmt_name);
if (rb)
{
#ifdef Q_OS_WIN
//On windows when user drag and drop an element from the common elements collection
//to the custom elements collection, the element file stay in read only mode, and so
//user can't save the element
//On windows when user drag and drop an element from the common elements collection
//to the custom elements collection, the element file stay in read only mode, and so
//user can't save the element
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
qt_ntfs_permission_lookup++;
QFile file(destination.fileSystemPath() + "/" + new_elmt_name);
@ -153,7 +153,7 @@ ElementsLocation ECHSFileToFile::copyElement(ElementsLocation &source, ElementsL
#endif
return ElementsLocation (destination.fileSystemPath() + "/" + new_elmt_name);
}
else
else
return ElementsLocation();
}
@ -165,7 +165,7 @@ ECHSXmlToFile::ECHSXmlToFile(ElementsLocation &source, ElementsLocation &destina
ElementsLocation ECHSXmlToFile::copy()
{
//Check if the destination already have an item with the same name of the item to copy
//Check if the destination already have an item with the same name of the item to copy
ElementsLocation location(m_destination.fileSystemPath() + "/" + m_source.fileName());
QString rename;
if (location.exist())
@ -194,7 +194,7 @@ ElementsLocation ECHSXmlToFile::copy()
else
return ElementsLocation();
}
if (m_source.isElement())
return copyElement(m_source, m_destination, rename);
else
@ -204,61 +204,61 @@ ElementsLocation ECHSXmlToFile::copy()
ElementsLocation ECHSXmlToFile::copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString& rename)
{
QDir destination_dir(destination.fileSystemPath());
if (!(destination_dir.exists() && source.exist())) return ElementsLocation();
QString new_dir_name = rename.isEmpty() ? source.fileName() : rename;
//Create new dir
//Create new dir
if (destination_dir.mkdir(new_dir_name))
{
QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name);
ElementsLocation created_location(created_dir.canonicalPath());
//Create the qet-directory file
//Create the qet-directory file
QDomDocument document;
QDomElement root = document.createElement("qet-directory");
document.appendChild(root);
root.appendChild(source.nameList().toXml(document));
QString filepath = created_dir.canonicalPath() + "/qet_directory";
QET::writeXmlFile(document, filepath);
//Create all directory found in source to created_dir
//Create all directory found in source to created_dir
XmlElementCollection *project_collection = source.projectCollection();
QStringList directories_names = project_collection->directoriesNames( project_collection->directory(source.collectionPath(false)) );
foreach(QString name, directories_names)
{
ElementsLocation sub_source_dir(source.projectCollectionPath() + "/" + name);
copyDirectory(sub_source_dir, created_location);
}
//Create all elements found in source to destination
//Create all elements found in source to destination
QStringList elements_names = project_collection->elementsNames( project_collection->directory(source.collectionPath(false))) ;
foreach (QString name, elements_names)
{
ElementsLocation source_element(source.projectCollectionPath() + "/" + name);
copyElement(source_element, created_location);
}
return created_location;
}
return ElementsLocation();
}
ElementsLocation ECHSXmlToFile::copyElement(ElementsLocation &source, ElementsLocation &destination, const QString& rename)
{
if (!(destination.exist() && source.exist())) return ElementsLocation();
QString new_element_name = rename.isEmpty() ? source.fileName() : rename;
//Get the xml descrption of the element
//Get the xml descrption of the element
QDomDocument document;
document.appendChild(document.importNode(source.xml(), true));
//Create the .elmt file
//Create the .elmt file
QString filepath = destination.fileSystemPath() + "/" + new_element_name;
if (QET::writeXmlFile(document, filepath))
return ElementsLocation(filepath);
@ -275,10 +275,10 @@ ECHSToXml::ECHSToXml(ElementsLocation &source, ElementsLocation &destination) :
ElementsLocation ECHSToXml::copy()
{
if (!(m_source.exist() && m_destination.isDirectory() && m_destination.isProject())) return ElementsLocation();
//Check if the destination already have an item with the same name of the item to copy
//Check if the destination already have an item with the same name of the item to copy
ElementsLocation location(m_destination.projectCollectionPath() + "/" + m_source.fileName());
QString rename;
if (location.exist())
{
@ -291,7 +291,7 @@ ElementsLocation ECHSToXml::copy()
else
return ElementsLocation();
}
return m_destination.projectCollection()->copy(m_source, m_destination, rename);
}
@ -305,7 +305,7 @@ ElementCollectionHandler::ElementCollectionHandler() {}
ElementCollectionHandler::~ElementCollectionHandler()
{
if (m_strategy) delete m_strategy;
if (m_strategy) delete m_strategy;
}
/**
@ -320,11 +320,11 @@ ElementCollectionHandler::~ElementCollectionHandler()
ElementsLocation ElementCollectionHandler::copy(ElementsLocation &source, ElementsLocation &destination)
{
if (!source.exist() || !destination.exist() || destination.isElement()) return ElementsLocation();
if (source.isFileSystem() && destination.isFileSystem()) m_strategy = new ECHSFileToFile(source, destination);
if (source.isFileSystem() && destination.isFileSystem()) m_strategy = new ECHSFileToFile(source, destination);
if (source.isProject() && destination.isFileSystem()) m_strategy = new ECHSXmlToFile(source, destination);
else if (destination.isProject()) m_strategy = new ECHSToXml(source, destination);
if (m_strategy)
return m_strategy->copy();
else
@ -342,31 +342,31 @@ ElementsLocation ElementCollectionHandler::copy(ElementsLocation &source, Elemen
*/
ElementsLocation ElementCollectionHandler::createDir(ElementsLocation &parent, const QString &name, const NamesList &name_list)
{
//Parent must be a directorie and writable
//Parent must be a directorie and writable
if (!(parent.isDirectory() && parent.isWritable() && parent.exist())) {
qDebug() << "ElementCollectionHandler::createDir : the prerequisites are not valid. " << parent;
return ElementsLocation();
}
//Directorie to create must not already exist
//Directorie to create must not already exist
ElementsLocation created_dir = parent;
created_dir.addToPath(name);
if (created_dir.exist()) {
return ElementsLocation();
}
//Location is a file system
//Location is a file system
if (parent.isFileSystem()) {
QDir parent_dir(parent.fileSystemPath());
if (parent_dir.mkdir(name)) {
//Create the qet-directory file
//Create the qet-directory file
QDomDocument document;
QDomElement root = document.createElement("qet-directory");
document.appendChild(root);
root.appendChild(name_list.toXml(document));
QString filepath = created_dir.fileSystemPath() + "/qet_directory";
if (!QET::writeXmlFile(document, filepath)) {
qDebug() << "ElementCollectionHandler::createDir : write qet-directory file failed";
@ -388,7 +388,7 @@ ElementsLocation ElementCollectionHandler::createDir(ElementsLocation &parent, c
return ElementsLocation();
}
}
return ElementsLocation();
}
@ -403,35 +403,35 @@ ElementsLocation ElementCollectionHandler::createDir(ElementsLocation &parent, c
bool ElementCollectionHandler::importFromProject(QETProject *project, ElementsLocation &location)
{
if (!(location.isElement() && location.exist() && location.isProject())) return false;
ElementsLocation destination(location.collectionPath(false), project);
if (destination.exist()) return true;
QList <QString> names;
//Get the parent of location and find if exist in embedded collection of project
//Get the parent of location and find if exist in embedded collection of project
ElementsLocation source = location.parent();
names.append(location.fileName());
destination = ElementsLocation(source.collectionPath(), project);
//Go back until to find an existing directory in destination
//Go back until to find an existing directory in destination
while (!destination.exist()) {
names.append(source.fileName());
source = source.parent();
destination = ElementsLocation(source.collectionPath(), project);
}
XmlElementCollection *collection = project->embeddedElementCollection();
while (!names.isEmpty()) {
source.addToPath(names.takeLast());
destination = collection->copy(source, destination, QString(), false);
if (!destination.exist())
return false;
}
return true;
}
@ -447,23 +447,23 @@ bool ElementCollectionHandler::setNames(ElementsLocation &location, const NamesL
if ( !(location.exist() && location.isWritable()) ) {
return false;
}
if (location.isFileSystem()) {
if (location.isDirectory()) {
QDomDocument document;
QDomElement root = document.createElement("qet-directory");
document.appendChild(root);
root.appendChild(name_list.toXml(document));
QString filepath = location.fileSystemPath() + "/qet_directory";
if (!QET::writeXmlFile(document, filepath)) {
qDebug() << "ElementCollectionHandler::setNames : write qet-directory file failed";
return false;
}
return true;
}
if (location.isElement()) {
QDomDocument document;
document.appendChild(document.importNode(location.xml(), true));
@ -471,19 +471,19 @@ bool ElementCollectionHandler::setNames(ElementsLocation &location, const NamesL
qDebug() << "ElementCollectionHandler::setNames : failed to load xml document from file";
return false;
}
QDomElement document_element = document.documentElement();
document_element.replaceChild(name_list.toXml(document), document_element.firstChildElement("names"));
return true;
}
}
if (location.isProject()) {
QDomElement element = location.xml();
QDomDocument document = element.ownerDocument();
element.replaceChild(name_list.toXml(document), element.firstChildElement("names"));
return true;
}
return false;
}

View File

@ -31,10 +31,10 @@
* @param parent : parent widget
*/
ConductorNumExport::ConductorNumExport(QETProject *project, QWidget *parent) :
m_project(project),
m_parent_widget(parent)
m_project(project),
m_parent_widget(parent)
{
fillHash();
fillHash();
}
/**
@ -44,44 +44,44 @@ ConductorNumExport::ConductorNumExport(QETProject *project, QWidget *parent) :
*/
bool ConductorNumExport::toCsv()
{
QString name = QObject::tr("numero_de_fileries_") + m_project->title() + ".csv";
// if(!name.endsWith(".csv")) {
// name += ".csv";
// }
QString filename = QFileDialog::getSaveFileName(m_parent_widget, QObject::tr("Enregister sous... "), name, QObject::tr("Fichiers csv (*.csv)"));
QFile file(filename);
if(!filename.isEmpty())
{
if(QFile::exists(filename))
{
// if file already exist -> delete it
if(!QFile::remove(filename))
{
QMessageBox::critical(m_parent_widget, QObject::tr("Erreur"),
QObject::tr("Impossible de remplacer le fichier!\n\n")+
"Destination : "+filename+"\n");
return false;
}
}
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream stream(&file);
QString name = QObject::tr("numero_de_fileries_") + m_project->title() + ".csv";
// if(!name.endsWith(".csv")) {
// name += ".csv";
// }
QString filename = QFileDialog::getSaveFileName(m_parent_widget, QObject::tr("Enregister sous... "), name, QObject::tr("Fichiers csv (*.csv)"));
QFile file(filename);
if(!filename.isEmpty())
{
if(QFile::exists(filename))
{
// if file already exist -> delete it
if(!QFile::remove(filename))
{
QMessageBox::critical(m_parent_widget, QObject::tr("Erreur"),
QObject::tr("Impossible de remplacer le fichier!\n\n")+
"Destination : "+filename+"\n");
return false;
}
}
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream stream(&file);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove
stream << wiresNum() << endl;
stream << wiresNum() << endl;
#else
stream << wiresNum() << &Qt::endl(stream);
stream << wiresNum() << &Qt::endl(stream);
#endif
}
else {
return false;
}
}
else {
return false;
}
return true;
}
else {
return false;
}
}
else {
return false;
}
return true;
}
/**
@ -90,18 +90,18 @@ bool ConductorNumExport::toCsv()
*/
QString ConductorNumExport::wiresNum() const
{
QString csv;
QStringList list = m_hash.keys();
list.sort();
for (QString key : list)
{
for (int i=0; i<m_hash.value(key) ; ++i) {
csv.append(key + "\n");
}
}
return csv;
QString csv;
QStringList list = m_hash.keys();
list.sort();
for (QString key : list)
{
for (int i=0; i<m_hash.value(key) ; ++i) {
csv.append(key + "\n");
}
}
return csv;
}
/**
@ -110,32 +110,32 @@ QString ConductorNumExport::wiresNum() const
*/
void ConductorNumExport::fillHash()
{
//We used this rx to avoid insert num composed only withe white space.
QRegularExpression rx("^ *$");
for (Diagram *d : m_project->diagrams())
{
DiagramContent dc(d, false);
for (Conductor *c : dc.conductors())
{
QString num = c->textItem()->toPlainText();
if (num.isEmpty() || num.contains(rx)) {
continue;
}
//We must to define if the connected terminal is a folio report, if it is the case
//we don't add the num to the hash because the terminal doesn't represent a real terminal.
if(!(c->terminal1->parentElement()->linkType() & Element::AllReport))
{
int value = m_hash.value(num, 0);
++value;
m_hash.insert(num, value);
}
if(!(c->terminal2->parentElement()->linkType() & Element::AllReport))
{
int value = m_hash.value(num, 0);
++value;
m_hash.insert(num, value);
}
}
}
//We used this rx to avoid insert num composed only withe white space.
QRegularExpression rx("^ *$");
for (Diagram *d : m_project->diagrams())
{
DiagramContent dc(d, false);
for (Conductor *c : dc.conductors())
{
QString num = c->textItem()->toPlainText();
if (num.isEmpty() || num.contains(rx)) {
continue;
}
//We must to define if the connected terminal is a folio report, if it is the case
//we don't add the num to the hash because the terminal doesn't represent a real terminal.
if(!(c->terminal1->parentElement()->linkType() & Element::AllReport))
{
int value = m_hash.value(num, 0);
++value;
m_hash.insert(num, value);
}
if(!(c->terminal2->parentElement()->linkType() & Element::AllReport))
{
int value = m_hash.value(num, 0);
++value;
m_hash.insert(num, value);
}
}
}
}

View File

@ -29,18 +29,18 @@ class QWidget;
*/
class ConductorNumExport
{
public:
ConductorNumExport(QETProject *project, QWidget *parent = nullptr);
bool toCsv();
QString wiresNum() const;
private:
void fillHash();
private:
QETProject *m_project = nullptr;
QHash <QString, int> m_hash;
QWidget *m_parent_widget = nullptr;
public:
ConductorNumExport(QETProject *project, QWidget *parent = nullptr);
bool toCsv();
QString wiresNum() const;
private:
void fillHash();
private:
QETProject *m_project = nullptr;
QHash <QString, int> m_hash;
QWidget *m_parent_widget = nullptr;
};
#endif // ConductorNumExport_H

File diff suppressed because it is too large Load Diff

View File

@ -56,26 +56,26 @@ DiagramEventAddImage::~DiagramEventAddImage()
*/
void DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (m_image && event -> button() == Qt::LeftButton)
{
QPointF pos = event->scenePos();
pos.rx() -= m_image->boundingRect().width()/2;
pos.ry() -= m_image->boundingRect().height()/2;
m_diagram -> undoStack().push (new AddItemCommand<DiagramImageItem *>(m_image, m_diagram, pos));
if (m_image && event -> button() == Qt::LeftButton)
{
QPointF pos = event->scenePos();
pos.rx() -= m_image->boundingRect().width()/2;
pos.ry() -= m_image->boundingRect().height()/2;
m_diagram -> undoStack().push (new AddItemCommand<DiagramImageItem *>(m_image, m_diagram, pos));
for (QGraphicsView *view : m_diagram->views()) {
view->setContextMenuPolicy((Qt::DefaultContextMenu));
view->setContextMenuPolicy((Qt::DefaultContextMenu));
}
m_running = false;
emit finish();
m_running = false;
emit finish();
event->setAccepted(true);
}
else if (m_image && event -> button() == Qt::RightButton)
{
m_image->setRotation(m_image->rotation() + 90);
event->setAccepted(true);
}
}
else if (m_image && event -> button() == Qt::RightButton)
{
m_image->setRotation(m_image->rotation() + 90);
event->setAccepted(true);
}
}
/**
@ -88,21 +88,21 @@ void DiagramEventAddImage::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (!m_image || event->buttons() != Qt::NoButton) {
return;
};
QPointF pos = event->scenePos();
if (!m_is_added)
{
QPointF pos = event->scenePos();
if (!m_is_added)
{
for (QGraphicsView *view : m_diagram->views()) {
view->setContextMenuPolicy((Qt::NoContextMenu));
view->setContextMenuPolicy((Qt::NoContextMenu));
}
m_diagram->addItem(m_image);
m_is_added = true;
}
m_image->setPos(pos - m_image->boundingRect().center());
event->setAccepted(true);
m_diagram->addItem(m_image);
m_is_added = true;
}
m_image->setPos(pos - m_image->boundingRect().center());
event->setAccepted(true);
}
/**
@ -125,14 +125,14 @@ void DiagramEventAddImage::wheelEvent(QGraphicsSceneWheelEvent *event)
if (!m_is_added || !m_image || event -> modifiers() != Qt::CTRL) {
return;
}
qreal scaling = m_image->scale();
event->delta() > 1? scaling += 0.01 : scaling -= 0.01;
qreal scaling = m_image->scale();
event->delta() > 1? scaling += 0.01 : scaling -= 0.01;
if (scaling>0.01 && scaling <= 2) {
m_image->setScale(scaling);
m_image->setScale(scaling);
}
event->setAccepted(true);
event->setAccepted(true);
}
/**
@ -141,8 +141,8 @@ void DiagramEventAddImage::wheelEvent(QGraphicsSceneWheelEvent *event)
*/
bool DiagramEventAddImage::isNull() const
{
if (!m_image) return true;
return false;
if (!m_image) return true;
return false;
}
/**
@ -151,21 +151,21 @@ bool DiagramEventAddImage::isNull() const
*/
void DiagramEventAddImage::openDialog()
{
if (m_diagram -> isReadOnly()) return;
//Open dialog for select image
QString pathPictures = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
QString fileName = QFileDialog::getOpenFileName(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Selectionner une image..."), pathPictures, QObject::tr("Image Files (*.png *.jpg *.jpeg *.bmp *.svg)"));
if (fileName.isEmpty()) return;
QImage image(fileName);
if(image.isNull())
{
QMessageBox::critical(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Erreur"), QObject::tr("Impossible de charger l'image."));
return;
}
m_image = new DiagramImageItem (QPixmap::fromImage(image));
m_running = true;
if (m_diagram -> isReadOnly()) return;
//Open dialog for select image
QString pathPictures = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
QString fileName = QFileDialog::getOpenFileName(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Selectionner une image..."), pathPictures, QObject::tr("Image Files (*.png *.jpg *.jpeg *.bmp *.svg)"));
if (fileName.isEmpty()) return;
QImage image(fileName);
if(image.isNull())
{
QMessageBox::critical(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Erreur"), QObject::tr("Impossible de charger l'image."));
return;
}
m_image = new DiagramImageItem (QPixmap::fromImage(image));
m_running = true;
}

View File

@ -1525,7 +1525,7 @@ void Element::setUpFormula(bool code_letter)
if(!m_freeze_label && !formula.isEmpty())
{
DiagramContext dc = m_element_informations;
m_element_informations.addValue("label", actualLabel());
m_element_informations.addValue("label", actualLabel());
emit elementInfoChange(dc, m_element_informations);
}
}