1 /* |
|
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QAbstractListModel> |
|
19 |
|
20 #include "cxutils.h" // debug |
|
21 #include "cxuienums.h" |
|
22 #include "cxuisettingsinfo.h" |
|
23 #include "cxuisettingradiobuttonlist.h" |
|
24 #include "cxuisettingradiobuttonlistmodel.h" |
|
25 |
|
26 |
|
27 |
|
28 /*! |
|
29 * CxuiSettingRadioButtonListModel::CxuiSettingRadioButtonListModel |
|
30 */ |
|
31 CxuiSettingRadioButtonListModel::CxuiSettingRadioButtonListModel() : |
|
32 QAbstractListModel(), |
|
33 mListBoxType(CxuiSettingRadioButtonList::SingleLine) |
|
34 |
|
35 { |
|
36 } |
|
37 |
|
38 |
|
39 |
|
40 /*! |
|
41 * CxuiSettingRadioButtonListModel::CxuiSettingRadioButtonListModel |
|
42 */ |
|
43 void CxuiSettingRadioButtonListModel::resetModel() |
|
44 { |
|
45 CX_DEBUG_ENTER_FUNCTION(); |
|
46 |
|
47 // starts reseting the model |
|
48 beginResetModel(); |
|
49 |
|
50 mItems.clear(); |
|
51 mListBoxType = CxuiSettingRadioButtonList::SingleLine; |
|
52 |
|
53 // ends reseting the model |
|
54 endResetModel(); |
|
55 |
|
56 CX_DEBUG_EXIT_FUNCTION(); |
|
57 } |
|
58 |
|
59 |
|
60 /*! |
|
61 * Reads data |
|
62 */ |
|
63 QVariant CxuiSettingRadioButtonListModel::data(const QModelIndex &index, int role) const |
|
64 { |
|
65 CX_DEBUG_ENTER_FUNCTION(); |
|
66 CX_DEBUG(("CxuiSettingRadioButtonListModel: index.row() = %d", index.row())); |
|
67 |
|
68 QVariant data; |
|
69 |
|
70 if (!index.isValid()) { |
|
71 CX_DEBUG(("[WARNING] CxuiSettingRadioButtonListModel: index.isValid() not true!")); |
|
72 } else if (index.row() >= rowCount(index)) { |
|
73 CX_DEBUG(("[WARNING] CxuiSettingRadioButtonListModel: row too large, row count %d!", rowCount(index))); |
|
74 } else if (role == Qt::DisplayRole) { // Happy case |
|
75 QStringList list; |
|
76 QString setting = mItems.at(index.row()); |
|
77 CX_DEBUG(("CxuiSettingRadioButtonListModel: data [%s]", setting.toAscii().constData())); |
|
78 |
|
79 if (mListBoxType == CxuiSettingRadioButtonList::TwoLine) { |
|
80 CX_DEBUG(("CxuiSettingRadioButtonListModel: Listbox type is TwoLineListBox")); |
|
81 // two line list box |
|
82 // get the two strings |
|
83 QStringList lines = setting.split(CxUiSettings::NEW_LINE_CHAR); |
|
84 // Split returns always atleast a single element list. |
|
85 list << lines[0]; |
|
86 if (lines.size() > 1) { |
|
87 list << lines[1]; |
|
88 } |
|
89 } else { |
|
90 CX_DEBUG(("CxuiSettingRadioButtonListModel: Listbox type is SingleLine")); |
|
91 list << setting; |
|
92 } |
|
93 |
|
94 data = QVariant(list); |
|
95 } else { |
|
96 // No action |
|
97 } |
|
98 |
|
99 CX_DEBUG_EXIT_FUNCTION(); |
|
100 return data; |
|
101 } |
|
102 |
|
103 /*! |
|
104 Returns number of rows in the radio button setting page. |
|
105 */ |
|
106 int CxuiSettingRadioButtonListModel::rowCount(const QModelIndex &parent) const |
|
107 { |
|
108 Q_UNUSED(parent) |
|
109 return mItems.count(); |
|
110 } |
|
111 |
|
112 |
|
113 /*! |
|
114 Sets the items visible in the radio button list |
|
115 */ |
|
116 void CxuiSettingRadioButtonListModel::setItems(QStringList items) |
|
117 { |
|
118 CX_DEBUG_ENTER_FUNCTION(); |
|
119 mItems = items; |
|
120 CX_DEBUG_EXIT_FUNCTION(); |
|
121 } |
|
122 |
|
123 |
|
124 /*! |
|
125 Sets the items visible in the radio button list |
|
126 */ |
|
127 QStringList CxuiSettingRadioButtonListModel::items() const |
|
128 { |
|
129 return mItems; |
|
130 } |
|
131 |
|
132 /*! |
|
133 Sets the items visible in the radio button list |
|
134 */ |
|
135 void |
|
136 CxuiSettingRadioButtonListModel::setListBoxType(int type) |
|
137 { |
|
138 mListBoxType = type; |
|
139 } |
|
140 |
|
141 int CxuiSettingRadioButtonListModel::listBoxType() const |
|
142 { |
|
143 return mListBoxType; |
|
144 } |
|