mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-17 13:01:41 +00:00
Fixed: #1302 Fixed crash program(LoadRootPrimitiveCommand and AddPrimitiveByClassCommand do not work with selection model, and edit points mode does not work with mouse panning).
This commit is contained in:
parent
8362d0b123
commit
b6db3ccfc7
5 changed files with 29 additions and 14 deletions
|
@ -135,7 +135,7 @@ void PrimitivesView::loadRootPrimitive()
|
||||||
Q_FOREACH(QString fileName, fileNames)
|
Q_FOREACH(QString fileName, fileNames)
|
||||||
{
|
{
|
||||||
m_lastDir = QFileInfo(fileName).absolutePath();
|
m_lastDir = QFileInfo(fileName).absolutePath();
|
||||||
m_undoStack->push(new LoadRootPrimitiveCommand(fileName, m_worldEditorScene, m_primitivesTreeModel));
|
m_undoStack->push(new LoadRootPrimitiveCommand(fileName, m_worldEditorScene, m_primitivesTreeModel, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileNames.count() > 1)
|
if (fileNames.count() > 1)
|
||||||
|
@ -258,7 +258,7 @@ void PrimitivesView::addNewPrimitiveByClass(int value)
|
||||||
QString className = node->primitiveClass()->DynamicChildren[value].ClassName.c_str();
|
QString className = node->primitiveClass()->DynamicChildren[value].ClassName.c_str();
|
||||||
|
|
||||||
m_undoStack->push(new AddPrimitiveByClassCommand(className, m_primitivesTreeModel->pathFromIndex(indexList.first()),
|
m_undoStack->push(new AddPrimitiveByClassCommand(className, m_primitivesTreeModel->pathFromIndex(indexList.first()),
|
||||||
m_worldEditorScene, m_primitivesTreeModel));
|
m_worldEditorScene, m_primitivesTreeModel, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitivesView::generatePrimitives(int value)
|
void PrimitivesView::generatePrimitives(int value)
|
||||||
|
|
|
@ -189,9 +189,10 @@ void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode
|
||||||
{
|
{
|
||||||
QGraphicsItem *item = getGraphicsItem(node);
|
QGraphicsItem *item = getGraphicsItem(node);
|
||||||
if (item != 0)
|
if (item != 0)
|
||||||
scene->removeWorldItem(item);
|
{
|
||||||
|
|
||||||
delete qvariant_cast<QPersistentModelIndex *>(item->data(Constants::NODE_PERISTENT_INDEX));
|
delete qvariant_cast<QPersistentModelIndex *>(item->data(Constants::NODE_PERISTENT_INDEX));
|
||||||
|
scene->removeWorldItem(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = model->rowCount(primIndex);
|
int count = model->rowCount(primIndex);
|
||||||
|
@ -350,11 +351,12 @@ void CreateRootPrimitiveCommand::redo()
|
||||||
|
|
||||||
|
|
||||||
LoadRootPrimitiveCommand::LoadRootPrimitiveCommand(const QString &fileName, WorldEditorScene *scene,
|
LoadRootPrimitiveCommand::LoadRootPrimitiveCommand(const QString &fileName, WorldEditorScene *scene,
|
||||||
PrimitivesTreeModel *model, QUndoCommand *parent)
|
PrimitivesTreeModel *model, QTreeView *view, QUndoCommand *parent)
|
||||||
: QUndoCommand(parent),
|
: QUndoCommand(parent),
|
||||||
m_fileName(fileName),
|
m_fileName(fileName),
|
||||||
m_scene(scene),
|
m_scene(scene),
|
||||||
m_model(model)
|
m_model(model),
|
||||||
|
m_view(view)
|
||||||
{
|
{
|
||||||
setText("Load primitive file");
|
setText("Load primitive file");
|
||||||
}
|
}
|
||||||
|
@ -368,6 +370,8 @@ void LoadRootPrimitiveCommand::undo()
|
||||||
// Disable edit points mode
|
// Disable edit points mode
|
||||||
m_scene->setEnabledEditPoints(false);
|
m_scene->setEnabledEditPoints(false);
|
||||||
|
|
||||||
|
m_view->selectionModel()->clearSelection();
|
||||||
|
|
||||||
QModelIndex index = m_model->pathToIndex(m_rootPrimIndex);
|
QModelIndex index = m_model->pathToIndex(m_rootPrimIndex);
|
||||||
|
|
||||||
removeGraphicsItems(index, m_model, m_scene);
|
removeGraphicsItems(index, m_model, m_scene);
|
||||||
|
@ -409,19 +413,20 @@ void LoadRootPrimitiveCommand::redo()
|
||||||
}
|
}
|
||||||
|
|
||||||
AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
||||||
WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent)
|
WorldEditorScene *scene, PrimitivesTreeModel *model, QTreeView *view, QUndoCommand *parent)
|
||||||
: QUndoCommand(parent),
|
: QUndoCommand(parent),
|
||||||
m_className(className),
|
m_className(className),
|
||||||
m_parentIndex(parentIndex),
|
m_parentIndex(parentIndex),
|
||||||
m_scene(scene),
|
m_scene(scene),
|
||||||
m_model(model)
|
m_model(model),
|
||||||
|
m_view(view)
|
||||||
{
|
{
|
||||||
setText(QString("Add %1").arg(m_className));
|
setText(QString("Add %1").arg(m_className));
|
||||||
|
|
||||||
QGraphicsView *view = m_scene->views().first();
|
QGraphicsView *graphicsView = m_scene->views().first();
|
||||||
|
|
||||||
// TODO: returns incorrect position when zoom in
|
// TODO: returns incorrect position when zoom in
|
||||||
QRectF visibleArea = view->mapToScene(view->rect()).boundingRect();
|
QRectF visibleArea = graphicsView->mapToScene(view->rect()).boundingRect();
|
||||||
m_delta = visibleArea.height() / 10.0;
|
m_delta = visibleArea.height() / 10.0;
|
||||||
m_initPos = visibleArea.center();
|
m_initPos = visibleArea.center();
|
||||||
}
|
}
|
||||||
|
@ -434,6 +439,8 @@ void AddPrimitiveByClassCommand::undo()
|
||||||
{
|
{
|
||||||
m_scene->setEnabledEditPoints(false);
|
m_scene->setEnabledEditPoints(false);
|
||||||
|
|
||||||
|
m_view->selectionModel()->clearSelection();
|
||||||
|
|
||||||
QModelIndex index = m_model->pathToIndex(m_newPrimIndex);
|
QModelIndex index = m_model->pathToIndex(m_newPrimIndex);
|
||||||
PrimitiveNode *node = static_cast<PrimitiveNode *>(index.internalPointer());
|
PrimitiveNode *node = static_cast<PrimitiveNode *>(index.internalPointer());
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QtGui/QUndoCommand>
|
#include <QtGui/QUndoCommand>
|
||||||
#include <QtGui/QGraphicsScene>
|
#include <QtGui/QGraphicsScene>
|
||||||
|
#include <QtGui/QTreeView>
|
||||||
#include <QtGui/QGraphicsItem>
|
#include <QtGui/QGraphicsItem>
|
||||||
#include <QPersistentModelIndex>
|
#include <QPersistentModelIndex>
|
||||||
|
|
||||||
|
@ -121,7 +122,8 @@ class LoadRootPrimitiveCommand: public QUndoCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LoadRootPrimitiveCommand(const QString &fileName, WorldEditorScene *scene,
|
LoadRootPrimitiveCommand(const QString &fileName, WorldEditorScene *scene,
|
||||||
PrimitivesTreeModel *model, QUndoCommand *parent = 0);
|
PrimitivesTreeModel *model, QTreeView *view,
|
||||||
|
QUndoCommand *parent = 0);
|
||||||
virtual ~LoadRootPrimitiveCommand();
|
virtual ~LoadRootPrimitiveCommand();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
@ -132,6 +134,7 @@ private:
|
||||||
const QString m_fileName;
|
const QString m_fileName;
|
||||||
WorldEditorScene *const m_scene;
|
WorldEditorScene *const m_scene;
|
||||||
PrimitivesTreeModel *const m_model;
|
PrimitivesTreeModel *const m_model;
|
||||||
|
QTreeView *m_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,7 +147,7 @@ class AddPrimitiveByClassCommand: public QUndoCommand
|
||||||
public:
|
public:
|
||||||
AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex,
|
||||||
WorldEditorScene *scene, PrimitivesTreeModel *model,
|
WorldEditorScene *scene, PrimitivesTreeModel *model,
|
||||||
QUndoCommand *parent = 0);
|
QTreeView *view, QUndoCommand *parent = 0);
|
||||||
virtual ~AddPrimitiveByClassCommand();
|
virtual ~AddPrimitiveByClassCommand();
|
||||||
|
|
||||||
virtual void undo();
|
virtual void undo();
|
||||||
|
@ -157,6 +160,7 @@ private:
|
||||||
Path m_parentIndex, m_newPrimIndex;
|
Path m_parentIndex, m_newPrimIndex;
|
||||||
WorldEditorScene *m_scene;
|
WorldEditorScene *m_scene;
|
||||||
PrimitivesTreeModel *m_model;
|
PrimitivesTreeModel *m_model;
|
||||||
|
QTreeView *m_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -369,6 +369,9 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
|
|
||||||
void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
|
||||||
{
|
{
|
||||||
|
if (mouseEvent->button() == Qt::MidButton)
|
||||||
|
return;
|
||||||
|
|
||||||
if (m_pointsMode)
|
if (m_pointsMode)
|
||||||
{
|
{
|
||||||
if (mouseEvent->button() == Qt::LeftButton)
|
if (mouseEvent->button() == Qt::LeftButton)
|
||||||
|
|
|
@ -193,7 +193,8 @@ void WorldEditorWindow::loadWorldEditFile(const QString &fileName)
|
||||||
m_undoStack->push(new LoadLandscapeCommand(QString(worldEditList[i].second.c_str()), m_primitivesModel, m_zoneBuilderBase));
|
m_undoStack->push(new LoadLandscapeCommand(QString(worldEditList[i].second.c_str()), m_primitivesModel, m_zoneBuilderBase));
|
||||||
break;
|
break;
|
||||||
case Utils::PrimitiveType:
|
case Utils::PrimitiveType:
|
||||||
m_undoStack->push(new LoadRootPrimitiveCommand(QString(worldEditList[i].second.c_str()), m_worldEditorScene, m_primitivesModel));
|
m_undoStack->push(new LoadRootPrimitiveCommand(QString(worldEditList[i].second.c_str()),
|
||||||
|
m_worldEditorScene, m_primitivesModel, m_ui.treePrimitivesView));
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -383,7 +384,7 @@ void WorldEditorWindow::readSettings()
|
||||||
restoreGeometry(settings->value(Constants::WORLD_WINDOW_GEOMETRY).toByteArray());
|
restoreGeometry(settings->value(Constants::WORLD_WINDOW_GEOMETRY).toByteArray());
|
||||||
|
|
||||||
// Use OpenGL graphics system instead raster graphics system
|
// Use OpenGL graphics system instead raster graphics system
|
||||||
if (settings->value(Constants::WORLD_EDITOR_USE_OPENGL, true).toBool())
|
if (settings->value(Constants::WORLD_EDITOR_USE_OPENGL, false).toBool())
|
||||||
{
|
{
|
||||||
m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer));
|
m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer));
|
||||||
m_ui.graphicsView->setViewport(m_oglWidget);
|
m_ui.graphicsView->setViewport(m_oglWidget);
|
||||||
|
|
Loading…
Reference in a new issue