forked from qt-creator/qt-creator
ModelEditor: Clear edit focus on exporting diagram
Task-number: QTCREATORBUG-16689 Change-Id: I01fb97e744a813c4f6c8cb2180e4c49cdafe17ec Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -33,8 +33,10 @@ public:
|
|||||||
virtual ~IEditable() { }
|
virtual ~IEditable() { }
|
||||||
|
|
||||||
virtual bool isEditable() const = 0;
|
virtual bool isEditable() const = 0;
|
||||||
|
virtual bool isEditing() const = 0;
|
||||||
|
|
||||||
virtual void edit() = 0;
|
virtual void edit() = 0;
|
||||||
|
virtual void finishEdit() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace qmt
|
} // namespace qmt
|
||||||
|
@@ -98,6 +98,7 @@ public:
|
|||||||
QSet<QGraphicsItem *> m_selectedItems;
|
QSet<QGraphicsItem *> m_selectedItems;
|
||||||
QSet<QGraphicsItem *> m_secondarySelectedItems;
|
QSet<QGraphicsItem *> m_secondarySelectedItems;
|
||||||
QGraphicsItem *m_focusItem = nullptr;
|
QGraphicsItem *m_focusItem = nullptr;
|
||||||
|
IEditable *m_editItem = nullptr;
|
||||||
bool m_exportSelectedElements = false;
|
bool m_exportSelectedElements = false;
|
||||||
QRectF m_sceneBoundingRect;
|
QRectF m_sceneBoundingRect;
|
||||||
};
|
};
|
||||||
@@ -955,6 +956,14 @@ void DiagramSceneModel::saveSelectionStatusBeforeExport(bool exportSelectedEleme
|
|||||||
|
|
||||||
// Selections would also render to the clipboard
|
// Selections would also render to the clipboard
|
||||||
m_graphicsScene->clearSelection();
|
m_graphicsScene->clearSelection();
|
||||||
|
foreach (QGraphicsItem *item, m_graphicsItems) {
|
||||||
|
if (IEditable *editItem = dynamic_cast<IEditable *>(item)) {
|
||||||
|
if (editItem->isEditing()) {
|
||||||
|
status->m_editItem = editItem;
|
||||||
|
editItem->finishEdit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
removeExtraSceneItems();
|
removeExtraSceneItems();
|
||||||
|
|
||||||
foreach (QGraphicsItem *item, m_graphicsItems) {
|
foreach (QGraphicsItem *item, m_graphicsItems) {
|
||||||
@@ -1002,6 +1011,10 @@ void DiagramSceneModel::restoreSelectedStatusAfterExport(const DiagramSceneModel
|
|||||||
m_focusItem = status.m_focusItem;
|
m_focusItem = status.m_focusItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset edit item
|
||||||
|
if (status.m_editItem)
|
||||||
|
status.m_editItem->edit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagramSceneModel::recalcSceneRectSize()
|
void DiagramSceneModel::recalcSceneRectSize()
|
||||||
|
@@ -233,12 +233,23 @@ bool AnnotationItem::isEditable() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AnnotationItem::isEditing() const
|
||||||
|
{
|
||||||
|
return m_textItem && m_textItem->hasFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void AnnotationItem::edit()
|
void AnnotationItem::edit()
|
||||||
{
|
{
|
||||||
if (m_textItem)
|
if (m_textItem)
|
||||||
m_textItem->setFocus();
|
m_textItem->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnnotationItem::finishEdit()
|
||||||
|
{
|
||||||
|
if (m_textItem)
|
||||||
|
m_textItem->clearFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void AnnotationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void AnnotationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton)
|
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton)
|
||||||
|
@@ -81,7 +81,9 @@ public:
|
|||||||
void setBoundarySelected(const QRectF &boundary, bool secondary) override;
|
void setBoundarySelected(const QRectF &boundary, bool secondary) override;
|
||||||
|
|
||||||
bool isEditable() const override;
|
bool isEditable() const override;
|
||||||
|
bool isEditing() const override;
|
||||||
void edit() override;
|
void edit() override;
|
||||||
|
void finishEdit() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
@@ -284,12 +284,23 @@ bool BoundaryItem::isEditable() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BoundaryItem::isEditing() const
|
||||||
|
{
|
||||||
|
return m_textItem && m_textItem->hasFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void BoundaryItem::edit()
|
void BoundaryItem::edit()
|
||||||
{
|
{
|
||||||
if (m_textItem)
|
if (m_textItem)
|
||||||
m_textItem->setFocus();
|
m_textItem->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BoundaryItem::finishEdit()
|
||||||
|
{
|
||||||
|
if (m_textItem)
|
||||||
|
m_textItem->clearFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void BoundaryItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void BoundaryItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {
|
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {
|
||||||
|
@@ -80,7 +80,9 @@ public:
|
|||||||
void setBoundarySelected(const QRectF &boundary, bool secondary) override;
|
void setBoundarySelected(const QRectF &boundary, bool secondary) override;
|
||||||
|
|
||||||
bool isEditable() const override;
|
bool isEditable() const override;
|
||||||
|
bool isEditing() const override;
|
||||||
void edit() override;
|
void edit() override;
|
||||||
|
void finishEdit() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
@@ -455,6 +455,11 @@ bool ObjectItem::isEditable() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ObjectItem::isEditing() const
|
||||||
|
{
|
||||||
|
return m_nameItem && m_nameItem->hasFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectItem::edit()
|
void ObjectItem::edit()
|
||||||
{
|
{
|
||||||
// TODO if name is initial name ("New Class" etc) select all text
|
// TODO if name is initial name ("New Class" etc) select all text
|
||||||
@@ -462,6 +467,12 @@ void ObjectItem::edit()
|
|||||||
m_nameItem->setFocus();
|
m_nameItem->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectItem::finishEdit()
|
||||||
|
{
|
||||||
|
if (m_nameItem)
|
||||||
|
m_nameItem->clearFocus();
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectItem::updateStereotypeIconDisplay()
|
void ObjectItem::updateStereotypeIconDisplay()
|
||||||
{
|
{
|
||||||
StereotypeDisplayVisitor stereotypeDisplayVisitor;
|
StereotypeDisplayVisitor stereotypeDisplayVisitor;
|
||||||
|
@@ -130,7 +130,9 @@ public:
|
|||||||
void align(AlignType alignType, const QString &identifier) override;
|
void align(AlignType alignType, const QString &identifier) override;
|
||||||
|
|
||||||
bool isEditable() const override;
|
bool isEditable() const override;
|
||||||
|
bool isEditing() const override;
|
||||||
void edit() override;
|
void edit() override;
|
||||||
|
void finishEdit() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateStereotypeIconDisplay();
|
void updateStereotypeIconDisplay();
|
||||||
|
Reference in New Issue
Block a user