From 97822cbd2c1a0f4d34d0815aeb91929706c8f399 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 11 Jan 2018 13:49:42 +0100 Subject: [PATCH] #2361 AppFwk : Template specialization of stream operator for vector of FilePath --- .../cafPdmXml/CMakeLists.txt | 3 ++ .../cafInternalPdmFilePathStreamOperators.cpp | 42 +++++++++++++++++++ .../cafInternalPdmFilePathStreamOperators.h | 10 +++++ .../cafInternalPdmXmlFieldReaderWriter.h | 1 + .../cafPdmUiDefaultObjectEditor.cpp | 4 ++ 5 files changed, 60 insertions(+) create mode 100644 Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.cpp create mode 100644 Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.h diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/CMakeLists.txt b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/CMakeLists.txt index c5a8585247..1ba575d743 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/CMakeLists.txt +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/CMakeLists.txt @@ -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 diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.cpp new file mode 100644 index 0000000000..b4dc732802 --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.cpp @@ -0,0 +1,42 @@ +#include "cafInternalPdmFilePathStreamOperators.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QTextStream& operator<<(QTextStream& str, const std::vector& filePathObjects) +{ + for (const auto& filePath : filePathObjects) + { + str << filePath << ";"; + } + + return str; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QTextStream& operator>>(QTextStream& str, std::vector& 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; +} + diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.h new file mode 100644 index 0000000000..1e6a77daa4 --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmFilePathStreamOperators.h @@ -0,0 +1,10 @@ +#pragma once + +#include "cafFilePath.h" + +#include + +#include + +QTextStream& operator << (QTextStream& str, const std::vector& sobj); +QTextStream& operator >> (QTextStream& str, std::vector& sobj); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldReaderWriter.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldReaderWriter.h index 68cd701683..8e5ddb8736 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldReaderWriter.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmXml/cafInternalPdmXmlFieldReaderWriter.h @@ -5,6 +5,7 @@ #include #include "cafInternalPdmStreamOperators.h" +#include "cafInternalPdmFilePathStreamOperators.h" #include "cafPdmReferenceHelper.h" #include "cafInternalPdmFieldIoHelper.h" diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index 5ebf9a60f8..fb0916eede 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -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); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiListEditor, std::vector); +CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR(PdmUiFilePathEditor, FilePath); + //-------------------------------------------------------------------------------------------------- ///