SceneInspector.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <Inventor/nodes/SoGroup.h>
00027 # include <QHeaderView>
00028 #endif
00029
00030 #include "SceneInspector.h"
00031 #include "ui_SceneInspector.h"
00032 #include "MainWindow.h"
00033 #include "View3DInventor.h"
00034 #include "View3DInventorViewer.h"
00035
00036 using namespace Gui::Dialog;
00037
00038
00039
00040 SceneModel::SceneModel(QObject* parent)
00041 : QStandardItemModel(parent)
00042 {
00043 }
00044
00045 SceneModel::~SceneModel()
00046 {
00047 }
00048
00049 int SceneModel::columnCount (const QModelIndex & parent) const
00050 {
00051 return 1;
00052 }
00053
00054 Qt::ItemFlags SceneModel::flags (const QModelIndex & index) const
00055 {
00056 return QAbstractItemModel::flags(index);
00057 }
00058
00059 QVariant SceneModel::headerData (int section, Qt::Orientation orientation, int role) const
00060 {
00061 if (orientation == Qt::Horizontal) {
00062 if (role != Qt::DisplayRole)
00063 return QVariant();
00064 if (section == 0)
00065 return tr("Inventor Tree");
00066 }
00067
00068 return QVariant();
00069 }
00070
00071 bool SceneModel::setHeaderData (int, Qt::Orientation, const QVariant &, int)
00072 {
00073 return false;
00074 }
00075
00076 void SceneModel::setNode(SoNode* node)
00077 {
00078 this->clear();
00079 this->setHeaderData(0, Qt::Horizontal, tr("Nodes"), Qt::DisplayRole);
00080
00081 this->insertColumns(0,1);
00082 this->insertRows(0,1);
00083 setNode(this->index(0, 0),node);
00084 }
00085
00086 void SceneModel::setNode(QModelIndex index, SoNode* node)
00087 {
00088 this->setData(index, QVariant(QString::fromAscii(node->getTypeId().getName())));
00089 if (node->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) {
00090 SoGroup *group = static_cast<SoGroup*>(node);
00091
00092 this->insertColumns(0,1,index);
00093 this->insertRows(0,group->getNumChildren(), index);
00094 for (int i=0; i<group->getNumChildren();i++) {
00095 SoNode* child = group->getChild(i);
00096 setNode(this->index(i, 0, index), child);
00097 }
00098 }
00099
00100 }
00101
00102
00103
00104
00105
00106 DlgInspector::DlgInspector(QWidget* parent, Qt::WFlags fl)
00107 : QDialog(parent, fl), ui(new Ui_SceneInspector())
00108 {
00109 ui->setupUi(this);
00110 setWindowTitle(tr("Scene Inspector"));
00111
00112 SceneModel* model = new SceneModel(this);
00113 ui->treeView->setModel(model);
00114 ui->treeView->setRootIsDecorated(true);
00115 }
00116
00117
00118
00119
00120 DlgInspector::~DlgInspector()
00121 {
00122
00123 delete ui;
00124 }
00125
00126 void DlgInspector::setNode(SoNode* node)
00127 {
00128 SceneModel* model = static_cast<SceneModel*>(ui->treeView->model());
00129 model->setNode(node);
00130
00131 QHeaderView* header = ui->treeView->header();
00132 header->setResizeMode(0, QHeaderView::Stretch);
00133 header->setMovable(false);
00134 }
00135
00136 void DlgInspector::changeEvent(QEvent *e)
00137 {
00138 if (e->type() == QEvent::LanguageChange) {
00139 ui->retranslateUi(this);
00140 setWindowTitle(tr("Scene Inspector"));
00141 }
00142 QDialog::changeEvent(e);
00143 }
00144
00145 void DlgInspector::on_refreshButton_clicked()
00146 {
00147 View3DInventor* child = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
00148 if (child) {
00149 View3DInventorViewer* viewer = child->getViewer();
00150 setNode(viewer->getSceneGraph());
00151 ui->treeView->expandToDepth(3);
00152 }
00153 else {
00154 SceneModel* model = static_cast<SceneModel*>(ui->treeView->model());
00155 model->clear();
00156 }
00157 }
00158
00159 #include "moc_SceneInspector.cpp"