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
viewLayout
=
layout
;
}
void
Controller
::
initTreeView
(
QTreeView
*
treeView
){
this
->
treeView
=
treeView
;
}
void
Controller
::
showSingleView
(){
viewLayout
=
new
QGridLayout
();
viewLayout
->
removeWidget
(
quadViewWidget
);
...
...
@@ -228,22 +232,28 @@ QQuaternion Controller::computeRotation(QPoint newPosition){
void
Controller
::
addSphere
(){
selectTransform
(
scene
->
addSphere
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
void
Controller
::
addBox
(){
selectTransform
(
scene
->
addBox
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
void
Controller
::
addCylinder
(){
selectTransform
(
scene
->
addCylinder
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
void
Controller
::
addCone
(){
selectTransform
(
scene
->
addCone
(
tesselation
));
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
void
Controller
::
addTorus
(){
selectTransform
(
scene
->
addTorus
(
tesselation
));
treeView
->
setSelectionMode
(
QAbstractItemView
::
SelectionMode
::
SingleSelection
);
treeView
->
setCurrentIndex
(
scene
->
getLastAddedIndex
());
}
void
Controller
::
deletePrimitive
(){
...
...
@@ -254,8 +264,15 @@ void Controller::deletePrimitive(){
void
Controller
::
selectTransform
(
RigidBodyTransformation
*
rbt
){
currentTransform
=
rbt
;
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
{
statusBar
->
showMessage
(
"None selected"
);
...
...
@@ -272,3 +289,14 @@ void Controller::itemSelected(QModelIndex q){
selectTransform
(
static_cast
<
RigidBodyTransformation
*>
(
t
));
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 @@
#include <rigidbodytransformation.h>
#include <QStatusBar>
#include <QModelIndex>
#include <QTreeView>
#include <math.h>
...
...
@@ -34,6 +35,7 @@ public:
void
initActions
(
QAction
*
cam
,
QAction
*
manipulate
);
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
void
processMousePressEvent
(
QMouseEvent
*
event
,
MyGLWidget
*
widget
);
...
...
@@ -47,7 +49,6 @@ public:
SceneGraph
*
getSceneGraph
();
RigidBodyTransformation
*
currentTransform
;
private
:
QAction
*
modeCameraAction
;
QAction
*
modeManipulateAction
;
...
...
@@ -74,10 +75,16 @@ private:
int
tesselation
;
RigidBodyTransformation
*
currentTransform
;
TreeItem
*
selectedItem
;
//might equal currentTransform. Or not.
SceneGraph
*
scene
;
void
selectTransform
(
RigidBodyTransformation
*
rbt
);
QTreeView
*
treeView
;
public
slots
:
void
switchToModeCamera
();
void
switchToModeManipulate
();
...
...
@@ -97,6 +104,8 @@ public slots:
void
deletePrimitive
();
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"?>
<!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>
<data>
<variable>
EnvironmentId
</variable>
...
...
helloqube/mainwindow.cpp
View file @
c7707b1a
...
...
@@ -256,8 +256,12 @@ MainWindow::MainWindow(QWidget *parent)
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(){
glMultMatrixf
(
m
.
data
());
//draw primitive
Primitive
*
p
=
(
*
i
)
->
getChildPrimitive
();
int
tesselation
=
p
->
getTesselation
();
Primitive
::
Type
type
=
p
->
getType
();
if
(
type
==
Primitive
::
Type
::
SPHERE
){
drawSphere
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
BOX
){
drawBox
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
CYLINDER
){
drawCylinder
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
CONE
){
drawCone
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
TORUS
){
drawTorus
(
tesselation
);
}
else
{
qDebug
()
<<
"Weird Type."
<<
type
;
for
(
int
j
=
0
;
j
<
(
*
i
)
->
getChildrenCount
();
j
++
){
qDebug
()
<<
"Draw child "
<<
j
<<
" for "
<<
(
*
i
)
->
getName
();
Primitive
*
p
=
(
*
i
)
->
getChildAsPrimitive
(
j
);
int
tesselation
=
p
->
getTesselation
();
Primitive
::
Type
type
=
p
->
getType
();
if
(
type
==
Primitive
::
Type
::
SPHERE
){
drawSphere
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
BOX
){
drawBox
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
CYLINDER
){
drawCylinder
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
CONE
){
drawCone
(
tesselation
);
}
else
if
(
type
==
Primitive
::
Type
::
TORUS
){
drawTorus
(
tesselation
);
}
else
{
qDebug
()
<<
"Weird Type."
<<
type
;
}
}
//reset transformation for next primitive
...
...
helloqube/myitemmodel.cpp
View file @
c7707b1a
...
...
@@ -92,20 +92,46 @@ TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
}
void
MyItemModel
::
addNewTransformToRoot
(
TreeItem
*
rbt
,
TreeItem
*
prim
){
beginInsertRows
(
QModelIndex
(),
0
,
0
);
QModelIndex
MyItemModel
::
addNewTransformToRoot
(
TreeItem
*
rbt
,
TreeItem
*
prim
){
int
ind
=
root
->
getChildrenCount
();
beginInsertRows
(
QModelIndex
(),
ind
,
ind
);
qDebug
()
<<
"Add child "
<<
rbt
->
data
(
0
);
root
->
addChild
(
rbt
);
root
->
addChild
(
rbt
,
ind
);
endInsertRows
();
QModelIndex
i
=
index
(
0
,
0
,
QModelIndex
());
QModelIndex
i
=
index
(
ind
,
0
,
QModelIndex
());
beginInsertRows
(
i
,
0
,
0
);
qDebug
()
<<
"Add primitive "
<<
prim
->
data
(
0
)
<<
" at "
<<
i
;
rbt
->
addChild
(
prim
);
rbt
->
addChild
(
prim
,
0
);
endInsertRows
();
return
i
;
// 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
){
int
row
=
-
1
;
for
(
int
i
=
0
;
i
<
root
->
getChildren
().
length
();
i
++
){
...
...
helloqube/myitemmodel.h
View file @
c7707b1a
...
...
@@ -22,7 +22,8 @@ public:
QModelIndex
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
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
);
TreeItem
*
getItem
(
const
QModelIndex
&
index
)
const
;
...
...
helloqube/primitive.cpp
View file @
c7707b1a
...
...
@@ -10,10 +10,6 @@ Primitive::~Primitive(){
}
QString
Primitive
::
getName
(){
return
name
;
}
Primitive
::
Primitive
(
QString
name
,
int
ID
,
int
tesselation
,
Type
t
){
this
->
name
=
name
;
this
->
ID
=
ID
;
...
...
helloqube/primitive.h
View file @
c7707b1a
...
...
@@ -19,8 +19,6 @@ public:
int
getTesselation
();
Primitive
::
Type
getType
();
QString
getName
();
QVariant
data
(
int
column
)
override
;
protected
:
...
...
helloqube/rigidbodytransformation.cpp
View file @
c7707b1a
...
...
@@ -43,10 +43,10 @@ void RigidBodyTransformation::setRotation(QQuaternion newRotation){
rotation
=
newRotation
;
}
Primitive
*
RigidBodyTransformation
::
getChild
Primitive
(
){
if
(
children
.
length
()
>
0
){
return
static_cast
<
Primitive
*>
(
children
[
0
]);
//TODO aufpassen falls höhere tiefe
Primitive
*
RigidBodyTransformation
::
getChild
AsPrimitive
(
int
row
){
if
(
row
<
children
.
length
()
){
return
static_cast
<
Primitive
*>
(
children
[
row
]);
//TODO aufpassen falls höhere tiefe
}
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:
const
QQuaternion
getRotation
();
const
QVector3D
getTranslation
();
Primitive
*
getChildPrimitive
();
void
drawChild
();
QVariant
data
(
int
column
)
override
;
Primitive
*
getChildAsPrimitive
(
int
row
);
private
:
//translation
QVector3D
translation
;
...
...
helloqube/scenegraph.cpp
View file @
c7707b1a
...
...
@@ -33,7 +33,6 @@ RigidBodyTransformation* SceneGraph::addSphere(int tesselation){
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextSphereName
,
idCounter
,
t
,
Primitive
::
Type
::
SPHERE
);
idCounter
++
;
sphereIndex
++
;
qDebug
()
<<
"New Sphere added in scenegraph."
<<
nextSphereName
;
...
...
@@ -46,7 +45,6 @@ RigidBodyTransformation* SceneGraph::addBox(int tesselation){
nextBoxName
=
"Box "
;
nextBoxName
.
append
(
QString
::
number
(
boxIndex
));
Primitive
*
p
=
new
Primitive
(
nextBoxName
,
idCounter
,
tesselation
,
Primitive
::
Type
::
BOX
);
idCounter
++
;
boxIndex
++
;
qDebug
(
"New box added in scenegraph"
);
...
...
@@ -60,7 +58,6 @@ RigidBodyTransformation* SceneGraph::addCylinder(int tesselation){
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextCylName
,
idCounter
,
t
,
Primitive
::
Type
::
CYLINDER
);
idCounter
++
;
cylIndex
++
;
qDebug
(
"added Cylinder to scenegraph"
);
return
addPrimitive
(
p
);
...
...
@@ -73,7 +70,6 @@ RigidBodyTransformation* SceneGraph::addCone(int tesselation){
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextConeName
,
idCounter
,
t
,
Primitive
::
Type
::
CONE
);
idCounter
++
;
coneIndex
++
;
return
addPrimitive
(
p
);
}
...
...
@@ -85,15 +81,18 @@ RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
int
t
=
tesselation
;
if
(
t
<
3
)
t
=
3
;
Primitive
*
p
=
new
Primitive
(
nextTorusName
,
idCounter
,
t
,
Primitive
::
Type
::
TORUS
);
idCounter
++
;
torusIndex
++
;
return
addPrimitive
(
p
);
}
RigidBodyTransformation
*
SceneGraph
::
addPrimitive
(
Primitive
*
p
){
RigidBodyTransformation
*
r
=
new
RigidBodyTransformation
();
QString
n
=
"RBT Group "
;
n
.
append
(
QString
::
number
(
idCounter
));
idCounter
++
;
r
->
setName
(
n
);
nodes
.
append
(
r
);
model
->
addNewTransformToRoot
(
r
,
p
);
lastAddedIndex
=
model
->
addNewTransformToRoot
(
r
,
p
);
qDebug
()
<<
"added primitive to root. childlength: "
<<
r
->
getChildren
().
length
();
// model->insertRows(1,1,QModelIndex());
notifyViews
();
...
...
@@ -114,6 +113,15 @@ RigidBodyTransformation* SceneGraph::deleteNode(RigidBodyTransformation *r){
else
return
0
;
}
QModelIndex
SceneGraph
::
getIndex
(
TreeItem
*
item
){
return
model
->
getIndex
(
item
);
}
QModelIndex
SceneGraph
::
getLastAddedIndex
(){
qDebug
()
<<
"last index "
<<
lastAddedIndex
;
return
lastAddedIndex
;
}
//transform something
void
SceneGraph
::
addRotation
(
RigidBodyTransformation
*
r
,
QQuaternion
diff
){
r
->
addRotation
(
diff
);
...
...
helloqube/scenegraph.h
View file @
c7707b1a
...
...
@@ -35,6 +35,8 @@ public:
MyItemModel
*
getModel
();
TreeItem
*
getItem
(
QModelIndex
q
);
QModelIndex
getIndex
(
TreeItem
*
item
);
QModelIndex
getLastAddedIndex
();
//Index of last added tree item
//Hallo. Todos:
//Log selected name in status bar
...
...
@@ -64,6 +66,8 @@ private:
MyItemModel
*
model
;
QModelIndex
lastAddedIndex
;
};
...
...
helloqube/treeitem.cpp
View file @
c7707b1a
...
...
@@ -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
){
this
->
parent
=
parent
;
}
...
...
@@ -26,9 +35,13 @@ int TreeItem::getChildrenCount(){
return
children
.
length
();
}
//adds to child list AND sets itself as parent.
void
TreeItem
::
addChild
(
TreeItem
*
item
){
children
.
append
(
item
);
//adds to child list before [index] AND sets itself as parent.
void
TreeItem
::
addChild
(
TreeItem
*
item
,
int
index
){
if
(
index
>=
children
.
length
()){
children
.
append
(
item
);
}
else
{
children
.
insert
(
index
,
item
);
}
item
->
setParent
(
this
);
}
...
...
helloqube/treeitem.h
View file @
c7707b1a
...
...
@@ -18,10 +18,13 @@ public:
virtual
QVariant
data
(
int
column
);
//returns QVariant for name string
void
addChild
(
TreeItem
*
item
);
void
addChild
(
TreeItem
*
item
,
int
row
);
bool
removeChild
(
TreeItem
*
item
);
void
setParent
(
TreeItem
*
parent
);
void
setName
(
QString
newName
);
QString
getName
();
int
childNumber
();
protected
:
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