66
|
1 |
/*
|
|
2 |
* ====================================================
|
|
3 |
* Name : treedataform.cpp
|
|
4 |
* Part of : fute/SecUiTestQt
|
|
5 |
* Description : Data form for SecUiTestQt
|
|
6 |
* Version : %version: 1 %
|
|
7 |
*
|
|
8 |
* Copyright (c) 2009 Nokia. All rights reserved.
|
|
9 |
* This material, including documentation and any related computer
|
|
10 |
* programs, is protected by copyright controlled by Nokia. All
|
|
11 |
* rights are reserved. Copying, including reproducing, storing,
|
|
12 |
* adapting or translating, any or all of this material requires the
|
|
13 |
* prior written consent of Nokia. This material also contains
|
|
14 |
* confidential information which may not be disclosed to others
|
|
15 |
* without the prior written consent of Nokia.
|
|
16 |
* ====================================================
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "treedataform.h"
|
|
20 |
#include "dirviewitem.h"
|
|
21 |
#include <hbtreeview.h>
|
|
22 |
#include <hbtreeviewitem.h>
|
|
23 |
#include <hbdataformmodel.h>
|
|
24 |
|
|
25 |
const QStringList KDepths = ( QStringList() << "1" << "3" << "5" << "all" );
|
|
26 |
const QStringList ViewItems = (QStringList() << "Default" << "DirItem");
|
|
27 |
|
|
28 |
// ======== MEMBER FUNCTIONS ========
|
|
29 |
|
|
30 |
TreeDataForm::TreeDataForm( HbAbstractItemView &view,
|
|
31 |
QGraphicsItem *parent):
|
|
32 |
ViewFuteDataForm(view, parent),
|
|
33 |
depth(1),
|
|
34 |
indentation(-1),
|
|
35 |
dirViewItemEnabled(false)
|
|
36 |
{
|
|
37 |
}
|
|
38 |
|
|
39 |
TreeDataForm::~TreeDataForm()
|
|
40 |
{
|
|
41 |
}
|
|
42 |
|
|
43 |
void TreeDataForm::initialise()
|
|
44 |
{
|
|
45 |
depth = 1;
|
|
46 |
dirViewItemEnabled = false;
|
|
47 |
for (int i=0; i< TreeCustomLast; i++) {
|
|
48 |
customTreeSettingsIndexes[i] = -1;
|
|
49 |
}
|
|
50 |
ViewFuteDataForm::initialise();
|
|
51 |
}
|
|
52 |
|
|
53 |
int TreeDataForm::populateCustomSettingsItem(int previousItem)
|
|
54 |
{
|
|
55 |
HbTreeView *tree = qobject_cast<HbTreeView*>(view);
|
|
56 |
HbTreeViewItem *prototype = qobject_cast<HbTreeViewItem *>(tree->itemPrototypes().first());
|
|
57 |
|
|
58 |
if (tree) {
|
|
59 |
if (previousItem == ViewFuteDataForm::ScrollHint) {
|
|
60 |
customTreeSettingsIndexes[Depth] = counter;
|
|
61 |
HbDataFormModelItem *item = settingsFormModel->appendDataFormItem(
|
|
62 |
HbDataFormModelItem::RadioButtonListItem, QString("Depth of visible tree:"));
|
|
63 |
item->setContentWidgetData("items", KDepths);
|
|
64 |
if (depth == 1) {
|
|
65 |
item->setContentWidgetData("selected", 0);
|
|
66 |
} else if (depth == 3) {
|
|
67 |
item->setContentWidgetData("selected", 1);
|
|
68 |
} else if (depth == 5) {
|
|
69 |
item->setContentWidgetData("selected", 2);
|
|
70 |
} else {
|
|
71 |
item->setContentWidgetData("selected", 3);
|
|
72 |
}
|
|
73 |
|
|
74 |
customTreeSettingsIndexes[Indentation] = counter+1;
|
|
75 |
item = settingsFormModel->appendDataFormItem(
|
|
76 |
HbDataFormModelItem::TextItem, QString("Indentation: (negative sets default)"));
|
|
77 |
QString indentationString;
|
|
78 |
indentationString.setNum(indentation);
|
|
79 |
item->setContentWidgetData("text", indentationString);
|
|
80 |
|
|
81 |
customTreeSettingsIndexes[ItemUserExpandable] = counter + 2;
|
|
82 |
item = settingsFormModel->appendDataFormItem(
|
|
83 |
HbDataFormModelItem::ToggleValueItem, QString("Items user expandable:"));
|
|
84 |
if (prototype->isUserExpandable()) {
|
|
85 |
item->setContentWidgetData("text", "On");
|
|
86 |
item->setContentWidgetData("additionalText", "Off");
|
|
87 |
} else {
|
|
88 |
item->setContentWidgetData("text", "Off");
|
|
89 |
item->setContentWidgetData("additionalText", "On");
|
|
90 |
}
|
|
91 |
return 3;
|
|
92 |
} else if ( previousItem == ViewFuteDataForm::FrictionEnabled
|
|
93 |
&& dirViewItemEnabled) {
|
|
94 |
customTreeSettingsIndexes[ViewItemType] = counter;
|
|
95 |
HbDataFormModelItem *item = settingsFormModel->appendDataFormItem(
|
|
96 |
HbDataFormModelItem::RadioButtonListItem, QString("View item type:"));
|
|
97 |
item->setContentWidgetData("items", ViewItems);
|
|
98 |
if (qobject_cast<DirViewItem*>(tree->itemPrototypes().first())) {
|
|
99 |
item->setContentWidgetData("selected", 1);
|
|
100 |
} else {
|
|
101 |
item->setContentWidgetData("selected", 0);
|
|
102 |
}
|
|
103 |
return 1;
|
|
104 |
}
|
|
105 |
}
|
|
106 |
return 0;
|
|
107 |
}
|
|
108 |
|
|
109 |
void TreeDataForm::resolveSettingsResults()
|
|
110 |
{
|
|
111 |
HbTreeView *tree = qobject_cast<HbTreeView*>(view);
|
|
112 |
HbTreeViewItem *prototype = qobject_cast<HbTreeViewItem *>(tree->itemPrototypes().first());
|
|
113 |
|
|
114 |
if (tree) {
|
|
115 |
if (dirViewItemEnabled) {
|
|
116 |
if ( static_cast<HbDataFormViewItem*>(itemByIndex(settingsFormModel->index(customTreeSettingsIndexes[ViewItemType],0)))->
|
|
117 |
dataItemContentWidget()->property("selected").toInt() == 1) {
|
|
118 |
if (!qgraphicsitem_cast<DirViewItem*>(tree->itemPrototypes().first())) {
|
|
119 |
DirViewItem *prototype = new DirViewItem;
|
|
120 |
tree->setItemPrototype(prototype);
|
|
121 |
tree->setLayoutName("treeviewitem_dir_button");
|
|
122 |
}
|
|
123 |
}
|
|
124 |
else {
|
|
125 |
HbTreeViewItem *prototype = new HbTreeViewItem;
|
|
126 |
tree->setItemPrototype(prototype);
|
|
127 |
tree->setLayoutName("default");
|
|
128 |
}
|
|
129 |
}
|
|
130 |
QString indentationString = static_cast<HbDataFormViewItem*>(itemByIndex(settingsFormModel->index(
|
|
131 |
customTreeSettingsIndexes[Indentation],0)))->dataItemContentWidget()->property("text").toString();
|
|
132 |
bool ok = false;
|
|
133 |
int newIndentation = indentationString.toInt(&ok);
|
|
134 |
if (ok) {
|
|
135 |
indentation = newIndentation;
|
|
136 |
}
|
|
137 |
tree->setIndentation(indentation);
|
|
138 |
|
|
139 |
if (prototype) {
|
|
140 |
if (static_cast<HbDataFormViewItem*>(itemByIndex(settingsFormModel->index(
|
|
141 |
customTreeSettingsIndexes[ItemUserExpandable],0)))->dataItemContentWidget()->property("text").toString() == "On") {
|
|
142 |
prototype->setUserExpandable(true);
|
|
143 |
} else {
|
|
144 |
prototype->setUserExpandable(false);
|
|
145 |
}
|
|
146 |
}
|
|
147 |
}
|
|
148 |
ViewFuteDataForm::resolveSettingsResults();
|
|
149 |
}
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
void TreeDataForm::setIndentation(int indentation)
|
|
154 |
{
|
|
155 |
this->indentation = indentation;
|
|
156 |
}
|
|
157 |
|
|
158 |
|
|
159 |
void TreeDataForm::setDepth(int depth)
|
|
160 |
{
|
|
161 |
this->depth = depth;
|
|
162 |
}
|
|
163 |
|
|
164 |
void TreeDataForm::setDirViewItemEnabled(bool enable)
|
|
165 |
{
|
|
166 |
dirViewItemEnabled = enable;
|
|
167 |
}
|
|
168 |
|
|
169 |
int TreeDataForm::getDepth() const
|
|
170 |
{
|
|
171 |
int selected = static_cast<HbDataFormViewItem*>(itemByIndex(settingsFormModel->index(customTreeSettingsIndexes[Depth],0)))->
|
|
172 |
dataItemContentWidget()->property("selected").toInt();
|
|
173 |
if ( selected >= 0
|
|
174 |
&& selected < KDepths.count()) {
|
|
175 |
if (KDepths[selected] == KDepths[KDepths.count()-1]) {
|
|
176 |
return 999;
|
|
177 |
} else {
|
|
178 |
return KDepths[selected].toInt();
|
|
179 |
}
|
|
180 |
} else {
|
|
181 |
return depth;
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|