Commit cb240d35 by Kai Westerkamp

added name CHange

parent 8ece7716
......@@ -23,7 +23,8 @@ SOURCES += main.cpp\
camera.cpp \
sceneprimitive.cpp \
sceneobject.cpp \
scenenode.cpp
scenenode.cpp \
treedelegate.cpp
HEADERS += mainwindow.h \
cubewidget.h \
......@@ -34,7 +35,8 @@ HEADERS += mainwindow.h \
sceneprimitive.h \
sceneobject.h \
scenenode.h \
glut.h
glut.h \
treedelegate.h
RESOURCES += \
hellocube.qrc
......
#include "mainwindow.h"
#include <treedelegate.h>
MainWindow::MainWindow(QWidget *parent)
......@@ -264,6 +264,7 @@ MainWindow::MainWindow(QWidget *parent)
}
void MainWindow::initDoc()
{
QDockWidget *dock = new QDockWidget("Scene", this);
......@@ -273,7 +274,10 @@ void MainWindow::initDoc()
sceneView->setSelectionBehavior(QAbstractItemView::SelectRows);
sceneView->expandAll();
sceneView->setModel(scene);
TreeDelegate *delegate = new TreeDelegate();
sceneView->setItemDelegate(delegate);
connect(sceneView,SIGNAL(clicked(QModelIndex)),scene, SLOT(objectSelected(QModelIndex)));
connect(delegate,SIGNAL(nameChanged()),this, SLOT(updateStatusBar()));
dock->setWidget(sceneView);
......
......@@ -5,7 +5,7 @@
Scene::Scene( )
{
root = new SceneNode();
root->setName("ROOT");
root->setName("<NONE>");
active = root;
activeIndex = QModelIndex();
}
......
#include "treedelegate.h"
#include <QDebug>
#include <QLineEdit>
#include <QString>
#include <scene.h>
TreeDelegate::TreeDelegate()
{
}
void TreeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
qDebug()<<"out";
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
if (!lineEdit->isModified()) {
return;
}
QString text = lineEdit->text();
text = text.trimmed();
if (text.isEmpty()) {
// If text is empty, do nothing - preserve the old value.
return;
} else {
if (index.isValid()) {
SceneObject *item = static_cast<SceneObject*>(index.internalPointer());
if (item)
item->setName(text);
}
emit nameChanged();
}
}
#ifndef TREEDELEGATE_H
#define TREEDELEGATE_H
#include <QItemDelegate>
class TreeDelegate : public QItemDelegate
{
Q_OBJECT;
public:
TreeDelegate();
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
signals:
void nameChanged() const;
};
#endif // TREEDELEGATE_H
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