mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 03:39:55 +00:00
Fix editing "ID" column within nested tables in dialogue subview.
This commit is contained in:
parent
1220369da3
commit
a632b2cfeb
@ -38,18 +38,26 @@ QVariant CSMWorld::IdTree::data (const QModelIndex & index, int role) const
|
||||
if ((role!=Qt::DisplayRole && role!=Qt::EditRole) || index.row() < 0 || index.column() < 0)
|
||||
return QVariant();
|
||||
|
||||
if (role==Qt::EditRole && !idCollection()->getColumn (index.column()).isEditable())
|
||||
return QVariant();
|
||||
|
||||
if (index.internalId() != 0)
|
||||
{
|
||||
std::pair<int, int> parentAdress(unfoldIndexAdress(index.internalId()));
|
||||
std::pair<int, int> parentAddress(unfoldIndexAddress(index.internalId()));
|
||||
|
||||
return mNestedCollection->getNestedData(parentAdress.first,
|
||||
parentAdress.second, index.row(), index.column());
|
||||
if (role == Qt::EditRole &&
|
||||
!mNestedCollection->getNestableColumn(parentAddress.second)->nestedColumn(index.column()).isEditable())
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
return mNestedCollection->getNestedData(parentAddress.first,
|
||||
parentAddress.second, index.row(), index.column());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (role==Qt::EditRole && !idCollection()->getColumn (index.column()).isEditable())
|
||||
return QVariant();
|
||||
|
||||
return idCollection()->getData (index.row(), index.column());
|
||||
}
|
||||
}
|
||||
|
||||
QVariant CSMWorld::IdTree::nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role) const
|
||||
@ -80,12 +88,12 @@ bool CSMWorld::IdTree::setData (const QModelIndex &index, const QVariant &value,
|
||||
{
|
||||
if (idCollection()->getColumn(parent(index).column()).isEditable() && role==Qt::EditRole)
|
||||
{
|
||||
const std::pair<int, int>& parentAdress(unfoldIndexAdress(index.internalId()));
|
||||
const std::pair<int, int>& parentAddress(unfoldIndexAddress(index.internalId()));
|
||||
|
||||
mNestedCollection->setNestedData(parentAdress.first, parentAdress.second, value, index.row(), index.column());
|
||||
mNestedCollection->setNestedData(parentAddress.first, parentAddress.second, value, index.row(), index.column());
|
||||
|
||||
emit dataChanged (CSMWorld::IdTree::index (parentAdress.first, 0),
|
||||
CSMWorld::IdTree::index (parentAdress.second, idCollection()->getColumns()-1));
|
||||
emit dataChanged (CSMWorld::IdTree::index (parentAddress.first, 0),
|
||||
CSMWorld::IdTree::index (parentAddress.second, idCollection()->getColumns()-1));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -145,7 +153,7 @@ QModelIndex CSMWorld::IdTree::index (int row, int column, const QModelIndex& par
|
||||
unsigned int encodedId = 0;
|
||||
if (parent.isValid())
|
||||
{
|
||||
encodedId = this->foldIndexAdress(parent);
|
||||
encodedId = this->foldIndexAddress(parent);
|
||||
}
|
||||
|
||||
if (row<0 || row>=idCollection()->getSize())
|
||||
@ -157,13 +165,18 @@ QModelIndex CSMWorld::IdTree::index (int row, int column, const QModelIndex& par
|
||||
return createIndex(row, column, encodedId); // store internal id
|
||||
}
|
||||
|
||||
QModelIndex CSMWorld::IdTree::getNestedModelIndex (const std::string& id, int column) const
|
||||
{
|
||||
return CSMWorld::IdTable::index(idCollection()->getIndex (id), column);
|
||||
}
|
||||
|
||||
QModelIndex CSMWorld::IdTree::parent (const QModelIndex& index) const
|
||||
{
|
||||
if (index.internalId() == 0) // 0 is used for indexs with invalid parent (top level data)
|
||||
return QModelIndex();
|
||||
|
||||
unsigned int id = index.internalId();
|
||||
const std::pair<int, int>& adress(unfoldIndexAdress(id));
|
||||
const std::pair<int, int>& adress(unfoldIndexAddress(id));
|
||||
|
||||
if (adress.first >= this->rowCount() || adress.second >= this->columnCount())
|
||||
throw "Parent index is not present in the model";
|
||||
@ -171,14 +184,14 @@ QModelIndex CSMWorld::IdTree::parent (const QModelIndex& index) const
|
||||
return createIndex(adress.first, adress.second);
|
||||
}
|
||||
|
||||
unsigned int CSMWorld::IdTree::foldIndexAdress (const QModelIndex& index) const
|
||||
unsigned int CSMWorld::IdTree::foldIndexAddress (const QModelIndex& index) const
|
||||
{
|
||||
unsigned int out = index.row() * this->columnCount();
|
||||
out += index.column();
|
||||
return ++out;
|
||||
}
|
||||
|
||||
std::pair< int, int > CSMWorld::IdTree::unfoldIndexAdress (unsigned int id) const
|
||||
std::pair< int, int > CSMWorld::IdTree::unfoldIndexAddress (unsigned int id) const
|
||||
{
|
||||
if (id == 0)
|
||||
throw "Attempt to unfold index id of the top level data cell";
|
||||
@ -189,6 +202,8 @@ std::pair< int, int > CSMWorld::IdTree::unfoldIndexAdress (unsigned int id) cons
|
||||
return std::make_pair (row, column);
|
||||
}
|
||||
|
||||
// FIXME: Not sure why this check is also needed?
|
||||
//
|
||||
// index.data().isValid() requires RefIdAdapter::getData() to return a valid QVariant for
|
||||
// nested columns (refidadapterimp.hpp)
|
||||
//
|
||||
@ -198,7 +213,7 @@ bool CSMWorld::IdTree::hasChildren(const QModelIndex& index) const
|
||||
return (index.isValid() &&
|
||||
index.internalId() == 0 &&
|
||||
mNestedCollection->getNestableColumn(index.column())->hasChildren() &&
|
||||
index.data().isValid()); // FIXME: not sure why this check is also needed
|
||||
index.data().isValid());
|
||||
}
|
||||
|
||||
void CSMWorld::IdTree::setNestedTable(const QModelIndex& index, const CSMWorld::NestedTableWrapperBase& nestedTable)
|
||||
|
@ -34,8 +34,8 @@ namespace CSMWorld
|
||||
IdTree (const IdTree&);
|
||||
IdTree& operator= (const IdTree&);
|
||||
|
||||
unsigned int foldIndexAdress(const QModelIndex& index) const;
|
||||
std::pair<int, int> unfoldIndexAdress(unsigned int id) const;
|
||||
unsigned int foldIndexAddress(const QModelIndex& index) const;
|
||||
std::pair<int, int> unfoldIndexAddress(unsigned int id) const;
|
||||
|
||||
public:
|
||||
|
||||
@ -61,6 +61,8 @@ namespace CSMWorld
|
||||
|
||||
virtual QModelIndex parent (const QModelIndex& index) const;
|
||||
|
||||
QModelIndex getNestedModelIndex (const std::string& id, int column) const;
|
||||
|
||||
QVariant nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
|
||||
NestedTableWrapperBase* nestedTable(const QModelIndex &index) const;
|
||||
|
@ -50,7 +50,7 @@ QModelIndex CSMWorld::NestedTableProxyModel::mapFromSource(const QModelIndex& so
|
||||
|
||||
QModelIndex CSMWorld::NestedTableProxyModel::mapToSource(const QModelIndex& proxyIndex) const
|
||||
{
|
||||
const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn);
|
||||
const QModelIndex& parent = mMainModel->getNestedModelIndex (mId, mParentColumn);
|
||||
return mMainModel->index(proxyIndex.row(), proxyIndex.column(), parent);
|
||||
}
|
||||
|
||||
@ -98,6 +98,10 @@ QVariant CSMWorld::NestedTableProxyModel::headerData(int section,
|
||||
return mMainModel->nestedHeaderData(mParentColumn, section, orientation, role);
|
||||
}
|
||||
|
||||
QVariant CSMWorld::NestedTableProxyModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
return mMainModel->data(mapToSource(index), role);
|
||||
}
|
||||
|
||||
bool CSMWorld::NestedTableProxyModel::setData (const QModelIndex & index, const QVariant & value, int role)
|
||||
{
|
||||
|
@ -53,6 +53,8 @@ namespace CSMWorld
|
||||
|
||||
virtual QVariant headerData (int section, Qt::Orientation orientation, int role) const;
|
||||
|
||||
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
|
||||
|
||||
virtual bool setData (const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
|
||||
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user