1 // Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2011 Adrian JAEKEL <aj@elane2k.com>
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>
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/>.
24 #include "georgesform_model.h"
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>
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()
52 void CUndoFormArrayRenameCommand::undo()
57 void CUndoFormArrayRenameCommand::update(bool redo
)
59 // Get the parent node
60 const NLGEORGES::CFormDfn
*parentDfn
;
62 const NLGEORGES::CFormDfn
*nodeDfn
;
63 const NLGEORGES::CType
*nodeType
;
64 NLGEORGES::CFormElm
*node
;
65 NLGEORGES::UFormDfn::TEntryType type
;
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
) );
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.
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()));
90 m_oldValue
= QString(array
->Elements
[m_item
->structId()].Name
.c_str());
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
));