Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
ThomasD
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook

Saving App Settings

I was wondering what the best way was to save user settings for an app.  Would you create a flat file that is parsed and modified based on the settings page or is their a better way to do this?

 

Thanks

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Saving App Settings

[ Edited ]

The most straightforward way for storing settings is Qt's QSettings class. Check starshipsettings Cascades sample:

https://github.com/blackberry/Cascades-Samples/tree/master/starshipsettings

 

You might find this usage pattern useful:

http://supportforums.blackberry.com/t5/Cascades-Development/Wanted-simple-example-of-data-class-with...


Andrey Fidrya, @zmeyc on twitter
Contributor
ThomasD
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook

Re: Saving App Settings

Thanks I will definitely look into that.
Developer
bcs925
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30

Re: Saving App Settings


Zmey wrote:

The most straightforward way for storing settings is Qt's QSettings class. Check starshipsettings Cascades sample:

https://github.com/blackberry/Cascades-Samples/tree/master/starshipsettings

 

You might find this usage pattern useful:

http://supportforums.blackberry.com/t5/Cascades-Development/Wanted-simple-example-of-data-class-with...


 

I have a tutorial where I explain what they do in the Starship Settings example: http://bbcascadescode.tumblr.com/post/35544384390/the-persistence-of-cascades-memory

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Contributor
ThomasD
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook

Re: Saving App Settings

Thanks for the info.  I have looked it over and have been testing some of the stuff along with my code.  Having a few minor issues though I was hoping you might be able to help rectify:

 

I have a Settings.qml file and a mix.qml file. In the settings file I have:

 

... inside a container

...

               RadioGroup {
                    id: measurementGroup
                    objectName: "radioGroup1"
                    horizontalAlignment: HorizontalAlignment.Center
                    scaleY: 0.85

                    Option {
                        id: imperial
                        objectName: "radioGroupOption0"
                        text: "Imperial";
                         
                        selected: app.getValueFor(objectName, "true")
                        
                        onSelectedChanged: {
                            app.saveValueFor(radioGroupOption0.objectName, radioGroupOption0.selected)

                        }
                     }
                     
                    Option {
                        id: metric;
                        objectName: "radioGroupOption2"
                        text: "Metric"
                        
                        selected: app.getValueFor(objectName, "false")
                        
                        onSelectedChanged: {
                            app.saveValueFor(radioGroupOption2.objectName, radioGroupOption2.selected)
                        }
                    }   
                }

...

...

 

and in the mix.qml

 

...

in container  have a property int that stores a int value that is passed to other functions

...

property int val

...

 

what I am trying to do is have this "val" change when a radiobutton is clicked.  I have mix2.qml, mix3.qml too and need it to propagate through them all.  Is this going to be overly difficult?

 

Thanks in advance.

Contributor
ThomasD
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook

Re: Saving App Settings

Was doing some thinking.

 

My main.qml is Tabbed - and am using onCreationCompleted.  Can I set a call to a javascript function in the onCreationCompleted that would use the persistant memory information from the settings radioButtons and property bindings in main.qml that could be used in each of the mix pages?

 

for example:

 

//main.qml

 

property alias VAL: maintab.value

property alias TYPE: maintab.type

 

TabbedPane {

      id: maintab

     

      property alias VAL: maintab.value

      property alias TYPE: maintab.type

      property int value

      property string type

 

      Tab {

          ...

       }

    

       Tab {

          ...

        }

onCreationCompleted: {

 

     // app comes from function.cpp --> qml->setContextProperty("app", this);

     var check = app.getValueFor("radioGroupOption0", "true")

     if (check == true) {

           setImpVariables()

     } else {

           setMetVariables()

     }

}

 

function setImpVariables () {

      // set int and string variables above in mainTab

}

 

function setMetVariables () {

      // set int and string variables above in mainTab

}

}

 

 

or am I pretty much completely out of it

Developer
Ebscer
Posts: 875
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha

Re: Saving App Settings

All of your save and load stuff is done on the backend with calls to the c methods...


Read my thoughts on BlackBerry Development at news.ebscer.com
Contributor
ThomasD
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook

Re: Saving App Settings

Hello Ebscer - I understand that and already have those functions built into the backend with calls to c. What I am trying to do is use the that data to modify a variable set on the front end.

For instance I have
getValueFor, saveValueFor functions already defined, etc in my c backend.

When the radiobutton is selected - if Imperial is selected - i need about 5 different variables set to imperial values, which are used in a number of different pages for different calculations. If metric, then the variable values change. Etc.

Am I just not understanding this correctly?
Developer
jasoncheung
Posts: 67
Registered: ‎09-01-2012
My Device: Dev Alpha

Re: Saving App Settings

If you set property alias for your Mix QML files...or even better, setup functions to update the properties, then in your main.qml, you can call those functions and populate them with the getValueFor function.

 

There are quite a few ways to do it depending on how your QML files are referenced in you main, but the gist of it is the same.

Contributor
ThomasD
Posts: 26
Registered: ‎01-04-2013
My Device: Playbook

Re: Saving App Settings

Jason,

 

I created a Function that would update the property alias variables I created in main.qml - this is what I tried:

 

--main.qml --

 

TabbedPane {
    id: mainTab
    showTabsOnActionBar: true

    property alias measureVAL: mainTab.value
    property int value
    property alias measureEND: mainTab.type
    property string type
    
     Tab {

       ...

     }        
    }

     Tab {

       ...

        }
    }

     Tab {

       ...

    }

    Tab {
        title: "Settings"
//        imageSource: "asset:///images/menuicons/icon_maxmin.png"

        SettingsPage {
            id: settingsMenuPage
        }
    }
    attachedObjects: [
        TextStyleDefinition {
            id: bigTextNormalWhite
            base: SystemDefaults.TextStyles.BigText
            fontWeight: FontWeight.W400
            color: Color.White
        },
        TextStyleDefinition {
            id: textTitleWhite
            base: SystemDefaults.TextStyles.Title
            fontWeight: FontWeigth.Normal
            color: Color.White
        },
        TextStyleDefinition {
            id: textTitleBlack
            base: SystemDefaults.TextStyles.Title
            fontWeight: FontWeigth.Normal
            color: Color.Black
        },
        TextStyleDefinition {
            id: textSmallBlack
            base: SystemDefaults.TextStyles.SmallText
            fontWeight: FontWeigth.Normal
            color: Color.Black
        },
        TextStyleDefinition {
            id: textTitleGrey
            base: SystemDefaults.TextStyles.Title
            fontWeight: FontWeight.W100
            color: Color.Grey
        }
    ]
    onCreationCompleted: {
        // Try to set global variables based on this
        var checkedSystem = app.getValueFor("imperial", "true")
        var checkedWater = app.getValueFor("water", "true")
        if ((checkedSystem == "true") && (checkedWater == "true")) {
            CalcFunctions.setVariables (0,0)
        } else if ((checkedSystem == "true") && (checkedWater == "false")) {
            CalcFunctions.setVariables (0,1)
        } else if ((checkedSystem == "false") && (checkedWater == "true")) {
            CalcFunctions.setVariables (1,0)
        } else {
            CalcFunctions.setVariables (1,1)
        }

        console.log("TabbedPane - onCreationCompleted()")
        OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
    }        
}

 

I am sure this is not the way to do it as when the app starts the values are correct based on the default settings, however when I change the RadioButton in the settings - the Mix.qml files do not update.

 

This is my SettingsPage.qml  ( you will see I tried a few things)

 

Page {
    id: settings
    
    Container {
        id: settings_menu
        background: Color.create("#262626")
    
        layout: StackLayout {
        }
        
        Container {
            id: settings_label
            background: Color.create("#3A3A38")
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Top
            preferredWidth: 768
            preferredHeight: 150
                
            Label {
                text: "Settings"
                horizontalAlignment: HorizontalAlignment.Center
                translationY: 20.0
                textStyle.base: bigTextNormalWhite.style
            }
        }
      
        Container {
            id: settings_divider
            background: Color.create("#000000")
            preferredWidth: 768
            preferredHeight: 5
        }

        Container {
            id: settings_choices
            background: back.imagePaint
                
            horizontalAlignment: HorizontalAlignment.Center
            preferredWidth: 760
            preferredHeight: 975

            Label {
                text: "Choose the system of measurement you \n prefer:"
                multiline: true
                translationY: 30
                preferredWidth: 740
                textStyle.fontWeight: FontWeight.W300
                textStyle.textAlign: TextAlign.Center
            }
            
            Container {
                id: measurementBox
                background: answer.imagePaint
                preferredWidth: 670
                preferredHeight: 140
                translationY: 40
                horizontalAlignment: HorizontalAlignment.Center
                
                RadioGroup {
                    id: measurementGroup
                    objectName: "radioGroup1"
                    
                    dividersVisible: true
                    preferredWidth: 600
                    horizontalAlignment: HorizontalAlignment.Center
                    scaleY: 0.85

                    Option {
                        id: imperial
                        objectName: "imperial"
                        text: "Imperial";
                         
                        selected: app.getValueFor(objectName, "true")
                        
                        onSelectedChanged: {
                            app.saveValueFor(imperial.objectName, radioGroupOption0.selected)
                            
                            if ((selected == "true") && (salt_water.selected == "true")) {
                                CalcFunctions.setVariables (0,0)
                            } else if ((selected == "true") && (salt_water.selected == "false")) {
                                CalcFunctions.setVariables (0,1)
                            } else if ((selected == "false") && (salt_water.selected == "true")) {
                                CalcFunctions.setVariables (1,0)
                            } else if ((selected == "false") && (salt_water.selected == "false")) {
                                CalcFunctions.setVariables (1,1)
                            }
                        }
                     }
                     
                    Option {
                        id: metric;
                        objectName: "metric"
                        text: "Metric"
                        
                        selected: app.getValueFor(objectName, "false")
                        
                        onSelectedChanged: {
                            app.saveValueFor(metric.objectName, radioGroupOption2.selected)

                            if ((selected == "true") && (salt_water.selected == "true")) {
                                CalcFunctions.setVariables (1,0)
                            } else if ((selected == "true") && (salt_water.selected == "false")) {
                                CalcFunctions.setVariables (1,1)
                            } else if ((selected == "false") && (salt_water.selected == "true")) {
                                CalcFunctions.setVariables (0,0)
                            } else if ((selected == "false") && (salt_water.selected == "false")) {
                                CalcFunctions.setVariables (0,1)
                            }
                        }
                    }   
                }                 
            }
            
            // Next Setting
            Label {
                text: "Choose salt water or fresh water for your\n calculations:"
                multiline: true
                translationY: 60
                preferredWidth: 740
                textStyle.fontWeight: FontWeight.W300
                textStyle.textAlign: TextAlign.Center
            }            

            Container {
                id: waterBox
                background: answer.imagePaint
                preferredWidth: 670
                preferredHeight: 140
                translationY: 70
                horizontalAlignment: HorizontalAlignment.Center
                
                RadioGroup {
                    id: waterGroup
                    objectName: "waterGroup"
                    
                    dividersVisible: true
                    preferredWidth: 600
                    horizontalAlignment: HorizontalAlignment.Center
                    scaleY: 0.85

                    Option {
                        id: salt_water
                        objectName: "salt_water"
                        text: "Salt water";
                         
                        selected: app.getValueFor(objectName, "true")
                        
                        onSelectedChanged: {
                            app.saveValueFor(salt_water.objectName, radioGroupOption0.selected)
                            
                            if ((imperial.selected == "true") && (selected == "true")) {
                                CalcFunctions.setVariables (0,0)
                            } else if ((imperial.selected == "true") && (selected == "false")) {
                                CalcFunctions.setVariables (0,1)
                            } else if ((imperial.selected == "false") && (selected == "true")) {
                                CalcFunctions.setVariables (1,0)
                            } else if ((imperial.selected == "false") && (selected == "false")) {
                                CalcFunctions.setVariables (1,1)
                            }
                        }
                     }
                     
                    Option {
                        id: fresh_water;
                        objectName: "fresh_water"
                        text: "Fresh water"
                        
                        selected: app.getValueFor(objectName, "false")
                        
                        onSelectedChanged: {
                            app.saveValueFor(fresh_water.objectName, radioGroupOption2.selected)

                            if ((imperial.selected == "true") && (selected == "true")) {
                                CalcFunctions.setVariables (0,1)
                            } else if ((imperial.selected == "true") && (selected == "false")) {
                                CalcFunctions.setVariables (0,0)
                            } else if ((imperial.selected == "false") && (selected == "true")) {
                                CalcFunctions.setVariables (1,1)
                            } else if ((imperial.selected == "false") && (selected == "false")) {
                                CalcFunctions.setVariables (1,0)
                            }
                        }
                    }   
                }                 
            }


        }
    }
    attachedObjects: [
        ImagePaintDefinition {
            id: back
            repeatPattern: RepeatPattern.Fill
            imageSource: "asset:///images/background.amd"
        },
        ImagePaintDefinition {
            id: answer
            repeatPattern: RepeatPatter.Fill
            imageSource: "asset:///images/answer.amd"
        }
    ]
}