aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
Commit message (Collapse)AuthorAgeFilesLines
* Implement default __ne__ and __eq__ for all PySide typesAlex Hughes2020-09-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | PySide types have been following the Qt implementation of comparisons, completely. This is not correct for Python, because the Python default has the operators `==` and `!=` at least. They are needed for tests like `obj in collection`. We fix this by redirecting the default case to `PyBaseObject_Type.tp_richcompare`. This is the correct way to fix it, because for types which do not define `tp_richcompare', this is the default, anyway. From the original patch, the test case is still in use. Old message: Implement __ne__ and __eq__ for QTreeWidgetItem Testing if a QTreeWidgetItem belongs to a list raises a NotImplementedError. I have exposed the operator== and the operator!= from C++ to shiboken which has solved our eq operator issue. Implemented the test from PYSIDE-74 for the QTreeWidgetItem eq operator and the ne operator. This also allows us to have the behavior "QTreeWidgetItem in ['a']" and "QTreeWidgetItem not in ['a']". Adding qtreewidgetitem_test.py to CMakeFiles.txt Fixes: PYSIDE-74 Change-Id: Id221c0163fc8c2d85730c4c26f22db5f61710706 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* Add support for briefdescription in doxygen parseRenato Araujo Oliveira Filho2020-09-022-16/+20
| | | | | | | | Extract briefdescription from doxygen files and make sure to generate sphinx docs with it Change-Id: Ibd2b104a2c85de6c3db1e8a48add061c804bd489 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Skip sphinx indexing for functions with multiple signaturesRenato Araujo Oliveira Filho2020-09-022-4/+9
| | | | | | | | Avoid duplicate functions on sphinx index for functions with multiple signature Change-Id: I1394657ff6e1978f65bacbab617972d04cac8aaa Reviewed-by: Christian Tismer <tismer@stackless.com>
* Fix constructor documentation for classes with namespaceRenato Araujo Oliveira Filho2020-09-021-8/+4
| | | | | | | Use correct class name on constructors documentation Change-Id: Ibee94f990dff7dbd5fad7e45f9c63ffa2f50207c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Fix documentation for functions argumentRenato Araujo Oliveira Filho2020-09-021-15/+34
| | | | | | | | Use the new sphinx flag `any` when the type is a class and remove any flag for native types. (`any`is available since sphinx vr. 1.3) Change-Id: I9ac896b716bbd010c0ec5240a135c9e93d2cc96c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Make sure to document class names without constructorsRenato Araujo Oliveira Filho2020-08-311-19/+23
| | | | | | | | Create class doc even if the class do not have a constructor Change-Id: I8bf93ab9a3184b2c810b57f46a0561f391db0eb7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
* Fix doc generation for class with namespaceRenato Araujo Oliveira Filho2020-08-311-18/+20
| | | | | | | | | class->name() and class->fullName() now returns the correct values we do not need to use getClassTargetFullName helper function. Change-Id: I68371d23d454412041ddd3e910f1e7d6d6435912 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* signature: pass `self` directly from parserChristian Tismer2020-08-241-0/+4
| | | | | | | | | | | | | | | | | | The signature module took the info from the PyCFunction flags for a long time to check if something is a function, method or staticmethod. It turned out that there are functions with multiple signatures where the method/staticmethod info varies in the signatures. This invalidated the PyCFunction flag usage. Instead, we now compute that info directly from abstractmetalang.cpp which has access to the correct info. Fixes: PYSIDE-1328 Change-Id: I6ba7237efcc486de014184b1787d05d87bee5a5e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken2: Fix formatting of operator functionsFriedemann Kleint2020-08-181-6/+12
| | | | | | | | | | | | In operator functions, some code would be generated for reverse shift operators and the remaining code was enclosed in if (!pyresult) without proper indentation. Generate the if (!pyresult) only when required and indent it properly by using a QScopedPointer<Indentation>. Change-Id: Iecffaa3d0a7b243e661b553726066d1177ab0298 Reviewed-by: Christian Tismer <tismer@stackless.com>
* feature-select: optimize feature access to the feasible maximumChristian Tismer2020-07-311-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | ** fix: MSVC needs extra sign bit in basewrapper_p.h! Buglet? ** The new feature selection has some tiny overhead. It is about two dict accesses plus a slot access for every tp_(get|set)attro call. The introduction of an explicit `__init_feature__` call allows to optimize this overhead very nicely, because this init is done for each __feature__ import: First, we can remove that tiny overhead completely by not initializing the feature_select module at all if no __feature__ import is used. Second, we can optimize this access further by caching the current module dict. If the dict is unchanged, then the last select_id can be used. This reduces the overhead of frequent calls to a single slot access. Third, we finally cache the select id in unused SbkObjectType bits. That removes the last structure where repeated attribute lookup is used. The overhead is therefore quite small when something is changed. But typically these changes are infrequent. The majority of accesses do change nothing, and this case is now quite much optimized. Change-Id: I7d1a4611a1c19216fd9be8f04457bb18ebd52ab1 Reviewed-by: Christian Tismer <tismer@stackless.com>
* feature-select: allow snake_case instead of camelCase for methodsChristian Tismer2020-07-241-3/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the implementation of the first of a series of dynamically selectable features. The decision depends of the following setting at the beginning of a module after PySide2 import: from __feature__ import snake_case For more info, see the Jira issue, section The Principle Of Selectable Features In PySide The crucial problems that are now solved were: - it is not sufficient to patch a type dict, instead the whole `tp_mro` must be walked to rename everything. - tp_getattro must be changed for every existing type. This is done either in shiboken by a changed PyObject_GenericGetAttr or PyObject_SenericGetAttr, or in the generated tp_(get|set)attro functions. An example is included in sources/pyside2/doc/tutorial/expenses. Task-number: PYSIDE-1019 Change-Id: I5f103190be2c884b0b4ad806187f3fef8e6598c9 Reviewed-by: Christian Tismer <tismer@stackless.com>
* Enable adding operators ==, != as functions without code injectionFriedemann Kleint2020-07-221-2/+9
| | | | | | | | | | | | | As of Qt 6, there is a trend of hiding bool returns of comparison operators of container classes behind some template expression which the clang parser cannot identify. To work arouind such cases, make it possible to add them as functions without code injection which will generate the default code. Task-number: PYSIDE-1339 Task-number: PYSIDE-904 Change-Id: Ia7bf5d583e0f80505fe1b759347955fec5dca600 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* shiboken2: Handle virtual methods returning a referenceFriedemann Kleint2020-07-141-0/+5
| | | | | | | | | | | | | | | | | | | Although it is a questionable practice, it occurs in Qt 6: virtual const QEventPoint &QPointerEvent::point(int i) const; Previously, the generated return statement return QEventPoint(); would cause a warning about returning a temporary. Fix by creating a static variable and returning a reference to it. Task-number: PYSIDE-1339 Task-number: PYSIDE-904 Change-Id: Id6467be22a166e99e8dcf08b2c7c14df33cd2786 Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken2: Handle default parameters of const pointersFriedemann Kleint2020-07-143-2/+19
| | | | | | | | | | | | Occurs in Qt 6: QKeyEvent(..., const QInputDevice *device = QInputDevice::primaryKeyboard()); We need a const-cast here since shiboken needs a QInputDevice * for type conversion. Change-Id: Iea1137eac44a26b7bc9cf0e1908c0e42ba2de39f Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken2: Refactor generating return values of virtual functionsFriedemann Kleint2020-07-142-58/+66
| | | | | | | Split out a function returning the return statement as a string. Change-Id: I9c893a8e0068d7d5d6eff4c7ae44c5f754211bdd Reviewed-by: Christian Tismer <tismer@stackless.com>
* shiboken: optimize method override stringsChristian Tismer2020-07-091-3/+4
| | | | | | | | | | | | | | | | The override strings in bindingmanager were based upon pure C strings for a long time. There was some mild overhead of creating PyObject all the time. With the upcoming name mangling of Selectable Features, this becomes even a bit more inefficient when strings also get mangled. With Python strings this is just a dict lookup. This patch uses the same machinery as `Shiboken::PyName`. Task-number: PYSIDE-1019 Change-Id: I4eed7222371dadeed0e9ba98cc7970e726ffc044 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* shiboken2: Add file location to more warningsFriedemann Kleint2020-06-231-1/+2
| | | | | | | | | | | | | | | | | | | | Output most warnings in the standard file:line syntax used by compilers. This is done for C++ source code and typesystem files. Introduce a class SourceLocation and add it to type entry, AbstractMetaFunction and AbstractMetaClass. Move more messages into messages.cpp and output the location. Change the errors reported by the XML typesystem parser to the same format. [ChangeLog][shiboken] A number of error and warning messages have been prefixed by file name and line for better tooling. Task-number: PYSIDE-904 Change-Id: Ie2008f4060757e9d7ca1b25c00c7c5585240a7b8 Reviewed-by: Christian Tismer <tismer@stackless.com>
* Further build fixes for Qt 6Friedemann Kleint2020-06-221-0/+4
| | | | | Change-Id: I2463997f1eb2012cbbd0192a019ca57beaf55d5b Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* Merge "Merge remote-tracking branch 'origin/5.14' into 5.15"Friedemann Kleint2020-06-191-1/+1
|\
| * Merge remote-tracking branch 'origin/5.14' into 5.15Friedemann Kleint2020-06-191-1/+1
| |\ | | | | | | | | | Change-Id: If40b0ab35cd2ad2bd0d982881094ce3dbf46ccf3
| | * Use Q_OS_WIN instead of _WINDOWS for the path splitterSergio Martins2020-06-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | _WINDOWS is MSVC specific Fixes passing --include-paths when using MinGW Change-Id: I041484eccf521869f4fb532edc55d2e1cf4063e4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* | | shiboken2: Remove code indenterFriedemann Kleint2020-06-192-70/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With the previous changes fixing the spaces of the snippets, the indenter can be removed. It just requires creating local indentors when writing to separate text streams to avoid unnecessarily indenting by the global indenter. Change-Id: Ic9d9661bb1827d40d6f38dc2d47b5fd84729887c Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | | shiboken2: Clean up code injection attributesFriedemann Kleint2020-06-191-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the unused enumeration values. Change the class of the "declaration" position from "native" to "shell" since that is where it is used and mention it in the documentation. Task-number: PYSIDE-1282 Change-Id: I547b4bab055df27ce8b0b7b41b9d382dc8f175d1 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | | shiboken2: Refactor wrapper method generationFriedemann Kleint2020-06-192-57/+65
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For virtual functions, the code injection for shell/beginning was not written to the shortcut path added by 50f382579d1323817165d85bf88a394328a4e9a0 (when the method cache is set, indicating there is no python override). Factor out the code into a separate function. As a drive by, actually generate the (hiterto unimplemented) shell/end injection at least for void functions. Task-number: PYSIDE-803 Task-number: PYSIDE-1282 Change-Id: If56f839d414bf7364fdf6af5f3f0d5a76a5fc434 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | shiboken2: Improve formatting of the converter codeFriedemann Kleint2020-06-191-7/+7
| | | | | | | | | | | | | | Indent the first lines properly. Change-Id: Icd4b86ef875662ef8def52cc3106aad79a0aace6 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | shiboken2: Improve whitespaces formatting in injected codeFriedemann Kleint2020-06-193-24/+12
| | | | | | | | | | | | | | | | | | - Trim newlines and dedent all snippets from XML - Move the trailing newlines into the code snippet function. - Do not indent preprocessor directives Change-Id: Ic8c3745f0b88ee4ed27ac9cbaf376d71a50d9188 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | shiboken2: Generate the num(Named)Args with the correct typeFriedemann Kleint2020-06-161-2/+2
| | | | | | | | | | | | | | Fixes an integer conversion warning with MSVC2019. Change-Id: I932fc0237712e774f2791d412ed1e52e268d1b69 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | Implement the QEnum/QFlag decorator, V2Christian Tismer2020-06-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implementation allows module-level and scoped QEnums which are Python enum types. Scoped types are registered in Qt's meta object system. Usage of QEnum/QFlag with decorator or function call: from enum import Enum, Flag, auto from PySide2.QtCore import QEnum, QFlag, QObject class Compass(QObject): @QEnum class Orientation(Enum): North, East, South, West = range(4) class Color(Flag): RED = auto() BLUE = auto() GREEN = auto() WHITE = RED | BLUE | GREEN QFlag(Color) Fixes: PYSIDE-957 Change-Id: Ie15f45cbd932c816b50724a96eee0c14ae1fdee8 Task-number: PYSIDE-487 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* | signature: use raw strings when needed, onlyChristian Tismer2020-06-121-2/+7
| | | | | | | | | | | | | | | | This is more convenient for developers who deal with signatures quite often. Change-Id: I009eaa854e0df02afc0e07954d743821dbc1e33c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Friedemann Kleint2020-06-111-1/+1
|\| | | | | | | Change-Id: I6cf604e1ae7234ce4f0d99169e9269a7dde07a4a
| * shiboken: Fix default-initialized function argumentsFriedemann Kleint2020-06-111-1/+1
| | | | | | | | | | | | | | | | Specifying {} causes it to be qualified, check this. Change-Id: Idd23c8a5af01cd7fbb63a2e5a01bb349c530fe54 Fixes: PYSIDE-1325 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | shiboken: Allow for multiple header files on command lineFriedemann Kleint2020-06-031-116/+119
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change ApiExtractor and MetaBuilder to use QFileInfoList. Refactor the options handling to work on a struct separating options from positional arguments to make handling multiple file names easier. Refactor and streamline the options parsing code a bit, avoid duplicated parsing of project files. Print the usage when positional arguments are missing. [ChangeLog][shiboken] shiboken now accepts multiple headers on the command line. Change-Id: I221ab5a71232af1323408f77295137dc92e3d582 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | shiboken: Fix invalid code generated for signatures with string default ↵Friedemann Kleint2020-05-262-16/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | parameters In the case of a default parameter with backslash escaping, wrong code can be generared. Factor out a helper function and generate signature strings as C++ raw string literals. Fixes: PYSIDE-1310 Change-Id: If7aa8e2449e959ce298da45a2977728823b25c2f Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Friedemann Kleint2020-05-261-1/+1
|\| | | | | | | Change-Id: I9c7163094bc934f481002adcea78ef4928ed26be
| * shiboken: Fix cross buildsFriedemann Kleint2020-05-181-1/+1
| | | | | | | | | | | | | | | | Patch as contributed on JIRA. Fixes: PYSIDE-1299 Change-Id: Ifbf94e59712cf16c0161da57691008f3895a64e3 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | shiboken: Refactor generation of sequence access methodsFriedemann Kleint2020-05-192-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rename writeStdListWrapperMethods() to writeDefaultSequenceMethods() since that is is more close to its purpose. In the function, get the base container type. Use std::advance instead of a loop to position the iterator. This is specialized for random access iterators to perform an addition and thus more efficient. Use const_iterator in __getitem__ to prevent Qt containers from detaching. Task-number: PYSIDE-904 Change-Id: I4735f39193c4f4efa856440ecddbc48b3a5071ae Reviewed-by: Christian Tismer <tismer@stackless.com>
* | shiboken: Rename enum ContainerTypeEntry::Type to ContainerKindFriedemann Kleint2020-05-191-5/+6
| | | | | | | | | | | | | | | | As it is, it clashes with TypeEntry::Type. Task-number: PYSIDE-904 Change-Id: I51b269f188b39dc18412b83c3d659cbf61a99608 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | shiboken: Add a cast to Py_hash_t in the hash function generatorFriedemann Kleint2020-05-191-3/+6
| | | | | | | | | | | | Task-number: PYSIDE-904 Change-Id: I95449299f7e6f5b798b77e51aa63a2fb609bd443 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | shiboken: Add an internal error when template instantiations are not foundFriedemann Kleint2020-05-181-1/+6
| | | | | | | | | | | | | | | | Happens in Qt 6 for QItemSelection. Task-number: PYSIDE-904 Change-Id: Id2463eeb046155615d3d356b3cf38b32cb5c15e5 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | shiboken: Move wrapperName and type into GeneratorContextFriedemann Kleint2020-05-156-65/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce a Type enumeration to GeneratorContext and add the wrapper name as a string. Overwrite creation function in ShibokenGenerator to add this. Remove unused wrapperName overloads. Use the wrapper name and type from the GeneratorContext where applicable instead of repeatedly running the check in shouldGenerateCppWrapper(). Change-Id: I52cace3ad165c2cd6c6ce718cec822abfb8ad8ce Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | shiboken: Prepare for extending GeneratorContextFriedemann Kleint2020-05-154-14/+28
| | | | | | | | | | | | | | | | | | Remove the constructor GeneratorContext and add creation functions to the generators. Make the class creation function virtual so that ShibokenGenerator can override it. Change-Id: I7bc002555356be73ddab5a2095802747796acb7e Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | shiboken: Use GeneratorContext in more functionsFriedemann Kleint2020-05-155-55/+99
| | | | | | | | | | Change-Id: Ief36279da5dfeeeacf83697d92b9f64680b2a56e Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | shiboken: Constify GeneratorContextFriedemann Kleint2020-05-158-77/+80
| | | | | | | | | | | | | | | | | | | | | | | | Pass around by const-ref and return a const pointer to the class. In HeaderGenerator::generateClass(), make a copy of the context passed in to prevent writing back via reference in the base class loop. Change-Id: I0338bd93b5a53c25ec18bc45b407ab67d8c7c91e Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
* | shiboken: Refactor ShibokenGenerator::wrapperName()Friedemann Kleint2020-05-153-18/+26
| | | | | | | | | | | | | | | | | | Assert that it is only used for wrapped classes and remove fallback path returning the class name, which obfuscates the code. Change-Id: I9af1a6a9edc5e566296ec99a50a9f8cfbe055cd0 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | Revert "Revert "Fix deprecation warnings about Qt::SplitBehavior""Friedemann Kleint2020-05-153-6/+6
| | | | | | | | | | | | | | | | | | Fix warnings in 5.15. This reverts commit 2ca788f85fbc9d58969533d13046bbe19f53fac8. Change-Id: Iaee39e2035f5e4ebdc9b5360a68a5f024f8bde38 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | Merge remote-tracking branch 'origin/5.14' into 5.15Friedemann Kleint2020-05-151-4/+10
|\| | | | | | | Change-Id: I302699433b1a9d11b5134b43703a775556bbee14
| * shiboken: Prepare for introduction of __qualname__Christian Tismer2020-05-141-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | To remove the groundwork from the next checkin, the step of replacing PyType_FromSpec with SbkType_FromSpec is extracted. This change introduces a packageLevel number that is generated as a name prefix in the class creation but does not use it, yet. Change-Id: Ic9061231708b546dbd3620d148bca24c27df60a5 Task-number: PYSIDE-1286 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
| * siboken: Fix compiler warningFriedemann Kleint2020-05-131-1/+4
| | | | | | | | | | | | | | shiboken2/generator/shiboken2/cppgenerator.cpp:3181:135: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers] Change-Id: Ib382f47a6cd226f05db2b4e99c7c5b05bd31f135 Reviewed-by: Christian Tismer <tismer@stackless.com>
* | Merge "Merge remote-tracking branch 'origin/5.14' into 5.15"Friedemann Kleint2020-05-133-7/+12
|\ \
| * | Merge remote-tracking branch 'origin/5.14' into 5.15Friedemann Kleint2020-05-133-7/+12
| |\| | | | | | | | | | Change-Id: I9fbc4217d1cdc0cb2c57459b56aa283dd9c6ef45