Qt Creator's wizards and configuration settings supports variable expansion, including evaluation of JavaScript expressions, e.g. the C++ class wizard file template contains:
%{JS: Cpp.openNamespaces('%{Class}')}
Cpp
seems to be a global object. Where in the Qt Creator sources are those defined, and what's available?
These are not documented anywhere.
The JavaScript variable expansion is performed by the JsExpander
in the core plugin. The expander can register QObject
instances and expose them as properties of the global JS object.
To find all of those global objects, search for registerQObjectForJs
method invocations. See the github search results for this method.
As of Qt Creator 4.2.1, and until at least 4.6, the following are the only objects registered:
Util
- exposing Internal::UtilsJsExtension
,Cpp
- exposing CppTools::Internal::CppToolsJsExtension
,Modeling
- exposing ModelEditor::Internal::JsExtension
,QtSupport
- exposing QtSupport::CodeGenerator
,Vcs
- exposing VcsBase::Internal::VcsJsExtension
.The method parameter types are mapped to JavaScript types by QJSEngine
. E.g. to obtain the Qt includes, one could have the following substitution:
%{JS: QtSupport.qtIncludes([ '%{Base}' ], [ '%{Base}' ])}
given the signature
QString qtIncludes(const QStringList &qt4, const QStringList &qt5)
The method list follows.
QString toNativeSeparators(const QString &in) const;
QString fromNativeSeparators(const QString &in) const;
QString baseName(const QString &in) const;
QString fileName(const QString &in) const;
QString completeBaseName(const QString &in) const;
QString suffix(const QString &in) const;
QString completeSuffix(const QString &in) const;
QString path(const QString &in) const;
QString absoluteFilePath(const QString &in) const;
QString relativeFilePath(const QString &path, const QString &base) const;
// File checks:
bool exists(const QString &in) const;
bool isDirectory(const QString &in) const;
bool isFile(const QString &in) const;
// MimeDB:
QString preferredSuffix(const QString &mimetype) const;
// Generate filename:
QString fileName(const QString &path,
const QString &extension) const;
// Generate temporary file:
QString mktemp(const QString &pattern) const;
// Generate a ascii-only string:
QString asciify(const QString &input) const;
// Generate header guard:
QString headerGuard(const QString &in) const;
// Fix the filename casing as configured in C++/File Naming:
QString fileName(const QString &path, const QString &extension) const;
// Work with classes:
QStringList namespaces(const QString &klass) const;
QString className(const QString &klass) const;
QString classToFileName(const QString &klass,
const QString &extension) const;
QString classToHeaderGuard(const QString &klass, const QString &extension) const;
QString openNamespaces(const QString &klass) const;
QString closeNamespaces(const QString &klass) const;
QString fileNameToElementName(const QString &file);
QString elementNameToFileName(const QString &element);
// Ui file related:
// Change the class name in a UI XML form
QString changeUiClassName(const QString &uiXml, const QString &newUiClassName);
QString uiClassName(const QString &uiXml);
// Generic Qt:
QString qtIncludes(const QStringList &qt4, const QStringList &qt5);
bool isConfigured(const QString &vcsId) const;
QString displayName(const QString &vcsId) const;
It is also useful to note that several JS variables exposed via the macroexpander see: https://github.com/qt-creator/qt-creator/blob/master/src/plugins/coreplugin/coreplugin.cpp#L169
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With