Added conversion of lists/arrays plus renames

Renamed/deprecated fromQString(), new function is toString()
This commit is contained in:
sigurdp 2013-12-04 11:51:12 +01:00
parent 4db4e44668
commit 192f4bba59
2 changed files with 51 additions and 10 deletions

View File

@ -39,6 +39,8 @@
#include "cvfVector2.h"
#include "cvfqtUtils.h"
#include <QtCore/QStringList>
namespace cvfqt {
@ -55,22 +57,22 @@ namespace cvfqt {
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString Utils::toQString(const cvf::String& ceeString)
QString Utils::toQString(const cvf::String& cvfString)
{
if (ceeString.isEmpty())
if (cvfString.isEmpty())
{
return QString();
}
if (sizeof(wchar_t) == 2)
{
const unsigned short* strPtr = reinterpret_cast<const unsigned short*>(ceeString.c_str());
const unsigned short* strPtr = reinterpret_cast<const unsigned short*>(cvfString.c_str());
return QString::fromUtf16(strPtr);
}
else if (sizeof(wchar_t) == 4)
{
const unsigned int* strPtr = reinterpret_cast<const unsigned int*>(ceeString.c_str());
const unsigned int* strPtr = reinterpret_cast<const unsigned int*>(cvfString.c_str());
return QString::fromUcs4(strPtr);
}
@ -83,7 +85,7 @@ QString Utils::toQString(const cvf::String& ceeString)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::String Utils::fromQString(const QString& qtString)
cvf::String Utils::toString(const QString& qtString)
{
if (qtString.length() == 0)
{
@ -110,6 +112,39 @@ cvf::String Utils::fromQString(const QString& qtString)
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::String> Utils::toStringVector(const QStringList& stringList)
{
std::vector<cvf::String> strVec;
foreach (QString s, stringList)
{
strVec.push_back(toString(s));
}
return strVec;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList Utils::toQStringList(const std::vector<cvf::String>& stringVector)
{
QStringList strList;
foreach (cvf::String s, stringVector)
{
strList.push_back(toQString(s));
}
return strList;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -54,12 +54,18 @@ namespace cvfqt {
class Utils
{
public:
static QString toQString(const cvf::String& ceeString);
static cvf::String fromQString(const QString& qtString);
static QString toQString(const cvf::String& cvfString);
static cvf::String toString(const QString& qtString);
static std::vector<cvf::String> toStringVector(const QStringList& stringList);
static QStringList toQStringList(const std::vector<cvf::String>& stringVector);
static QImage toQImage(const cvf::TextureImage& textureImage);
static void fromQImage(const QImage& qImage, cvf::TextureImage* textureImage);
static void fromQImageRegion(const QImage& qImage, const cvf::Vec2ui& srcPos, const cvf::Vec2ui& size, cvf::TextureImage* textureImage);
// Deprecated
static cvf::String fromQString(const QString& qtString) { return toString(qtString); }
};
}