Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
grapa_alisa
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Alisa Jung
grapa_alisa
Commits
c7707b1a
Commit
c7707b1a
authored
Nov 23, 2015
by
Alisa Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
consistency between selection in scene graph and automatically selecting…
consistency between selection in scene graph and automatically selecting primitives after adding/deleting
parent
1ad003b8
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
140 additions
and
48 deletions
+140
-48
controller.cpp
helloqube/controller.cpp
+29
-1
controller.h
helloqube/controller.h
+10
-1
helloqube.pro.user
helloqube/helloqube.pro.user
+1
-1
mainwindow.cpp
helloqube/mainwindow.cpp
+5
-1
myglwidget.cpp
helloqube/myglwidget.cpp
+18
-15
myitemmodel.cpp
helloqube/myitemmodel.cpp
+31
-5
myitemmodel.h
helloqube/myitemmodel.h
+2
-1
primitive.cpp
helloqube/primitive.cpp
+0
-4
primitive.h
helloqube/primitive.h
+0
-2
rigidbodytransformation.cpp
helloqube/rigidbodytransformation.cpp
+4
-4
rigidbodytransformation.h
helloqube/rigidbodytransformation.h
+2
-3
scenegraph.cpp
helloqube/scenegraph.cpp
+14
-6
scenegraph.h
helloqube/scenegraph.h
+4
-0
treeitem.cpp
helloqube/treeitem.cpp
+16
-3
treeitem.h
helloqube/treeitem.h
+4
-1
No files found.
helloqube/controller.cpp
View file @
c7707b1a
...
@@ -36,6 +36,10 @@ void Controller::initViewWidgets(MyGLWidget *allViews[4], QWidget *two, QWidget
...
@@ -36,6 +36,10 @@ void Controller::initViewWidgets(MyGLWidget *allViews[4], QWidget *two, QWidget
viewLayout
=
layout
;
viewLayout
=
layout
;
}
}
void
Controller
::
initTreeView
(
QTreeView
*
treeView
){
this
->
treeView
=
treeView
;
}
void
Controller
::
showSingleView
(){
void
Controller
::
showSingleView
(){
viewLayout
=
new
QGridLayout
();
viewLayout
=
new
QGridLayout
();
viewLayout
->
removeWidget
(
quadViewWidget
);
viewLayout
->
removeWidget
(
quadViewWidget
);
...
@@ -228,22 +232,28 @@ QQuaternion Controller::computeRotation(QPoint newPosition){
...
@@ -228,22 +232,28 @@ QQuaternion Controller::computeRotation(QPoint newPosition){
void
Controller
::
addSphere
(){
void
Controller
::
addSphere
(){
selectTransform
(
scene
->
addSphere
(
tesselation
));
selectTransform
(
scene
->
addSphere
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
}
void
Controller
::
addBox
(){
void
Controller
::
addBox
(){
selectTransform
(
scene
->
addBox
(
tesselation
));
selectTransform
(
scene
->
addBox
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
}
void
Controller
::
addCylinder
(){
void
Controller
::
addCylinder
(){
selectTransform
(
scene
->
addCylinder
(
tesselation
));
selectTransform
(
scene
->
addCylinder
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
}
void
Controller
::
addCone
(){
void
Controller
::
addCone
(){
selectTransform
(
scene
->
addCone
(
tesselation
));
selectTransform
(
scene
->
addCone
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
}
void
Controller
::
addTorus
(){
void
Controller
::
addTorus
(){
selectTransform
(
scene
->
addTorus
(
tesselation
));
selectTransform
(
scene
->
addTorus
(
tesselation
));
treeView
->
setSelectionMode
(
QAbstractItemView
::
SelectionMode
::
SingleSelection
);
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
}
void
Controller
::
deletePrimitive
(){
void
Controller
::
deletePrimitive
(){
...
@@ -254,8 +264,15 @@ void Controller::deletePrimitive(){
...
@@ -254,8 +264,15 @@ void Controller::deletePrimitive(){
void
Controller
::
selectTransform
(
RigidBodyTransformation
*
rbt
){
void
Controller
::
selectTransform
(
RigidBodyTransformation
*
rbt
){
currentTransform
=
rbt
;
currentTransform
=
rbt
;
if
(
currentTransform
){
if
(
currentTransform
){
statusBar
->
showMessage
(
currentTransform
->
getChildPrimitive
()
->
getName
());
if
(
currentTransform
->
getChildrenCount
()
>
1
){
QString
n
=
"Group selected: "
;
n
.
append
(
currentTransform
->
getName
());
statusBar
->
showMessage
(
n
);
}
else
{
statusBar
->
showMessage
(
currentTransform
->
getChild
(
0
)
->
getName
());
}
}
}
else
{
else
{
statusBar
->
showMessage
(
"None selected"
);
statusBar
->
showMessage
(
"None selected"
);
...
@@ -272,3 +289,14 @@ void Controller::itemSelected(QModelIndex q){
...
@@ -272,3 +289,14 @@ void Controller::itemSelected(QModelIndex q){
selectTransform
(
static_cast
<
RigidBodyTransformation
*>
(
t
));
selectTransform
(
static_cast
<
RigidBodyTransformation
*>
(
t
));
qDebug
()
<<
"selected name "
<<
t
->
data
(
0
);
qDebug
()
<<
"selected name "
<<
t
->
data
(
0
);
}
}
void
Controller
::
itemDoubleClicked
(
QModelIndex
q
){
qDebug
()
<<
"item Double clicked. Row: "
<<
q
.
row
()
<<
", column: "
<<
q
.
column
();
selectedItem
=
scene
->
getItem
(
q
);
}
void
Controller
::
changeItemName
(
QString
q
){
//TODO this is not working.
qDebug
()
<<
"Name entered: "
<<
q
;
selectedItem
->
setName
(
q
);
}
helloqube/controller.h
View file @
c7707b1a
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include <rigidbodytransformation.h>
#include <rigidbodytransformation.h>
#include <QStatusBar>
#include <QStatusBar>
#include <QModelIndex>
#include <QModelIndex>
#include <QTreeView>
#include <math.h>
#include <math.h>
...
@@ -34,6 +35,7 @@ public:
...
@@ -34,6 +35,7 @@ public:
void
initActions
(
QAction
*
cam
,
QAction
*
manipulate
);
void
initActions
(
QAction
*
cam
,
QAction
*
manipulate
);
void
initViewWidgets
(
MyGLWidget
*
views
[
4
],
QWidget
*
doubleViews
,
QWidget
*
quadViews
,
QGridLayout
*
layout
);
void
initViewWidgets
(
MyGLWidget
*
views
[
4
],
QWidget
*
doubleViews
,
QWidget
*
quadViews
,
QGridLayout
*
layout
);
void
initTreeView
(
QTreeView
*
treeView
);
//processes input and might call follow up functions in widget
//processes input and might call follow up functions in widget
void
processMousePressEvent
(
QMouseEvent
*
event
,
MyGLWidget
*
widget
);
void
processMousePressEvent
(
QMouseEvent
*
event
,
MyGLWidget
*
widget
);
...
@@ -47,7 +49,6 @@ public:
...
@@ -47,7 +49,6 @@ public:
SceneGraph
*
getSceneGraph
();
SceneGraph
*
getSceneGraph
();
RigidBodyTransformation
*
currentTransform
;
private
:
private
:
QAction
*
modeCameraAction
;
QAction
*
modeCameraAction
;
QAction
*
modeManipulateAction
;
QAction
*
modeManipulateAction
;
...
@@ -74,10 +75,16 @@ private:
...
@@ -74,10 +75,16 @@ private:
int
tesselation
;
int
tesselation
;
RigidBodyTransformation
*
currentTransform
;
TreeItem
*
selectedItem
;
//might equal currentTransform. Or not.
SceneGraph
*
scene
;
SceneGraph
*
scene
;
void
selectTransform
(
RigidBodyTransformation
*
rbt
);
void
selectTransform
(
RigidBodyTransformation
*
rbt
);
QTreeView
*
treeView
;
public
slots
:
public
slots
:
void
switchToModeCamera
();
void
switchToModeCamera
();
void
switchToModeManipulate
();
void
switchToModeManipulate
();
...
@@ -97,6 +104,8 @@ public slots:
...
@@ -97,6 +104,8 @@ public slots:
void
deletePrimitive
();
void
deletePrimitive
();
void
itemSelected
(
QModelIndex
q
);
void
itemSelected
(
QModelIndex
q
);
void
itemDoubleClicked
(
QModelIndex
q
);
void
changeItemName
(
QString
q
);
};
};
...
...
helloqube/helloqube.pro.user
View file @
c7707b1a
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-2
2T14:19:27
. -->
<!-- Written by QtCreator 3.5.1, 2015-11-2
3T01:20:22
. -->
<qtcreator>
<qtcreator>
<data>
<data>
<variable>
EnvironmentId
</variable>
<variable>
EnvironmentId
</variable>
...
...
helloqube/mainwindow.cpp
View file @
c7707b1a
...
@@ -256,8 +256,12 @@ MainWindow::MainWindow(QWidget *parent)
...
@@ -256,8 +256,12 @@ MainWindow::MainWindow(QWidget *parent)
connect
(
treeView
,
SIGNAL
(
clicked
(
QModelIndex
)),
controller
,
SLOT
(
itemSelected
(
QModelIndex
)));
connect
(
treeView
,
SIGNAL
(
clicked
(
QModelIndex
)),
controller
,
SLOT
(
itemSelected
(
QModelIndex
)));
connect
(
treeView
,
SIGNAL
(
doubleClicked
(
QModelIndex
)),
controller
,
SLOT
(
itemDoubleClicked
(
QModelIndex
)));
connect
(
treeView
,
SIGNAL
(
objectNameChanged
(
QString
)),
controller
,
SLOT
(
changeItemName
(
QString
)));
}
controller
->
initTreeView
(
treeView
);
}
...
...
helloqube/myglwidget.cpp
View file @
c7707b1a
...
@@ -170,21 +170,24 @@ void MyGLWidget::paintGL(){
...
@@ -170,21 +170,24 @@ void MyGLWidget::paintGL(){
glMultMatrixf
(
m
.
data
());
glMultMatrixf
(
m
.
data
());
//draw primitive
//draw primitive
Primitive
*
p
=
(
*
i
)
->
getChildPrimitive
();
for
(
int
j
=
0
;
j
<
(
*
i
)
->
getChildrenCount
();
j
++
){
int
tesselation
=
p
->
getTesselation
();
qDebug
()
<<
"Draw child "
<<
j
<<
" for "
<<
(
*
i
)
->
getName
();
Primitive
::
Type
type
=
p
->
getType
();
Primitive
*
p
=
(
*
i
)
->
getChildAsPrimitive
(
j
);
if
(
type
==
Primitive
::
Type
::
SPHERE
){
int
tesselation
=
p
->
getTesselation
();
drawSphere
(
tesselation
);
Primitive
::
Type
type
=
p
->
getType
();
}
else
if
(
type
==
Primitive
::
Type
::
BOX
){
if
(
type
==
Primitive
::
Type
::
SPHERE
){
drawBox
(
tesselation
);
drawSphere
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
CYLINDER
){
}
else
if
(
type
==
Primitive
::
Type
::
BOX
){
drawCylinder
(
tesselation
);
drawBox
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
CONE
){
}
else
if
(
type
==
Primitive
::
Type
::
CYLINDER
){
drawCone
(
tesselation
);
drawCylinder
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
TORUS
){
}
else
if
(
type
==
Primitive
::
Type
::
CONE
){
drawTorus
(
tesselation
);
drawCone
(
tesselation
);
}
else
{
}
else
if
(
type
==
Primitive
::
Type
::
TORUS
){
qDebug
()
<<
"Weird Type."
<<
type
;
drawTorus
(
tesselation
);
}
else
{
qDebug
()
<<
"Weird Type."
<<
type
;
}
}
}
//reset transformation for next primitive
//reset transformation for next primitive
...
...
helloqube/myitemmodel.cpp
View file @
c7707b1a
...
@@ -92,20 +92,46 @@ TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
...
@@ -92,20 +92,46 @@ TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
}
}
void
MyItemModel
::
addNewTransformToRoot
(
TreeItem
*
rbt
,
TreeItem
*
prim
){
QModelIndex
MyItemModel
::
addNewTransformToRoot
(
TreeItem
*
rbt
,
TreeItem
*
prim
){
beginInsertRows
(
QModelIndex
(),
0
,
0
);
int
ind
=
root
->
getChildrenCount
();
beginInsertRows
(
QModelIndex
(),
ind
,
ind
);
qDebug
()
<<
"Add child "
<<
rbt
->
data
(
0
);
qDebug
()
<<
"Add child "
<<
rbt
->
data
(
0
);
root
->
addChild
(
rbt
);
root
->
addChild
(
rbt
,
ind
);
endInsertRows
();
endInsertRows
();
QModelIndex
i
=
index
(
0
,
0
,
QModelIndex
());
QModelIndex
i
=
index
(
ind
,
0
,
QModelIndex
());
beginInsertRows
(
i
,
0
,
0
);
beginInsertRows
(
i
,
0
,
0
);
qDebug
()
<<
"Add primitive "
<<
prim
->
data
(
0
)
<<
" at "
<<
i
;
qDebug
()
<<
"Add primitive "
<<
prim
->
data
(
0
)
<<
" at "
<<
i
;
rbt
->
addChild
(
prim
);
rbt
->
addChild
(
prim
,
0
);
endInsertRows
();
endInsertRows
();
return
i
;
// return true;
// return true;
}
}
QModelIndex
MyItemModel
::
getIndex
(
TreeItem
*
item
){
if
(
item
==
root
){
return
QModelIndex
();
}
else
{
for
(
int
i
=
0
;
i
<
root
->
getChildrenCount
();
i
++
){
TreeItem
*
c
=
root
->
getChild
(
i
);
QModelIndex
p
=
index
(
i
,
0
,
QModelIndex
());
if
(
c
==
item
){
return
p
;
}
else
{
//Hartgecoded auf tiefe 2.
for
(
int
j
=
0
;
j
<
c
->
getChildrenCount
();
j
++
){
TreeItem
*
d
=
c
->
getChild
(
j
);
if
(
d
==
item
){
return
index
(
j
,
0
,
p
);
}
}
}
}
}
qDebug
()
<<
"Could not find "
<<
item
->
getName
();
return
QModelIndex
();
}
void
MyItemModel
::
removeTransformFromRoot
(
TreeItem
*
rbt
){
void
MyItemModel
::
removeTransformFromRoot
(
TreeItem
*
rbt
){
int
row
=
-
1
;
int
row
=
-
1
;
for
(
int
i
=
0
;
i
<
root
->
getChildren
().
length
();
i
++
){
for
(
int
i
=
0
;
i
<
root
->
getChildren
().
length
();
i
++
){
...
...
helloqube/myitemmodel.h
View file @
c7707b1a
...
@@ -22,7 +22,8 @@ public:
...
@@ -22,7 +22,8 @@ public:
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
Q_DECL_OVERRIDE
;
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
Q_DECL_OVERRIDE
;
QModelIndex
parent
(
const
QModelIndex
&
index
)
const
Q_DECL_OVERRIDE
;
QModelIndex
parent
(
const
QModelIndex
&
index
)
const
Q_DECL_OVERRIDE
;
void
addNewTransformToRoot
(
TreeItem
*
rbt
,
TreeItem
*
prim
);
QModelIndex
addNewTransformToRoot
(
TreeItem
*
rbt
,
TreeItem
*
prim
);
QModelIndex
getIndex
(
TreeItem
*
item
);
void
removeTransformFromRoot
(
TreeItem
*
rbt
);
void
removeTransformFromRoot
(
TreeItem
*
rbt
);
TreeItem
*
getItem
(
const
QModelIndex
&
index
)
const
;
TreeItem
*
getItem
(
const
QModelIndex
&
index
)
const
;
...
...
helloqube/primitive.cpp
View file @
c7707b1a
...
@@ -10,10 +10,6 @@ Primitive::~Primitive(){
...
@@ -10,10 +10,6 @@ Primitive::~Primitive(){
}
}
QString
Primitive
::
getName
(){
return
name
;
}
Primitive
::
Primitive
(
QString
name
,
int
ID
,
int
tesselation
,
Type
t
){
Primitive
::
Primitive
(
QString
name
,
int
ID
,
int
tesselation
,
Type
t
){
this
->
name
=
name
;
this
->
name
=
name
;
this
->
ID
=
ID
;
this
->
ID
=
ID
;
...
...
helloqube/primitive.h
View file @
c7707b1a
...
@@ -19,8 +19,6 @@ public:
...
@@ -19,8 +19,6 @@ public:
int
getTesselation
();
int
getTesselation
();
Primitive
::
Type
getType
();
Primitive
::
Type
getType
();
QString
getName
();
QVariant
data
(
int
column
)
override
;
QVariant
data
(
int
column
)
override
;
protected
:
protected
:
...
...
helloqube/rigidbodytransformation.cpp
View file @
c7707b1a
...
@@ -43,10 +43,10 @@ void RigidBodyTransformation::setRotation(QQuaternion newRotation){
...
@@ -43,10 +43,10 @@ void RigidBodyTransformation::setRotation(QQuaternion newRotation){
rotation
=
newRotation
;
rotation
=
newRotation
;
}
}
Primitive
*
RigidBodyTransformation
::
getChild
Primitive
(
){
Primitive
*
RigidBodyTransformation
::
getChild
AsPrimitive
(
int
row
){
if
(
children
.
length
()
>
0
){
if
(
row
<
children
.
length
()
){
return
static_cast
<
Primitive
*>
(
children
[
0
]);
//TODO aufpassen falls höhere tiefe
return
static_cast
<
Primitive
*>
(
children
[
row
]);
//TODO aufpassen falls höhere tiefe
}
else
{
}
else
{
qDebug
(
"WAAAH - RBT has no chilren."
)
;
qDebug
(
)
<<
"WAAAH - RBT has not enough chilren for row "
<<
row
;
}
}
}
}
helloqube/rigidbodytransformation.h
View file @
c7707b1a
...
@@ -18,12 +18,11 @@ public:
...
@@ -18,12 +18,11 @@ public:
const
QQuaternion
getRotation
();
const
QQuaternion
getRotation
();
const
QVector3D
getTranslation
();
const
QVector3D
getTranslation
();
Primitive
*
getChildPrimitive
();
void
drawChild
();
QVariant
data
(
int
column
)
override
;
QVariant
data
(
int
column
)
override
;
Primitive
*
getChildAsPrimitive
(
int
row
);
private
:
private
:
//translation
//translation
QVector3D
translation
;
QVector3D
translation
;
...
...
helloqube/scenegraph.cpp
View file @
c7707b1a
...
@@ -33,7 +33,6 @@ RigidBodyTransformation* SceneGraph::addSphere(int tesselation){
...
@@ -33,7 +33,6 @@ RigidBodyTransformation* SceneGraph::addSphere(int tesselation){
int
t
=
tesselation
;
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextSphereName
,
idCounter
,
t
,
Primitive
::
Type
::
SPHERE
);
Primitive
*
p
=
new
Primitive
(
nextSphereName
,
idCounter
,
t
,
Primitive
::
Type
::
SPHERE
);
idCounter
++
;
sphereIndex
++
;
sphereIndex
++
;
qDebug
()
<<
"New Sphere added in scenegraph."
<<
nextSphereName
;
qDebug
()
<<
"New Sphere added in scenegraph."
<<
nextSphereName
;
...
@@ -46,7 +45,6 @@ RigidBodyTransformation* SceneGraph::addBox(int tesselation){
...
@@ -46,7 +45,6 @@ RigidBodyTransformation* SceneGraph::addBox(int tesselation){
nextBoxName
=
"Box "
;
nextBoxName
=
"Box "
;
nextBoxName
.
append
(
QString
::
number
(
boxIndex
));
nextBoxName
.
append
(
QString
::
number
(
boxIndex
));
Primitive
*
p
=
new
Primitive
(
nextBoxName
,
idCounter
,
tesselation
,
Primitive
::
Type
::
BOX
);
Primitive
*
p
=
new
Primitive
(
nextBoxName
,
idCounter
,
tesselation
,
Primitive
::
Type
::
BOX
);
idCounter
++
;
boxIndex
++
;
boxIndex
++
;
qDebug
(
"New box added in scenegraph"
);
qDebug
(
"New box added in scenegraph"
);
...
@@ -60,7 +58,6 @@ RigidBodyTransformation* SceneGraph::addCylinder(int tesselation){
...
@@ -60,7 +58,6 @@ RigidBodyTransformation* SceneGraph::addCylinder(int tesselation){
int
t
=
tesselation
;
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextCylName
,
idCounter
,
t
,
Primitive
::
Type
::
CYLINDER
);
Primitive
*
p
=
new
Primitive
(
nextCylName
,
idCounter
,
t
,
Primitive
::
Type
::
CYLINDER
);
idCounter
++
;
cylIndex
++
;
cylIndex
++
;
qDebug
(
"added Cylinder to scenegraph"
);
qDebug
(
"added Cylinder to scenegraph"
);
return
addPrimitive
(
p
);
return
addPrimitive
(
p
);
...
@@ -73,7 +70,6 @@ RigidBodyTransformation* SceneGraph::addCone(int tesselation){
...
@@ -73,7 +70,6 @@ RigidBodyTransformation* SceneGraph::addCone(int tesselation){
int
t
=
tesselation
;
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextConeName
,
idCounter
,
t
,
Primitive
::
Type
::
CONE
);
Primitive
*
p
=
new
Primitive
(
nextConeName
,
idCounter
,
t
,
Primitive
::
Type
::
CONE
);
idCounter
++
;
coneIndex
++
;
coneIndex
++
;
return
addPrimitive
(
p
);
return
addPrimitive
(
p
);
}
}
...
@@ -85,15 +81,18 @@ RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
...
@@ -85,15 +81,18 @@ RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
int
t
=
tesselation
;
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextTorusName
,
idCounter
,
t
,
Primitive
::
Type
::
TORUS
);
Primitive
*
p
=
new
Primitive
(
nextTorusName
,
idCounter
,
t
,
Primitive
::
Type
::
TORUS
);
idCounter
++
;
torusIndex
++
;
torusIndex
++
;
return
addPrimitive
(
p
);
return
addPrimitive
(
p
);
}
}
RigidBodyTransformation
*
SceneGraph
::
addPrimitive
(
Primitive
*
p
){
RigidBodyTransformation
*
SceneGraph
::
addPrimitive
(
Primitive
*
p
){
RigidBodyTransformation
*
r
=
new
RigidBodyTransformation
();
RigidBodyTransformation
*
r
=
new
RigidBodyTransformation
();
QString
n
=
"RBT Group "
;
n
.
append
(
QString
::
number
(
idCounter
));
idCounter
++
;
r
->
setName
(
n
);
nodes
.
append
(
r
);
nodes
.
append
(
r
);
model
->
addNewTransformToRoot
(
r
,
p
);
lastAddedIndex
=
model
->
addNewTransformToRoot
(
r
,
p
);
qDebug
()
<<
"added primitive to root. childlength: "
<<
r
->
getChildren
().
length
();
qDebug
()
<<
"added primitive to root. childlength: "
<<
r
->
getChildren
().
length
();
// model->insertRows(1,1,QModelIndex());
// model->insertRows(1,1,QModelIndex());
notifyViews
();
notifyViews
();
...
@@ -114,6 +113,15 @@ RigidBodyTransformation* SceneGraph::deleteNode(RigidBodyTransformation *r){
...
@@ -114,6 +113,15 @@ RigidBodyTransformation* SceneGraph::deleteNode(RigidBodyTransformation *r){
else
return
0
;
else
return
0
;
}
}
QModelIndex
SceneGraph
::
getIndex
(
TreeItem
*
item
){
return
model
->
getIndex
(
item
);
}
QModelIndex
SceneGraph
::
getLastAddedIndex
(){
qDebug
()
<<
"last index "
<<
lastAddedIndex
;
return
lastAddedIndex
;
}
//transform something
//transform something
void
SceneGraph
::
addRotation
(
RigidBodyTransformation
*
r
,
QQuaternion
diff
){
void
SceneGraph
::
addRotation
(
RigidBodyTransformation
*
r
,
QQuaternion
diff
){
r
->
addRotation
(
diff
);
r
->
addRotation
(
diff
);
...
...
helloqube/scenegraph.h
View file @
c7707b1a
...
@@ -35,6 +35,8 @@ public:
...
@@ -35,6 +35,8 @@ public:
MyItemModel
*
getModel
();
MyItemModel
*
getModel
();
TreeItem
*
getItem
(
QModelIndex
q
);
TreeItem
*
getItem
(
QModelIndex
q
);
QModelIndex
getIndex
(
TreeItem
*
item
);
QModelIndex
getLastAddedIndex
();
//Index of last added tree item
//Hallo. Todos:
//Hallo. Todos:
//Log selected name in status bar
//Log selected name in status bar
...
@@ -64,6 +66,8 @@ private:
...
@@ -64,6 +66,8 @@ private:
MyItemModel
*
model
;
MyItemModel
*
model
;
QModelIndex
lastAddedIndex
;
};
};
...
...
helloqube/treeitem.cpp
View file @
c7707b1a
...
@@ -14,6 +14,15 @@ TreeItem::~TreeItem(){
...
@@ -14,6 +14,15 @@ TreeItem::~TreeItem(){
}
}
}
}
void
TreeItem
::
setName
(
QString
newName
){
name
=
newName
;
qDebug
()
<<
"Name set to "
<<
name
;
}
QString
TreeItem
::
getName
(){
return
name
;
}
void
TreeItem
::
setParent
(
TreeItem
*
parent
){
void
TreeItem
::
setParent
(
TreeItem
*
parent
){
this
->
parent
=
parent
;
this
->
parent
=
parent
;
}
}
...
@@ -26,9 +35,13 @@ int TreeItem::getChildrenCount(){
...
@@ -26,9 +35,13 @@ int TreeItem::getChildrenCount(){
return
children
.
length
();
return
children
.
length
();
}
}
//adds to child list AND sets itself as parent.
//adds to child list before [index] AND sets itself as parent.
void
TreeItem
::
addChild
(
TreeItem
*
item
){
void
TreeItem
::
addChild
(
TreeItem
*
item
,
int
index
){
children
.
append
(
item
);
if
(
index
>=
children
.
length
()){
children
.
append
(
item
);
}
else
{
children
.
insert
(
index
,
item
);
}
item
->
setParent
(
this
);
item
->
setParent
(
this
);
}
}
...
...
helloqube/treeitem.h
View file @
c7707b1a
...
@@ -18,10 +18,13 @@ public:
...
@@ -18,10 +18,13 @@ public:
virtual
QVariant
data
(
int
column
);
//returns QVariant for name string
virtual
QVariant
data
(
int
column
);
//returns QVariant for name string
void
addChild
(
TreeItem
*
item
);
void
addChild
(
TreeItem
*
item
,
int
row
);
bool
removeChild
(
TreeItem
*
item
);
bool
removeChild
(
TreeItem
*
item
);
void
setParent
(
TreeItem
*
parent
);
void
setParent
(
TreeItem
*
parent
);
void
setName
(
QString
newName
);
QString
getName
();
int
childNumber
();
int
childNumber
();
protected
:
protected
:
TreeItem
*
parent
;
TreeItem
*
parent
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment