1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 04:19:55 +00:00

Quick and dirty prototype of actual nested header data implementation

This commit is contained in:
Marek Kochanowicz 2014-06-19 18:46:09 +02:00
parent 256b075914
commit a076798f8f
9 changed files with 76 additions and 49 deletions

View file

@ -3,6 +3,8 @@
#include "columns.hpp"
#include <cassert>
CSMWorld::ColumnBase::ColumnBase (int columnId, Display displayType, int flags, bool canNest)
: mColumnId (columnId), mDisplayType (displayType), mFlags (flags), mCanNest(canNest)
{}
@ -28,3 +30,15 @@ bool CSMWorld::ColumnBase::canHaveNestedColumns() const
{
return mCanNest;
}
std::string CSMWorld::ColumnBase::getNestedColumnTitle(int columnNumber) const
{
return Columns::getName (mDisplayType, columnNumber);
}
void CSMWorld::ColumnBase::addNestedColumnDisplay(CSMWorld::ColumnBase::Display displayDefinition)
{
assert (canHaveNestedColumns());
mNestedDisplayType.push_back(displayDefinition);
}

View file

@ -2,6 +2,7 @@
#define CSM_WOLRD_COLUMNBASE_H
#include <string>
#include <vector>
#include <Qt>
#include <QVariant>
@ -97,6 +98,7 @@ namespace CSMWorld
int mColumnId;
int mFlags;
Display mDisplayType;
std::vector<Display> mNestedDisplayType;
const bool mCanNest;
ColumnBase (int columnId, Display displayType, int flag, bool canNest = false);
@ -110,6 +112,10 @@ namespace CSMWorld
virtual std::string getTitle() const;
std::string getNestedColumnTitle(int columnNumber) const;
virtual void addNestedColumnDisplay(Display displayDefinition);
virtual int getId() const;
bool canHaveNestedColumns() const;

View file

@ -216,6 +216,21 @@ std::string CSMWorld::Columns::getName (ColumnId column)
return "";
}
std::string CSMWorld::Columns::getName(CSMWorld::ColumnBase::Display displayType, int columnNumber)
{
//TODO, this is just temporary solution
switch (displayType)
{
case CSMWorld::ColumnBase::Display_NestedItemList:
if (columnNumber == 0)
return "ID";
if (columnNumber == 1)
return "Count";
}
return "Do yourself a favor and take a look at the columns.cpp";
}
int CSMWorld::Columns::getId (const std::string& name)
{
std::string name2 = Misc::StringUtils::lowerCase (name);

View file

@ -4,6 +4,8 @@
#include <string>
#include <vector>
#include "columnbase.hpp"
namespace CSMWorld
{
namespace Columns
@ -208,6 +210,8 @@ namespace CSMWorld
std::string getName (ColumnId column);
std::string getName (ColumnBase::Display displayType, int columnNumber);
int getId (const std::string& name);
///< Will return -1 for an invalid name.

View file

@ -1,5 +1,7 @@
#include "idtable.hpp"
#include <cassert>
#include "collectionbase.hpp"
#include "columnbase.hpp"
@ -70,6 +72,25 @@ QVariant CSMWorld::IdTable::headerData (int section,
return QVariant();
}
QVariant CSMWorld::IdTable::nestedHeaderData(int section, int subSection, Qt::Orientation orientation, int role) const
{
assert(mIdCollection->getColumn(section).canHaveNestedColumns());
if (orientation==Qt::Vertical)
return QVariant();
if (role==Qt::DisplayRole)
return tr (mIdCollection->getColumn(section).getNestedColumnTitle(subSection).c_str());
if (role==ColumnBase::Role_Flags)
return mIdCollection->getColumn (section).mFlags;
if (role==ColumnBase::Role_Display)
return mIdCollection->getColumn (section).mNestedDisplayType.at(subSection);
return QVariant();
}
bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value, int role)
{
if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole)

View file

@ -72,6 +72,8 @@ namespace CSMWorld
virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QVariant nestedHeaderData(int section, int subSection, Qt::Orientation orientation, 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;

View file

@ -6,21 +6,20 @@
CSMWorld::NestedTableModel::NestedTableModel(const QModelIndex& parent,
ColumnBase::Display columnId,
CSMWorld::IdTable* parentModel)
: mParentColumn(parent.column())
: mParentColumn(parent.column()),
mMainModel(parentModel)
{
const int parentRow = parent.row();
mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8());
QAbstractProxyModel::setSourceModel(parentModel);
setupHeaderVectors(columnId);
}
QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceIndex) const
{
const QModelIndex& testedParent = sourceModel()->parent(sourceIndex);
const QModelIndex& parent = dynamic_cast<CSMWorld::IdTable*>(sourceModel())->getModelIndex (mId, mParentColumn);
const QModelIndex& testedParent = mMainModel->parent(sourceIndex);
const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn);
if (testedParent == parent)
{
return createIndex(sourceIndex.row(), sourceIndex.column());
@ -34,36 +33,30 @@ QModelIndex CSMWorld::NestedTableModel::mapFromSource(const QModelIndex& sourceI
QModelIndex CSMWorld::NestedTableModel::mapToSource(const QModelIndex& proxyIndex) const
{
const QModelIndex& parent = dynamic_cast<CSMWorld::IdTable*>(sourceModel())->getModelIndex (mId, mParentColumn);
return sourceModel()->index(proxyIndex.row(), proxyIndex.column(), parent);
const QModelIndex& parent = mMainModel->getModelIndex (mId, mParentColumn);
return mMainModel->index(proxyIndex.row(), proxyIndex.column(), parent);
}
int CSMWorld::NestedTableModel::rowCount(const QModelIndex& index) const
{
assert (!index.isValid());
CSMWorld::IdTable* table = dynamic_cast<CSMWorld::IdTable*>(sourceModel());
return table->rowCount(table->getModelIndex(mId, mParentColumn));
return mMainModel->rowCount(mMainModel->getModelIndex(mId, mParentColumn));
}
int CSMWorld::NestedTableModel::columnCount(const QModelIndex& parent) const
{
assert (!parent.isValid());
CSMWorld::IdTable* table = dynamic_cast<CSMWorld::IdTable*>(sourceModel());
return table->columnCount(table->getModelIndex(mId, mParentColumn));
return mMainModel->columnCount(mMainModel->getModelIndex(mId, mParentColumn));
}
QModelIndex CSMWorld::NestedTableModel::index(int row, int column, const QModelIndex& parent) const
{
assert (!parent.isValid());
CSMWorld::IdTable* table = dynamic_cast<CSMWorld::IdTable*>(sourceModel());
int rows = table->rowCount(parent);
int columns = table->columnCount(parent);
int rows = mMainModel->rowCount(parent);
int columns = mMainModel->columnCount(parent);
if (row < 0 ||
row >= rows ||
@ -85,34 +78,5 @@ QVariant CSMWorld::NestedTableModel::headerData(int section,
Qt::Orientation orientation,
int role) const
{
if (orientation==Qt::Vertical)
return QVariant();
if (role==Qt::DisplayRole)
return tr (mHeaderTitle[section].c_str());
if (role==ColumnBase::Role_Flags)
return QVariant(); //TODO
if (role==ColumnBase::Role_Display)
return mHeaderDisplay[section];
return QVariant();
}
void CSMWorld::NestedTableModel::setupHeaderVectors(ColumnBase::Display columnId)
{
switch(columnId)
{
case ColumnBase::Display_NestedItemList:
mHeaderTitle.push_back("test1");
mHeaderTitle.push_back("test2");
mHeaderDisplay.push_back(ColumnBase::Display_String);
mHeaderDisplay.push_back(ColumnBase::Display_Integer);
break;
default:
assert(false);
}
return mMainModel->nestedHeaderData(mParentColumn, section, orientation, role);
}

View file

@ -22,9 +22,8 @@ namespace CSMWorld
class NestedTableModel : public QAbstractProxyModel
{
const int mParentColumn;
IdTable* mMainModel;
std::string mId;
std::vector<std::string> mHeaderTitle;
std::vector<ColumnBase::Display> mHeaderDisplay;
public:
NestedTableModel(const QModelIndex& parent,

View file

@ -168,6 +168,8 @@ CSMWorld::RefIdCollection::RefIdCollection()
mColumns.push_back(RefIdColumn (Columns::ColumnId_ContainerContent, ColumnBase::Display_NestedItemList, ColumnBase::Flag_Dialogue, true, true, true));
const RefIdColumn *content = &mColumns.back();
(&mColumns.back())->addNestedColumnDisplay(CSMWorld::ColumnBase::Display_String);
(&mColumns.back())->addNestedColumnDisplay(CSMWorld::ColumnBase::Display_Integer);
CreatureColumns creatureColumns (actorsColumns);