Re: [Qt-creator] Patch for autocreate method implementation
Hi Eric, No problem ;-) this functionality was developed by Nicolas in separate plugin: http://gitorious.org/creator-plugins I think, this more clean way. Also, it can be developed/tested/used independ of main Qt Creator development. I think that this comments will be interesting for Nicolas also. But, thanks for comments, I will remember its :-) В Mon, 1 Mar 2010 17:59:38 +0100 пишет: EVC> Hello Alexander, EVC> EVC> On Feb 21, 2010, at 9:16 , ext Alexander 'hatred' Drozdoff wrote: EVC> EVC> > Hi all, EVC> > EVC> > I prepare patch that may be helpful in development process. EVC> > EVC> > With this patch you can go to Header file, write function prototype (or method prototype in EVC> > class definition), press Shift-F2 (or press Right mouse button on prototype and select item EVC> > "Switch between Method Declaration/Definition"), in case when definition does not present, EVC> > you can see message box: Implementation does not found. Will I try to create it? [Yes/No] EVC> > If you answer Yes, template of method will created and you moved to it. EVC> EVC> I am afraid I will have to reject this patch, for the following two reasons: EVC> EVC> First, it iterates over all files in the project. This might lead to iterating over a lot of EVC> files (4810 when I have Creator loaded), and might very well find the wrong one if one of them EVC> just happens to include the header file. Now in C++ it is actually allowed to put the method EVC> in any file which gets linked into the target (or nowhere if it is never used), but a good EVC> heuristic might be to first search for the file where the constructor is defined. Or if none EVC> is declared, to find the first preceding or following symbol declaration (not definition) and EVC> go to the file where it is defined. (And then I am ignoring the cases where you might want to EVC> define them inline in the header file, but outside the class.) EVC> EVC> The second reason is that it does not take namespaces into account, but appends it to the end EVC> of the file. A typical (easy) use-case is when a user uses the new-class-wizard and enters EVC> "MyNamespace::MyClass" as the class name. This will result in a namespace in the .cpp file, EVC> which, by default, closes at the end of the file. So the definition will incorrectly end up EVC> outside the namespace. EVC> EVC> Now this last one is actually the reason why we did not implement this yet. And getter/setter EVC> generation has the same "exciting" (corner-)cases. For example, if somebody puts a EVC> struct/class/enum declaration inside a class, code generation for the definitions would not EVC> only have to check for "using namespace" and truncate the types accordingly, but also the EVC> other way around: it might need to add qualifiers to types (but obviously not too many of EVC> them). It is definitely solvable, but be prepared to fix lots of corner cases. EVC> EVC> Regards, EVC> Erik. -- WBR Alexander Drozdov ___ Qt-creator mailing list Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator
Re: [Qt-creator] Patch for autocreate method implementation
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 Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator
Re: [Qt-creator] Patch for autocreate method implementation
В Tue, 23 Feb 2010 10:57:35 +0100 "Nicolas Arnaud-Cormos" пишет: NAC> On Sunday 21 February 2010 09:16:12 Alexander 'hatred' Drozdoff wrote: NAC> > Hi all, NAC> > NAC> > I prepare patch that may be helpful in development process. NAC> > NAC> > With this patch you can go to Header file, write function prototype (or NAC> > method prototype in class definition), press Shift-F2 (or press Right NAC> > mouse button on prototype and select item "Switch between Method NAC> > Declaration/Definition"), in case when definition does not present, you NAC> > can see message box: Implementation does not found. Will I try to create NAC> > it? [Yes/No] If you answer Yes, template of method will created and you NAC> > moved to it. NAC> > NAC> > Path is attached to this letter. NAC> > NAC> > For russian-speak guys avail my description in blog: NAC> > http://hatred.homelinux.net/wiki/zhurnal:2010-02-11_20.47_qt_creator_i_avto NAC> > maticheskoe_sozdanie_realizacii_metoda_prototipa also, here you can see NAC> > screens that demonstrate work of patch. NAC> > NAC> NAC> Hi, NAC> Hi Nicolas! NAC> I had a quick look at the patch, and it reminds me of a merge request I've NAC> submitted some times ago. NAC> NAC> Anyway, I did almost the same thing here (without the dialog, and using a NAC> plugin): NAC> http://gitorious.org/creator-plugins (CppHelper plugin) NAC> Oh, I will try to use it ;-) NAC> Note that I'm using the CppTools::Constants::SWITCH_HEADER_SOURCE command NAC> instead of searching in the project for the source file. When I completed my work, I was looked to source for more optimized way for switch files, but currently I have no time for this work :( NAC> Anyway, I'll have a better look at the way you get the return NAC> type/signature/arguments, for the moment it's really basic for me. NAC> Yeah! Open Source is great! :-D -- WBR Alexander Drozdov ___ Qt-creator mailing list Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator
Re: [Qt-creator] Patch for autocreate method implementation
В Tue, 23 Feb 2010 09:39:40 + Danny Price пишет: DP> Nice! DP> DP> Couple of language issues: DP> DP> "Switch between Method Declaration/Definition" should be "Switch between DP> Member Decleration/Defintion". C++ does not have 'methods'. It has member DP> functions. DP> I did not implement this part, so this is upstream issue, you can report it via official bug-tracker DP> "Implementation does not found. Will I try to create it?" should be DP> "Implementation not found. Create it?" DP> Ok well, english is not my native language, I will fix it in my patch ;-) DP> However I wonder if this dialog is necessary? I think that this dialog is necessary, because you need have alternative, for ex. in case when you press Shift+F2 on declaration in 'signal' section accidentally. -- WBR Alexander Drozdov ___ Qt-creator mailing list Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator
Re: [Qt-creator] Patch for autocreate method implementation
On Sunday 21 February 2010 09:16:12 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. > > Path is attached to this letter. > > For russian-speak guys avail my description in blog: > http://hatred.homelinux.net/wiki/zhurnal:2010-02-11_20.47_qt_creator_i_avto > maticheskoe_sozdanie_realizacii_metoda_prototipa also, here you can see > screens that demonstrate work of patch. > Hi, I had a quick look at the patch, and it reminds me of a merge request I've submitted some times ago. Anyway, I did almost the same thing here (without the dialog, and using a plugin): http://gitorious.org/creator-plugins (CppHelper plugin) Note that I'm using the CppTools::Constants::SWITCH_HEADER_SOURCE command instead of searching in the project for the source file. Anyway, I'll have a better look at the way you get the return type/signature/arguments, for the moment it's really basic for me. Cheers, Nicolas -- Nicolas Arnaud-Cormos | nico...@kdab.com | Software Ingeneer Klarälvdalens Datakonsult AB, a KDAB Group company Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322) KDAB - Qt Experts - Platform-independent software solutions ___ Qt-creator mailing list Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator
Re: [Qt-creator] Patch for autocreate method implementation
Nice! Couple of language issues: "Switch between Method Declaration/Definition" should be "Switch between Member Decleration/Defintion". C++ does not have 'methods'. It has member functions. "Implementation does not found. Will I try to create it?" should be "Implementation not found. Create it?" However I wonder if this dialog is necessary? On Sun, Feb 21, 2010 at 8:16 AM, Alexander 'hatred' Drozdoff < adrozd...@gmail.com> 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. > > Path is attached to this letter. > > For russian-speak guys avail my description in blog: > > http://hatred.homelinux.net/wiki/zhurnal:2010-02-11_20.47_qt_creator_i_avtomaticheskoe_sozdanie_realizacii_metoda_prototipa > also, here you can see screens that demonstrate work of patch. > > -- > WBR > Alexander Drozdov > > ___ > Qt-creator mailing list > Qt-creator@trolltech.com > http://lists.trolltech.com/mailman/listinfo/qt-creator > > ___ Qt-creator mailing list Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator
Re: [Qt-creator] Patch for autocreate method implementation
This patch looks great and the functionalities it provides are really interesting. I really hope it get integrated in mainstream. ___ Qt-creator mailing list Qt-creator@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-creator
[Qt-creator] Patch for autocreate method implementation
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. Path is attached to this letter. For russian-speak guys avail my description in blog: http://hatred.homelinux.net/wiki/zhurnal:2010-02-11_20.47_qt_creator_i_avtomaticheskoe_sozdanie_realizacii_metoda_prototipa also, here you can see screens that demonstrate work of patch. -- WBR Alexander Drozdov diff -Nur ./src/plugins/cppeditor.orig/cppeditor.cpp ./src/plugins/cppeditor/cppeditor.cpp --- ./src/plugins/cppeditor.orig/cppeditor.cpp 2010-02-11 03:07:28.122106992 +1000 +++ ./src/plugins/cppeditor/cppeditor.cpp 2010-02-11 20:47:29.062472254 +1000 @@ -69,7 +69,11 @@ #include #include #include +#include +#include #include +#include +#include #include #include #include @@ -81,6 +85,7 @@ #include #include #include +#include #include #include #include @@ -92,8 +97,10 @@ #include #include #include +#include #include +#include enum { UPDATE_METHOD_BOX_INTERVAL = 150, @@ -1248,6 +1255,7 @@ } if (f) { +// We move here when our direct is DECLARATION TypeOfExpression typeOfExpression; typeOfExpression.setSnapshot(m_modelManager->snapshot()); QList resolvedSymbols = typeOfExpression(QString(), doc, lastSymbol); @@ -1268,8 +1276,126 @@ if (declaration) openCppEditorAt(linkToSymbol(declaration)); } else if (lastSymbol->type()->isFunctionType()) { -if (Symbol *def = findDefinition(lastSymbol)) +// We move here when out direction is IMPLEMENTATION +Symbol *def = findDefinition(lastSymbol); +if (def) +{ openCppEditorAt(linkToSymbol(def)); +} +else +{ +// Ask for create method implementation +if ( QMessageBox::question(this, + "Implementation not found", + "Implementation does not found. Will I try to create it?", + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes) == QMessageBox::Yes ) +{ +Overview o; +QString definition; +QString className; +QString functionName; +QString functionSignature; +QString functionReturnType; + +functionName = o.prettyName( lastSymbol->name() ); + +if (lastSymbol->scope()->isClassScope()) +{ +className = o.prettyName( lastSymbol->scope()->owner()->name() ); +className += QLatin1String("::"); +} + +if (lastSymbol->isDeclaration()) +{ +o.setShowArgumentNames(true); +o.setShowFunctionSignatures(true); +o.setShowReturnTypes(false); +functionSignature = o.prettyType( lastSymbol->asDeclaration()->type() ); + +o.setShowArgumentNames(false); +o.setShowFunctionSignatures(false); +o.setShowReturnTypes(true); +functionReturnType = o.prettyType( lastSymbol->asDeclaration()->type() ); +} +else +{ +return; +} + +definition += QLatin1String("\n"); +definition += QLatin1String("/**\n"); +definition += QLatin1String(" * \n"); +definition += QLatin1String(" */\n"); +definition += functionReturnType; +definition += QLatin1String(" "); +definition += className; +definition += functionName; +definition += functionSignature; +definition += QLatin1String("\n{\n"); +definition += QLatin1String("/// @TODO"); +definition += QLatin1String("\n}\n"); + +const ProjectExplorer::Project *current_project = + ProjectExplorer::ProjectExplorerPlugin::instance()->session()->projectForFile(file()->fileName()); +if (!current_project) +{ +std::cout << "Can't locate current project\n"; +return; +} + +Snapshot::iterator it; +QFileInfo headerFI(file()->fileName()); +const QString headerBaseName = headerFI.complete