rewrote column class

actorid
Marc Zinnschlag 12 years ago
parent 640c218df3
commit faa5ef0874

@ -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() {}

@ -15,21 +15,25 @@
namespace CSMWorld
{
template<typename ESXRecordT>
struct Column
struct ColumnBase
{
std::string mTitle;
enum Roles
{
Role_Flags = Qt::UserRole
};
Column (const std::string& title) : mTitle (title) {}
enum Flags
{
Flag_Table = 1, // column should be displayed in table view
Flag_Dialogue = 2 // column should be displayed in dialogue view
};
virtual ~Column() {}
std::string mTitle;
int mFlags;
virtual QVariant get (const Record<ESXRecordT>& record) const = 0;
ColumnBase (const std::string& title, int flag);
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
{
throw std::logic_error ("Column " + mTitle + " is not editable");
}
virtual ~ColumnBase();
virtual bool isEditable() const = 0;
@ -38,10 +42,21 @@ namespace CSMWorld
};
template<typename ESXRecordT>
bool Column<ESXRecordT>::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<ESXRecordT>& record) const = 0;
virtual void set (Record<ESXRecordT>& 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<typename ESXRecordT>
std::string IdCollection<ESXRecordT>::getTitle (int column) const
{
return mColumns.at (column)->mTitle;
}
template<typename ESXRecordT>
bool IdCollection<ESXRecordT>::isEditable (int column) const
{
return mColumns.at (column)->isEditable();
}
template<typename ESXRecordT>
bool IdCollection<ESXRecordT>::isUserEditable (int column) const
const ColumnBase& IdCollection<ESXRecordT>::getColumn (int column) const
{
return mColumns.at (column)->isUserEditable();
return *mColumns.at (column);
}
template<typename ESXRecordT>

@ -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;

Loading…
Cancel
Save