mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-19 13:46:13 +00:00
Changed: #1302 Added save/saveAs action for primitive item.
This commit is contained in:
parent
7b0f46abb0
commit
6da400630b
7 changed files with 89 additions and 8 deletions
|
@ -235,6 +235,7 @@ Node::NodeType PrimitiveNode::type() const
|
|||
|
||||
RootPrimitiveNode::RootPrimitiveNode(const QString &name, NLLIGO::CPrimitives *primitives)
|
||||
: PrimitiveNode(primitives->RootNode),
|
||||
m_fileName(name),
|
||||
m_primitives(primitives)
|
||||
{
|
||||
setData(Qt::DisplayRole, name);
|
||||
|
@ -249,6 +250,17 @@ NLLIGO::CPrimitives *RootPrimitiveNode::primitives() const
|
|||
return m_primitives;
|
||||
}
|
||||
|
||||
void RootPrimitiveNode::setFileName(const QString &fileName)
|
||||
{
|
||||
setData(Qt::DisplayRole, fileName);
|
||||
m_fileName = fileName;
|
||||
}
|
||||
|
||||
QString RootPrimitiveNode::fileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
Node::NodeType RootPrimitiveNode::type() const
|
||||
{
|
||||
return RootPrimitiveNodeType;
|
||||
|
|
|
@ -167,9 +167,13 @@ public:
|
|||
|
||||
NLLIGO::CPrimitives *primitives() const;
|
||||
|
||||
void setFileName(const QString &fileName);
|
||||
QString fileName() const;
|
||||
virtual NodeType type() const;
|
||||
|
||||
private:
|
||||
|
||||
QString m_fileName;
|
||||
NLLIGO::CPrimitives *m_primitives;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "primitive_item.h"
|
||||
#include "primitives_model.h"
|
||||
#include "world_editor_misc.h"
|
||||
#include "world_editor_constants.h"
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/debug.h>
|
||||
|
@ -218,6 +219,10 @@ Path PrimitivesTreeModel::createRootPrimitiveNode(const QString &fileName, NLLIG
|
|||
if (m_worldEditNode == 0)
|
||||
createWorldEditNode("NewWorldEdit");
|
||||
|
||||
QString name = "NewPrimitive";
|
||||
if (!fileName.isEmpty())
|
||||
name = fileName;
|
||||
|
||||
// Get position
|
||||
int pos = m_worldEditNode->childCount();
|
||||
|
||||
|
@ -225,10 +230,13 @@ Path PrimitivesTreeModel::createRootPrimitiveNode(const QString &fileName, NLLIG
|
|||
|
||||
// Add root node in tree model
|
||||
beginInsertRows(parentIndex, pos, pos);
|
||||
RootPrimitiveNode *newNode = new RootPrimitiveNode(fileName, primitives);
|
||||
RootPrimitiveNode *newNode = new RootPrimitiveNode(name, primitives);
|
||||
m_worldEditNode->appendChildNode(newNode);
|
||||
endInsertRows();
|
||||
|
||||
newNode->setData(Constants::PRIMITIVE_FILE_IS_CREATED, !fileName.isEmpty());
|
||||
newNode->setData(Constants::PRIMITIVE_IS_MODIFIED, false);
|
||||
|
||||
QModelIndex rootPrimIndex = index(pos, 0, parentIndex);
|
||||
|
||||
// Scan childs items and add in the tree model
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "primitives_view.h"
|
||||
#include "primitives_model.h"
|
||||
#include "world_editor_actions.h"
|
||||
#include "world_editor_constants.h"
|
||||
|
||||
#include "../core/core_constants.h"
|
||||
#include "../landscape_editor/landscape_editor_constants.h"
|
||||
|
@ -27,9 +28,11 @@
|
|||
#include <nel/ligo/primitive.h>
|
||||
#include <nel/ligo/ligo_config.h>
|
||||
#include <nel/ligo/primitive_class.h>
|
||||
#include <nel/ligo/primitive_utils.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QFileDialog>
|
||||
|
||||
|
@ -49,12 +52,10 @@ PrimitivesView::PrimitivesView(QWidget *parent)
|
|||
m_unloadAction->setEnabled(false);
|
||||
|
||||
m_saveAction = new QAction("Save", this);
|
||||
m_saveAction->setEnabled(false);
|
||||
m_saveAction->setIcon(QIcon(Core::Constants::ICON_SAVE));
|
||||
|
||||
m_saveAsAction = new QAction("Save As...", this);
|
||||
m_saveAsAction->setIcon(QIcon(Core::Constants::ICON_SAVE_AS));
|
||||
m_saveAsAction->setEnabled(false);
|
||||
|
||||
m_loadLandAction = new QAction("Load landscape file", this);
|
||||
m_loadLandAction->setIcon(QIcon(LandscapeEditor::Constants::ICON_ZONE_ITEM));
|
||||
|
@ -83,6 +84,8 @@ PrimitivesView::PrimitivesView(QWidget *parent)
|
|||
connect(m_newPrimitiveAction, SIGNAL(triggered()), this, SLOT(createRootPrimitive()));
|
||||
connect(m_selectChildrenAction, SIGNAL(triggered()), this, SLOT(selectChildren()));
|
||||
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(deletePrimitives()));
|
||||
connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save()));
|
||||
connect(m_saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||
|
||||
#ifdef Q_OS_DARWIN
|
||||
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
|
@ -186,6 +189,54 @@ void PrimitivesView::selectChildren()
|
|||
selectChildren(parentIndex);
|
||||
}
|
||||
|
||||
void PrimitivesView::save()
|
||||
{
|
||||
nlassert(m_primitivesTreeModel);
|
||||
|
||||
QModelIndexList indexList = selectionModel()->selectedRows();
|
||||
QModelIndex index = indexList.first();
|
||||
|
||||
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
|
||||
|
||||
if (node->data(Constants::PRIMITIVE_FILE_IS_CREATED).toBool())
|
||||
{
|
||||
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), node->fileName().toStdString()))
|
||||
QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(node->fileName()));
|
||||
else
|
||||
node->setData(Constants::PRIMITIVE_IS_MODIFIED, false);
|
||||
}
|
||||
else
|
||||
saveAs();
|
||||
}
|
||||
|
||||
void PrimitivesView::saveAs()
|
||||
{
|
||||
nlassert(m_primitivesTreeModel);
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(this,
|
||||
tr("Save NeL Ligo primitive file"), m_lastDir,
|
||||
tr("NeL Ligo primitive file (*.primitive)"));
|
||||
|
||||
setCursor(Qt::WaitCursor);
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
QModelIndexList indexList = selectionModel()->selectedRows();
|
||||
QModelIndex index = indexList.first();
|
||||
|
||||
RootPrimitiveNode *node = static_cast<RootPrimitiveNode *>(index.internalPointer());
|
||||
|
||||
if (!NLLIGO::saveXmlPrimitiveFile(*node->primitives(), fileName.toStdString()))
|
||||
QMessageBox::warning(this, "World Editor Qt", QString("Error writing output file: %1").arg(fileName));
|
||||
else
|
||||
{
|
||||
node->setFileName(fileName);
|
||||
node->setData(Constants::PRIMITIVE_FILE_IS_CREATED, true);
|
||||
node->setData(Constants::PRIMITIVE_IS_MODIFIED, false);
|
||||
}
|
||||
}
|
||||
setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
void PrimitivesView::deletePrimitives()
|
||||
{
|
||||
nlassert(m_undoStack);
|
||||
|
@ -267,8 +318,8 @@ void PrimitivesView::selectChildren(const QModelIndex &parent)
|
|||
void PrimitivesView::fillMenu_WorldEdit(QMenu *menu)
|
||||
{
|
||||
menu->addAction(m_unloadAction);
|
||||
menu->addAction(m_saveAction);
|
||||
menu->addAction(m_saveAsAction);
|
||||
//menu->addAction(m_saveAction);
|
||||
//menu->addAction(m_saveAsAction);
|
||||
menu->addSeparator();
|
||||
menu->addAction(m_loadLandAction);
|
||||
menu->addAction(m_loadPrimitiveAction);
|
||||
|
@ -279,7 +330,7 @@ void PrimitivesView::fillMenu_WorldEdit(QMenu *menu)
|
|||
|
||||
void PrimitivesView::fillMenu_Landscape(QMenu *menu)
|
||||
{
|
||||
menu->addAction(m_deleteAction);
|
||||
menu->addAction(m_unloadAction);
|
||||
menu->addSeparator();
|
||||
menu->addAction(m_showAction);
|
||||
menu->addAction(m_hideAction);
|
||||
|
@ -289,7 +340,9 @@ void PrimitivesView::fillMenu_RootPrimitive(QMenu *menu, const QModelIndex &inde
|
|||
{
|
||||
menu->addAction(m_saveAction);
|
||||
menu->addAction(m_saveAsAction);
|
||||
menu->addAction(m_unloadAction);
|
||||
fillMenu_Primitive(menu, index);
|
||||
menu->removeAction(m_deleteAction);
|
||||
}
|
||||
|
||||
void PrimitivesView::fillMenu_Primitive(QMenu *menu, const QModelIndex &index)
|
||||
|
|
|
@ -67,6 +67,8 @@ private Q_SLOTS:
|
|||
void createRootPrimitive();
|
||||
void selectChildren();
|
||||
|
||||
void save();
|
||||
void saveAs();
|
||||
void deletePrimitives();
|
||||
void addNewPrimitiveByClass(int value);
|
||||
void generatePrimitives(int value);
|
||||
|
|
|
@ -295,7 +295,7 @@ void CreateRootPrimitiveCommand::undo()
|
|||
void CreateRootPrimitiveCommand::redo()
|
||||
{
|
||||
NLLIGO::CPrimitives *newRootPrim = new NLLIGO::CPrimitives();
|
||||
m_rootPrimIndex = m_model->createRootPrimitiveNode(m_fileName, newRootPrim);
|
||||
m_rootPrimIndex = m_model->createRootPrimitiveNode("", newRootPrim);
|
||||
}
|
||||
|
||||
|
||||
|
@ -337,7 +337,7 @@ void LoadRootPrimitiveCommand::redo()
|
|||
// set the primitive context
|
||||
NLLIGO::CPrimitiveContext::instance().CurrentPrimitive = primitives;
|
||||
|
||||
NLLIGO::loadXmlPrimitiveFile(*primitives, m_fileName.toStdString(), *NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig);
|
||||
NLLIGO::loadXmlPrimitiveFile(*primitives, m_fileName.toStdString(), *Utils::ligoConfig());
|
||||
|
||||
// unset the context
|
||||
NLLIGO::CPrimitiveContext::instance().CurrentPrimitive = NULL;
|
||||
|
|
|
@ -28,6 +28,8 @@ const int NODE_PERISTENT_INDEX = USER_TYPE + 1;
|
|||
const int WORLD_EDITOR_NODE = USER_TYPE + 2;
|
||||
const int GRAPHICS_DATA_QT4_2D = USER_TYPE + 3;
|
||||
const int GRAPHICS_DATA_NEL3D = USER_TYPE + 4;
|
||||
const int PRIMITIVE_IS_MODIFIED = USER_TYPE + 5;
|
||||
const int PRIMITIVE_FILE_IS_CREATED = USER_TYPE + 6;
|
||||
|
||||
//settings
|
||||
const char *const WORLD_EDITOR_SECTION = "WorldEditor";
|
||||
|
|
Loading…
Reference in a new issue