diff --git a/sources/diagramcontent.cpp b/sources/diagramcontent.cpp index 161a21299..002f2c6cd 100644 --- a/sources/diagramcontent.cpp +++ b/sources/diagramcontent.cpp @@ -68,7 +68,7 @@ DiagramContent::DiagramContent(Diagram *diagram, bool selected) : if (m_potential_conductors.isEmpty()) { m_potential_conductors << c; } else { - if (!potentialIsManaged(c->relatedPotentialConductors(true).values())) { + if (!potentialIsManaged(c->relatedPotentialConductors(true).values())) { m_potential_conductors << c; } } @@ -91,28 +91,28 @@ DiagramContent::DiagramContent(Diagram *diagram, bool selected) : //For each selected element, we determine if conductors must be moved or updated. for(Element *elmt : m_elements) { - if (elmt->isSelected()) - { - for(Terminal *terminal : elmt->terminals()) - { - for(Conductor *conductor : terminal->conductors()) - { - Terminal *other_terminal; - if (conductor->terminal1 == terminal) - other_terminal = conductor->terminal2; - else - other_terminal = conductor->terminal1; + if (elmt->isSelected()) + { + for(Terminal *terminal : elmt->terminals()) + { + for(Conductor *conductor : terminal->conductors()) + { + Terminal *other_terminal; + if (conductor->terminal1 == terminal) + other_terminal = conductor->terminal2; + else + other_terminal = conductor->terminal1; //If the two elements of conductor are movable if (m_elements.contains(other_terminal -> parentElement())) { if (!m_conductors_to_move.contains(conductor)) m_conductors_to_move << conductor; } - else if (!m_conductors_to_update.contains(conductor)) - m_conductors_to_update << conductor; - } - } - } + else if (!m_conductors_to_update.contains(conductor)) + m_conductors_to_update << conductor; + } + } + } } } diff --git a/sources/editor/arceditor.cpp b/sources/editor/arceditor.cpp index 8276869e4..6d27c8327 100644 --- a/sources/editor/arceditor.cpp +++ b/sources/editor/arceditor.cpp @@ -106,7 +106,7 @@ bool ArcEditor::setPart(CustomElementPart *new_part) if (!new_part) { if (part) - disconnectChangeConnections(); + disconnectChangeConnections(); part = nullptr; style_ -> setPart(nullptr); @@ -117,11 +117,11 @@ bool ArcEditor::setPart(CustomElementPart *new_part) { if (part == part_arc) return true; if (part) - disconnectChangeConnections(); + disconnectChangeConnections(); part = part_arc; style_ -> setPart(part); updateForm(); - setUpChangeConnections(); + setUpChangeConnections(); return(true); } @@ -130,12 +130,12 @@ bool ArcEditor::setPart(CustomElementPart *new_part) bool ArcEditor::setParts(QList parts) { - if (parts.isEmpty()) - return false; + if (parts.isEmpty()) + return false; - if (!setPart(parts.first())) - return false; - return style_->setParts(parts); + if (!setPart(parts.first())) + return false; + return style_->setParts(parts); } /** @@ -147,7 +147,7 @@ CustomElementPart *ArcEditor::currentPart() const { } QList ArcEditor::currentParts() const { - return style_->currentParts(); + return style_->currentParts(); } /** @@ -158,20 +158,20 @@ void ArcEditor::updateArcS() { if (m_locked) return; m_locked = true; - double value = start_angle->value() * 16; + double value = start_angle->value() * 16; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartArc* arc = static_cast(part); + PartArc* arc = static_cast(part); - if (value != arc->property("startAngle")) - { - QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "startAngle", arc->property("startAngle"), value); - undo->setText("Modifier l'angle de depart d'un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + if (value != arc->property("startAngle")) + { + QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "startAngle", arc->property("startAngle"), value); + undo->setText("Modifier l'angle de depart d'un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } @@ -186,17 +186,17 @@ void ArcEditor::updateArcA() m_locked = true; double value = angle->value() * 16; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartArc* arc = static_cast(part); - if (value != arc->property("spanAngle")) - { - QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "spanAngle", arc->property("spanAngle"), value); - undo->setText("Modifier l'angle d'un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + PartArc* arc = static_cast(part); + if (value != arc->property("spanAngle")) + { + QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "spanAngle", arc->property("spanAngle"), value); + undo->setText("Modifier l'angle d'un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } @@ -210,95 +210,95 @@ void ArcEditor::updateArcRectX() if (m_locked) return; m_locked = true; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartArc* arc = static_cast(part); - QRectF rect = arc->property("rect").toRectF(); - QPointF point = arc->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); // does not matter which value y is, because only the x value is used - rect.setX(point.x()); // change only the x value + PartArc* arc = static_cast(part); + QRectF rect = arc->property("rect").toRectF(); + QPointF point = arc->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); // does not matter which value y is, because only the x value is used + rect.setX(point.x()); // change only the x value - if (rect != part->property("rect")) - { - QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + if (rect != part->property("rect")) + { + QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } void ArcEditor::updateArcRectY() { - if (m_locked) return; - m_locked = true; + if (m_locked) return; + m_locked = true; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartArc* arc = static_cast(part); - QRectF rect = arc->property("rect").toRectF(); + PartArc* arc = static_cast(part); + QRectF rect = arc->property("rect").toRectF(); - QPointF point = arc->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); - rect.setY(point.y()); + QPointF point = arc->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); + rect.setY(point.y()); - if (rect != arc->property("rect")) - { - QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } + if (rect != arc->property("rect")) + { + QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } - } + } - m_locked = false; + m_locked = false; } void ArcEditor::updateArcRectH() { - if (m_locked) return; - m_locked = true; + if (m_locked) return; + m_locked = true; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartArc* arc = static_cast(part); - QRectF rect = arc->property("rect").toRectF(); + PartArc* arc = static_cast(part); + QRectF rect = arc->property("rect").toRectF(); - if (rect.width() != h->value()) - { - rect.setWidth(h->value()); - QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + if (rect.width() != h->value()) + { + rect.setWidth(h->value()); + QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } - m_locked = false; + m_locked = false; } void ArcEditor::updateArcRectV() { - if (m_locked) return; - m_locked = true; + if (m_locked) return; + m_locked = true; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartArc* arc = static_cast(part); - QRectF rect = arc->property("rect").toRectF(); + PartArc* arc = static_cast(part); + QRectF rect = arc->property("rect").toRectF(); - if (rect.height() != v->value()) - { - rect.setHeight(v->value()); - QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + if (rect.height() != v->value()) + { + rect.setHeight(v->value()); + QPropertyUndoCommand *undo= new QPropertyUndoCommand(arc, "rect", arc->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } - m_locked = false; + m_locked = false; } /** @@ -329,19 +329,19 @@ void ArcEditor::activeConnections(bool active) { if (active) { - connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRectX())); - connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRectY())); - connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRectH())); - connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRectV())); + connect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRectX())); + connect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRectY())); + connect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRectH())); + connect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRectV())); connect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS())); connect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA())); } else { - disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRectX())); - disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRectY())); - disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRectH())); - disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRectV())); + disconnect(x, SIGNAL(editingFinished()), this, SLOT(updateArcRectX())); + disconnect(y, SIGNAL(editingFinished()), this, SLOT(updateArcRectY())); + disconnect(h, SIGNAL(editingFinished()), this, SLOT(updateArcRectH())); + disconnect(v, SIGNAL(editingFinished()), this, SLOT(updateArcRectV())); disconnect(start_angle, SIGNAL(editingFinished()), this, SLOT(updateArcS())); disconnect(angle, SIGNAL(editingFinished()), this, SLOT(updateArcA())); } diff --git a/sources/editor/arceditor.h b/sources/editor/arceditor.h index df88557ea..aaa79efe2 100644 --- a/sources/editor/arceditor.h +++ b/sources/editor/arceditor.h @@ -47,31 +47,31 @@ class ArcEditor : public ElementItemEditor QSpinBox *angle, *start_angle; bool m_locked; - QList m_change_connections; + QList m_change_connections; // methods public: bool setPart(CustomElementPart *) override; - bool setParts(QList parts) override; + bool setParts(QList parts) override; CustomElementPart *currentPart() const override; - QList currentParts() const override; + QList currentParts() const override; public slots: void updateArcS(); void updateArcA(); - void updateArcRectX(); - void updateArcRectY(); - void updateArcRectH(); - void updateArcRectV(); + void updateArcRectX(); + void updateArcRectY(); + void updateArcRectH(); + void updateArcRectV(); void updateForm() override; private: void activeConnections(bool); - /*! - * \brief setUpChangeConnections - * Setup the connection from the arc(s) to the widget, to update it when the arc(s) are changed (moved ...) - */ - void setUpChangeConnections(); - void disconnectChangeConnections(); + /*! + * \brief setUpChangeConnections + * Setup the connection from the arc(s) to the widget, to update it when the arc(s) are changed (moved ...) + */ + void setUpChangeConnections(); + void disconnectChangeConnections(); }; #endif diff --git a/sources/editor/elementview.cpp b/sources/editor/elementview.cpp index 4028d317d..5cb99066b 100644 --- a/sources/editor/elementview.cpp +++ b/sources/editor/elementview.cpp @@ -417,7 +417,7 @@ void ElementView::wheelEvent(QWheelEvent *e) { if (e -> modifiers() & Qt::ControlModifier) e -> angleDelta().y() > 0 ? zoomInSlowly() : zoomOutSlowly(); else - QGraphicsView::wheelEvent(e); + QGraphicsView::wheelEvent(e); } else { e -> angleDelta().y() > 0 ? zoomIn(): zoomOut(); } diff --git a/sources/editor/ellipseeditor.cpp b/sources/editor/ellipseeditor.cpp index b374f090d..b14a59ce7 100644 --- a/sources/editor/ellipseeditor.cpp +++ b/sources/editor/ellipseeditor.cpp @@ -96,7 +96,7 @@ bool EllipseEditor::setPart(CustomElementPart *new_part) if (!new_part) { if (part) - disconnectChangeConnections(); + disconnectChangeConnections(); part = nullptr; style_ -> setPart(nullptr); return(true); @@ -105,11 +105,11 @@ bool EllipseEditor::setPart(CustomElementPart *new_part) { if (part == part_ellipse) return true; if (part) - disconnectChangeConnections(); + disconnectChangeConnections(); part = part_ellipse; style_ -> setPart(part); updateForm(); - setUpChangeConnections(); + setUpChangeConnections(); return(true); } return(false); @@ -117,12 +117,12 @@ bool EllipseEditor::setPart(CustomElementPart *new_part) bool EllipseEditor::setParts(QList parts) { - if (parts.isEmpty()) - return false; + if (parts.isEmpty()) + return false; - if (!setPart(parts.first())) - return false; - return style_->setParts(parts); + if (!setPart(parts.first())) + return false; + return style_->setParts(parts); } /** @@ -138,98 +138,98 @@ QList EllipseEditor::currentParts() const { void EllipseEditor::editingFinishedX() { - if (m_locked) return; - m_locked = true; + if (m_locked) return; + m_locked = true; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartEllipse* ell = static_cast(part); - QRectF rect = ell->property("rect").toRectF(); - QPointF point = ell->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); // does not matter which value y is, because only the x value is used - rect.setX(point.x()); // change only the x value + PartEllipse* ell = static_cast(part); + QRectF rect = ell->property("rect").toRectF(); + QPointF point = ell->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); // does not matter which value y is, because only the x value is used + rect.setX(point.x()); // change only the x value - if (rect != part->property("rect")) - { - QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + if (rect != part->property("rect")) + { + QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } - m_locked = false; + m_locked = false; } void EllipseEditor::editingFinishedY() { - if (m_locked) return; - m_locked = true; + if (m_locked) return; + m_locked = true; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartEllipse* ell = static_cast(part); - QRectF rect = ell->property("rect").toRectF(); + PartEllipse* ell = static_cast(part); + QRectF rect = ell->property("rect").toRectF(); - QPointF point = ell->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); - rect.setY(point.y()); + QPointF point = ell->mapFromScene(x->value() - h->value()/2, y->value() - v->value()/2); + rect.setY(point.y()); - if (rect != ell->property("rect")) - { - QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } + if (rect != ell->property("rect")) + { + QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } - } - - m_locked = false; + } + + m_locked = false; } void EllipseEditor::editingFinishedH() { - if (m_locked) return; - m_locked = true; + if (m_locked) return; + m_locked = true; - for (auto part: style_->currentParts()) { + for (auto part: style_->currentParts()) { - PartEllipse* ell = static_cast(part); - QRectF rect = ell->property("rect").toRectF(); + PartEllipse* ell = static_cast(part); + QRectF rect = ell->property("rect").toRectF(); - if (rect.width() != h->value()) - { - rect.setWidth(h->value()); - QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + if (rect.width() != h->value()) + { + rect.setWidth(h->value()); + QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } - m_locked = false; + m_locked = false; } void EllipseEditor::editingFinishedV() { - if (m_locked) return; - m_locked = true; + if (m_locked) return; + m_locked = true; + + for (auto part: style_->currentParts()) { + + PartEllipse* ell = static_cast(part); + QRectF rect = ell->property("rect").toRectF(); + + if (rect.height() != v->value()) + { + rect.setHeight(v->value()); + QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); + undo->setText("Modifier un arc"); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } - for (auto part: style_->currentParts()) { - - PartEllipse* ell = static_cast(part); - QRectF rect = ell->property("rect").toRectF(); - - if (rect.height() != v->value()) - { - rect.setHeight(v->value()); - QPropertyUndoCommand *undo= new QPropertyUndoCommand(ell, "rect", ell->property("rect"), rect); - undo->setText("Modifier un arc"); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - - m_locked = false; + m_locked = false; } /** @@ -255,16 +255,16 @@ void EllipseEditor::activeConnections(bool active) { if (active) { - connect(x, SIGNAL(editingFinished()), this, SLOT(editingFinishedX())); - connect(y, SIGNAL(editingFinished()), this, SLOT(editingFinishedY())); - connect(h, SIGNAL(editingFinished()), this, SLOT(editingFinishedH())); - connect(v, SIGNAL(editingFinished()), this, SLOT(editingFinishedV())); + connect(x, SIGNAL(editingFinished()), this, SLOT(editingFinishedX())); + connect(y, SIGNAL(editingFinished()), this, SLOT(editingFinishedY())); + connect(h, SIGNAL(editingFinished()), this, SLOT(editingFinishedH())); + connect(v, SIGNAL(editingFinished()), this, SLOT(editingFinishedV())); } else { - disconnect(x, SIGNAL(editingFinished()), this, SLOT(editingFinishedX())); - disconnect(y, SIGNAL(editingFinished()), this, SLOT(editingFinishedY())); - disconnect(h, SIGNAL(editingFinished()), this, SLOT(editingFinishedH())); - disconnect(v, SIGNAL(editingFinished()), this, SLOT(editingFinishedV())); + disconnect(x, SIGNAL(editingFinished()), this, SLOT(editingFinishedX())); + disconnect(y, SIGNAL(editingFinished()), this, SLOT(editingFinishedY())); + disconnect(h, SIGNAL(editingFinished()), this, SLOT(editingFinishedH())); + disconnect(v, SIGNAL(editingFinished()), this, SLOT(editingFinishedV())); } } diff --git a/sources/editor/ellipseeditor.h b/sources/editor/ellipseeditor.h index c42ffd029..735561631 100644 --- a/sources/editor/ellipseeditor.h +++ b/sources/editor/ellipseeditor.h @@ -44,29 +44,29 @@ class EllipseEditor : public ElementItemEditor StyleEditor *style_; QDoubleSpinBox *x, *y, *h, *v; bool m_locked; - QList m_change_connections; + QList m_change_connections; // methods public: bool setPart(CustomElementPart *) override; - bool setParts(QList parts) override; + bool setParts(QList parts) override; CustomElementPart *currentPart() const override; - QList currentParts() const override; + QList currentParts() const override; public slots: - void editingFinishedX(); - void editingFinishedY(); - void editingFinishedH(); - void editingFinishedV(); + void editingFinishedX(); + void editingFinishedY(); + void editingFinishedH(); + void editingFinishedV(); void updateForm() override; private: void activeConnections(bool); - /*! - * \brief setUpChangeConnections - * Setup the connection from the ellipse(s) to the widget, to update it when the ellipse(s) are changed (moved ...) - */ - void setUpChangeConnections(); - void disconnectChangeConnections(); + /*! + * \brief setUpChangeConnections + * Setup the connection from the ellipse(s) to the widget, to update it when the ellipse(s) are changed (moved ...) + */ + void setUpChangeConnections(); + void disconnectChangeConnections(); }; #endif diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index 5cc7b2616..4767337ca 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -265,11 +265,11 @@ void PartPolygon::setClosed(bool close) */ void PartPolygon::setHandlerColor(QPointF pos, const QColor &color) { - for (QetGraphicsHandlerItem *qghi : m_handler_vector) { - if (qghi->pos() == mapToScene(pos)) { - qghi->setColor(color); - } - } + for (QetGraphicsHandlerItem *qghi : m_handler_vector) { + if (qghi->pos() == mapToScene(pos)) { + qghi->setColor(color); + } + } } /** @@ -278,9 +278,9 @@ void PartPolygon::setHandlerColor(QPointF pos, const QColor &color) */ void PartPolygon::resetAllHandlerColor() { - for (QetGraphicsHandlerItem *qghi : m_handler_vector) { - qghi->setColor(Qt::blue); - } + for (QetGraphicsHandlerItem *qghi : m_handler_vector) { + qghi->setColor(Qt::blue); + } } /** diff --git a/sources/editor/lineeditor.cpp b/sources/editor/lineeditor.cpp index ca774feb8..bc9d9d18e 100644 --- a/sources/editor/lineeditor.cpp +++ b/sources/editor/lineeditor.cpp @@ -122,7 +122,7 @@ bool LineEditor::setPart(CustomElementPart *new_part) { if (part) { - disconnectChangeConnections(); + disconnectChangeConnections(); } part = nullptr; style_ -> setPart(nullptr); @@ -133,12 +133,12 @@ bool LineEditor::setPart(CustomElementPart *new_part) if (part == part_line) return true; if (part) { - disconnectChangeConnections(); + disconnectChangeConnections(); } part = part_line; style_ -> setPart(part); updateForm(); - setUpChangeConnections(); + setUpChangeConnections(); return(true); } return(false); @@ -146,12 +146,12 @@ bool LineEditor::setPart(CustomElementPart *new_part) bool LineEditor::setParts(QList parts) { - if (parts.isEmpty()) - return false; - - if (!setPart(parts.first())) - return false; - return style_->setParts(parts); + if (parts.isEmpty()) + return false; + + if (!setPart(parts.first())) + return false; + return style_->setParts(parts); } /** @@ -187,18 +187,18 @@ void LineEditor::updateLineEndType1() if (m_locked) return; m_locked = true; QVariant end = end1_type -> itemData(end1_type->currentIndex()); - - for (auto part: style_->currentParts()) { - - PartLine* line = static_cast(part); - - if (end != line->property("end1")) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "end1", line->property("end1"), end); - undo->setText(tr("Modifier une ligne")); - elementScene()->undoStack().push(undo); - } - } + + for (auto part: style_->currentParts()) { + + PartLine* line = static_cast(part); + + if (end != line->property("end1")) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "end1", line->property("end1"), end); + undo->setText(tr("Modifier une ligne")); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } @@ -208,19 +208,19 @@ void LineEditor::updateLineEndLength1() if (m_locked) return; m_locked = true; double length = end1_length->value(); - - for (auto part: style_->currentParts()) { - - PartLine* line = static_cast(part); - - if (length != line->property("length1")) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "length1", line->property("length1"), length); - undo->setText(tr("Modifier une ligne")); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + + for (auto part: style_->currentParts()) { + + PartLine* line = static_cast(part); + + if (length != line->property("length1")) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "length1", line->property("length1"), length); + undo->setText(tr("Modifier une ligne")); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } @@ -230,18 +230,18 @@ void LineEditor::updateLineEndType2() if (m_locked) return; m_locked = true; QVariant end = end2_type -> itemData(end2_type->currentIndex()); - - for (auto part: style_->currentParts()) { - - PartLine* line = static_cast(part); - - if (end != line->property("end2")) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "end2", line->property("end2"), end); - undo->setText(tr("Modifier une ligne")); - elementScene()->undoStack().push(undo); - } - } + + for (auto part: style_->currentParts()) { + + PartLine* line = static_cast(part); + + if (end != line->property("end2")) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "end2", line->property("end2"), end); + undo->setText(tr("Modifier une ligne")); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } @@ -251,19 +251,19 @@ void LineEditor::updateLineEndLength2() if (m_locked) return; m_locked = true; double length = end2_length->value(); - - for (auto part: style_->currentParts()) { - - PartLine* line = static_cast(part); - - if (length != line->property("length2")) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "length2", line->property("length2"), length); - undo->setText(tr("Modifier une ligne")); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + + for (auto part: style_->currentParts()) { + + PartLine* line = static_cast(part); + + if (length != line->property("length2")) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(line, "length2", line->property("length2"), length); + undo->setText(tr("Modifier une ligne")); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } @@ -271,100 +271,100 @@ void LineEditor::lineEditingFinishedX1() { if (m_locked) return; m_locked = true; - - for (auto part: style_->currentParts()) { - - PartLine* l = static_cast(part); - QLineF line = l->property("line").toLineF(); - - QPointF p1 = l->mapFromScene(x1->value(), y1->value()); - - if (p1.x() != line.p1().x()) - { - p1.setY(line.p1().y()); // restore old y value - line.setP1(p1); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); - undo->setText(tr("Modifier une ligne")); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } + + for (auto part: style_->currentParts()) { + + PartLine* l = static_cast(part); + QLineF line = l->property("line").toLineF(); + + QPointF p1 = l->mapFromScene(x1->value(), y1->value()); + + if (p1.x() != line.p1().x()) + { + p1.setY(line.p1().y()); // restore old y value + line.setP1(p1); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); + undo->setText(tr("Modifier une ligne")); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } m_locked = false; } void LineEditor::lineEditingFinishedY1() { - if (m_locked) return; - m_locked = true; - - for (auto part: style_->currentParts()) { - - PartLine* l = static_cast(part); - QLineF line = l->property("line").toLineF(); - - QPointF p1 = l->mapFromScene(x1->value(), y1->value()); - - if (p1.y() != line.p1().y()) - { - p1.setX(line.p1().x()); // restore old x value - line.setP1(p1); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); - undo->setText(tr("Modifier une ligne")); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - m_locked = false; + if (m_locked) return; + m_locked = true; + + for (auto part: style_->currentParts()) { + + PartLine* l = static_cast(part); + QLineF line = l->property("line").toLineF(); + + QPointF p1 = l->mapFromScene(x1->value(), y1->value()); + + if (p1.y() != line.p1().y()) + { + p1.setX(line.p1().x()); // restore old x value + line.setP1(p1); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); + undo->setText(tr("Modifier une ligne")); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } + m_locked = false; } void LineEditor::lineEditingFinishedX2() { - if (m_locked) return; - m_locked = true; - - for (auto part: style_->currentParts()) { - - PartLine* l = static_cast(part); - QLineF line = l->property("line").toLineF(); - - QPointF p2 = l->mapFromScene(x2->value(), y2->value()); - - if (p2.x() != line.p1().x()) - { - p2.setY(line.p2().y()); // restore old y value - line.setP2(p2); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); - undo->setText(tr("Modifier une ligne")); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - m_locked = false; + if (m_locked) return; + m_locked = true; + + for (auto part: style_->currentParts()) { + + PartLine* l = static_cast(part); + QLineF line = l->property("line").toLineF(); + + QPointF p2 = l->mapFromScene(x2->value(), y2->value()); + + if (p2.x() != line.p1().x()) + { + p2.setY(line.p2().y()); // restore old y value + line.setP2(p2); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); + undo->setText(tr("Modifier une ligne")); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } + m_locked = false; } void LineEditor::lineEditingFinishedY2() { - if (m_locked) return; - m_locked = true; - - for (auto part: style_->currentParts()) { - - PartLine* l = static_cast(part); - QLineF line = l->property("line").toLineF(); - - QPointF p2 = l->mapFromScene(x2->value(), y2->value()); - - if (p2.y() != line.p1().y()) - { - p2.setX(line.p2().x()); // restore old y value - line.setP2(p2); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); - undo->setText(tr("Modifier une ligne")); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - m_locked = false; + if (m_locked) return; + m_locked = true; + + for (auto part: style_->currentParts()) { + + PartLine* l = static_cast(part); + QLineF line = l->property("line").toLineF(); + + QPointF p2 = l->mapFromScene(x2->value(), y2->value()); + + if (p2.y() != line.p1().y()) + { + p2.setX(line.p2().x()); // restore old y value + line.setP2(p2); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(l, "line", l->property("line"), line); + undo->setText(tr("Modifier une ligne")); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } + m_locked = false; } /** @@ -398,10 +398,10 @@ void LineEditor::activeConnections(bool active) { if (active) { - connect(x1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX1())); - connect(y1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY1())); - connect(x2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX2())); - connect(y2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY2())); + connect(x1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX1())); + connect(y1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY1())); + connect(x2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX2())); + connect(y2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY2())); connect(end1_type, SIGNAL(currentIndexChanged(int)), this, SLOT(updateLineEndType1())); connect(end1_length, SIGNAL(editingFinished()), this, SLOT(updateLineEndLength1())); connect(end2_type, SIGNAL(currentIndexChanged(int)), this, SLOT(updateLineEndType2())); @@ -409,10 +409,10 @@ void LineEditor::activeConnections(bool active) } else { - disconnect(x1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX1())); - disconnect(y1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY1())); - disconnect(x2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX2())); - disconnect(y2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY2())); + disconnect(x1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX1())); + disconnect(y1, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY1())); + disconnect(x2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedX2())); + disconnect(y2, SIGNAL(editingFinished()), this, SLOT(lineEditingFinishedY2())); disconnect(end1_type, SIGNAL(currentIndexChanged(int)), this, SLOT(updateLineEndType1())); disconnect(end1_length, SIGNAL(editingFinished()), this, SLOT(updateLineEndLength1())); disconnect(end2_type, SIGNAL(currentIndexChanged(int)), this, SLOT(updateLineEndType2())); diff --git a/sources/editor/lineeditor.h b/sources/editor/lineeditor.h index 0863d6434..e04d01558 100644 --- a/sources/editor/lineeditor.h +++ b/sources/editor/lineeditor.h @@ -46,14 +46,14 @@ class LineEditor : public ElementItemEditor QComboBox *end1_type, *end2_type; QDoubleSpinBox*end1_length, *end2_length; bool m_locked; - QList m_change_connections; + QList m_change_connections; // methods public: bool setPart(CustomElementPart *) override; - bool setParts(QList parts) override; + bool setParts(QList parts) override; CustomElementPart *currentPart() const override; - QList currentParts() const override; + QList currentParts() const override; QPointF editedP1() const; QPointF editedP2() const; @@ -62,19 +62,19 @@ class LineEditor : public ElementItemEditor void updateLineEndLength1(); void updateLineEndType2(); void updateLineEndLength2(); - void lineEditingFinishedX1(); - void lineEditingFinishedY1(); - void lineEditingFinishedX2(); - void lineEditingFinishedY2(); + void lineEditingFinishedX1(); + void lineEditingFinishedY1(); + void lineEditingFinishedX2(); + void lineEditingFinishedY2(); void updateForm() override; - - private: + + private: void activeConnections(bool); - /*! - * \brief setUpChangeConnections - * Setup the connection from the line(s) to the widget, to update it when the line(s) are changed (moved ...) - */ - void setUpChangeConnections(); - void disconnectChangeConnections(); + /*! + * \brief setUpChangeConnections + * Setup the connection from the line(s) to the widget, to update it when the line(s) are changed (moved ...) + */ + void setUpChangeConnections(); + void disconnectChangeConnections(); }; #endif diff --git a/sources/editor/qetelementeditor.cpp b/sources/editor/qetelementeditor.cpp index c380a38a8..abdc9836a 100644 --- a/sources/editor/qetelementeditor.cpp +++ b/sources/editor/qetelementeditor.cpp @@ -610,119 +610,119 @@ void QETElementEditor::slot_setNoDragToView() { void QETElementEditor::slot_updateInformations() { QList selected_qgis = m_elmt_scene -> selectedItems(); - if (selected_qgis.isEmpty()) { - clearToolsDock(); - m_default_informations -> setText(tr("%n partie(s) sélectionnée(s).", - "", - selected_qgis.size())); - m_default_informations -> setAlignment(Qt::AlignHCenter | Qt::AlignTop); - m_tools_dock_stack -> setCurrentIndex(0); - return; - } - + if (selected_qgis.isEmpty()) { + clearToolsDock(); + m_default_informations -> setText(tr("%n partie(s) sélectionnée(s).", + "", + selected_qgis.size())); + m_default_informations -> setAlignment(Qt::AlignHCenter | Qt::AlignTop); + m_tools_dock_stack -> setCurrentIndex(0); + return; + } + QList cep_list; - - CustomElementPart* part = dynamic_cast(selected_qgis.first()); - QString selection_xml_name = part->xmlName(); - bool same_xml_name = true; - bool style_editable = true; - for (QGraphicsItem *qgi: selected_qgis) { - if (CustomElementPart *cep = dynamic_cast(qgi)) { - cep_list << cep; - if (cep->xmlName() != selection_xml_name) - same_xml_name = false; - } else { - style_editable = false; - same_xml_name = false; - } - } - if (style_editable) - style_editable = StyleEditor::isStyleEditable(cep_list); - - if (same_xml_name) { - if (selection_xml_name == "terminal" || - selection_xml_name == "text" || - selection_xml_name == "dynamic_text" || - selection_xml_name == "line" || - selection_xml_name == "rect" || - selection_xml_name == "ellipse" || - selection_xml_name == "arc") { - clearToolsDock(); - //We add the editor widget - ElementItemEditor *editor = static_cast(m_editors[selection_xml_name]); - - // TODO: Check if it takes longer than setting the parts again to the editor. - bool equal = true; - QList parts = editor->currentParts(); - if (parts.length() == cep_list.length()) { - for (auto cep: cep_list) { - bool part_found = false; - for (auto part: parts) { - if (part == cep) { - part_found = true; - break; - } - } - if (!part_found) { - equal = false; - break; - } - } - } else - equal = false; - - if (editor) - { - bool success = true; - if (equal == false) { - success = editor->setParts(cep_list); - } - if (success) - { - m_tools_dock_stack->insertWidget(1, editor); - m_tools_dock_stack -> setCurrentIndex(1); - } - else - { - qDebug() << "Editor refused part."; - } - } - return; - } else if (selection_xml_name == "polygon" && cep_list.length() == 1) { - // multi edit for polygons makes no sense - // TODO: maybe allowing multipart edit when number of points is the same? - //We add the editor widget - clearToolsDock(); - ElementItemEditor *editor = static_cast(m_editors[selection_xml_name]); - CustomElementPart* part = editor->currentPart(); - bool equal = part == cep_list.first(); - - if (editor) - { - bool success = true; - if (equal == false) { - success = editor->setPart(cep_list.first()); - } - if (success) - { - m_tools_dock_stack->insertWidget(1, editor); - m_tools_dock_stack -> setCurrentIndex(1); - } - else - { - qDebug() << "Editor refused part."; - } - } - return; - - } else { - qDebug() << "Multiedit not supported for: " << cep_list.first()->xmlName(); - } - - } - - //There's several parts selecteds and all can be edited by style editor. - if (style_editable) + + CustomElementPart* part = dynamic_cast(selected_qgis.first()); + QString selection_xml_name = part->xmlName(); + bool same_xml_name = true; + bool style_editable = true; + for (QGraphicsItem *qgi: selected_qgis) { + if (CustomElementPart *cep = dynamic_cast(qgi)) { + cep_list << cep; + if (cep->xmlName() != selection_xml_name) + same_xml_name = false; + } else { + style_editable = false; + same_xml_name = false; + } + } + if (style_editable) + style_editable = StyleEditor::isStyleEditable(cep_list); + + if (same_xml_name) { + if (selection_xml_name == "terminal" || + selection_xml_name == "text" || + selection_xml_name == "dynamic_text" || + selection_xml_name == "line" || + selection_xml_name == "rect" || + selection_xml_name == "ellipse" || + selection_xml_name == "arc") { + clearToolsDock(); + //We add the editor widget + ElementItemEditor *editor = static_cast(m_editors[selection_xml_name]); + + // TODO: Check if it takes longer than setting the parts again to the editor. + bool equal = true; + QList parts = editor->currentParts(); + if (parts.length() == cep_list.length()) { + for (auto cep: cep_list) { + bool part_found = false; + for (auto part: parts) { + if (part == cep) { + part_found = true; + break; + } + } + if (!part_found) { + equal = false; + break; + } + } + } else + equal = false; + + if (editor) + { + bool success = true; + if (equal == false) { + success = editor->setParts(cep_list); + } + if (success) + { + m_tools_dock_stack->insertWidget(1, editor); + m_tools_dock_stack -> setCurrentIndex(1); + } + else + { + qDebug() << "Editor refused part."; + } + } + return; + } else if (selection_xml_name == "polygon" && cep_list.length() == 1) { + // multi edit for polygons makes no sense + // TODO: maybe allowing multipart edit when number of points is the same? + //We add the editor widget + clearToolsDock(); + ElementItemEditor *editor = static_cast(m_editors[selection_xml_name]); + CustomElementPart* part = editor->currentPart(); + bool equal = part == cep_list.first(); + + if (editor) + { + bool success = true; + if (equal == false) { + success = editor->setPart(cep_list.first()); + } + if (success) + { + m_tools_dock_stack->insertWidget(1, editor); + m_tools_dock_stack -> setCurrentIndex(1); + } + else + { + qDebug() << "Editor refused part."; + } + } + return; + + } else { + qDebug() << "Multiedit not supported for: " << cep_list.first()->xmlName(); + } + + } + + //There's several parts selecteds and all can be edited by style editor. + if (style_editable) { clearToolsDock(); ElementItemEditor *selection_editor = m_editors["style"]; diff --git a/sources/editor/terminaleditor.cpp b/sources/editor/terminaleditor.cpp index 604829004..29bfd9ba4 100644 --- a/sources/editor/terminaleditor.cpp +++ b/sources/editor/terminaleditor.cpp @@ -98,22 +98,22 @@ TerminalEditor::~TerminalEditor() { */ bool TerminalEditor::setPart(CustomElementPart* new_part) { - m_terminals.clear(); + m_terminals.clear(); if (!new_part) { - if (m_part) - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - m_part = nullptr; + if (m_part) + disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); + m_part = nullptr; return(true); } - if (PartTerminal *part_terminal = static_cast(new_part)) + if (PartTerminal *part_terminal = static_cast(new_part)) { - if(m_part == part_terminal) return true; - if (m_part) - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - m_part = part_terminal; + if(m_part == part_terminal) return true; + if (m_part) + disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); + m_part = part_terminal; updateForm(); - connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); + connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); return(true); } return(false); @@ -121,44 +121,44 @@ bool TerminalEditor::setPart(CustomElementPart* new_part) bool TerminalEditor::setParts(QList parts) { - if (parts.isEmpty()) - { - m_terminals.clear(); - if (m_part) - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - m_part = nullptr; - return(true); - } - - if (PartTerminal *part_terminal = static_cast(parts.first())) - { - if (m_part) - disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - m_part = part_terminal; - m_terminals.clear(); - m_terminals.append(part_terminal); - for (int i=1; i < parts.length(); i++) - m_terminals.append(static_cast(parts[i])); - updateForm(); - connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); - return(true); - } - return(false); + if (parts.isEmpty()) + { + m_terminals.clear(); + if (m_part) + disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); + m_part = nullptr; + return(true); + } + + if (PartTerminal *part_terminal = static_cast(parts.first())) + { + if (m_part) + disconnect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); + m_part = part_terminal; + m_terminals.clear(); + m_terminals.append(part_terminal); + for (int i=1; i < parts.length(); i++) + m_terminals.append(static_cast(parts[i])); + updateForm(); + connect(m_part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm); + return(true); + } + return(false); } /** @return la primitive actuellement editee, ou 0 si ce widget n'en edite pas */ CustomElementPart *TerminalEditor::currentPart() const { - return(m_part); + return(m_part); } QList TerminalEditor::currentParts() const { - QList parts; - for (auto term: m_terminals) { - parts.append(static_cast(term)); - } - return parts; + QList parts; + for (auto term: m_terminals) { + parts.append(static_cast(term)); + } + return parts; } /// Met a jour l'orientation de la borne et cree un objet d'annulation @@ -167,53 +167,53 @@ void TerminalEditor::updateTerminalO() if (m_locked) return; m_locked = true; QVariant var(orientation -> itemData(orientation -> currentIndex())); - - for (int i=0; i < m_terminals.length(); i++) { - PartTerminal* term = m_terminals[i]; - if (var != term->property("orientation")) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "orientation", term->property("orientation"), var); - undo->setText(tr("Modifier l'orientation d'une borne")); - undoStack().push(undo); - } - } + + for (int i=0; i < m_terminals.length(); i++) { + PartTerminal* term = m_terminals[i]; + if (var != term->property("orientation")) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "orientation", term->property("orientation"), var); + undo->setText(tr("Modifier l'orientation d'une borne")); + undoStack().push(undo); + } + } m_locked = false; } void TerminalEditor::updateXPos() { - if (m_locked) return; - m_locked = true; - QPointF new_pos(qle_x->value(), 0); - - for (int i=0; i < m_terminals.length(); i++) { - PartTerminal* term = m_terminals[i]; - new_pos.setY(term->pos().y()); // change only x value - if (term->pos() != new_pos) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos); - undo->setText(tr("Déplacer une borne")); - undo->enableAnimation(); - undoStack().push(undo); - } - } - m_locked=false; + if (m_locked) return; + m_locked = true; + QPointF new_pos(qle_x->value(), 0); + + for (int i=0; i < m_terminals.length(); i++) { + PartTerminal* term = m_terminals[i]; + new_pos.setY(term->pos().y()); // change only x value + if (term->pos() != new_pos) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos); + undo->setText(tr("Déplacer une borne")); + undo->enableAnimation(); + undoStack().push(undo); + } + } + m_locked=false; } void TerminalEditor::updateYPos() { - if (m_locked) return; - m_locked = true; - QPointF new_pos(0, qle_y->value()); // change only y value - - for (int i=0; i < m_terminals.length(); i++) { - PartTerminal* term = m_terminals[i]; - new_pos.setX(term->pos().x()); - if (term->pos() != new_pos) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos); - undo->setText(tr("Déplacer une borne")); - undo->enableAnimation(); - undoStack().push(undo); - } - } - m_locked=false; + if (m_locked) return; + m_locked = true; + QPointF new_pos(0, qle_y->value()); // change only y value + + for (int i=0; i < m_terminals.length(); i++) { + PartTerminal* term = m_terminals[i]; + new_pos.setX(term->pos().x()); + if (term->pos() != new_pos) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(term, "pos", term->property("pos"), new_pos); + undo->setText(tr("Déplacer une borne")); + undo->enableAnimation(); + undoStack().push(undo); + } + } + m_locked=false; } /// update Number and name, create cancel object @@ -221,11 +221,11 @@ void TerminalEditor::updateYPos() { Met a jour le formulaire d'edition */ void TerminalEditor::updateForm() { - if (!m_part) return; + if (!m_part) return; activeConnections(false); - qle_x -> setValue(m_part->property("x").toReal()); - qle_y -> setValue(m_part->property("y").toReal()); - orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation"))); + qle_x -> setValue(m_part->property("x").toReal()); + qle_y -> setValue(m_part->property("y").toReal()); + orientation -> setCurrentIndex(orientation->findData(m_part->property("orientation"))); activeConnections(true); } @@ -237,14 +237,14 @@ void TerminalEditor::activeConnections(bool active) { if (active) { - connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos); - connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos); - connect(orientation, QOverload::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO); + connect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos); + connect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos); + connect(orientation, QOverload::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO); } else { - disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos); - disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos); - disconnect(orientation, QOverload::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO); + disconnect(qle_x, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateXPos); + disconnect(qle_y, &QDoubleSpinBox::editingFinished, this, &TerminalEditor::updateYPos); + disconnect(orientation, QOverload::of(&QComboBox::activated), this, &TerminalEditor::updateTerminalO); } } diff --git a/sources/editor/ui/dynamictextfieldeditor.cpp b/sources/editor/ui/dynamictextfieldeditor.cpp index 803292e22..b8ac75abe 100644 --- a/sources/editor/ui/dynamictextfieldeditor.cpp +++ b/sources/editor/ui/dynamictextfieldeditor.cpp @@ -58,7 +58,7 @@ DynamicTextFieldEditor::~DynamicTextFieldEditor() */ bool DynamicTextFieldEditor::setPart(CustomElementPart *part) { - disconnectConnections(); + disconnectConnections(); QGraphicsItem *qgi = part->toItem(); if(!qgi) @@ -69,40 +69,40 @@ bool DynamicTextFieldEditor::setPart(CustomElementPart *part) m_text_field = static_cast(qgi); updateForm(); - setUpConnections(); + setUpConnections(); return true; } bool DynamicTextFieldEditor::setParts(QList parts) { - if (parts.isEmpty()) - { - m_parts.clear(); - if (m_text_field) { - disconnectConnections(); - } - m_text_field = nullptr; - return true; - } - - if (PartDynamicTextField *part= static_cast(parts.first())) - { - if (m_text_field) { - disconnectConnections(); - } - - m_text_field = part; - m_parts.clear(); - m_parts.append(part); - for (int i=1; i < parts.length(); i++) - m_parts.append(static_cast(parts[i])); - - setUpConnections(); - - updateForm(); - return true; - } - return(false); + if (parts.isEmpty()) + { + m_parts.clear(); + if (m_text_field) { + disconnectConnections(); + } + m_text_field = nullptr; + return true; + } + + if (PartDynamicTextField *part= static_cast(parts.first())) + { + if (m_text_field) { + disconnectConnections(); + } + + m_text_field = part; + m_parts.clear(); + m_parts.append(part); + for (int i=1; i < parts.length(); i++) + m_parts.append(static_cast(parts[i])); + + setUpConnections(); + + updateForm(); + return true; + } + return(false); } /** @@ -115,11 +115,11 @@ CustomElementPart *DynamicTextFieldEditor::currentPart() const { } QList DynamicTextFieldEditor::currentParts() const { - QList parts; - for (auto part: m_parts) { - parts.append(static_cast(part)); - } - return parts; + QList parts; + for (auto part: m_parts) { + parts.append(static_cast(part)); + } + return parts; } void DynamicTextFieldEditor::updateForm() @@ -156,26 +156,26 @@ void DynamicTextFieldEditor::updateForm() } void DynamicTextFieldEditor::setUpConnections() { - assert(m_connection_list.isEmpty()); - //Setup the connection - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::frameChanged, [this](){this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textWidthChanged,[this]() {this->updateForm();}); - m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();}); + assert(m_connection_list.isEmpty()); + //Setup the connection + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::frameChanged, [this](){this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textWidthChanged,[this]() {this->updateForm();}); + m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();}); } void DynamicTextFieldEditor::disconnectConnections() { - //Remove previous connection - if(!m_connection_list.isEmpty()) - for(const QMetaObject::Connection& con : m_connection_list) - disconnect(con); - m_connection_list.clear(); + //Remove previous connection + if(!m_connection_list.isEmpty()) + for(const QMetaObject::Connection& con : m_connection_list) + disconnect(con); + m_connection_list.clear(); } /** @@ -206,101 +206,101 @@ void DynamicTextFieldEditor::fillInfoComboBox() void DynamicTextFieldEditor::on_m_x_sb_editingFinished() { - double value = ui->m_x_sb->value(); - for (int i = 0; i < m_parts.length(); i++) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "x", m_parts[i]->x(), value); - undo->setText(tr("Déplacer un champ texte")); - undo->enableAnimation(true); - undoStack().push(undo); - } + double value = ui->m_x_sb->value(); + for (int i = 0; i < m_parts.length(); i++) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "x", m_parts[i]->x(), value); + undo->setText(tr("Déplacer un champ texte")); + undo->enableAnimation(true); + undoStack().push(undo); + } } void DynamicTextFieldEditor::on_m_y_sb_editingFinished() { - double value = ui->m_y_sb->value(); - for (int i = 0; i < m_parts.length(); i++) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "y", m_parts[i]->y(), value); - undo->setText(tr("Déplacer un champ texte")); - undo->enableAnimation(true); - undoStack().push(undo); - } + double value = ui->m_y_sb->value(); + for (int i = 0; i < m_parts.length(); i++) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "y", m_parts[i]->y(), value); + undo->setText(tr("Déplacer un champ texte")); + undo->enableAnimation(true); + undoStack().push(undo); + } } void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished() { - int value = ui->m_rotation_sb->value(); - for (int i = 0; i < m_parts.length(); i++) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "rotation", m_parts[i]->rotation(), value); - undo->setText(tr("Pivoter un champ texte")); - undo->enableAnimation(true); - undoStack().push(undo); - } + int value = ui->m_rotation_sb->value(); + for (int i = 0; i < m_parts.length(); i++) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "rotation", m_parts[i]->rotation(), value); + undo->setText(tr("Pivoter un champ texte")); + undo->enableAnimation(true); + undoStack().push(undo); + } } void DynamicTextFieldEditor::on_m_user_text_le_editingFinished() { - QString text = ui->m_user_text_le->text(); - for (int i = 0; i < m_parts.length(); i++) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "text", m_parts[i]->text(), text); - undo->setText(tr("Modifier le texte d'un champ texte")); - undoStack().push(undo); - } + QString text = ui->m_user_text_le->text(); + for (int i = 0; i < m_parts.length(); i++) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "text", m_parts[i]->text(), text); + undo->setText(tr("Modifier le texte d'un champ texte")); + undoStack().push(undo); + } } void DynamicTextFieldEditor::on_m_size_sb_editingFinished() { QFont font_ = m_text_field->font(); font_.setPointSize(ui->m_size_sb->value()); - for (int i = 0; i < m_parts.length(); i++) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_); - undo->setText(tr("Modifier la police d'un champ texte")); - undoStack().push(undo); - } + for (int i = 0; i < m_parts.length(); i++) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_); + undo->setText(tr("Modifier la police d'un champ texte")); + undoStack().push(undo); + } } void DynamicTextFieldEditor::on_m_frame_cb_clicked() { - bool frame = ui->m_frame_cb->isChecked(); + bool frame = ui->m_frame_cb->isChecked(); - for (int i = 0; i < m_parts.length(); i++) { - if(frame != m_parts[i]->frame()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "frame", m_parts[i]->frame(), frame); - undo->setText(tr("Modifier le cadre d'un champ texte")); - undoStack().push(undo); - } - } + for (int i = 0; i < m_parts.length(); i++) { + if(frame != m_parts[i]->frame()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "frame", m_parts[i]->frame(), frame); + undo->setText(tr("Modifier le cadre d'un champ texte")); + undoStack().push(undo); + } + } } void DynamicTextFieldEditor::on_m_width_sb_editingFinished() { - qreal width = (qreal)ui->m_width_sb->value(); + qreal width = (qreal)ui->m_width_sb->value(); - for (int i = 0; i < m_parts.length(); i++) { - if(width != m_parts[i]->textWidth()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textWidth", m_parts[i]->textWidth(), width); - undo->setText(tr("Modifier la largeur d'un texte")); - undoStack().push(undo); - } - } + for (int i = 0; i < m_parts.length(); i++) { + if(width != m_parts[i]->textWidth()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textWidth", m_parts[i]->textWidth(), width); + undo->setText(tr("Modifier la largeur d'un texte")); + undoStack().push(undo); + } + } } void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1) { - Q_UNUSED(arg1) + Q_UNUSED(arg1) QString info = ui->m_elmt_info_cb->currentData().toString(); - for (int i = 0; i < m_parts.length(); i++) { - if(info != m_parts[i]->infoName()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "infoName", m_parts[i]->infoName(), info); - undo->setText(tr("Modifier l'information d'un texte")); - undoStack().push(undo); - - m_parts[i]->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_parts[i]->infoName()).toString()); - } - } + for (int i = 0; i < m_parts.length(); i++) { + if(info != m_parts[i]->infoName()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "infoName", m_parts[i]->infoName(), info); + undo->setText(tr("Modifier l'information d'un texte")); + undoStack().push(undo); + + m_parts[i]->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_parts[i]->infoName()).toString()); + } + } } void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index) @@ -308,7 +308,7 @@ void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index) ui->m_user_text_le->setDisabled(true); ui->m_elmt_info_cb->setDisabled(true); ui->m_composite_text_pb->setDisabled(true); - + if(index == 0) ui->m_user_text_le->setEnabled(true); else if (index == 1) @@ -321,14 +321,14 @@ void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index) else if(index == 1) tf = DynamicElementTextItem::ElementInfo; else tf = DynamicElementTextItem::CompositeText; - for (int i = 0; i < m_parts.length(); i++) { - if(tf != m_parts[i]->textFrom()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textFrom", m_parts[i]->textFrom(), tf); - undo->setText(tr("Modifier la source de texte, d'un texte")); - undoStack().push(undo); - } - } + for (int i = 0; i < m_parts.length(); i++) { + if(tf != m_parts[i]->textFrom()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textFrom", m_parts[i]->textFrom(), tf); + undo->setText(tr("Modifier la source de texte, d'un texte")); + undoStack().push(undo); + } + } } void DynamicTextFieldEditor::on_m_composite_text_pb_clicked() @@ -337,29 +337,29 @@ void DynamicTextFieldEditor::on_m_composite_text_pb_clicked() if(ctd.exec()) { QString ct = ctd.plainText(); - for (int i = 0; i < m_parts.length(); i++) { - if(ct != m_parts[i]->compositeText()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "compositeText", m_parts[i]->compositeText(), ctd.plainText()); - undoStack().push(undo); - } - } + for (int i = 0; i < m_parts.length(); i++) { + if(ct != m_parts[i]->compositeText()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "compositeText", m_parts[i]->compositeText(), ctd.plainText()); + undoStack().push(undo); + } + } } } void DynamicTextFieldEditor::on_m_alignment_pb_clicked() { - AlignmentTextDialog atd(m_text_field.data()->alignment(), this); + AlignmentTextDialog atd(m_text_field.data()->alignment(), this); atd.exec(); - - for (int i = 0; i < m_parts.length(); i++) { - if(atd.alignment() != m_parts[i]->alignment()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "alignment", QVariant(m_parts[i]->alignment()), QVariant(atd.alignment())); - undo->setText(tr("Modifier l'alignement d'un champ texte")); - undoStack().push(undo); - } - } + + for (int i = 0; i < m_parts.length(); i++) { + if(atd.alignment() != m_parts[i]->alignment()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "alignment", QVariant(m_parts[i]->alignment()), QVariant(atd.alignment())); + undo->setText(tr("Modifier l'alignement d'un champ texte")); + undoStack().push(undo); + } + } } void DynamicTextFieldEditor::on_m_font_pb_clicked() @@ -370,26 +370,26 @@ void DynamicTextFieldEditor::on_m_font_pb_clicked() { ui->m_font_pb->setText(font_.family()); ui->m_size_sb->setValue(font_.pointSize()); - - for (int i = 0; i < m_parts.length(); i++) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_); - undo->setText(tr("Modifier la police d'un champ texte")); - undoStack().push(undo); - } + + for (int i = 0; i < m_parts.length(); i++) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_); + undo->setText(tr("Modifier la police d'un champ texte")); + undoStack().push(undo); + } } } void DynamicTextFieldEditor::on_m_color_kpb_changed(const QColor &newColor) { - if (!newColor.isValid()) - return; - - for (int i = 0; i < m_parts.length(); i++) { - if(newColor != m_parts[i]->color()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "color", m_parts[i]->color(), newColor); - undo->setText(tr("Modifier la couleur d'un champ texte")); - undoStack().push(undo); - } - } + if (!newColor.isValid()) + return; + + for (int i = 0; i < m_parts.length(); i++) { + if(newColor != m_parts[i]->color()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "color", m_parts[i]->color(), newColor); + undo->setText(tr("Modifier la couleur d'un champ texte")); + undoStack().push(undo); + } + } } diff --git a/sources/editor/ui/polygoneditor.cpp b/sources/editor/ui/polygoneditor.cpp index b3baf2051..7cdc50878 100644 --- a/sources/editor/ui/polygoneditor.cpp +++ b/sources/editor/ui/polygoneditor.cpp @@ -73,30 +73,30 @@ void PolygonEditor::disconnectChangeConnections() */ bool PolygonEditor::setPart(CustomElementPart *new_part) { - if (!new_part) - { - if (m_part) - { - disconnectChangeConnections(); - } - m_part = nullptr; - m_style -> setPart(nullptr); - return(true); - } - if (PartPolygon *part_polygon = dynamic_cast(new_part)) - { - if (m_part == part_polygon) return true; - if (m_part) - { - disconnectChangeConnections(); - } - m_part = part_polygon; - m_style -> setPart(m_part); - updateForm(); - setUpChangeConnections(); - return(true); - } - return(false); + if (!new_part) + { + if (m_part) + { + disconnectChangeConnections(); + } + m_part = nullptr; + m_style -> setPart(nullptr); + return(true); + } + if (PartPolygon *part_polygon = dynamic_cast(new_part)) + { + if (m_part == part_polygon) return true; + if (m_part) + { + disconnectChangeConnections(); + } + m_part = part_polygon; + m_style -> setPart(m_part); + updateForm(); + setUpChangeConnections(); + return(true); + } + return(false); } /** @@ -143,35 +143,35 @@ void PolygonEditor::updateForm() */ QVector PolygonEditor::pointsFromTree() { - QVector points; - if (!m_part) { - return points; - } - - for(int i = 0 ; i < ui->m_points_list_tree->topLevelItemCount() ; ++ i) - { - QTreeWidgetItem *qtwi = ui->m_points_list_tree->topLevelItem(i); - bool x_convert_ok, y_convert_ok; - qreal x = qtwi->data(0, Qt::EditRole).toReal(&x_convert_ok); - qreal y = qtwi->data(1, Qt::EditRole).toReal(&y_convert_ok); - if (x_convert_ok && y_convert_ok) { - points << m_part->mapFromScene(QPointF(x, y)); - } - } - return(points); + QVector points; + if (!m_part) { + return points; + } + + for(int i = 0 ; i < ui->m_points_list_tree->topLevelItemCount() ; ++ i) + { + QTreeWidgetItem *qtwi = ui->m_points_list_tree->topLevelItem(i); + bool x_convert_ok, y_convert_ok; + qreal x = qtwi->data(0, Qt::EditRole).toReal(&x_convert_ok); + qreal y = qtwi->data(1, Qt::EditRole).toReal(&y_convert_ok); + if (x_convert_ok && y_convert_ok) { + points << m_part->mapFromScene(QPointF(x, y)); + } + } + return(points); } bool PolygonEditor::eventFilter(QObject *watched, QEvent *event) { - if (watched == ui->m_points_list_tree && - event->type() == QEvent::FocusOut && - m_part) - { - m_part->resetAllHandlerColor(); - return true; - } - - return false; + if (watched == ui->m_points_list_tree && + event->type() == QEvent::FocusOut && + m_part) + { + m_part->resetAllHandlerColor(); + return true; + } + + return false; } /** @@ -179,18 +179,18 @@ bool PolygonEditor::eventFilter(QObject *watched, QEvent *event) */ void PolygonEditor::on_m_close_polygon_cb_stateChanged(int arg1) { - Q_UNUSED(arg1); - - if (!m_part) { - return; - } - bool close = ui->m_close_polygon_cb->isChecked(); - if (close != m_part->isClosed()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_part, "closed", m_part->property("closed"), close); - undo->setText(tr("Modifier un polygone")); - undoStack().push(undo); - } + Q_UNUSED(arg1); + + if (!m_part) { + return; + } + bool close = ui->m_close_polygon_cb->isChecked(); + if (close != m_part->isClosed()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_part, "closed", m_part->property("closed"), close); + undo->setText(tr("Modifier un polygone")); + undoStack().push(undo); + } } /** @@ -199,26 +199,26 @@ void PolygonEditor::on_m_close_polygon_cb_stateChanged(int arg1) */ void PolygonEditor::on_m_points_list_tree_itemChanged(QTreeWidgetItem *item, int column) { - Q_UNUSED(item); - Q_UNUSED(column); - - if (!m_part) { - return; - } - - QPolygonF points = pointsFromTree(); - if (points.count() < 2) - { - QET::QetMessageBox::warning(this, tr("Erreur", "message box title"), tr("Le polygone doit comporter au moins deux points.", "message box content")); - return; - } - - if (points != m_part->polygon()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_part, "polygon", m_part->property("polygon"), points); - undo->setText(tr("Modifier un polygone")); - undoStack().push(undo); - } + Q_UNUSED(item); + Q_UNUSED(column); + + if (!m_part) { + return; + } + + QPolygonF points = pointsFromTree(); + if (points.count() < 2) + { + QET::QetMessageBox::warning(this, tr("Erreur", "message box title"), tr("Le polygone doit comporter au moins deux points.", "message box content")); + return; + } + + if (points != m_part->polygon()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_part, "polygon", m_part->property("polygon"), points); + undo->setText(tr("Modifier un polygone")); + undoStack().push(undo); + } } /** @@ -227,76 +227,76 @@ void PolygonEditor::on_m_points_list_tree_itemChanged(QTreeWidgetItem *item, int */ void PolygonEditor::on_m_points_list_tree_itemSelectionChanged() { - //Prevent when selection change but the widget ins't focused - if (!ui->m_points_list_tree->hasFocus()) { - return; - } - - QTreeWidgetItem *qtwi = ui->m_points_list_tree->currentItem(); - if (!qtwi || !m_part) { - return; - } - - m_part->resetAllHandlerColor(); - int index = ui->m_points_list_tree->indexOfTopLevelItem(qtwi); - - //We need to check if index isn't out of range of polygon - //this case can occur when user remove the last point of the polygon - //with the context menu of the tree widget - if(index >= 0 && - index < m_part->polygon().size()) - { - m_part->setHandlerColor(m_part->polygon().at(index), QColor(0, 255, 128)); - } + //Prevent when selection change but the widget ins't focused + if (!ui->m_points_list_tree->hasFocus()) { + return; + } + + QTreeWidgetItem *qtwi = ui->m_points_list_tree->currentItem(); + if (!qtwi || !m_part) { + return; + } + + m_part->resetAllHandlerColor(); + int index = ui->m_points_list_tree->indexOfTopLevelItem(qtwi); + + //We need to check if index isn't out of range of polygon + //this case can occur when user remove the last point of the polygon + //with the context menu of the tree widget + if(index >= 0 && + index < m_part->polygon().size()) + { + m_part->setHandlerColor(m_part->polygon().at(index), QColor(0, 255, 128)); + } } void PolygonEditor::on_m_add_point_action_triggered() { - QTreeWidgetItem *qtwi = ui->m_points_list_tree->currentItem(); - if (!qtwi || !m_part) { - return; - } - - int index = ui->m_points_list_tree->indexOfTopLevelItem(qtwi); - QPolygonF new_polygon = m_part->polygon(); - - //Special case when user add a point after the last point of the polygon - if (index == m_part->polygon().size()-1) - { - QPointF p = m_part->polygon().last(); - p.rx()+=20; - p.ry()+=20; - new_polygon.append(p); - } - else - { - QPointF p = m_part->polygon().at(index) + - m_part->polygon().at(index+1); - p/=2; - new_polygon.insert(index+1, p); - } - - //Wrap the undo for avoid to merge the undo commands when user add several points. - QUndoCommand *undo = new QUndoCommand(tr("Ajouter un point à un polygone")); - new QPropertyUndoCommand(m_part, "polygon", m_part->polygon(), new_polygon, undo); - elementScene()->undoStack().push(undo); - - m_part->resetAllHandlerColor(); - m_part->setHandlerColor(m_part->polygon().at(index+1), QColor(0, 255, 128)); + QTreeWidgetItem *qtwi = ui->m_points_list_tree->currentItem(); + if (!qtwi || !m_part) { + return; + } + + int index = ui->m_points_list_tree->indexOfTopLevelItem(qtwi); + QPolygonF new_polygon = m_part->polygon(); + + //Special case when user add a point after the last point of the polygon + if (index == m_part->polygon().size()-1) + { + QPointF p = m_part->polygon().last(); + p.rx()+=20; + p.ry()+=20; + new_polygon.append(p); + } + else + { + QPointF p = m_part->polygon().at(index) + + m_part->polygon().at(index+1); + p/=2; + new_polygon.insert(index+1, p); + } + + //Wrap the undo for avoid to merge the undo commands when user add several points. + QUndoCommand *undo = new QUndoCommand(tr("Ajouter un point à un polygone")); + new QPropertyUndoCommand(m_part, "polygon", m_part->polygon(), new_polygon, undo); + elementScene()->undoStack().push(undo); + + m_part->resetAllHandlerColor(); + m_part->setHandlerColor(m_part->polygon().at(index+1), QColor(0, 255, 128)); } void PolygonEditor::on_m_remove_point_action_triggered() { - QTreeWidgetItem *qtwi = ui->m_points_list_tree->currentItem(); - if (!qtwi || !m_part) { - return; - } - - QPolygonF new_polygon = m_part->polygon(); - new_polygon.removeAt(ui->m_points_list_tree->indexOfTopLevelItem(qtwi)); - - //Wrap the undo for avoid to merge the undo commands when user remove several points. - QUndoCommand *undo = new QUndoCommand(tr("Supprimer un point d'un polygone")); - new QPropertyUndoCommand(m_part, "polygon", m_part->polygon(), new_polygon, undo); - elementScene()->undoStack().push(undo); + QTreeWidgetItem *qtwi = ui->m_points_list_tree->currentItem(); + if (!qtwi || !m_part) { + return; + } + + QPolygonF new_polygon = m_part->polygon(); + new_polygon.removeAt(ui->m_points_list_tree->indexOfTopLevelItem(qtwi)); + + //Wrap the undo for avoid to merge the undo commands when user remove several points. + QUndoCommand *undo = new QUndoCommand(tr("Supprimer un point d'un polygone")); + new QPropertyUndoCommand(m_part, "polygon", m_part->polygon(), new_polygon, undo); + elementScene()->undoStack().push(undo); } diff --git a/sources/editor/ui/polygoneditor.h b/sources/editor/ui/polygoneditor.h index edb5ffae1..41ebb85f8 100644 --- a/sources/editor/ui/polygoneditor.h +++ b/sources/editor/ui/polygoneditor.h @@ -30,39 +30,39 @@ namespace Ui { class PolygonEditor : public ElementItemEditor { - Q_OBJECT - - public: - explicit PolygonEditor(QETElementEditor *editor, PartPolygon *part = nullptr, QWidget *parent = nullptr); - ~PolygonEditor() override; - - bool setPart(CustomElementPart *part) override; - CustomElementPart *currentPart() const override; - QList currentParts() const override; - void updateForm() override; - QVector pointsFromTree(); - bool eventFilter(QObject *watched, QEvent *event) override; - - private slots: - void on_m_close_polygon_cb_stateChanged(int arg1); - void on_m_points_list_tree_itemChanged(QTreeWidgetItem *item, int column); - void on_m_points_list_tree_itemSelectionChanged(); - void on_m_add_point_action_triggered(); - void on_m_remove_point_action_triggered(); - -private: - /*! - * \brief setUpChangeConnections - * Setup the connection from the line(s) to the widget, to update it when the line(s) are changed (moved ...) - */ - void setUpChangeConnections(); - void disconnectChangeConnections(); - -private: - Ui::PolygonEditor *ui; - StyleEditor *m_style = nullptr; - PartPolygon *m_part = nullptr; - QList m_change_connections; + Q_OBJECT + + public: + explicit PolygonEditor(QETElementEditor *editor, PartPolygon *part = nullptr, QWidget *parent = nullptr); + ~PolygonEditor() override; + + bool setPart(CustomElementPart *part) override; + CustomElementPart *currentPart() const override; + QList currentParts() const override; + void updateForm() override; + QVector pointsFromTree(); + bool eventFilter(QObject *watched, QEvent *event) override; + + private slots: + void on_m_close_polygon_cb_stateChanged(int arg1); + void on_m_points_list_tree_itemChanged(QTreeWidgetItem *item, int column); + void on_m_points_list_tree_itemSelectionChanged(); + void on_m_add_point_action_triggered(); + void on_m_remove_point_action_triggered(); + + private: + /*! + * \brief setUpChangeConnections + * Setup the connection from the line(s) to the widget, to update it when the line(s) are changed (moved ...) + */ + void setUpChangeConnections(); + void disconnectChangeConnections(); + + private: + Ui::PolygonEditor *ui; + StyleEditor *m_style = nullptr; + PartPolygon *m_part = nullptr; + QList m_change_connections; }; #endif // POLYGONEDITOR_H diff --git a/sources/editor/ui/rectangleeditor.cpp b/sources/editor/ui/rectangleeditor.cpp index 4628a2626..050a1663b 100644 --- a/sources/editor/ui/rectangleeditor.cpp +++ b/sources/editor/ui/rectangleeditor.cpp @@ -48,19 +48,19 @@ RectangleEditor::~RectangleEditor() { void RectangleEditor::setUpChangeConnections() { - m_change_connections << connect(m_part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm); - m_change_connections << connect(m_part, &PartRectangle::XRadiusChanged, this, &RectangleEditor::updateForm); - m_change_connections << connect(m_part, &PartRectangle::YRadiusChanged, this, &RectangleEditor::updateForm); - m_change_connections << connect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm); - m_change_connections << connect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm); + m_change_connections << connect(m_part, &PartRectangle::rectChanged, this, &RectangleEditor::updateForm); + m_change_connections << connect(m_part, &PartRectangle::XRadiusChanged, this, &RectangleEditor::updateForm); + m_change_connections << connect(m_part, &PartRectangle::YRadiusChanged, this, &RectangleEditor::updateForm); + m_change_connections << connect(m_part, &PartRectangle::xChanged, this, &RectangleEditor::updateForm); + m_change_connections << connect(m_part, &PartRectangle::yChanged, this, &RectangleEditor::updateForm); } void RectangleEditor::disconnectChangeConnections() { - for (QMetaObject::Connection c : m_change_connections) { - disconnect(c); - } - m_change_connections.clear(); + for (QMetaObject::Connection c : m_change_connections) { + disconnect(c); + } + m_change_connections.clear(); } /** @@ -74,13 +74,13 @@ bool RectangleEditor::setPart(CustomElementPart *part) { if (m_part) { - disconnectChangeConnections(); + disconnectChangeConnections(); } m_part = nullptr; m_style->setPart(nullptr); return(true); } - + if (PartRectangle *part_rectangle = dynamic_cast(part)) { if (m_part == part_rectangle) { @@ -88,26 +88,26 @@ bool RectangleEditor::setPart(CustomElementPart *part) } if (m_part) { - disconnectChangeConnections(); + disconnectChangeConnections(); } m_part = part_rectangle; m_style->setPart(m_part); updateForm(); - setUpChangeConnections(); + setUpChangeConnections(); return(true); } - + return(false); } bool RectangleEditor::setParts(QList parts) { - if (parts.isEmpty()) - return false; - - if (!setPart(parts.first())) - return false; - return m_style->setParts(parts); + if (parts.isEmpty()) + return false; + + if (!setPart(parts.first())) + return false; + return m_style->setParts(parts); } /** @@ -119,7 +119,7 @@ CustomElementPart *RectangleEditor::currentPart() const { } QList RectangleEditor::currentParts() const { - return m_style->currentParts(); + return m_style->currentParts(); } /** @@ -165,7 +165,7 @@ void RectangleEditor::editingFinished() return; } m_locked = true; - + QUndoCommand *undo = new QUndoCommand(); undo->setText(tr("Modifier un rectangle")); @@ -186,158 +186,158 @@ void RectangleEditor::editingFinished() u->setAnimated(); } elementScene()->undoStack().push(undo); - + m_locked = false; } void RectangleEditor::xPosChanged() { - if (m_locked) { - return; - } - m_locked = true; - - for (auto part: m_style->currentParts()) { - - PartRectangle* rec = static_cast(part); - - QRectF rect = rec->rect(); - - QPointF p = rec->mapFromScene(ui->m_x_sb->value(), ui->m_y_sb->value()); - - if (rect.x() != p.x()) { - rect.moveLeft(p.x()); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - - m_locked = false; + if (m_locked) { + return; + } + m_locked = true; + + for (auto part: m_style->currentParts()) { + + PartRectangle* rec = static_cast(part); + + QRectF rect = rec->rect(); + + QPointF p = rec->mapFromScene(ui->m_x_sb->value(), ui->m_y_sb->value()); + + if (rect.x() != p.x()) { + rect.moveLeft(p.x()); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } + + m_locked = false; } void RectangleEditor::yPosChanged() { - if (m_locked) { - return; - } - m_locked = true; - - for (auto part: m_style->currentParts()) { - - PartRectangle* rec = static_cast(part); - - QRectF rect = rec->rect(); - - QPointF p = rec->mapFromScene(ui->m_x_sb->value(), ui->m_y_sb->value()); - - if (rect.y() != p.y()) { - rect.moveTop(p.y()); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - - m_locked = false; + if (m_locked) { + return; + } + m_locked = true; + + for (auto part: m_style->currentParts()) { + + PartRectangle* rec = static_cast(part); + + QRectF rect = rec->rect(); + + QPointF p = rec->mapFromScene(ui->m_x_sb->value(), ui->m_y_sb->value()); + + if (rect.y() != p.y()) { + rect.moveTop(p.y()); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } + + m_locked = false; } void RectangleEditor::widthChanged() { - if (m_locked) { - return; - } - m_locked = true; - - double width = ui->m_width_sb->value(); - - for (auto part: m_style->currentParts()) { - - PartRectangle* rec = static_cast(part); - - QRectF rect = rec->rect(); - - if (rect.width() != width) { - rect.setWidth(width); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - - m_locked = false; + if (m_locked) { + return; + } + m_locked = true; + + double width = ui->m_width_sb->value(); + + for (auto part: m_style->currentParts()) { + + PartRectangle* rec = static_cast(part); + + QRectF rect = rec->rect(); + + if (rect.width() != width) { + rect.setWidth(width); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } + + m_locked = false; } void RectangleEditor::heightChanged() { - if (m_locked) { - return; - } - m_locked = true; - - double height = ui->m_height_sb->value(); - - for (auto part: m_style->currentParts()) { - - PartRectangle* rec = static_cast(part); - - QRectF rect = rec->rect(); - - if (rect.height() != height) { - rect.setHeight(height); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); - undo->enableAnimation(); - elementScene()->undoStack().push(undo); - } - } - - m_locked = false; + if (m_locked) { + return; + } + m_locked = true; + + double height = ui->m_height_sb->value(); + + for (auto part: m_style->currentParts()) { + + PartRectangle* rec = static_cast(part); + + QRectF rect = rec->rect(); + + if (rect.height() != height) { + rect.setHeight(height); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "rect", rec->rect(), rect); + undo->enableAnimation(); + elementScene()->undoStack().push(undo); + } + } + + m_locked = false; } void RectangleEditor::xRadiusChanged() { - if (m_locked) { - return; - } - m_locked = true; - - double radius = ui->m_rx_sb->value(); - - for (auto part: m_style->currentParts()) { - - PartRectangle* rec = static_cast(part); - - if (rec->XRadius() != radius) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "xRadius", rec->XRadius(), radius); - undo->setAnimated(); - elementScene()->undoStack().push(undo); - } - } - - m_locked = false; + if (m_locked) { + return; + } + m_locked = true; + + double radius = ui->m_rx_sb->value(); + + for (auto part: m_style->currentParts()) { + + PartRectangle* rec = static_cast(part); + + if (rec->XRadius() != radius) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "xRadius", rec->XRadius(), radius); + undo->setAnimated(); + elementScene()->undoStack().push(undo); + } + } + + m_locked = false; } void RectangleEditor::yRadiusChanged() { - if (m_locked) { - return; - } - m_locked = true; - - double radius = ui->m_ry_sb->value(); - - for (auto part: m_style->currentParts()) { - - PartRectangle* rec = static_cast(part); - - if (rec->YRadius() != radius) { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "yRadius", rec->YRadius(), radius); - undo->setAnimated(); - elementScene()->undoStack().push(undo); - } - } - - m_locked = false; + if (m_locked) { + return; + } + m_locked = true; + + double radius = ui->m_ry_sb->value(); + + for (auto part: m_style->currentParts()) { + + PartRectangle* rec = static_cast(part); + + if (rec->YRadius() != radius) { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(rec, "yRadius", rec->YRadius(), radius); + undo->setAnimated(); + elementScene()->undoStack().push(undo); + } + } + + m_locked = false; } @@ -351,20 +351,20 @@ void RectangleEditor::activeConnections(bool active) { if (active) { - connect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xPosChanged); - connect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yPosChanged); - connect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::widthChanged); - connect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::heightChanged); - connect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xRadiusChanged); - connect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yRadiusChanged); + connect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xPosChanged); + connect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yPosChanged); + connect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::widthChanged); + connect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::heightChanged); + connect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xRadiusChanged); + connect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yRadiusChanged); } else { - disconnect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xPosChanged); - disconnect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yPosChanged); - disconnect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::widthChanged); - disconnect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::heightChanged); - disconnect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xRadiusChanged); - disconnect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yRadiusChanged); + disconnect(ui->m_x_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xPosChanged); + disconnect(ui->m_y_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yPosChanged); + disconnect(ui->m_width_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::widthChanged); + disconnect(ui->m_height_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::heightChanged); + disconnect(ui->m_rx_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::xRadiusChanged); + disconnect(ui->m_ry_sb, &QDoubleSpinBox::editingFinished, this, &RectangleEditor::yRadiusChanged); } } diff --git a/sources/editor/ui/rectangleeditor.h b/sources/editor/ui/rectangleeditor.h index 6e056c762..09e606897 100644 --- a/sources/editor/ui/rectangleeditor.h +++ b/sources/editor/ui/rectangleeditor.h @@ -38,38 +38,38 @@ class RectangleEditor : public ElementItemEditor public: explicit RectangleEditor(QETElementEditor *editor, PartRectangle *rect = nullptr, QWidget *parent = nullptr); - ~RectangleEditor() override; + ~RectangleEditor() override; - bool setPart(CustomElementPart *part) override; - bool setParts(QList parts) override; - CustomElementPart *currentPart() const override; - QList currentParts() const override; - QPointF editedTopLeft () const; + bool setPart(CustomElementPart *part) override; + bool setParts(QList parts) override; + CustomElementPart *currentPart() const override; + QList currentParts() const override; + QPointF editedTopLeft () const; public slots: - void updateForm() override; + void updateForm() override; private: - void editingFinished(); - void activeConnections(bool active); - void xPosChanged(); - void yPosChanged(); - void widthChanged(); - void heightChanged(); - void xRadiusChanged(); - void yRadiusChanged(); - /*! - * \brief setUpChangeConnections - * Setup the connection from the rectangles(s) to the widget, to update it when the rectangles(s) are changed (moved ...) - */ - void setUpChangeConnections(); - void disconnectChangeConnections(); + void editingFinished(); + void activeConnections(bool active); + void xPosChanged(); + void yPosChanged(); + void widthChanged(); + void heightChanged(); + void xRadiusChanged(); + void yRadiusChanged(); + /*! + * \brief setUpChangeConnections + * Setup the connection from the rectangles(s) to the widget, to update it when the rectangles(s) are changed (moved ...) + */ + void setUpChangeConnections(); + void disconnectChangeConnections(); private: - bool m_locked = false; - StyleEditor *m_style; - PartRectangle *m_part; - Ui::RectangleEditor *ui; - QList m_change_connections; + bool m_locked = false; + StyleEditor *m_style; + PartRectangle *m_part; + Ui::RectangleEditor *ui; + QList m_change_connections; }; #endif // RECTANGLEEDITOR_H diff --git a/sources/editor/ui/texteditor.cpp b/sources/editor/ui/texteditor.cpp index fb79cde85..e9b231446 100644 --- a/sources/editor/ui/texteditor.cpp +++ b/sources/editor/ui/texteditor.cpp @@ -107,19 +107,19 @@ bool TextEditor::setPart(CustomElementPart *part) if (!part) { m_text = nullptr; - disconnectChangeConnection(); + disconnectChangeConnection(); return true; } - - if (PartText *part_text = static_cast(part)) + + if (PartText *part_text = static_cast(part)) { if (part_text == m_text) { return true; } m_text = part_text; - - setUpChangeConnection(m_text); - + + setUpChangeConnection(m_text); + updateForm(); return true; } @@ -127,34 +127,34 @@ bool TextEditor::setPart(CustomElementPart *part) } bool TextEditor::setParts(QList parts) { - if (parts.isEmpty()) - { - m_parts.clear(); - if (m_text) { - disconnectChangeConnection(); - } - m_text = nullptr; - return true; - } - - if (PartText *part= static_cast(parts.first())) - { - if (m_text) { - disconnectChangeConnection(); - } - - m_text = part; - m_parts.clear(); - m_parts.append(part); - for (int i=1; i < parts.length(); i++) - m_parts.append(static_cast(parts[i])); - - setUpChangeConnection(m_text); - - updateForm(); - return true; - } - return(false); + if (parts.isEmpty()) + { + m_parts.clear(); + if (m_text) { + disconnectChangeConnection(); + } + m_text = nullptr; + return true; + } + + if (PartText *part= static_cast(parts.first())) + { + if (m_text) { + disconnectChangeConnection(); + } + + m_text = part; + m_parts.clear(); + m_parts.append(part); + for (int i=1; i < parts.length(); i++) + m_parts.append(static_cast(parts[i])); + + setUpChangeConnection(m_text); + + updateForm(); + return true; + } + return(false); } /** @@ -166,11 +166,11 @@ CustomElementPart *TextEditor::currentPart() const { } QList TextEditor::currentParts() const { - QList parts; - for (auto part: m_parts) { - parts.append(static_cast(part)); - } - return parts; + QList parts; + for (auto part: m_parts) { + parts.append(static_cast(part)); + } + return parts; } /** @@ -180,77 +180,77 @@ QList TextEditor::currentParts() const { */ void TextEditor::setUpEditConnection() { - disconnectEditConnection(); - + disconnectEditConnection(); + m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, [this]() { QString text_ = ui->m_line_edit->text(); - for (int i=0; i < m_parts.length(); i++) { - PartText* partText = m_parts[i]; - if (text_ != partText->toPlainText()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "text", partText->toPlainText(), text_); - undo->setText(tr("Modifier le contenu d'un champ texte")); - undoStack().push(undo); - } - } + for (int i=0; i < m_parts.length(); i++) { + PartText* partText = m_parts[i]; + if (text_ != partText->toPlainText()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "text", partText->toPlainText(), text_); + undo->setText(tr("Modifier le contenu d'un champ texte")); + undoStack().push(undo); + } + } }); m_edit_connection << connect(ui->m_x_sb, QOverload::of(&QSpinBox::valueChanged), [this]() { - QPointF pos(ui->m_x_sb->value(), 0); - for (int i=0; i < m_parts.length(); i++) { - PartText* partText = m_parts[i]; - pos.setY(partText->pos().y()); - if (pos != partText->pos()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos); - undo->setText(tr("Déplacer un champ texte")); - undo->setAnimated(true, false); - undoStack().push(undo); - } - } + QPointF pos(ui->m_x_sb->value(), 0); + for (int i=0; i < m_parts.length(); i++) { + PartText* partText = m_parts[i]; + pos.setY(partText->pos().y()); + if (pos != partText->pos()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos); + undo->setText(tr("Déplacer un champ texte")); + undo->setAnimated(true, false); + undoStack().push(undo); + } + } }); m_edit_connection << connect(ui->m_y_sb, QOverload::of(&QSpinBox::valueChanged), [this]() { - QPointF pos(0, ui->m_y_sb->value()); - for (int i=0; i < m_parts.length(); i++) { - PartText* partText = m_parts[i]; - pos.setX(partText->pos().x()); - if (pos != partText->pos()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos); - undo->setText(tr("Déplacer un champ texte")); - undo->setAnimated(true, false); - undoStack().push(undo); - } - } + QPointF pos(0, ui->m_y_sb->value()); + for (int i=0; i < m_parts.length(); i++) { + PartText* partText = m_parts[i]; + pos.setX(partText->pos().x()); + if (pos != partText->pos()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos); + undo->setText(tr("Déplacer un champ texte")); + undo->setAnimated(true, false); + undoStack().push(undo); + } + } }); m_edit_connection << connect(ui->m_rotation_sb, QOverload::of(&QSpinBox::valueChanged), [this]() { - for (int i=0; i < m_parts.length(); i++) { - PartText* partText = m_parts[i]; - if (ui->m_rotation_sb->value() != partText->rotation()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "rotation", partText->rotation(), ui->m_rotation_sb->value()); - undo->setText(tr("Pivoter un champ texte")); - undo->setAnimated(true, false); - undoStack().push(undo); - } - } + for (int i=0; i < m_parts.length(); i++) { + PartText* partText = m_parts[i]; + if (ui->m_rotation_sb->value() != partText->rotation()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "rotation", partText->rotation(), ui->m_rotation_sb->value()); + undo->setText(tr("Pivoter un champ texte")); + undo->setAnimated(true, false); + undoStack().push(undo); + } + } }); m_edit_connection << connect(ui->m_size_sb, QOverload::of(&QSpinBox::valueChanged), [this]() { - for (int i=0; i < m_parts.length(); i++) { - PartText* partText = m_parts[i]; - if (partText->font().pointSize() != ui->m_size_sb->value()) - { - QFont font_ = partText->font(); - font_.setPointSize(ui->m_size_sb->value()); - QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_); - undo->setText(tr("Modifier la police d'un texte")); - undoStack().push(undo); - } - } + for (int i=0; i < m_parts.length(); i++) { + PartText* partText = m_parts[i]; + if (partText->font().pointSize() != ui->m_size_sb->value()) + { + QFont font_ = partText->font(); + font_.setPointSize(ui->m_size_sb->value()); + QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_); + undo->setText(tr("Modifier la police d'un texte")); + undoStack().push(undo); + } + } }); } @@ -261,24 +261,24 @@ void TextEditor::on_m_font_pb_clicked() { bool ok; QFont font_ = QFontDialog::getFont(&ok, m_text->font(), this); - - if (ok && font_ != m_text->font()) { - ui->m_size_sb->blockSignals(true); - ui->m_size_sb->setValue(font_.pointSize()); - ui->m_size_sb->blockSignals(false); - - ui->m_font_pb->setText(font_.family()); - } - - for (int i=0; i < m_parts.length(); i++) { - PartText* partText = m_parts[i]; - if (ok && font_ != partText->font()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_); - undo->setText(tr("Modifier la police d'un texte")); - undoStack().push(undo); - } - } + + if (ok && font_ != m_text->font()) { + ui->m_size_sb->blockSignals(true); + ui->m_size_sb->setValue(font_.pointSize()); + ui->m_size_sb->blockSignals(false); + + ui->m_font_pb->setText(font_.family()); + } + + for (int i=0; i < m_parts.length(); i++) { + PartText* partText = m_parts[i]; + if (ok && font_ != partText->font()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_); + undo->setText(tr("Modifier la police d'un texte")); + undoStack().push(undo); + } + } } /** @@ -287,13 +287,13 @@ void TextEditor::on_m_font_pb_clicked() */ void TextEditor::on_m_color_pb_changed(const QColor &newColor) { - for (int i=0; i < m_parts.length(); i++) { - PartText* partText = m_parts[i]; - if (newColor != partText->defaultTextColor()) - { - QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "color", partText->defaultTextColor(), newColor); - undo->setText(tr("Modifier la couleur d'un texte")); - undoStack().push(undo); - } - } + for (int i=0; i < m_parts.length(); i++) { + PartText* partText = m_parts[i]; + if (newColor != partText->defaultTextColor()) + { + QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "color", partText->defaultTextColor(), newColor); + undo->setText(tr("Modifier la couleur d'un texte")); + undoStack().push(undo); + } + } } diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index 7fb4a8543..6b66b740c 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -164,7 +164,7 @@ QTreeWidgetItem *ElementsPanel::updateTemplateItem(QTreeWidgetItem *tb_template_ item -> setStatusTip( 0, tr( - "Glissez-déposez ce modèle de cartouche sur un folio pour l'y appliquer.", + "Glissez-déposez ce modèle de cartouche sur un folio pour l'y appliquer.", "Status tip displayed when selecting a title block template" ) ); diff --git a/sources/elementtextpattern.cpp b/sources/elementtextpattern.cpp index 2006226b5..b1253f948 100644 --- a/sources/elementtextpattern.cpp +++ b/sources/elementtextpattern.cpp @@ -167,8 +167,8 @@ ImportElementTextPattern::ImportElementTextPattern(Element *elmt): QString ImportElementTextPattern::getName(const QStringList& list, bool *ok, bool *erase) const { return ImportElementTextPatternDialog::getItem(parentWidget(), - QObject::tr("Sélectionner une configuration de textes"), - QObject::tr("Sélectionner la configuration de textes à ajouter à l'élément"), + QObject::tr("Sélectionner une configuration de textes"), + QObject::tr("Sélectionner la configuration de textes à ajouter à l'élément"), list, ok, erase); diff --git a/sources/nomenclature.cpp b/sources/nomenclature.cpp index ba10447ac..7c9878334 100644 --- a/sources/nomenclature.cpp +++ b/sources/nomenclature.cpp @@ -60,7 +60,7 @@ bool nomenclature::saveToCSVFile() if(!QFile::remove ( filename ) ){ QMessageBox::critical(this->m_parent, QObject::tr("Erreur"), QObject::tr("Impossible de remplacer le fichier!\n\n")+ - "Destination : "+filename+"\n"); + "Destination : "+filename+"\n"); return false; } } @@ -88,28 +88,28 @@ QString nomenclature::getNomenclature() { //Process... QString data = QObject::tr("NOMENCLATURE : ") + m_project -> title() + "\n\n"; - data += QObject::tr("A001") +";" //:Don't translate this text! //ID for folio position in project - ""+ QObject::tr("B001") +";" //:Don't translate this text! //ID for folio title - ""+ QObject::tr("C001") +";" //:Don't translate this text! //ID for folio number - ""+ QObject::tr("D001") +";" //:Don't translate this text! //ID for qet designation - ""+ QObject::tr("E001") +";" //:Don't translate this text! //ID for position of element on the folio - ""+ QObject::tr("F001") +";" //:Don't translate this text! //ID for label of element - ""+ QObject::tr("F002") +";" //:Don't translate this text! //ID for label formula of element - ""+ QObject::tr("G001") +";" //:Don't translate this text! //ID for order number - ""+ QObject::tr("H001") +";" //:Don't translate this text! //ID for article description - ""+ QObject::tr("H002") +";" //:Don't translate this text! //ID for plant - ""+ QObject::tr("I001") +";" //:Don't translate this text! //ID for comment - ""+ QObject::tr("J001") +";" //:Don't translate this text! //ID for manufacturer - ""+ QObject::tr("K001") +";" //:Don't translate this text! //ID for article number - ""+ QObject::tr("L001") +";" //:Don't translate this text! //ID for quantity - ""+ QObject::tr("L002") +";" //:Don't translate this text! //ID for unity - ""+ QObject::tr("L003") +";" //:Don't translate this text! //ID for supplier - ""+ QObject::tr("M001") +";" //:Don't translate this text! //ID for auxiliary field 1 - ""+ QObject::tr("M002") +";" //:Don't translate this text! //ID for auxiliary field 2 - ""+ QObject::tr("N001")+";" //:Don't translate this text! //ID for internal number - ""+ QObject::tr("O001")+";" //:Don't translate this text! //ID for location - ""+ QObject::tr("P001") +"\n"; //:Don't translate this text! //ID for function - data += QObject::tr("Position du folio") +";" + data += QObject::tr("A001") +";" //:Don't translate this text! //ID for folio position in project + ""+ QObject::tr("B001") +";" //:Don't translate this text! //ID for folio title + ""+ QObject::tr("C001") +";" //:Don't translate this text! //ID for folio number + ""+ QObject::tr("D001") +";" //:Don't translate this text! //ID for qet designation + ""+ QObject::tr("E001") +";" //:Don't translate this text! //ID for position of element on the folio + ""+ QObject::tr("F001") +";" //:Don't translate this text! //ID for label of element + ""+ QObject::tr("F002") +";" //:Don't translate this text! //ID for label formula of element + ""+ QObject::tr("G001") +";" //:Don't translate this text! //ID for order number + ""+ QObject::tr("H001") +";" //:Don't translate this text! //ID for article description + ""+ QObject::tr("H002") +";" //:Don't translate this text! //ID for plant + ""+ QObject::tr("I001") +";" //:Don't translate this text! //ID for comment + ""+ QObject::tr("J001") +";" //:Don't translate this text! //ID for manufacturer + ""+ QObject::tr("K001") +";" //:Don't translate this text! //ID for article number + ""+ QObject::tr("L001") +";" //:Don't translate this text! //ID for quantity + ""+ QObject::tr("L002") +";" //:Don't translate this text! //ID for unity + ""+ QObject::tr("L003") +";" //:Don't translate this text! //ID for supplier + ""+ QObject::tr("M001") +";" //:Don't translate this text! //ID for auxiliary field 1 + ""+ QObject::tr("M002") +";" //:Don't translate this text! //ID for auxiliary field 2 + ""+ QObject::tr("N001")+";" //:Don't translate this text! //ID for internal number + ""+ QObject::tr("O001")+";" //:Don't translate this text! //ID for location + ""+ QObject::tr("P001") +"\n"; //:Don't translate this text! //ID for function + data += QObject::tr("Position du folio") +";" ""+ QObject::tr("Titre de folio") +";" ""+ QObject::tr("Numéro de folio") +";" ""+ QObject::tr("Désignation qet") +";" diff --git a/sources/projectview.cpp b/sources/projectview.cpp index 6340bd0e3..434c570ab 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -887,27 +887,27 @@ void ProjectView::diagramAdded(Diagram *diagram) */ void ProjectView::updateTabTitle(DiagramView *diagram_view) { - int diagram_tab_id = m_diagram_ids.key(diagram_view, -1); - - if (diagram_tab_id != -1) - { - QSettings settings; - QString title; - Diagram *diagram = diagram_view->diagram(); - - if (settings.value("genericpanel/folio", false).toBool()) - { - QString formula = diagram->border_and_titleblock.folio(); - autonum::sequentialNumbers seq; - title = autonum::AssignVariables::formulaToLabel(formula, seq, diagram); - } - else - title = QString::number(diagram->folioIndex() + 1); - - title += " - "; - title += diagram->title(); - m_tab->setTabText(diagram_tab_id ,title); - } + int diagram_tab_id = m_diagram_ids.key(diagram_view, -1); + + if (diagram_tab_id != -1) + { + QSettings settings; + QString title; + Diagram *diagram = diagram_view->diagram(); + + if (settings.value("genericpanel/folio", false).toBool()) + { + QString formula = diagram->border_and_titleblock.folio(); + autonum::sequentialNumbers seq; + title = autonum::AssignVariables::formulaToLabel(formula, seq, diagram); + } + else + title = QString::number(diagram->folioIndex() + 1); + + title += " - "; + title += diagram->title(); + m_tab->setTabText(diagram_tab_id ,title); + } } /** diff --git a/sources/pugixml/pugixml.cpp b/sources/pugixml/pugixml.cpp index 0ad062d5d..04407d7fb 100644 --- a/sources/pugixml/pugixml.cpp +++ b/sources/pugixml/pugixml.cpp @@ -11063,7 +11063,7 @@ PUGI__NS_BEGIN // Use optimized path for @attr = 'value' or @attr = $value if (_type == ast_op_equal && _left && _right && // workaround for clang static analyzer and Coverity (_left and _right are never null for ast_op_equal) - // coverity[mixed_enums] + // coverity[mixed_enums] _left->_type == ast_step && _left->_axis == axis_attribute && _left->_test == nodetest_name && !_left->_left && !_left->_right && (_right->_type == ast_string_constant || (_right->_type == ast_variable && _right->_rettype == xpath_type_string))) { diff --git a/sources/qet.cpp b/sources/qet.cpp index 08da0e375..928ccda86 100644 --- a/sources/qet.cpp +++ b/sources/qet.cpp @@ -561,35 +561,35 @@ bool QET::compareCanonicalFilePaths(const QString &first, const QString &second) */ bool QET::writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString *error_message) { - QSaveFile file(filepath); - - // Note: we do not set QIODevice::Text to avoid generating CRLF end of lines - bool file_opening = file.open(QIODevice::WriteOnly); - if (!file_opening) - { - if (error_message) - { - *error_message = QString(QObject::tr("Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.", - "error message when attempting to write an XML file")).arg(filepath).arg(file.error()); - } - return(false); - } - - QTextStream out(&file); - out.setCodec("UTF-8"); - out.setGenerateByteOrderMark(false); - out << xml_doc.toString(4); - if (!file.commit()) - { - if (error_message) { - *error_message = QString(QObject::tr("Une erreur est survenue lors de l'écriture du fichier %1, erreur %2 rencontrée.", - "error message when attempting to write an XML file")).arg(filepath).arg(file.error()); - } - - return false; - } - - return(true); + QSaveFile file(filepath); + + // Note: we do not set QIODevice::Text to avoid generating CRLF end of lines + bool file_opening = file.open(QIODevice::WriteOnly); + if (!file_opening) + { + if (error_message) + { + *error_message = QString(QObject::tr("Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.", + "error message when attempting to write an XML file")).arg(filepath).arg(file.error()); + } + return(false); + } + + QTextStream out(&file); + out.setCodec("UTF-8"); + out.setGenerateByteOrderMark(false); + out << xml_doc.toString(4); + if (!file.commit()) + { + if (error_message) { + *error_message = QString(QObject::tr("Une erreur est survenue lors de l'écriture du fichier %1, erreur %2 rencontrée.", + "error message when attempting to write an XML file")).arg(filepath).arg(file.error()); + } + + return false; + } + + return(true); } /** diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index c76cb246f..3659dcd63 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -576,9 +576,9 @@ QString QETApp::customElementsDir() if (dir.exists()) { m_user_custom_elements_dir = path; - if(!m_user_custom_elements_dir.endsWith("/")) { - m_user_custom_elements_dir.append("/"); - } + if(!m_user_custom_elements_dir.endsWith("/")) { + m_user_custom_elements_dir.append("/"); + } return m_user_custom_elements_dir; } } @@ -1786,17 +1786,17 @@ void QETApp::buildSystemTrayMenu() { */ void QETApp::checkBackupFiles() { - QList stale_files = KAutoSaveFile::allStaleFiles(); - - //Remove from the list @stale_files, the stales file of opened project + QList stale_files = KAutoSaveFile::allStaleFiles(); + + //Remove from the list @stale_files, the stales file of opened project const QList sf = stale_files; - for (KAutoSaveFile *kasf : sf) - { - for (QETProject *project : registeredProjects().values()) - { - //We must to adjust with the flag QUrl::StripTrailingSlash to compar a path formated like the path returned by KAutoSaveFile - const QString path = QUrl::fromLocalFile(project->filePath()).adjusted(QUrl::RemoveScheme | QUrl::StripTrailingSlash).path(); - if (kasf->managedFile() == path) { + for (KAutoSaveFile *kasf : sf) + { + for (QETProject *project : registeredProjects().values()) + { + //We must to adjust with the flag QUrl::StripTrailingSlash to compar a path formated like the path returned by KAutoSaveFile + const QString path = QUrl::fromLocalFile(project->filePath()).adjusted(QUrl::RemoveScheme | QUrl::StripTrailingSlash).path(); + if (kasf->managedFile() == path) { stale_files.removeOne(kasf); } } diff --git a/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp b/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp index 9a5a303d1..fcfe08d86 100644 --- a/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp +++ b/sources/qetgraphicsitem/ViewItem/projectdbmodel.cpp @@ -1,19 +1,19 @@ /* - Copyright 2006-2020 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 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 . + Copyright 2006-2020 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 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 . */ #include "projectdbmodel.h" #include "projectdatabase.h" @@ -30,8 +30,8 @@ * @param parent : parent QObject */ ProjectDBModel::ProjectDBModel(QETProject *project, QObject *parent) : - QAbstractTableModel(parent), - m_project(project) + QAbstractTableModel(parent), + m_project(project) { connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated); } @@ -41,13 +41,13 @@ ProjectDBModel::ProjectDBModel(QETProject *project, QObject *parent) : * @param other_model */ ProjectDBModel::ProjectDBModel(const ProjectDBModel &other_model) : - QAbstractTableModel(other_model.parent()) + QAbstractTableModel(other_model.parent()) { - this->setParent(other_model.parent()); - m_project = other_model.m_project; + this->setParent(other_model.parent()); + m_project = other_model.m_project; connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated); - m_index_0_0_data = other_model.m_index_0_0_data; - setQuery(other_model.queryString()); + m_index_0_0_data = other_model.m_index_0_0_data; + setQuery(other_model.queryString()); } /** @@ -58,10 +58,10 @@ ProjectDBModel::ProjectDBModel(const ProjectDBModel &other_model) : */ int ProjectDBModel::rowCount(const QModelIndex &parent) const { - if (parent.isValid()) - return 0; - - return m_record.count(); + if (parent.isValid()) + return 0; + + return m_record.count(); } /** @@ -72,14 +72,14 @@ int ProjectDBModel::rowCount(const QModelIndex &parent) const */ int ProjectDBModel::columnCount(const QModelIndex &parent) const { - if (parent.isValid()) - return 0; - - if (m_record.count()) { - return m_record.first().count(); - } - - return 0; + if (parent.isValid()) + return 0; + + if (m_record.count()) { + return m_record.first().count(); + } + + return 0; } /** @@ -94,14 +94,14 @@ int ProjectDBModel::columnCount(const QModelIndex &parent) const */ bool ProjectDBModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) { - if (orientation == Qt::Vertical) { - return false; - } - auto hash_ = m_header_data.value(section); - hash_.insert(role, value); - m_header_data.insert(section, hash_); - emit headerDataChanged(orientation, section, section); - return true; + if (orientation == Qt::Vertical) { + return false; + } + auto hash_ = m_header_data.value(section); + hash_.insert(role, value); + m_header_data.insert(section, hash_); + emit headerDataChanged(orientation, section, section); + return true; } /** @@ -114,19 +114,19 @@ bool ProjectDBModel::setHeaderData(int section, Qt::Orientation orientation, con */ QVariant ProjectDBModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation == Qt::Vertical) { - return QVariant(); - } - - if (m_header_data.contains(section)) - { - auto hash_ = m_header_data.value(section); - if (role == Qt::DisplayRole && !hash_.contains(Qt::DisplayRole)) { //special case to have the same behavior as Qt - return hash_.value(Qt::EditRole); - } - return m_header_data.value(section).value(role); - } - return QVariant(); + if (orientation == Qt::Vertical) { + return QVariant(); + } + + if (m_header_data.contains(section)) + { + auto hash_ = m_header_data.value(section); + if (role == Qt::DisplayRole && !hash_.contains(Qt::DisplayRole)) { //special case to have the same behavior as Qt + return hash_.value(Qt::EditRole); + } + return m_header_data.value(section).value(role); + } + return QVariant(); } /** @@ -139,12 +139,12 @@ QVariant ProjectDBModel::headerData(int section, Qt::Orientation orientation, in */ bool ProjectDBModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (!index.isValid() || index.row() != 0 || index.column() != 0) { - return false; - } - m_index_0_0_data.insert(role, value); - emit dataChanged(index, index, QVector(role)); - return true; + if (!index.isValid() || index.row() != 0 || index.column() != 0) { + return false; + } + m_index_0_0_data.insert(role, value); + emit dataChanged(index, index, QVector(role)); + return true; } /** @@ -156,21 +156,21 @@ bool ProjectDBModel::setData(const QModelIndex &index, const QVariant &value, in */ QVariant ProjectDBModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); - - if (index.row() == 0 && - index.column() == 0 && - role != Qt::DisplayRole) { - return m_index_0_0_data.value(role); - } - - if (role == Qt::DisplayRole) { - QVariant v(m_record.at(index.row()).at(index.column())); - return v; - } - - return QVariant(); + if (!index.isValid()) + return QVariant(); + + if (index.row() == 0 && + index.column() == 0 && + role != Qt::DisplayRole) { + return m_index_0_0_data.value(role); + } + + if (role == Qt::DisplayRole) { + QVariant v(m_record.at(index.row()).at(index.column())); + return v; + } + + return QVariant(); } /** @@ -180,29 +180,29 @@ QVariant ProjectDBModel::data(const QModelIndex &index, int role) const */ void ProjectDBModel::setQuery(const QString &query) { - auto rm_ = m_query != query; - if (rm_) { - emit beginResetModel(); - } - - m_query = query; - - if (m_project) - { - if (rm_) { - disconnect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated); - } - m_project->dataBase()->updateDB(); - if (rm_) { - setHeaderString(); - fillValue(); - connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated); - } - } - - if (rm_) { - emit endResetModel(); - } + auto rm_ = m_query != query; + if (rm_) { + emit beginResetModel(); + } + + m_query = query; + + if (m_project) + { + if (rm_) { + disconnect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated); + } + m_project->dataBase()->updateDB(); + if (rm_) { + setHeaderString(); + fillValue(); + connect(m_project->dataBase(), &projectDataBase::dataBaseUpdated, this, &ProjectDBModel::dataBaseUpdated); + } + } + + if (rm_) { + emit endResetModel(); + } } /** @@ -210,11 +210,11 @@ void ProjectDBModel::setQuery(const QString &query) * @return the current query used by this model */ QString ProjectDBModel::queryString() const { - return m_query; + return m_query; } QETProject *ProjectDBModel::project() const { - return m_project.data(); + return m_project.data(); } /** @@ -226,42 +226,42 @@ QETProject *ProjectDBModel::project() const { */ QDomElement ProjectDBModel::toXml(QDomDocument &document) const { - auto dom_element = document.createElement(xmlTagName()); - - //Identifier - auto dom_identifier = document.createElement("identifier"); - auto dom_identifier_text = document.createTextNode(m_identifier); - dom_identifier.appendChild(dom_identifier_text); - dom_element.appendChild(dom_identifier); - - //query - auto dom_query = document.createElement("query"); - auto dom_query_text = document.createTextNode(m_query); - dom_query.appendChild(dom_query_text); - dom_element.appendChild(dom_query); - - //Add index 0,0 data - auto index_00 = document.createElement("index00"); - index_00.setAttribute("font", m_index_0_0_data.value(Qt::FontRole).toString()); - auto me = QMetaEnum::fromType(); - index_00.setAttribute("alignment", me.valueToKey(m_index_0_0_data.value(Qt::TextAlignmentRole).toInt())); - dom_element.appendChild(index_00); - index_00.setAttribute("margins", m_index_0_0_data.value(Qt::UserRole+1).toString()); - - //header data - QHash> horizontal_; - for (auto key : m_header_data.keys()) - { - //We save all data except the display role, because he was generated in the fly - auto list = m_header_data.value(key).keys(); - list.removeAll(Qt::DisplayRole); - - horizontal_.insert(key, list); - } - - dom_element.appendChild(QETXML::modelHeaderDataToXml(document, this, horizontal_, QHash>())); - - return dom_element; + auto dom_element = document.createElement(xmlTagName()); + + //Identifier + auto dom_identifier = document.createElement("identifier"); + auto dom_identifier_text = document.createTextNode(m_identifier); + dom_identifier.appendChild(dom_identifier_text); + dom_element.appendChild(dom_identifier); + + //query + auto dom_query = document.createElement("query"); + auto dom_query_text = document.createTextNode(m_query); + dom_query.appendChild(dom_query_text); + dom_element.appendChild(dom_query); + + //Add index 0,0 data + auto index_00 = document.createElement("index00"); + index_00.setAttribute("font", m_index_0_0_data.value(Qt::FontRole).toString()); + auto me = QMetaEnum::fromType(); + index_00.setAttribute("alignment", me.valueToKey(m_index_0_0_data.value(Qt::TextAlignmentRole).toInt())); + dom_element.appendChild(index_00); + index_00.setAttribute("margins", m_index_0_0_data.value(Qt::UserRole+1).toString()); + + //header data + QHash> horizontal_; + for (auto key : m_header_data.keys()) + { + //We save all data except the display role, because he was generated in the fly + auto list = m_header_data.value(key).keys(); + list.removeAll(Qt::DisplayRole); + + horizontal_.insert(key, list); + } + + dom_element.appendChild(QETXML::modelHeaderDataToXml(document, this, horizontal_, QHash>())); + + return dom_element; } /** @@ -271,22 +271,22 @@ QDomElement ProjectDBModel::toXml(QDomDocument &document) const */ void ProjectDBModel::fromXml(const QDomElement &element) { - if (element.tagName() != xmlTagName()) - return; - - setIdentifier(element.firstChildElement("identifier").text()); - setQuery(element.firstChildElement("query").text()); - - //Index 0,0 - auto index_00 = element.firstChildElement("index00"); - QFont font_; - font_.fromString(index_00.attribute("font")); - m_index_0_0_data.insert(Qt::FontRole, font_); - auto me = QMetaEnum::fromType(); - m_index_0_0_data.insert(Qt::TextAlignmentRole, me.keyToValue(index_00.attribute("alignment").toStdString().data())); - m_index_0_0_data.insert(Qt::UserRole+1, index_00.attribute("margins")); - - QETXML::modelHeaderDataFromXml(element.firstChildElement("header_data"), this); + if (element.tagName() != xmlTagName()) + return; + + setIdentifier(element.firstChildElement("identifier").text()); + setQuery(element.firstChildElement("query").text()); + + //Index 0,0 + auto index_00 = element.firstChildElement("index00"); + QFont font_; + font_.fromString(index_00.attribute("font")); + m_index_0_0_data.insert(Qt::FontRole, font_); + auto me = QMetaEnum::fromType(); + m_index_0_0_data.insert(Qt::TextAlignmentRole, me.keyToValue(index_00.attribute("alignment").toStdString().data())); + m_index_0_0_data.insert(Qt::UserRole+1, index_00.attribute("margins")); + + QETXML::modelHeaderDataFromXml(element.firstChildElement("header_data"), this); } /** @@ -304,39 +304,39 @@ void ProjectDBModel::setIdentifier(const QString &identifier) { */ void ProjectDBModel::dataBaseUpdated() { - auto original_record = m_record; - fillValue(); - auto new_record = m_record; - m_record = original_record; - - //This a very special case, if this nomenclature model is added - //befor any element, column count return 0, so in this case we emit column inserted - if (new_record.size() != m_record.size()) - { - emit beginResetModel(); - m_record = new_record; - emit endResetModel(); - } - else - { - m_record = new_record; - auto row = m_record.size(); - auto col = row ? m_record.first().count() : 1; - - emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector(Qt::DisplayRole)); - } + auto original_record = m_record; + fillValue(); + auto new_record = m_record; + m_record = original_record; + + //This a very special case, if this nomenclature model is added + //befor any element, column count return 0, so in this case we emit column inserted + if (new_record.size() != m_record.size()) + { + emit beginResetModel(); + m_record = new_record; + emit endResetModel(); + } + else + { + m_record = new_record; + auto row = m_record.size(); + auto col = row ? m_record.first().count() : 1; + + emit dataChanged(this->index(0,0), this->index(row-1, col-1), QVector(Qt::DisplayRole)); + } } void ProjectDBModel::setHeaderString() { auto q = m_project->dataBase()->newQuery(m_query); auto record = q.record(); - + for (auto i=0 ; idataBase()->newQuery(m_query); if (!query_.exec()) { qDebug() << "Query error : " << query_.lastError(); } - + while (query_.next()) { QStringList record_; diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 55bea7a7b..804b4aa24 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -581,27 +581,27 @@ bool Conductor::valideXml(QDomElement &e){ if (!e.hasAttribute("terminal2")) return(false); bool conv_ok; - // parse l'abscisse - if (e.hasAttribute("element1")) { - if (QUuid(e.attribute("element1")).isNull()) - return false; - if (QUuid(e.attribute("terminal1")).isNull()) - return false; - } else { - e.attribute("terminal1").toInt(&conv_ok); - if (!conv_ok) return(false); - } + // parse l'abscisse + if (e.hasAttribute("element1")) { + if (QUuid(e.attribute("element1")).isNull()) + return false; + if (QUuid(e.attribute("terminal1")).isNull()) + return false; + } else { + e.attribute("terminal1").toInt(&conv_ok); + if (!conv_ok) return(false); + } // parse l'ordonnee - if (e.hasAttribute("element2")) { - if (QUuid(e.attribute("element2")).isNull()) - return false; - if (QUuid(e.attribute("terminal2")).isNull()) - return false; - } else { - e.attribute("terminal2").toInt(&conv_ok); - if (!conv_ok) return(false); - } + if (e.hasAttribute("element2")) { + if (QUuid(e.attribute("element2")).isNull()) + return false; + if (QUuid(e.attribute("terminal2")).isNull()) + return false; + } else { + e.attribute("terminal2").toInt(&conv_ok); + if (!conv_ok) return(false); + } return(true); } diff --git a/sources/qetgraphicsitem/conductortextitem.cpp b/sources/qetgraphicsitem/conductortextitem.cpp index c52d0a6b3..012d98a43 100644 --- a/sources/qetgraphicsitem/conductortextitem.cpp +++ b/sources/qetgraphicsitem/conductortextitem.cpp @@ -130,22 +130,22 @@ void ConductorTextItem::forceRotateByUser(bool rotate_by_user) { */ void ConductorTextItem::setPos(const QPointF &pos) { - /* - * In some condition the conductor text item is outside the border of folio in the left. - * They cause a margin on the left of folio and in most case this margin is unwanted and annoying the user. - * If the text is empty and the scene position is outside the border (left and top), - * we can say that this position, is unwanted by user. - * So we move this text item to the top left of the bounding rect of parent conductors, because we sure this position is wanted by user. - */ - DiagramTextItem::setPos(pos); - if(toPlainText().isEmpty() && (scenePos().x() < 0 || scenePos().y() < 0)) - { - Conductor *cond = parentConductor(); - if(cond) - DiagramTextItem::setPos(cond->boundingRect().topLeft()); - else - DiagramTextItem::setPos(0,0); - } + /* + * In some condition the conductor text item is outside the border of folio in the left. + * They cause a margin on the left of folio and in most case this margin is unwanted and annoying the user. + * If the text is empty and the scene position is outside the border (left and top), + * we can say that this position, is unwanted by user. + * So we move this text item to the top left of the bounding rect of parent conductors, because we sure this position is wanted by user. + */ + DiagramTextItem::setPos(pos); + if(toPlainText().isEmpty() && (scenePos().x() < 0 || scenePos().y() < 0)) + { + Conductor *cond = parentConductor(); + if(cond) + DiagramTextItem::setPos(cond->boundingRect().topLeft()); + else + DiagramTextItem::setPos(0,0); + } } /** diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index c8eb09cf7..56452cc94 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -632,27 +632,27 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt) // for delay on contact if (flags &DelayOn) { if (flags &NO) { - painter.drawLine(12, offset+8, 12, offset+11); - QRectF r(9.5, offset+9, 5, 3); - painter.drawArc(r, 180*16, 180*16); + painter.drawLine(12, offset+8, 12, offset+11); + QRectF r(9.5, offset+9, 5, 3); + painter.drawArc(r, 180*16, 180*16); } - if (flags &NC) { - painter.drawLine(QPointF(12.5, offset+5), QPointF(12.5, offset+8)); - QRectF r(10, offset+6, 5, 3); - painter.drawArc(r, 180*16, 180*16); + if (flags &NC) { + painter.drawLine(QPointF(12.5, offset+5), QPointF(12.5, offset+8)); + QRectF r(10, offset+6, 5, 3); + painter.drawArc(r, 180*16, 180*16); } } - // for delay off contact + // for delay off contact else if ( flags &DelayOff){ if (flags &NO) { - painter.drawLine(12, offset+8, 12, offset+9.5); - QRectF r(9.5, offset+9.5, 5, 3); - painter.drawArc(r, 0, 180*16); - } + painter.drawLine(12, offset+8, 12, offset+9.5); + QRectF r(9.5, offset+9.5, 5, 3); + painter.drawArc(r, 0, 180*16); + } if (flags &NC) { - painter.drawLine(QPointF(12.5, offset+5), QPointF(12.5, offset+7)); - QRectF r(10, offset+7.5, 5, 3); - painter.drawArc(r, 0, 180*16); + painter.drawLine(QPointF(12.5, offset+5), QPointF(12.5, offset+7)); + QRectF r(10, offset+7.5, 5, 3); + painter.drawArc(r, 0, 180*16); } } diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp index d6aa1e4ca..ba8ea4fcb 100644 --- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp +++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp @@ -1045,18 +1045,18 @@ void DynamicElementTextItem::updateLabel() (m_text_from == CompositeText && m_composite_text.contains("%{label}"))) { DiagramContext dc; - Element *element = elementUseForInfo(); - if(element) { - dc = element->elementInformations(); - } + Element *element = elementUseForInfo(); + if(element) { + dc = element->elementInformations(); + } - if(m_text_from == ElementInfo && element) { - setPlainText(element->actualLabel()); + if(m_text_from == ElementInfo && element) { + setPlainText(element->actualLabel()); } - else if (m_text_from == CompositeText) { + else if (m_text_from == CompositeText) { setPlainText(autonum::AssignVariables::replaceVariable(m_composite_text, dc)); - } + } } } diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 17ce03caa..173a4be83 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -1377,23 +1377,23 @@ void Element::initLink(QETProject *prj) QString Element::linkTypeToString() const { - switch (m_link_type) - { - case Simple: - return "Simple"; - case NextReport : - return "NextReport"; - case PreviousReport: - return "PreviousReport"; - case Master: - return "Master"; - case Slave: - return "Slave"; - case Terminale: - return "Terminale"; - default: - return "Unknown"; - } + switch (m_link_type) + { + case Simple: + return "Simple"; + case NextReport : + return "NextReport"; + case PreviousReport: + return "PreviousReport"; + case Master: + return "Master"; + case Slave: + return "Slave"; + case Terminale: + return "Terminale"; + default: + return "Unknown"; + } } /** diff --git a/sources/qetgraphicsitem/qetshapeitem.cpp b/sources/qetgraphicsitem/qetshapeitem.cpp index aec56e60e..20208a32c 100644 --- a/sources/qetgraphicsitem/qetshapeitem.cpp +++ b/sources/qetgraphicsitem/qetshapeitem.cpp @@ -366,24 +366,24 @@ void QetShapeItem::mousePressEvent(QGraphicsSceneMouseEvent *event) */ QVariant QetShapeItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) { - if (change == ItemSelectedHasChanged) - { - if (value.toBool() == true) { //If this is selected, wa add handlers. + if (change == ItemSelectedHasChanged) + { + if (value.toBool() == true) { //If this is selected, wa add handlers. addHandler(); - } - else //Else this is deselected, we remove handlers - { - if(!m_handler_vector.isEmpty()) - { - qDeleteAll(m_handler_vector); - m_handler_vector.clear(); - } + } + else //Else this is deselected, we remove handlers + { + if(!m_handler_vector.isEmpty()) + { + qDeleteAll(m_handler_vector); + m_handler_vector.clear(); + } m_resize_mode = 1; - } - } - else if (change == ItemPositionHasChanged) { + } + } + else if (change == ItemPositionHasChanged) { adjusteHandlerPos(); - } + } else if (change == ItemSceneHasChanged) { if (!scene()) //This is removed from scene, then we deselect this, and so, the handlers is also removed. @@ -391,8 +391,8 @@ QVariant QetShapeItem::itemChange(QGraphicsItem::GraphicsItemChange change, cons setSelected(false); } } - - return QGraphicsItem::itemChange(change, value); + + return QGraphicsItem::itemChange(change, value); } /** diff --git a/sources/richtext/richtexteditor.cpp b/sources/richtext/richtexteditor.cpp index bff565967..ddd3ad7f1 100644 --- a/sources/richtext/richtexteditor.cpp +++ b/sources/richtext/richtexteditor.cpp @@ -178,631 +178,631 @@ namespace qdesigner_internal { class RichTextEditor : public QTextEdit { - Q_OBJECT -public: - RichTextEditor(QWidget *parent = nullptr); - void setDefaultFont(QFont font); - - QToolBar *createToolBar(QWidget *parent = nullptr); - bool simplifyRichText() const { return m_simplifyRichText; } - -public slots: - void setFontBold(bool b); - void setFontPointSize(double); - void setText(const QString &text); - void setSimplifyRichText(bool v); - QString text(Qt::TextFormat format) const; - -signals: - void stateChanged(); - void simplifyRichTextChanged(bool); - -private: - bool m_simplifyRichText; + Q_OBJECT + public: + RichTextEditor(QWidget *parent = nullptr); + void setDefaultFont(QFont font); + + QToolBar *createToolBar(QWidget *parent = nullptr); + bool simplifyRichText() const { return m_simplifyRichText; } + + public slots: + void setFontBold(bool b); + void setFontPointSize(double); + void setText(const QString &text); + void setSimplifyRichText(bool v); + QString text(Qt::TextFormat format) const; + + signals: + void stateChanged(); + void simplifyRichTextChanged(bool); + + private: + bool m_simplifyRichText; }; class AddLinkDialog : public QDialog { - Q_OBJECT - -public: - AddLinkDialog(RichTextEditor *editor, QWidget *parent = nullptr); - ~AddLinkDialog() override; - - int showDialog(); - -public slots: - void accept() override; - -private: - RichTextEditor *m_editor; - Ui::AddLinkDialog *m_ui; + Q_OBJECT + + public: + AddLinkDialog(RichTextEditor *editor, QWidget *parent = nullptr); + ~AddLinkDialog() override; + + int showDialog(); + + public slots: + void accept() override; + + private: + RichTextEditor *m_editor; + Ui::AddLinkDialog *m_ui; }; AddLinkDialog::AddLinkDialog(RichTextEditor *editor, QWidget *parent) : - QDialog(parent), - m_ui(new Ui::AddLinkDialog) + QDialog(parent), + m_ui(new Ui::AddLinkDialog) { - m_ui->setupUi(this); - - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - - m_editor = editor; + m_ui->setupUi(this); + + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + m_editor = editor; } AddLinkDialog::~AddLinkDialog() { - delete m_ui; + delete m_ui; } int AddLinkDialog::showDialog() { - // Set initial focus - const QTextCursor cursor = m_editor->textCursor(); - if (cursor.hasSelection()) { - m_ui->titleInput->setText(cursor.selectedText()); - m_ui->urlInput->setFocus(); - } else { - m_ui->titleInput->setFocus(); - } - - return exec(); + // Set initial focus + const QTextCursor cursor = m_editor->textCursor(); + if (cursor.hasSelection()) { + m_ui->titleInput->setText(cursor.selectedText()); + m_ui->urlInput->setFocus(); + } else { + m_ui->titleInput->setFocus(); + } + + return exec(); } void AddLinkDialog::accept() { - const QString title = m_ui->titleInput->text(); - const QString url = m_ui->urlInput->text(); - - if (!title.isEmpty()) { - QString html = QLatin1String(""); - html += title; - html += QLatin1String(""); - - m_editor->insertHtml(html); - } - - m_ui->titleInput->clear(); - m_ui->urlInput->clear(); - - QDialog::accept(); + const QString title = m_ui->titleInput->text(); + const QString url = m_ui->urlInput->text(); + + if (!title.isEmpty()) { + QString html = QLatin1String(""); + html += title; + html += QLatin1String(""); + + m_editor->insertHtml(html); + } + + m_ui->titleInput->clear(); + m_ui->urlInput->clear(); + + QDialog::accept(); } class HtmlTextEdit : public QTextEdit { - Q_OBJECT - -public: - HtmlTextEdit(QWidget *parent = nullptr) - : QTextEdit(parent) - {} - - void contextMenuEvent(QContextMenuEvent *event) override; - -private slots: - void actionTriggered(QAction *action); + Q_OBJECT + + public: + HtmlTextEdit(QWidget *parent = nullptr) + : QTextEdit(parent) + {} + + void contextMenuEvent(QContextMenuEvent *event) override; + + private slots: + void actionTriggered(QAction *action); }; void HtmlTextEdit::contextMenuEvent(QContextMenuEvent *event) { - QMenu *menu = createStandardContextMenu(); - QMenu *htmlMenu = new QMenu(tr("Insert HTML entity"), menu); - - typedef struct { - const char *text; - const char *entity; - } Entry; - - const Entry entries[] = { - { "&& (&&)", "&" }, - { "& ", " " }, - { "&< (<)", "<" }, - { "&> (>)", ">" }, - { "&© (Copyright)", "©" }, - { "&® (Trade Mark)", "®" }, - }; - - for (int i = 0; i < 6; ++i) { - QAction *entityAction = new QAction(QLatin1String(entries[i].text), - htmlMenu); - entityAction->setData(QLatin1String(entries[i].entity)); - htmlMenu->addAction(entityAction); - } - - menu->addMenu(htmlMenu); - connect(htmlMenu, SIGNAL(triggered(QAction*)), - SLOT(actionTriggered(QAction*))); - menu->exec(event->globalPos()); - delete menu; + QMenu *menu = createStandardContextMenu(); + QMenu *htmlMenu = new QMenu(tr("Insert HTML entity"), menu); + + typedef struct { + const char *text; + const char *entity; + } Entry; + + const Entry entries[] = { + { "&& (&&)", "&" }, + { "& ", " " }, + { "&< (<)", "<" }, + { "&> (>)", ">" }, + { "&© (Copyright)", "©" }, + { "&® (Trade Mark)", "®" }, + }; + + for (int i = 0; i < 6; ++i) { + QAction *entityAction = new QAction(QLatin1String(entries[i].text), + htmlMenu); + entityAction->setData(QLatin1String(entries[i].entity)); + htmlMenu->addAction(entityAction); + } + + menu->addMenu(htmlMenu); + connect(htmlMenu, SIGNAL(triggered(QAction*)), + SLOT(actionTriggered(QAction*))); + menu->exec(event->globalPos()); + delete menu; } void HtmlTextEdit::actionTriggered(QAction *action) { - insertPlainText(action->data().toString()); + insertPlainText(action->data().toString()); } class ColorAction : public QAction { - Q_OBJECT - -public: - ColorAction(QObject *parent); - - const QColor& color() const { return m_color; } - void setColor(const QColor &color); - -signals: - void colorChanged(const QColor &color); - -private slots: - void chooseColor(); - -private: - QColor m_color; + Q_OBJECT + + public: + ColorAction(QObject *parent); + + const QColor& color() const { return m_color; } + void setColor(const QColor &color); + + signals: + void colorChanged(const QColor &color); + + private slots: + void chooseColor(); + + private: + QColor m_color; }; ColorAction::ColorAction(QObject *parent): - QAction(parent) + QAction(parent) { - setText(tr("Text Color")); - setColor(Qt::black); - connect(this, SIGNAL(triggered()), this, SLOT(chooseColor())); + setText(tr("Text Color")); + setColor(Qt::black); + connect(this, SIGNAL(triggered()), this, SLOT(chooseColor())); } void ColorAction::setColor(const QColor &color) { - if (color == m_color) - return; - m_color = color; - QPixmap pix(24, 24); - QPainter painter(&pix); - painter.setRenderHint(QPainter::Antialiasing, false); - painter.fillRect(pix.rect(), m_color); - painter.setPen(m_color.darker()); - painter.drawRect(pix.rect().adjusted(0, 0, -1, -1)); - setIcon(pix); + if (color == m_color) + return; + m_color = color; + QPixmap pix(24, 24); + QPainter painter(&pix); + painter.setRenderHint(QPainter::Antialiasing, false); + painter.fillRect(pix.rect(), m_color); + painter.setPen(m_color.darker()); + painter.drawRect(pix.rect().adjusted(0, 0, -1, -1)); + setIcon(pix); } void ColorAction::chooseColor() { - const QColor col = QColorDialog::getColor(m_color, nullptr); - if (col.isValid() && col != m_color) { - setColor(col); - emit colorChanged(m_color); - } + const QColor col = QColorDialog::getColor(m_color, nullptr); + if (col.isValid() && col != m_color) { + setColor(col); + emit colorChanged(m_color); + } } class RichTextEditorToolBar : public QToolBar { - Q_OBJECT -public: - RichTextEditorToolBar(RichTextEditor *editor, - QWidget *parent = nullptr); - -public slots: - void updateActions(); - -private slots: - void alignmentActionTriggered(QAction *action); - void sizeInputActivated(const QString &size); - void colorChanged(const QColor &color); - void setVAlignSuper(bool super); - void setVAlignSub(bool sub); - void insertLink(); - void insertImage(); - - -private: - QAction *m_bold_action; - QAction *m_italic_action; - QAction *m_underline_action; - QAction *m_valign_sup_action; - QAction *m_valign_sub_action; - QAction *m_align_left_action; - QAction *m_align_center_action; - QAction *m_align_right_action; - QAction *m_align_justify_action; - QAction *m_link_action; - QAction *m_image_action; - QAction *m_simplify_richtext_action; - ColorAction *m_color_action; - QComboBox *m_font_size_input; - - QPointer m_editor; + Q_OBJECT + public: + RichTextEditorToolBar(RichTextEditor *editor, + QWidget *parent = nullptr); + + public slots: + void updateActions(); + + private slots: + void alignmentActionTriggered(QAction *action); + void sizeInputActivated(const QString &size); + void colorChanged(const QColor &color); + void setVAlignSuper(bool super); + void setVAlignSub(bool sub); + void insertLink(); + void insertImage(); + + + private: + QAction *m_bold_action; + QAction *m_italic_action; + QAction *m_underline_action; + QAction *m_valign_sup_action; + QAction *m_valign_sub_action; + QAction *m_align_left_action; + QAction *m_align_center_action; + QAction *m_align_right_action; + QAction *m_align_justify_action; + QAction *m_link_action; + QAction *m_image_action; + QAction *m_simplify_richtext_action; + ColorAction *m_color_action; + QComboBox *m_font_size_input; + + QPointer m_editor; }; static QAction *createCheckableAction(const QIcon &icon, const QString &text, - QObject *receiver, const char *slot, - QObject *parent = nullptr) + QObject *receiver, const char *slot, + QObject *parent = nullptr) { - QAction *result = new QAction(parent); - result->setIcon(icon); - result->setText(text); - result->setCheckable(true); - result->setChecked(false); - if (slot) - QObject::connect(result, SIGNAL(triggered(bool)), receiver, slot); - return result; + QAction *result = new QAction(parent); + result->setIcon(icon); + result->setText(text); + result->setCheckable(true); + result->setChecked(false); + if (slot) + QObject::connect(result, SIGNAL(triggered(bool)), receiver, slot); + return result; } RichTextEditorToolBar::RichTextEditorToolBar(RichTextEditor *editor, - QWidget *parent) : - QToolBar(parent), - m_link_action(new QAction(this)), - m_image_action(new QAction(this)), - m_color_action(new ColorAction(this)), - m_font_size_input(new QComboBox), - m_editor(editor) + QWidget *parent) : + QToolBar(parent), + m_link_action(new QAction(this)), + m_image_action(new QAction(this)), + m_color_action(new ColorAction(this)), + m_font_size_input(new QComboBox), + m_editor(editor) { - - // Font size combo box - m_font_size_input->setEditable(false); - const QList font_sizes = QFontDatabase::standardSizes(); - foreach (int font_size, font_sizes) - m_font_size_input->addItem(QString::number(font_size)); - - connect(m_font_size_input, SIGNAL(activated(QString)), - this, SLOT(sizeInputActivated(QString))); - addWidget(m_font_size_input); - - - // Bold, italic and underline buttons - - m_bold_action = createCheckableAction( - QIcon(":/ico/32x32/format-text-bold.png"), - tr("Texte en gras"), editor, SLOT(setFontBold(bool)), this); - m_bold_action->setShortcut(tr("CTRL+B")); - addAction(m_bold_action); - - m_italic_action = createCheckableAction( - QIcon(":/ico/32x32/format-text-italic.png"), - tr("Texte en italique"), editor, SLOT(setFontItalic(bool)), this); - m_italic_action->setShortcut(tr("CTRL+I")); - addAction(m_italic_action); - - m_underline_action = createCheckableAction( - QIcon(":/ico/32x32/format-text-underline.png"), - tr("Texte souligé"), editor, SLOT(setFontUnderline(bool)), this); - m_underline_action->setShortcut(tr("CTRL+U")); - addAction(m_underline_action); - - - // Left, center, right and justified alignment buttons - - QActionGroup *alignment_group = new QActionGroup(this); - connect(alignment_group, SIGNAL(triggered(QAction*)), - SLOT(alignmentActionTriggered(QAction*))); - - m_align_left_action = createCheckableAction( - QIcon(), - tr("Left Align"), editor, nullptr, alignment_group); - addAction(m_align_left_action); - - m_align_center_action = createCheckableAction( - QIcon(), - tr("Center"), editor, nullptr, alignment_group); - addAction(m_align_center_action); - - m_align_right_action = createCheckableAction( - QIcon(), - tr("Right Align"), editor, nullptr, alignment_group); - addAction(m_align_right_action); - - m_align_justify_action = createCheckableAction( - QIcon(), - tr("Justify"), editor, nullptr, alignment_group); - addAction(m_align_justify_action); - + + // Font size combo box + m_font_size_input->setEditable(false); + const QList font_sizes = QFontDatabase::standardSizes(); + foreach (int font_size, font_sizes) + m_font_size_input->addItem(QString::number(font_size)); + + connect(m_font_size_input, SIGNAL(activated(QString)), + this, SLOT(sizeInputActivated(QString))); + addWidget(m_font_size_input); + + + // Bold, italic and underline buttons + + m_bold_action = createCheckableAction( + QIcon(":/ico/32x32/format-text-bold.png"), + tr("Texte en gras"), editor, SLOT(setFontBold(bool)), this); + m_bold_action->setShortcut(tr("CTRL+B")); + addAction(m_bold_action); + + m_italic_action = createCheckableAction( + QIcon(":/ico/32x32/format-text-italic.png"), + tr("Texte en italique"), editor, SLOT(setFontItalic(bool)), this); + m_italic_action->setShortcut(tr("CTRL+I")); + addAction(m_italic_action); + + m_underline_action = createCheckableAction( + QIcon(":/ico/32x32/format-text-underline.png"), + tr("Texte souligé"), editor, SLOT(setFontUnderline(bool)), this); + m_underline_action->setShortcut(tr("CTRL+U")); + addAction(m_underline_action); + + + // Left, center, right and justified alignment buttons + + QActionGroup *alignment_group = new QActionGroup(this); + connect(alignment_group, SIGNAL(triggered(QAction*)), + SLOT(alignmentActionTriggered(QAction*))); + + m_align_left_action = createCheckableAction( + QIcon(), + tr("Left Align"), editor, nullptr, alignment_group); + addAction(m_align_left_action); + + m_align_center_action = createCheckableAction( + QIcon(), + tr("Center"), editor, nullptr, alignment_group); + addAction(m_align_center_action); + + m_align_right_action = createCheckableAction( + QIcon(), + tr("Right Align"), editor, nullptr, alignment_group); + addAction(m_align_right_action); + + m_align_justify_action = createCheckableAction( + QIcon(), + tr("Justify"), editor, nullptr, alignment_group); + addAction(m_align_justify_action); + m_align_justify_action -> setVisible( false ); - m_align_center_action -> setVisible( false ); - m_align_left_action -> setVisible( false ); - m_align_right_action -> setVisible( false ); - - // Superscript and subscript buttons - - m_valign_sup_action = createCheckableAction( - QIcon(":/ico/22x22/format-text-superscript.png"), - tr("Superscript"), - this, SLOT(setVAlignSuper(bool)), this); - addAction(m_valign_sup_action); - - m_valign_sub_action = createCheckableAction( - QIcon(":/ico/22x22/format-text-subscript.png"), - tr("Subscript"), - this, SLOT(setVAlignSub(bool)), this); - addAction(m_valign_sub_action); + m_align_center_action -> setVisible( false ); + m_align_left_action -> setVisible( false ); + m_align_right_action -> setVisible( false ); + + // Superscript and subscript buttons + + m_valign_sup_action = createCheckableAction( + QIcon(":/ico/22x22/format-text-superscript.png"), + tr("Superscript"), + this, SLOT(setVAlignSuper(bool)), this); + addAction(m_valign_sup_action); + + m_valign_sub_action = createCheckableAction( + QIcon(":/ico/22x22/format-text-subscript.png"), + tr("Subscript"), + this, SLOT(setVAlignSub(bool)), this); + addAction(m_valign_sub_action); m_valign_sup_action -> setVisible( true ); m_valign_sub_action -> setVisible( true ); - - // Insert hyperlink and image buttons - + + // Insert hyperlink and image buttons + m_link_action->setText(tr("Insérer un lien")); - connect(m_link_action, SIGNAL(triggered()), SLOT(insertLink())); - addAction(m_link_action); - - m_image_action->setText(tr("Insert &Image")); - connect(m_image_action, SIGNAL(triggered()), SLOT(insertImage())); - addAction(m_image_action); - + connect(m_link_action, SIGNAL(triggered()), SLOT(insertLink())); + addAction(m_link_action); + + m_image_action->setText(tr("Insert &Image")); + connect(m_image_action, SIGNAL(triggered()), SLOT(insertImage())); + addAction(m_image_action); + m_image_action -> setVisible( false ); - addSeparator(); - + addSeparator(); + // Text color button connect(m_color_action, SIGNAL(colorChanged(QColor)), - this, SLOT(colorChanged(QColor))); - addAction(m_color_action); - - - // Simplify rich text - m_simplify_richtext_action = createCheckableAction( - QIcon(":/ico/32x32/simplifyrichtext.png"), - tr("Simplify Rich Text"), editor, SLOT(setSimplifyRichText(bool)),this); - m_simplify_richtext_action->setChecked(editor->simplifyRichText()); - connect(m_editor, SIGNAL(simplifyRichTextChanged(bool)), - m_simplify_richtext_action, SLOT(setChecked(bool))); - addAction(m_simplify_richtext_action); - - connect(editor, SIGNAL(textChanged()), this, SLOT(updateActions())); - connect(editor, SIGNAL(stateChanged()), this, SLOT(updateActions())); - - updateActions(); + this, SLOT(colorChanged(QColor))); + addAction(m_color_action); + + + // Simplify rich text + m_simplify_richtext_action = createCheckableAction( + QIcon(":/ico/32x32/simplifyrichtext.png"), + tr("Simplify Rich Text"), editor, SLOT(setSimplifyRichText(bool)),this); + m_simplify_richtext_action->setChecked(editor->simplifyRichText()); + connect(m_editor, SIGNAL(simplifyRichTextChanged(bool)), + m_simplify_richtext_action, SLOT(setChecked(bool))); + addAction(m_simplify_richtext_action); + + connect(editor, SIGNAL(textChanged()), this, SLOT(updateActions())); + connect(editor, SIGNAL(stateChanged()), this, SLOT(updateActions())); + + updateActions(); } void RichTextEditorToolBar::alignmentActionTriggered(QAction *action) { - Qt::Alignment new_alignment; - - if (action == m_align_left_action) { - new_alignment = Qt::AlignLeft; - } else if (action == m_align_center_action) { - new_alignment = Qt::AlignCenter; - } else if (action == m_align_right_action) { - new_alignment = Qt::AlignRight; - } else { - new_alignment = Qt::AlignJustify; - } - - m_editor->setAlignment(new_alignment); + Qt::Alignment new_alignment; + + if (action == m_align_left_action) { + new_alignment = Qt::AlignLeft; + } else if (action == m_align_center_action) { + new_alignment = Qt::AlignCenter; + } else if (action == m_align_right_action) { + new_alignment = Qt::AlignRight; + } else { + new_alignment = Qt::AlignJustify; + } + + m_editor->setAlignment(new_alignment); } void RichTextEditorToolBar::colorChanged(const QColor &color) { - m_editor->setTextColor(color); - m_editor->setFocus(); + m_editor->setTextColor(color); + m_editor->setFocus(); } void RichTextEditorToolBar::sizeInputActivated(const QString &size) { - bool ok; - int i = size.toInt(&ok); - if (!ok) - return; - - m_editor->setFontPointSize(i); - m_editor->setFocus(); + bool ok; + int i = size.toInt(&ok); + if (!ok) + return; + + m_editor->setFontPointSize(i); + m_editor->setFocus(); } void RichTextEditorToolBar::setVAlignSuper(bool super) { - const QTextCharFormat::VerticalAlignment align = super ? - QTextCharFormat::AlignSuperScript : QTextCharFormat::AlignNormal; - - QTextCharFormat charFormat = m_editor->currentCharFormat(); - charFormat.setVerticalAlignment(align); - m_editor->setCurrentCharFormat(charFormat); - - m_valign_sub_action->setChecked(false); + const QTextCharFormat::VerticalAlignment align = super ? + QTextCharFormat::AlignSuperScript : QTextCharFormat::AlignNormal; + + QTextCharFormat charFormat = m_editor->currentCharFormat(); + charFormat.setVerticalAlignment(align); + m_editor->setCurrentCharFormat(charFormat); + + m_valign_sub_action->setChecked(false); } void RichTextEditorToolBar::setVAlignSub(bool sub) { - const QTextCharFormat::VerticalAlignment align = sub ? - QTextCharFormat::AlignSubScript : QTextCharFormat::AlignNormal; - - QTextCharFormat charFormat = m_editor->currentCharFormat(); - charFormat.setVerticalAlignment(align); - m_editor->setCurrentCharFormat(charFormat); - - m_valign_sup_action->setChecked(false); + const QTextCharFormat::VerticalAlignment align = sub ? + QTextCharFormat::AlignSubScript : QTextCharFormat::AlignNormal; + + QTextCharFormat charFormat = m_editor->currentCharFormat(); + charFormat.setVerticalAlignment(align); + m_editor->setCurrentCharFormat(charFormat); + + m_valign_sup_action->setChecked(false); } void RichTextEditorToolBar::insertLink() { - AddLinkDialog linkDialog(m_editor, this); - linkDialog.showDialog(); - m_editor->setFocus(); + AddLinkDialog linkDialog(m_editor, this); + linkDialog.showDialog(); + m_editor->setFocus(); } void RichTextEditorToolBar::insertImage() { #ifdef hip - const QString path = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), QString(), this); - if (!path.isEmpty()) - m_editor->insertHtml(QLatin1String("")); + const QString path = IconSelector::choosePixmapResource(m_core, m_core->resourceModel(), QString(), this); + if (!path.isEmpty()) + m_editor->insertHtml(QLatin1String("")); #endif } void RichTextEditorToolBar::updateActions() { - if (m_editor == nullptr) { - setEnabled(false); - return; - } - - const Qt::Alignment alignment = m_editor->alignment(); - const QTextCursor cursor = m_editor->textCursor(); - const QTextCharFormat charFormat = cursor.charFormat(); - const QFont font = charFormat.font(); - const QTextCharFormat::VerticalAlignment valign = - charFormat.verticalAlignment(); - const bool superScript = valign == QTextCharFormat::AlignSuperScript; - const bool subScript = valign == QTextCharFormat::AlignSubScript; - - if (alignment & Qt::AlignLeft) { - m_align_left_action->setChecked(true); - } else if (alignment & Qt::AlignRight) { - m_align_right_action->setChecked(true); - } else if (alignment & Qt::AlignHCenter) { - m_align_center_action->setChecked(true); - } else { - m_align_justify_action->setChecked(true); - } - - m_bold_action->setChecked(font.bold()); - m_italic_action->setChecked(font.italic()); - m_underline_action->setChecked(font.underline()); - m_valign_sup_action->setChecked(superScript); - m_valign_sub_action->setChecked(subScript); - - const int size = font.pointSize(); - const int idx = m_font_size_input->findText(QString::number(size)); - if (idx != -1) - m_font_size_input->setCurrentIndex(idx); - - m_color_action->setColor(m_editor->textColor()); + if (m_editor == nullptr) { + setEnabled(false); + return; + } + + const Qt::Alignment alignment = m_editor->alignment(); + const QTextCursor cursor = m_editor->textCursor(); + const QTextCharFormat charFormat = cursor.charFormat(); + const QFont font = charFormat.font(); + const QTextCharFormat::VerticalAlignment valign = + charFormat.verticalAlignment(); + const bool superScript = valign == QTextCharFormat::AlignSuperScript; + const bool subScript = valign == QTextCharFormat::AlignSubScript; + + if (alignment & Qt::AlignLeft) { + m_align_left_action->setChecked(true); + } else if (alignment & Qt::AlignRight) { + m_align_right_action->setChecked(true); + } else if (alignment & Qt::AlignHCenter) { + m_align_center_action->setChecked(true); + } else { + m_align_justify_action->setChecked(true); + } + + m_bold_action->setChecked(font.bold()); + m_italic_action->setChecked(font.italic()); + m_underline_action->setChecked(font.underline()); + m_valign_sup_action->setChecked(superScript); + m_valign_sub_action->setChecked(subScript); + + const int size = font.pointSize(); + const int idx = m_font_size_input->findText(QString::number(size)); + if (idx != -1) + m_font_size_input->setCurrentIndex(idx); + + m_color_action->setColor(m_editor->textColor()); } RichTextEditor::RichTextEditor(QWidget *parent) - : QTextEdit(parent) + : QTextEdit(parent) { - connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)), - this, SIGNAL(stateChanged())); - connect(this, SIGNAL(cursorPositionChanged()), - this, SIGNAL(stateChanged())); + connect(this, SIGNAL(currentCharFormatChanged(QTextCharFormat)), + this, SIGNAL(stateChanged())); + connect(this, SIGNAL(cursorPositionChanged()), + this, SIGNAL(stateChanged())); } QToolBar *RichTextEditor::createToolBar(QWidget *parent) { - return new RichTextEditorToolBar(this, parent); + return new RichTextEditorToolBar(this, parent); } void RichTextEditor::setFontBold(bool b) { - if (b) - setFontWeight(QFont::Bold); - else - setFontWeight(QFont::Normal); + if (b) + setFontWeight(QFont::Bold); + else + setFontWeight(QFont::Normal); } void RichTextEditor::setFontPointSize(double d) { - QTextEdit::setFontPointSize(qreal(d)); + QTextEdit::setFontPointSize(qreal(d)); } void RichTextEditor::setText(const QString &text) { - if (Qt::mightBeRichText(text)) - setHtml(text); - else - setPlainText(text); + if (Qt::mightBeRichText(text)) + setHtml(text); + else + setPlainText(text); } void RichTextEditor::setSimplifyRichText(bool v) { - if (v != m_simplifyRichText) { - m_simplifyRichText = v; - emit simplifyRichTextChanged(v); - } + if (v != m_simplifyRichText) { + m_simplifyRichText = v; + emit simplifyRichTextChanged(v); + } } void RichTextEditor::setDefaultFont(QFont font) { - // Some default fonts on Windows have a default size of 7.8, - // which results in complicated rich text generated by toHtml(). - // Use an integer value. - const int pointSize = qRound(font.pointSizeF()); - if (pointSize > 0 && !qFuzzyCompare(qreal(pointSize), font.pointSizeF())) { - font.setPointSize(pointSize); - } - - document()->setDefaultFont(font); - if (font.pointSize() > 0) - setFontPointSize(font.pointSize()); - else - setFontPointSize(QFontInfo(font).pointSize()); - emit textChanged(); + // Some default fonts on Windows have a default size of 7.8, + // which results in complicated rich text generated by toHtml(). + // Use an integer value. + const int pointSize = qRound(font.pointSizeF()); + if (pointSize > 0 && !qFuzzyCompare(qreal(pointSize), font.pointSizeF())) { + font.setPointSize(pointSize); + } + + document()->setDefaultFont(font); + if (font.pointSize() > 0) + setFontPointSize(font.pointSize()); + else + setFontPointSize(QFontInfo(font).pointSize()); + emit textChanged(); } QString RichTextEditor::text(Qt::TextFormat format) const { - switch (format) { - case Qt::PlainText: - return toPlainText(); - case Qt::RichText: - return m_simplifyRichText ? simplifyRichTextFilter(toHtml()) : toHtml(); - case Qt::AutoText: - break; + switch (format) { + case Qt::PlainText: + return toPlainText(); + case Qt::RichText: + return m_simplifyRichText ? simplifyRichTextFilter(toHtml()) : toHtml(); + case Qt::AutoText: + break; #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) #else - case Qt::MarkdownText: //This enum value was added in Qt 5.14. - break; + case Qt::MarkdownText: //This enum value was added in Qt 5.14. + break; #endif - default: - qInfo("(RichTextEditor::text) no valid switch: %d",format); - break; - } - const QString html = toHtml(); - bool isPlainText; - const QString simplifiedHtml = simplifyRichTextFilter(html, &isPlainText); - if (isPlainText) - return toPlainText(); - return m_simplifyRichText ? simplifiedHtml : html; + default: + qInfo("(RichTextEditor::text) no valid switch: %d",format); + break; + } + const QString html = toHtml(); + bool isPlainText; + const QString simplifiedHtml = simplifyRichTextFilter(html, &isPlainText); + if (isPlainText) + return toPlainText(); + return m_simplifyRichText ? simplifiedHtml : html; } RichTextEditorDialog::RichTextEditorDialog(QWidget *parent) : - QDialog(parent), - m_editor(new RichTextEditor()), - m_text_edit(new HtmlTextEdit), - m_tab_widget(new QTabWidget), - m_state(Clean) + QDialog(parent), + m_editor(new RichTextEditor()), + m_text_edit(new HtmlTextEdit), + m_tab_widget(new QTabWidget), + m_state(Clean) { - setWindowTitle(tr("Edit text")); - setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - - m_text_edit->setAcceptRichText(false); - - connect(m_editor, SIGNAL(textChanged()), this, SLOT(richTextChanged())); - connect(m_editor, SIGNAL(simplifyRichTextChanged(bool)), this, SLOT(richTextChanged())); - connect(m_text_edit, SIGNAL(textChanged()), this, SLOT(sourceChanged())); - - // The toolbar needs to be created after the RichTextEditor - QToolBar *tool_bar = m_editor->createToolBar(); - tool_bar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); - - QWidget *rich_edit = new QWidget; - QVBoxLayout *rich_edit_layout = new QVBoxLayout(rich_edit); - rich_edit_layout->addWidget(tool_bar); - rich_edit_layout->addWidget(m_editor); - - QWidget *plain_edit = new QWidget; - QVBoxLayout *plain_edit_layout = new QVBoxLayout(plain_edit); - plain_edit_layout->addWidget(m_text_edit); - - m_tab_widget->setTabPosition(QTabWidget::South); - m_tab_widget->addTab(rich_edit, tr("Rich Text")); - m_tab_widget->addTab(plain_edit, tr("Source")); - connect(m_tab_widget, SIGNAL(currentChanged(int)), - SLOT(tabIndexChanged(int))); - - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal); - QPushButton *ok_button = buttonBox->button(QDialogButtonBox::Ok); - ok_button->setText(tr("&OK")); - ok_button->setDefault(true); - buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("&Cancel")); - connect(buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - - QVBoxLayout *layout = new QVBoxLayout(this); - layout->addWidget(m_tab_widget); - layout->addWidget(buttonBox); - - m_editor->setFocus(); - + setWindowTitle(tr("Edit text")); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + m_text_edit->setAcceptRichText(false); + + connect(m_editor, SIGNAL(textChanged()), this, SLOT(richTextChanged())); + connect(m_editor, SIGNAL(simplifyRichTextChanged(bool)), this, SLOT(richTextChanged())); + connect(m_text_edit, SIGNAL(textChanged()), this, SLOT(sourceChanged())); + + // The toolbar needs to be created after the RichTextEditor + QToolBar *tool_bar = m_editor->createToolBar(); + tool_bar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); + + QWidget *rich_edit = new QWidget; + QVBoxLayout *rich_edit_layout = new QVBoxLayout(rich_edit); + rich_edit_layout->addWidget(tool_bar); + rich_edit_layout->addWidget(m_editor); + + QWidget *plain_edit = new QWidget; + QVBoxLayout *plain_edit_layout = new QVBoxLayout(plain_edit); + plain_edit_layout->addWidget(m_text_edit); + + m_tab_widget->setTabPosition(QTabWidget::South); + m_tab_widget->addTab(rich_edit, tr("Rich Text")); + m_tab_widget->addTab(plain_edit, tr("Source")); + connect(m_tab_widget, SIGNAL(currentChanged(int)), + SLOT(tabIndexChanged(int))); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal); + QPushButton *ok_button = buttonBox->button(QDialogButtonBox::Ok); + ok_button->setText(tr("&OK")); + ok_button->setDefault(true); + buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("&Cancel")); + connect(buttonBox, SIGNAL(accepted()), this, SLOT(on_buttonBox_accepted())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + QVBoxLayout *layout = new QVBoxLayout(this); + layout->addWidget(m_tab_widget); + layout->addWidget(buttonBox); + + m_editor->setFocus(); + } RichTextEditorDialog::~RichTextEditorDialog() @@ -820,77 +820,77 @@ void RichTextEditorDialog::on_buttonBox_accepted() { int RichTextEditorDialog::showDialog() { - m_tab_widget->setCurrentIndex(0); - m_editor->selectAll(); - m_editor->setFocus(); - - return exec(); + m_tab_widget->setCurrentIndex(0); + m_editor->selectAll(); + m_editor->setFocus(); + + return exec(); } void RichTextEditorDialog::setDefaultFont(const QFont &font) { - m_editor->setDefaultFont(font); + m_editor->setDefaultFont(font); } void RichTextEditorDialog::setText(const QString &text) { - // Generally simplify rich text unless verbose text is found. - const bool isSimplifiedRichText = !text.startsWith(""); - m_editor->setSimplifyRichText(isSimplifiedRichText); - m_editor->setText(text); - m_text_edit->setPlainText(text); - m_state = Clean; + // Generally simplify rich text unless verbose text is found. + const bool isSimplifiedRichText = !text.startsWith(""); + m_editor->setSimplifyRichText(isSimplifiedRichText); + m_editor->setText(text); + m_text_edit->setPlainText(text); + m_state = Clean; } QString RichTextEditorDialog::text(Qt::TextFormat format) const { - // In autotext mode, if the user has changed the source, use that - if (format == Qt::AutoText && (m_state == Clean || m_state == SourceChanged)) - return m_text_edit->toPlainText(); - // If the plain text HTML editor is selected, first copy its contents over - // to the rich text editor so that it is converted to Qt-HTML or actual - // plain text. - if (m_tab_widget->currentIndex() == SourceIndex && m_state == SourceChanged) - m_editor->setHtml(m_text_edit->toPlainText()); - return m_editor->text(format); + // In autotext mode, if the user has changed the source, use that + if (format == Qt::AutoText && (m_state == Clean || m_state == SourceChanged)) + return m_text_edit->toPlainText(); + // If the plain text HTML editor is selected, first copy its contents over + // to the rich text editor so that it is converted to Qt-HTML or actual + // plain text. + if (m_tab_widget->currentIndex() == SourceIndex && m_state == SourceChanged) + m_editor->setHtml(m_text_edit->toPlainText()); + return m_editor->text(format); } void RichTextEditorDialog::tabIndexChanged(int newIndex) { - // Anything changed, is there a need for a conversion? - if (newIndex == SourceIndex && m_state != RichTextChanged) - return; - if (newIndex == RichTextIndex && m_state != SourceChanged) - return; - const State oldState = m_state; - // Remember the cursor position, since it is invalidated by setPlainText - QTextEdit *new_edit = (newIndex == SourceIndex) ? m_text_edit : m_editor; - const int position = new_edit->textCursor().position(); - - if (newIndex == SourceIndex) { - const QString html = m_editor->text(Qt::RichText); - m_text_edit->setPlainText(html); - - } else - m_editor->setHtml(m_text_edit->toPlainText()); - - QTextCursor cursor = new_edit->textCursor(); - cursor.movePosition(QTextCursor::End); - if (cursor.position() > position) { - cursor.setPosition(position); - } - new_edit->setTextCursor(cursor); - m_state = oldState; // Changed is triggered by setting the text + // Anything changed, is there a need for a conversion? + if (newIndex == SourceIndex && m_state != RichTextChanged) + return; + if (newIndex == RichTextIndex && m_state != SourceChanged) + return; + const State oldState = m_state; + // Remember the cursor position, since it is invalidated by setPlainText + QTextEdit *new_edit = (newIndex == SourceIndex) ? m_text_edit : m_editor; + const int position = new_edit->textCursor().position(); + + if (newIndex == SourceIndex) { + const QString html = m_editor->text(Qt::RichText); + m_text_edit->setPlainText(html); + + } else + m_editor->setHtml(m_text_edit->toPlainText()); + + QTextCursor cursor = new_edit->textCursor(); + cursor.movePosition(QTextCursor::End); + if (cursor.position() > position) { + cursor.setPosition(position); + } + new_edit->setTextCursor(cursor); + m_state = oldState; // Changed is triggered by setting the text } void RichTextEditorDialog::richTextChanged() { - m_state = RichTextChanged; + m_state = RichTextChanged; } void RichTextEditorDialog::sourceChanged() { - m_state = SourceChanged; + m_state = SourceChanged; } } // namespace qdesigner_internal diff --git a/sources/richtext/ui_addlinkdialog.h b/sources/richtext/ui_addlinkdialog.h index 2c38f6d9b..c1134fd98 100644 --- a/sources/richtext/ui_addlinkdialog.h +++ b/sources/richtext/ui_addlinkdialog.h @@ -29,87 +29,87 @@ QT_BEGIN_NAMESPACE class Ui_AddLinkDialog { public: - QVBoxLayout *verticalLayout; - QFormLayout *formLayout; - QLabel *label; - QLineEdit *titleInput; - QLabel *label_2; - QLineEdit *urlInput; - QSpacerItem *verticalSpacer; - QFrame *line; - QDialogButtonBox *buttonBox; - - void setupUi(QDialog *AddLinkDialog) - { - if (AddLinkDialog->objectName().isEmpty()) - AddLinkDialog->setObjectName(QString::fromUtf8("AddLinkDialog")); - AddLinkDialog->setSizeGripEnabled(false); - AddLinkDialog->setModal(true); - verticalLayout = new QVBoxLayout(AddLinkDialog); - verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); - formLayout = new QFormLayout(); - formLayout->setObjectName(QString::fromUtf8("formLayout")); - label = new QLabel(AddLinkDialog); - label->setObjectName(QString::fromUtf8("label")); - - formLayout->setWidget(0, QFormLayout::LabelRole, label); - - titleInput = new QLineEdit(AddLinkDialog); - titleInput->setObjectName(QString::fromUtf8("titleInput")); - titleInput->setMinimumSize(QSize(337, 0)); - - formLayout->setWidget(0, QFormLayout::FieldRole, titleInput); - - label_2 = new QLabel(AddLinkDialog); - label_2->setObjectName(QString::fromUtf8("label_2")); - - formLayout->setWidget(1, QFormLayout::LabelRole, label_2); - - urlInput = new QLineEdit(AddLinkDialog); - urlInput->setObjectName(QString::fromUtf8("urlInput")); - - formLayout->setWidget(1, QFormLayout::FieldRole, urlInput); - - - verticalLayout->addLayout(formLayout); - - verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); - - verticalLayout->addItem(verticalSpacer); - - line = new QFrame(AddLinkDialog); - line->setObjectName(QString::fromUtf8("line")); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - - verticalLayout->addWidget(line); - - buttonBox = new QDialogButtonBox(AddLinkDialog); - buttonBox->setObjectName(QString::fromUtf8("buttonBox")); - buttonBox->setOrientation(Qt::Horizontal); - buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); - - verticalLayout->addWidget(buttonBox); - - - retranslateUi(AddLinkDialog); - QObject::connect(buttonBox, SIGNAL(accepted()), AddLinkDialog, SLOT(accept())); - QObject::connect(buttonBox, SIGNAL(rejected()), AddLinkDialog, SLOT(reject())); - - QMetaObject::connectSlotsByName(AddLinkDialog); - } // setupUi - - void retranslateUi(QDialog *AddLinkDialog) - { + QVBoxLayout *verticalLayout; + QFormLayout *formLayout; + QLabel *label; + QLineEdit *titleInput; + QLabel *label_2; + QLineEdit *urlInput; + QSpacerItem *verticalSpacer; + QFrame *line; + QDialogButtonBox *buttonBox; + + void setupUi(QDialog *AddLinkDialog) + { + if (AddLinkDialog->objectName().isEmpty()) + AddLinkDialog->setObjectName(QString::fromUtf8("AddLinkDialog")); + AddLinkDialog->setSizeGripEnabled(false); + AddLinkDialog->setModal(true); + verticalLayout = new QVBoxLayout(AddLinkDialog); + verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); + formLayout = new QFormLayout(); + formLayout->setObjectName(QString::fromUtf8("formLayout")); + label = new QLabel(AddLinkDialog); + label->setObjectName(QString::fromUtf8("label")); + + formLayout->setWidget(0, QFormLayout::LabelRole, label); + + titleInput = new QLineEdit(AddLinkDialog); + titleInput->setObjectName(QString::fromUtf8("titleInput")); + titleInput->setMinimumSize(QSize(337, 0)); + + formLayout->setWidget(0, QFormLayout::FieldRole, titleInput); + + label_2 = new QLabel(AddLinkDialog); + label_2->setObjectName(QString::fromUtf8("label_2")); + + formLayout->setWidget(1, QFormLayout::LabelRole, label_2); + + urlInput = new QLineEdit(AddLinkDialog); + urlInput->setObjectName(QString::fromUtf8("urlInput")); + + formLayout->setWidget(1, QFormLayout::FieldRole, urlInput); + + + verticalLayout->addLayout(formLayout); + + verticalSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + + verticalLayout->addItem(verticalSpacer); + + line = new QFrame(AddLinkDialog); + line->setObjectName(QString::fromUtf8("line")); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + + verticalLayout->addWidget(line); + + buttonBox = new QDialogButtonBox(AddLinkDialog); + buttonBox->setObjectName(QString::fromUtf8("buttonBox")); + buttonBox->setOrientation(Qt::Horizontal); + buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); + + verticalLayout->addWidget(buttonBox); + + + retranslateUi(AddLinkDialog); + QObject::connect(buttonBox, SIGNAL(accepted()), AddLinkDialog, SLOT(accept())); + QObject::connect(buttonBox, SIGNAL(rejected()), AddLinkDialog, SLOT(reject())); + + QMetaObject::connectSlotsByName(AddLinkDialog); + } // setupUi + + void retranslateUi(QDialog *AddLinkDialog) + { AddLinkDialog->setWindowTitle(QApplication::translate("AddLinkDialog", "Insert Link", nullptr)); label->setText(QApplication::translate("AddLinkDialog", "Title:", nullptr)); label_2->setText(QApplication::translate("AddLinkDialog", "URL:", nullptr)); - } // retranslateUi - + } // retranslateUi + }; namespace Ui { - class AddLinkDialog: public Ui_AddLinkDialog {}; + class AddLinkDialog: public Ui_AddLinkDialog {}; } // namespace Ui QT_END_NAMESPACE diff --git a/sources/ui/bomexportdialog.cpp b/sources/ui/bomexportdialog.cpp index 84093d602..3ce6242ef 100644 --- a/sources/ui/bomexportdialog.cpp +++ b/sources/ui/bomexportdialog.cpp @@ -105,9 +105,9 @@ BOMExportDialog::BOMExportDialog(QETProject *project, QWidget *parent) : updateQueryLine(); }); - setUpItems(); - createDataBase(); - fillSavedQuery(); + setUpItems(); + createDataBase(); + fillSavedQuery(); } /** @@ -115,8 +115,8 @@ BOMExportDialog::BOMExportDialog(QETProject *project, QWidget *parent) : */ BOMExportDialog::~BOMExportDialog() { - delete ui; - m_data_base.close(); + delete ui; + m_data_base.close(); } /** @@ -126,39 +126,39 @@ BOMExportDialog::~BOMExportDialog() */ int BOMExportDialog::exec() { - int r = QDialog::exec(); - if (r == QDialog::Accepted) - { - //save in csv file - QString file_name = tr("nomenclature_") + QString(m_project ->title() + ".csv"); -// if (!file_name.endsWith(".csv")) { -// file_name += ".csv"; -// } - QString file_path = QFileDialog::getSaveFileName(this, tr("Enregister sous... "), file_name, tr("Fichiers csv (*.csv)")); - QFile file(file_path); - if (!file_path.isEmpty()) - { - if (QFile::exists(file_path )) - { - // if file already exist -> delete it - if (!QFile::remove(file_path) ) - { - QMessageBox::critical(this, tr("Erreur"), - tr("Impossible de remplacer le fichier!\n\n")+ - "Destination : "+file_path+"\n"); - } - } - if (file.open(QIODevice::WriteOnly | QIODevice::Text)) - { - QTextStream stream(&file); + int r = QDialog::exec(); + if (r == QDialog::Accepted) + { + //save in csv file + QString file_name = tr("nomenclature_") + QString(m_project ->title() + ".csv"); + // if (!file_name.endsWith(".csv")) { + // file_name += ".csv"; + // } + QString file_path = QFileDialog::getSaveFileName(this, tr("Enregister sous... "), file_name, tr("Fichiers csv (*.csv)")); + QFile file(file_path); + if (!file_path.isEmpty()) + { + if (QFile::exists(file_path )) + { + // if file already exist -> delete it + if (!QFile::remove(file_path) ) + { + QMessageBox::critical(this, tr("Erreur"), + tr("Impossible de remplacer le fichier!\n\n")+ + "Destination : "+file_path+"\n"); + } + } + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream stream(&file); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove - stream << getBom() << endl; + stream << getBom() << endl; #else - stream << getBom() << &Qt::endl(stream); + stream << getBom() << &Qt::endl(stream); #endif - } - } - } + } + } + } return r; } @@ -168,7 +168,7 @@ int BOMExportDialog::exec() */ QStringList BOMExportDialog::selectedKeys() const { - //Made a string list with the colomns (keys) choosen by the user + //Made a string list with the colomns (keys) choosen by the user QStringList keys; int row = 0; while (auto *item = ui->m_choosen_list->item(row)) @@ -176,7 +176,7 @@ QStringList BOMExportDialog::selectedKeys() const keys.append(item->data(Qt::UserRole).toString()); ++row; } - + return keys; } @@ -205,14 +205,14 @@ QString BOMExportDialog::translatedKeys(const QString &key) const */ void BOMExportDialog::setUpItems() { - for(QString key : QETApp::elementInfoKeys()) - { + for(QString key : QETApp::elementInfoKeys()) + { auto item = new QListWidgetItem(QETApp::elementTranslatedInfoKey(key), ui->m_var_list); item->setData(Qt::UserRole+1, key); //We store the real key before replace "-" by "_" to easily retrieve it in the element information item->setData(Qt::UserRole, key.replace("-", "_")); //We must to replace "-" by "_" because "-" is a sql keyword. m_items_list << item; - } - + } + for (auto key : m_export_info.keys()) { auto item = new QListWidgetItem(m_export_info.value(key), ui->m_var_list); @@ -227,11 +227,11 @@ void BOMExportDialog::setUpItems() */ void BOMExportDialog::on_m_add_pb_clicked() { - if (auto *item = ui->m_var_list->takeItem(ui->m_var_list->currentRow())) { - ui->m_choosen_list->addItem(item); - } - - updateQueryLine(); + if (auto *item = ui->m_var_list->takeItem(ui->m_var_list->currentRow())) { + ui->m_choosen_list->addItem(item); + } + + updateQueryLine(); } /** @@ -239,11 +239,11 @@ void BOMExportDialog::on_m_add_pb_clicked() */ void BOMExportDialog::on_m_remove_pb_clicked() { - if (auto *item = ui->m_choosen_list->takeItem(ui->m_choosen_list->currentRow())) { - ui->m_var_list->addItem(item); - } - - updateQueryLine(); + if (auto *item = ui->m_choosen_list->takeItem(ui->m_choosen_list->currentRow())) { + ui->m_var_list->addItem(item); + } + + updateQueryLine(); } /** @@ -251,16 +251,16 @@ void BOMExportDialog::on_m_remove_pb_clicked() */ void BOMExportDialog::on_m_up_pb_clicked() { - auto row = ui->m_choosen_list->currentRow(); - if(row <= 0) { - return; - } - - auto *item = ui->m_choosen_list->takeItem(row); - ui->m_choosen_list->insertItem(row-1, item); - ui->m_choosen_list->setCurrentItem(item); - - updateQueryLine(); + auto row = ui->m_choosen_list->currentRow(); + if(row <= 0) { + return; + } + + auto *item = ui->m_choosen_list->takeItem(row); + ui->m_choosen_list->insertItem(row-1, item); + ui->m_choosen_list->setCurrentItem(item); + + updateQueryLine(); } /** @@ -268,20 +268,20 @@ void BOMExportDialog::on_m_up_pb_clicked() */ void BOMExportDialog::on_m_down_pb_clicked() { - auto row = ui->m_choosen_list->currentRow(); - if (row == -1) { - return; - } - - auto *item = ui->m_choosen_list->takeItem(row); - ui->m_choosen_list->insertItem(row+1, item); - ui->m_choosen_list->setCurrentItem(item); - - updateQueryLine(); + auto row = ui->m_choosen_list->currentRow(); + if (row == -1) { + return; + } + + auto *item = ui->m_choosen_list->takeItem(row); + ui->m_choosen_list->insertItem(row+1, item); + ui->m_choosen_list->setCurrentItem(item); + + updateQueryLine(); } void BOMExportDialog::on_m_save_name_le_textChanged(const QString &arg1) { - ui->m_save_current_conf_pb->setDisabled(arg1.isEmpty()); + ui->m_save_current_conf_pb->setDisabled(arg1.isEmpty()); } /** @@ -291,17 +291,17 @@ void BOMExportDialog::on_m_save_name_le_textChanged(const QString &arg1) { */ QString BOMExportDialog::getBom() { - QString data; //The string to be returned - if (ui->m_include_header_cb->isChecked()) { - data = headers(); + QString data; //The string to be returned + if (ui->m_include_header_cb->isChecked()) { + data = headers(); data += "\n"; - } - - QSqlQuery query (queryStr() , m_data_base); - if (!query.exec()) { - qDebug() << "Query error : " << query.lastError(); - } - + } + + QSqlQuery query (queryStr() , m_data_base); + if (!query.exec()) { + qDebug() << "Query error : " << query.lastError(); + } + QStringList record; while (query.next()) { @@ -321,13 +321,13 @@ QString BOMExportDialog::getBom() record << sql_record.value(key).toString(); } } - + data += record.join(";") + "\n"; record.clear(); } - - m_data_base.close(); - return data; + + m_data_base.close(); + return data; } /** @@ -336,10 +336,10 @@ QString BOMExportDialog::getBom() */ QString BOMExportDialog::headers() const { - QString header_string; - - if (!ui->m_edit_sql_query_cb->isChecked()) - { + QString header_string; + + if (!ui->m_edit_sql_query_cb->isChecked()) + { for (auto key : selectedKeys()) { if (!header_string.isEmpty()) { @@ -347,32 +347,32 @@ QString BOMExportDialog::headers() const } header_string += translatedKeys(key); } - - header_string += "\n"; - } - else if (!queryStr().isEmpty()) //Try to retreive the header according to the sql query - { - if (queryStr().startsWith("SELECT ") && queryStr().contains("FROM")) - { - auto header = queryStr(); - header.remove(0, 7); //Remove SELECT from the string; - header.truncate(header.indexOf("FROM")); //Now we only have the string between SELECT and FROM - header.replace(" ", ""); //remove white space - QStringList list = header.split(","); - if (!list.isEmpty()) - { - for (int i=0 ; im_var_list->item(row)) - { - keys << ui->m_var_list->item(row)->data(Qt::UserRole).toString(); - ++row; - } - keys << "element_type" << "element_subtype"; + if (!m_data_base.open()) + { + m_data_base.close(); + return false; + } + + //Create the table: + QStringList keys; + auto row = 0; + while (ui->m_var_list->item(row)) + { + keys << ui->m_var_list->item(row)->data(Qt::UserRole).toString(); + ++row; + } + keys << "element_type" << "element_subtype"; keys.removeAll("designation_qty"); - - QString table("CREATE TABLE bom("); - bool first = true; - for (auto string : keys) - { - if (first) { - first = false; - } else { - table += ","; + + QString table("CREATE TABLE bom("); + bool first = true; + for (auto string : keys) + { + if (first) { + first = false; + } else { + table += ","; } - + table += string += " VARCHAR(512)"; - } - table += ");"; - m_data_base.exec(table); - - QStringList bind_values; - for (auto key : keys) { - bind_values << key.prepend(":"); - } - - //Prepare the query used for insert new record - QString insert("INSERT INTO bom (" + - keys.join(", ") + - ") VALUES (" + - bind_values.join(", ") + - ")"); - - m_insert_query = QSqlQuery(m_data_base); - m_insert_query.prepare(insert); - - populateDataBase(); - - return true; + } + table += ");"; + m_data_base.exec(table); + + QStringList bind_values; + for (auto key : keys) { + bind_values << key.prepend(":"); + } + + //Prepare the query used for insert new record + QString insert("INSERT INTO bom (" + + keys.join(", ") + + ") VALUES (" + + bind_values.join(", ") + + ")"); + + m_insert_query = QSqlQuery(m_data_base); + m_insert_query.prepare(insert); + + populateDataBase(); + + return true; } /** @@ -441,30 +441,30 @@ bool BOMExportDialog::createDataBase() */ void BOMExportDialog::populateDataBase() { - for (auto *diagram : m_project->diagrams()) - { - ElementProvider ep(diagram); - QList elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master); - - //Insert all value into the database - for (auto elmt : elements_list) - { - auto hash = elementInfoToString(elmt); - for (auto key : hash.keys()) - { - QString value = hash.value(key); - QString bind = key.prepend(":"); - m_insert_query.bindValue(bind, value); - } - - m_insert_query.bindValue(":element_type", elmt->linkTypeToString()); - m_insert_query.bindValue(":element_subtype", elmt->kindInformations()["type"].toString()); - - if (!m_insert_query.exec()) { - qDebug() << "BOMExportDialog::populateDataBase insert error : " << m_insert_query.lastError(); - } - } - } + for (auto *diagram : m_project->diagrams()) + { + ElementProvider ep(diagram); + QList elements_list = ep.find(Element::Simple | Element::Terminale | Element::Master); + + //Insert all value into the database + for (auto elmt : elements_list) + { + auto hash = elementInfoToString(elmt); + for (auto key : hash.keys()) + { + QString value = hash.value(key); + QString bind = key.prepend(":"); + m_insert_query.bindValue(bind, value); + } + + m_insert_query.bindValue(":element_type", elmt->linkTypeToString()); + m_insert_query.bindValue(":element_subtype", elmt->kindInformations()["type"].toString()); + + if (!m_insert_query.exec()) { + qDebug() << "BOMExportDialog::populateDataBase insert error : " << m_insert_query.lastError(); + } + } + } } /** @@ -474,39 +474,39 @@ void BOMExportDialog::populateDataBase() */ QHash BOMExportDialog::elementInfoToString(Element *elmt) const { - QHash keys_hash; //Use to get the element info according to the database columns name - int row = 0; - while (auto *item = ui->m_var_list->item(row)) - { - keys_hash.insert(item->data(Qt::UserRole).toString(), - item->data(Qt::UserRole+1).toString()); - ++row; - } - - QHash hash; //Store the value for each columns - for (auto key : keys_hash.keys()) - { - if (key == "pos") { - hash.insert(key, elmt->diagram()->convertPosition(elmt->scenePos()).toString()); - } - else if (key == "folio_title") { - hash.insert(key, elmt->diagram()->title()); - } - else if (key == "folio_pos") { - hash.insert(key, QString::number(elmt->diagram()->folioIndex() + 1)); - } - else if (key == "folio_num") { + QHash keys_hash; //Use to get the element info according to the database columns name + int row = 0; + while (auto *item = ui->m_var_list->item(row)) + { + keys_hash.insert(item->data(Qt::UserRole).toString(), + item->data(Qt::UserRole+1).toString()); + ++row; + } + + QHash hash; //Store the value for each columns + for (auto key : keys_hash.keys()) + { + if (key == "pos") { + hash.insert(key, elmt->diagram()->convertPosition(elmt->scenePos()).toString()); + } + else if (key == "folio_title") { + hash.insert(key, elmt->diagram()->title()); + } + else if (key == "folio_pos") { + hash.insert(key, QString::number(elmt->diagram()->folioIndex() + 1)); + } + else if (key == "folio_num") { hash.insert(key, elmt->diagram()->border_and_titleblock.finalfolio()); - } - else if (key == "label") { - hash.insert(key, elmt->actualLabel()); - } - else { - hash.insert(key, elmt->elementInformations()[keys_hash.value(key)].toString()); - } - } - - return hash; + } + else if (key == "label") { + hash.insert(key, elmt->actualLabel()); + } + else { + hash.insert(key, elmt->elementInformations()[keys_hash.value(key)].toString()); + } + } + + return hash; } /** @@ -515,33 +515,33 @@ QHash BOMExportDialog::elementInfoToString(Element *elmt) cons */ QString BOMExportDialog::queryStr() const { - //User define is own query - if (ui->m_edit_sql_query_cb->isChecked()) { - return ui->m_sql_query->text(); - } - //Made a string list with the colomns (keys) choosen by the user + //User define is own query + if (ui->m_edit_sql_query_cb->isChecked()) { + return ui->m_sql_query->text(); + } + //Made a string list with the colomns (keys) choosen by the user QStringList keys = selectedKeys(); keys.removeAll("designation_qty"); - - QString select ="SELECT "; - QString order_by = " ORDER BY "; - - QString column; - bool first = true; - for (auto key: keys) { - if (first) { - first = false; - } else { - column += ", "; - order_by += ", "; - } - column += key; - order_by += key; - } - - QString from = " FROM bom"; + + QString select ="SELECT "; + QString order_by = " ORDER BY "; + + QString column; + bool first = true; + for (auto key: keys) { + if (first) { + first = false; + } else { + column += ", "; + order_by += ", "; + } + column += key; + order_by += key; + } + + QString from = " FROM bom"; QString count = ui->m_format_as_bom_rb->isChecked() ? QString(", COUNT(*) AS designation_qty ") : QString(); - QString where; + QString where; if (ui->m_all_cb->checkState() == Qt::PartiallyChecked) { if (ui->m_terminal_cb->isChecked()) { @@ -564,24 +564,24 @@ QString BOMExportDialog::queryStr() const where += str; } } - QString where_bom; - if(ui->m_format_as_bom_rb->isChecked()) - { - if (where.isEmpty()) { - where = " WHERE designation IS NOT NULL"; - } else { - where.append(" AND designation IS NOT NULL"); - } - - } - - QString group_by = ui->m_format_as_bom_rb->isChecked() ? " GROUP BY designation" : ""; + QString where_bom; + if(ui->m_format_as_bom_rb->isChecked()) + { + if (where.isEmpty()) { + where = " WHERE designation IS NOT NULL"; + } else { + where.append(" AND designation IS NOT NULL"); + } + + } + + QString group_by = ui->m_format_as_bom_rb->isChecked() ? " GROUP BY designation" : ""; QString q(select + column + count + from + where + where_bom + group_by + order_by); - return q; + return q; } void BOMExportDialog::updateQueryLine() { - ui->m_sql_query->setText(queryStr()); + ui->m_sql_query->setText(queryStr()); } /** @@ -590,16 +590,16 @@ void BOMExportDialog::updateQueryLine() { */ void BOMExportDialog::fillSavedQuery() { - QFile file(QETApp::configDir() + "/bill_of_materials.json"); - if (file.open(QFile::ReadOnly)) - { - QJsonDocument jsd(QJsonDocument::fromJson(file.readAll())); - QJsonObject jso = jsd.object(); - - for (auto it = jso.begin() ; it != jso.end() ; ++it) { - ui->m_conf_cb->addItem(it.key()); - } - } + QFile file(QETApp::configDir() + "/bill_of_materials.json"); + if (file.open(QFile::ReadOnly)) + { + QJsonDocument jsd(QJsonDocument::fromJson(file.readAll())); + QJsonObject jso = jsd.object(); + + for (auto it = jso.begin() ; it != jso.end() ; ++it) { + ui->m_conf_cb->addItem(it.key()); + } + } } void BOMExportDialog::on_m_format_as_nomenclature_rb_toggled(bool checked) { @@ -613,20 +613,20 @@ void BOMExportDialog::on_m_format_as_nomenclature_rb_toggled(bool checked) { */ void BOMExportDialog::on_m_edit_sql_query_cb_clicked() { - ui->m_sql_query->setEnabled(ui->m_edit_sql_query_cb->isChecked()); - ui->m_info_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked()); - ui->m_parametre_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked()); + ui->m_sql_query->setEnabled(ui->m_edit_sql_query_cb->isChecked()); + ui->m_info_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked()); + ui->m_parametre_widget->setDisabled(ui->m_edit_sql_query_cb->isChecked()); ui->m_format_as_gb->setDisabled(ui->m_edit_sql_query_cb->isChecked()); - - if (ui->m_edit_sql_query_cb->isChecked() && !m_custom_query.isEmpty()) - { - ui->m_sql_query->setText(m_custom_query); - } - else if (!ui->m_edit_sql_query_cb->isChecked()) - { - m_custom_query = ui->m_sql_query->text(); - updateQueryLine(); - } + + if (ui->m_edit_sql_query_cb->isChecked() && !m_custom_query.isEmpty()) + { + ui->m_sql_query->setText(m_custom_query); + } + else if (!ui->m_edit_sql_query_cb->isChecked()) + { + m_custom_query = ui->m_sql_query->text(); + updateQueryLine(); + } } /** @@ -635,24 +635,24 @@ void BOMExportDialog::on_m_edit_sql_query_cb_clicked() */ void BOMExportDialog::on_m_save_current_conf_pb_clicked() { - QFile file(QETApp::configDir() + "/bill_of_materials.json"); - - if (file.open(QFile::ReadWrite)) - { - QJsonDocument jsd(QJsonDocument::fromJson(file.readAll())); - QJsonObject root_object; - - if (!jsd.isEmpty()) - { - root_object = jsd.object(); - if (root_object.contains(ui->m_save_name_le->text())) { - root_object.remove(ui->m_save_name_le->text()); - } - } - - QVariantMap vm; + QFile file(QETApp::configDir() + "/bill_of_materials.json"); + + if (file.open(QFile::ReadWrite)) + { + QJsonDocument jsd(QJsonDocument::fromJson(file.readAll())); + QJsonObject root_object; + + if (!jsd.isEmpty()) + { + root_object = jsd.object(); + if (root_object.contains(ui->m_save_name_le->text())) { + root_object.remove(ui->m_save_name_le->text()); + } + } + + QVariantMap vm; vm.insert("user query", ui->m_edit_sql_query_cb->isChecked()); - + if (ui->m_edit_sql_query_cb->isChecked()) { vm.insert("query", ui->m_sql_query->text()); } @@ -660,13 +660,13 @@ void BOMExportDialog::on_m_save_current_conf_pb_clicked() { vm.insert("header", ui->m_include_header_cb->isChecked()); vm.insert("format as bill of material", ui->m_format_as_bom_rb->isChecked()); - + QJsonArray keys_array; for (auto key : selectedKeys()) { keys_array.append(QJsonValue(key)); } vm.insert("selected infos", keys_array); - + QJsonArray selected_elements_array; for (auto button : m_button_group.buttons()) { @@ -677,14 +677,14 @@ void BOMExportDialog::on_m_save_current_conf_pb_clicked() } vm.insert("selected elements", selected_elements_array); } - + root_object[ui->m_save_name_le->text()] = QJsonObject::fromVariantMap(vm); - - - jsd.setObject(root_object); - file.resize(0); - file.write(jsd.toJson()); - } + + + jsd.setObject(root_object); + file.resize(0); + file.write(jsd.toJson()); + } } /** @@ -697,20 +697,20 @@ void BOMExportDialog::on_m_load_pb_clicked() if (name.isEmpty()) { return; } - + QFile file(QETApp::configDir() + "/bill_of_materials.json"); if (!file.open(QFile::ReadOnly)) { return; } - + QJsonDocument jsd(QJsonDocument::fromJson(file.readAll())); QJsonObject jso = jsd.object(); - + auto value = jso.value(name); if (!value.isObject()) { return; } - + auto value_object = value.toObject(); if (value_object["user query"].toBool()) { @@ -722,13 +722,13 @@ void BOMExportDialog::on_m_load_pb_clicked() ui->m_edit_sql_query_cb->setChecked(false); ui->m_include_header_cb->setChecked(value_object["header"].toBool()); ui->m_format_as_bom_rb->setChecked(value_object["format as bill of material"].toBool()); - - - //Ugly hack to force to remove all selected infos + + + //Ugly hack to force to remove all selected infos while (auto item = ui->m_choosen_list->takeItem(0)) { ui->m_var_list->addItem(item); } - + QVariantList vl = value_object["selected infos"].toArray().toVariantList(); for (auto variant : vl) { @@ -741,16 +741,16 @@ void BOMExportDialog::on_m_load_pb_clicked() } } } - + QJsonArray selected_elements_array = value_object["selected elements"].toArray(); for (int id=0 ; idsetChecked(obj["checked"].toBool()); } - + updateQueryLine(); } - + on_m_edit_sql_query_cb_clicked(); //Force to update dialog } diff --git a/sources/ui/configpage/generalconfigurationpage.cpp b/sources/ui/configpage/generalconfigurationpage.cpp index 4dc24d67d..aa93e36bc 100644 --- a/sources/ui/configpage/generalconfigurationpage.cpp +++ b/sources/ui/configpage/generalconfigurationpage.cpp @@ -47,7 +47,7 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : if(tabbed) ui->m_use_tab_mode_rb->setChecked(true); else - ui->m_use_windows_mode_rb->setChecked(true); + ui->m_use_windows_mode_rb->setChecked(true); ui->m_zoom_out_beyond_folio->setChecked(settings.value("diagrameditor/zoom-out-beyond-of-folio", false).toBool()); ui->m_use_gesture_trackpad->setChecked(settings.value("diagramview/gestures", false).toBool()); ui->m_save_label_paste->setChecked(settings.value("diagramcommands/erase-label-on-copy", true).toBool()); @@ -57,8 +57,8 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : ui->m_autosave_sb->setValue(settings.value("diagrameditor/autosave-interval", 0).toInt()); QString fontInfos = settings.value("diagramitemfont").toString() + " " + - settings.value("diagramitemsize").toString() + " (" + - settings.value("diagramitemstyle").toString() + ")"; + settings.value("diagramitemsize").toString() + " (" + + settings.value("diagramitemstyle").toString() + ")"; ui->m_font_pb->setText(fontInfos); @@ -309,9 +309,9 @@ void GeneralConfigurationPage::on_m_font_pb_clicked() settings.setValue("diagramitemweight", font.weight()); settings.setValue("diagramitemstyle", font.styleName()); QString fontInfos = settings.value("diagramitemfont").toString() + " " + - settings.value("diagramitemsize").toString() + " (" + - settings.value("diagramitemstyle").toString() + ")"; - ui->m_font_pb->setText(fontInfos); + settings.value("diagramitemsize").toString() + " (" + + settings.value("diagramitemstyle").toString() + ")"; + ui->m_font_pb->setText(fontInfos); } } @@ -339,7 +339,7 @@ void GeneralConfigurationPage::on_m_dyn_text_font_pb_clicked() void GeneralConfigurationPage::on_m_common_elmt_path_cb_currentIndexChanged(int index) { - if (index == 1) + if (index == 1) { QString path = QFileDialog::getExistingDirectory(this, tr("Chemin de la collection commune"), QDir::homePath()); if (!path.isEmpty()) { @@ -353,7 +353,7 @@ void GeneralConfigurationPage::on_m_common_elmt_path_cb_currentIndexChanged(int void GeneralConfigurationPage::on_m_custom_elmt_path_cb_currentIndexChanged(int index) { - if (index == 1) + if (index == 1) { QString path = QFileDialog::getExistingDirectory(this, tr("Chemin de la collection utilisateur"), QDir::homePath()); if (!path.isEmpty()) { @@ -367,7 +367,7 @@ void GeneralConfigurationPage::on_m_custom_elmt_path_cb_currentIndexChanged(int void GeneralConfigurationPage::on_m_custom_tbt_path_cb_currentIndexChanged(int index) { - if (index == 1) + if (index == 1) { QString path = QFileDialog::getExistingDirectory(this, tr("Chemin des cartouches utilisateur"), QDir::homePath()); if (!path.isEmpty()) { diff --git a/sources/ui/dynamicelementtextmodel.h b/sources/ui/dynamicelementtextmodel.h index 5845ab9f6..493290947 100644 --- a/sources/ui/dynamicelementtextmodel.h +++ b/sources/ui/dynamicelementtextmodel.h @@ -37,92 +37,92 @@ class DynamicElementTextModel : public QStandardItemModel Q_OBJECT public: - enum ValueType { - textFrom =1, - userText, - infoText, - compositeText, - txtAlignment, - size, - font, - color, - pos, - frame, - rotation, - textWidth, - grpAlignment, - grpPos, - grpRotation, - grpVAdjust, - grpName, - grpHoldBottom, - grpFrame - }; - - DynamicElementTextModel(Element *element, QObject *parent = nullptr); - ~DynamicElementTextModel() override; - - bool indexIsInGroup(const QModelIndex &index) const; - DynamicElementTextItem *textFromIndex(const QModelIndex &index) const; - DynamicElementTextItem *textFromItem(QStandardItem *item) const; - QModelIndex indexFromText(DynamicElementTextItem *text) const; - QUndoCommand *undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo = nullptr) const; - QUndoCommand *undoForEditedGroup(ElementTextItemGroup *group, QUndoCommand *parent_undo = nullptr) const; - - ElementTextItemGroup *groupFromIndex(const QModelIndex &index) const; - ElementTextItemGroup *groupFromItem(QStandardItem *item) const; - QModelIndex indexFromGroup(ElementTextItemGroup *group) const; - bool indexIsText(const QModelIndex &index) const; - bool indexIsGroup(const QModelIndex &index) const; - - bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override; - bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; - QMimeData *mimeData(const QModelIndexList &indexes) const override; - QStringList mimeTypes() const override; - + enum ValueType { + textFrom =1, + userText, + infoText, + compositeText, + txtAlignment, + size, + font, + color, + pos, + frame, + rotation, + textWidth, + grpAlignment, + grpPos, + grpRotation, + grpVAdjust, + grpName, + grpHoldBottom, + grpFrame + }; + + DynamicElementTextModel(Element *element, QObject *parent = nullptr); + ~DynamicElementTextModel() override; + + bool indexIsInGroup(const QModelIndex &index) const; + DynamicElementTextItem *textFromIndex(const QModelIndex &index) const; + DynamicElementTextItem *textFromItem(QStandardItem *item) const; + QModelIndex indexFromText(DynamicElementTextItem *text) const; + QUndoCommand *undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo = nullptr) const; + QUndoCommand *undoForEditedGroup(ElementTextItemGroup *group, QUndoCommand *parent_undo = nullptr) const; + + ElementTextItemGroup *groupFromIndex(const QModelIndex &index) const; + ElementTextItemGroup *groupFromItem(QStandardItem *item) const; + QModelIndex indexFromGroup(ElementTextItemGroup *group) const; + bool indexIsText(const QModelIndex &index) const; + bool indexIsGroup(const QModelIndex &index) const; + + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override; + bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; + QMimeData *mimeData(const QModelIndexList &indexes) const override; + QStringList mimeTypes() const override; + signals: - void dataChanged(); - - private: - QList itemsForText(DynamicElementTextItem *deti); - void addText(DynamicElementTextItem *deti); - void removeText(DynamicElementTextItem *deti); - void addGroup(ElementTextItemGroup *group); - void removeGroup(ElementTextItemGroup *group); - void addTextToGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group); - void removeTextFromGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group); - void enableSourceText(DynamicElementTextItem *deti, DynamicElementTextItem::TextFrom tf ); - void enableGroupRotationAndPos(ElementTextItemGroup *group); - void itemDataChanged(QStandardItem *qsi); - void setConnection(DynamicElementTextItem *deti, bool set); - void setConnection(ElementTextItemGroup *group, bool set); - void updateDataFromText(DynamicElementTextItem *deti, DynamicElementTextModel::ValueType type); - void updateDataFromGroup(ElementTextItemGroup *group, DynamicElementTextModel::ValueType type); - + void dataChanged(); + private: - QPointer m_element; - QHash m_texts_list; - QHash m_groups_list; - QHash > m_hash_text_connect; - QHash > m_hash_group_connect; - bool m_block_dataChanged = false; + QList itemsForText(DynamicElementTextItem *deti); + void addText(DynamicElementTextItem *deti); + void removeText(DynamicElementTextItem *deti); + void addGroup(ElementTextItemGroup *group); + void removeGroup(ElementTextItemGroup *group); + void addTextToGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group); + void removeTextFromGroup(DynamicElementTextItem *deti, ElementTextItemGroup *group); + void enableSourceText(DynamicElementTextItem *deti, DynamicElementTextItem::TextFrom tf ); + void enableGroupRotationAndPos(ElementTextItemGroup *group); + void itemDataChanged(QStandardItem *qsi); + void setConnection(DynamicElementTextItem *deti, bool set); + void setConnection(ElementTextItemGroup *group, bool set); + void updateDataFromText(DynamicElementTextItem *deti, DynamicElementTextModel::ValueType type); + void updateDataFromGroup(ElementTextItemGroup *group, DynamicElementTextModel::ValueType type); + + private: + QPointer m_element; + QHash m_texts_list; + QHash m_groups_list; + QHash > m_hash_text_connect; + QHash > m_hash_group_connect; + bool m_block_dataChanged = false; }; class DynamicTextItemDelegate : public QStyledItemDelegate { Q_OBJECT - public: - DynamicTextItemDelegate(QObject *parent = Q_NULLPTR); - - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; - void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; - + public: + DynamicTextItemDelegate(QObject *parent = Q_NULLPTR); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + protected: - bool eventFilter(QObject *object, QEvent *event) override; - + bool eventFilter(QObject *object, QEvent *event) override; + private: - QStringList availableInfo(DynamicElementTextItem *deti) const; + QStringList availableInfo(DynamicElementTextItem *deti) const; }; #endif // DYNAMICELEMENTTEXTMODEL_H diff --git a/sources/ui/linksingleelementwidget.cpp b/sources/ui/linksingleelementwidget.cpp index fee4c0732..26b1e1484 100644 --- a/sources/ui/linksingleelementwidget.cpp +++ b/sources/ui/linksingleelementwidget.cpp @@ -220,10 +220,10 @@ void LinkSingleElementWidget::buildTree() QStringList search_list; QStringList str_list; - str_list << elmt->actualLabel(); - if(!str_list.last().isEmpty()) { - search_list << str_list.last(); - } + str_list << elmt->actualLabel(); + if(!str_list.last().isEmpty()) { + search_list << str_list.last(); + } str_list << elmt->elementInformations()["comment"].toString(); if (!str_list.last().isEmpty()) @@ -254,7 +254,7 @@ void LinkSingleElementWidget::buildTree() m_qtwi_strl_hash.insert(qtwi, search_list); } - + QVariant v = settings.value("link-element-widget/slave-state"); if(!v.isNull()) ui->m_tree_widget->header()->restoreState(v.toByteArray()); @@ -319,7 +319,7 @@ void LinkSingleElementWidget::buildTree() if(!v.isNull()) ui->m_tree_widget->header()->restoreState(v.toByteArray()); } - + setUpCompleter(); } @@ -347,10 +347,10 @@ bool LinkSingleElementWidget::setLiveEdit(bool live_edit) QList LinkSingleElementWidget::availableElements() { QList elmt_list; - //if element isn't free and unlink isn't pressed, return an empty list + //if element isn't free and unlink isn't pressed, return an empty list if (!m_element->isFree() && !m_unlink) return elmt_list; - + if (!m_element->diagram() || !m_element->diagram()->project()) return elmt_list; ElementProvider ep(m_element->diagram()->project()); @@ -359,9 +359,9 @@ QList LinkSingleElementWidget::availableElements() else elmt_list = ep.find(m_filter); - //If element is linked, remove is parent from the list + //If element is linked, remove is parent from the list if(!m_element->isFree()) elmt_list.removeAll(m_element->linkedElements().first()); - + return elmt_list; } @@ -445,8 +445,8 @@ void LinkSingleElementWidget::setUpHeaderLabels() */ void LinkSingleElementWidget::diagramWasRemovedFromProject() { - //We use a timer because if the removed diagram contain the master element linked to the edited element - //we must to wait for this elements be unlinked, else the list of available master isn't up to date + //We use a timer because if the removed diagram contain the master element linked to the edited element + //we must to wait for this elements be unlinked, else the list of available master isn't up to date QTimer::singleShot(10, this, SLOT(updateUi())); } @@ -473,8 +473,8 @@ void LinkSingleElementWidget::linkTriggered() } else { - //In no live edit mode, we set the background of the qtwi green, to inform the user - //which element will be linked when he press the apply button + //In no live edit mode, we set the background of the qtwi green, to inform the user + //which element will be linked when he press the apply button if (m_pending_qtwi) { for(int i=0 ; i<6 ; i++) @@ -559,13 +559,13 @@ void LinkSingleElementWidget::on_m_tree_widget_itemDoubleClicked(QTreeWidgetItem elmt->setHighlighted(true); m_showed_element = elmt; connect(m_showed_element, SIGNAL(destroyed()), this, SLOT(showedElementWasDeleted())); - + } void LinkSingleElementWidget::on_m_tree_widget_customContextMenuRequested(const QPoint &pos) { - //add the size of the header to display the topleft of the QMenu at the position of the mouse. - //See doc about QWidget::customContextMenuRequested section related to QAbstractScrollArea + //add the size of the header to display the topleft of the QMenu at the position of the mouse. + //See doc about QWidget::customContextMenuRequested section related to QAbstractScrollArea QPoint point = pos; point.ry()+=ui->m_tree_widget->header()->height(); point = ui->m_tree_widget->mapToGlobal(point); @@ -606,7 +606,7 @@ void LinkSingleElementWidget::on_m_show_this_pb_clicked() */ void LinkSingleElementWidget::on_m_search_field_textEdited(const QString &arg1) { - //Show all items if arg1 is empty, if not hide all items + //Show all items if arg1 is empty, if not hide all items foreach(QTreeWidgetItem *qtwi, m_qtwi_elmt_hash.keys()) qtwi->setHidden(!arg1.isEmpty()); @@ -624,7 +624,7 @@ void LinkSingleElementWidget::on_m_search_field_textEdited(const QString &arg1) } } - //Show items which match with arg1 + //Show items which match with arg1 foreach(QTreeWidgetItem *qtwi, qtwi_list) qtwi->setHidden(false); } diff --git a/sources/ui/potentialselectordialog.cpp b/sources/ui/potentialselectordialog.cpp index 1077e497f..acabbf4ba 100644 --- a/sources/ui/potentialselectordialog.cpp +++ b/sources/ui/potentialselectordialog.cpp @@ -104,7 +104,7 @@ class NewConductorPotentialSelector : public AbstractPotentialSelector seq_num = conductor_in_potential->sequenceNum(); number = conductor_in_potential->relatedPotentialConductors().size()+1; //We add +1 because conductor_in_potential isn't count by relatedPotentialConductors - c_list = conductor_in_potential->relatedPotentialConductors().values(); + c_list = conductor_in_potential->relatedPotentialConductors().values(); c_list.append(conductor_in_potential); foreach(Conductor *c, c_list) properties_list.append(c->properties());