diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt index 1108fc67e8..725ff7201f 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/CMakeLists.txt @@ -39,12 +39,15 @@ set( PROJECT_FILES cafPdmReferenceHelper.h cafPdmUiFieldHandleInterface.h cafPdmValueField.h + cafInternalPdmValueFieldSpecializations.h cafNotificationCenter.cpp cafNotificationCenter.h cafTristate.cpp cafTristate.h + cafFilePath.cpp + cafFilePath.h ) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.cpp new file mode 100644 index 0000000000..edc816de53 --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.cpp @@ -0,0 +1,67 @@ +#include "cafFilePath.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::FilePath::FilePath() {} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +caf::FilePath::FilePath(const QString& filePath) : m_filePath(filePath) {} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString caf::FilePath::path() const +{ + return m_filePath; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::FilePath::setPath(const QString& filePath) +{ + m_filePath = filePath; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::FilePath::operator=(const FilePath& other) +{ + m_filePath = other.m_filePath; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool caf::FilePath::operator==(const FilePath& other) const +{ + return m_filePath == other.m_filePath; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QTextStream& operator>>(QTextStream& str, caf::FilePath& filePath) +{ + QString text; + str >> text; + filePath.setPath(text); + + return str; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QTextStream& operator<<(QTextStream& str, const caf::FilePath& filePath) +{ + str << filePath.path(); + + return str; +} diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.h new file mode 100644 index 0000000000..e859bfe079 --- /dev/null +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +class QTextStream; + +namespace caf +{ +//================================================================================================== +// +//================================================================================================== +class FilePath +{ +public: + FilePath(); + FilePath(const QString& filePath); + + QString path() const; + void setPath(const QString& valueText); + + void operator=(const FilePath& other); + bool operator==(const FilePath& other) const; + +private: + QString m_filePath; +}; + +} // end namespace caf + +//================================================================================================== +// Overload of QTextStream +//================================================================================================== +QTextStream& operator>>(QTextStream& str, caf::FilePath& filePath); +QTextStream& operator<<(QTextStream& str, const caf::FilePath& filePath); + +Q_DECLARE_METATYPE(caf::FilePath); diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafInternalPdmValueFieldSpecializations.h b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafInternalPdmValueFieldSpecializations.h index 5aa3878e38..8aef1f8988 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafInternalPdmValueFieldSpecializations.h +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafInternalPdmValueFieldSpecializations.h @@ -1,6 +1,7 @@ #pragma once #include "cafAppEnum.h" +#include "cafFilePath.h" #include "cafPdmPointer.h" #include @@ -141,4 +142,27 @@ public: } }; +//================================================================================================== +/// Partial specialization for caf::FilePath +//================================================================================================== +template <> +class PdmValueFieldSpecialization +{ +public: + static QVariant convert(const FilePath& value) + { + return QVariant(value.path()); + } + + static void setFromVariant(const QVariant& variantValue, FilePath& value) + { + value.setPath(variantValue.toString()); + } + + static bool isEqual(const QVariant& variantValue, const QVariant& variantValue2) + { + return variantValue.value() == variantValue2.value(); + } +}; + } // End of namespace caf