Be more precise in setting optional properties
parent
726e52a81a
commit
0fe433f701
|
@ -140,6 +140,10 @@ pub unsafe extern "C" fn tree_path_get(ptr: *const Tree,
|
|||
pub unsafe extern "C" fn tree_path_set(ptr: *mut Tree, v: QStringIn) {
|
||||
(&mut *ptr).set_path(Some(v.convert()));
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_path_set_none(ptr: *mut Tree) {
|
||||
(&mut *ptr).set_path(None);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn tree_row_count(ptr: *const Tree, row: c_int, parent: usize) -> c_int {
|
||||
|
|
|
@ -54,6 +54,7 @@ extern "C" {
|
|||
void tree_free(Tree::Private*);
|
||||
void tree_path_get(const Tree::Private*, QString*, qstring_set);
|
||||
void tree_path_set(Tree::Private*, qstring_t);
|
||||
void tree_path_set_none(Tree::Private*);
|
||||
};
|
||||
Tree::Tree(QObject *parent):
|
||||
QAbstractItemModel(parent),
|
||||
|
@ -97,7 +98,11 @@ QString Tree::path() const
|
|||
return v;
|
||||
}
|
||||
void Tree::setPath(const QString& v) {
|
||||
tree_path_set(d, v);
|
||||
if (v.isNull()) {
|
||||
tree_path_set_none(d);
|
||||
} else {
|
||||
tree_path_set(d, v);
|
||||
}
|
||||
}
|
||||
extern "C" {
|
||||
void tree_data_file_name(const Tree::Private*, int, quintptr, QString*, qstring_set);
|
||||
|
|
|
@ -572,6 +572,10 @@ void writeObjectCDecl(QTextStream& cpp, const Object& o) {
|
|||
if (p.write) {
|
||||
cpp << QString(" void %2_set(%1::Private*, %3);")
|
||||
.arg(o.name, base, p.type.cSetType) << endl;
|
||||
if (p.optional) {
|
||||
cpp << QString(" void %2_set_none(%1::Private*);")
|
||||
.arg(o.name, base) << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -668,7 +672,15 @@ void writeCppObject(QTextStream& cpp, const Object& o) {
|
|||
}
|
||||
if (p.write) {
|
||||
cpp << "void " << o.name << "::set" << upperInitial(p.name) << "(" << p.type.cppSetType << " v) {" << endl;
|
||||
cpp << QString(" %1_set(d, v);").arg(base) << endl;
|
||||
if (p.optional) {
|
||||
cpp << QString(" if (v.isNull()) {") << endl;
|
||||
cpp << QString(" %1_set_none(d);").arg(base) << endl;
|
||||
cpp << QString(" } else {") << endl;
|
||||
cpp << QString(" %1_set(d, v);").arg(base) << endl;
|
||||
cpp << QString(" }") << endl;
|
||||
} else {
|
||||
cpp << QString(" %1_set(d, v);").arg(base) << endl;
|
||||
}
|
||||
cpp << "}" << endl;
|
||||
}
|
||||
}
|
||||
|
@ -1042,6 +1054,10 @@ pub unsafe extern "C" fn %2_get(ptr: *const %1,
|
|||
pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) {
|
||||
(&mut *ptr).set_%3(Some(v.convert()));
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_set_none(ptr: *mut %1) {
|
||||
(&mut *ptr).set_%3(None);
|
||||
}
|
||||
)").arg(o.name, base, snakeCase(p.name), type);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -199,6 +199,10 @@ pub unsafe extern "C" fn object_optional_string_get(ptr: *const Object,
|
|||
pub unsafe extern "C" fn object_optional_string_set(ptr: *mut Object, v: QStringIn) {
|
||||
(&mut *ptr).set_optional_string(Some(v.convert()));
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_optional_string_set_none(ptr: *mut Object) {
|
||||
(&mut *ptr).set_optional_string(None);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_bytearray_get(ptr: *const Object,
|
||||
|
@ -227,3 +231,7 @@ pub unsafe extern "C" fn object_optional_bytearray_get(ptr: *const Object,
|
|||
pub unsafe extern "C" fn object_optional_bytearray_set(ptr: *mut Object, v: QByteArray) {
|
||||
(&mut *ptr).set_optional_bytearray(Some(v.convert()));
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn object_optional_bytearray_set_none(ptr: *mut Object) {
|
||||
(&mut *ptr).set_optional_bytearray(None);
|
||||
}
|
||||
|
|
|
@ -117,7 +117,6 @@ void TestRustObjectTypes::testOptionalByteArray()
|
|||
testSetter(QByteArray(), &Object::setOptionalBytearray,
|
||||
&Object::optionalBytearray, &Object::optionalBytearrayChanged);
|
||||
const char data[10] = {0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};
|
||||
qDebug() << (QByteArray().data() == 0);
|
||||
testSetter(QByteArray(data, 0), &Object::setOptionalBytearray,
|
||||
&Object::optionalBytearray, &Object::optionalBytearrayChanged);
|
||||
testSetter(QByteArray(data, 10), &Object::setOptionalBytearray,
|
||||
|
|
|
@ -57,10 +57,12 @@ extern "C" {
|
|||
void object_string_set(Object::Private*, qstring_t);
|
||||
void object_optional_string_get(const Object::Private*, QString*, qstring_set);
|
||||
void object_optional_string_set(Object::Private*, qstring_t);
|
||||
void object_optional_string_set_none(Object::Private*);
|
||||
void object_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
|
||||
void object_bytearray_set(Object::Private*, qbytearray_t);
|
||||
void object_optional_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
|
||||
void object_optional_bytearray_set(Object::Private*, qbytearray_t);
|
||||
void object_optional_bytearray_set_none(Object::Private*);
|
||||
};
|
||||
Object::Object(QObject *parent):
|
||||
QObject(parent),
|
||||
|
@ -121,7 +123,11 @@ QString Object::optionalString() const
|
|||
return v;
|
||||
}
|
||||
void Object::setOptionalString(const QString& v) {
|
||||
object_optional_string_set(d, v);
|
||||
if (v.isNull()) {
|
||||
object_optional_string_set_none(d);
|
||||
} else {
|
||||
object_optional_string_set(d, v);
|
||||
}
|
||||
}
|
||||
QByteArray Object::bytearray() const
|
||||
{
|
||||
|
@ -139,5 +145,9 @@ QByteArray Object::optionalBytearray() const
|
|||
return v;
|
||||
}
|
||||
void Object::setOptionalBytearray(const QByteArray& v) {
|
||||
object_optional_bytearray_set(d, v);
|
||||
if (v.isNull()) {
|
||||
object_optional_bytearray_set_none(d);
|
||||
} else {
|
||||
object_optional_bytearray_set(d, v);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue