Hi,

attached is a small patch which adds environment variable expansion to the 
import statement. Rationale: this might be useful to implement different 
(native) component styles.

You could make a module:

com.mycompany.qml-ui-components

which contains a C++ plugin and a bunch of files, e.g. Button.qml

The Button.qml itself reads only:

-----------Button.qml-----------
import "$STYLE"
Button{}
--------------------------------

and you have subdirectories like:

 plain/Button.qml
 fancy/Button.qml
 crazy/Button.qml

The C++ plugin is responsible for setting the correct default style (using 
::qputenv()) on the current platform, if not set otherwise.

Currently you can only achive this when playing with the module imports path, 
the patch would make this easier.

Reasonable extension?

Matthias
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
index 0eb7e1b..084cf1d 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp
+++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
@@ -560,6 +560,26 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
         if (imp.type == QDeclarativeScriptParser::Import::Script)
             continue;
 
+        if (imp.type == QDeclarativeScriptParser::Import::File) {
+            // expand import variables
+            int i = 0;
+            forever {
+                i = imp.uri.indexOf(QLatin1Char('$'), i);
+                if (i < 0)
+                    break;
+                if (i > 0 && imp.uri.at(i-1) == QLatin1Char('\\'))
+                    continue;
+                int len = 1;
+                if (i + len < imp.uri.size() && imp.uri.at(i + len).isLetter()) {
+                    ++len;
+                    while (i + len < imp.uri.size() && imp.uri.at(i + len).isLetterOrNumber())
+                        ++len;
+                }
+                QByteArray var = ::qgetenv(imp.uri.mid(i+1, len-1).toLatin1());
+                imp.uri.replace(i, len, QString::fromLatin1(var));
+            }
+        }
+
         if (imp.type == QDeclarativeScriptParser::Import::File && imp.qualifier.isEmpty()) {
             QString importUrl = unit->imports.baseUrl().resolved(QUrl(imp.uri + QLatin1String("/qmldir"))).toString();
             for (int ii = 0; ii < unit->resources.count(); ++ii) {
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to