From ea1ede9cb3fed5a49a43f4ec65a13e5f3dca42f9 Mon Sep 17 00:00:00 2001 From: joshua Date: Wed, 28 Sep 2022 21:53:30 +0200 Subject: [PATCH] Remove unnecessary assert Just call : void DynamicTextFieldEditor::disconnectConnections() instead of use an assert if there is an active connection. --- sources/editor/ui/texteditor.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sources/editor/ui/texteditor.cpp b/sources/editor/ui/texteditor.cpp index 512a5614b..3f641e819 100644 --- a/sources/editor/ui/texteditor.cpp +++ b/sources/editor/ui/texteditor.cpp @@ -70,8 +70,10 @@ void TextEditor::updateForm() setUpEditConnection(); } -void TextEditor::setUpChangeConnection(QPointer part) { - assert(m_change_connection.isEmpty()); +void TextEditor::setUpChangeConnection(QPointer part) +{ + disconnectChangeConnection(); + m_change_connection << connect(part, &PartText::plainTextChanged, this, &TextEditor::updateForm); m_change_connection << connect(part, &PartText::xChanged, this, &TextEditor::updateForm); m_change_connection << connect(part, &PartText::yChanged, this, &TextEditor::updateForm); @@ -82,8 +84,8 @@ void TextEditor::setUpChangeConnection(QPointer part) { void TextEditor::disconnectChangeConnection() { - for (QMetaObject::Connection c : m_change_connection) { - disconnect(c); + for (const auto &connection : qAsConst(m_change_connection)) { + disconnect(connection); } m_change_connection.clear(); } @@ -122,20 +124,19 @@ bool TextEditor::setPart(CustomElementPart *part) { return false; } -bool TextEditor::setParts(QList parts) { - if (parts.isEmpty()) { +bool TextEditor::setParts(QList parts) +{ + if (parts.isEmpty()) + { m_parts.clear(); - if (m_text) { - disconnectChangeConnection(); - } + disconnectChangeConnection(); m_text = nullptr; return true; } - if (PartText *part = static_cast(parts.first())) { - if (m_text) { - disconnectChangeConnection(); - } + if (PartText *part = static_cast(parts.first())) + { + disconnectChangeConnection(); m_text = part; m_parts.clear(); m_parts.append(part);