goat3d
changeset 85:91e3aa1a60c3
more powerful treeview
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 14 May 2014 05:34:18 +0300 |
parents | 022b13ed975b |
children | 6d04caf510ab |
files | goatview/Makefile goatview/src/goatview.cc goatview/src/goatview.h |
diffstat | 3 files changed, 32 insertions(+), 51 deletions(-) [+] |
line diff
1.1 --- a/goatview/Makefile Mon May 12 07:37:30 2014 +0300 1.2 +++ b/goatview/Makefile Wed May 14 05:34:18 2014 +0300 1.3 @@ -2,7 +2,7 @@ 1.4 1.5 src = $(wildcard src/*.cc) 1.6 csrc = $(wildcard src/*.c) 1.7 -mochdr = src/goatview.h 1.8 +mochdr = src/goatview.h src/scenemodel.h 1.9 mocsrc = $(patsubst src/%.h,src/moc_%.cc,$(mochdr)) 1.10 obj = $(sort $(csrc:.c=.o) $(src:.cc=.o) $(mocsrc:.cc=.o)) 1.11 dep = $(obj:.o=.d)
2.1 --- a/goatview/src/goatview.cc Mon May 12 07:37:30 2014 +0300 2.2 +++ b/goatview/src/goatview.cc Wed May 14 05:34:18 2014 +0300 2.3 @@ -1,17 +1,16 @@ 2.4 #include <stdio.h> 2.5 +#include <map> 2.6 #include "opengl.h" 2.7 #include <QtOpenGL/QtOpenGL> 2.8 #include <vmath/vmath.h> 2.9 #include "goatview.h" 2.10 #include "goat3d.h" 2.11 2.12 -static void update_tree(QTreeWidget *tree); 2.13 -static void add_tree(QTreeWidget *tree, goat3d_node *node, QTreeWidgetItem *parent); 2.14 - 2.15 static void draw_node(goat3d_node *node); 2.16 static void draw_mesh(goat3d_mesh *mesh); 2.17 2.18 goat3d *scene; 2.19 +static SceneModel *sdata; 2.20 2.21 static long anim_time; 2.22 static float cam_theta, cam_phi, cam_dist = 8; 2.23 @@ -23,6 +22,7 @@ 2.24 GoatView::GoatView() 2.25 { 2.26 glview = 0; 2.27 + scene_model = 0; 2.28 2.29 QSettings settings; 2.30 resize(settings.value("main/size", QSize(1024, 768)).toSize()); 2.31 @@ -41,6 +41,8 @@ 2.32 2.33 GoatView::~GoatView() 2.34 { 2.35 + delete scene_model; 2.36 + sdata = 0; 2.37 } 2.38 2.39 void GoatView::closeEvent(QCloseEvent *ev) 2.40 @@ -69,7 +71,11 @@ 2.41 printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist); 2.42 } 2.43 2.44 - update_tree(scntree); 2.45 + scene_model->set_scene(scene); 2.46 + treeview->expandAll(); 2.47 + treeview->resizeColumnToContents(0); 2.48 + 2.49 + sdata = scene_model; // set the global sdata ptr 2.50 return true; 2.51 } 2.52 2.53 @@ -130,20 +136,24 @@ 2.54 addDockWidget(Qt::LeftDockWidgetArea, dock); 2.55 2.56 // make the tree view widget 2.57 - scntree = new QTreeWidget; 2.58 + treeview = new QTreeView; 2.59 + /* 2.60 scntree->setColumnCount(1); 2.61 QStringList hdrstr; 2.62 hdrstr << "Node";// << "Type"; 2.63 scntree->setHeaderItem(new QTreeWidgetItem((QTreeWidget*)0, hdrstr)); 2.64 - scntree->setAlternatingRowColors(true); 2.65 - dock_vbox->addWidget(scntree); 2.66 + */ 2.67 + treeview->setAlternatingRowColors(true); 2.68 + dock_vbox->addWidget(treeview); 2.69 2.70 - update_tree(scntree); 2.71 + scene_model = new SceneModel; 2.72 + connect(scene_model, &SceneModel::dataChanged, [&](){ glview->updateGL(); }); 2.73 + treeview->setModel(scene_model); 2.74 2.75 // misc 2.76 QPushButton *bn_quit = new QPushButton("quit"); 2.77 dock_vbox->addWidget(bn_quit); 2.78 - connect(bn_quit, &QPushButton::clicked, [&](){qApp->quit();}); 2.79 + connect(bn_quit, &QPushButton::clicked, [&](){ qApp->quit(); }); 2.80 2.81 // ---- bottom dock ---- 2.82 dock_cont = new QWidget; 2.83 @@ -189,43 +199,6 @@ 2.84 statusBar()->showMessage("opening animation..."); 2.85 } 2.86 2.87 -static void update_tree(QTreeWidget *tree) 2.88 -{ 2.89 - tree->clear(); 2.90 - 2.91 - if(!scene) return; 2.92 - 2.93 - int num_nodes = goat3d_get_node_count(scene); 2.94 - for(int i=0; i<num_nodes; i++) { 2.95 - goat3d_node *node = goat3d_get_node(scene, i); 2.96 - if(goat3d_get_node_parent(node)) { 2.97 - continue; 2.98 - } 2.99 - 2.100 - // only add the root nodes, the rest will be added recursively by them 2.101 - add_tree(tree, node, 0); 2.102 - } 2.103 - tree->expandAll(); 2.104 -} 2.105 - 2.106 -static void add_tree(QTreeWidget *tree, goat3d_node *node, QTreeWidgetItem *parent) 2.107 -{ 2.108 - //char icon_name[64]; 2.109 - //sprintf(icon_name, ":/icons/icons/icon_%s.png", node->get_type()); 2.110 - 2.111 - QStringList row; 2.112 - row << goat3d_get_node_name(node) << "M"; 2.113 - QTreeWidgetItem *item = new QTreeWidgetItem(parent, row); 2.114 - //item->setIcon(0, QIcon(icon_name)); 2.115 - tree->addTopLevelItem(item); 2.116 - 2.117 - int num_children = goat3d_get_node_child_count(node); 2.118 - for(int i=0; i<num_children; i++) { 2.119 - add_tree(tree, goat3d_get_node_child(node, i), item); 2.120 - } 2.121 -} 2.122 - 2.123 - 2.124 2.125 // ---- OpenGL viewport ---- 2.126 GoatViewport::GoatViewport(QWidget *main_win) 2.127 @@ -329,16 +302,21 @@ 2.128 2.129 static void draw_node(goat3d_node *node) 2.130 { 2.131 + SceneNodeData *data = sdata ? sdata->get_node_data(node) : 0; 2.132 + if(!data) return; 2.133 + 2.134 float xform[16]; 2.135 goat3d_get_node_matrix(node, xform, anim_time); 2.136 2.137 glPushMatrix(); 2.138 glMultTransposeMatrixf(xform); 2.139 2.140 - if(goat3d_get_node_type(node) == GOAT3D_NODE_MESH) { 2.141 - goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node); 2.142 + if(data->visible) { 2.143 + if(goat3d_get_node_type(node) == GOAT3D_NODE_MESH) { 2.144 + goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node); 2.145 2.146 - draw_mesh(mesh); 2.147 + draw_mesh(mesh); 2.148 + } 2.149 } 2.150 2.151 int num_child = goat3d_get_node_child_count(node);
3.1 --- a/goatview/src/goatview.h Mon May 12 07:37:30 2014 +0300 3.2 +++ b/goatview/src/goatview.h Wed May 14 05:34:18 2014 +0300 3.3 @@ -5,17 +5,20 @@ 3.4 #include <QtWidgets/QtWidgets> 3.5 #include <QtOpenGL/QGLWidget> 3.6 #include "goat3d.h" 3.7 +#include "scenemodel.h" 3.8 3.9 extern goat3d *scene; 3.10 3.11 class GoatViewport; 3.12 3.13 + 3.14 class GoatView : public QMainWindow { 3.15 private: 3.16 Q_OBJECT 3.17 3.18 GoatViewport *glview; 3.19 - QTreeWidget *scntree; 3.20 + QTreeView *treeview; 3.21 + SceneModel *scene_model; 3.22 3.23 void closeEvent(QCloseEvent *ev); 3.24 bool make_menu();