2012-11-26 11:29:22 +00:00
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2012-11-29 17:56:28 +00:00
|
|
|
return mIdCollection->getColumns();
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CSMWorld::IdTable::data (const QModelIndex & index, int role) const
|
|
|
|
{
|
2012-11-29 13:45:34 +00:00
|
|
|
if (role!=Qt::DisplayRole && role!=Qt::EditRole)
|
2012-11-26 11:29:22 +00:00
|
|
|
return QVariant();
|
|
|
|
|
2012-12-13 13:53:16 +00:00
|
|
|
if (role==Qt::EditRole && !mIdCollection->getColumn (index.column()).isEditable())
|
2012-12-11 14:35:47 +00:00
|
|
|
return QVariant();
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2012-11-29 17:56:28 +00:00
|
|
|
return mIdCollection->getData (index.row(), index.column());
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation, int role) const
|
|
|
|
{
|
|
|
|
if (orientation==Qt::Vertical)
|
|
|
|
return QVariant();
|
|
|
|
|
2012-12-13 13:53:16 +00:00
|
|
|
if (role==Qt::DisplayRole)
|
|
|
|
return tr (mIdCollection->getColumn (section).mTitle.c_str());
|
|
|
|
|
|
|
|
if (role==ColumnBase::Role_Flags)
|
|
|
|
return mIdCollection->getColumn (section).mFlags;
|
|
|
|
|
2013-01-03 10:20:25 +00:00
|
|
|
if (role==ColumnBase::Role_Display)
|
|
|
|
return mIdCollection->getColumn (section).mDisplayType;
|
|
|
|
|
2012-12-13 13:53:16 +00:00
|
|
|
return QVariant();
|
2012-11-29 13:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CSMWorld::IdTable::setData ( const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
{
|
2012-12-13 13:53:16 +00:00
|
|
|
if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole)
|
2012-11-29 13:45:34 +00:00
|
|
|
{
|
2012-11-29 17:56:28 +00:00
|
|
|
mIdCollection->setData (index.row(), index.column(), value);
|
2012-12-06 13:56:04 +00:00
|
|
|
|
|
|
|
emit dataChanged (CSMWorld::IdTable::index (index.row(), 0),
|
|
|
|
CSMWorld::IdTable::index (index.row(), mIdCollection->getColumns()-1));
|
|
|
|
|
2012-11-29 13:45:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags CSMWorld::IdTable::flags (const QModelIndex & index) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
|
2012-12-13 13:53:16 +00:00
|
|
|
if (mIdCollection->getColumn (index.column()).isUserEditable())
|
2012-11-29 13:45:34 +00:00
|
|
|
flags |= Qt::ItemIsEditable;
|
|
|
|
|
|
|
|
return flags;
|
2012-12-03 20:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-12-06 13:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMWorld::IdTable::setRecord (const RecordBase& record)
|
|
|
|
{
|
|
|
|
int index = mIdCollection->searchId (mIdCollection->getId (record));
|
|
|
|
|
|
|
|
if (index==-1)
|
|
|
|
{
|
|
|
|
int index = mIdCollection->getSize();
|
|
|
|
|
|
|
|
beginInsertRows (QModelIndex(), index, index);
|
|
|
|
|
|
|
|
mIdCollection->appendRecord (record);
|
|
|
|
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mIdCollection->replace (index, record);
|
|
|
|
emit dataChanged (CSMWorld::IdTable::index (index, 0),
|
|
|
|
CSMWorld::IdTable::index (index, mIdCollection->getColumns()-1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const CSMWorld::RecordBase& CSMWorld::IdTable::getRecord (const std::string& id) const
|
|
|
|
{
|
|
|
|
return mIdCollection->getRecord (id);
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|