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 bool isEditable() const = 0;
|
||||
virtual bool isEditing() const = 0;
|
||||
|
||||
virtual void edit() = 0;
|
||||
virtual void finishEdit() = 0;
|
||||
};
|
||||
|
||||
} // namespace qmt
|
||||
|
@@ -98,6 +98,7 @@ public:
|
||||
QSet<QGraphicsItem *> m_selectedItems;
|
||||
QSet<QGraphicsItem *> m_secondarySelectedItems;
|
||||
QGraphicsItem *m_focusItem = nullptr;
|
||||
IEditable *m_editItem = nullptr;
|
||||
bool m_exportSelectedElements = false;
|
||||
QRectF m_sceneBoundingRect;
|
||||
};
|
||||
@@ -955,6 +956,14 @@ void DiagramSceneModel::saveSelectionStatusBeforeExport(bool exportSelectedEleme
|
||||
|
||||
// Selections would also render to the clipboard
|
||||
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();
|
||||
|
||||
foreach (QGraphicsItem *item, m_graphicsItems) {
|
||||
@@ -1002,6 +1011,10 @@ void DiagramSceneModel::restoreSelectedStatusAfterExport(const DiagramSceneModel
|
||||
m_focusItem = status.m_focusItem;
|
||||
}
|
||||
}
|
||||
|
||||
// reset edit item
|
||||
if (status.m_editItem)
|
||||
status.m_editItem->edit();
|
||||
}
|
||||
|
||||
void DiagramSceneModel::recalcSceneRectSize()
|
||||
|
@@ -233,12 +233,23 @@ bool AnnotationItem::isEditable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AnnotationItem::isEditing() const
|
||||
{
|
||||
return m_textItem && m_textItem->hasFocus();
|
||||
}
|
||||
|
||||
void AnnotationItem::edit()
|
||||
{
|
||||
if (m_textItem)
|
||||
m_textItem->setFocus();
|
||||
}
|
||||
|
||||
void AnnotationItem::finishEdit()
|
||||
{
|
||||
if (m_textItem)
|
||||
m_textItem->clearFocus();
|
||||
}
|
||||
|
||||
void AnnotationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton)
|
||||
|
@@ -81,7 +81,9 @@ public:
|
||||
void setBoundarySelected(const QRectF &boundary, bool secondary) override;
|
||||
|
||||
bool isEditable() const override;
|
||||
bool isEditing() const override;
|
||||
void edit() override;
|
||||
void finishEdit() override;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
@@ -284,12 +284,23 @@ bool BoundaryItem::isEditable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BoundaryItem::isEditing() const
|
||||
{
|
||||
return m_textItem && m_textItem->hasFocus();
|
||||
}
|
||||
|
||||
void BoundaryItem::edit()
|
||||
{
|
||||
if (m_textItem)
|
||||
m_textItem->setFocus();
|
||||
}
|
||||
|
||||
void BoundaryItem::finishEdit()
|
||||
{
|
||||
if (m_textItem)
|
||||
m_textItem->clearFocus();
|
||||
}
|
||||
|
||||
void BoundaryItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) {
|
||||
|
@@ -80,7 +80,9 @@ public:
|
||||
void setBoundarySelected(const QRectF &boundary, bool secondary) override;
|
||||
|
||||
bool isEditable() const override;
|
||||
bool isEditing() const override;
|
||||
void edit() override;
|
||||
void finishEdit() override;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
|
@@ -455,6 +455,11 @@ bool ObjectItem::isEditable() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ObjectItem::isEditing() const
|
||||
{
|
||||
return m_nameItem && m_nameItem->hasFocus();
|
||||
}
|
||||
|
||||
void ObjectItem::edit()
|
||||
{
|
||||
// TODO if name is initial name ("New Class" etc) select all text
|
||||
@@ -462,6 +467,12 @@ void ObjectItem::edit()
|
||||
m_nameItem->setFocus();
|
||||
}
|
||||
|
||||
void ObjectItem::finishEdit()
|
||||
{
|
||||
if (m_nameItem)
|
||||
m_nameItem->clearFocus();
|
||||
}
|
||||
|
||||
void ObjectItem::updateStereotypeIconDisplay()
|
||||
{
|
||||
StereotypeDisplayVisitor stereotypeDisplayVisitor;
|
||||
|
@@ -130,7 +130,9 @@ public:
|
||||
void align(AlignType alignType, const QString &identifier) override;
|
||||
|
||||
bool isEditable() const override;
|
||||
bool isEditing() const override;
|
||||
void edit() override;
|
||||
void finishEdit() override;
|
||||
|
||||
protected:
|
||||
void updateStereotypeIconDisplay();
|
||||
|
Reference in New Issue
Block a user