diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2010-12-29 16:34:39 -0200 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:12:51 -0300 |
commit | 87ae5790fa75114dbf335380ca7ab644b013a50b (patch) | |
tree | c4b502dcf425cb832d8ba1c577d790a1ba28ce1a | |
parent | 4a25e3a3801cebfb90cf89fd1eb1faf05c4725a1 (diff) |
Add support to fix the bug#493 - "__eq__ and friends not implemented for QKeyEvent == QKeySequence"
-rw-r--r-- | generator/cppgenerator.cpp | 8 | ||||
-rw-r--r-- | tests/libsample/objecttypeoperators.cpp | 22 | ||||
-rw-r--r-- | tests/libsample/objecttypeoperators.h | 8 | ||||
-rw-r--r-- | tests/samplebinding/objecttypeoperators_test.py | 9 |
4 files changed, 40 insertions, 7 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index 68a00e0a4..a2da128b0 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -2013,6 +2013,9 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } } else if (func->isOperatorOverload()) { QString firstArg("(*" CPP_SELF_VAR ")"); + if (func->isPointerOperator()) + firstArg.remove(1, 1); // remove the de-reference operator + QString secondArg(CPP_ARG0); if (!func->isUnaryOperator() && shouldDereferenceArgumentPointer(func->arguments().first())) { secondArg.prepend('('); @@ -2855,7 +2858,10 @@ void CppGenerator::writeRichCompareFunction(QTextStream& s, const AbstractMetaCl s << INDENT << "Py_INCREF(Py_None);" << endl; s << INDENT << CPP_SELF_VAR " " << op << " cppOther; // this op return void" << endl; } else { - writeToPythonConversion(s, func->type(), metaClass, CPP_SELF_VAR " " + op + " cppOther"); + QByteArray self(CPP_SELF_VAR); + if (func->isPointerOperator()) + self.prepend('&'); + writeToPythonConversion(s, func->type(), metaClass, self + ' ' + op + " cppOther"); s << ';' << endl; } } diff --git a/tests/libsample/objecttypeoperators.cpp b/tests/libsample/objecttypeoperators.cpp index 08c49b1a4..43aedc5de 100644 --- a/tests/libsample/objecttypeoperators.cpp +++ b/tests/libsample/objecttypeoperators.cpp @@ -31,13 +31,27 @@ bool ObjectTypeOperators::operator==(const ObjectTypeOperators& other) const return m_key == other.m_key; } -bool ObjectTypeOperators::operator==(const std::string& other) const +const ObjectTypeOperators& ObjectTypeOperators::operator<(const ObjectTypeOperators& other) const { - return m_key == other; + return m_key < other.m_key ? *this : other; } -const ObjectTypeOperators& ObjectTypeOperators::operator<(const ObjectTypeOperators& other) const +bool operator==(const ObjectTypeOperators* obj, const std::string& str) { - return m_key < other.m_key ? *this : other; + return obj->key() == str; +} + +bool operator==(const std::string& str, const ObjectTypeOperators* obj) +{ + return str == obj->key(); +} + +std::string operator+(const ObjectTypeOperators* obj, const std::string& str) +{ + return obj->key() + str; } +std::string operator+(const std::string& str, const ObjectTypeOperators* obj) +{ + return str + obj->key(); +} diff --git a/tests/libsample/objecttypeoperators.h b/tests/libsample/objecttypeoperators.h index 1d65eb167..9c1a85dc7 100644 --- a/tests/libsample/objecttypeoperators.h +++ b/tests/libsample/objecttypeoperators.h @@ -29,10 +29,9 @@ class LIBSAMPLE_API ObjectTypeOperators { public: - ObjectTypeOperators(const std::string key); + explicit ObjectTypeOperators(const std::string key); bool operator==(const ObjectTypeOperators& other) const; - bool operator==(const std::string& other) const; const ObjectTypeOperators& operator<(const ObjectTypeOperators& other) const; // chaos! @@ -47,4 +46,9 @@ private: ObjectTypeOperators& operator=(ObjectTypeOperators&); }; +LIBSAMPLE_API bool operator==(const ObjectTypeOperators* obj, const std::string& str); +LIBSAMPLE_API bool operator==(const std::string& str, const ObjectTypeOperators* obj); +LIBSAMPLE_API std::string operator+(const ObjectTypeOperators* obj, const std::string& str); +LIBSAMPLE_API std::string operator+(const std::string& str, const ObjectTypeOperators* obj); + #endif // OBJECTTYPEOPERATORS_H diff --git a/tests/samplebinding/objecttypeoperators_test.py b/tests/samplebinding/objecttypeoperators_test.py index d03c9bc48..148bc3591 100644 --- a/tests/samplebinding/objecttypeoperators_test.py +++ b/tests/samplebinding/objecttypeoperators_test.py @@ -39,5 +39,14 @@ class ObjectTypeOperatorsTest(unittest.TestCase): self.assertEqual(None, a > b) self.assertEqual(a.key(), "aoperator>") + def testPointerOpeators(self): + a = ObjectTypeOperators("a") + b = ObjectTypeOperators("b") + self.assertEqual(a + "bc", "abc") + self.assertEqual("bc" + a, "bca") + self.assertEqual("a", a) + self.assertEqual(a, "a") + + if __name__ == '__main__': unittest.main() |