SlideShare uma empresa Scribd logo
1 de 15
Platform and device-specific settings for your QML layouts Artem Marchenko October 8, 2011 After Easy Discount Calculator by Artem Marchenko, JarmoParkkinen, TuukkaLindroos and Ekaterina Kuts Technical solution by Artem Marchenko and TuukkaLindroos
Artem Marchenko Product Manager, Agile Coach, QML engineer for hire Was a Product Manager shipping multi-hundred MEur products Three times Forum Nokia Champion Private entrepreneur Available for hire for all things QML http://fi.linkedin.com/in/artemmarchenko
Same app running on Harmattan, Android and Symbian
Easy Discount Calculator Symbian, MeeGo/Harmattan - http://store.ovi.com/content/186742 Android - http://bit.ly/discountcalculator Free, but has font issues on some models due to porting technology bug. Well working proof of concept for now
All the parameters can be fine-tuned on desktop
Settings system // SettingsBase.QML import Qt 4.7 import "GlobalSettings.js" as Js QtObject {     id: settingsObject // logical switches/conditions     property boolexitButtonPresent: true     property boolclearButtonIsBetweenTheLines: true     // element sizes     property introllerHeight: 110     property intdigitRollerWidth: 56     property intpercentageRollerWidth: digitRollerWidth
Settings system // SettingsMaemo.qml import Qt 4.7 SettingsBase {     property string platformTitle: "Maemo"     property intscreenWidthInPortrait:  480 ...     property introllerHeight: 160     property introllerNumberLineInnerSpacing:  0     property int digitRollerWidth:69 statusLineHeight: 0
Tree of settings
Using platform settings in JS //GlobalSettings.js .pragma library   // - the only QML possibility for global variables varglobalSettings = null // Will fetch the settings object from the item. If the settings object doesn't // exists, will return the global one or generate one on the fly based on base settings.  function getSettings(item) { …  if(item.settings) {         if(!globalSettings) { globalSettings = item.settings         } if(!globalSettings) { var component = Qt.createComponent("SettingsBase.qml") globalSettings = component.createObject(item)     }     return globalSettings;
Using Settings in QML // SmallButton.qml import Qt 4.7 import "GlobalSettings.js" as Js Rectangle {     id: button     width: Js.getSettings(button).smallButtonWidth     height: Js.getSettings(button).smallButtonHeight     radius: 3
Injecting Settings from C++ QStringsettingsPath = "qml/discountcalcui/Settings" + platformTitle + ".qml"; // localAdjustPath cares about platform-specific file location details settingsUrl = QUrl::fromLocalFile(CrossPlatformUtils::localAdjustPath(settingsPath)); QDeclarativeComponent component(view.engine(), settingsUrl); settingsInstance = component.create(); if(!settingsInstance) {           // No settings found - no object to install qWarning() << "Settings not found for this platform!"; qWarning() << component.errorString(); } else { settingsInstance->setProperty("shouldInitializeGlobalSettingWithItself", true); view.engine()->rootContext()->setContextProperty("forcedSettings”, settingsInstance);     } // continue with normal QML initialization
JavaScript side of initialization //SettingsBase.qml import Qt 4.7 import "GlobalSettings.js" as Js QtObject {     id: settingsObject     property boolshouldInitializeGlobalSettingWithItself: false // Is executed way before main QML file is loaded onShouldInitializeGlobalSettingWithItselfChanged: {         if(shouldInitializeGlobalSettingWithItself) { console.log("SBase: initializing global settings with " + settingsObject) Js.globalSettings = settingsObject         }     }
Switching settings for desktop simulation // Simulator for different platforms DiscountCalcUi {         id: main     } ListModel {         id: platformsModel ListElement {title: "Symbian"; visualTitle: "S^3"} ListElement{title: "Android480x800"; visualTitle: "Andr 800" } ListElement{title: "Harmattan" }     } onButtonClicked: { var component = Qt.createComponent("Settings" + model.title + ".qml") main.settings = component.createObject(main) } // actually, maybe we should have changed the global JS reference :/
Summary Parameterizing code everywhere is possible and easy Use JavaScript libraries for storing global objects To initialize settings by the moment of QML instantiations, inject settings from C++ before the main QML object Care about ability to change settings object for the desktop simulation of different platforms
Thank you Q&As time You can find these and similar slides at http://agilesoftwaredevelopment.com/tags/qml

Mais conteúdo relacionado

Destaque

Difference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationDifference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationBill Miller
 
Scrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoScrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoIgor Macaubas
 
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Raj Lal
 
Vídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosVídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosIgor Macaubas
 
QML demo for makerpro (1)
QML demo for makerpro (1)QML demo for makerpro (1)
QML demo for makerpro (1)diro fan
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UIOpenBossa
 
Terraforming organisations
Terraforming organisationsTerraforming organisations
Terraforming organisationsClaudio Perrone
 
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Raj Lal
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Nativeaccount inactive
 
Having the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationHaving the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationDerek Huether
 
Fases de RUP - PDF
Fases de RUP - PDFFases de RUP - PDF
Fases de RUP - PDFradoslawkb
 

Destaque (19)

Difference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam InsulationDifference Between Open And Closed Cell Foam Insulation
Difference Between Open And Closed Cell Foam Insulation
 
Scrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básicoScrum não é suficiente - ultrapassando o básico
Scrum não é suficiente - ultrapassando o básico
 
Resumen RUP
Resumen RUPResumen RUP
Resumen RUP
 
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
Fun with QML and JavaScript: Embedded Linux Conference 11th April 2011, Hotel...
 
QtQuick Day 4
QtQuick Day 4QtQuick Day 4
QtQuick Day 4
 
Agile Contracts
Agile ContractsAgile Contracts
Agile Contracts
 
Vídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafiosVídeos - novos hábitos, grandes desafios
Vídeos - novos hábitos, grandes desafios
 
QML demo for makerpro (1)
QML demo for makerpro (1)QML demo for makerpro (1)
QML demo for makerpro (1)
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
QtQuick Day 2
QtQuick Day 2QtQuick Day 2
QtQuick Day 2
 
QtQuick Day 3
QtQuick Day 3QtQuick Day 3
QtQuick Day 3
 
Intro to QML / Declarative UI
Intro to QML / Declarative UIIntro to QML / Declarative UI
Intro to QML / Declarative UI
 
Terraforming organisations
Terraforming organisationsTerraforming organisations
Terraforming organisations
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
Build Cutting edge Mobile Apps using QML and JavaScript for MeeGo N9: Linux F...
 
QtQuick Day 1
QtQuick Day 1QtQuick Day 1
QtQuick Day 1
 
How to Make Your Qt App Look Native
How to Make Your Qt App Look NativeHow to Make Your Qt App Look Native
How to Make Your Qt App Look Native
 
Having the Correct Context for an Agile Transformation
Having the Correct Context for an Agile TransformationHaving the Correct Context for an Agile Transformation
Having the Correct Context for an Agile Transformation
 
Fases de RUP - PDF
Fases de RUP - PDFFases de RUP - PDF
Fases de RUP - PDF
 

Mais de Artem Marchenko

One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, AndroidArtem Marchenko
 
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandArtem Marchenko
 
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandArtem Marchenko
 
Misapplied Scrum pattern
Misapplied Scrum patternMisapplied Scrum pattern
Misapplied Scrum patternArtem Marchenko
 
Effective Software Development for the 21st century
Effective Software Development for the 21st centuryEffective Software Development for the 21st century
Effective Software Development for the 21st centuryArtem Marchenko
 

Mais de Artem Marchenko (7)

One code Web, iOS, Android
One code Web, iOS, AndroidOne code Web, iOS, Android
One code Web, iOS, Android
 
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 29 Mar 2014, Tampere, Finland
 
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, FinlandGetting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
Getting started with coding for Jolla Sailfish OS. 22 Feb 2014, Tampere, Finland
 
Test driving-qml
Test driving-qmlTest driving-qml
Test driving-qml
 
Test driving QML
Test driving QMLTest driving QML
Test driving QML
 
Misapplied Scrum pattern
Misapplied Scrum patternMisapplied Scrum pattern
Misapplied Scrum pattern
 
Effective Software Development for the 21st century
Effective Software Development for the 21st centuryEffective Software Development for the 21st century
Effective Software Development for the 21st century
 

Último

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Último (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

QML settings

  • 1. Platform and device-specific settings for your QML layouts Artem Marchenko October 8, 2011 After Easy Discount Calculator by Artem Marchenko, JarmoParkkinen, TuukkaLindroos and Ekaterina Kuts Technical solution by Artem Marchenko and TuukkaLindroos
  • 2. Artem Marchenko Product Manager, Agile Coach, QML engineer for hire Was a Product Manager shipping multi-hundred MEur products Three times Forum Nokia Champion Private entrepreneur Available for hire for all things QML http://fi.linkedin.com/in/artemmarchenko
  • 3. Same app running on Harmattan, Android and Symbian
  • 4. Easy Discount Calculator Symbian, MeeGo/Harmattan - http://store.ovi.com/content/186742 Android - http://bit.ly/discountcalculator Free, but has font issues on some models due to porting technology bug. Well working proof of concept for now
  • 5. All the parameters can be fine-tuned on desktop
  • 6. Settings system // SettingsBase.QML import Qt 4.7 import "GlobalSettings.js" as Js QtObject { id: settingsObject // logical switches/conditions property boolexitButtonPresent: true property boolclearButtonIsBetweenTheLines: true // element sizes property introllerHeight: 110 property intdigitRollerWidth: 56 property intpercentageRollerWidth: digitRollerWidth
  • 7. Settings system // SettingsMaemo.qml import Qt 4.7 SettingsBase { property string platformTitle: "Maemo" property intscreenWidthInPortrait: 480 ... property introllerHeight: 160 property introllerNumberLineInnerSpacing: 0 property int digitRollerWidth:69 statusLineHeight: 0
  • 9. Using platform settings in JS //GlobalSettings.js .pragma library // - the only QML possibility for global variables varglobalSettings = null // Will fetch the settings object from the item. If the settings object doesn't // exists, will return the global one or generate one on the fly based on base settings. function getSettings(item) { … if(item.settings) { if(!globalSettings) { globalSettings = item.settings } if(!globalSettings) { var component = Qt.createComponent("SettingsBase.qml") globalSettings = component.createObject(item) } return globalSettings;
  • 10. Using Settings in QML // SmallButton.qml import Qt 4.7 import "GlobalSettings.js" as Js Rectangle { id: button width: Js.getSettings(button).smallButtonWidth height: Js.getSettings(button).smallButtonHeight radius: 3
  • 11. Injecting Settings from C++ QStringsettingsPath = "qml/discountcalcui/Settings" + platformTitle + ".qml"; // localAdjustPath cares about platform-specific file location details settingsUrl = QUrl::fromLocalFile(CrossPlatformUtils::localAdjustPath(settingsPath)); QDeclarativeComponent component(view.engine(), settingsUrl); settingsInstance = component.create(); if(!settingsInstance) { // No settings found - no object to install qWarning() << "Settings not found for this platform!"; qWarning() << component.errorString(); } else { settingsInstance->setProperty("shouldInitializeGlobalSettingWithItself", true); view.engine()->rootContext()->setContextProperty("forcedSettings”, settingsInstance); } // continue with normal QML initialization
  • 12. JavaScript side of initialization //SettingsBase.qml import Qt 4.7 import "GlobalSettings.js" as Js QtObject { id: settingsObject property boolshouldInitializeGlobalSettingWithItself: false // Is executed way before main QML file is loaded onShouldInitializeGlobalSettingWithItselfChanged: { if(shouldInitializeGlobalSettingWithItself) { console.log("SBase: initializing global settings with " + settingsObject) Js.globalSettings = settingsObject } }
  • 13. Switching settings for desktop simulation // Simulator for different platforms DiscountCalcUi { id: main } ListModel { id: platformsModel ListElement {title: "Symbian"; visualTitle: "S^3"} ListElement{title: "Android480x800"; visualTitle: "Andr 800" } ListElement{title: "Harmattan" } } onButtonClicked: { var component = Qt.createComponent("Settings" + model.title + ".qml") main.settings = component.createObject(main) } // actually, maybe we should have changed the global JS reference :/
  • 14. Summary Parameterizing code everywhere is possible and easy Use JavaScript libraries for storing global objects To initialize settings by the moment of QML instantiations, inject settings from C++ before the main QML object Care about ability to change settings object for the desktop simulation of different platforms
  • 15. Thank you Q&As time You can find these and similar slides at http://agilesoftwaredevelopment.com/tags/qml