Mod doc, Improve code style

This commit is contained in:
Simon De Backer
2020-08-12 21:53:02 +02:00
parent 87db0e2020
commit 69ff437368
6 changed files with 558 additions and 363 deletions

View File

@@ -31,19 +31,19 @@ static int header = 5;
static int cross_min_heigth = 33;
/**
* @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref
*/
@brief CrossRefItem::CrossRefItem
@param elmt : element to display the cross ref
*/
CrossRefItem::CrossRefItem(Element *elmt) :
QGraphicsObject(elmt),
m_element(elmt)
{init();}
/**
* @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref
* @param text : If the Xref must be displayed under a text, the text.
*/
@brief CrossRefItem::CrossRefItem
@param elmt : element to display the cross ref
@param text : If the Xref must be displayed under a text, the text.
*/
CrossRefItem::CrossRefItem(Element *elmt, DynamicElementTextItem *text) :
QGraphicsObject(text),
m_element (elmt),
@@ -51,10 +51,10 @@ CrossRefItem::CrossRefItem(Element *elmt, DynamicElementTextItem *text) :
{init();}
/**
* @brief CrossRefItem::CrossRefItem
* @param elmt : element to display the cross ref
* @param group : If the Xref must be displayed under a group, the group.
*/
@brief CrossRefItem::CrossRefItem
@param elmt : element to display the cross ref
@param group : If the Xref must be displayed under a group, the group.
*/
CrossRefItem::CrossRefItem(Element *elmt, ElementTextItemGroup *group) :
QGraphicsObject(group),
m_element(elmt),
@@ -62,15 +62,15 @@ CrossRefItem::CrossRefItem(Element *elmt, ElementTextItemGroup *group) :
{init();}
/**
* @brief CrossRefItem::~CrossRefItem
* Default destructor
*/
@brief CrossRefItem::~CrossRefItem
Default destructor
*/
CrossRefItem::~CrossRefItem() {}
/**
* @brief CrossRefItem::init
* init this Xref
*/
@brief CrossRefItem::init
init this Xref
*/
void CrossRefItem::init()
{
if(!m_element->diagram())
@@ -91,9 +91,9 @@ void CrossRefItem::init()
}
/**
* @brief CrossRefItem::setUpConnection
* Set up several connection to keep up to date the Xref
*/
@brief CrossRefItem::setUpConnection
Set up several connection to keep up to date the Xref
*/
void CrossRefItem::setUpConnection()
{
for(const QMetaObject::Connection& c : m_update_connection)
@@ -123,47 +123,58 @@ void CrossRefItem::setUpConnection()
}
/**
* @brief CrossRefItem::boundingRect
* @return the bounding rect of this item
*/
@brief CrossRefItem::boundingRect
@return the bounding rect of this item
*/
QRectF CrossRefItem::boundingRect() const {
return m_bounding_rect;
}
/**
* @brief CrossRefItem::shape
* @return the shape of this item
*/
@brief CrossRefItem::shape
@return the shape of this item
*/
QPainterPath CrossRefItem::shape() const{
return m_shape_path;
}
/**
* @brief CrossRefItem::elementPositionText
* @param elmt
* @return the string corresponding to the position of @elmt in the diagram.
* if @add_prefix is true, prefix (for power and delay contact) is added to the poistion text.
*/
QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_prefix) const
@brief CrossRefItem::elementPositionText
@param elmt
@param add_prefix
@return the string corresponding to the position of elmt in the diagram.
if add_prefix is true,
prefix (for power and delay contact) is added to the poistion text.
*/
QString CrossRefItem::elementPositionText(const Element *elmt,
const bool &add_prefix) const
{
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
XRefProperties xrp =
m_element->diagram()->project()->defaultXRefProperties(
m_element->kindInformations()["type"].toString());
QString formula = xrp.masterLabel();
autonum::sequentialNumbers seq;
QString txt = autonum::AssignVariables::formulaToLabel(formula, seq, elmt->diagram(), elmt);
QString txt = autonum::AssignVariables::formulaToLabel(
formula,
seq, elmt->diagram(),
elmt);
if (add_prefix)
{
if (elmt->kindInformations()["type"].toString() == "power") txt.prepend(m_properties.prefix("power"));
else if (elmt->kindInformations()["type"].toString().contains("delay")) txt.prepend(m_properties.prefix("delay"));
else if (elmt->kindInformations()["state"].toString() == "SW") txt.prepend(m_properties.prefix("switch"));
if (elmt->kindInformations()["type"].toString() == "power")
txt.prepend(m_properties.prefix("power"));
else if (elmt->kindInformations()["type"].toString().contains("delay"))
txt.prepend(m_properties.prefix("delay"));
else if (elmt->kindInformations()["state"].toString() == "SW")
txt.prepend(m_properties.prefix("switch"));
}
return txt;
}
/**
* @brief CrossRefItem::updateProperties
* update the curent properties
*/
@brief CrossRefItem::updateProperties
update the curent properties
*/
void CrossRefItem::updateProperties()
{
XRefProperties xrp = m_element->diagram()->project()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
@@ -183,9 +194,9 @@ void CrossRefItem::updateProperties()
}
/**
* @brief CrossRefItem::updateLabel
* Update the content of the item
*/
@brief CrossRefItem::updateLabel
Update the content of the item
*/
void CrossRefItem::updateLabel()
{
//init the shape and bounding rect
@@ -218,22 +229,31 @@ void CrossRefItem::updateLabel()
}
/**
* @brief CrossRefItem::autoPos
* Calculate and set position automaticaly.
*/
@brief CrossRefItem::autoPos
Calculate and set position automaticaly.
*/
void CrossRefItem::autoPos() {
//We calcul the position according to the @snapTo of the xrefproperties
//We calcul the position according to the @snapTo of the xrefproperties
if (m_properties.snapTo() == XRefProperties::Bottom)
centerToBottomDiagram(this, m_element, m_properties.offset() <= 40 ? 5 : m_properties.offset());
centerToBottomDiagram(this,
m_element,
m_properties.offset() <= 40
? 5
: m_properties.offset());
else
centerToParentBottom(this);
}
/**
@brief CrossRefItem::sceneEvent
@param event
@return
*/
bool CrossRefItem::sceneEvent(QEvent *event)
{
//By default when a QGraphicsItem is a child of a QGraphicsItemGroup
//all events are forwarded to group.
//We override it, when this Xref is in a group
//By default when a QGraphicsItem is a child of a QGraphicsItemGroup
//all events are forwarded to group.
//We override it, when this Xref is in a group
if(m_group)
{
switch (event->type())
@@ -259,22 +279,24 @@ bool CrossRefItem::sceneEvent(QEvent *event)
}
/**
* @brief CrossRefItem::paint
* Paint this item
* @param painter
* @param option
* @param widget
*/
void CrossRefItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
@brief CrossRefItem::paint
Paint this item
@param painter
@param option
@param widget
*/
void CrossRefItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget) {
Q_UNUSED(option)
Q_UNUSED(widget)
m_drawing.play(painter);
}
/**
* @brief CrossRefItem::mouseDoubleClickEvent
* @param event
*/
@brief CrossRefItem::mouseDoubleClickEvent
@param event
*/
void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
@@ -288,7 +310,8 @@ void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
m_hovered_contact->setSelected(true);
//Zoom to the linked slave element
foreach(QGraphicsView *view, m_hovered_contact->diagram()->views())
foreach(QGraphicsView *view,
m_hovered_contact->diagram()->views())
{
QRectF fit = m_hovered_contact->sceneBoundingRect();
fit.adjust(-200, -200, 200, 200);
@@ -297,12 +320,20 @@ void CrossRefItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
}
}
/**
@brief CrossRefItem::hoverEnterEvent
@param event
*/
void CrossRefItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
m_hovered_contact = nullptr;
QGraphicsObject::hoverEnterEvent(event);
}
/**
@brief CrossRefItem::hoverMoveEvent
@param event
*/
void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
QPointF pos = event->pos();
@@ -311,7 +342,7 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
foreach(QRectF rect, m_hovered_contacts_map.values(m_hovered_contact))
{
//Mouse hover the same rect than previous hover event
//Mouse hover the same rect than previous hover event
if (rect.contains(pos))
{
QGraphicsObject::hoverMoveEvent(event);
@@ -319,7 +350,7 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
}
}
//At this point, mouse don't hover previous rect
//At this point, mouse don't hover previous rect
m_hovered_contact = nullptr;
foreach (Element *elmt, m_hovered_contacts_map.keys())
@@ -344,7 +375,7 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
foreach(QRectF rect, m_hovered_contacts_map.values(elmt))
{
//Mouse hover a contact
//Mouse hover a contact
if (rect.contains(pos))
{
m_hovered_contact = elmt;
@@ -357,6 +388,10 @@ void CrossRefItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
}
}
/**
@brief CrossRefItem::hoverLeaveEvent
@param event
*/
void CrossRefItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
m_hovered_contact = nullptr;
@@ -364,6 +399,9 @@ void CrossRefItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QGraphicsObject::hoverLeaveEvent(event);
}
/**
@brief CrossRefItem::linkedChanged
*/
void CrossRefItem::linkedChanged()
{
for(const QMetaObject::Connection& c : m_slave_connection)
@@ -376,17 +414,23 @@ void CrossRefItem::linkedChanged()
for(Element *elmt : m_element->linkedElements())
{
m_slave_connection << connect(elmt, &Element::xChanged, this, &CrossRefItem::updateLabel);
m_slave_connection << connect(elmt, &Element::yChanged, this, &CrossRefItem::updateLabel);
m_slave_connection << connect(elmt,
&Element::xChanged,
this,
&CrossRefItem::updateLabel);
m_slave_connection << connect(elmt,
&Element::yChanged,
this,
&CrossRefItem::updateLabel);
}
updateLabel();
}
/**
* @brief CrossRefItem::buildHeaderContact
* Draw the QPicture of m_hdr_no_ctc and m_hdr_nc_ctc
*/
@brief CrossRefItem::buildHeaderContact
Draw the QPicture of m_hdr_no_ctc and m_hdr_nc_ctc
*/
void CrossRefItem::buildHeaderContact() {
if (!m_hdr_no_ctc.isNull() && !m_hdr_nc_ctc.isNull()) return;
@@ -430,11 +474,13 @@ void CrossRefItem::buildHeaderContact() {
}
/**
* @brief CrossRefItem::setUpCrossBoundingRect
* Get the numbers of slaves elements linked to this parent element,
* for calculate the size of the cross bounding rect.
* The cross ref item is drawing according to the size of the cross bounding rect.
*/
@brief CrossRefItem::setUpCrossBoundingRect
Get the numbers of slaves elements linked to this parent element,
for calculate the size of the cross bounding rect.
The cross ref item is drawing according to the size of
the cross bounding rect.
@param painter
*/
void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
{
//No need to calcul if nothing is linked
@@ -492,10 +538,10 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter)
}
/**
* @brief CrossRefItem::drawAsCross
* Draw this crossref with a cross
* @param painter, painter to use
*/
@brief CrossRefItem::drawAsCross
Draw this crossref with a cross
@param painter: painter to use
*/
void CrossRefItem::drawAsCross(QPainter &painter)
{
//calcul the size of the cross
@@ -522,10 +568,10 @@ void CrossRefItem::drawAsCross(QPainter &painter)
}
/**
* @brief CrossRefItem::drawAsContacts
* Draw this crossref with symbolic contacts
* @param painter painter to use
*/
@brief CrossRefItem::drawAsContacts
Draw this crossref with symbolic contacts
@param painter painter to use
*/
void CrossRefItem::drawAsContacts(QPainter &painter)
{
if (m_element -> isFree())
@@ -567,13 +613,13 @@ void CrossRefItem::drawAsContacts(QPainter &painter)
}
/**
* @brief CrossRefItem::drawContact
* Draw one contact, the type of contact to draw is define in @flags.
* @param painter, painter to use
* @param flags, define how to draw the contact (see enul CONTACTS)
* @param elmt, the element to display text (the position of the contact)
* @return The bounding rect of the draw (contact + text)
*/
@brief CrossRefItem::drawContact
Draw one contact, the type of contact to draw is define in flags.
@param painter : painter to use
@param flags : define how to draw the contact (see enul CONTACTS)
@param elmt : the element to display text (the position of the contact)
@return The bounding rect of the draw (contact + text)
*/
QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
{
QString str = elementPositionText(elmt);
@@ -735,8 +781,13 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
}
//Draw position text
QRectF text_rect = painter.boundingRect(QRectF(30, offset+5, 5, 10), Qt::AlignLeft | Qt::AlignVCenter, str);
painter.drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, str);
QRectF text_rect = painter.boundingRect(
QRectF(30, offset+5, 5, 10),
Qt::AlignLeft | Qt::AlignVCenter,
str);
painter.drawText(text_rect,
Qt::AlignLeft | Qt::AlignVCenter,
str);
bounding_rect = bounding_rect.united(text_rect);
if (m_hovered_contacts_map.contains(elmt)) {
@@ -754,10 +805,10 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt)
}
/**
* @brief CrossRefItem::fillCrossRef
* Fill the content of the cross ref
* @param painter painter to use.
*/
@brief CrossRefItem::fillCrossRef
Fill the content of the cross ref
@param painter painter to use.
*/
void CrossRefItem::fillCrossRef(QPainter &painter)
{
if (m_element->isFree()) return;
@@ -773,7 +824,11 @@ void CrossRefItem::fillCrossRef(QPainter &painter)
painter.setPen(pen);
QString str = elementPositionText(elmt, true);
QRectF bounding = painter.boundingRect(QRectF(no_top_left, QSize(middle_cross, 1)), Qt::AlignLeft, str);
QRectF bounding = painter.boundingRect(
QRectF(no_top_left,
QSize(middle_cross, 1)),
Qt::AlignLeft,
str);
painter.drawText(bounding, Qt::AlignLeft, str);
if (m_hovered_contacts_map.contains(elmt))
@@ -793,11 +848,16 @@ void CrossRefItem::fillCrossRef(QPainter &painter)
foreach(Element *elmt, NCElements())
{
QPen pen = painter.pen();
m_hovered_contact == elmt ? pen.setColor(Qt::blue) :pen.setColor(Qt::black);
m_hovered_contact == elmt ? pen.setColor(Qt::blue)
:pen.setColor(Qt::black);
painter.setPen(pen);
QString str = elementPositionText(elmt, true);
QRectF bounding = painter.boundingRect(QRectF(nc_top_left, QSize(middle_cross, 1)), Qt::AlignRight, str);
QRectF bounding = painter.boundingRect(
QRectF(nc_top_left,
QSize(middle_cross, 1)),
Qt::AlignRight,
str);
painter.drawText(bounding, Qt::AlignRight, str);
if (m_hovered_contacts_map.contains(elmt))
@@ -814,14 +874,18 @@ void CrossRefItem::fillCrossRef(QPainter &painter)
}
/**
* @brief CrossRefItem::AddExtraInfo
* Add the comment info of the parent item if needed.
* @param painter painter to use for draw the text
* @param type type of Info do be draw e.g. comment, location.
*/
@brief CrossRefItem::AddExtraInfo
Add the comment info of the parent item if needed.
@param painter painter to use for draw the text
@param type type of Info do be draw e.g. comment, location.
*/
void CrossRefItem::AddExtraInfo(QPainter &painter, const QString& type)
{
QString text = autonum::AssignVariables::formulaToLabel(m_element -> elementInformations()[type].toString(), m_element->rSequenceStruct(), m_element->diagram(), m_element);
QString text = autonum::AssignVariables::formulaToLabel(
m_element->elementInformations()[type].toString(),
m_element->rSequenceStruct(),
m_element->diagram(),
m_element);
bool must_show = m_element -> elementInformations().keyMustShow(type);
if (!text.isEmpty() && must_show)
@@ -831,38 +895,51 @@ void CrossRefItem::AddExtraInfo(QPainter &painter, const QString& type)
QRectF r, text_bounding;
qreal center = boundingRect().center().x();
qreal width = boundingRect().width() > 70 ? boundingRect().width()/2 : 35;
qreal width = boundingRect().width() > 70
? boundingRect().width()/2
: 35;
r = QRectF(QPointF(center - width, boundingRect().bottom()),
QPointF(center + width, boundingRect().bottom() + 1));
r = QRectF(QPointF(center - width,
boundingRect().bottom()),
QPointF(center + width,
boundingRect().bottom() + 1));
text_bounding = painter.boundingRect(r, Qt::TextWordWrap | Qt::AlignHCenter, text);
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, text);
text_bounding = painter.boundingRect(
r,
Qt::TextWordWrap | Qt::AlignHCenter,
text);
painter.drawText(text_bounding,
Qt::TextWordWrap | Qt::AlignHCenter,
text);
text_bounding.adjust(-1,0,1,0); //adjust only for better visual
m_shape_path.addRect(text_bounding);
prepareGeometryChange();
m_bounding_rect = m_bounding_rect.united(text_bounding);
if (type == "comment") painter.drawRoundedRect(text_bounding, 2, 2);
if (type == "comment") painter.drawRoundedRect(text_bounding,
2,
2);
painter.restore();
}
}
/**
* @brief CrossRefItem::NOElements
* @return The linked elements of @m_element wich are open or switch contact.
* If linked element is a power contact, xref propertie is set to don't show power contact
* and this cross item must be drawed as cross, the element is not append in the list.
*/
@brief CrossRefItem::NOElements
@return The linked elements of m_element wich are open or switch contact.
If linked element is a power contact,
xref propertie is set to don't show power contact
and this cross item must be drawed as cross,
the element is not append in the list.
*/
QList<Element *> CrossRefItem::NOElements() const
{
QList<Element *> no_list;
foreach (Element *elmt, m_element->linkedElements())
{
//We continue if element is a power contact and xref propertie
//is set to don't show power contact
//We continue if element is a power contact and xref propertie
//is set to don't show power contact
if (m_properties.displayHas() == XRefProperties::Cross &&
!m_properties.showPowerContact() &&
elmt -> kindInformations()["type"].toString() == "power")
@@ -880,19 +957,22 @@ QList<Element *> CrossRefItem::NOElements() const
}
/**
* @brief CrossRefItem::NCElements
* @return The linked elements of @m_element wich are close or switch contact
* If linked element is a power contact, xref propertie is set to don't show power contact
* and this cross item must be drawed as cross, the element is not append in the list.
*/
@brief CrossRefItem::NCElements
@return The linked elements of m_element wich are close
or switch contact
If linked element is a power contact,
xref propertie is set to don't show power contact
and this cross item must be drawed as cross,
the element is not append in the list.
*/
QList<Element *> CrossRefItem::NCElements() const
{
QList<Element *> nc_list;
foreach (Element *elmt, m_element->linkedElements())
{
//We continue if element is a power contact and xref propertie
//is set to don't show power contact
//We continue if element is a power contact and xref propertie
//is set to don't show power contact
if (m_properties.displayHas() == XRefProperties::Cross &&
!m_properties.showPowerContact() &&
elmt -> kindInformations()["type"].toString() == "power")