mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2361 AppFwk : Add cafFilePath and conversion to QVariant
This commit is contained in:
parent
90f9b63b44
commit
f86b13adc8
@ -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
|
||||
)
|
||||
|
||||
|
||||
|
67
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.cpp
Normal file
67
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.cpp
Normal 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;
|
||||
}
|
36
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.h
Normal file
36
Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafFilePath.h
Normal 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);
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user