Wrap code for better readability + Mod doc

This commit is contained in:
Simon De Backer
2020-07-15 18:20:08 +02:00
committed by Laurent Trinques
parent 2cdfce18ec
commit d7e1d326a2
6 changed files with 129 additions and 77 deletions

View File

@@ -249,8 +249,14 @@ void MoveElementsCommand::move(const QPointF &actual_movement)
{
typedef DiagramContent dc;
//Move every movable items, except conductor
for (QGraphicsItem *qgi : content_to_move.items(dc::Elements | dc::TextFields | dc::Images | dc::Shapes | dc::TextGroup | dc::ElementTextFields | dc::Tables))
//Move every movable items, except conductor
for (QGraphicsItem *qgi : content_to_move.items(dc::Elements
| dc::TextFields
| dc::Images
| dc::Shapes
| dc::TextGroup
| dc::ElementTextFields
| dc::Tables))
{
//If curent item have parent, and parent item is in content_to_move
//we don't apply movement to this item, because this item will be moved by is parent.
@@ -259,19 +265,22 @@ void MoveElementsCommand::move(const QPointF &actual_movement)
continue;
if(qgi->toGraphicsObject())
setupAnimation(qgi->toGraphicsObject(), "pos", qgi->pos(), qgi->pos() + actual_movement);
else if(qgi->type() == QGraphicsItemGroup::Type) //ElementTextItemGroup is a QObject but not a QGraphicsObject
setupAnimation(qgi->toGraphicsObject(), "pos",
qgi->pos(), qgi->pos() + actual_movement);
else if(qgi->type() == QGraphicsItemGroup::Type)
{
//ElementTextItemGroup is a QObject but not a QGraphicsObject
if(ElementTextItemGroup *etig = dynamic_cast<ElementTextItemGroup *>(qgi))
setupAnimation(etig, "pos", etig->pos(), etig->pos() + actual_movement);
setupAnimation(etig, "pos", etig->pos(),
etig->pos() + actual_movement);
}
else qgi -> setPos(qgi->pos() + actual_movement);
}
// Move some conductors
for (Conductor *conductor : content_to_move.m_conductors_to_move)
setupAnimation(conductor, "pos", conductor->pos(), conductor->pos() + actual_movement);
setupAnimation(conductor, "pos", conductor->pos(),
conductor->pos() + actual_movement);
// Recalcul the path of other conductor
for (Conductor *conductor : content_to_move.m_conductors_to_update)
@@ -279,14 +288,17 @@ void MoveElementsCommand::move(const QPointF &actual_movement)
}
/**
* @brief MoveElementsCommand::setupAnimation
* Set up the animation for this undo command
* @param target object to anim
* @param propertyName property to animate
* @param start value at start
* @param end value at end
*/
void MoveElementsCommand::setupAnimation(QObject *target, const QByteArray &propertyName, const QVariant& start, const QVariant& end) {
@brief MoveElementsCommand::setupAnimation
Set up the animation for this undo command
@param target object to anim
@param propertyName property to animate
@param start value at start
@param end value at end
*/
void MoveElementsCommand::setupAnimation(QObject *target,
const QByteArray &propertyName,
const QVariant& start,
const QVariant& end) {
//create animation group if not yet.
if (m_anim_group == nullptr) m_anim_group = new QParallelAnimationGroup();
QPropertyAnimation *animation = new QPropertyAnimation(target, propertyName);
@@ -366,11 +378,15 @@ void MoveConductorsTextsCommand::redo() {
@param alread_moved true si le champ de texte etait deja a une position
personnalisee par l'utilisateur, false sinon
*/
void MoveConductorsTextsCommand::addTextMovement(ConductorTextItem *text_item, const QPointF &old_pos, const QPointF &new_pos, bool already_moved) {
void MoveConductorsTextsCommand::addTextMovement(ConductorTextItem *text_item,
const QPointF &old_pos,
const QPointF &new_pos,
bool already_moved) {
// si le champ de texte est deja connu de l'objet d'annulation, il sera ignore
if (texts_to_move_.contains(text_item)) return;
// on memorise le champ de texte, en l'associant au mouvement effectue et a son etat avant le deplacement
// on memorise le champ de texte,
//en l'associant au mouvement effectue et a son etat avant le deplacement
texts_to_move_.insert(text_item, qMakePair(new_pos - old_pos, already_moved));
// met a jour la description de l'objet d'annulation

View File

@@ -88,7 +88,8 @@ QString itemText(const Conductor *item);
class PasteDiagramCommand : public QUndoCommand {
// constructors, destructor
public:
PasteDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand * = nullptr);
PasteDiagramCommand(Diagram *, const DiagramContent &,
QUndoCommand * = nullptr);
~PasteDiagramCommand() override;
private:
PasteDiagramCommand(const PasteDiagramCommand &);
@@ -117,7 +118,8 @@ class PasteDiagramCommand : public QUndoCommand {
class CutDiagramCommand : public DeleteQGraphicsItemCommand {
// constructors, destructor
public:
CutDiagramCommand(Diagram *, const DiagramContent &, QUndoCommand * = nullptr);
CutDiagramCommand(Diagram *, const DiagramContent &,
QUndoCommand * = nullptr);
~CutDiagramCommand() override;
private:
CutDiagramCommand(const CutDiagramCommand &);
@@ -130,7 +132,8 @@ class CutDiagramCommand : public DeleteQGraphicsItemCommand {
class MoveElementsCommand : public QUndoCommand {
// constructors, destructor
public:
MoveElementsCommand(Diagram *, const DiagramContent &, const QPointF &m, QUndoCommand * = nullptr);
MoveElementsCommand(Diagram *, const DiagramContent &,
const QPointF &m, QUndoCommand * = nullptr);
~MoveElementsCommand() override;
private:
MoveElementsCommand(const MoveElementsCommand &);
@@ -142,7 +145,10 @@ class MoveElementsCommand : public QUndoCommand {
virtual void move(const QPointF &);
private:
void setupAnimation (QObject * target, const QByteArray &propertyName, const QVariant& start, const QVariant& end);
void setupAnimation (QObject * target,
const QByteArray &propertyName,
const QVariant& start,
const QVariant& end);
// attributes
private:
@@ -175,7 +181,8 @@ class MoveConductorsTextsCommand : public QUndoCommand {
public:
void undo() override;
void redo() override;
virtual void addTextMovement(ConductorTextItem *, const QPointF &, const QPointF &, bool = false);
virtual void addTextMovement(ConductorTextItem *, const QPointF &,
const QPointF &, bool = false);
private:
void regenerateTextLabel();
@@ -191,12 +198,16 @@ class MoveConductorsTextsCommand : public QUndoCommand {
};
/**
@brief The ChangeDiagramTextCommand class
This commad modifies a text item.
*/
class ChangeDiagramTextCommand : public QUndoCommand {
// constructors, destructor
public:
ChangeDiagramTextCommand(DiagramTextItem *, const QString &before, const QString &after, QUndoCommand * = nullptr);
ChangeDiagramTextCommand(DiagramTextItem *,
const QString &before,
const QString &after,
QUndoCommand * = nullptr);
~ChangeDiagramTextCommand() override;
private:
ChangeDiagramTextCommand(const ChangeDiagramTextCommand &);
@@ -220,12 +231,15 @@ class ChangeDiagramTextCommand : public QUndoCommand {
};
/**
@brief The ChangeConductorCommand class
This command changes a particular conductor.
*/
class ChangeConductorCommand : public QUndoCommand {
// constructors, destructor
public:
ChangeConductorCommand(Conductor *, const ConductorProfile &, const ConductorProfile &, Qt::Corner, QUndoCommand * = nullptr);
ChangeConductorCommand(Conductor *, const ConductorProfile &,
const ConductorProfile &, Qt::Corner,
QUndoCommand * = nullptr);
~ChangeConductorCommand() override;
private:
ChangeConductorCommand(const ChangeConductorCommand &);
@@ -256,12 +270,15 @@ class ChangeConductorCommand : public QUndoCommand {
};
/**
@brief The ResetConductorCommand class
This command resets conductor paths.
*/
class ResetConductorCommand : public QUndoCommand {
// constructors, destructor
public:
ResetConductorCommand(const QHash<Conductor *, ConductorProfilesGroup> &, QUndoCommand * = nullptr);
ResetConductorCommand(const QHash<Conductor *,
ConductorProfilesGroup> &,
QUndoCommand * = nullptr);
~ResetConductorCommand() override;
private:
ResetConductorCommand(const ResetConductorCommand &);
@@ -281,12 +298,14 @@ class ResetConductorCommand : public QUndoCommand {
/**
@brief The ChangeBorderCommand class
This command changes the border properties of a particular diagram.
*/
class ChangeBorderCommand : public QUndoCommand {
// constructors, destructor
public:
ChangeBorderCommand(Diagram *, const BorderProperties &, const BorderProperties &, QUndoCommand * = nullptr);
ChangeBorderCommand(Diagram *, const BorderProperties &,
const BorderProperties &, QUndoCommand * = nullptr);
~ChangeBorderCommand() override;
private:
ChangeBorderCommand(const ChangeBorderCommand &);

View File

@@ -42,11 +42,11 @@ const qreal Terminal::Z = 1000;
*/
void Terminal::init(QString number, QString name, bool hiddenName) {
hovered_color_ = Terminal::neutralColor;
hovered_color_ = Terminal::neutralColor;
// calcul de la position du point d'amarrage a l'element
dock_elmt_ = d->m_pos;
switch(d->m_orientation) {
dock_elmt_ = d->m_pos;
switch(d->m_orientation) {
case Qet::North: dock_elmt_ += QPointF(0, Terminal::terminalSize); break;
case Qet::East : dock_elmt_ += QPointF(-Terminal::terminalSize, 0); break;
case Qet::West : dock_elmt_ += QPointF(Terminal::terminalSize, 0); break;
@@ -82,14 +82,14 @@ void Terminal::init(QString number, QString name, bool hiddenName) {
*/
void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName)
{
// definition du pount d'amarrage pour un conducteur
d->m_pos = pf;
// definition du pount d'amarrage pour un conducteur
d->m_pos = pf;
// definition de l'orientation de la borne (par defaut : sud)
if (o < Qet::North || o > Qet::West) d->m_orientation = Qet::South;
else d->m_orientation = o;
// definition de l'orientation de la borne (par defaut : sud)
if (o < Qet::North || o > Qet::West) d->m_orientation = Qet::South;
else d->m_orientation = o;
init(number, name, hiddenName);
init(number, name, hiddenName);
}
/**
@@ -101,8 +101,8 @@ void Terminal::init(QPointF pf, Qet::Orientation o, QString number, QString name
*/
Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
QGraphicsObject(e),
d(new TerminalData(this)),
parent_element_ (e)
d(new TerminalData(this)),
parent_element_ (e)
{
init(pf, o, "_", "_", false);
}
@@ -117,10 +117,10 @@ Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
*/
Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
QGraphicsObject(e),
d(new TerminalData(this)),
parent_element_ (e)
d(new TerminalData(this)),
parent_element_ (e)
{
init(QPointF(pf_x, pf_y), o, "_", "_", false);
init(QPointF(pf_x, pf_y), o, "_", "_", false);
}
/**
@@ -135,20 +135,20 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
*/
Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
QGraphicsObject (e),
d(new TerminalData(this)),
parent_element_ (e)
d(new TerminalData(this)),
parent_element_ (e)
{
init(pf, o, std::move(num), std::move(name), hiddenName);
}
Terminal::Terminal(TerminalData* data, Element* e) :
QGraphicsObject(e),
d(data),
parent_element_(e)
QGraphicsObject(e),
d(data),
parent_element_(e)
{
// TODO: what is when multiple parents exist. So the other relation is lost.
d->setParent(this);
init("_", "_", false);
// TODO: what is when multiple parents exist. So the other relation is lost.
d->setParent(this);
init("_", "_", false);
}
/**
@@ -172,15 +172,15 @@ Qet::Orientation Terminal::orientation() const {
if (Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
// orientations actuelle et par defaut de l'element
int ori_cur = elt -> orientation();
if (ori_cur == 0) return(d->m_orientation);
if (ori_cur == 0) return(d->m_orientation);
else {
// calcul l'angle de rotation implique par l'orientation de l'element parent
// angle de rotation de la borne sur la scene, divise par 90
int angle = ori_cur + d->m_orientation;
int angle = ori_cur + d->m_orientation;
while (angle >= 4) angle -= 4;
return((Qet::Orientation)angle);
}
} else return(d->m_orientation);
} else return(d->m_orientation);
}
@@ -258,7 +258,7 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
p -> setRenderHint(QPainter::SmoothPixmapTransform, false);
// on travaille avec les coordonnees de l'element parent
QPointF c = mapFromParent(d->m_pos);
QPointF c = mapFromParent(d->m_pos);
QPointF e = mapFromParent(dock_elmt_);
QPen t;
@@ -410,12 +410,13 @@ QLineF Terminal::HelpLine() const
@return Le rectangle (en precision flottante) delimitant la borne et ses alentours.
*/
QRectF Terminal::boundingRect() const {
if (br_ -> isNull()) {
qreal dcx = d->m_pos.x();
qreal dcy = d->m_pos.y();
if (br_ -> isNull())
{
qreal dcx = d->m_pos.x();
qreal dcy = d->m_pos.y();
qreal dex = dock_elmt_.x();
qreal dey = dock_elmt_.y();
QPointF origin = (dcx <= dex && dcy <= dey ? d->m_pos : dock_elmt_);
QPointF origin = (dcx <= dex && dcy <= dey ? d->m_pos : dock_elmt_);
origin += QPointF(-3.0, -3.0);
qreal w = qAbs((int)(dcx - dex)) + 7;
qreal h = qAbs((int)(dcy - dey)) + 7;
@@ -637,7 +638,7 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
if (use_properties)
{
Conductor *other = conductors_list.values().first();
Conductor *other = conductors_list.values().first();
new_conductor->rSequenceNum() = other->sequenceNum();
new_conductor->setProperties(others_properties);
}
@@ -651,7 +652,7 @@ void Terminal::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
diagram() -> undoStack().push(undo);
if (use_properties)
{
Conductor *other = conductors_list.values().first();
Conductor *other = conductors_list.values().first();
new_conductor->setProperties(other->properties());
}
}
@@ -717,9 +718,13 @@ QList<Conductor *> Terminal::conductors() const {
*/
QDomElement Terminal::toXml(QDomDocument &doc) const {
QDomElement qdo = doc.createElement("terminal");
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x())); // for backward compatibility
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));// for backward compatibility
qdo.setAttribute("orientation", d->m_orientation);
// for backward compatibility
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
// end for backward compatibility
qdo.setAttribute("orientation", d->m_orientation);
qdo.setAttribute("number", number_terminal_);
qdo.setAttribute("name", name_terminal_);
qdo.setAttribute("nameHidden", name_terminal_hidden);
@@ -757,7 +762,10 @@ bool Terminal::valideXml(QDomElement &terminal) {
// parse l'orientation
int terminal_or = terminal.attribute("orientation").toInt(&conv_ok);
if (!conv_ok) return(false);
if (terminal_or != Qet::North && terminal_or != Qet::South && terminal_or != Qet::East && terminal_or != Qet::West) return(false);
if (terminal_or != Qet::North
&& terminal_or != Qet::South
&& terminal_or != Qet::East
&& terminal_or != Qet::West) return(false);
// a ce stade, la borne est syntaxiquement correcte
return(true);

View File

@@ -43,8 +43,9 @@ class Terminal : public QGraphicsObject
public:
Terminal(QPointF, Qet::Orientation, Element * = nullptr);
Terminal(qreal, qreal, Qet::Orientation, Element * = nullptr);
Terminal(TerminalData* data, Element *e = nullptr);
Terminal(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName, Element * = nullptr);
Terminal(TerminalData* data, Element *e = nullptr);
Terminal(QPointF, Qet::Orientation, QString number,
QString name, bool hiddenName, Element * = nullptr);
~Terminal() override;
private:
@@ -60,7 +61,8 @@ class Terminal : public QGraphicsObject
*/
int type() const override { return Type; }
void paint (QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
void paint (QPainter *,const QStyleOptionGraphicsItem *,
QWidget *) override;
void drawHelpLine (bool draw = true);
QLineF HelpLine () const;
QRectF boundingRect () const override;
@@ -148,8 +150,9 @@ class Terminal : public QGraphicsObject
bool name_terminal_hidden;
private:
void init(QString number, QString name, bool hiddenName);
void init(QPointF pf, Qet::Orientation o, QString number, QString name, bool hiddenName);
void init(QString number, QString name, bool hiddenName);
void init(QPointF pf, Qet::Orientation o, QString number,
QString name, bool hiddenName);
};
/**
@@ -169,12 +172,14 @@ inline QString Terminal::number() const {
}
/**
@brief Terminal::name
@return the name of terminal.
*/
inline QString Terminal::name() const {
return(name_terminal_);
}
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal, const bool all_diagram = true);
QList<Terminal *> relatedPotentialTerminal (const Terminal *terminal,
const bool all_diagram = true);
#endif

View File

@@ -18,14 +18,15 @@
#include "terminalelement.h"
/**
* @brief TerminalElement::TerminalElement
* Default constructor
* @param location location of xml definition
* @param qgi parent QGraphicItem
* @param s parent diagram
* @param state int used to know if the creation of element have error
*/
TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
@brief TerminalElement::TerminalElement
Default constructor
@param location location of xml definition
@param qgi parent QGraphicItem
@param s parent diagram
@param state int used to know if the creation of element have error
*/
TerminalElement::TerminalElement(const ElementsLocation &location,
QGraphicsItem *qgi, int *state) :
Element(location, qgi, state, Element::Terminale)
{}

View File

@@ -22,12 +22,15 @@
#include "element.h"
class QETProject;
/**
@brief The TerminalElement class
*/
class TerminalElement : public Element
{
Q_OBJECT
public:
TerminalElement(const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr);
TerminalElement(const ElementsLocation &,
QGraphicsItem * = nullptr, int * = nullptr);
~TerminalElement() override;
void initLink(QETProject *project) override;
};