New lua versions
[ryzomcore.git] / studio / src / plugins / georges_editor / actions.cpp
blob54819dc18d1de58c3cd7fb128cb06f2203106c29
1 // Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2011 Adrian JAEKEL <aj@elane2k.com>
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012 Matt RAYKOWSKI (sfb) <matt.raykowski@gmail.com>
6 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // Project includes
22 #include "actions.h"
23 #include "formitem.h"
24 #include "georgesform_model.h"
26 // Qt includes
29 // NeL includes
30 #include <nel/misc/debug.h>
31 #include <nel/misc/file.h>
32 #include <nel/misc/o_xml.h>
33 #include <nel/georges/u_form_loader.h>
34 #include <nel/georges/form.h>
35 #include <nel/georges/u_form.h>
36 #include <nel/georges/u_type.h>
38 namespace GeorgesQt
41 CUndoFormArrayRenameCommand::CUndoFormArrayRenameCommand(CGeorgesFormModel *model, CFormItem *item, const QVariant &value, QUndoCommand *parent)
42 : QUndoCommand("Rename Form Array Member", parent), m_model(model), m_item(item)
44 m_newValue = value.toString();
47 void CUndoFormArrayRenameCommand::redo()
49 update(true);
52 void CUndoFormArrayRenameCommand::undo()
54 update(false);
57 void CUndoFormArrayRenameCommand::update(bool redo)
59 // Get the parent node
60 const NLGEORGES::CFormDfn *parentDfn;
61 uint indexDfn;
62 const NLGEORGES::CFormDfn *nodeDfn;
63 const NLGEORGES::CType *nodeType;
64 NLGEORGES::CFormElm *node;
65 NLGEORGES::UFormDfn::TEntryType type;
66 bool isArray;
67 bool vdfnArray;
68 NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_item->form());
69 NLGEORGES::CFormElm *elm = static_cast<NLGEORGES::CFormElm*>(&form->Elements);
71 nlverify ( elm->getNodeByName (m_item->formName().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray, vdfnArray, true, NLGEORGES_FIRST_ROUND) );
72 if (node)
74 std::string tmpName;
75 node->getFormName(tmpName);
77 NLGEORGES::CFormElmArray* array = static_cast<NLGEORGES::CFormElmArray*> (node->getParent ());
79 // In the redo stage save the old value, just in case.
80 if(redo)
82 // If the name of the element is empty then give it a nice default.
83 if(array->Elements[m_item->structId()].Name.empty())
85 m_oldValue.append("#");
86 m_oldValue.append(QString("%1").arg(m_item->structId()));
88 else
90 m_oldValue = QString(array->Elements[m_item->structId()].Name.c_str());
94 QString value;
95 if(redo)
96 value = m_newValue;
97 else
98 value = m_oldValue;
101 array->Elements[m_item->structId()].Name = value.toAscii().data();
102 m_item->setName(value.toAscii().data());
104 m_model->emitDataChanged(m_model->index(m_item->row(), 0, m_item));