diff --git a/apps/opencs/model/world/idcollection.cpp b/apps/opencs/model/world/idcollection.cpp index fc4bb1ef65..c6469ea984 100644 --- a/apps/opencs/model/world/idcollection.cpp +++ b/apps/opencs/model/world/idcollection.cpp @@ -1,6 +1,17 @@ #include "idcollection.hpp" +CSMWorld::ColumnBase::ColumnBase (const std::string& title, int flags) +: mTitle (title), mFlags (flags) +{} + +CSMWorld::ColumnBase::~ColumnBase() {} + +bool CSMWorld::ColumnBase::isUserEditable() const +{ + return isEditable(); +} + CSMWorld::IdCollectionBase::IdCollectionBase() {} CSMWorld::IdCollectionBase::~IdCollectionBase() {} \ No newline at end of file diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 529e474d56..5d6f52aa0f 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -15,21 +15,25 @@ namespace CSMWorld { - template - struct Column + struct ColumnBase { - std::string mTitle; - - Column (const std::string& title) : mTitle (title) {} - - virtual ~Column() {} - - virtual QVariant get (const Record& record) const = 0; - - virtual void set (Record& record, const QVariant& data) + enum Roles { - throw std::logic_error ("Column " + mTitle + " is not editable"); - } + Role_Flags = Qt::UserRole + }; + + enum Flags + { + Flag_Table = 1, // column should be displayed in table view + Flag_Dialogue = 2 // column should be displayed in dialogue view + }; + + std::string mTitle; + int mFlags; + + ColumnBase (const std::string& title, int flag); + + virtual ~ColumnBase(); virtual bool isEditable() const = 0; @@ -38,10 +42,21 @@ namespace CSMWorld }; template - bool Column::isUserEditable() const + struct Column : public ColumnBase { - return isEditable(); - } + std::string mTitle; + int mFlags; + + Column (const std::string& title, int flags = Flag_Table | Flag_Dialogue) + : ColumnBase (title, flags) {} + + virtual QVariant get (const Record& record) const = 0; + + virtual void set (Record& record, const QVariant& data) + { + throw std::logic_error ("Column " + mTitle + " is not editable"); + } + }; class IdCollectionBase { @@ -63,16 +78,12 @@ namespace CSMWorld virtual int getColumns() const = 0; - virtual std::string getTitle (int column) const = 0; + virtual const ColumnBase& getColumn (int column) const = 0; virtual QVariant getData (int index, int column) const = 0; virtual void setData (int index, int column, const QVariant& data) = 0; - virtual bool isEditable (int column) const = 0; - - virtual bool isUserEditable (int column) const = 0; - virtual void merge() = 0; ///< Merge modified into base. @@ -136,11 +147,7 @@ namespace CSMWorld virtual void setData (int index, int column, const QVariant& data); - virtual std::string getTitle (int column) const; - - virtual bool isEditable (int column) const; - - virtual bool isUserEditable (int column) const; + virtual const ColumnBase& getColumn (int column) const; virtual void merge(); ///< Merge modified into base. @@ -252,21 +259,9 @@ namespace CSMWorld } template - std::string IdCollection::getTitle (int column) const + const ColumnBase& IdCollection::getColumn (int column) const { - return mColumns.at (column)->mTitle; - } - - template - bool IdCollection::isEditable (int column) const - { - return mColumns.at (column)->isEditable(); - } - - template - bool IdCollection::isUserEditable (int column) const - { - return mColumns.at (column)->isUserEditable(); + return *mColumns.at (column); } template diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 3ec2f3d170..2815e318c8 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -34,7 +34,7 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const if (role!=Qt::DisplayRole && role!=Qt::EditRole) return QVariant(); - if (role==Qt::EditRole && !mIdCollection->isEditable (index.column())) + if (role==Qt::EditRole && !mIdCollection->getColumn (index.column()).isEditable()) return QVariant(); return mIdCollection->getData (index.row(), index.column()); @@ -42,18 +42,21 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation, int role) const { - if (role!=Qt::DisplayRole) - return QVariant(); - if (orientation==Qt::Vertical) return QVariant(); - return tr (mIdCollection->getTitle (section).c_str()); + if (role==Qt::DisplayRole) + return tr (mIdCollection->getColumn (section).mTitle.c_str()); + + if (role==ColumnBase::Role_Flags) + return mIdCollection->getColumn (section).mFlags; + + return QVariant(); } bool CSMWorld::IdTable::setData ( const QModelIndex &index, const QVariant &value, int role) { - if (mIdCollection->isEditable (index.column()) && role==Qt::EditRole) + if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole) { mIdCollection->setData (index.row(), index.column(), value); @@ -70,7 +73,7 @@ Qt::ItemFlags CSMWorld::IdTable::flags (const QModelIndex & index) const { Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; - if (mIdCollection->isUserEditable (index.column())) + if (mIdCollection->getColumn (index.column()).isUserEditable()) flags |= Qt::ItemIsEditable; return flags;