From 95afca0558c732af60a2fb5c4b5589185f6d7a26 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 17 Mar 2014 19:28:41 +0100 Subject: [PATCH] delete record button --- apps/opencs/view/world/dialoguesubview.cpp | 26 +++++++++++++++++++++- apps/opencs/view/world/dialoguesubview.hpp | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index 8f602aa8d3..6bd8001c7a 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -418,6 +418,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM connect(prevButton, SIGNAL(clicked()), this, SLOT(prevId())); connect(revertButton, SIGNAL(clicked()), this, SLOT(revertRecord())); + connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteRecord())); mMainLayout = new QVBoxLayout(mainWidget); @@ -550,7 +551,30 @@ void CSVWorld::DialogueSubView::revertRecord() { if (mTable->rowCount() == 0) { - mEditWidget->setDisabled(true); + mEditWidget->setDisabled(true); //closing the editor is other option + return; + } + if (mRow >= mTable->rowCount()) + { + prevId(); + } else { + dataChanged(mTable->index(mRow, 0)); + } + } + } +} + +void CSVWorld::DialogueSubView::deleteRecord() +{ + int rows = mTable->rowCount(); + if (!mLocked && mTable->columnCount() > 0 && mRow < mTable->rowCount() ) + { + mUndoStack.push(new CSMWorld::DeleteCommand(*mTable, mTable->data(mTable->index (mRow, 0)).toString().toStdString())); + if (rows != mTable->rowCount()) + { + if (mTable->rowCount() == 0) + { + mEditWidget->setDisabled(true); //closing the editor is other option return; } if (mRow >= mTable->rowCount()) diff --git a/apps/opencs/view/world/dialoguesubview.hpp b/apps/opencs/view/world/dialoguesubview.hpp index b7920a3874..bf6e70e0d3 100644 --- a/apps/opencs/view/world/dialoguesubview.hpp +++ b/apps/opencs/view/world/dialoguesubview.hpp @@ -180,6 +180,7 @@ namespace CSVWorld void prevId(); void revertRecord(); + void deleteRecord(); void dataChanged(const QModelIndex & index); ///\brief we need to care for deleting currently edited record