mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:49:55 +00:00
Add the ability to search a nested column index
This commit is contained in:
parent
feeb9ea8b0
commit
a7f31988d1
4 changed files with 49 additions and 0 deletions
|
@ -261,3 +261,13 @@ CSMWorld::NestedTableWrapperBase* CSMWorld::IdTree::nestedTable(const QModelInde
|
|||
|
||||
return mNestedCollection->nestedTable(index.row(), index.column());
|
||||
}
|
||||
|
||||
int CSMWorld::IdTree::searchNestedColumnIndex(int parentColumn, Columns::ColumnId id)
|
||||
{
|
||||
return mNestedCollection->searchNestedColumnIndex(parentColumn, id);
|
||||
}
|
||||
|
||||
int CSMWorld::IdTree::findNestedColumnIndex(int parentColumn, Columns::ColumnId id)
|
||||
{
|
||||
return mNestedCollection->findNestedColumnIndex(parentColumn, id);
|
||||
}
|
||||
|
|
|
@ -73,6 +73,12 @@ namespace CSMWorld
|
|||
|
||||
virtual bool hasChildren (const QModelIndex& index) const;
|
||||
|
||||
virtual int searchNestedColumnIndex(int parentColumn, Columns::ColumnId id);
|
||||
///< \return the column index or -1 if the requested column wasn't found.
|
||||
|
||||
virtual int findNestedColumnIndex(int parentColumn, Columns::ColumnId id);
|
||||
///< \return the column index or throws an exception if the requested column wasn't found.
|
||||
|
||||
signals:
|
||||
|
||||
void resetStart(const QString& id);
|
||||
|
|
|
@ -15,3 +15,28 @@ int CSMWorld::NestedCollection::getNestedColumnsCount(int row, int column) const
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CSMWorld::NestedCollection::searchNestedColumnIndex(int parentColumn, Columns::ColumnId id)
|
||||
{
|
||||
// Assumed that the parentColumn is always a valid index
|
||||
const NestableColumn *parent = getNestableColumn(parentColumn);
|
||||
int nestedColumnCount = getNestedColumnsCount(0, parentColumn);
|
||||
for (int i = 0; i < nestedColumnCount; ++i)
|
||||
{
|
||||
if (parent->nestedColumn(i).mColumnId == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CSMWorld::NestedCollection::findNestedColumnIndex(int parentColumn, Columns::ColumnId id)
|
||||
{
|
||||
int index = searchNestedColumnIndex(parentColumn, id);
|
||||
if (index == -1)
|
||||
{
|
||||
throw std::logic_error("CSMWorld::NestedCollection: No such nested column");
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef CSM_WOLRD_NESTEDCOLLECTION_H
|
||||
#define CSM_WOLRD_NESTEDCOLLECTION_H
|
||||
|
||||
#include "columns.hpp"
|
||||
|
||||
class QVariant;
|
||||
|
||||
namespace CSMWorld
|
||||
|
@ -33,6 +35,12 @@ namespace CSMWorld
|
|||
virtual int getNestedColumnsCount(int row, int column) const;
|
||||
|
||||
virtual NestableColumn *getNestableColumn(int column) = 0;
|
||||
|
||||
virtual int searchNestedColumnIndex(int parentColumn, Columns::ColumnId id);
|
||||
///< \return the column index or -1 if the requested column wasn't found.
|
||||
|
||||
virtual int findNestedColumnIndex(int parentColumn, Columns::ColumnId id);
|
||||
///< \return the column index or throws an exception if the requested column wasn't found.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue