From 4327b81bc3a4decb476dca3a2ec46e9dc63c51bc Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 25 Jul 2013 14:38:53 +0200 Subject: [PATCH] fixed column handling in table (had problems with filtered out columns before) --- apps/opencs/view/world/table.cpp | 56 ++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 9085592df6..d8a840be4d 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -44,20 +44,30 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) std::vector CSVWorld::Table::listRevertableSelectedIds() const { - /// \todo columns filtering fixes - QModelIndexList selectedRows = selectionModel()->selectedRows(); - + /// \todo Do not use hardcoded column numbers std::vector revertableIds; - for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter) + if (mProxyModel->columnCount()>0) { - std::string id = mProxyModel->data (*iter).toString().toStdString(); + QModelIndexList selectedRows = selectionModel()->selectedRows(); - CSMWorld::RecordBase::State state = - static_cast (mModel->data (mModel->getModelIndex (id, 1)).toInt()); + for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); + ++iter) + { + QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)); - if (state!=CSMWorld::RecordBase::State_BaseOnly) - revertableIds.push_back (id); + CSMWorld::RecordBase::State state = + static_cast ( + mModel->data (mModel->index (index.row(), 1)).toInt()); + + if (state!=CSMWorld::RecordBase::State_BaseOnly) + { + std::string id = mModel->data (mModel->index (index.row(), 0)). + toString().toUtf8().constData(); + + revertableIds.push_back (id); + } + } } return revertableIds; @@ -65,20 +75,30 @@ std::vector CSVWorld::Table::listRevertableSelectedIds() const std::vector CSVWorld::Table::listDeletableSelectedIds() const { - /// \todo columns filtering fixes - QModelIndexList selectedRows = selectionModel()->selectedRows(); - + /// \todo Do not use hardcoded column numbers std::vector deletableIds; - for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter) + if (mProxyModel->columnCount()>0) { - std::string id = mProxyModel->data (*iter).toString().toStdString(); + QModelIndexList selectedRows = selectionModel()->selectedRows(); - CSMWorld::RecordBase::State state = - static_cast (mModel->data (mModel->getModelIndex (id, 1)).toInt()); + for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); + ++iter) + { + QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)); - if (state!=CSMWorld::RecordBase::State_Deleted) - deletableIds.push_back (id); + CSMWorld::RecordBase::State state = + static_cast ( + mModel->data (mModel->index (index.row(), 1)).toInt()); + + if (state!=CSMWorld::RecordBase::State_Deleted) + { + std::string id = mModel->data (mModel->index (index.row(), 0)). + toString().toUtf8().constData(); + + deletableIds.push_back (id); + } + } } return deletableIds;