#2361 AppFwk : Template specialization of stream operator for vector of FilePath

This commit is contained in:
Magne Sjaastad 2018-01-11 13:49:42 +01:00
parent f86b13adc8
commit 97822cbd2c
5 changed files with 60 additions and 0 deletions

View File

@ -14,12 +14,15 @@ include_directories (
set( PROJECT_FILES
cafInternalPdmFieldIoHelper.cpp
cafInternalPdmFieldIoHelper.h
cafInternalPdmFilePathStreamOperators.cpp
cafInternalPdmFilePathStreamOperators.h
cafInternalPdmStreamOperators.cpp
cafInternalPdmStreamOperators.h
cafInternalPdmXmlFieldCapability.h
cafInternalPdmXmlFieldCapability.inl
cafInternalPdmXmlFieldReaderWriter.cpp
cafInternalPdmXmlFieldReaderWriter.h
cafPdmXmlFieldHandle.cpp
cafPdmXmlFieldHandle.h
cafPdmXmlObjectHandle.cpp

View File

@ -0,0 +1,42 @@
#include "cafInternalPdmFilePathStreamOperators.h"
#include <QStringList>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QTextStream& operator<<(QTextStream& str, const std::vector<caf::FilePath>& filePathObjects)
{
for (const auto& filePath : filePathObjects)
{
str << filePath << ";";
}
return str;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QTextStream& operator>>(QTextStream& str, std::vector<caf::FilePath>& filePathObjects)
{
QString stringSeparatedBySemicolon;
while (str.status() == QTextStream::Ok)
{
// Read QChar to avoid white space trimming when reading QString
QChar singleChar;
str >> singleChar;
stringSeparatedBySemicolon += singleChar;
}
QStringList splitBySemicolon = stringSeparatedBySemicolon.split(";");
for (const auto& s : splitBySemicolon )
{
filePathObjects.push_back(s);
}
return str;
}

View File

@ -0,0 +1,10 @@
#pragma once
#include "cafFilePath.h"
#include <QTextStream>
#include <vector>
QTextStream& operator << (QTextStream& str, const std::vector<caf::FilePath>& sobj);
QTextStream& operator >> (QTextStream& str, std::vector<caf::FilePath>& sobj);

View File

@ -5,6 +5,7 @@
#include <QTextStream>
#include "cafInternalPdmStreamOperators.h"
#include "cafInternalPdmFilePathStreamOperators.h"
#include "cafPdmReferenceHelper.h"
#include "cafInternalPdmFieldIoHelper.h"

View File

@ -36,11 +36,13 @@
#include "cafPdmUiDefaultObjectEditor.h"
#include "cafFilePath.h"
#include "cafPdmField.h"
#include "cafPdmProxyValueField.h"
#include "cafPdmUiCheckBoxEditor.h"
#include "cafPdmUiDateEditor.h"
#include "cafPdmUiFieldEditorHandle.h"
#include "cafPdmUiFilePathEditor.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiListEditor.h"
@ -64,6 +66,8 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector<int>);
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector<unsigned int>);
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector<float>);
CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiFilePathEditor, FilePath);
//--------------------------------------------------------------------------------------------------
///