diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp index 1114d339b..f0dd0aabf 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -483,6 +483,18 @@ namespace GeorgesQt m_browserCtrl->clicked( idx ); } + void CGeorgesTreeViewDialog::onDeleteArrayEntry() + { + QModelIndex current = m_ui.treeView->currentIndex(); + QModelIndex parent = current.parent(); + + m_model->deleteArrayEntry( current ); + + m_ui.treeView->expandAll(); + m_ui.treeView->setCurrentIndex( parent ); + m_browserCtrl->clicked( parent ); + } + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) { Q_EMIT closing(); @@ -541,8 +553,9 @@ namespace GeorgesQt } else if(item->isArrayMember()) { - contextMenu.addAction("Delete array entry..."); - contextMenu.addAction("Insert after array entry..."); + QAction *deleteAction = contextMenu.addAction("Delete array entry..."); + connect( deleteAction, SIGNAL( triggered( bool ) ), this, SLOT( onDeleteArrayEntry() ) ); + //contextMenu.addAction("Insert after array entry..."); } // else if(item->getFormElm()->isStruct()) // { diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h index 739fa0e28..5e3e30ed8 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -105,6 +105,7 @@ namespace GeorgesQt void onArrayResized( const QString &name, int size ); void onAppendArray(); + void onDeleteArrayEntry(); private: Ui::CGeorgesTreeViewDialog m_ui; diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index f0f70b642..dfe581ed2 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -569,7 +569,50 @@ void CGeorgesFormModel::appendArray( QModelIndex idx ) item->add( CFormItem::Form, name.c_str(), s, formName.c_str(), 0, item->form(), false ); } +void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) +{ + CFormItem *item = reinterpret_cast< CFormItem* >( idx.internalPointer() ); + NLGEORGES::UFormElm &uroot = item->form()->getRootNode(); + NLGEORGES::CFormElm *root = static_cast< NLGEORGES::CFormElm* >( &item->form()->getRootNode() ); + NLGEORGES::UFormElm *unode; + uroot.getNodeByName( &unode, item->formName().c_str() ); + NLGEORGES::CFormElm *cnode = static_cast< NLGEORGES::CFormElm* >( unode ); + NLGEORGES::CFormElmArray *arr = static_cast< NLGEORGES::CFormElmArray* >( cnode->getParent() ); + + NLGEORGES::CFormElm *elm = arr->Elements[ idx.row() ].Element; + + Q_EMIT beginResetModel(); + + std::vector< NLGEORGES::CFormElmArray::CElement >::iterator itr = arr->Elements.begin() + idx.row(); + arr->Elements.erase( itr ); + + delete elm; + + item = item->parent(); + item->clearChildren(); + + NLGEORGES::CFormElmArray *celm = arr; + + for( int i = 0; i < celm->Elements.size(); i++ ) + { + NLGEORGES::CFormElmArray::CElement &e = celm->Elements[ i ]; + + QString formName = item->formName().c_str(); + formName += '['; + formName += QString::number( i ); + formName += ']'; + QString n; + if( e.Name.empty() ) + n = "#" + QString::number( i ); + else + n = e.Name.c_str(); + + item->add( CFormItem::Form, n.toUtf8().constData(), i, formName.toUtf8().constData(), 0, item->form(), false ); + } + + Q_EMIT endResetModel(); +} /******************************************************************************/ diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.h b/code/studio/src/plugins/georges_editor/georgesform_model.h index 03c4c592a..18b98735f 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -77,6 +77,7 @@ namespace GeorgesQt void arrayResized( const QString &name, int size ); void appendArray( QModelIndex idx ); + void deleteArrayEntry( QModelIndex idx ); private: void setupModelData();