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
|
namespace GeorgesQt
|
||||||
{
|
{
|
||||||
|
|
||||||
CUndoFormArrayRenameCommand::CUndoFormArrayRenameCommand(CGeorgesFormModel *model, const QModelIndex &index, const QVariant &value, uint elementId, QUndoCommand *parent)
|
CUndoFormArrayRenameCommand::CUndoFormArrayRenameCommand(CGeorgesFormModel *model, CFormItem *item, const QVariant &value, QUndoCommand *parent)
|
||||||
: QUndoCommand(parent), m_model(model), m_elementId(elementId)
|
: QUndoCommand("Rename Form Array Member", parent), m_model(model), m_item(item)
|
||||||
{
|
{
|
||||||
m_row = index.row();
|
|
||||||
m_col = index.column();
|
|
||||||
|
|
||||||
m_newValue = value.toString();
|
m_newValue = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +52,6 @@ namespace GeorgesQt
|
||||||
|
|
||||||
void CUndoFormArrayRenameCommand::update(bool redo)
|
void CUndoFormArrayRenameCommand::update(bool redo)
|
||||||
{
|
{
|
||||||
QModelIndex index = m_model->index(m_row, m_col);
|
|
||||||
CFormItem *item = m_model->getItem(index);
|
|
||||||
|
|
||||||
// Get the parent node
|
// Get the parent node
|
||||||
const NLGEORGES::CFormDfn *parentDfn;
|
const NLGEORGES::CFormDfn *parentDfn;
|
||||||
uint indexDfn;
|
uint indexDfn;
|
||||||
|
@ -67,41 +61,29 @@ namespace GeorgesQt
|
||||||
NLGEORGES::UFormDfn::TEntryType type;
|
NLGEORGES::UFormDfn::TEntryType type;
|
||||||
bool isArray;
|
bool isArray;
|
||||||
bool vdfnArray;
|
bool vdfnArray;
|
||||||
NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(item->form());
|
NLGEORGES::CForm *form=static_cast<NLGEORGES::CForm*>(m_item->form());
|
||||||
if(!form)
|
|
||||||
{
|
|
||||||
nlinfo("failed to convert form.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
NLGEORGES::CFormElm *elm = static_cast<NLGEORGES::CFormElm*>(&form->Elements);
|
NLGEORGES::CFormElm *elm = static_cast<NLGEORGES::CFormElm*>(&form->Elements);
|
||||||
|
|
||||||
if(!elm)
|
nlverify ( elm->getNodeByName (m_item->formName().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray, vdfnArray, true, NLGEORGES_FIRST_ROUND) );
|
||||||
nlwarning("Failed to convert elm!");
|
|
||||||
|
|
||||||
nlverify ( elm->getNodeByName (item->formName().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, isArray, vdfnArray, true, NLGEORGES_FIRST_ROUND) );
|
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
std::string tmpName;
|
std::string tmpName;
|
||||||
node->getFormName(tmpName);
|
node->getFormName(tmpName);
|
||||||
nlinfo("doing array rename on '%s'", tmpName.c_str());
|
|
||||||
|
|
||||||
NLGEORGES::CFormElmArray* array = static_cast<NLGEORGES::CFormElmArray*> (node->getParent ());
|
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.
|
// In the redo stage save the old value, just in case.
|
||||||
if(redo)
|
if(redo)
|
||||||
{
|
{
|
||||||
// If the name of the element is empty then give it a nice default.
|
// 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("#");
|
||||||
m_oldValue.append(QString("%1").arg(m_elementId));
|
m_oldValue.append(QString("%1").arg(m_item->structId()));
|
||||||
}
|
}
|
||||||
else
|
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;
|
value = m_oldValue;
|
||||||
|
|
||||||
|
|
||||||
array->Elements[m_elementId].Name = value.toStdString();
|
array->Elements[m_item->structId()].Name = value.toStdString();
|
||||||
item->setName(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
|
class CUndoFormArrayRenameCommand : public QUndoCommand
|
||||||
{
|
{
|
||||||
public:
|
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() {}
|
~CUndoFormArrayRenameCommand() {}
|
||||||
|
|
||||||
void redo();
|
void redo();
|
||||||
|
@ -37,12 +37,11 @@ namespace GeorgesQt
|
||||||
void update(bool redo);
|
void update(bool redo);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int m_row, m_col;
|
CFormItem *m_item;
|
||||||
CGeorgesFormModel *m_model;
|
CGeorgesFormModel *m_model;
|
||||||
|
|
||||||
QString m_newValue;
|
QString m_newValue;
|
||||||
QString m_oldValue;
|
QString m_oldValue;
|
||||||
uint m_elementId;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -120,8 +120,7 @@ namespace GeorgesQt
|
||||||
if(!item->isEditable(index.column()))
|
if(!item->isEditable(index.column()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//bool result = item->setData(index.column(), value);
|
GeorgesEditorForm::UndoStack->push(new CUndoFormArrayRenameCommand(this,item,value));
|
||||||
GeorgesEditorForm::UndoStack->push(new CUndoFormArrayRenameCommand(this,index,value,item->structId()));
|
|
||||||
|
|
||||||
Q_EMIT dataChanged(index, index);
|
Q_EMIT dataChanged(index, index);
|
||||||
|
|
||||||
|
@ -214,6 +213,14 @@ namespace GeorgesQt
|
||||||
return QModelIndex();
|
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
|
QModelIndex CGeorgesFormModel::parent(const QModelIndex &index) const
|
||||||
|
@ -278,8 +285,6 @@ namespace GeorgesQt
|
||||||
// Add the new node
|
// Add the new node
|
||||||
CFormItem *newNode = parent->add(CFormItem::Form, name, structId, formName, slot, m_form);
|
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
|
// Can be NULL in virtual DFN
|
||||||
if (parentDfn)
|
if (parentDfn)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,7 @@ namespace GeorgesQt
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) 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, const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
QModelIndex index(int row, int column, CFormItem *item) const;
|
||||||
QModelIndex parent(const QModelIndex &index) const;
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
|
Loading…
Reference in a new issue