diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp index 513a9a8329..ea7bf022f0 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.cpp @@ -371,15 +371,7 @@ void PdmUiListEditor::slotListItemEdited(const QModelIndex&, const QModelIndex&) QStringList uiList = m_model->stringList(); - // Remove dummy elements specifically at the end of list. - - QStringList result; - foreach (const QString &str, uiList) - { - if (str != "" && str != " ") result += str; - } - - this->setValueToField(result); + trimAndSetValuesToField(uiList); } //-------------------------------------------------------------------------------------------------- @@ -406,7 +398,21 @@ void PdmUiListEditor::pasteFromString(const QString& content) { QStringList strList = content.split("\n"); - this->setValueToField(strList); + trimAndSetValuesToField(strList); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void PdmUiListEditor::trimAndSetValuesToField(const QStringList& stringList) +{ + QStringList result; + for (const auto& str : stringList) + { + if (str != "" && str != " ") result += str; + } + + this->setValueToField(result); } //-------------------------------------------------------------------------------------------------- @@ -458,14 +464,7 @@ bool PdmUiListEditor::eventFilter(QObject* object, QEvent * event) { QStringList uiList = m_model->stringList(); - // Remove dummy elements specifically at the end of list. - - QStringList result; - foreach (const QString &str, uiList) - { - if (str != "" && str != " ") result += str; - } - this->setValueToField(result); + trimAndSetValuesToField(uiList); } return true; } diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.h b/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.h index c088bbf056..980622e259 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.h +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiListEditor.h @@ -39,11 +39,12 @@ #include "cafPdmUiFieldEditorHandle.h" -class QStringListModel; class QItemSelection; -class QListViewHeightHint; class QLabel; +class QListViewHeightHint; class QModelIndex; +class QStringList; +class QStringListModel; namespace caf { @@ -93,6 +94,8 @@ protected slots: private: QString contentAsString() const; void pasteFromString(const QString& content); + + void trimAndSetValuesToField(const QStringList& stringList); private: QPointer m_listView;