git-svn-id: svn://db.shs.com.ru/pip@672 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -68,6 +68,36 @@ PIVariant::PIVariant(const PIVariant &v) {
|
||||
}
|
||||
|
||||
|
||||
void PIVariant::setValueFromString(const PIString & v) {
|
||||
switch (_type) {
|
||||
case PIVariant::pivBool: {setValue(v.toBool());} break;
|
||||
case PIVariant::pivChar: {setValue(v.toChar());} break;
|
||||
case PIVariant::pivUChar: {setValue((uchar)v.toChar());} break;
|
||||
case PIVariant::pivShort: {setValue(v.toShort());} break;
|
||||
case PIVariant::pivUShort: {setValue(v.toUShort());} break;
|
||||
case PIVariant::pivInt: {setValue(v.toInt());} break;
|
||||
case PIVariant::pivUInt: {setValue(v.toUInt());} break;
|
||||
case PIVariant::pivLLong: {setValue(v.toLLong());} break;
|
||||
case PIVariant::pivULLong: {setValue(v.toULLong());} break;
|
||||
case PIVariant::pivFloat: {setValue(v.toFloat());} break;
|
||||
case PIVariant::pivDouble: {setValue(v.toDouble());} break;
|
||||
case PIVariant::pivLDouble: {setValue(v.toLDouble());} break;
|
||||
case PIVariant::pivTime: {} break; // TODO
|
||||
case PIVariant::pivDate: {} break; // TODO
|
||||
case PIVariant::pivDateTime: {} break; // TODO
|
||||
case PIVariant::pivString: {setValue(v);} break;
|
||||
case PIVariant::pivStringList: {setValue(v.split(";"));} break;
|
||||
case PIVariant::pivEnum: {PIVariantTypes::Enum r = toEnum(); r.selectName(v); setValue(r);} break;
|
||||
case PIVariant::pivFile: {PIVariantTypes::File r = toFile(); r.file = v; setValue(r);} break;
|
||||
case PIVariant::pivDir: {PIVariantTypes::Dir r = toDir(); r.dir = v; setValue(r);} break;
|
||||
case PIVariant::pivColor: {setValue(PIVariantTypes::Color(v.mid(1).toUInt(16)));} break;
|
||||
case PIVariant::pivIODevice: {setValue(PIVariantTypes::IODevice());} break; // TODO
|
||||
case PIVariant::pivCustom: {} break; // TODO;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PIVariant & PIVariant::operator =(const PIVariant & v) {
|
||||
_type = v._type;
|
||||
_content = v._content;
|
||||
@@ -439,6 +469,7 @@ PIString PIVariant::toString() const {
|
||||
case PIVariant::pivFile: {PIVariantTypes::File r; ba >> r; return r.file;}
|
||||
case PIVariant::pivDir: {PIVariantTypes::Dir r; ba >> r; return r.dir;}
|
||||
case PIVariant::pivColor: {PIVariantTypes::Color r; ba >> r; return "#" + PIString::fromNumber(r.rgba, 16);}
|
||||
case PIVariant::pivIODevice: {PIVariantTypes::IODevice r; ba >> r; return "IODevice";} // TODO
|
||||
case PIVariant::pivCustom: return getAsValue<PIString>(*this);
|
||||
default: break;
|
||||
}
|
||||
@@ -534,6 +565,16 @@ PIVariantTypes::Color PIVariant::toColor() const {
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as IODevice
|
||||
* \details In case of IODevice type returns IODevice value. \n
|
||||
* In case of other types returns empty IODevice. */
|
||||
PIVariantTypes::IODevice PIVariant::toIODevice() const {
|
||||
PIByteArray ba(_content);
|
||||
if (_type == PIVariant::pivIODevice) {PIVariantTypes::IODevice r; ba >> r; return r;}
|
||||
return PIVariantTypes::IODevice();
|
||||
}
|
||||
|
||||
|
||||
/** \brief Returns variant content as point
|
||||
* \details In case of PIPointd type returns point value. \n
|
||||
* In case of other types returns empty PIPointd. */
|
||||
|
||||
@@ -236,6 +236,7 @@ public:
|
||||
pivColor /** PIVariantTypes::Color */ ,
|
||||
pivPoint /** PIPoint */ ,
|
||||
pivRect /** PIRect */ ,
|
||||
pivIODevice /** PIVariantTypes::IODevice */ ,
|
||||
pivCustom /** Custom */ = 0xFF
|
||||
};
|
||||
|
||||
@@ -319,6 +320,9 @@ public:
|
||||
//! Constructs variant from color
|
||||
PIVariant(const PIVariantTypes::Color & v) {initType(v);}
|
||||
|
||||
//! Constructs variant from IODevice
|
||||
PIVariant(const PIVariantTypes::IODevice & v) {initType(v);}
|
||||
|
||||
//! Constructs variant from point
|
||||
PIVariant(const PIPointd & v) {initType(v);}
|
||||
|
||||
@@ -401,12 +405,18 @@ public:
|
||||
//! Set variant content and type to color
|
||||
void setValue(const PIVariantTypes::Color & v) {initType(v);}
|
||||
|
||||
//! Set variant content and type to IODevice
|
||||
void setValue(const PIVariantTypes::IODevice & v) {initType(v);}
|
||||
|
||||
//! Set variant content and type to point
|
||||
void setValue(const PIPointd & v) {initType(v);}
|
||||
|
||||
//! Set variant content and type to rect
|
||||
void setValue(const PIRectd & v) {initType(v);}
|
||||
|
||||
//! Set current value from string without change type
|
||||
void setValueFromString(const PIString & v);
|
||||
|
||||
|
||||
bool toBool() const;
|
||||
int toInt() const;
|
||||
@@ -426,6 +436,7 @@ public:
|
||||
PIVariantTypes::File toFile() const;
|
||||
PIVariantTypes::Dir toDir() const;
|
||||
PIVariantTypes::Color toColor() const;
|
||||
PIVariantTypes::IODevice toIODevice() const;
|
||||
PIPointd toPoint() const;
|
||||
PIRectd toRect() const;
|
||||
|
||||
@@ -514,6 +525,8 @@ public:
|
||||
//! Assign operator
|
||||
PIVariant & operator =(const PIVariantTypes::Color & v) {setValue(v); return *this;}
|
||||
//! Assign operator
|
||||
PIVariant & operator =(const PIVariantTypes::IODevice & v) {setValue(v); return *this;}
|
||||
//! Assign operator
|
||||
PIVariant & operator =(const PIPointd & v) {setValue(v); return *this;}
|
||||
//! Assign operator
|
||||
PIVariant & operator =(const PIRectd & v) {setValue(v); return *this;}
|
||||
@@ -643,6 +656,7 @@ template<> inline PIVariantTypes::Enum PIVariant::value() const {return toEnum()
|
||||
template<> inline PIVariantTypes::File PIVariant::value() const {return toFile();}
|
||||
template<> inline PIVariantTypes::Dir PIVariant::value() const {return toDir();}
|
||||
template<> inline PIVariantTypes::Color PIVariant::value() const {return toColor();}
|
||||
template<> inline PIVariantTypes::IODevice PIVariant::value() const {return toIODevice();}
|
||||
template<> inline PIPointd PIVariant::value() const {return toPoint();}
|
||||
template<> inline PIRectd PIVariant::value() const {return toRect();}
|
||||
|
||||
@@ -671,6 +685,7 @@ template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Enum & v)
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::File & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Dir & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::Color & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIVariantTypes::IODevice & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIPointd & v) {return PIVariant(v);}
|
||||
template<> inline PIVariant PIVariant::fromValue(const PIRectd & v) {return PIVariant(v);}
|
||||
|
||||
@@ -698,6 +713,7 @@ template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Enum>() {re
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::File>() {return PIVariant::pivFile;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Dir>() {return PIVariant::pivDir;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::Color>() {return PIVariant::pivColor;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIVariantTypes::IODevice>() {return PIVariant::pivIODevice;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIPointd>() {return PIVariant::pivPoint;}
|
||||
template<> inline PIVariant::Type PIVariant::getType<PIRectd>() {return PIVariant::pivRect;}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "pivarianttypes.h"
|
||||
#include "pipropertystorage.h"
|
||||
|
||||
|
||||
int PIVariantTypes::Enum::selectedValue() const {
|
||||
@@ -80,6 +81,24 @@ PIStringList PIVariantTypes::Enum::names() const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void PIVariantTypes::IODevice::set(const PIPropertyStorage & ps) {
|
||||
props.clear();
|
||||
props << ps;
|
||||
}
|
||||
|
||||
|
||||
PIPropertyStorage PIVariantTypes::IODevice::get() const {
|
||||
PIPropertyStorage ret;
|
||||
PIByteArray ba = props;
|
||||
if (!ba.isEmpty()) ba >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIVariantTypes::Enumerator & v) {
|
||||
enum_list << v;
|
||||
return *this;
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "pistring.h"
|
||||
|
||||
class PIPropertyStorage;
|
||||
|
||||
|
||||
namespace PIVariantTypes {
|
||||
|
||||
@@ -75,6 +77,13 @@ namespace PIVariantTypes {
|
||||
uint rgba;
|
||||
};
|
||||
|
||||
struct PIP_EXPORT IODevice {
|
||||
IODevice() {}
|
||||
void set(const PIPropertyStorage & ps);
|
||||
PIPropertyStorage get() const;
|
||||
PIByteArray props;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PIVariantTypes::Enumerator & v) {s << v.value << v.name; return s;}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "pitimer.h"
|
||||
#include "piqueue.h"
|
||||
|
||||
|
||||
// function executed from threaded read, pass ThreadedReadData, readedData, sizeOfData
|
||||
typedef bool (*ReadRetFunc)(void * , uchar * , int );
|
||||
|
||||
@@ -344,7 +345,13 @@ protected:
|
||||
virtual PIString constructFullPathDevice() const {return path();}
|
||||
|
||||
//! Reimplement to configure your device with parameters of full unambiguous string. Default implementation does nothing
|
||||
virtual void configureFromFullPathDevice(const PIString & full_path) {;}
|
||||
virtual void configureFromFullPathDevice(const PIString & full_path) {setPath(full_path);}
|
||||
|
||||
//! Reimplement to construct full unambiguous string, describes this device. Default implementation returns \a path()
|
||||
virtual PIVariantTypes::IODevice constructPropertyStorage() const {return PIVariantTypes::IODevice();}
|
||||
|
||||
//! Reimplement to configure your device with parameters of full unambiguous string. Default implementation does nothing
|
||||
virtual void configureFromPropertyStorage(const PIVariantTypes::IODevice & d) {}
|
||||
|
||||
//! Reimplement to apply new device options
|
||||
virtual void optionsChanged() {;}
|
||||
|
||||
Reference in New Issue
Block a user