|
1 /* |
|
2 * Copyright (c) 2002-2005 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: This class provides custom list item for the |
|
15 * DataForm |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <settingsdataformcustomitem.h> |
|
20 #include <hbdataformmodelitem.h> |
|
21 #include <hblineedit.h> |
|
22 #include <hbinputeditorinterface.h> |
|
23 #include <qgraphicslinearlayout.h> |
|
24 #include <hblabel.h> |
|
25 #include <hbabstractitemview.h> |
|
26 #include <hbdataformmodel.h> |
|
27 |
|
28 SettingsDataFormCustomItem::SettingsDataFormCustomItem(QGraphicsItem *parent) : |
|
29 HbDataFormViewItem(parent),mLineEdit(NULL) |
|
30 { |
|
31 } |
|
32 |
|
33 SettingsDataFormCustomItem::~SettingsDataFormCustomItem() |
|
34 { |
|
35 } |
|
36 |
|
37 HbAbstractViewItem* SettingsDataFormCustomItem::createItem() |
|
38 { |
|
39 return new SettingsDataFormCustomItem(*this); |
|
40 } |
|
41 |
|
42 HbWidget* SettingsDataFormCustomItem::createCustomWidget() |
|
43 { |
|
44 HbDataFormModelItem::DataItemType itemType = |
|
45 static_cast<HbDataFormModelItem::DataItemType> |
|
46 ( modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt() ); |
|
47 switch (itemType) |
|
48 { |
|
49 case HbDataFormModelItem::CustomItemBase : |
|
50 { |
|
51 mLineEdit = new HbLineEdit(); |
|
52 HbEditorInterface editorInterface(mLineEdit); |
|
53 editorInterface.setMode(HbInputModeNumeric); |
|
54 editorInterface.setInputConstraints(HbEditorConstraintFixedInputMode); |
|
55 return mLineEdit; |
|
56 } |
|
57 default: |
|
58 return 0; |
|
59 } |
|
60 } |
|
61 |
|
62 bool SettingsDataFormCustomItem::canSetModelIndex( const QModelIndex& aIndex ) const |
|
63 { |
|
64 int itemType = aIndex.data(HbDataFormModelItem::ItemTypeRole).toInt(); |
|
65 return itemType == HbDataFormModelItem::CustomItemBase; |
|
66 } |
|
67 |
|
68 void SettingsDataFormCustomItem::restore() |
|
69 { |
|
70 HbDataFormViewItem::restore(); |
|
71 HbDataFormModelItem::DataItemType itemType = static_cast<HbDataFormModelItem::DataItemType>( |
|
72 modelIndex().data(HbDataFormModelItem::ItemTypeRole).toInt()); |
|
73 if( itemType == HbDataFormModelItem::CustomItemBase ) { |
|
74 QModelIndex itemIndex = modelIndex(); |
|
75 HbDataFormModelItem *modelItem = static_cast<HbDataFormModelItem*>( |
|
76 static_cast<HbDataFormModel*>(itemView()->model())->itemFromIndex(itemIndex)); |
|
77 QString port = modelItem->contentWidgetData("text").toString(); |
|
78 qDebug("port is %d",port.toInt()); |
|
79 mLineEdit->setText(port); |
|
80 } |
|
81 } |