From f913d51e354b9e5db2b1226e5b1707a032c0d49d Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 7 Sep 2014 12:55:52 +0200 Subject: [PATCH] remove deleted debug profiles from run tool --- apps/opencs/view/render/worldspacewidget.cpp | 55 ++++++++++++++++++++ apps/opencs/view/render/worldspacewidget.hpp | 6 +++ apps/opencs/view/widget/scenetoolrun.cpp | 19 +++++++ apps/opencs/view/widget/scenetoolrun.hpp | 2 + 4 files changed, 82 insertions(+) diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 40324f4158..fd7ead6e5b 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -42,6 +42,14 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg this, SLOT (referenceAboutToBeRemoved (const QModelIndex&, int, int))); connect (references, SIGNAL (rowsInserted (const QModelIndex&, int, int)), this, SLOT (referenceAdded (const QModelIndex&, int, int))); + + QAbstractItemModel *debugProfiles = + document.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles); + + connect (debugProfiles, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), + this, SLOT (debugProfileDataChanged (const QModelIndex&, const QModelIndex&))); + connect (debugProfiles, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)), + this, SLOT (debugProfileAboutToBeRemoved (const QModelIndex&, int, int))); } void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode) @@ -248,6 +256,53 @@ void CSVRender::WorldspaceWidget::runRequest (const std::string& profile) mDocument.startRunning (profile, getStartupInstruction()); } +void CSVRender::WorldspaceWidget::debugProfileDataChanged (const QModelIndex& topLeft, + const QModelIndex& bottomRight) +{ + if (!mRun) + return; + + CSMWorld::IdTable& debugProfiles = dynamic_cast ( + *mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles)); + + int idColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Id); + int stateColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Modification); + + for (int i=topLeft.row(); i<=bottomRight.row(); ++i) + { + int state = debugProfiles.data (debugProfiles.index (i, stateColumn)).toInt(); + + // As of version 0.33 this case can not happen because debug profiles exist only in + // project or session scope, which means they will never be in deleted state. But we + // are adding the code for the sake of completeness and to avoid surprises if debug + // profile ever get extended to content scope. + if (state==CSMWorld::RecordBase::State_Deleted) + mRun->removeProfile (debugProfiles.data ( + debugProfiles.index (i, idColumn)).toString().toUtf8().constData()); + } +} + +void CSVRender::WorldspaceWidget::debugProfileAboutToBeRemoved (const QModelIndex& parent, + int start, int end) +{ + if (parent.isValid()) + return; + + if (!mRun) + return; + + CSMWorld::IdTable& debugProfiles = dynamic_cast ( + *mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_DebugProfiles)); + + int idColumn = debugProfiles.findColumnIndex (CSMWorld::Columns::ColumnId_Id); + + for (int i=start; i<=end; ++i) + { + mRun->removeProfile (debugProfiles.data ( + debugProfiles.index (i, idColumn)).toString().toUtf8().constData()); + } +} + void CSVRender::WorldspaceWidget::elementSelectionChanged() { setVisibilityMask (getElementMask()); diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index 0c74b24bcc..d730b21a8e 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -113,6 +113,12 @@ namespace CSVRender virtual void runRequest (const std::string& profile); + void debugProfileDataChanged (const QModelIndex& topLeft, + const QModelIndex& bottomRight); + + void debugProfileAboutToBeRemoved (const QModelIndex& parent, int start, int end); + + protected slots: void elementSelectionChanged(); diff --git a/apps/opencs/view/widget/scenetoolrun.cpp b/apps/opencs/view/widget/scenetoolrun.cpp index b2f4675598..ce2dbe76f7 100644 --- a/apps/opencs/view/widget/scenetoolrun.cpp +++ b/apps/opencs/view/widget/scenetoolrun.cpp @@ -33,3 +33,22 @@ void CSVWidget::SceneToolRun::showPanel (const QPoint& position) if (mCurrentIndex!=-1) emit runRequest (mProfiles[mCurrentIndex]); } + +void CSVWidget::SceneToolRun::removeProfile (const std::string& profile) +{ + std::pair::iterator, std::vector::iterator> + result = std::equal_range (mProfiles.begin(), mProfiles.end(), profile); + + if (result.first!=result.second) + { + mProfiles.erase (result.first); + + if (mCurrentIndex>=static_cast (mProfiles.size())) + --mCurrentIndex; + + if (mCurrentIndex==-1) + updateIcon(); + + adjustToolTips(); + } +} \ No newline at end of file diff --git a/apps/opencs/view/widget/scenetoolrun.hpp b/apps/opencs/view/widget/scenetoolrun.hpp index cf16a172d6..50008dae91 100644 --- a/apps/opencs/view/widget/scenetoolrun.hpp +++ b/apps/opencs/view/widget/scenetoolrun.hpp @@ -31,6 +31,8 @@ namespace CSVWidget virtual void showPanel (const QPoint& position); + void removeProfile (const std::string& profile); + signals: void runRequest (const std::string& profile);