cleaning this file up a bit while I'm in here

master
zetaPRIME 2022-03-20 03:20:06 -04:00
parent 3eb25120ce
commit dc042ae1ac
1 changed files with 13 additions and 14 deletions

View File

@ -60,8 +60,8 @@ void PortObject::setHighlighted(bool h, bool hideLabel) {
auto gs = static_cast<GadgetScene*>(scene());
if (h && !hideLabel) {
auto c = tcolor[port->dataType()];
auto txt = qs("%1 %2").arg(Util::enumName(port->dataType()).toLower()).arg(Util::hex(port->index));
if (!port->name.isEmpty()) txt = qs("%1 (%2)").arg(port->name).arg(txt);
auto txt = qs("%1 %2").arg(Util::enumName(port->dataType()).toLower(), Util::hex(port->index));
if (!port->name.isEmpty()) txt = qs("%1 (%2)").arg(port->name, txt);
double side = port->type == Port::Input ? -1.0 : 1.0;
gs->toolTip(this, txt, {side, 0}, c);
} else gs->toolTip(this);
@ -76,7 +76,7 @@ PortObject::PortObject(const std::shared_ptr<Data::Port>& p) {
setAcceptedMouseButtons(Qt::LeftButton);
setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
for (auto c : port->connections) {
for (auto& c : port->connections) {
if (auto cc = c.lock(); cc && cc->obj) connectTo(cc->obj);
}
@ -204,7 +204,7 @@ void NodeObject::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
setPos(std::round((x()+cx)/grid)*grid-cx, std::round((y()+cy)/grid)*grid-cy);
auto posDelta = pos() - oPos;
for (auto itm : scene()->selectedItems()) {
for (auto itm : scene()->selectedItems()) { // clazy:exclude=range-loop-detach
if (itm == this) continue;
itm->moveBy(posDelta.x(), posDelta.y()); // apply snap to everything else, in relative terms
}
@ -217,7 +217,7 @@ void NodeObject::mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) {
void NodeObject::contextMenuEvent(QGraphicsSceneContextMenuEvent* e) {
if (!isSelected()) {
for (auto* s : scene()->selectedItems()) s->setSelected(false);
for (auto* s : scene()->selectedItems()) s->setSelected(false); // clazy:exclude=range-loop-detach
setSelected(true);
}
auto* m = new QMenu();
@ -247,7 +247,7 @@ void NodeObject::contextMenuEvent(QGraphicsSceneContextMenuEvent* e) {
}
void NodeObject::bringToTop(bool force) {
for (auto o : collidingItems()) if (o->parentItem() == parentItem() && (force || !o->isSelected())) o->stackBefore(this);
for (auto o : collidingItems()) if (o->parentItem() == parentItem() && (force || !o->isSelected())) o->stackBefore(this); // clazy:exclude=range-loop-detach
}
void NodeObject::createPorts() {
@ -261,8 +261,8 @@ void NodeObject::createPorts() {
QPointF inc(0, PortObject::portSize + PortObject::portSpacing);
QPointF cursor = QPointF(0, 0);
for (auto mdt : node->inputs) {
for (auto pp : mdt.second) {
for (auto& mdt : node->inputs) {
for (auto& pp : mdt.second) {
auto* p = new PortObject(pp.second);
p->setParentItem(ipc);
p->setPos(cursor);
@ -275,8 +275,8 @@ void NodeObject::createPorts() {
ipc->setPen(p);
cursor = QPointF(0, 0);
for (auto mdt : node->outputs) {
for (auto pp : mdt.second) {
for (auto& mdt : node->outputs) {
for (auto& pp : mdt.second) {
auto* p = new PortObject(pp.second);
p->setParentItem(opc);
p->setPos(cursor);
@ -297,7 +297,7 @@ void NodeObject::updateGeometry() {
if (autoPositionPorts) {
qreal pm = PortObject::portSize * .5 + PortObject::portSpacing;
if (inputPortContainer) inputPortContainer->setPos(QPointF(-pm, PortObject::portSize));
if (outputPortContainer) outputPortContainer->setPos(QPointF(boundingRect().width() + pm, PortObject::portSize));
if (outputPortContainer) outputPortContainer->setPos(QPointF(boundingRect().width() + pm, PortObject::portSize)); // NOLINT we're calling this on *this*
}
emit postGeometryUpdate();
}
@ -398,12 +398,11 @@ PortConnectionObject::PortConnectionObject(PortObject* in, PortObject* out) {
in->connections[out] = this;
out->connections[in] = this;
QTimer::singleShot(1, [this] { this->in->scene()->addItem(this); });
QTimer::singleShot(1, this, [this] { this->in->scene()->addItem(this); });
setZValue(-100);
setAcceptHoverEvents(true);
//setFlag(QGraphicsItem::GraphicsItemFlag::)
QTimer::singleShot(1, [this] {
QTimer::singleShot(1, this, [this] {
auto* op = static_cast<QGraphicsObject*>(this->out->parentItem()->parentItem());
auto* ip = static_cast<QGraphicsObject*>(this->in->parentItem()->parentItem());
connect(op, &QGraphicsObject::xChanged, this, &PortConnectionObject::updateEnds);