mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-24 07:46:20 +00:00
Changed: #1306 Fixed index bug with form array rename.
This commit is contained in:
parent
882b31546f
commit
f2d5492b0c
4 changed files with 24 additions and 37 deletions
|
@ -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<NLGEORGES::CForm*>(item->form());
|
||||
if(!form)
|
||||
{
|
||||
nlinfo("failed to convert form.");
|
||||
return;
|
||||
}
|
||||
|
||||
NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_item->form());
|
||||
NLGEORGES::CFormElm *elm = static_cast<NLGEORGES::CFormElm*>(&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<NLGEORGES::CFormElmArray*> (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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue