aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/scxmleditor
diff options
context:
space:
mode:
authorArtem Sokolovskii <artem.sokolovskii@qt.io>2024-04-08 16:09:34 +0200
committerArtem Sokolovskii <artem.sokolovskii@qt.io>2024-04-16 11:31:26 +0000
commit5b9f2d5b3efcc118c6c313d7f65ce69d036d682b (patch)
treeb9cba9b9a8bf7693b7b0b17636f8099103ef0da4 /src/plugins/scxmleditor
parentf452431cdc11a8db4c0c31d852995057620bf765 (diff)
SCXMLEditor: Add conditions for transition
- Moved transition event name always above the line - Added transition condition always below the line Fixes: QTCREATORBUG-21946 Change-Id: Ib3525bd81c4bf4017998e4a6abfd5bc19b4876d7 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src/plugins/scxmleditor')
-rw-r--r--src/plugins/scxmleditor/plugin_interface/tagtextitem.cpp15
-rw-r--r--src/plugins/scxmleditor/plugin_interface/tagtextitem.h2
-rw-r--r--src/plugins/scxmleditor/plugin_interface/transitionitem.cpp75
-rw-r--r--src/plugins/scxmleditor/plugin_interface/transitionitem.h1
-rw-r--r--src/plugins/scxmleditor/scxmleditorconstants.h1
5 files changed, 85 insertions, 9 deletions
diff --git a/src/plugins/scxmleditor/plugin_interface/tagtextitem.cpp b/src/plugins/scxmleditor/plugin_interface/tagtextitem.cpp
index 1613d59927f..791a704db1e 100644
--- a/src/plugins/scxmleditor/plugin_interface/tagtextitem.cpp
+++ b/src/plugins/scxmleditor/plugin_interface/tagtextitem.cpp
@@ -7,6 +7,7 @@
#include <QGraphicsSceneHoverEvent>
#include <QLabel>
#include <QPainter>
+#include <QTextDocument>
using namespace ScxmlEditor::PluginInterface;
@@ -17,7 +18,10 @@ TagTextItem::TagTextItem(QGraphicsItem *parent)
setFlag(ItemIsFocusable, true);
setFlag(ItemIsSelectable, true);
m_textItem = new TextItem(this);
- connect(m_textItem, &TextItem::textChanged, this, [this] { emit textChanged(); });
+ connect(m_textItem, &TextItem::textChanged, this, [this] {
+ m_textItem->setTextWidth(m_maxWidth);
+ emit textChanged();
+ });
connect(m_textItem, &TextItem::textReady,
this, [this](const QString &text) { emit textReady(text); });
connect(m_textItem, &TextItem::selected, this, [this](bool sel) { emit selected(sel); });
@@ -115,3 +119,12 @@ QPointF TagTextItem::movePoint() const
{
return m_movePoint;
}
+
+void TagTextItem::setTextMaxWidth(qreal width)
+{
+ m_maxWidth = width;
+ QTextOption opt = m_textItem->document()->defaultTextOption();
+ opt.setWrapMode(QTextOption::WordWrap);
+ m_textItem->document()->setDefaultTextOption(opt);
+ m_textItem->setTextWidth(m_maxWidth);
+}
diff --git a/src/plugins/scxmleditor/plugin_interface/tagtextitem.h b/src/plugins/scxmleditor/plugin_interface/tagtextitem.h
index 3c0a13b935f..4ffcdbb9426 100644
--- a/src/plugins/scxmleditor/plugin_interface/tagtextitem.h
+++ b/src/plugins/scxmleditor/plugin_interface/tagtextitem.h
@@ -34,6 +34,7 @@ public:
void resetMovePoint(const QPointF &p = QPointF(0, 0));
QPointF movePoint() const;
+ void setTextMaxWidth(qreal width);
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *e) override;
@@ -54,6 +55,7 @@ private:
QPointF m_movePoint;
QPointF m_startPos;
TextItem *m_textItem;
+ qreal m_maxWidth;
};
} // namespace PluginInterface
diff --git a/src/plugins/scxmleditor/plugin_interface/transitionitem.cpp b/src/plugins/scxmleditor/plugin_interface/transitionitem.cpp
index 63f35a1fd2c..20c4ff6e204 100644
--- a/src/plugins/scxmleditor/plugin_interface/transitionitem.cpp
+++ b/src/plugins/scxmleditor/plugin_interface/transitionitem.cpp
@@ -28,6 +28,26 @@ using namespace ScxmlEditor::PluginInterface;
const qreal SELECTION_DISTANCE = 10;
+static QString wrapText(const QString &text)
+{
+ QString wrappedText = "[" + text.trimmed() + "]";
+ return wrappedText;
+
+}
+
+static QString unwrapText(const QString &text)
+{
+ QString unwrappedText = text.trimmed();
+
+ if (unwrappedText.startsWith("["))
+ unwrappedText = unwrappedText.mid(1);
+
+ if (unwrappedText.endsWith("]"))
+ unwrappedText.chop(1);
+
+ return unwrappedText;
+}
+
TransitionItem::TransitionItem(BaseItem *parent)
: BaseItem(parent)
, m_startTargetFactor(0.5, 0.5)
@@ -53,6 +73,15 @@ TransitionItem::TransitionItem(BaseItem *parent)
connect(m_eventTagItem, &TagTextItem::textReady, this, &TransitionItem::textHasChanged);
connect(m_eventTagItem, &TagTextItem::movePointChanged, this, &TransitionItem::textItemPositionChanged);
+ m_condTagItem = new TagTextItem(this);
+ connect(m_condTagItem, &TagTextItem::selected, this, [this](bool sel) { setItemSelected(sel); });
+ connect(m_condTagItem, &TagTextItem::textReady, this, [this](const QString &text) {
+ setTagValue("cond", unwrapText(text));
+ updateEventName();
+ });
+ connect(m_condTagItem, &TagTextItem::movePointChanged,
+ this, &TransitionItem::textItemPositionChanged);
+
checkWarningItems();
}
@@ -80,8 +109,10 @@ void TransitionItem::setTag(ScxmlTag *tag)
{
BaseItem::setTag(tag);
if (tag) {
- if (tag->tagType() == InitialTransition)
+ if (tag->tagType() == InitialTransition) {
m_eventTagItem->setVisible(false);
+ m_condTagItem->setVisible(false);
+ }
}
}
@@ -96,12 +127,22 @@ void TransitionItem::textItemPositionChanged()
}
setEditorInfo(Constants::C_SCXML_EDITORINFO_MOVEPOINT, data);
+ QPointF p2 = m_condTagItem->movePoint();
+ QString data2;
+ if (p2.toPoint() != QPoint(0, 0)) {
+ Serializer s;
+ s.append(p2);
+ data2 = s.data();
+ }
+ setEditorInfo(Constants::C_SCXML_EDITORINFO_MOVEPOINT_COND, data2);
+
updateComponents();
}
void TransitionItem::textHasChanged(const QString &text)
{
setTagValue("event", text);
+ updateComponents();
}
void TransitionItem::createGrabbers()
@@ -876,13 +917,18 @@ void TransitionItem::updateComponents()
QLineF nameLine(m_cornerPoints[ind], m_cornerPoints[ind + 1]);
if (m_targetType <= InternalNoTarget) {
m_eventTagItem->setPos(m_cornerPoints[1].x() + 6, m_cornerPoints[1].y() - m_eventTagItem->boundingRect().height() / 3);
+ m_condTagItem->setPos(m_cornerPoints[1].x() + 6, m_cornerPoints[1].y() + m_condTagItem->boundingRect().height() / 3);
} else {
- const qreal w2 = m_eventTagItem->boundingRect().width() / 2;
- QPointF startPos = nameLine.pointAt(0.5);
- QLineF targetLine(startPos, startPos + QPointF(SELECTION_DISTANCE, SELECTION_DISTANCE));
- targetLine.setAngle(nameLine.angle() + 90);
+ const qreal widthEventItem = m_eventTagItem->boundingRect().width() / 2;
+ m_eventTagItem->setPos(
+ nameLine.pointAt(0.5)
+ + QPointF(-widthEventItem, -m_eventTagItem->boundingRect().height() / 1.5));
+
+ const qreal width = qMax(nameLine.length(), m_eventTagItem->boundingRect().width());
+ m_condTagItem->setTextMaxWidth(width);
+ const qreal widthCondItem = m_condTagItem->boundingRect().width() / 2;
+ m_condTagItem->setPos(nameLine.pointAt(0.5) + QPointF(-widthCondItem, 2));
- m_eventTagItem->setPos(targetLine.p2() + m_eventTagItem->movePoint() - QPointF(w2, m_eventTagItem->boundingRect().height() / 2));
}
if (m_warningItem)
@@ -944,6 +990,7 @@ void TransitionItem::updateEditorInfo(bool allChilds)
const QColor fontColor = editorInfo(Constants::C_SCXML_EDITORINFO_FONTCOLOR);
m_eventTagItem->setDefaultTextColor(fontColor.isValid() ? fontColor : Qt::black);
+ m_condTagItem->setDefaultTextColor(fontColor.isValid() ? fontColor : Qt::black);
const QColor stateColor = editorInfo(Constants::C_SCXML_EDITORINFO_STATECOLOR);
m_pen.setColor(stateColor.isValid() ? stateColor : qRgb(0x12, 0x12, 0x12));
@@ -1026,6 +1073,7 @@ void TransitionItem::readUISpecifiedProperties(const ScxmlTag *tag)
}
m_eventTagItem->resetMovePoint(loadPoint(Constants::C_SCXML_EDITORINFO_MOVEPOINT));
+ m_condTagItem->resetMovePoint(loadPoint(Constants::C_SCXML_EDITORINFO_MOVEPOINT_COND));
if (m_lineSelected)
createGrabbers();
@@ -1048,6 +1096,7 @@ void TransitionItem::finalizeCreation()
void TransitionItem::checkVisibility(double scaleFactor)
{
m_eventTagItem->setVisible(scaleFactor > 0.5);
+ m_condTagItem->setVisible(scaleFactor > 0.5);
}
bool TransitionItem::containsScenePoint(const QPointF &p) const
@@ -1092,6 +1141,8 @@ void TransitionItem::findEndItem()
void TransitionItem::updateEventName()
{
m_eventTagItem->setText(tagValue("event"));
+ m_condTagItem->setText(wrapText(tagValue("cond")));
+ updateComponents();
}
void TransitionItem::storeGeometry(bool block)
@@ -1123,6 +1174,11 @@ void TransitionItem::storeMovePoint(bool block)
setEditorInfo(Constants::C_SCXML_EDITORINFO_MOVEPOINT, QString(), block);
else
savePoint(m_eventTagItem->movePoint(), Constants::C_SCXML_EDITORINFO_MOVEPOINT);
+
+ if (m_condTagItem->movePoint().toPoint() == QPoint(0, 0))
+ setEditorInfo(Constants::C_SCXML_EDITORINFO_MOVEPOINT_COND, QString(), block);
+ else
+ savePoint(m_condTagItem->movePoint(), Constants::C_SCXML_EDITORINFO_MOVEPOINT_COND);
}
void TransitionItem::storeTargetFactors(bool block)
@@ -1176,6 +1232,7 @@ void TransitionItem::updateTargetType()
if (type <= InternalNoTarget) {
m_eventTagItem->resetMovePoint();
+ m_condTagItem->resetMovePoint();
m_arrowSize = 6;
// Remove extra points
while (m_cornerPoints.count() > 2)
@@ -1187,8 +1244,10 @@ void TransitionItem::updateTargetType()
setEditorInfo(Constants::C_SCXML_EDITORINFO_GEOMETRY, QString(), true);
setEditorInfo(Constants::C_SCXML_EDITORINFO_LOCALGEOMETRY, QString(), true);
setEditorInfo(Constants::C_SCXML_EDITORINFO_MOVEPOINT, QString(), true);
+ setEditorInfo(Constants::C_SCXML_EDITORINFO_MOVEPOINT_COND, QString(), true);
setEditorInfo(Constants::C_SCXML_EDITORINFO_STARTTARGETFACTORS, QString(), true);
setEditorInfo(Constants::C_SCXML_EDITORINFO_ENDTARGETFACTORS, QString(), true);
+ updateComponents();
} else {
m_arrowSize = 10;
}
@@ -1244,10 +1303,10 @@ void TransitionItem::updateZValue()
qreal TransitionItem::textWidth() const
{
- return m_eventTagItem->boundingRect().width();
+ return m_eventTagItem->boundingRect().width() + m_condTagItem->boundingRect().width();
}
QRectF TransitionItem::wholeBoundingRect() const
{
- return boundingRect().united(m_eventTagItem->sceneBoundingRect());
+ return boundingRect().united(m_eventTagItem->sceneBoundingRect().united(m_condTagItem->sceneBoundingRect()));
}
diff --git a/src/plugins/scxmleditor/plugin_interface/transitionitem.h b/src/plugins/scxmleditor/plugin_interface/transitionitem.h
index 6eb256d6d83..13a3a3cf2da 100644
--- a/src/plugins/scxmleditor/plugin_interface/transitionitem.h
+++ b/src/plugins/scxmleditor/plugin_interface/transitionitem.h
@@ -143,6 +143,7 @@ private:
bool m_lineSelected = false;
TagTextItem *m_eventTagItem;
+ TagTextItem *m_condTagItem;
TransitionWarningItem *m_warningItem = nullptr;
TransitionTargetType m_targetType = ExternalTarget;
bool m_movingFirstPoint = false;
diff --git a/src/plugins/scxmleditor/scxmleditorconstants.h b/src/plugins/scxmleditor/scxmleditorconstants.h
index 13b9fe2fc54..5fd6e53f075 100644
--- a/src/plugins/scxmleditor/scxmleditorconstants.h
+++ b/src/plugins/scxmleditor/scxmleditorconstants.h
@@ -28,6 +28,7 @@ const char C_SCXML_EDITORINFO_GEOMETRY[] = "geometry";
const char C_SCXML_EDITORINFO_SCENEGEOMETRY[] = "scenegeometry";
const char C_SCXML_EDITORINFO_LOCALGEOMETRY[] = "localGeometry";
const char C_SCXML_EDITORINFO_MOVEPOINT[] = "movePoint";
+const char C_SCXML_EDITORINFO_MOVEPOINT_COND[] = "movePointCond";
const char C_SCXML_EDITORINFO_STARTTARGETFACTORS[] = "startTargetFactors";
const char C_SCXML_EDITORINFO_ENDTARGETFACTORS[] = "endTargetFactors";
const char C_SCXML_EDITORINFO_FONTCOLOR[] = "fontColor";