Commit ab86fe42 by Alisa Jung

somehow working tree display?!

parent bcc14a79
......@@ -244,10 +244,16 @@ MainWindow::MainWindow(QWidget *parent)
deletePrimitive->setShortcut(QKeySequence(Qt::Key_Delete));
dockWidget = new QDockWidget(tr("Scenegraph"),this);
dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
treeView = new QTreeView(this);
treeView->setModel(controller->getSceneGraph()->getModel());
treeView->expandAll();
dockWidget->setWidget(treeView);
addDockWidget(Qt::RightDockWidgetArea, dockWidget);
}
......
......@@ -19,6 +19,7 @@
#include <QTreeView>
#include <scenegraph.h>
#include <myitemmodel.h>
#include <QDockWidget>
class MainWindow : public QMainWindow
{
Q_OBJECT
......@@ -89,6 +90,7 @@ private:
QAction* deletePrimitive;
QDockWidget* dockWidget;
QTreeView* treeView;
public slots :
......
......@@ -31,6 +31,7 @@ QVariant MyItemModel::data(const QModelIndex &index, int role) const{
return item->data(index.column());
}
QVariant MyItemModel::headerData(int section, Qt::Orientation orientation, int role) const{
//Im tutorial stand mehr. erstmal ignorieren.
return root->data(section);
......@@ -89,3 +90,39 @@ TreeItem* MyItemModel::getItem(const QModelIndex& index) const{
}
return root;
}
bool MyItemModel::insertRows(int position, int rows, const QModelIndex &parent)
{
beginInsertRows(QModelIndex(), position, position+rows-1);
TreeItem* p = getItem(parent);
for (int row = 0; row < rows; ++row) {
qDebug("Add Child to item");
p->addChild(new TreeItem());
}
endInsertRows();
return true;
}
void MyItemModel::addChildToRoot(TreeItem *rbt, TreeItem* prim){
beginInsertRows(QModelIndex(), 0, 0);
qDebug() << "Add child " << rbt->data(0);
root->addChild(rbt);
endInsertRows();
QModelIndex i = index(0,0,QModelIndex());
beginInsertRows(i,0,0);
qDebug() << "Add primitive " << prim->data(0) << " at " << i;
rbt->addChild(prim);
endInsertRows();
// return true;
}
......@@ -22,6 +22,10 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
void addChildToRoot(TreeItem* rbt, TreeItem* prim);
bool insertRows(int row, int count, const QModelIndex &parent);
private:
TreeItem* root;
......
......@@ -14,9 +14,9 @@ QString Primitive::getName(){
return name;
}
Primitive::Primitive(int ID, QString name, int tesselation, Type t){
this->ID = ID;
Primitive::Primitive(QString name, int ID, int tesselation, Type t){
this->name = name;
this->ID = ID;
this->tesselation = tesselation;
this->type = t;
}
......@@ -28,3 +28,11 @@ int Primitive::getTesselation(){
Primitive::Type Primitive::getType(){
return type;
}
QVariant Primitive::data(int column){
if (column == 0) return QVariant(name);
else if (column == 1) return QVariant(ID);
else if (column == 2) return QVariant(tesselation);
else if (column == 4) return QVariant(type);
else return QVariant();
}
......@@ -14,13 +14,15 @@ public:
Primitive();
~Primitive();
Primitive(int ID, QString name, int tesselation, Type t);
Primitive(QString name, int ID, int tesselation, Type t);
int getTesselation();
Primitive::Type getType();
QString getName();
QVariant data(int column) override;
protected:
int ID;
int tesselation;
......
#include "rigidbodytransformation.h"
#include "primitive.h"
RigidBodyTransformation::RigidBodyTransformation(Primitive* child)
RigidBodyTransformation::RigidBodyTransformation()
{
translation = QVector3D(0,0,0);
rotation = QQuaternion();
// this->child = child;
children.append(child);
name = "";
// qDebug() << "new rbt " << tx << "," << ty << "," << tz << ", rot " << rotation;
}
......@@ -16,6 +13,14 @@ RigidBodyTransformation::~RigidBodyTransformation(){
//apparently I do not need to call the baseclass destructor.
}
//0 = name, 1 = translation, 2=rotation
QVariant RigidBodyTransformation::data(int column){
if (column == 0) return QVariant(name);
else if (column == 1) return QVariant(translation);
else if (column == 2) return QVariant(rotation);
else return QVariant();
}
void RigidBodyTransformation::addTranslation(QVector3D diff){
translation += diff;
......
......@@ -9,7 +9,7 @@ class Primitive;
class RigidBodyTransformation : public TreeItem
{
public:
RigidBodyTransformation(Primitive* child);
RigidBodyTransformation();
~RigidBodyTransformation();
void addTranslation(QVector3D diff);
......@@ -22,6 +22,8 @@ public:
void drawChild();
QVariant data(int column) override;
private :
//translation
QVector3D translation;
......
......@@ -32,7 +32,7 @@ RigidBodyTransformation* SceneGraph::addSphere(int tesselation){
//tesselation < 3 makes no sense (except for box)
int t = tesselation;
if (t < 3) t = 3;
Primitive* p = new Primitive(idCounter, nextSphereName, t, Primitive::Type::SPHERE);
Primitive* p = new Primitive(nextSphereName, idCounter, t, Primitive::Type::SPHERE);
idCounter++;
sphereIndex++;
......@@ -45,7 +45,7 @@ RigidBodyTransformation* SceneGraph::addBox(int tesselation){
nextBoxName = "Box ";
nextBoxName.append(QString::number(boxIndex));
Primitive* p = new Primitive(idCounter, nextBoxName, tesselation, Primitive::Type::BOX);
Primitive* p = new Primitive(nextBoxName, idCounter, tesselation, Primitive::Type::BOX);
idCounter++;
boxIndex++;
......@@ -59,7 +59,7 @@ RigidBodyTransformation* SceneGraph::addCylinder(int tesselation){
nextCylName.append(QString::number(cylIndex));
int t = tesselation;
if (t < 3) t = 3;
Primitive* p = new Primitive(idCounter,nextCylName, t, Primitive::Type::CYLINDER);
Primitive* p = new Primitive(nextCylName, idCounter, t, Primitive::Type::CYLINDER);
idCounter++;
cylIndex++;
qDebug("added Cylinder to scenegraph");
......@@ -72,7 +72,7 @@ RigidBodyTransformation* SceneGraph::addCone(int tesselation){
nextConeName.append(QString::number(coneIndex));
int t = tesselation;
if (t < 3) t = 3;
Primitive* p = new Primitive(idCounter,nextConeName, t, Primitive::Type::CONE);
Primitive* p = new Primitive(nextConeName, idCounter, t, Primitive::Type::CONE);
idCounter++;
coneIndex++;
return addPrimitive(p);
......@@ -84,15 +84,17 @@ RigidBodyTransformation* SceneGraph::addTorus(int tesselation){
nextTorusName.append(QString::number(torusIndex));
int t = tesselation;
if (t < 3) t = 3;
Primitive* p = new Primitive(idCounter,nextTorusName, t, Primitive::Type::TORUS);
Primitive* p = new Primitive(nextTorusName, idCounter, t, Primitive::Type::TORUS);
idCounter++;
torusIndex++;
return addPrimitive(p);
}
RigidBodyTransformation* SceneGraph::addPrimitive(Primitive* p){
RigidBodyTransformation* r = new RigidBodyTransformation(p);
RigidBodyTransformation* r = new RigidBodyTransformation();
nodes.append(r);
model->addChildToRoot(r,p);
// model->insertRows(1,1,QModelIndex());
notifyViews();
return r;
}
......
......@@ -16,7 +16,7 @@ public:
int getChildrenCount();
int columnCount();
QVariant data(int column); //returns QVariant for name string
virtual QVariant data(int column); //returns QVariant for name string
void addChild(TreeItem* item);
bool removeChild(TreeItem* item);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment