camerauis/cameraxui/cxui/src/cxuisettingradiobuttonlist.cpp
changeset 48 42ba2d16bf40
parent 37 64817133cd1d
child 56 01e205c615b9
equal deleted inserted replaced
37:64817133cd1d 48:42ba2d16bf40
    69 
    69 
    70         setSettingId(data->mSettingId);
    70         setSettingId(data->mSettingId);
    71         setListBoxType(data->mListboxType);
    71         setListBoxType(data->mListboxType);
    72 
    72 
    73         // Store the original setting value and focus matching item.
    73         // Store the original setting value and focus matching item.
    74         QString value;
    74         QString value = mEngine->settings().get<QString>(mSettingId, "");
    75         mEngine->settings().get(mSettingId, value);
    75         CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", qPrintable(value)));
    76         CX_DEBUG(("CxuiSettingRadioButtonList - original value: [%s]", value.toAscii().data()));
       
    77         setOriginalSelectedItemByValue(QVariant(value));
    76         setOriginalSelectedItemByValue(QVariant(value));
    78     }
    77     }
    79 }
    78 }
    80 
    79 
    81 /*!
    80 /*!
    85  */
    84  */
    86 void CxuiSettingRadioButtonList::setOriginalSelectedItemByValue(const QVariant &value)
    85 void CxuiSettingRadioButtonList::setOriginalSelectedItemByValue(const QVariant &value)
    87 {
    86 {
    88     CX_DEBUG_ENTER_FUNCTION();
    87     CX_DEBUG_ENTER_FUNCTION();
    89 
    88 
       
    89     // Find the index of given value among setting values.
       
    90     // Default to first item, if given value is not found.
    90     int index = mSettingValues.indexOf(QVariant(value));
    91     int index = mSettingValues.indexOf(QVariant(value));
    91     if (index >= 0) {
    92     if (index < 0) {
    92         mOriginalIndex = index;
    93         CX_DEBUG(("[WARNING] Value [%s] not found, selecting first item", qPrintable(value.toString())));
    93         setSelected(index);
    94         index = 0;
    94         // ensure that currently selected item is visible
    95     }
    95         scrollTo(currentIndex());
    96 
    96     } else {
    97     // Store the original value.
    97         CX_DEBUG(("[WARNING] Value %s not found, defaulting to first item", value.toString().toAscii().data()));
    98     mOriginalIndex = index;
    98     }
    99     // Select the index with current value item.
       
   100     setSelected(index);
       
   101     // Ensure that currently selected item is visible.
       
   102     scrollTo(currentIndex());
       
   103 
    99     CX_DEBUG_EXIT_FUNCTION();
   104     CX_DEBUG_EXIT_FUNCTION();
   100 }
   105 }
   101 
   106 
   102 /*!
   107 /*!
   103 * Set list texts.
   108 * Set list texts.
   188 */
   193 */
   189 void CxuiSettingRadioButtonList::commit(int index)
   194 void CxuiSettingRadioButtonList::commit(int index)
   190 {
   195 {
   191     CX_DEBUG_ENTER_FUNCTION();
   196     CX_DEBUG_ENTER_FUNCTION();
   192 
   197 
   193     CX_DEBUG(("id: %s", mSettingId.toAscii().data()));
   198     CX_DEBUG(("CxuiSettingRadioButtonList - id: %s", qPrintable(mSettingId)));
   194 
   199 
   195     if (!mSettingId.isEmpty() && !mSettingValues.isEmpty()) {
   200     if (!mSettingId.isEmpty() && !mSettingValues.isEmpty()) {
   196         QVariant value = mSettingValues.at(index);
   201         QVariant value = mSettingValues.at(index);
   197         if (value.type() == QVariant::Int) {
   202         if (value.type() == QVariant::Int) {
   198             CX_DEBUG(("index:%d value:%d", index, value.toInt()));
   203             CX_DEBUG(("CxuiSettingRadioButtonList - index:%d value:%d", index, value.toInt()));
   199 
   204 
   200             // Don't set the value again, if it is the current value.
   205             // Don't set the value again, if it is the current value.
   201             // For e.g. video quality it would result in re-preparation etc.
   206             // For e.g. video quality it would result in re-preparation etc.
   202             int current(0);
   207             try {
   203             CxeError::Id status(mEngine->settings().get(mSettingId, current));
   208                 int current = mEngine->settings().get<int>(mSettingId);
   204 
   209                 if (current != value.toInt()) {
   205             if (status != CxeError::None || current != value.toInt()) {
   210                     mEngine->settings().set(mSettingId, value.toInt());
   206                 mEngine->settings().set(mSettingId, value.toInt());
   211                 }
       
   212             } catch (CxeException &e) {
       
   213                 // ignore error
   207             }
   214             }
   208             // inform interested clients about value changed event
   215             // inform interested clients about value changed event
   209             emit valueSelected(value.toInt());
   216             emit valueSelected(value.toInt());
   210 
   217 
   211         } else if (value.type() == QVariant::String) {
   218         } else if (value.type() == QVariant::String) {
   212             CX_DEBUG(("index:%d value:[%s]", index, value.toString().toAscii().constData()));
   219             CX_DEBUG(("CxuiSettingRadioButtonList - index:%d value:[%s]", index, qPrintable(value.toString())));
   213 
   220 
   214             QString current;
   221             try {
   215             CxeError::Id status(mEngine->settings().get(mSettingId, current));
   222                 QString current = mEngine->settings().get<QString>(mSettingId);
   216             CX_DEBUG(("settings model value:[%s]", current.toAscii().constData()));
   223                 CX_DEBUG(("CxuiSettingRadioButtonList - settings model value:[%s]", qPrintable(current)));
   217 
   224                 if (current != value.toString()) {
   218             if (status != CxeError::None || current != value.toString()) {
   225                     mEngine->settings().set(mSettingId, value.toString());
   219                 mEngine->settings().set(mSettingId, value.toString());
   226                 }
       
   227             } catch (CxeException &e) {
       
   228                 // ignore error
   220             }
   229             }
   221         }
   230         }
   222     }
   231     }
   223 
   232 
   224     CX_DEBUG_EXIT_FUNCTION();
   233     CX_DEBUG_EXIT_FUNCTION();