From 4c52c8c9d0312604ee74bb53b4462d735c2d7ae0 Mon Sep 17 00:00:00 2001 From: plc-user <74435298+plc-user@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:28:58 +0200 Subject: [PATCH] correct indentations / whitespace --- sources/diagram.cpp | 148 +++++++-------- sources/diagramcontext.h | 4 +- sources/elementdialog.cpp | 4 +- sources/elementsmover.cpp | 28 +-- sources/exportdialog.cpp | 284 ++++++++++++++--------------- sources/machine_info.cpp | 9 +- sources/main.cpp | 16 +- sources/qetapp.cpp | 168 ++++++++--------- sources/qetapp.h | 14 +- sources/qetdiagrameditor.cpp | 24 +-- sources/qetproject.cpp | 10 +- sources/qetproject.h | 6 +- sources/qetversion.cpp | 136 +++++++------- sources/qetversion.h | 48 ++--- sources/qetxml.cpp | 340 +++++++++++++++++------------------ sources/qetxml.h | 88 ++++----- 16 files changed, 662 insertions(+), 665 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index d0bde49e3..957ebc1ac 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -193,7 +193,7 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) { */ QPen pen; Diagram::background_color == Qt::black? pen.setColor(Qt::white) - : pen.setColor(Qt::black); + : pen.setColor(Qt::black); pen.setCosmetic(true); p->setPen(pen); @@ -363,11 +363,11 @@ void Diagram::keyPressEvent(QKeyEvent *event) #pragma message("@TODO move code to new function") #endif //Move item with the keyboard arrow - #ifdef Q_OS_MACOS - if(event->modifiers() == Qt::KeypadModifier) - #else - if(event->modifiers() == Qt::NoModifier) - #endif + #ifdef Q_OS_MACOS + if(event->modifiers() == Qt::KeypadModifier) + #else + if(event->modifiers() == Qt::NoModifier) + #endif { QSettings settings; int xKeyGrid = settings.value(QStringLiteral("diagrameditor/key_Xgrid"), @@ -376,26 +376,26 @@ void Diagram::keyPressEvent(QKeyEvent *event) Diagram::yKeyGrid).toInt(); switch(event->key()) { - case Qt::Key_Left: + case Qt::Key_Left: for (Element *item : dc.m_elements) { - left_position = item->sceneBoundingRect().x(); + left_position = item->sceneBoundingRect().x(); if(left_position <= 5) return; } movement = QPointF(-xKeyGrid, 0.0); - break; - case Qt::Key_Right: + break; + case Qt::Key_Right: movement = QPointF(+xKeyGrid, 0.0); break; - case Qt::Key_Up: - for(Element *item : dc.m_elements) + case Qt::Key_Up: + for(Element *item : dc.m_elements) { top_position = item->sceneBoundingRect().y(); if(top_position <= 5) return; } - movement = QPointF(0.0, -yKeyGrid); + movement = QPointF(0.0, -yKeyGrid); break; case Qt::Key_Down: movement = QPointF(0.0, +yKeyGrid); @@ -486,7 +486,7 @@ void Diagram::keyPressEvent(QKeyEvent *event) Qt::AlignRight)); } } - } + } event->ignore(); QGraphicsScene::keyPressEvent(event); } @@ -601,9 +601,9 @@ void Diagram::setConductorsAutonumName(const QString &name) { @return Une QImage representant le schema */ bool Diagram::toPaintDevice(QPaintDevice &pix, - int width, - int height, - Qt::AspectRatioMode aspectRatioMode) { + int width, + int height, + Qt::AspectRatioMode aspectRatioMode) { // determine the source area = schema content + margins // determine la zone source = contenu du schema + marges QRectF source_area; @@ -650,9 +650,9 @@ bool Diagram::toPaintDevice(QPaintDevice &pix, // renders itself // effectue le rendu lui-meme render(&p, - QRect(QPoint(0, 0),image_size), - source_area, - aspectRatioMode); + QRect(QPoint(0, 0),image_size), + source_area, + aspectRatioMode); p.end(); // restore selected items @@ -767,7 +767,7 @@ QDomDocument Diagram::toXml(bool whole_content) { // Conductor autonum if (!m_conductors_autonum_name.isEmpty()) { dom_root.setAttribute(QStringLiteral("conductorAutonum"), - m_conductors_autonum_name); + m_conductors_autonum_name); } //Default New Element @@ -776,7 +776,7 @@ QDomDocument Diagram::toXml(bool whole_content) { //Default New Conductor dom_root.setAttribute(QStringLiteral("freezeNewConductor"), - m_freeze_new_conductors_ + m_freeze_new_conductors_ ? QStringLiteral("true") : QStringLiteral("false")); //Element Folio Sequential Variables @@ -791,10 +791,10 @@ QDomDocument Diagram::toXml(bool whole_content) { document.createElement( QStringLiteral("elementunitfolioseq")); folioSequentialsToXml(&m_elmt_unitfolio_max, - &elmtfolioseq, + &elmtfolioseq, QStringLiteral("sequf_"), QStringLiteral("unitfolioseq"), - &document); + &document); elmtfoliosequential.appendChild(elmtfolioseq); } if (!m_elmt_tenfolio_max.isEmpty()) { @@ -802,10 +802,10 @@ QDomDocument Diagram::toXml(bool whole_content) { document.createElement( QStringLiteral("elementtenfolioseq")); folioSequentialsToXml(&m_elmt_tenfolio_max, - &elmtfolioseq, + &elmtfolioseq, QStringLiteral("seqtf_"), QStringLiteral("tenfolioseq"), - &document); + &document); elmtfoliosequential.appendChild(elmtfolioseq); } if (!m_elmt_hundredfolio_max.isEmpty()) { @@ -813,10 +813,10 @@ QDomDocument Diagram::toXml(bool whole_content) { document.createElement( QStringLiteral("elementhundredfolioseq")); folioSequentialsToXml(&m_elmt_hundredfolio_max, - &elmtfolioseq, + &elmtfolioseq, QStringLiteral("seqhf_"), QStringLiteral("hundredfolioseq"), - &document); + &document); elmtfoliosequential.appendChild(elmtfolioseq); } dom_root.appendChild(elmtfoliosequential); @@ -834,10 +834,10 @@ QDomDocument Diagram::toXml(bool whole_content) { document.createElement( QStringLiteral("conductorunitfolioseq")); folioSequentialsToXml(&m_cnd_unitfolio_max, - &cndfolioseq, + &cndfolioseq, QStringLiteral("sequf_"), QStringLiteral("unitfolioseq"), - &document); + &document); cndfoliosequential.appendChild(cndfolioseq); } if (!m_cnd_tenfolio_max.isEmpty()) { @@ -845,10 +845,10 @@ QDomDocument Diagram::toXml(bool whole_content) { document.createElement( QStringLiteral("conductortenfolioseq")); folioSequentialsToXml(&m_cnd_tenfolio_max, - &cndfolioseq, + &cndfolioseq, QStringLiteral("seqtf_"), QStringLiteral("tenfolioseq"), - &document); + &document); cndfoliosequential.appendChild(cndfolioseq); } if (!m_cnd_hundredfolio_max.isEmpty()) { @@ -856,10 +856,10 @@ QDomDocument Diagram::toXml(bool whole_content) { document.createElement( QStringLiteral("conductorhundredfolioseq")); folioSequentialsToXml(&m_cnd_hundredfolio_max, - &cndfolioseq, + &cndfolioseq, QStringLiteral("seqhf_"), QStringLiteral("hundredfolioseq"), - &document); + &document); cndfoliosequential.appendChild(cndfolioseq); } dom_root.appendChild(cndfoliosequential); @@ -882,7 +882,7 @@ QDomDocument Diagram::toXml(bool whole_content) { QVector list_images; QVector list_shapes; QVector table_vector; - QVector strip_vector; + QVector strip_vector; //Ckeck graphics item to "XMLise" for(QGraphicsItem *qgi : items()) @@ -931,15 +931,15 @@ QDomDocument Diagram::toXml(bool whole_content) { auto table = static_cast(qgi); if (whole_content || table->isSelected()) table_vector << table; - break; + break; + } + case TerminalStripItem::Type: { + const auto strip = static_cast(qgi); + if (whole_content || strip->isSelected()) { + strip_vector << strip; + } + break; } - case TerminalStripItem::Type: { - const auto strip = static_cast(qgi); - if (whole_content || strip->isSelected()) { - strip_vector << strip; - } - break; - } } } @@ -951,7 +951,7 @@ QDomDocument Diagram::toXml(bool whole_content) { auto dom_elements = document.createElement(QStringLiteral("elements")); for (auto elmt : list_elements) { dom_elements.appendChild(elmt->toXml(document, - table_adr_id)); + table_adr_id)); } dom_root.appendChild(dom_elements); } @@ -997,9 +997,9 @@ QDomDocument Diagram::toXml(bool whole_content) { dom_root.appendChild(tables); } - if (!strip_vector.isEmpty()) { - dom_root.appendChild(TerminalStripItemXml::toXml(strip_vector, document)); - } + if (!strip_vector.isEmpty()) { + dom_root.appendChild(TerminalStripItemXml::toXml(strip_vector, document)); + } return(document); @@ -1015,10 +1015,10 @@ QDomDocument Diagram::toXml(bool whole_content) { @param doc */ void Diagram::folioSequentialsToXml(QHash *hash, - QDomElement *domElement, - const QString& seq_type, - const QString& type, + QStringList> *hash, + QDomElement *domElement, + const QString& seq_type, + const QString& type, QDomDocument *doc) { QHash::iterator i; @@ -1030,7 +1030,7 @@ void Diagram::folioSequentialsToXml(QHashappendChild(folioseq); } @@ -1068,9 +1068,9 @@ void Diagram::folioSequentialsToXml(QHash added_strips { TerminalStripItemXml::fromXml(this, root) }; + //Load terminal strip item + QVector added_strips { TerminalStripItemXml::fromXml(this, root) }; //Translate items if a new position was given in parameter if (position != QPointF()) @@ -1459,7 +1459,7 @@ bool Diagram::fromXml(QDomElement &document, for (auto text : qAsConst(added_texts )) added_items << text; for (auto image : qAsConst(added_images )) added_items << image; for (auto table : qAsConst(added_tables )) added_items << table; - for (const auto &strip : qAsConst(added_strips)) added_items << strip; + for (const auto &strip : qAsConst(added_strips)) added_items << strip; //Get the top left corner of the rectangle that contain all added items QRectF items_rect; @@ -1500,9 +1500,9 @@ bool Diagram::fromXml(QDomElement &document, content_ptr -> m_shapes = QSet( added_shapes.begin(), added_shapes.end()); - content_ptr->m_terminal_strip.swap(added_strips); + content_ptr->m_terminal_strip.swap(added_strips); #endif - content_ptr->m_tables.swap(added_tables); + content_ptr->m_tables.swap(added_tables); } adjustSceneRect(); @@ -1556,25 +1556,25 @@ void Diagram::folioSequentialsFromXml(const QDomElement &root, */ void Diagram::refreshContents() { - DiagramContent dc_(this, false); + DiagramContent dc_(this, false); - for (auto &elmt : dc_.m_elements) { + for (auto &elmt : dc_.m_elements) { elmt->initLink(project()); - for (auto &deti : elmt->dynamicTextItems()) + for (auto &deti : elmt->dynamicTextItems()) deti->refreshLabelConnection(); } - for (auto &conductor : dc_.conductors()) { + for (auto &conductor : dc_.conductors()) { conductor->refreshText(); - } + } - for (auto &table : qAsConst(dc_.m_tables)) { + for (auto &table : qAsConst(dc_.m_tables)) { table->initLink(); - } + } - for (auto &strip :qAsConst(dc_.m_terminal_strip)) { - strip->refreshPending(); - } + for (auto &strip :qAsConst(dc_.m_terminal_strip)) { + strip->refreshPending(); + } } /** diff --git a/sources/diagramcontext.h b/sources/diagramcontext.h index 2748d591d..24219948a 100644 --- a/sources/diagramcontext.h +++ b/sources/diagramcontext.h @@ -28,8 +28,8 @@ /** This class represents a diagram context, i.e. the data (a list of key/value pairs) of a diagram at a given time. It is notably used by titleblock - templates to fetch the informations they need to do their rendering, or - element for retrieve information about itself + templates to fetch the informations they need to do their rendering, or + element for retrieve information about itself */ /** diff --git a/sources/elementdialog.cpp b/sources/elementdialog.cpp index 47cf63ae0..263abea33 100644 --- a/sources/elementdialog.cpp +++ b/sources/elementdialog.cpp @@ -93,9 +93,9 @@ void ElementDialog::setUpWidget() prjs.append(prj); if (m_mode == OpenElement) - m_model->loadCollections(true, true, true, prjs); + m_model->loadCollections(true, true, true, prjs); else - m_model->loadCollections(false, true, true, prjs); + m_model->loadCollections(false, true, true, prjs); m_tree_view->setModel(m_model); m_tree_view->setHeaderHidden(true); diff --git a/sources/elementsmover.cpp b/sources/elementsmover.cpp index ec0f2e128..b30b55a77 100644 --- a/sources/elementsmover.cpp +++ b/sources/elementsmover.cpp @@ -85,15 +85,15 @@ int ElementsMover::beginMovement(Diagram *diagram, QGraphicsItem *driver_item) m_moved_content = DiagramContent(diagram); m_moved_content.removeNonMovableItems(); - //Remove element text and text group, if the parent element is selected. - const auto element_text{m_moved_content.m_element_texts}; - for(const auto &deti : element_text) { + //Remove element text and text group, if the parent element is selected. + const auto element_text{m_moved_content.m_element_texts}; + for(const auto &deti : element_text) { if(m_moved_content.m_elements.contains(deti->parentElement())) { m_moved_content.m_element_texts.remove(deti); } - } - const auto element_text_group{m_moved_content.m_texts_groups}; - for(const auto &etig : element_text_group) { + } + const auto element_text_group{m_moved_content.m_texts_groups}; + for(const auto &etig : element_text_group) { if (m_moved_content.m_elements.contains(etig->parentElement())) { m_moved_content.m_texts_groups.remove(etig); } @@ -153,7 +153,7 @@ void ElementsMover::continueMovement(const QPointF &movement) conductor->updatePath(); } - if (m_status_bar && m_movement_driver) + if (m_status_bar && m_movement_driver) { const auto point_{m_movement_driver->scenePos()}; m_status_bar->showMessage(QString("x %1 : y %2").arg(QString::number(point_.x()), QString::number(point_.y()))); @@ -176,19 +176,19 @@ void ElementsMover::endMovement() //Create undo move if there is a movement if (!m_current_movement.isNull()) { - QUndoCommand *quc{new MoveGraphicsItemCommand(m_diagram, m_moved_content, m_current_movement, undo_object)}; + QUndoCommand *quc{new MoveGraphicsItemCommand(m_diagram, m_moved_content, m_current_movement, undo_object)}; undo_object->setText(quc->text()); } //There is only one element moved, and project authorize auto conductor, //we try auto connection of conductor; typedef DiagramContent dc; - if (m_moved_content.items(dc::TextFields - | dc::Images - | dc::Shapes - | dc::TerminalStrip).isEmpty() - && m_moved_content.items(dc::Elements).size() == 1 - && m_diagram->project()->autoConductor()) + if (m_moved_content.items(dc::TextFields + | dc::Images + | dc::Shapes + | dc::TerminalStrip).isEmpty() + && m_moved_content.items(dc::Elements).size() == 1 + && m_diagram->project()->autoConductor()) { const Element *elmt{m_moved_content.m_elements.first()}; const auto aligned_free_terminals{elmt->AlignedFreeTerminals()}; diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index 9ca6931a6..8ea411934 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -435,8 +435,8 @@ void ExportDialog::generateSvg( */ void ExportDialog::generateDxf( Diagram *diagram, - int width, - int height, + int width, + int height, QString &file_path) { saveReloadDiagramParameters(diagram, true); @@ -451,8 +451,8 @@ void ExportDialog::generateDxf( //Add project elements (lines, rectangles, circles, texts) to dxf file if (epw -> exportProperties().draw_border) { - QRectF rect(Diagram::margin,Diagram::margin,width,height); - Createdxf::drawRectangle(file_path,rect,0); + QRectF rect(Diagram::margin,Diagram::margin,width,height); + Createdxf::drawRectangle(file_path,rect,0); } diagram -> border_and_titleblock.drawDxf(file_path, 0); @@ -465,8 +465,8 @@ void ExportDialog::generateDxf( QList list_rectangles; //QList list_ellipses; QList list_shapes; - QList list_tables; -// QList list_terminals; + QList list_tables; +// QList list_terminals; // Determine les elements a "XMLiser" foreach(QGraphicsItem *qgi, diagram -> items()) { @@ -482,18 +482,18 @@ void ExportDialog::generateDxf( list_shapes << dii; } else if (DynamicElementTextItem *deti = qgraphicsitem_cast(qgi)) { list_texts << deti; - } else if (QetGraphicsTableItem *gti = qgraphicsitem_cast(qgi)) { - list_tables << gti; - } + } else if (QetGraphicsTableItem *gti = qgraphicsitem_cast(qgi)) { + list_tables << gti; + } } - // Draw shapes + // Draw shapes foreach (QetShapeItem *qsi, list_shapes) qsi->toDXF(file_path, qsi->pen()); - // Draw tables - foreach (QetGraphicsTableItem *gti, list_tables) { - gti->toDXF(file_path); - } + // Draw tables + foreach (QetGraphicsTableItem *gti, list_tables) { + gti->toDXF(file_path); + } //Draw elements foreach(Element *elmt, list_elements) @@ -507,179 +507,179 @@ void ExportDialog::generateDxf( for(QGraphicsSimpleTextItem *text : primitives.m_texts) { - qreal fontSize = text->font().pointSizeF(); - if (fontSize < 0) - fontSize = text->font().pixelSize(); + qreal fontSize = text->font().pointSizeF(); + if (fontSize < 0) + fontSize = text->font().pixelSize(); - qreal x = elem_pos_x + text->pos().x(); - qreal y = elem_pos_y + text->pos().y(); + qreal x = elem_pos_x + text->pos().x(); + qreal y = elem_pos_y + text->pos().y(); - qreal angle = text -> rotation() + rotation_angle; - qreal angler = angle * M_PI/180; - int xdir = -sin(angler); - int ydir = -cos(angler); + qreal angle = text -> rotation() + rotation_angle; + qreal angler = angle * M_PI/180; + int xdir = -sin(angler); + int ydir = -cos(angler); - QPointF transformed_point = rotation_transformed(x, y, elem_pos_x, elem_pos_y, -rotation_angle); - x = transformed_point.x() - ydir * fontSize * 0.5; - y = transformed_point.y() - xdir * fontSize * 0.5; - QStringList lines = text->text().split('\n'); - qreal offset = fontSize * 1.6; - for (QString line : lines) - { - if (line.size() > 0 && line != "_" ) { - Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360 - angle, 0, 0.72); - } - x += offset * xdir; - y -= offset * ydir; - } + QPointF transformed_point = rotation_transformed(x, y, elem_pos_x, elem_pos_y, -rotation_angle); + x = transformed_point.x() - ydir * fontSize * 0.5; + y = transformed_point.y() - xdir * fontSize * 0.5; + QStringList lines = text->text().split('\n'); + qreal offset = fontSize * 1.6; + for (QString line : lines) + { + if (line.size() > 0 && line != "_" ) { + Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360 - angle, 0, 0.72); + } + x += offset * xdir; + y -= offset * ydir; + } } for (QLineF line : primitives.m_lines) { - QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); - QLineF l = t.map(line); - Createdxf::drawLine(file_path, l, 0); + QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); + QLineF l = t.map(line); + Createdxf::drawLine(file_path, l, 0); } for (QRectF rect : primitives.m_rectangles) { - QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); - QRectF r = t.mapRect(rect); - Createdxf::drawRectangle(file_path,r,0); + QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); + QRectF r = t.mapRect(rect); + Createdxf::drawRectangle(file_path,r,0); } for (QRectF circle_rect : primitives.m_circles) { - QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); - QPointF c = t.map(QPointF(circle_rect.center().x(),circle_rect.center().y())); - Createdxf::drawCircle(file_path,c,circle_rect.width()/2,0); + QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); + QPointF c = t.map(QPointF(circle_rect.center().x(),circle_rect.center().y())); + Createdxf::drawCircle(file_path,c,circle_rect.width()/2,0); } for (QVector polygon : primitives.m_polygons) { if (polygon.size() == 0) continue; - QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); - QPolygonF poly = t.map(polygon); - if(poly.isClosed()) - Createdxf::drawPolygon(file_path,poly,0); - else - Createdxf::drawPolyline(file_path,poly,0); + QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); + QPolygonF poly = t.map(polygon); + if(poly.isClosed()) + Createdxf::drawPolygon(file_path,poly,0); + else + Createdxf::drawPolyline(file_path,poly,0); } // Draw arcs and ellipses for (QVector arc : primitives.m_arcs) { - if (arc.size() == 0) - continue; - qreal x = (elem_pos_x + arc.at(0)); - qreal y = (elem_pos_y + arc.at(1)); - qreal w = arc.at(2); - qreal h = arc.at(3); - qreal startAngle = arc.at(4); - qreal spanAngle = arc .at(5); - QRectF r(x,y,w,h); - QPointF hotspot(elem_pos_x,elem_pos_y); - Createdxf::drawArcEllipse(file_path, r, startAngle, spanAngle, hotspot, rotation_angle, 0); + if (arc.size() == 0) + continue; + qreal x = (elem_pos_x + arc.at(0)); + qreal y = (elem_pos_y + arc.at(1)); + qreal w = arc.at(2); + qreal h = arc.at(3); + qreal startAngle = arc.at(4); + qreal spanAngle = arc .at(5); + QRectF r(x,y,w,h); + QPointF hotspot(elem_pos_x,elem_pos_y); + Createdxf::drawArcEllipse(file_path, r, startAngle, spanAngle, hotspot, rotation_angle, 0); + } + if (epw -> exportProperties().draw_terminals) { + // Draw terminals + QList list_terminals = elmt->terminals(); + QColor col("red"); + QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); + foreach(Terminal *tp, list_terminals) { + QPointF c = t.map(QPointF(tp->dock_elmt_.x(),tp->dock_elmt_.y())); + Createdxf::drawCircle(file_path,c,3.0,Createdxf::dxfColor(col)); + } } - if (epw -> exportProperties().draw_terminals) { - // Draw terminals - QList list_terminals = elmt->terminals(); - QColor col("red"); - QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle); - foreach(Terminal *tp, list_terminals) { - QPointF c = t.map(QPointF(tp->dock_elmt_.x(),tp->dock_elmt_.y())); - Createdxf::drawCircle(file_path,c,3.0,Createdxf::dxfColor(col)); - } - } } //Draw conductors - foreach(Conductor *cond, list_conductors) { - QPolygonF poly; - bool firstseg = true; - foreach(ConductorSegment *segment, cond -> segmentsList()) { - //Createdxf::drawLine(file_path,QLineF(cond->pos()+segment->firstPoint(),cond->pos()+segment->secondPoint()),0); - if(firstseg){ - poly << cond->pos()+segment->firstPoint(); - firstseg = false; - } - poly << cond->pos()+segment->secondPoint(); + foreach(Conductor *cond, list_conductors) { + QPolygonF poly; + bool firstseg = true; + foreach(ConductorSegment *segment, cond -> segmentsList()) { + //Createdxf::drawLine(file_path,QLineF(cond->pos()+segment->firstPoint(),cond->pos()+segment->secondPoint()),0); + if(firstseg){ + poly << cond->pos()+segment->firstPoint(); + firstseg = false; + } + poly << cond->pos()+segment->secondPoint(); } - Createdxf::drawPolyline(file_path,poly,0); + Createdxf::drawPolyline(file_path,poly,0); //Draw conductor text item ConductorTextItem *textItem = cond -> textItem(); - if (textItem) { - qreal fontSize = textItem -> font().pointSizeF(); - if (fontSize < 0) - fontSize = textItem -> font().pixelSize(); - qreal angle = textItem -> rotation(); - qreal angler = angle * M_PI/180; - int xdir = -sin(angler); - int ydir = -cos(angler); + if (textItem) { + qreal fontSize = textItem -> font().pointSizeF(); + if (fontSize < 0) + fontSize = textItem -> font().pixelSize(); + qreal angle = textItem -> rotation(); + qreal angler = angle * M_PI/180; + int xdir = -sin(angler); + int ydir = -cos(angler); - qreal x = (cond->pos().x() + textItem -> pos().x()) - + xdir * fontSize * 1.8 - - ydir * fontSize; - qreal y = (cond->pos().y() + textItem -> pos().y()) - - ydir * fontSize * 1.8 - - xdir * fontSize * 0.9; - QStringList lines = textItem->toPlainText().split('\n'); - qreal offset = fontSize * 1.6; - foreach (QString line, lines) { - if (line.size() > 0 && line != "_" ) - Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360-angle, 0, 0.72 ); - x += offset * xdir; - y -= offset * ydir; - } - } + qreal x = (cond->pos().x() + textItem -> pos().x()) + + xdir * fontSize * 1.8 + - ydir * fontSize; + qreal y = (cond->pos().y() + textItem -> pos().y()) + - ydir * fontSize * 1.8 + - xdir * fontSize * 0.9; + QStringList lines = textItem->toPlainText().split('\n'); + qreal offset = fontSize * 1.6; + foreach (QString line, lines) { + if (line.size() > 0 && line != "_" ) + Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360-angle, 0, 0.72 ); + x += offset * xdir; + y -= offset * ydir; + } + } - // Draw the junctions - QList junctions_list = cond->junctions(); - if (!junctions_list.isEmpty()) { - foreach(QPointF point, junctions_list) { - Createdxf::drawEllipse(file_path,QRectF(cond->pos().x() + point.x() - 1.5, cond->pos().y() + point.y() - 1.5, 3.0, 3.0),0); - } - } + // Draw the junctions + QList junctions_list = cond->junctions(); + if (!junctions_list.isEmpty()) { + foreach(QPointF point, junctions_list) { + Createdxf::drawEllipse(file_path,QRectF(cond->pos().x() + point.x() - 1.5, cond->pos().y() + point.y() - 1.5, 3.0, 3.0),0); + } + } } //Draw text items - foreach(DiagramTextItem *dti, list_texts) { - qreal fontSize = dti -> font().pointSizeF(); - if (fontSize < 0) - fontSize = dti -> font().pixelSize(); + foreach(DiagramTextItem *dti, list_texts) { + qreal fontSize = dti -> font().pointSizeF(); + if (fontSize < 0) + fontSize = dti -> font().pixelSize(); - qreal angle = dti -> rotation(); + qreal angle = dti -> rotation(); - QGraphicsItem *parent = dti->parentItem(); - while (parent) { - angle += parent->rotation(); - parent = parent->parentItem(); - } + QGraphicsItem *parent = dti->parentItem(); + while (parent) { + angle += parent->rotation(); + parent = parent->parentItem(); + } - qreal angler = angle * M_PI/180; - int xdir = -sin(angler); - int ydir = -cos(angler); - qreal x = (dti->scenePos().x()) - + xdir * fontSize * 1.8 - - ydir * fontSize; - qreal y = dti->scenePos().y() - - ydir * fontSize * 1.8 - - xdir * fontSize * 0.9; - QStringList lines = dti -> toPlainText().split('\n'); - qreal offset = fontSize * 1.6; - foreach (QString line, lines) { - if (line.size() > 0 && line != "_" ) - Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360-angle, Createdxf::dxfColor(dti->color()), 0.72 ); - x += offset * xdir; - y -= offset * ydir; - } - } + qreal angler = angle * M_PI/180; + int xdir = -sin(angler); + int ydir = -cos(angler); + qreal x = (dti->scenePos().x()) + + xdir * fontSize * 1.8 + - ydir * fontSize; + qreal y = dti->scenePos().y() + - ydir * fontSize * 1.8 + - xdir * fontSize * 0.9; + QStringList lines = dti -> toPlainText().split('\n'); + qreal offset = fontSize * 1.6; + foreach (QString line, lines) { + if (line.size() > 0 && line != "_" ) + Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360-angle, Createdxf::dxfColor(dti->color()), 0.72 ); + x += offset * xdir; + y -= offset * ydir; + } + } Createdxf::dxfEnd(file_path); - saveReloadDiagramParameters(diagram, false); + saveReloadDiagramParameters(diagram, false); } QPointF ExportDialog::rotation_transformed(qreal px, diff --git a/sources/machine_info.cpp b/sources/machine_info.cpp index 64f6f7afc..2169e1f86 100644 --- a/sources/machine_info.cpp +++ b/sources/machine_info.cpp @@ -125,10 +125,10 @@ void MachineInfo::send_info_to_debug() if (strlen(GIT_COMMIT_SHA)) { qInfo() << "GitRevision " + QString(GIT_COMMIT_SHA); } - qInfo()<< "QElectroTech V " + QetVersion::displayedVersion(); + qInfo()<< "QElectroTech V " + QetVersion::displayedVersion(); qInfo()<< QObject::tr("Compilation : ") + pc.built.version; qInfo()<< "Built with Qt " + pc.built.QT - + " - " + pc.built.arch + + " - " + pc.built.arch + " - Date : " + pc.built.date + " : " + pc.built.time; qInfo()<< "Run with Qt "+ QString(qVersion()) @@ -261,7 +261,7 @@ void MachineInfo::init_get_cpu_info_linux() QString linuxGPUOutput = linuxgpuinfo.readAllStandardOutput(); pc.gpu.info=QString(linuxGPUOutput.toLocal8Bit().constData()); linuxgpuinfo.close(); - + QProcess linuxgpuRAM; linuxgpuRAM.start("bash", QStringList() @@ -271,9 +271,6 @@ void MachineInfo::init_get_cpu_info_linux() QString linuxGPURAMOutput = linuxgpuRAM.readAllStandardOutput(); pc.gpu.RAM=QString(linuxGPURAMOutput.toLocal8Bit().constData()); linuxgpuRAM.close(); - - - } /** diff --git a/sources/main.cpp b/sources/main.cpp index be9d19a4e..7f00aada5 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -215,15 +215,15 @@ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(QetSettings::hdpiScaleFacto QObject::connect(&app, &SingleApplication::receivedMessage, &qetapp, &QETApp::receiveMessage); - QtConcurrent::run([=]() - { - // for debugging - qInstallMessageHandler(myMessageOutput); - qInfo("Start-up"); - // delete old log files of max 7 days old. - delete_old_log_files(7); + QtConcurrent::run([=]() + { + // for debugging + qInstallMessageHandler(myMessageOutput); + qInfo("Start-up"); + // delete old log files of max 7 days old. + delete_old_log_files(7); MachineInfo::instance()->send_info_to_debug(); - }); + }); return app.exec(); } diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index dbfa53528..203888acb 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -170,7 +170,7 @@ QETApp::~QETApp() ElementFactory::dropInstance(); ElementPictureFactory::dropInstance(); MachineInfo::dropInstance(); - TerminalStripEditorWindow::dropInstance(); + TerminalStripEditorWindow::dropInstance(); } @@ -589,101 +589,101 @@ QString QETApp::commonElementsDir() } /** - @brief QETApp::customElementsDir - @return the dir path of user elements collection appended with a - "/" separator + @brief QETApp::customElementsDir + @return the dir path of user elements collection appended with a + "/" separator */ QString QETApp::customElementsDir() { - if (m_custom_element_dir_is_set) - { - return m_custom_element_dir; - } - else - { - m_custom_element_dir_is_set = true; + if (m_custom_element_dir_is_set) + { + return m_custom_element_dir; + } + else + { + m_custom_element_dir_is_set = true; - QSettings settings; - QString path = settings.value( - "elements-collections/custom-collection-path", - "default").toString(); - if (path != "default" && !path.isEmpty()) - { - QDir dir(path); - if (dir.exists()) - { - m_custom_element_dir = path; - if(!m_custom_element_dir.endsWith("/")) { - m_custom_element_dir.append("/"); - } - return m_custom_element_dir; - } - } + QSettings settings; + QString path = settings.value( + "elements-collections/custom-collection-path", + "default").toString(); + if (path != "default" && !path.isEmpty()) + { + QDir dir(path); + if (dir.exists()) + { + m_custom_element_dir = path; + if(!m_custom_element_dir.endsWith("/")) { + m_custom_element_dir.append("/"); + } + return m_custom_element_dir; + } + } - m_custom_element_dir = configDir() + "elements/"; - return m_custom_element_dir; - } + m_custom_element_dir = configDir() + "elements/"; + return m_custom_element_dir; + } } /** - @brief QETApp::companyElementsDir - @return the dir path of company elements collection appended with a - "/" separator + @brief QETApp::companyElementsDir + @return the dir path of company elements collection appended with a + "/" separator */ QString QETApp::companyElementsDir() { - if (m_company_element_dir_is_set) - { - return m_company_element_dir; - } - else - { - m_company_element_dir_is_set = true; + if (m_company_element_dir_is_set) + { + return m_company_element_dir; + } + else + { + m_company_element_dir_is_set = true; - QSettings settings; - QString path = settings.value( - "elements-collections/company-collection-path", - "default").toString(); - if (path != "default" && !path.isEmpty()) - { - QDir dir(path); - if (dir.exists()) - { - m_company_element_dir = path; - if(!m_company_element_dir.endsWith("/")) { - m_company_element_dir.append("/"); - } - return m_company_element_dir; - } - } + QSettings settings; + QString path = settings.value( + "elements-collections/company-collection-path", + "default").toString(); + if (path != "default" && !path.isEmpty()) + { + QDir dir(path); + if (dir.exists()) + { + m_company_element_dir = path; + if(!m_company_element_dir.endsWith("/")) { + m_company_element_dir.append("/"); + } + return m_company_element_dir; + } + } - m_company_element_dir = configDir() + "elements-company/"; - return m_company_element_dir; - } + m_company_element_dir = configDir() + "elements-company/"; + return m_company_element_dir; + } } /** - @brief QETApp::commonElementsDirN - like QString QETApp::commonElementsDir but without "/" at the end - @return QString path + @brief QETApp::commonElementsDirN + like QString QETApp::commonElementsDir but without "/" at the end + @return QString path */ QString QETApp::commonElementsDirN() { - QString path = commonElementsDir(); - if (path.endsWith("/")) path.remove(path.length()-1, 1); - return path; + QString path = commonElementsDir(); + if (path.endsWith("/")) path.remove(path.length()-1, 1); + return path; } /** - @brief QETApp::companyElementsDirN - like QString QETApp::companyElementsDir but without "/" at the end - @return QString path + @brief QETApp::companyElementsDirN + like QString QETApp::companyElementsDir but without "/" at the end + @return QString path */ QString QETApp::companyElementsDirN() { - QString path = companyElementsDir(); - if (path.endsWith("/")) path.remove(path.length()-1, 1); - return path; + QString path = companyElementsDir(); + if (path.endsWith("/")) path.remove(path.length()-1, 1); + return path; } /** @@ -1263,7 +1263,7 @@ QFont QETApp::indiTextsItemFont(qreal size) */ QList QETApp::diagramEditors() { - return(QETApp::instance() -> detectWindows()); + return(QETApp::instance() -> detectWindows()); } /** @@ -1273,18 +1273,18 @@ QList QETApp::diagramEditors() */ QETDiagramEditor *QETApp::diagramEditor(QETProject *project) { - for (const auto &editor : QETApp::instance()->detectWindows()) - { - for (const auto &project_view : editor->openedProjects()) - { - if (project_view->project() == project) - { - return editor; - } - } - } + for (const auto &editor : QETApp::instance()->detectWindows()) + { + for (const auto &project_view : editor->openedProjects()) + { + if (project_view->project() == project) + { + return editor; + } + } + } - return nullptr; + return nullptr; } /** @@ -2454,7 +2454,7 @@ void QETApp::printHelp() */ void QETApp::printVersion() { - std::cout << qPrintable(QetVersion::displayedVersion()) << std::endl; + std::cout << qPrintable(QetVersion::displayedVersion()) << std::endl; } /** diff --git a/sources/qetapp.h b/sources/qetapp.h index 9c114025d..f775d3d3b 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -81,12 +81,12 @@ class QETApp : public QObject static QList availableTitleBlockTemplatesCollections(); static TitleBlockTemplatesCollection *titleBlockTemplatesCollection(const QString &); - static QString commonElementsDir(); - static QString companyElementsDir(); - static QString customElementsDir(); + static QString commonElementsDir(); + static QString companyElementsDir(); + static QString customElementsDir(); static QString commonElementsDirN(); - static QString companyElementsDirN(); - static QString customElementsDirN(); + static QString companyElementsDirN(); + static QString customElementsDirN(); static void resetCollectionsPath(); static QString commonTitleBlockTemplatesDir(); static QString companyTitleBlockTemplatesDir(); @@ -153,8 +153,8 @@ class QETApp : public QObject static QFont indiTextsItemFont (qreal = -1.0); static QETDiagramEditor *diagramEditorForFile(const QString &); static QETDiagramEditor *diagramEditorAncestorOf (const QWidget *child); - static QList diagramEditors(); - static QETDiagramEditor* diagramEditor(QETProject *project); + static QList diagramEditors(); + static QETDiagramEditor* diagramEditor(QETProject *project); static QList elementEditors(); static QList elementEditors(QETProject *); static QList titleBlockTemplateEditors(); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index 5b1451236..33e38142e 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -447,7 +447,7 @@ void QETDiagramEditor::setUpActions() { if (auto project = this->currentProject()) { - TerminalStripEditorWindow::instance(project, this)->show(); + TerminalStripEditorWindow::instance(project, this)->show(); } }); @@ -675,19 +675,19 @@ void QETDiagramEditor::setUpActions() add_polyline ->setStatusTip(tr("Ajoute une polyligne sur le folio actuel")); add_terminal_strip->setStatusTip(tr("Ajoute un plan de bornier sur le folio actuel")); - add_text ->setData(QStringLiteral("text")); - add_image ->setData(QStringLiteral("image")); - add_line ->setData(QStringLiteral("line")); - add_rectangle->setData(QStringLiteral("rectangle")); - add_ellipse ->setData(QStringLiteral("ellipse")); - add_polyline ->setData(QStringLiteral("polyline")); + add_text ->setData(QStringLiteral("text")); + add_image ->setData(QStringLiteral("image")); + add_line ->setData(QStringLiteral("line")); + add_rectangle->setData(QStringLiteral("rectangle")); + add_ellipse ->setData(QStringLiteral("ellipse")); + add_polyline ->setData(QStringLiteral("polyline")); add_terminal_strip->setData(QStringLiteral("terminal_strip")); - add_text->setCheckable(true); - add_line->setCheckable(true); - add_rectangle->setCheckable(true); - add_ellipse->setCheckable(true); - add_polyline->setCheckable(true); + add_text->setCheckable(true); + add_line->setCheckable(true); + add_rectangle->setCheckable(true); + add_ellipse->setCheckable(true); + add_polyline->setCheckable(true); connect(&m_add_item_actions_group, &QActionGroup::triggered, this, &QETDiagramEditor::addItemGroupTriggered); diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index cc06166b1..06ae749e8 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -260,7 +260,7 @@ void QETProject::refresh() dlgWaiting->setDetail(diagram->title()); } diagram->refreshContents(); - } + } } /** @@ -510,7 +510,7 @@ void QETProject::setDefaultTitleBlockProperties(const TitleBlockProperties &titl collection = QETApp::commonTitleBlockTemplatesCollection(); break; case QET::Company : - // collection = QETApp::companyTitleBlockTemplatesCollection(); + // collection = QETApp::companyTitleBlockTemplatesCollection(); break; case QET::Custom : collection = QETApp::customTitleBlockTemplatesCollection(); @@ -919,7 +919,7 @@ QDomDocument QETProject::toXml() // racine du projet QDomDocument xml_doc; QDomElement project_root = xml_doc.createElement("project"); - QetVersion::toXmlAttribute(project_root); + QetVersion::toXmlAttribute(project_root); if (project_title_.isEmpty()) { // if project_title_is Empty add title from m_file_path @@ -1362,7 +1362,7 @@ void QETProject::readProjectXml(QDomDocument &xml_project) "\n qui est ultérieure à votre version !" " \n" "Vous utilisez actuellement QElectroTech en version %2") - .arg(root_elmt.attribute(QStringLiteral("version")), QetVersion::currentVersion().toString() + + .arg(root_elmt.attribute(QStringLiteral("version")), QetVersion::currentVersion().toString() + tr(".\n Il est alors possible que l'ouverture de tout ou partie de ce " "document échoue.\n" "Que désirez vous faire ?"), @@ -1386,7 +1386,7 @@ void QETProject::readProjectXml(QDomDocument &xml_project) tr("Avertissement ", "message box title"), tr("Le projet que vous tentez d'ouvrir est partiellement " "compatible avec votre version %1 de QElectroTech.\n") - .arg(QetVersion::currentVersion().toString()) + + .arg(QetVersion::currentVersion().toString()) + tr("Afin de le rendre totalement compatible veuillez ouvrir ce même projet " "avec la version 0.8, ou 0.80 de QElectroTech et sauvegarder le projet " "et l'ouvrir à nouveau avec cette version.\n" diff --git a/sources/qetproject.h b/sources/qetproject.h index ca5aad484..67de3d581 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -89,7 +89,7 @@ class QETProject : public QObject // methods public: - ProjectPropertiesHandler& projectPropertiesHandler(); + ProjectPropertiesHandler& projectPropertiesHandler(); projectDataBase *dataBase(); QUuid uuid() const; ProjectState state() const; @@ -238,7 +238,7 @@ class QETProject : public QObject void writeBackup(); void init(); ProjectState openFile(QFile *file); - void refresh(); + void refresh(); // attributes private: @@ -296,7 +296,7 @@ class QETProject : public QObject projectDataBase m_data_base; QVector m_terminal_strip_vector; - ProjectPropertiesHandler m_project_properties_handler; + ProjectPropertiesHandler m_project_properties_handler; }; Q_DECLARE_METATYPE(QETProject *) diff --git a/sources/qetversion.cpp b/sources/qetversion.cpp index babe2dfec..02e9f7c52 100644 --- a/sources/qetversion.cpp +++ b/sources/qetversion.cpp @@ -1,85 +1,85 @@ /* - Copyright 2006-2024 The QElectroTech Team - This file is part of QElectroTech. + Copyright 2006-2024 The QElectroTech Team + This file is part of QElectroTech. - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . */ #include "qetversion.h" namespace QetVersion { - QetVersion::VersionType VERSION_TYPE = QetVersion::dev; + QetVersion::VersionType VERSION_TYPE = QetVersion::dev; - QVersionNumber currentVersion() - { - return QVersionNumber{ 0, 100, 0 }; - } + QVersionNumber currentVersion() + { + return QVersionNumber{ 0, 100, 0 }; + } - QString displayedVersion() - { - auto str = currentVersion().toString(); + QString displayedVersion() + { + auto str = currentVersion().toString(); - switch (VERSION_TYPE) { - case dev: - str.append(QStringLiteral("-dev")); - break; - case alpha1: - str.append(QStringLiteral("-alpha 1 ")); - break; - case alpha2: - str.append(QStringLiteral("-alpha 2 ")); - break; - case alpha3: - str.append(QStringLiteral("-alpha 3 ")); - break; - default: - break; - } + switch (VERSION_TYPE) { + case dev: + str.append(QStringLiteral("-dev")); + break; + case alpha1: + str.append(QStringLiteral("-alpha 1 ")); + break; + case alpha2: + str.append(QStringLiteral("-alpha 2 ")); + break; + case alpha3: + str.append(QStringLiteral("-alpha 3 ")); + break; + default: + break; + } - return str; - } + return str; + } - /** - * @brief toXmlAttribute - * Write @a version as an attribute of @a xml - * @param xml - * @param version - */ - void toXmlAttribute(QDomElement &xml) - { - xml.setAttribute(QStringLiteral("version"), currentVersion().toString()); - } + /** + * @brief toXmlAttribute + * Write @a version as an attribute of @a xml + * @param xml + * @param version + */ + void toXmlAttribute(QDomElement &xml) + { + xml.setAttribute(QStringLiteral("version"), currentVersion().toString()); + } - /** - * @brief fromXmlAttribute - * Read and return a QVersionNumber - * stored as attribute of @a xml - * @param xml - * @return the version stored in @a xml. - * Note that the returned version can be null - */ - QVersionNumber fromXmlAttribute(const QDomElement &xml) - { - if (xml.hasAttribute(QStringLiteral("version"))) { - return QVersionNumber::fromString(xml.attribute(QStringLiteral("version"))); - } else { - return QVersionNumber{}; - } - } + /** + * @brief fromXmlAttribute + * Read and return a QVersionNumber + * stored as attribute of @a xml + * @param xml + * @return the version stored in @a xml. + * Note that the returned version can be null + */ + QVersionNumber fromXmlAttribute(const QDomElement &xml) + { + if (xml.hasAttribute(QStringLiteral("version"))) { + return QVersionNumber::fromString(xml.attribute(QStringLiteral("version"))); + } else { + return QVersionNumber{}; + } + } - QVersionNumber versionZeroDotSix() - { - return QVersionNumber{ 0, 60 }; - } + QVersionNumber versionZeroDotSix() + { + return QVersionNumber{ 0, 60 }; + } } diff --git a/sources/qetversion.h b/sources/qetversion.h index dada2eff9..0b8c1d38d 100644 --- a/sources/qetversion.h +++ b/sources/qetversion.h @@ -1,19 +1,19 @@ /* - Copyright 2006-2024 The QElectroTech Team - This file is part of QElectroTech. + Copyright 2006-2024 The QElectroTech Team + This file is part of QElectroTech. - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . */ #ifndef QETVERSION_H #define QETVERSION_H @@ -23,21 +23,21 @@ namespace QetVersion { - enum VersionType { - dev = 0, - alpha1 = 1, - alpha2 = 2, - alpha3 = 3, - stable = 4 - }; + enum VersionType { + dev = 0, + alpha1 = 1, + alpha2 = 2, + alpha3 = 3, + stable = 4 + }; - QVersionNumber currentVersion(); - QString displayedVersion(); + QVersionNumber currentVersion(); + QString displayedVersion(); - QVersionNumber versionZeroDotSix(); + QVersionNumber versionZeroDotSix(); - void toXmlAttribute(QDomElement &xml); - QVersionNumber fromXmlAttribute(const QDomElement &xml); + void toXmlAttribute(QDomElement &xml); + QVersionNumber fromXmlAttribute(const QDomElement &xml); } #endif // QETVERSION_H diff --git a/sources/qetxml.cpp b/sources/qetxml.cpp index a7206d05b..8924b98d0 100644 --- a/sources/qetxml.cpp +++ b/sources/qetxml.cpp @@ -631,28 +631,28 @@ bool boolFromString(const QString &value, bool default_value, bool *conv_ok) PropertyFlags debugReadXml(PropertyFlags flag, const QDomElement &e, const QString& attribute_name, const QString& attr, const QString& type) { - if (flag == QETXML::PropertyFlags::NoValidConversion) - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << type << ". value: " << attr; + if (flag == QETXML::PropertyFlags::NoValidConversion) + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << type << ". value: " << attr; - return flag; + return flag; } QDomElement createXmlProperty(const QString& name, const QString value) { - QDomDocument doc; - QDomElement p = doc.createElement("property"); - p.setAttribute("name", name); - p.setAttribute("type", stringS); - p.setAttribute("value", value); - return p; + QDomDocument doc; + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", stringS); + p.setAttribute("value", value); + return p; } QDomElement createXmlProperty(const QString& name, const char* value) { - QDomDocument doc; - QDomElement p = doc.createElement("property"); - p.setAttribute("name", name); - p.setAttribute("type", stringS); - p.setAttribute("value", value); - return p; + QDomDocument doc; + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", stringS); + p.setAttribute("value", value); + return p; } /*! @@ -665,48 +665,48 @@ QDomElement createXmlProperty(const QString& name, const char* value) { * \p entier is not valid and the return value is False */ QDomElement createXmlProperty(const QString& name, const int value) { - QDomDocument doc; - QDomElement p = doc.createElement("property"); - p.setAttribute("name", name); - p.setAttribute("type", integerS); - p.setAttribute("value", QString::number(value)); - return p; + QDomDocument doc; + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", integerS); + p.setAttribute("value", QString::number(value)); + return p; } QDomElement createXmlProperty(const QString& name, const double value) { - QDomDocument doc; - QDomElement p = doc.createElement("property"); - p.setAttribute("name", name); - p.setAttribute("type", doubleS); - p.setAttribute("value", QString::number(value)); - return p; + QDomDocument doc; + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", doubleS); + p.setAttribute("value", QString::number(value)); + return p; } QDomElement createXmlProperty(const QString& name, const bool value) { - QDomDocument doc; - QDomElement p = doc.createElement("property"); - p.setAttribute("name", name); - p.setAttribute("type", boolS); - p.setAttribute("value", QString::number(value)); - return p; + QDomDocument doc; + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", boolS); + p.setAttribute("value", QString::number(value)); + return p; } QDomElement createXmlProperty(const QString& name, const QUuid value) { - QDomDocument doc; - QDomElement p = doc.createElement("property"); - p.setAttribute("name", name); - p.setAttribute("type", uuidS); - p.setAttribute("value", value.toString()); - return p; + QDomDocument doc; + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", uuidS); + p.setAttribute("value", value.toString()); + return p; } QDomElement createXmlProperty(const QString& name, const QColor value) { - QDomDocument doc; - QDomElement p = doc.createElement("property"); - p.setAttribute("name", name); - p.setAttribute("type", colorS); - p.setAttribute("value", value.name()); - return p; + QDomDocument doc; + QDomElement p = doc.createElement("property"); + p.setAttribute("name", name); + p.setAttribute("type", colorS); + p.setAttribute("value", value.name()); + return p; } /*! @@ -720,159 +720,159 @@ QDomElement createXmlProperty(const QString& name, const QColor value) { */ PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier) { - QString attr; + QString attr; - if (!attribute(e, attribute_name, integerS, &attr)) { - return PropertyFlags::NotFound; - } + if (!attribute(e, attribute_name, integerS, &attr)) { + return PropertyFlags::NotFound; + } - return debugReadXml(propertyInteger(attr, entier), e, attribute_name, attr, integerS); + return debugReadXml(propertyInteger(attr, entier), e, attribute_name, attr, integerS); } PropertyFlags propertyInteger(const QString& value, int* entier) { - // verifie la validite de l'attribut - bool ok; - int tmp = value.toInt(&ok); - if (!ok) { - return QETXML::PropertyFlags::NoValidConversion; - } + // verifie la validite de l'attribut + bool ok; + int tmp = value.toInt(&ok); + if (!ok) { + return QETXML::PropertyFlags::NoValidConversion; + } - if (entier != nullptr) - *entier = tmp; + if (entier != nullptr) + *entier = tmp; - return PropertyFlags::Success; + return PropertyFlags::Success; } PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) { - QString attr; + QString attr; - if (!attribute(e, attribute_name, doubleS, &attr)) { - return PropertyFlags::NotFound; - } + if (!attribute(e, attribute_name, doubleS, &attr)) { + return PropertyFlags::NotFound; + } - return debugReadXml(propertyDouble(attr, reel), e, attribute_name, attr, doubleS); + return debugReadXml(propertyDouble(attr, reel), e, attribute_name, attr, doubleS); } PropertyFlags propertyDouble(const QString& value, double* reel) { - // verifie la validite de l'attribut - bool ok; - double tmp = value.toDouble(&ok); - if (!ok) { - return QETXML::PropertyFlags::NoValidConversion; - } + // verifie la validite de l'attribut + bool ok; + double tmp = value.toDouble(&ok); + if (!ok) { + return QETXML::PropertyFlags::NoValidConversion; + } - if (reel != nullptr) - *reel = tmp; + if (reel != nullptr) + *reel = tmp; - return PropertyFlags::Success; + return PropertyFlags::Success; } PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) { - QString attr; + QString attr; - if (!attribute(e, attribute_name, boolS, &attr)) { - return PropertyFlags::NotFound; - } + if (!attribute(e, attribute_name, boolS, &attr)) { + return PropertyFlags::NotFound; + } - return debugReadXml(propertyBool(attr, boolean), e, attribute_name, attr, boolS); + return debugReadXml(propertyBool(attr, boolean), e, attribute_name, attr, boolS); } PropertyFlags propertyBool(const QString& value, bool* boolean) { - // verifie la validite de l'attribut - bool ok; - bool tmp = value.toInt(&ok); - if (!ok) { - if (value == "true" || value == "1") - tmp = true; - else if (value == "false" || value == "0") - tmp = false; - else { - return QETXML::PropertyFlags::NoValidConversion; - } - } + // verifie la validite de l'attribut + bool ok; + bool tmp = value.toInt(&ok); + if (!ok) { + if (value == "true" || value == "1") + tmp = true; + else if (value == "false" || value == "0") + tmp = false; + else { + return QETXML::PropertyFlags::NoValidConversion; + } + } - if (boolean != nullptr) - *boolean = tmp; + if (boolean != nullptr) + *boolean = tmp; - return PropertyFlags::Success; + return PropertyFlags::Success; } PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) { - QString attr; + QString attr; - if (!attribute(e, attribute_name, colorS, &attr)) { - return PropertyFlags::NotFound; - } + if (!attribute(e, attribute_name, colorS, &attr)) { + return PropertyFlags::NotFound; + } - return debugReadXml(propertyColor(attr, color), e, attribute_name, attr, colorS); + return debugReadXml(propertyColor(attr, color), e, attribute_name, attr, colorS); } PropertyFlags propertyColor(const QString& value, QColor* color) { - // verifie la validite de l'attribut - QColor tmp = QColor(value); - if (!tmp.isValid()) { - return QETXML::PropertyFlags::NoValidConversion; - } + // verifie la validite de l'attribut + QColor tmp = QColor(value); + if (!tmp.isValid()) { + return QETXML::PropertyFlags::NoValidConversion; + } - if (color != nullptr) - *color = tmp; + if (color != nullptr) + *color = tmp; - return PropertyFlags::Success; + return PropertyFlags::Success; } PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) { - QString attr; + QString attr; - if (!attribute(e, attribute_name, uuidS, &attr)) { - return PropertyFlags::NotFound; - } + if (!attribute(e, attribute_name, uuidS, &attr)) { + return PropertyFlags::NotFound; + } - return debugReadXml(propertyUuid(attr, uuid), e, attribute_name, attr, uuidS); + return debugReadXml(propertyUuid(attr, uuid), e, attribute_name, attr, uuidS); } PropertyFlags propertyUuid(const QString& value, QUuid* uuid) { - if (QUuid(value).isNull()){ - return QETXML::PropertyFlags::NoValidConversion; - } + if (QUuid(value).isNull()){ + return QETXML::PropertyFlags::NoValidConversion; + } - if (uuid != nullptr) - *uuid = QUuid(value); + if (uuid != nullptr) + *uuid = QUuid(value); - return PropertyFlags::Success; + return PropertyFlags::Success; } PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string) { - QString attr; - if (!attribute(e, attribute_name, stringS, &attr)) { - return PropertyFlags::NotFound; - } + QString attr; + if (!attribute(e, attribute_name, stringS, &attr)) { + return PropertyFlags::NotFound; + } - // verifie la validite de l'attribut - if (string != nullptr) - *string = attr; + // verifie la validite de l'attribut + if (string != nullptr) + *string = attr; - return PropertyFlags::Success; + return PropertyFlags::Success; } QDomElement property(const QDomElement& e, const QString& name) { - for (int i=0; i < e.childNodes().count(); i++) { - QDomElement child = e.childNodes().at(i).toElement(); - if (!validXmlProperty(child)) - continue; // there might also non property childs + for (int i=0; i < e.childNodes().count(); i++) { + QDomElement child = e.childNodes().at(i).toElement(); + if (!validXmlProperty(child)) + continue; // there might also non property childs - if (child.attribute("name") == name) - return child; - } - return QDomElement(); + if (child.attribute("name") == name) + return child; + } + return QDomElement(); } /*! @@ -885,40 +885,40 @@ QDomElement property(const QDomElement& e, const QString& name) { * \return */ bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr) { - QDomElement p = property(e, attribute_name); - if (p.isNull()) { - // check if legacy property is available, - // where the property is inside the element as attribute - if (!e.hasAttribute(attribute_name)) { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "Property " << attribute_name << "is not available"; - return false; - } + QDomElement p = property(e, attribute_name); + if (p.isNull()) { + // check if legacy property is available, + // where the property is inside the element as attribute + if (!e.hasAttribute(attribute_name)) { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "Property " << attribute_name << "is not available"; + return false; + } - *attr = e.attribute(attribute_name); + *attr = e.attribute(attribute_name); - } else { - if (p.attribute("type") != type) { - qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ", Property: " << attribute_name << "(" << p.attribute("type") << ") has not type: " << type; - return false; - } + } else { + if (p.attribute("type") != type) { + qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ", Property: " << attribute_name << "(" << p.attribute("type") << ") has not type: " << type; + return false; + } - *attr = p.attribute("value"); + *attr = p.attribute("value"); - } - return true; + } + return true; } bool validXmlProperty(const QDomElement& e) { - if (!e.hasAttribute("name")) - return false; + if (!e.hasAttribute("name")) + return false; - if (!e.hasAttribute("type")) - return false; + if (!e.hasAttribute("type")) + return false; - if (!e.hasAttribute("value")) - return false; + if (!e.hasAttribute("value")) + return false; - return true; + return true; } /** @@ -932,25 +932,25 @@ bool validXmlProperty(const QDomElement& e) { */ QDomElement qGraphicsItemPosToXml(QGraphicsItem *item, QDomDocument &document) { - auto dom_pos = document.createElement(QStringLiteral("pos")); - dom_pos.setAttribute(QStringLiteral("x"), QString::number(item->pos().x())); - dom_pos.setAttribute(QStringLiteral("y"), QString::number(item->pos().y())); - dom_pos.setAttribute(QStringLiteral("z"), QString::number(item->zValue())); + auto dom_pos = document.createElement(QStringLiteral("pos")); + dom_pos.setAttribute(QStringLiteral("x"), QString::number(item->pos().x())); + dom_pos.setAttribute(QStringLiteral("y"), QString::number(item->pos().y())); + dom_pos.setAttribute(QStringLiteral("z"), QString::number(item->zValue())); - return dom_pos; + return dom_pos; } bool qGraphicsItemPosFromXml(QGraphicsItem *item, const QDomElement &xml_elmt) { - if (xml_elmt.tagName() == QLatin1String("pos")) - { - item->setX(xml_elmt.attribute(QStringLiteral("x"), QStringLiteral("0")).toDouble()); - item->setY(xml_elmt.attribute(QStringLiteral("y"), QStringLiteral("0")).toDouble()); - item->setZValue(xml_elmt.attribute(QStringLiteral("z"), QStringLiteral("0")).toInt()); + if (xml_elmt.tagName() == QLatin1String("pos")) + { + item->setX(xml_elmt.attribute(QStringLiteral("x"), QStringLiteral("0")).toDouble()); + item->setY(xml_elmt.attribute(QStringLiteral("y"), QStringLiteral("0")).toDouble()); + item->setZValue(xml_elmt.attribute(QStringLiteral("z"), QStringLiteral("0")).toInt()); - return true; - } - return false; + return true; + } + return false; } } diff --git a/sources/qetxml.h b/sources/qetxml.h index e73acb1a2..2bd4d1415 100644 --- a/sources/qetxml.h +++ b/sources/qetxml.h @@ -91,61 +91,61 @@ namespace QETXML QVector findInDomElement(const QDomElement &dom_elmt, const QString &tag_name); - QDomElement qGraphicsItemPosToXml(QGraphicsItem *item, QDomDocument &document); - bool qGraphicsItemPosFromXml(QGraphicsItem *item, const QDomElement &xml_elmt); + QDomElement qGraphicsItemPosToXml(QGraphicsItem *item, QDomDocument &document); + bool qGraphicsItemPosFromXml(QGraphicsItem *item, const QDomElement &xml_elmt); QString boolToString(bool value); bool boolFromString(const QString &value, bool default_value = true, bool *conv_ok = nullptr); - const QString integerS = "int"; - const QString doubleS = "double"; - const QString boolS = "bool"; - const QString stringS = "string"; - const QString uuidS = "uuid"; - const QString colorS = "color"; + const QString integerS = "int"; + const QString doubleS = "double"; + const QString boolS = "bool"; + const QString stringS = "string"; + const QString uuidS = "uuid"; + const QString colorS = "color"; - enum PropertyFlags { - Success = 0, - NotFound = 1, - NoValidConversion = 2, - // = 4 - }; + enum PropertyFlags { + Success = 0, + NotFound = 1, + NoValidConversion = 2, + // = 4 + }; - /*! - * Use this functions to add properties to the xml document - */ - QDomElement createXmlProperty(const QString& name, const QString value); - QDomElement createXmlProperty(const QString& name, const char* value); - QDomElement createXmlProperty(const QString& name, const int value); - QDomElement createXmlProperty(const QString& name, const double value); - QDomElement createXmlProperty(const QString& name, const bool value); - QDomElement createXmlProperty(const QString& name, const QUuid value); - QDomElement createXmlProperty(const QString& name, const QColor value); + /*! + * Use this functions to add properties to the xml document + */ + QDomElement createXmlProperty(const QString& name, const QString value); + QDomElement createXmlProperty(const QString& name, const char* value); + QDomElement createXmlProperty(const QString& name, const int value); + QDomElement createXmlProperty(const QString& name, const double value); + QDomElement createXmlProperty(const QString& name, const bool value); + QDomElement createXmlProperty(const QString& name, const QUuid value); + QDomElement createXmlProperty(const QString& name, const QColor value); - PropertyFlags propertyInteger(const QString& value, int* entry = nullptr); - PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr); - PropertyFlags propertyDouble(const QString& value, double* entry = nullptr); - PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr); - PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr); - PropertyFlags propertyBool(const QString& value, bool* entry = nullptr); - PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr); - PropertyFlags propertyUuid(const QString& value, QUuid* entry = nullptr); - PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr); - PropertyFlags propertyColor(const QString& value, QColor* entry = nullptr); - PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr); + PropertyFlags propertyInteger(const QString& value, int* entry = nullptr); + PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr); + PropertyFlags propertyDouble(const QString& value, double* entry = nullptr); + PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr); + PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr); + PropertyFlags propertyBool(const QString& value, bool* entry = nullptr); + PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr); + PropertyFlags propertyUuid(const QString& value, QUuid* entry = nullptr); + PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr); + PropertyFlags propertyColor(const QString& value, QColor* entry = nullptr); + PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr); - QDomElement property(const QDomElement& e, const QString& name); - bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); + QDomElement property(const QDomElement& e, const QString& name); + bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr); - /*! - * \brief PropertiesInterface::validXmlProperty - * Check if the Xml element contains the needed fields - * \param e Xml Property - * \return True if name, type, value attribute are available, else false - */ - bool validXmlProperty(const QDomElement& e); + /*! + * \brief PropertiesInterface::validXmlProperty + * Check if the Xml element contains the needed fields + * \param e Xml Property + * \return True if name, type, value attribute are available, else false + */ + bool validXmlProperty(const QDomElement& e); } #endif // QETXML_H