mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 10:53:51 +00:00
rewrote column class
This commit is contained in:
parent
640c218df3
commit
faa5ef0874
3 changed files with 56 additions and 47 deletions
|
@ -1,6 +1,17 @@
|
||||||
|
|
||||||
#include "idcollection.hpp"
|
#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() {}
|
||||||
|
|
||||||
CSMWorld::IdCollectionBase::~IdCollectionBase() {}
|
CSMWorld::IdCollectionBase::~IdCollectionBase() {}
|
|
@ -15,21 +15,25 @@
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
template<typename ESXRecordT>
|
struct ColumnBase
|
||||||
struct Column
|
|
||||||
{
|
{
|
||||||
|
enum Roles
|
||||||
|
{
|
||||||
|
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;
|
std::string mTitle;
|
||||||
|
int mFlags;
|
||||||
|
|
||||||
Column (const std::string& title) : mTitle (title) {}
|
ColumnBase (const std::string& title, int flag);
|
||||||
|
|
||||||
virtual ~Column() {}
|
virtual ~ColumnBase();
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool isEditable() const = 0;
|
virtual bool isEditable() const = 0;
|
||||||
|
|
||||||
|
@ -38,10 +42,21 @@ namespace CSMWorld
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ESXRecordT>
|
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
|
class IdCollectionBase
|
||||||
{
|
{
|
||||||
|
@ -63,16 +78,12 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual int getColumns() const = 0;
|
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 QVariant getData (int index, int column) const = 0;
|
||||||
|
|
||||||
virtual void setData (int index, int column, const QVariant& data) = 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;
|
virtual void merge() = 0;
|
||||||
///< Merge modified into base.
|
///< Merge modified into base.
|
||||||
|
|
||||||
|
@ -136,11 +147,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
virtual void setData (int index, int column, const QVariant& data);
|
virtual void setData (int index, int column, const QVariant& data);
|
||||||
|
|
||||||
virtual std::string getTitle (int column) const;
|
virtual const ColumnBase& getColumn (int column) const;
|
||||||
|
|
||||||
virtual bool isEditable (int column) const;
|
|
||||||
|
|
||||||
virtual bool isUserEditable (int column) const;
|
|
||||||
|
|
||||||
virtual void merge();
|
virtual void merge();
|
||||||
///< Merge modified into base.
|
///< Merge modified into base.
|
||||||
|
@ -252,21 +259,9 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ESXRecordT>
|
template<typename ESXRecordT>
|
||||||
std::string IdCollection<ESXRecordT>::getTitle (int column) const
|
const ColumnBase& IdCollection<ESXRecordT>::getColumn (int column) const
|
||||||
{
|
{
|
||||||
return mColumns.at (column)->mTitle;
|
return *mColumns.at (column);
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
return mColumns.at (column)->isUserEditable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ESXRecordT>
|
template<typename ESXRecordT>
|
||||||
|
|
|
@ -34,7 +34,7 @@ QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const
|
||||||
if (role!=Qt::DisplayRole && role!=Qt::EditRole)
|
if (role!=Qt::DisplayRole && role!=Qt::EditRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (role==Qt::EditRole && !mIdCollection->isEditable (index.column()))
|
if (role==Qt::EditRole && !mIdCollection->getColumn (index.column()).isEditable())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
return mIdCollection->getData (index.row(), index.column());
|
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
|
QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (role!=Qt::DisplayRole)
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
if (orientation==Qt::Vertical)
|
if (orientation==Qt::Vertical)
|
||||||
return QVariant();
|
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)
|
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);
|
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;
|
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
|
|
||||||
if (mIdCollection->isUserEditable (index.column()))
|
if (mIdCollection->getColumn (index.column()).isUserEditable())
|
||||||
flags |= Qt::ItemIsEditable;
|
flags |= Qt::ItemIsEditable;
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
|
|
Loading…
Reference in a new issue