|
1 /* |
|
2 * Copyright (c) 2009 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 "cxuisettingradiobuttonlist.h" |
|
23 #include "cxuisettingradiobuttonlistmodel.h" |
|
24 |
|
25 |
|
26 |
|
27 /*! |
|
28 * CxuiSettingRadioButtonListModel::CxuiSettingRadioButtonListModel |
|
29 */ |
|
30 CxuiSettingRadioButtonListModel::CxuiSettingRadioButtonListModel() : |
|
31 QAbstractListModel(), |
|
32 mListBoxType(CxuiSettingRadioButtonList::SingleLine) |
|
33 |
|
34 { |
|
35 } |
|
36 |
|
37 |
|
38 |
|
39 /*! |
|
40 * CxuiSettingRadioButtonListModel::CxuiSettingRadioButtonListModel |
|
41 */ |
|
42 void CxuiSettingRadioButtonListModel::resetModel() |
|
43 { |
|
44 CX_DEBUG_ENTER_FUNCTION(); |
|
45 |
|
46 // starts reseting the model |
|
47 beginResetModel(); |
|
48 |
|
49 mItems.clear(); |
|
50 mListBoxType = CxuiSettingRadioButtonList::SingleLine; |
|
51 |
|
52 // ends reseting the model |
|
53 endResetModel(); |
|
54 |
|
55 CX_DEBUG_EXIT_FUNCTION(); |
|
56 } |
|
57 |
|
58 |
|
59 /*! |
|
60 * Reads data |
|
61 */ |
|
62 QVariant CxuiSettingRadioButtonListModel::data(const QModelIndex &index, int role) const |
|
63 { |
|
64 CX_DEBUG_ENTER_FUNCTION(); |
|
65 CX_DEBUG(("CxuiSettingRadioButtonListModel: index.row() = %d", index.row())); |
|
66 |
|
67 QVariant data; |
|
68 |
|
69 if (!index.isValid()) { |
|
70 CX_DEBUG(("[WARNING] CxuiSettingRadioButtonListModel: index.isValid() not true!")); |
|
71 } else if (index.row() >= rowCount(index)) { |
|
72 CX_DEBUG(("[WARNING] CxuiSettingRadioButtonListModel: row too large, row count %d!", rowCount(index))); |
|
73 } else if (role == Qt::DisplayRole) { // Happy case |
|
74 QStringList list; |
|
75 QString setting = mItems.at(index.row()); |
|
76 CX_DEBUG(("CxuiSettingRadioButtonListModel: data [%s]", setting.toAscii().constData())); |
|
77 |
|
78 if (mListBoxType == CxuiSettingRadioButtonList::TwoLine) { |
|
79 CX_DEBUG(("CxuiSettingRadioButtonListModel: Listbox type is TwoLineListBox")); |
|
80 // two line list box |
|
81 // get the two strings |
|
82 QStringList lines = setting.split(","); |
|
83 QString first = lines[0]; |
|
84 QString second = lines[1]; |
|
85 list << first << second ; |
|
86 } else { |
|
87 CX_DEBUG(("CxuiSettingRadioButtonListModel: Listbox type is SingleLine")); |
|
88 list << setting; |
|
89 } |
|
90 |
|
91 data = QVariant(list); |
|
92 } else { |
|
93 CX_DEBUG(("[WARNING] CxuiSettingRadioButtonListModel: role is not DisplayRole!")); |
|
94 } |
|
95 |
|
96 CX_DEBUG_EXIT_FUNCTION(); |
|
97 return data; |
|
98 } |
|
99 |
|
100 /*! |
|
101 Returns number of rows in the radio button setting page. |
|
102 */ |
|
103 int CxuiSettingRadioButtonListModel::rowCount(const QModelIndex &parent) const |
|
104 { |
|
105 Q_UNUSED(parent) |
|
106 return mItems.count(); |
|
107 } |
|
108 |
|
109 |
|
110 /*! |
|
111 Sets the items visible in the radio button list |
|
112 */ |
|
113 void CxuiSettingRadioButtonListModel::setItems(QStringList items) |
|
114 { |
|
115 CX_DEBUG_ENTER_FUNCTION(); |
|
116 mItems = items; |
|
117 CX_DEBUG_EXIT_FUNCTION(); |
|
118 } |
|
119 |
|
120 |
|
121 /*! |
|
122 Sets the items visible in the radio button list |
|
123 */ |
|
124 QStringList CxuiSettingRadioButtonListModel::items() const |
|
125 { |
|
126 return mItems; |
|
127 } |
|
128 |
|
129 /*! |
|
130 Sets the items visible in the radio button list |
|
131 */ |
|
132 void |
|
133 CxuiSettingRadioButtonListModel::setListBoxType(int type) |
|
134 { |
|
135 mListBoxType = type; |
|
136 } |
|
137 |
|
138 int CxuiSettingRadioButtonListModel::listBoxType() const |
|
139 { |
|
140 return mListBoxType; |
|
141 } |