From 127e0b48efec09a4ce38b050e7e6458bc5d02c55 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 27 Aug 2014 20:24:05 +0200 Subject: [PATCH] Implemented rename context menu. --- .../georges_treeview_dialog.cpp | 22 +++++++++++++++ .../georges_editor/georges_treeview_dialog.h | 1 + .../georges_editor/georgesform_model.cpp | 28 +++++++++++++++++++ .../georges_editor/georgesform_model.h | 1 + 4 files changed, 52 insertions(+) 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 6dbbe4899..9450eeec2 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -516,6 +516,25 @@ namespace GeorgesQt log( key + " = " + value ); } + void CGeorgesTreeViewDialog::onRenameArrayEntry() + { + QModelIndex idx = m_ui.treeView->currentIndex(); + + CFormItem *item = static_cast< CFormItem* >( idx.internalPointer() ); + + QString newName = QInputDialog::getText( this, + tr( "Rename" ), + tr( "Enter new name" ), + QLineEdit::Normal, + item->name().c_str() ); + + m_model->renameArrayEntry( idx, newName ); + + QString formName = item->formName().c_str(); + + log( formName + " renamed = " + newName ); + } + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) { Q_EMIT closing(); @@ -576,6 +595,9 @@ namespace GeorgesQt { QAction *deleteAction = contextMenu.addAction("Delete array entry..."); connect( deleteAction, SIGNAL( triggered( bool ) ), this, SLOT( onDeleteArrayEntry() ) ); + + QAction *renameAction = contextMenu.addAction("Rename"); + connect( renameAction, SIGNAL( triggered( bool ) ), this, SLOT( onRenameArrayEntry() ) ); //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 17923e429..c3e9937ef 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -107,6 +107,7 @@ namespace GeorgesQt void onAppendArray(); void onDeleteArrayEntry(); void onValueChanged( const QString &key, const QString &value ); + void onRenameArrayEntry(); private: void log( const QString &msg ); diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index dfe581ed2..f00e090f2 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -614,6 +614,34 @@ void CGeorgesFormModel::deleteArrayEntry( QModelIndex idx ) Q_EMIT endResetModel(); } +void CGeorgesFormModel::renameArrayEntry( QModelIndex idx, const QString &name ) +{ + CFormItem *item = static_cast< CFormItem* >( idx.internalPointer() ); + + NLGEORGES::UFormElm *elm; + + item->form()->getRootNode().getNodeByName( &elm, item->formName().c_str() ); + + NLGEORGES::CFormElm *celm = dynamic_cast< NLGEORGES::CFormElm* >( elm ); + if( celm == NULL ) + return; + + NLGEORGES::UFormElm *uparent = celm->getParent(); + NLGEORGES::CFormElmArray *cparent = dynamic_cast< NLGEORGES::CFormElmArray* >( uparent ); + if( cparent == NULL ) + return; + + int i = 0; + for( i = 0; i < cparent->Elements.size(); i++ ) + { + if( cparent->Elements[ i ].Element == celm ) + break; + } + + cparent->Elements[ i ].Name = name.toUtf8().constData(); + item->setName( name.toUtf8().constData() ); +} + /******************************************************************************/ void CGeorgesFormModel::loadFormHeader() diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.h b/code/studio/src/plugins/georges_editor/georgesform_model.h index 18b98735f..dc4b67a62 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -78,6 +78,7 @@ namespace GeorgesQt void arrayResized( const QString &name, int size ); void appendArray( QModelIndex idx ); void deleteArrayEntry( QModelIndex idx ); + void renameArrayEntry( QModelIndex idx, const QString &name ); private: void setupModelData();