Add potion magic effects table to dialogue subview. Integration of the adapters to RefIdCollection is incomplete.

test
cc9cii 10 years ago
parent ef84e553be
commit 25261a60e5

@ -45,7 +45,7 @@ namespace CSMWorld
virtual std::string getId (const RecordBase& record) const = 0;
virtual void setId(RecordBase& record, const std::string& id) = 0; // FIXME: used by RefIdCollection::cloneRecord()
virtual void setId(RecordBase& record, const std::string& id) = 0; // used by RefIdCollection::cloneRecord()
};
class NestedRefIdAdapterBase
@ -55,23 +55,27 @@ namespace CSMWorld
virtual ~NestedRefIdAdapterBase();
virtual void setNestedData (const RefIdColumn *column, RefIdData& data, int row,
const QVariant& value, int subRowIndex, int subColIndex) const = 0;
virtual void setNestedData (const RefIdColumn *column,
RefIdData& data, int row, const QVariant& value, int subRowIndex, int subColIndex) const = 0;
virtual QVariant getNestedData (const RefIdColumn *column, const RefIdData& data,
int index, int subRowIndex, int subColIndex) const = 0;
virtual QVariant getNestedData (const RefIdColumn *column,
const RefIdData& data, int index, int subRowIndex, int subColIndex) const = 0;
virtual int getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const = 0;
virtual int getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const = 0;
virtual void removeNestedRow (const RefIdColumn *column, RefIdData& data, int index, int rowToRemove) const = 0;
virtual void removeNestedRow (const RefIdColumn *column,
RefIdData& data, int index, int rowToRemove) const = 0;
virtual void addNestedRow (const RefIdColumn *column, RefIdData& data, int index, int position) const = 0;
virtual void addNestedRow (const RefIdColumn *column,
RefIdData& data, int index, int position) const = 0;
virtual void setNestedTable (const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const = 0;
virtual void setNestedTable (const RefIdColumn* column,
RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const = 0;
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column, const RefIdData& data, int index) const = 0;
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column,
const RefIdData& data, int index) const = 0;
};
class NestedRefIdAdapter : public NestedRefIdAdapterBase

@ -7,10 +7,13 @@
#include <components/esm/loadcont.hpp>
#include "nestedtablewrapper.hpp"
CSMWorld::PotionRefIdAdapter::PotionRefIdAdapter (const InventoryColumns& columns,
CSMWorld::PotionColumns::PotionColumns (const InventoryColumns& columns)
: InventoryColumns (columns) {}
CSMWorld::PotionRefIdAdapter::PotionRefIdAdapter (const PotionColumns& columns,
const RefIdColumn *autoCalc)
: InventoryRefIdAdapter<ESM::Potion> (UniversalId::Type_Potion, columns),
mAutoCalc (autoCalc)
mAutoCalc (autoCalc), mColumns(columns)
{}
QVariant CSMWorld::PotionRefIdAdapter::getData (const RefIdColumn *column, const RefIdData& data,
@ -22,6 +25,9 @@ QVariant CSMWorld::PotionRefIdAdapter::getData (const RefIdColumn *column, const
if (column==mAutoCalc)
return record.get().mData.mAutoCalc!=0;
if (column==mColumns.mEffects)
return true; // Required to show nested tables in dialogue subview
return InventoryRefIdAdapter<ESM::Potion>::getData (column, data, index);
}

@ -6,6 +6,7 @@
#include <QVariant>
#include <components/esm/loadalch.hpp>
#include <components/esm/loadench.hpp>
#include <components/esm/loadappa.hpp>
#include "record.hpp"
@ -315,13 +316,21 @@ namespace CSMWorld
record.setModified(record2);
}
struct PotionColumns : public InventoryColumns
{
const RefIdColumn *mEffects;
PotionColumns (const InventoryColumns& columns);
};
class PotionRefIdAdapter : public InventoryRefIdAdapter<ESM::Potion>
{
PotionColumns mColumns;
const RefIdColumn *mAutoCalc;
public:
PotionRefIdAdapter (const InventoryColumns& columns, const RefIdColumn *autoCalc);
PotionRefIdAdapter (const PotionColumns& columns, const RefIdColumn *autoCalc);
virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int index)
const;
@ -828,6 +837,88 @@ namespace CSMWorld
const QVariant& value) const;
///< If the data type does not match an exception is thrown.
};
class NestedRefIdAdapterBase;
template<typename ESXRecordT>
class EffectsListAdapter;
template<typename ESXRecordT>
class EffectsRefIdAdapter : public EffectsListAdapter<ESXRecordT>, public NestedRefIdAdapterBase
{
UniversalId::Type mType;
// not implemented
EffectsRefIdAdapter (const EffectsRefIdAdapter&);
EffectsRefIdAdapter& operator= (const EffectsRefIdAdapter&);
public:
EffectsRefIdAdapter(UniversalId::Type type) :mType(type) {}
virtual ~EffectsRefIdAdapter() {}
virtual void addNestedRow (const RefIdColumn *column,
RefIdData& data, int index, int position) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
EffectsListAdapter<ESXRecordT>::addNestedRow(record, position);
}
virtual void removeNestedRow (const RefIdColumn *column,
RefIdData& data, int index, int rowToRemove) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
EffectsListAdapter<ESXRecordT>::removeNestedRow(record, rowToRemove);
}
virtual void setNestedTable (const RefIdColumn* column,
RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
EffectsListAdapter<ESXRecordT>::setNestedTable(record, nestedTable);
}
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column,
const RefIdData& data, int index) const
{
const Record<ESXRecordT>& record =
static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
return EffectsListAdapter<ESXRecordT>::nestedTable(record);
}
virtual QVariant getNestedData (const RefIdColumn *column,
const RefIdData& data, int index, int subRowIndex, int subColIndex) const
{
const Record<ESXRecordT>& record =
static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
return EffectsListAdapter<ESXRecordT>::getNestedData(record, subRowIndex, subColIndex);
}
virtual void setNestedData (const RefIdColumn *column,
RefIdData& data, int row, const QVariant& value, int subRowIndex, int subColIndex) const
{
Record<ESXRecordT>& record =
static_cast<Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (row, mType)));
EffectsListAdapter<ESXRecordT>::setNestedData(record, value, subRowIndex, subColIndex);
}
virtual int getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const
{
const Record<ESXRecordT> record;
return EffectsListAdapter<ESXRecordT>::getNestedColumnsCount(record);
}
virtual int getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const
{
const Record<ESXRecordT>& record =
static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
return EffectsListAdapter<ESXRecordT>::getNestedRowsCount(record);
}
};
}
#endif

@ -9,6 +9,7 @@
#include "refidadapterimp.hpp"
#include "columns.hpp"
#include "nestedtablewrapper.hpp"
#include "nestedcoladapterimp.hpp"
CSMWorld::RefIdColumn::RefIdColumn (int columnId, Display displayType, int flag,
bool editable, bool userEditable)
@ -70,6 +71,29 @@ CSMWorld::RefIdCollection::RefIdCollection()
mColumns.push_back (RefIdColumn (Columns::ColumnId_CoinValue, ColumnBase::Display_Integer));
inventoryColumns.mValue = &mColumns.back();
// nested table
PotionColumns potionColumns (inventoryColumns);
mColumns.push_back (RefIdColumn (Columns::ColumnId_EffectList, ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
potionColumns.mEffects = &mColumns.back(); // see refidadapterimp.hpp
mNestedAdapters.insert (std::make_pair(&mColumns.back(),
new EffectsRefIdAdapter<ESM::Potion> (UniversalId::Type_Potion)));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_EffectId, ColumnBase::Display_String/*, false*/));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_Skill, ColumnBase::Display_String));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_Attribute, ColumnBase::Display_String)); // reuse attribute
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_EffectRange, ColumnBase::Display_Integer));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_EffectArea, ColumnBase::Display_String));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_Duration, ColumnBase::Display_Integer)); // reuse from light
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_MinRange, ColumnBase::Display_Integer)); // reuse from sound
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_MaxRange, ColumnBase::Display_Integer)); // reuse from sound
EnchantableColumns enchantableColumns (inventoryColumns);
mColumns.push_back (RefIdColumn (Columns::ColumnId_Enchantment, ColumnBase::Display_String));
@ -385,7 +409,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
mAdapters.insert (std::make_pair (UniversalId::Type_Activator,
new NameRefIdAdapter<ESM::Activator> (UniversalId::Type_Activator, nameColumns)));
mAdapters.insert (std::make_pair (UniversalId::Type_Potion,
new PotionRefIdAdapter (inventoryColumns, autoCalc)));
new PotionRefIdAdapter (potionColumns, autoCalc)));
mAdapters.insert (std::make_pair (UniversalId::Type_Apparatus,
new ApparatusRefIdAdapter (inventoryColumns, apparatusType, toolsColumns.mQuality)));
mAdapters.insert (std::make_pair (UniversalId::Type_Armor,
@ -430,6 +454,10 @@ CSMWorld::RefIdCollection::~RefIdCollection()
for (std::map<UniversalId::Type, RefIdAdapter *>::iterator iter (mAdapters.begin());
iter!=mAdapters.end(); ++iter)
delete iter->second;
for (std::map<const ColumnBase*, NestedRefIdAdapterBase* >::iterator iter (mNestedAdapters.begin());
iter!=mNestedAdapters.end(); ++iter)
delete iter->second;
}
int CSMWorld::RefIdCollection::getSize() const
@ -475,6 +503,12 @@ QVariant CSMWorld::RefIdCollection::getNestedData (int row, int column, int subR
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex(row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column));
if (nestedAdapter)
{
return nestedAdapter->getNestedData(&mColumns.at (column), mData, localIndex.first, subRow, subColumn);
}
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
return adaptor.getNestedData (&mColumns.at (column), mData, localIndex.first, subRow, subColumn);
@ -493,6 +527,13 @@ void CSMWorld::RefIdCollection::setNestedData(int row, int column, const QVarian
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column));
if (nestedAdapter)
{
nestedAdapter->setNestedData(&mColumns.at (column), mData, localIndex.first, data, subRow, subColumn);
return;
}
const RefIdAdapter& adaptor = findAdapter (localIndex.second);
dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(adaptor).setNestedData (&mColumns.at (column), mData, localIndex.first, data, subRow, subColumn);
@ -507,6 +548,13 @@ void CSMWorld::RefIdCollection::removeNestedRows(int row, int column, int subRow
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column));
if (nestedAdapter)
{
nestedAdapter->removeNestedRow(&mColumns.at (column), mData, localIndex.first, subRow);
return;
}
const RefIdAdapter& adaptor = findAdapter (localIndex.second);
dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(adaptor).removeNestedRow(&mColumns.at (column), mData, localIndex.first, subRow);
@ -651,6 +699,12 @@ int CSMWorld::RefIdCollection::getNestedRowsCount(int row, int column) const
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column));
if (nestedAdapter)
{
return nestedAdapter->getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
}
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
return adaptor.getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
@ -660,6 +714,12 @@ int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column));
if (nestedAdapter)
{
return nestedAdapter->getNestedColumnsCount(&mColumns.at(column), mData);
}
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
return adaptor.getNestedColumnsCount(&mColumns.at(column), mData);
@ -674,6 +734,13 @@ void CSMWorld::RefIdCollection::addNestedRow(int row, int col, int position)
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(col));
if (nestedAdapter)
{
nestedAdapter->addNestedRow(&mColumns.at(col), mData, localIndex.first, position);
return;
}
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
adaptor.addNestedRow(&mColumns.at(col), mData, localIndex.first, position);
@ -683,6 +750,13 @@ void CSMWorld::RefIdCollection::setNestedTable(int row, int column, const CSMWor
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column));
if (nestedAdapter)
{
nestedAdapter->setNestedTable(&mColumns.at(column), mData, localIndex.first, nestedTable);
return;
}
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
adaptor.setNestedTable(&mColumns.at(column), mData, localIndex.first, nestedTable);
@ -692,7 +766,26 @@ CSMWorld::NestedTableWrapperBase* CSMWorld::RefIdCollection::nestedTable(int row
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column));
if (nestedAdapter)
{
return nestedAdapter->nestedTable(&mColumns.at(column), mData, localIndex.first);
}
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdapter (localIndex.second));
return adaptor.nestedTable(&mColumns.at(column), mData, localIndex.first);
}
const CSMWorld::NestedRefIdAdapterBase* CSMWorld::RefIdCollection::getNestedAdapter(const CSMWorld::ColumnBase &column) const
{
std::map<const ColumnBase*, NestedRefIdAdapterBase* >::const_iterator iter =
mNestedAdapters.find (&column);
if (iter==mNestedAdapters.end())
return 0; // FIXME: testing only
//throw std::runtime_error("No such column in the nestedadapters");
//return *iter->second;
return iter->second;
}

@ -19,6 +19,7 @@ namespace CSMWorld
{
class RefIdAdapter;
struct NestedTableWrapperBase;
class NestedRefIdAdapterBase;
class RefIdColumn : public NestableColumn
{
@ -44,11 +45,16 @@ namespace CSMWorld
std::deque<RefIdColumn> mColumns;
std::map<UniversalId::Type, RefIdAdapter *> mAdapters;
std::map<const ColumnBase*, NestedRefIdAdapterBase* > mNestedAdapters;
private:
const RefIdAdapter& findAdapter (UniversalId::Type) const;
///< Throws an exception if no adaptor for \a Type can be found.
//const NestedRefIdAdapterBase& getNestedAdapter(const ColumnBase &column) const;
const NestedRefIdAdapterBase* getNestedAdapter(const ColumnBase &column) const;
public:
RefIdCollection();

Loading…
Cancel
Save