#2361 AppFwk : cafPdmuiListEditor : Refactor setting of strings to field

This commit is contained in:
Magne Sjaastad 2018-01-11 13:46:45 +01:00
parent 3786adc9b7
commit 90f9b63b44
2 changed files with 22 additions and 20 deletions

View File

@ -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;
}

View File

@ -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<QListViewHeightHint> m_listView;