From d221486a140cd81233b8f1f5b7897b59bd7bcc90 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Mon, 7 Jul 2014 12:07:29 +0200 Subject: [PATCH] Fixed problem in the idtable. --- apps/opencs/model/world/idtable.cpp | 40 +++++++++++++++++--------- apps/opencs/view/world/nestedtable.cpp | 3 +- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index a74bd629b4..c2eb32fa54 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -1,4 +1,5 @@ #include "idtable.hpp" +#include #include @@ -93,23 +94,34 @@ QVariant CSMWorld::IdTable::nestedHeaderData(int section, int subSection, Qt::Or bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value, int role) { - if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole) + if (index.internalId() != 0) { - if (index.internalId() == 0) - { - mIdCollection->setData (index.row(), index.column(), value); - - emit dataChanged (CSMWorld::IdTable::index (index.row(), 0), - CSMWorld::IdTable::index (index.row(), mIdCollection->getColumns()-1)); - } else + if (mIdCollection->getColumn(parent(index).column()).isEditable() && role==Qt::EditRole) { const std::pair& parentAdress(unfoldIndexAdress(index.internalId())); mIdCollection->setNestedData(parentAdress.first, parentAdress.second, value, index.row(), index.column()); - } - return true; - } + + emit dataChanged (CSMWorld::IdTable::index (parentAdress.first, 0), + CSMWorld::IdTable::index (parentAdress.second, mIdCollection->getColumns()-1)); + return true; + } else + { + return false; + } + } + + if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole) + { + mIdCollection->setData (index.row(), index.column(), value); + + emit dataChanged (CSMWorld::IdTable::index (index.row(), 0), + CSMWorld::IdTable::index (index.row(), mIdCollection->getColumns()-1)); + + return true; + } + return false; } @@ -131,9 +143,9 @@ bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& paren { for (int i = 0; i < count; ++i) { - mIdCollection->removeNestedRows(parent.row(), parent.column(), row+i); + mIdCollection->removeNestedRows(parent.row(), parent.column(), row+i); } - } else + } else { beginRemoveRows (parent, row, row+count-1); @@ -157,7 +169,7 @@ void CSMWorld::IdTable::addNestedRow(const QModelIndex& parent, int position) emit dataChanged (CSMWorld::IdTable::index (row, 0), CSMWorld::IdTable::index (row, mIdCollection->getColumns()-1)); - + endInsertRows(); } diff --git a/apps/opencs/view/world/nestedtable.cpp b/apps/opencs/view/world/nestedtable.cpp index a185fc7ce0..21bef504bc 100644 --- a/apps/opencs/view/world/nestedtable.cpp +++ b/apps/opencs/view/world/nestedtable.cpp @@ -7,6 +7,7 @@ #include #include #include +#include CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack, CSMWorld::NestedTableModel* model, @@ -32,7 +33,7 @@ CSVWorld::NestedTable::NestedTable(QUndoStack& undoStack, CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate(display, undoStack, this); - + setItemDelegateForColumn(i, delegate); }