From fd55c0cae2603562c7a648bf62c70bbbd33976a3 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 29 Nov 2012 18:56:28 +0100 Subject: [PATCH] record IDs are no longer handled as a special case --- apps/opencs/model/world/columns.hpp | 16 +++++++++++++++ apps/opencs/model/world/data.cpp | 1 + apps/opencs/model/world/idcollection.hpp | 6 +++++- apps/opencs/model/world/idtable.cpp | 26 +++++++----------------- apps/opencs/view/world/globals.cpp | 2 +- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/apps/opencs/model/world/columns.hpp b/apps/opencs/model/world/columns.hpp index 4d0ecb58eb..3220b3bba7 100644 --- a/apps/opencs/model/world/columns.hpp +++ b/apps/opencs/model/world/columns.hpp @@ -28,6 +28,22 @@ namespace CSMWorld } }; + template + struct StringIdColumn : public Column + { + StringIdColumn() : Column ("ID") {} + + virtual QVariant get (const Record& record) const + { + return record.get().mId.c_str(); + } + + virtual bool isEditable() const + { + return false; + } + }; + } #endif \ No newline at end of file diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 7fdb149b31..aeafc16761 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -12,6 +12,7 @@ CSMWorld::Data::Data() { + mGlobals.addColumn (new StringIdColumn); mGlobals.addColumn (new FloatValueColumn); mModels.insert (std::make_pair ( diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index ee6a4b2ce8..41cd352ced 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -24,7 +25,10 @@ namespace CSMWorld virtual QVariant get (const Record& record) const = 0; - virtual void set (Record& record, const QVariant& data) = 0; + virtual void set (Record& record, const QVariant& data) + { + throw std::logic_error ("Column " + mTitle + " is not editable"); + } virtual bool isEditable() const = 0; }; diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 8fdc4fb8ff..1fc2bfedbe 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -26,7 +26,7 @@ int CSMWorld::IdTable::columnCount (const QModelIndex & parent) const if (parent.isValid()) return 0; - return 1+mIdCollection->getColumns(); + return mIdCollection->getColumns(); } QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const @@ -34,19 +34,10 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const if (role!=Qt::DisplayRole && role!=Qt::EditRole) return QVariant(); - if (role==Qt::EditRole) - { - if (index.column()==0) + if (role==Qt::EditRole && !mIdCollection->isEditable (index.column())) return QVariant(); - if (!mIdCollection->isEditable (index.column()-1)) - return QVariant(); - } - - if (index.column()==0) - return QVariant (tr (mIdCollection->getId (index.row()).c_str())); - - return mIdCollection->getData (index.row(), index.column()-1); + return mIdCollection->getData (index.row(), index.column()); } QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation, int role) const @@ -57,17 +48,14 @@ QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation if (orientation==Qt::Vertical) return QVariant(); - if (section==0) - return QVariant (tr ("ID")); - - return tr (mIdCollection->getTitle (section-1).c_str()); + return tr (mIdCollection->getTitle (section).c_str()); } bool CSMWorld::IdTable::setData ( const QModelIndex &index, const QVariant &value, int role) { - if (index.column()>0 && role==Qt::EditRole) + if (mIdCollection->isEditable (index.column()) && role==Qt::EditRole) { - mIdCollection->setData (index.row(), index.column()-1, value); + mIdCollection->setData (index.row(), index.column(), value); emit dataChanged (index, index); return true; } @@ -79,7 +67,7 @@ Qt::ItemFlags CSMWorld::IdTable::flags (const QModelIndex & index) const { Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; - if (index.column()>0) + if (mIdCollection->isEditable (index.column())) flags |= Qt::ItemIsEditable; return flags; diff --git a/apps/opencs/view/world/globals.cpp b/apps/opencs/view/world/globals.cpp index a57f63dffe..459b8c3579 100644 --- a/apps/opencs/view/world/globals.cpp +++ b/apps/opencs/view/world/globals.cpp @@ -63,7 +63,7 @@ CSVWorld::Globals::Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& dat int columns = model->columnCount(); - for (int i=1; isetItemDelegateForColumn (i, delegate);