camerauis/cameraxui/cxui/src/cxuisettingradiobuttonlist.cpp
changeset 37 64817133cd1d
parent 32 5c1e3c6aa4ef
child 42 feebad15db8c
child 48 42ba2d16bf40
--- a/camerauis/cameraxui/cxui/src/cxuisettingradiobuttonlist.cpp	Wed Jun 23 17:59:54 2010 +0300
+++ b/camerauis/cameraxui/cxui/src/cxuisettingradiobuttonlist.cpp	Tue Jul 06 14:04:02 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -38,7 +38,9 @@
     connect(this, SIGNAL(itemSelected(int)), this, SLOT(handleItemSelected(int)));
 }
 
-
+/*!
+* Init contents of the listbox and select current setting value.
+*/
 void CxuiSettingRadioButtonList::init(CxUiSettings::RadioButtonListParams *data)
 {
     // first we reset the model and clear any previous data
@@ -68,11 +70,12 @@
         setSettingId(data->mSettingId);
         setListBoxType(data->mListboxType);
 
-        initOriginalSelectedItem();
-        // ensure that currently selected item is visible
-        scrollTo(currentIndex());
+        // Store the original setting value and focus matching item.
+        QString value;
+        mEngine->settings().get(mSettingId, value);
+        CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", value.toAscii().data()));
+        setOriginalSelectedItemByValue(QVariant(value));
     }
-
 }
 
 /*!
@@ -91,30 +94,43 @@
         // ensure that currently selected item is visible
         scrollTo(currentIndex());
     } else {
-        CX_DEBUG(("Value %s not found", value.toString().toAscii().data()));
+        CX_DEBUG(("[WARNING] Value %s not found, defaulting to first item", value.toString().toAscii().data()));
     }
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*!
+* Set list texts.
+* @param values List of the texts.
+*/
 void CxuiSettingRadioButtonList::setItems(const QStringList &values)
 {
     mListModel->setItems(values);
 }
 
+/*!
+* Set the type of this list.
+* @param type Type identifier, SingleLine or TwoLine.
+*/
 void CxuiSettingRadioButtonList::setListBoxType(int type)
 {
     mListModel->setListBoxType(type);
 }
 
-
+/*!
+* Set id of the setting this list represents.
+* @param id Id of the setting.
+*/
 void CxuiSettingRadioButtonList::setSettingId(const QString &id)
 {
     // Selected item is updated, when this list is shown.
     mSettingId = id;
 }
 
-
-
+/*!
+* Handle selecting an item.
+* @param index Index of the selected item in list.
+*/
 void CxuiSettingRadioButtonList::handleItemSelected(int index)
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -128,30 +144,6 @@
 }
 
 /*!
-*  Get the value currently active in settings.
-*/
-void CxuiSettingRadioButtonList::initOriginalSelectedItem()
-{
-    CX_DEBUG_ENTER_FUNCTION();
-
-    QString value;
-    int err = mEngine->settings().get(mSettingId, value);
-    CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", value.toAscii().data()));
-
-    int index = 0;
-
-    if (err == CxeError::None) {
-        index = mSettingValues.indexOf(QVariant(value));
-        CX_DEBUG(("CxuiSettingRadioButtonList - got original index of: %d", index));
-    }
-
-    mOriginalIndex = index;
-    setSelected(mOriginalIndex);
-
-    CX_DEBUG_EXIT_FUNCTION();
-}
-
-/*!
     This slot can be used to set the selection accepted.
 */
 void CxuiSettingRadioButtonList::handleSelectionAccepted()
@@ -167,6 +159,11 @@
     CX_DEBUG_EXIT_FUNCTION();
 }
 
+/*!
+* Handle closing the listbox. If the current selection was accepted,
+* we commit the new value here. If current selection has been cancelled,
+* we commit the original value.
+*/
 void CxuiSettingRadioButtonList::handleClose()
 {
     CX_DEBUG_ENTER_FUNCTION();
@@ -187,7 +184,7 @@
 
 
 /*!
-  Commits value to the cenrep store.
+  Commits value to settings.
 */
 void CxuiSettingRadioButtonList::commit(int index)
 {