mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-30 23:45:59 +00:00
Added: #1306 Added undo/redo action for renaming array entry names
This commit is contained in:
parent
4cb71eedf2
commit
65268b8226
6 changed files with 148 additions and 30 deletions
|
@ -14,4 +14,84 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Project includes
|
||||||
#include "actions.h"
|
#include "actions.h"
|
||||||
|
#include "formitem.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
#include <nel/misc/file.h>
|
||||||
|
#include <nel/misc/o_xml.h>
|
||||||
|
#include <nel/georges/u_form_loader.h>
|
||||||
|
#include <nel/georges/form.h>
|
||||||
|
#include <nel/georges/u_form.h>
|
||||||
|
#include <nel/georges/u_type.h>
|
||||||
|
|
||||||
|
namespace GeorgesQt
|
||||||
|
{
|
||||||
|
|
||||||
|
CUndoFormArrayRenameCommand::CUndoFormArrayRenameCommand(CFormItem *item, QString newValue, uint elementId, QUndoCommand *parent)
|
||||||
|
: QUndoCommand("Rename Form Array", parent), m_item(item), m_newValue(newValue), m_elementId(elementId)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void CUndoFormArrayRenameCommand::redo()
|
||||||
|
{
|
||||||
|
// Get the parent node
|
||||||
|
const NLGEORGES::CFormDfn *parentDfn;
|
||||||
|
uint indexDfn;
|
||||||
|
const NLGEORGES::CFormDfn *nodeDfn;
|
||||||
|
const NLGEORGES::CType *nodeType;
|
||||||
|
NLGEORGES::CFormElm *node;
|
||||||
|
NLGEORGES::UFormDfn::TEntryType type;
|
||||||
|
bool isArray;
|
||||||
|
bool vdfnArray;
|
||||||
|
NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_item->form());
|
||||||
|
NLGEORGES::CFormElm *elm = static_cast<NLGEORGES::CFormElm*>(&form->getRootNode());
|
||||||
|
nlverify ( elm->getNodeByName (m_item->formName().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray, vdfnArray, true, NLGEORGES_FIRST_ROUND) );
|
||||||
|
if (node)
|
||||||
|
{
|
||||||
|
nlinfo("doing array rename");
|
||||||
|
NLGEORGES::CFormElmArray* array = NLMISC::safe_cast<NLGEORGES::CFormElmArray*> (node->getParent ());
|
||||||
|
if(array->Elements[m_elementId].Name.empty())
|
||||||
|
{
|
||||||
|
m_oldValue.append("#");
|
||||||
|
m_oldValue.append(QString("%1").arg(m_elementId));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_oldValue = array->Elements[m_elementId].Name.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
array->Elements[m_elementId].Name = m_newValue.toStdString();
|
||||||
|
m_item->setName(m_newValue.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CUndoFormArrayRenameCommand::undo()
|
||||||
|
{
|
||||||
|
// Get the parent node
|
||||||
|
const NLGEORGES::CFormDfn *parentDfn;
|
||||||
|
uint indexDfn;
|
||||||
|
const NLGEORGES::CFormDfn *nodeDfn;
|
||||||
|
const NLGEORGES::CType *nodeType;
|
||||||
|
NLGEORGES::CFormElm *node;
|
||||||
|
NLGEORGES::UFormDfn::TEntryType type;
|
||||||
|
bool isArray;
|
||||||
|
bool vdfnArray;
|
||||||
|
NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_item->form());
|
||||||
|
NLGEORGES::CFormElm *elm = static_cast<NLGEORGES::CFormElm*>(&form->getRootNode());
|
||||||
|
nlverify ( elm->getNodeByName (m_item->formName().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray, vdfnArray, true, NLGEORGES_FIRST_ROUND) );
|
||||||
|
if (node)
|
||||||
|
{
|
||||||
|
NLGEORGES::CFormElmArray* array = NLMISC::safe_cast<NLGEORGES::CFormElmArray*> (node->getParent ());
|
||||||
|
//m_oldValue = array->Elements[m_elementId].Name.c_str();
|
||||||
|
array->Elements[m_elementId].Name = m_oldValue.toStdString();
|
||||||
|
m_item->setName(m_oldValue.toStdString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,4 +17,27 @@
|
||||||
#ifndef ACTIONS_H
|
#ifndef ACTIONS_H
|
||||||
#define ACTIONS_H
|
#define ACTIONS_H
|
||||||
|
|
||||||
|
#include <QtGui/QUndoCommand>
|
||||||
|
|
||||||
|
namespace GeorgesQt
|
||||||
|
{
|
||||||
|
class CFormItem;
|
||||||
|
|
||||||
|
class CUndoFormArrayRenameCommand : public QUndoCommand
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CUndoFormArrayRenameCommand(CFormItem *item, QString newValue, uint elementId, QUndoCommand *parent = 0);
|
||||||
|
~CUndoFormArrayRenameCommand() {}
|
||||||
|
|
||||||
|
void redo();
|
||||||
|
void undo();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CFormItem *m_item;
|
||||||
|
QString m_newValue;
|
||||||
|
QString m_oldValue;
|
||||||
|
uint m_elementId;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // ACTIONS_H
|
#endif // ACTIONS_H
|
|
@ -14,7 +14,10 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Project includes
|
||||||
#include "formitem.h"
|
#include "formitem.h"
|
||||||
|
#include "actions.h"
|
||||||
|
#include "georges_editor_form.h"
|
||||||
|
|
||||||
// Qt includes
|
// Qt includes
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
@ -81,13 +84,13 @@ namespace GeorgesQt
|
||||||
|
|
||||||
bool CFormItem::setData(int column, const QVariant &value)
|
bool CFormItem::setData(int column, const QVariant &value)
|
||||||
{
|
{
|
||||||
if (column != 0)
|
if(isEditable(column))
|
||||||
return false;
|
{
|
||||||
|
nlinfo("form item is editable.");
|
||||||
bool deleteInsert = false;
|
// Ensure that it is a child.
|
||||||
|
if (parentItem && parentItem->nodeType () == CFormItem::Form)
|
||||||
|
{
|
||||||
|
nlinfo("retrieving node information for data change.");
|
||||||
// Get the parent node
|
// Get the parent node
|
||||||
const NLGEORGES::CFormDfn *parentDfn;
|
const NLGEORGES::CFormDfn *parentDfn;
|
||||||
uint indexDfn;
|
uint indexDfn;
|
||||||
|
@ -95,21 +98,26 @@ namespace GeorgesQt
|
||||||
const NLGEORGES::CType *nodeType;
|
const NLGEORGES::CType *nodeType;
|
||||||
NLGEORGES::CFormElm *parentNode;
|
NLGEORGES::CFormElm *parentNode;
|
||||||
NLGEORGES::UFormDfn::TEntryType type;
|
NLGEORGES::UFormDfn::TEntryType type;
|
||||||
bool array;
|
bool isArray;
|
||||||
bool parentVDfnArray;
|
bool parentVDfnArray;
|
||||||
NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_form);
|
NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_form);
|
||||||
NLGEORGES::CFormElm *elm = static_cast<CFormElm*>(&form->getRootNode());
|
NLGEORGES::CFormElm *elm = static_cast<CFormElm*>(&form->getRootNode());
|
||||||
nlverify ( elm->getNodeByName (_FormName.c_str(), &parentDfn, indexDfn, &nodeDfn, &nodeType, &parentNode, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) );
|
|
||||||
|
|
||||||
if (parentItem && parentItem->nodeType () == CFormItem::Form)
|
// Lets check the parent first, for arrays.
|
||||||
|
nlverify ( elm->getNodeByName (parentItem->formName().c_str(), &parentDfn, indexDfn, &nodeDfn, &nodeType, &parentNode, type, isArray, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) );
|
||||||
|
|
||||||
|
if(isArray && parentNode)
|
||||||
{
|
{
|
||||||
std::string newName = value.toString().toStdString();
|
nlinfo( "is array and a child, generate rename command");
|
||||||
_Name = newName;
|
CUndoFormArrayRenameCommand *cmd = new CUndoFormArrayRenameCommand(this,value.toString(), _StructId);
|
||||||
|
GeorgesEditorForm::UndoStack->push(cmd);
|
||||||
// Create an action to update the form.
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CFormItem::isEditable(int column)
|
bool CFormItem::isEditable(int column)
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,9 +58,14 @@ namespace GeorgesQt
|
||||||
|
|
||||||
TSub nodeType() { return _Type; }
|
TSub nodeType() { return _Type; }
|
||||||
std::string formName() { return _FormName; }
|
std::string formName() { return _FormName; }
|
||||||
|
|
||||||
std::string name() { return _Name; }
|
std::string name() { return _Name; }
|
||||||
|
void setName(std::string name) { _Name = name; }
|
||||||
|
|
||||||
uint structId() { return _StructId; }
|
uint structId() { return _StructId; }
|
||||||
|
|
||||||
|
NLGEORGES::UForm *form() { return m_form; }
|
||||||
|
|
||||||
bool isEditable(int column);
|
bool isEditable(int column);
|
||||||
|
|
||||||
QIcon getItemImage(CFormItem *rootItem);
|
QIcon getItemImage(CFormItem *rootItem);
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
namespace GeorgesQt
|
namespace GeorgesQt
|
||||||
{
|
{
|
||||||
|
QUndoStack *GeorgesEditorForm::UndoStack = NULL;
|
||||||
|
|
||||||
GeorgesEditorForm::GeorgesEditorForm(QWidget *parent)
|
GeorgesEditorForm::GeorgesEditorForm(QWidget *parent)
|
||||||
: QMainWindow(parent),
|
: QMainWindow(parent),
|
||||||
|
@ -61,7 +62,7 @@ namespace GeorgesQt
|
||||||
m_mainDock->setDockNestingEnabled(true);
|
m_mainDock->setDockNestingEnabled(true);
|
||||||
layout->addWidget(m_mainDock);
|
layout->addWidget(m_mainDock);
|
||||||
|
|
||||||
m_undoStack = new QUndoStack(this);
|
UndoStack = new QUndoStack(this);
|
||||||
|
|
||||||
Core::MenuManager *menuManager = Core::ICore::instance()->menuManager();
|
Core::MenuManager *menuManager = Core::ICore::instance()->menuManager();
|
||||||
m_openAction = menuManager->action(Core::Constants::OPEN);
|
m_openAction = menuManager->action(Core::Constants::OPEN);
|
||||||
|
@ -114,7 +115,7 @@ namespace GeorgesQt
|
||||||
|
|
||||||
QUndoStack *GeorgesEditorForm::undoStack() const
|
QUndoStack *GeorgesEditorForm::undoStack() const
|
||||||
{
|
{
|
||||||
return m_undoStack;
|
return UndoStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeorgesEditorForm::open()
|
void GeorgesEditorForm::open()
|
||||||
|
@ -211,7 +212,7 @@ namespace GeorgesQt
|
||||||
}
|
}
|
||||||
|
|
||||||
CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock);
|
CGeorgesTreeViewDialog *dock = new CGeorgesTreeViewDialog(m_mainDock);
|
||||||
dock->setUndoStack(m_undoStack);
|
dock->setUndoStack(UndoStack);
|
||||||
m_lastActiveDock = dock;
|
m_lastActiveDock = dock;
|
||||||
m_dockedWidgets.append(dock);
|
m_dockedWidgets.append(dock);
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ public:
|
||||||
|
|
||||||
QUndoStack *undoStack() const;
|
QUndoStack *undoStack() const;
|
||||||
|
|
||||||
|
static QUndoStack *UndoStack;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void open();
|
void open();
|
||||||
void loadFile(const QString fileName);
|
void loadFile(const QString fileName);
|
||||||
|
@ -54,7 +56,6 @@ private:
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
|
|
||||||
QUndoStack *m_undoStack;
|
|
||||||
Ui::GeorgesEditorForm m_ui;
|
Ui::GeorgesEditorForm m_ui;
|
||||||
|
|
||||||
CGeorgesDirTreeDialog *m_georgesDirTreeDialog;
|
CGeorgesDirTreeDialog *m_georgesDirTreeDialog;
|
||||||
|
|
Loading…
Reference in a new issue