Hello Alexander,

On Feb 21, 2010, at 9:16 , ext Alexander 'hatred' Drozdoff wrote:

> Hi all,
> 
> I prepare patch that may be helpful in development process.
> 
> With this patch you can go to Header file, write function prototype (or 
> method prototype in class
> definition), press Shift-F2 (or press Right mouse button on prototype and 
> select item "Switch
> between Method Declaration/Definition"), in case when definition does not 
> present, you can see
> message box: Implementation does not found. Will I try to create it? [Yes/No]
> If you answer Yes, template of method will created and you moved to it.

I am afraid I will have to reject this patch, for the following two reasons:

First, it iterates over all files in the project. This might lead to iterating 
over a lot of files (4810 when I have Creator loaded), and might very well find 
the wrong one if one of them just happens to include the header file. Now in 
C++ it is actually allowed to put the method in any file which gets linked into 
the target (or nowhere if it is never used), but a good heuristic might be to 
first search for the file where the constructor is defined. Or if none is 
declared, to find the first preceding or following symbol declaration (not 
definition) and go to the file where it is defined. (And then I am ignoring the 
cases where you might want to define them inline in the header file, but 
outside the class.)

The second reason is that it does not take namespaces into account, but appends 
it to the end of the file. A typical (easy) use-case is when a user uses the 
new-class-wizard and enters "MyNamespace::MyClass" as the class name. This will 
result in a namespace in the .cpp file, which, by default, closes at the end of 
the file. So the definition will incorrectly end up outside the namespace.

Now this last one is actually the reason why we did not implement this yet. And 
getter/setter generation has the same "exciting" (corner-)cases. For example, 
if somebody puts a struct/class/enum declaration inside a class, code 
generation for the definitions would not only have to check for "using 
namespace" and truncate the types accordingly, but also the other way around: 
it might need to add qualifiers to types (but obviously not too many of them). 
It is definitely solvable, but be prepared to fix lots of corner cases.

Regards,
Erik.
_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-creator

Reply via email to