From a419c51a81fa8aa2edc36b334c45e5338267dab6 Mon Sep 17 00:00:00 2001 From: sfb Date: Fri, 28 Sep 2012 09:50:44 -0500 Subject: [PATCH] Changed: #1306 Fixed index bug with form array rename. --- .../src/plugins/georges_editor/actions.cpp | 40 +++++-------------- .../src/plugins/georges_editor/actions.h | 5 +-- .../georges_editor/georgesform_model.cpp | 15 ++++--- .../georges_editor/georgesform_model.h | 1 + 4 files changed, 24 insertions(+), 37 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.cpp index a55bc389a..9fe3b0fa6 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.cpp @@ -34,12 +34,9 @@ namespace GeorgesQt { - CUndoFormArrayRenameCommand::CUndoFormArrayRenameCommand(CGeorgesFormModel *model, const QModelIndex &index, const QVariant &value, uint elementId, QUndoCommand *parent) - : QUndoCommand(parent), m_model(model), m_elementId(elementId) + CUndoFormArrayRenameCommand::CUndoFormArrayRenameCommand(CGeorgesFormModel *model, CFormItem *item, const QVariant &value, QUndoCommand *parent) + : QUndoCommand("Rename Form Array Member", parent), m_model(model), m_item(item) { - m_row = index.row(); - m_col = index.column(); - m_newValue = value.toString(); } @@ -54,10 +51,7 @@ namespace GeorgesQt } void CUndoFormArrayRenameCommand::update(bool redo) - { - QModelIndex index = m_model->index(m_row, m_col); - CFormItem *item = m_model->getItem(index); - + { // Get the parent node const NLGEORGES::CFormDfn *parentDfn; uint indexDfn; @@ -67,41 +61,29 @@ namespace GeorgesQt NLGEORGES::UFormDfn::TEntryType type; bool isArray; bool vdfnArray; - NLGEORGES::CForm *form=static_cast(item->form()); - if(!form) - { - nlinfo("failed to convert form."); - return; - } - + NLGEORGES::CForm *form=static_cast(m_item->form()); NLGEORGES::CFormElm *elm = static_cast(&form->Elements); - if(!elm) - nlwarning("Failed to convert elm!"); - - nlverify ( elm->getNodeByName (item->formName().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray, vdfnArray, true, NLGEORGES_FIRST_ROUND) ); + nlverify ( elm->getNodeByName (m_item->formName().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray, vdfnArray, true, NLGEORGES_FIRST_ROUND) ); if (node) { std::string tmpName; node->getFormName(tmpName); - nlinfo("doing array rename on '%s'", tmpName.c_str()); NLGEORGES::CFormElmArray* array = static_cast (node->getParent ()); - if(!array) - nlwarning("the array is invalid."); // In the redo stage save the old value, just in case. if(redo) { // If the name of the element is empty then give it a nice default. - if(array->Elements[m_elementId].Name.empty()) + if(array->Elements[m_item->structId()].Name.empty()) { m_oldValue.append("#"); - m_oldValue.append(QString("%1").arg(m_elementId)); + m_oldValue.append(QString("%1").arg(m_item->structId())); } else { - m_oldValue = QString::fromStdString(array->Elements[m_elementId].Name); + m_oldValue = QString::fromStdString(array->Elements[m_item->structId()].Name); } } @@ -112,10 +94,10 @@ namespace GeorgesQt value = m_oldValue; - array->Elements[m_elementId].Name = value.toStdString(); - item->setName(value.toStdString()); + array->Elements[m_item->structId()].Name = value.toStdString(); + m_item->setName(value.toStdString()); - m_model->emitDataChanged(index); + m_model->emitDataChanged(m_model->index(m_item->row(), 0, m_item)); } } } \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.h index 43a19257d..0c57b0577 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/actions.h @@ -28,7 +28,7 @@ namespace GeorgesQt class CUndoFormArrayRenameCommand : public QUndoCommand { public: - CUndoFormArrayRenameCommand(CGeorgesFormModel *model, const QModelIndex &index, const QVariant &value, uint elementId, QUndoCommand *parent = 0); + CUndoFormArrayRenameCommand(CGeorgesFormModel *model, CFormItem *item, const QVariant &value, QUndoCommand *parent = 0); ~CUndoFormArrayRenameCommand() {} void redo(); @@ -37,12 +37,11 @@ namespace GeorgesQt void update(bool redo); protected: - int m_row, m_col; + CFormItem *m_item; CGeorgesFormModel *m_model; QString m_newValue; QString m_oldValue; - uint m_elementId; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp index b9511231b..387bc8917 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.cpp @@ -119,9 +119,8 @@ namespace GeorgesQt if(!item->isEditable(index.column())) return false; - - //bool result = item->setData(index.column(), value); - GeorgesEditorForm::UndoStack->push(new CUndoFormArrayRenameCommand(this,index,value,item->structId())); + + GeorgesEditorForm::UndoStack->push(new CUndoFormArrayRenameCommand(this,item,value)); Q_EMIT dataChanged(index, index); @@ -214,6 +213,14 @@ namespace GeorgesQt return QModelIndex(); } + QModelIndex CGeorgesFormModel::index(int row, int column, CFormItem *item) const + { + if(item == m_rootItem) + return QModelIndex(); + + return createIndex(row, 0, item); + } + /******************************************************************************/ QModelIndex CGeorgesFormModel::parent(const QModelIndex &index) const @@ -278,8 +285,6 @@ namespace GeorgesQt // Add the new node CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form); - nlinfo("Added form %s : %s", name, formName); - // Can be NULL in virtual DFN if (parentDfn) { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h index 6c6c2817d..07589b63c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/georges_editor/georgesform_model.h @@ -50,6 +50,7 @@ namespace GeorgesQt Qt::ItemFlags flags(const QModelIndex &index) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex index(int row, int column, CFormItem *item) const; QModelIndex parent(const QModelIndex &index) const; int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;