mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-10 15:39:02 +00:00
104 lines
2.3 KiB
C++
104 lines
2.3 KiB
C++
|
|
#include "idtable.hpp"
|
|
|
|
#include "idcollection.hpp"
|
|
|
|
CSMWorld::IdTable::IdTable (IdCollectionBase *idCollection) : mIdCollection (idCollection)
|
|
{
|
|
|
|
}
|
|
|
|
CSMWorld::IdTable::~IdTable()
|
|
{
|
|
|
|
}
|
|
|
|
int CSMWorld::IdTable::rowCount (const QModelIndex & parent) const
|
|
{
|
|
if (parent.isValid())
|
|
return 0;
|
|
|
|
return mIdCollection->getSize();
|
|
}
|
|
|
|
int CSMWorld::IdTable::columnCount (const QModelIndex & parent) const
|
|
{
|
|
if (parent.isValid())
|
|
return 0;
|
|
|
|
return mIdCollection->getColumns();
|
|
}
|
|
|
|
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()))
|
|
return QVariant();
|
|
|
|
return mIdCollection->getData (index.row(), index.column());
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
bool CSMWorld::IdTable::setData ( const QModelIndex &index, const QVariant &value, int role)
|
|
{
|
|
if (mIdCollection->isEditable (index.column()) && role==Qt::EditRole)
|
|
{
|
|
mIdCollection->setData (index.row(), index.column(), value);
|
|
emit dataChanged (index, index);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
Qt::ItemFlags CSMWorld::IdTable::flags (const QModelIndex & index) const
|
|
{
|
|
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
if (mIdCollection->isEditable (index.column()))
|
|
flags |= Qt::ItemIsEditable;
|
|
|
|
return flags;
|
|
}
|
|
|
|
bool CSMWorld::IdTable::removeRows (int row, int count, const QModelIndex& parent)
|
|
{
|
|
if (parent.isValid())
|
|
return false;
|
|
|
|
beginRemoveRows (parent, row, row+count-1);
|
|
|
|
mIdCollection->removeRows (row, count);
|
|
|
|
endRemoveRows();
|
|
|
|
return true;
|
|
}
|
|
|
|
void CSMWorld::IdTable::addRecord (const std::string& id)
|
|
{
|
|
int index = mIdCollection->getSize();
|
|
|
|
beginInsertRows (QModelIndex(), index, index);
|
|
|
|
mIdCollection->appendBlankRecord (id);
|
|
|
|
endInsertRows();
|
|
}
|
|
|
|
QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column) const
|
|
{
|
|
return index (mIdCollection->getIndex (id), column);
|
|
} |