Preserve source widget on click.

Remove TreeTableNodeText from parent, store it in TreeTableNodeLineEdit
and moves it back when the latter loses focus.
This commit is contained in:
SET
2020-11-22 18:58:04 +01:00
parent 14964f9862
commit bbc62a6efa
2 changed files with 15 additions and 6 deletions

View File

@@ -51,6 +51,7 @@ void TreeTableNodeText::OnClick()
m_lineEdit->setReadOnly(true);
m_lineEdit->blurred().connect(m_lineEdit, &TreeTableNodeLineEdit::OnBlurred);
m_lineEdit->setSelection(0, text().toUTF8().length());
m_lineEdit->HoldSourceWidget(removeFromParent());
m_node->setColumnWidget(m_colIndex, unique_ptr<WLineEdit> (m_lineEdit));
m_lineEdit->setFocus(true); // +++
}
@@ -78,13 +79,15 @@ void TreeTableNodeLineEdit::Init(WTreeTableNode* node, uint colIndex)
{
m_node = node;
m_colIndex = colIndex;
m_text = NULL;
clicked().connect(this, &TreeTableNodeLineEdit::OnBlurred);
}
void TreeTableNodeLineEdit::OnBlurred()
{
m_text = new TreeTableNodeText(text(), m_node, m_colIndex);
m_text->clicked().connect(m_text, &TreeTableNodeText::OnClick);
m_node->setColumnWidget(m_colIndex, unique_ptr<TreeTableNodeText> (m_text));
m_node->setColumnWidget(m_colIndex, std::move(m_sourceWidget));
}
void TreeTableNodeLineEdit::HoldSourceWidget(std::unique_ptr<WWidget> sourceWidget)
{
m_sourceWidget.swap(sourceWidget);
}

View File

@@ -58,13 +58,19 @@ public:
WTreeTableNode * node, uint colIndex);
virtual ~TreeTableNodeLineEdit();
/**
* Creates back a TreeTableNodeText replacing this TreeTableNodeLineEdit.
* Move back the original TreeTableNodeText replacing this
* TreeTableNodeLineEdit.
*/
void OnBlurred();
/**
* Keep the original TreeTableNodeText verbatim.
* @param text
*/
void HoldSourceWidget(std::unique_ptr<WWidget> sourceWidget);
private:
WTreeTableNode * m_node;
uint m_colIndex;
TreeTableNodeText * m_text;
std::unique_ptr<WWidget> m_sourceWidget;
void Init(WTreeTableNode * node, uint colIndex);
};