mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-19 20:44:16 +02:00
Terminal strip item: redraw the strip as soon as it changes
TerminalStripItem was connected to nothing: after applying the terminal strip editor (width, catalog terminal, color, type...), undo or redo, the strip drawn on the folio kept its old drawing until something else made the scene repaint, and its bounding rect was not updated when the width of the terminals changed. - TerminalStrip::dataChanged() is emitted when the data of the strip is set, and when the data of the element of one of its terminals changes (Element::setElementData(), Element::setElementInformations()). - TerminalStripItem connects to dataChanged(), orderChanged(), bridgeChanged() and bridgeColorChanged() of its strip, and updates its geometry and redraws itself.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "../../project/projectpropertieshandler.h"
|
||||
#include "../../qetgraphicsitem/qgraphicsitemutility.h"
|
||||
#include "../terminalstrip.h"
|
||||
#include "../terminalstripbridge.h"
|
||||
#include "../physicalterminal.h"
|
||||
#include "../realterminal.h"
|
||||
#include "../ui/terminalstripeditorwindow.h"
|
||||
@@ -49,7 +50,21 @@ TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) :
|
||||
|
||||
void TerminalStripItem::setTerminalStrip(TerminalStrip *strip)
|
||||
{
|
||||
for (const auto &connection_ : std::as_const(m_strip_connections)) {
|
||||
disconnect(connection_);
|
||||
}
|
||||
m_strip_connections.clear();
|
||||
|
||||
m_strip = strip;
|
||||
if (strip)
|
||||
{
|
||||
//Redraw as soon as the strip or one of its terminals changes
|
||||
//(terminal strip editor applied, undo, redo...)
|
||||
m_strip_connections << connect(strip, &TerminalStrip::orderChanged, this, &TerminalStripItem::stripChanged)
|
||||
<< connect(strip, &TerminalStrip::bridgeChanged, this, &TerminalStripItem::stripChanged)
|
||||
<< connect(strip, &TerminalStrip::bridgeColorChanged, this, &TerminalStripItem::stripChanged)
|
||||
<< connect(strip, &TerminalStrip::dataChanged, this, &TerminalStripItem::stripChanged);
|
||||
}
|
||||
m_drawer.setStrip(QSharedPointer<TerminalStripDrawer::TrueTerminalStrip> {
|
||||
new TerminalStripDrawer::TrueTerminalStrip { strip }});
|
||||
m_pending_strip_uuid = QUuid();
|
||||
@@ -256,6 +271,17 @@ TerminalStripLayoutPattern::DrawStyle TerminalStripItem::drawStyle() const {
|
||||
return m_drawer.drawStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStripItem::stripChanged
|
||||
* The strip or one of its terminals changed : the size of the drawing
|
||||
* can change (width of the terminals, number of terminals...), redraw it.
|
||||
*/
|
||||
void TerminalStripItem::stripChanged()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
update();
|
||||
}
|
||||
|
||||
void TerminalStripItem::setDefaultLayout()
|
||||
{
|
||||
if (m_strip && m_strip->project()) {
|
||||
|
||||
@@ -76,9 +76,11 @@ class TerminalStripItem : public QetGraphicsItem
|
||||
private:
|
||||
void setDefaultLayout();
|
||||
QString xrefToolTip(const TerminalStripDrawer::hoverTerminal &terminal) const;
|
||||
void stripChanged();
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_strip;
|
||||
QList<QMetaObject::Connection> m_strip_connections;
|
||||
TerminalStripDrawer::TerminalStripDrawer m_drawer;
|
||||
QUuid m_pending_strip_uuid;
|
||||
};
|
||||
|
||||
@@ -100,6 +100,17 @@ TerminalStripData TerminalStrip::data() const {
|
||||
*/
|
||||
void TerminalStrip::setData(const TerminalStripData &data) {
|
||||
m_data = data;
|
||||
emit dataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::terminalDataChanged
|
||||
* Called when the data of the element of one of the terminals of this strip
|
||||
* is changed (Element::setElementData(), Element::setElementInformations()) :
|
||||
* the items which draw this strip on the folios are redrawn.
|
||||
*/
|
||||
void TerminalStrip::terminalDataChanged() {
|
||||
emit dataChanged();
|
||||
}
|
||||
|
||||
bool TerminalStrip::addTerminal(QSharedPointer<RealTerminal> real_t)
|
||||
|
||||
@@ -53,6 +53,9 @@ class TerminalStrip : public QObject
|
||||
void orderChanged(); //Emitted when the order of the physical terminal is changed
|
||||
void bridgeChanged();
|
||||
void bridgeColorChanged(QSharedPointer<TerminalStripBridge> bridge);
|
||||
//Emitted when the data of the strip (name...) or of one of its
|
||||
//terminals (width, color, type...) is changed : what is drawn changes
|
||||
void dataChanged();
|
||||
public:
|
||||
|
||||
TerminalStrip(QETProject *project);
|
||||
@@ -79,6 +82,7 @@ class TerminalStrip : public QObject
|
||||
|
||||
TerminalStripData data() const;
|
||||
void setData(const TerminalStripData &data);
|
||||
void terminalDataChanged();
|
||||
|
||||
bool addTerminal (QSharedPointer<RealTerminal> real_t);
|
||||
void addTerminals (QVector<QSharedPointer<RealTerminal>> real_t_vector);
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#include "../undocommand/changeelementinformationcommand.h"
|
||||
#include "../undocommand/setautonumcontextcommand.h"
|
||||
#include "crossrefitem.h"
|
||||
#include "terminalelement.h"
|
||||
#include "../TerminalStrip/terminalstrip.h"
|
||||
#include "dynamicelementtextitem.h"
|
||||
#include "elementtextitemgroup.h"
|
||||
#include "iostream"
|
||||
@@ -2087,6 +2089,22 @@ void Element::setUuid(const QUuid &uuid)
|
||||
diagram()->project()->dataBase()->elementUuidChanged(this, old_uuid);
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
@brief notifyTerminalStrip
|
||||
If @a element is a terminal of a terminal strip, tell the strip that the
|
||||
data of the terminal changed, so that the strip is redrawn on the folios.
|
||||
*/
|
||||
void notifyTerminalStrip(Element *element)
|
||||
{
|
||||
if (auto terminal_ = dynamic_cast<TerminalElement *>(element)) {
|
||||
if (auto strip_ = terminal_->parentTerminalStrip()) {
|
||||
strip_->terminalDataChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::storeInformation
|
||||
Write this symbol's information to its project's store, once it is
|
||||
@@ -2116,6 +2134,7 @@ void Element::setElementInformations(DiagramContext dc)
|
||||
}
|
||||
storeInformation();
|
||||
emit elementInfoChange(old_info, m_data.m_informations);
|
||||
notifyTerminalStrip(this);
|
||||
|
||||
// Propagate label change to linked PLC slaves (label is changed via
|
||||
// setElementInformations through the undo stack, not via setElementData)
|
||||
@@ -2204,6 +2223,8 @@ void Element::setElementData(ElementData data)
|
||||
}
|
||||
emit elementInfoChange(old_info, m_data.m_informations);
|
||||
}
|
||||
//Type, function, led... of a terminal are not informations
|
||||
notifyTerminalStrip(this);
|
||||
|
||||
// Propagate PLC master data changes to linked slaves
|
||||
if (m_data.m_type == ElementData::Master && m_data.m_master_type == ElementData::PLC)
|
||||
|
||||
Reference in New Issue
Block a user