-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTreeItem.cpp
executable file
·242 lines (197 loc) · 5.68 KB
/
TreeItem.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/****************************************************************************
** Part of this file was copied from the Qt4 examples, and so is still ...
** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved.
**
treeitem.cpp
A container for items of data supplied by the simple tree model.
*/
#include <QStringList>
#include "TreeItem.h"
#include "GeometryScene.h"
#include "tagFileItem.h"
//! [0]
TreeItem::TreeItem(const QVector<QVariant> &data,
ResourceForm *rf, TreeItem *parent) : QObject()
{
form = rf;
parentItem = parent;
itemData = data;
haveProps = false;
formInstantiated = false;
currentTagSize=0.05; //initialize tag size to defult of SpinBox in Widget
currTagR= 0.0 ; currTagG= 255.0; currTagB= 255.0;
}
//! [0]
//! [1]
TreeItem::~TreeItem()
{
qDeleteAll(childItems);
}
//! [1]
//! [2]
TreeItem *TreeItem::child(int number)
{
return childItems.value(number);
}
//! [2]
//! [3]
int TreeItem::childCount() const
{
return childItems.count();
}
//! [3]
//! [4]
int TreeItem::childNumber() const
{
if (parentItem)
return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
return 0;
}
//! [4]
//! [5]
int TreeItem::columnCount() const
{
return itemData.count();
}
//! [5]
//! [6]
QVariant TreeItem::data(int column) const
{
return itemData.value(column);
}
//! [6]
//! [7]
bool TreeItem::insertChildren(int position, int count, int columns)
{
if (position < 0 || position > childItems.size())
return false;
for (int row = 0; row < count; ++row) {
QVector<QVariant> data(columns);
TreeItem *item = new TreeItem(data, form, this);
childItems.insert(position, item);
}
return true;
}
//! [7]
//! [8]
bool TreeItem::insertColumns(int position, int columns)
{
if (position < 0 || position > itemData.size())
return false;
for (int column = 0; column < columns; ++column)
itemData.insert(position, QVariant());
foreach (TreeItem *child, childItems)
child->insertColumns(position, columns);
return true;
}
//! [8]
//! [9]
TreeItem *TreeItem::parent()
{
return parentItem;
}
//! [9]
//! [10]
bool TreeItem::removeChildren(int position, int count)
{
if (position < 0 || position + count > childItems.size())
return false;
for (int row = 0; row < count; ++row)
delete childItems.takeAt(position);
return true;
}
//! [10]
bool TreeItem::removeColumns(int position, int columns)
{
if (position < 0 || position + columns > itemData.size())
return false;
for (int column = 0; column < columns; ++column)
itemData.remove(position);
foreach (TreeItem *child, childItems)
child->removeColumns(position, columns);
return true;
}
void TreeItem::setViewer(BrainQuarter *quarterViewer) {
viewer = quarterViewer;
}
//! [11]
bool TreeItem::setData(int column, const QVariant &value)
{
if (column < 0 || column >= itemData.size())
return false;
itemData[column] = value;
return true;
}
//! [11]
bool TreeItem::insertGeometry(QFile &file) {
QVector<QVariant> data(columnCount());
GeometryScene *item = new GeometryScene(data, form, this);
item->setViewer(viewer);
childItems.insert(childCount(), item);
// item->loadGeometry(file, data, form, this,cylinder_flag,dbfile);
item->loadGeometry(file, data, form, this);
// return item;
return true;
}
// GeometryScene * TreeItem::insertGeometry(QFile &file) {
// QVector<QVariant> data(columnCount());
// GeometryScene *item = new GeometryScene(data, form, this);
// item->setViewer(viewer);
// childItems.insert(childCount(), item);
// QFile nullfile;
// item->loadGeometry(file, data, form, this,false,nullfile);
//
// return item;
//
// }
bool TreeItem::insertTags(QFile &file) {
QVector<QVariant> data(columnCount());
tagFileItem *item = new tagFileItem(viewer->getRootSeparator(),
data, form, this);
childItems.insert(childCount(), item);
item->loadFile(file,currentTagSize,currTagR,currTagG,currTagB);
}
bool TreeItem::createTag(float *tagpoint){
QVector<QVariant> data(columnCount());
tagFileItem *item = new tagFileItem(viewer->getRootSeparator(),
data, form, this);
childItems.insert(childCount(), item);
//qDebug()<<"current tag size : " << currentTagSize ;
item->showTag(tagpoint,currentTagSize,currTagR,currTagG,currTagB);
}
void TreeItem::updateTagSize(double newsize){
QVector<QVariant> data(columnCount());
tagFileItem *item = new tagFileItem(viewer->getRootSeparator(),
data, form, this);
// qDebug() << "viewer root number of children: " << viewer->getRootSeparator()->getNumChildren() ;
// childItems.insert(childCount(), item);
// item->updateSize(newsize,currentTagSize);
currentTagSize= newsize; //update the tagsize for next tags
}
void TreeItem::TagcolourDialog(){
QColor tagcolour = QColorDialog::getColor();
if (tagcolour.isValid()) {
//form->uitag.TagColour->setText(tagcolour.name());
form->uitag.TagColour->setPalette(QPalette(tagcolour));
form->uitag.TagColour->setAutoFillBackground(true);
int tr,tg,tb;
tagcolour.getRgb(&tr,&tg,&tb);
currTagR = float(tr); currTagG = float(tg); currTagB = float(tb);
}
}
bool TreeItem::insertCone() {
SoSeparator *root = viewer->getRootSeparator();
SoBaseColor *col = new SoBaseColor;
col->rgb = SbColor(1, 1, 0);
root->addChild(col);
root->addChild(new SoCone);
viewer->viewAll();
insertChildren(childCount(), 1, columnCount());
child(childCount() - 1)->setData(0, "Cone");
}
QWidget* TreeItem::createForm() {
}
void TreeItem::destroyForm() {
}
bool TreeItem::createRootSeparator() {
}