-
Notifications
You must be signed in to change notification settings - Fork 0
/
EPropertySheet.cpp
189 lines (168 loc) · 4.69 KB
/
EPropertySheet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "stdafx.h"
#include "EPropertySheet.h"
#include "qstandarditemmodel.h"
#include "EPropertySheetDelegate.h"
#include <assert.h>
#include "EPropertySheetTreeItem.h"
#include "EPropertytreeview.h"
#include "GObject.h"
#include "qtablewidget.h"
void toQVariant ( CXProp* prop, QVariant& var )
{
switch ( prop->getType() )
{
case eType_Bool:
{
var = * ( ( bool* ) ( ( CXPropEntity<bool>* ) prop )->mVar );
}
break;
case eType_Int:
{
var = * ( ( int* ) ( ( CXPropEntity<int>* ) prop )->mVar );
}
break;
case eType_UInt:
{
var = * ( ( unsigned int* ) ( ( CXPropEntity<unsigned int>* ) prop )->mVar );
}
break;
case eType_Float:
{
var = * ( ( float* ) ( ( CXPropEntity<float>* ) prop )->mVar );
}
break;
case eType_String:
{
var = ( ( GString* ) ( ( CXPropEntity<GString>* ) prop )->mVar )->c_str();
}
break;
case eType_Enum:
{
CXPropEnum* pEnum = ( CXPropEnum* ) prop;
var = pEnum->getTheName();
}
break;
default:
break;
}
}
EPropertySheet::~EPropertySheet()
{
clearData();
dSafeDelete ( mDelegate );
dSafeDelete ( mTreeModel );
}
EPropertySheet::EPropertySheet ( QWidget* parent/*=0*/ )
: QWidget ( parent )
, mTreeView ( 0 )
, mTreeModel ( 0 )
{
mTreeView = new EPropertyTreeView ( parent );
mTreeModel = new QStandardItemModel();
mTreeView->setModel ( mTreeModel );
//mTreeView->setGeometry(parent->childrenRect());
mTreeView->setWindowTitle ( "Simple Tree Model" );
mDelegate = new EPropertySheetDelegate;
mTreeView->setItemDelegate ( mDelegate );
mTreeView->setBaseSize ( 400, 340 );
QSizePolicy sizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
mTreeView->setSizePolicy ( sizePolicy );
mTreeView->setAcceptDrops ( true );
mTreeView->setColumnWidth ( 0, 200 );
}
void EPropertySheet::show()
{
mTreeView->show();
}
void EPropertySheet::update ( GObject* obj, bool changeHeader/*=true*/ )
{
CXASSERT_RETURN ( obj );
obj->registerAll();
clearPropertyies();
if ( changeHeader )
{
setHeader ( "Object", obj->categoryName() );
}
const CategoryPropertyMap& propMap = obj->getPropertyMap();
for ( auto pMap: propMap )
{
PropertyMap* propMap = pMap.second;
for ( auto walk: *propMap )
{
addProperty ( pMap.first.c_str(), walk.first.c_str(), walk.second );
}
}
}
QStandardItem* EPropertySheet::getCategory ( const char* name )
{
int row = mTreeModel->rowCount();
QStandardItem* item = 0;
for ( int i = 0; i < row; ++i )
{
QStandardItem* child = mTreeModel->item ( i, 0 );
if ( child )
{
if ( child->text() == name )
{
item = child;
return item;
}
}
}
return item;
}
void EPropertySheet::clearPropertyies()
{
clearData();
mTreeModel->setColumnCount ( 2 );
mTreeView->setColumnWidth ( 0, 200 );
}
void EPropertySheet::addProperty ( const char* categoryName, const char* propName, EPropertyVar* propVar )
{
QStandardItem* categoryItem = getCategory ( categoryName );
int curRow = 0;
if ( !categoryItem )
{
curRow = mTreeModel->rowCount();
mTreeModel->setRowCount ( curRow + 1 );
categoryItem = new QStandardItem ( categoryName );
mTreeModel->setItem ( curRow, 0, categoryItem );
categoryItem->setEditable ( false );
mTreeView->expand ( categoryItem->index() );
}
QList<QStandardItem*> lists;
EPropertySheetTreeItem* item = new EPropertySheetTreeItem ( propName );
item->setBackground ( QBrush ( Qt::lightGray ) );
item->setEditable ( false );
lists.push_back ( item );
item = new EPropertySheetTreeItem();
item->SetExtraData ( propVar );
QVariant var;
toQVariant ( propVar->mProp, var );
item->setData ( var, Qt::EditRole );
//item->setWhatsThis("WhatsThis");
//item->setStatusTip("StatusTip");
item->setToolTip("ToolTip");
//item->setData ( Qt::EditRole ,var);
lists.push_back ( item );
categoryItem->appendRow ( lists );
}
void EPropertySheet::clearData()
{
int row = mTreeModel->rowCount();
int col = mTreeModel->columnCount();
for ( int i = 0; i < row; ++i )
{
for ( int j = 0; j < col; ++j )
{
QStandardItem* child = mTreeModel->item ( i, j );
dSafeDelete ( child );
}
}
mTreeModel->clear();
}
void EPropertySheet::setHeader ( const char* first, const char* second )
{
mTreeModel->setHeaderData ( 0, Qt::Horizontal, first, Qt::DisplayRole );
mTreeModel->setHeaderData ( 1, Qt::Horizontal, second, Qt::DisplayRole );
}