#2361 AppFwk : Add cafFilePath and conversion to QVariant

This commit is contained in:
Magne Sjaastad 2018-01-11 13:48:47 +01:00
parent 90f9b63b44
commit f86b13adc8
4 changed files with 130 additions and 0 deletions

View File

@ -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
)

View File

@ -0,0 +1,67 @@
#include "cafFilePath.h"
#include <QTextStream>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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;
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <QMetaType>
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);

View File

@ -1,6 +1,7 @@
#pragma once
#include "cafAppEnum.h"
#include "cafFilePath.h"
#include "cafPdmPointer.h"
#include <vector>
@ -141,4 +142,27 @@ public:
}
};
//==================================================================================================
/// Partial specialization for caf::FilePath
//==================================================================================================
template <>
class PdmValueFieldSpecialization<FilePath>
{
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<FilePath>() == variantValue2.value<FilePath>();
}
};
} // End of namespace caf