1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge remote-tracking branch 'cc9cii/NonTableFields'

This commit is contained in:
Marc Zinnschlag 2015-04-21 09:38:15 +02:00
commit fc3aa7122a
44 changed files with 4860 additions and 296 deletions

View File

@ -18,14 +18,14 @@ opencs_hdrs_noqt (model/doc
opencs_units (model/world
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable
idtable idtableproxymodel regionmap data commanddispatcher idtablebase resourcetable nestedtableproxymodel idtree
)
opencs_units_noqt (model/world
universalid record commands columnbase scriptcontext cell refidcollection
refidadapter refiddata refidadapterimp ref collectionbase refcollection columns infocollection tablemimedata cellcoordinates cellselection resources resourcesmanager scope
pathgrid landtexture land
pathgrid landtexture land nestedtablewrapper nestedcollection nestedcoladapterimp nestedinfocollection
)
opencs_hdrs_noqt (model/world
@ -62,7 +62,7 @@ opencs_hdrs_noqt (view/doc
opencs_units (view/world
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
cellcreator referenceablecreator referencecreator scenesubview
infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable
infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable
)
opencs_units_noqt (view/world

View File

@ -69,7 +69,7 @@ void CSMDoc::DocumentManager::removeDocument (CSMDoc::Document *document)
throw std::runtime_error ("removing invalid document");
mDocuments.erase (iter);
delete document;
document->deleteLater();
if (mDocuments.empty())
emit lastDocumentDeleted();

View File

@ -148,6 +148,8 @@ namespace CSMWorld
void setRecord (int index, const Record<ESXRecordT>& record);
///< \attention This function must not change the ID.
NestableColumn *getNestableColumn (int column) const;
};
template<typename ESXRecordT, typename IdAccessorT>
@ -289,6 +291,15 @@ namespace CSMWorld
return *mColumns.at (column);
}
template<typename ESXRecordT, typename IdAccessorT>
NestableColumn *Collection<ESXRecordT, IdAccessorT>::getNestableColumn (int column) const
{
if (column < 0 || column >= static_cast<int>(mColumns.size()))
throw std::runtime_error("column index out of range");
return mColumns.at (column);
}
template<typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::addColumn (Column<ESXRecordT> *column)
{

View File

@ -1,10 +1,9 @@
#include "columnbase.hpp"
#include "columns.hpp"
CSMWorld::ColumnBase::ColumnBase (int columnId, Display displayType, int flags)
: mColumnId (columnId), mDisplayType (displayType), mFlags (flags)
: mColumnId (columnId), mDisplayType (displayType), mFlags (flags)
{}
CSMWorld::ColumnBase::~ColumnBase() {}
@ -19,7 +18,7 @@ std::string CSMWorld::ColumnBase::getTitle() const
return Columns::getName (static_cast<Columns::ColumnId> (mColumnId));
}
int CSMWorld::ColumnBase::getId() const
int CSMWorld::ColumnBase::getId() const
{
return mColumnId;
}
@ -76,6 +75,12 @@ bool CSMWorld::ColumnBase::isId (Display display)
Display_Video,
Display_Id,
Display_SkillImpact,
Display_EffectRange,
Display_EffectId,
Display_PartRefType,
Display_AiPackageType,
Display_YesNo,
Display_None
};
@ -84,7 +89,7 @@ bool CSMWorld::ColumnBase::isId (Display display)
if (ids[i]==display)
return true;
return false;
return false;
}
bool CSMWorld::ColumnBase::isText (Display display)
@ -96,3 +101,44 @@ bool CSMWorld::ColumnBase::isScript (Display display)
{
return display==Display_ScriptFile || display==Display_ScriptLines;
}
void CSMWorld::NestableColumn::addColumn(CSMWorld::NestableColumn *column)
{
mNestedColumns.push_back(column);
}
const CSMWorld::ColumnBase& CSMWorld::NestableColumn::nestedColumn(int subColumn) const
{
if (mNestedColumns.empty())
throw std::logic_error("Tried to access nested column of the non-nest column");
return *mNestedColumns.at(subColumn);
}
CSMWorld::NestableColumn::NestableColumn(int columnId, CSMWorld::ColumnBase::Display displayType,
int flag)
: CSMWorld::ColumnBase(columnId, displayType, flag)
{}
CSMWorld::NestableColumn::~NestableColumn()
{
for (unsigned int i = 0; i < mNestedColumns.size(); ++i)
{
delete mNestedColumns[i];
}
}
bool CSMWorld::NestableColumn::hasChildren() const
{
return !mNestedColumns.empty();
}
CSMWorld::NestedChildColumn::NestedChildColumn (int id,
CSMWorld::ColumnBase::Display display, bool isEditable)
: NestableColumn (id, display, CSMWorld::ColumnBase::Flag_Dialogue) , mIsEditable(isEditable)
{}
bool CSMWorld::NestedChildColumn::isEditable () const
{
return mIsEditable;
}

View File

@ -2,6 +2,8 @@
#define CSM_WOLRD_COLUMNBASE_H
#include <string>
#include <vector>
#include <stdexcept>
#include <Qt>
#include <QVariant>
@ -21,7 +23,8 @@ namespace CSMWorld
enum Flags
{
Flag_Table = 1, // column should be displayed in table view
Flag_Dialogue = 2 // column should be displayed in dialogue view
Flag_Dialogue = 2, // column should be displayed in dialogue view
Flag_Dialogue_List = 4 // column should be diaplyed in dialogue view
};
enum Display
@ -30,7 +33,7 @@ namespace CSMWorld
Display_String,
Display_LongString,
//CONCRETE TYPES STARTS HERE
//CONCRETE TYPES STARTS HERE (for drag and drop)
Display_Skill,
Display_Class,
Display_Faction,
@ -105,7 +108,16 @@ namespace CSMWorld
Display_ScriptLines, // console context
Display_SoundGeneratorType,
Display_School,
Display_Id
Display_Id,
Display_SkillImpact,
Display_EffectRange,
Display_EffectId,
Display_PartRefType,
Display_AiPackageType,
Display_YesNo,
//top level columns that nest other columns
Display_NestedHeader
};
int mColumnId;
@ -132,11 +144,28 @@ namespace CSMWorld
static bool isScript (Display display);
};
class NestableColumn : public ColumnBase
{
std::vector<NestableColumn *> mNestedColumns;
public:
NestableColumn(int columnId, Display displayType, int flag);
~NestableColumn();
void addColumn(CSMWorld::NestableColumn *column);
const ColumnBase& nestedColumn(int subColumn) const;
bool hasChildren() const;
};
template<typename ESXRecordT>
struct Column : public ColumnBase
struct Column : public NestableColumn
{
Column (int columnId, Display displayType, int flags = Flag_Table | Flag_Dialogue)
: ColumnBase (columnId, displayType, flags) {}
: NestableColumn (columnId, displayType, flags) {}
virtual QVariant get (const Record<ESXRecordT>& record) const = 0;
@ -145,6 +174,34 @@ namespace CSMWorld
throw std::logic_error ("Column " + getTitle() + " is not editable");
}
};
template<typename ESXRecordT>
struct NestedParentColumn : public Column<ESXRecordT>
{
NestedParentColumn (int id, int flags = ColumnBase::Flag_Dialogue) : Column<ESXRecordT> (id,
ColumnBase::Display_NestedHeader, flags)
{}
virtual QVariant get (const Record<ESXRecordT>& record) const
{
return true; // required by IdTree::hasChildren()
}
virtual bool isEditable() const
{
return true;
}
};
struct NestedChildColumn : public NestableColumn
{
NestedChildColumn (int id, Display display, bool isEditable = true);
virtual bool isEditable() const;
private:
bool mIsEditable;
};
}
#endif

View File

@ -1277,7 +1277,6 @@ namespace CSMWorld
}
};
template<typename ESXRecordT>
struct PosColumn : public Column<ESXRecordT>
{

View File

@ -173,6 +173,11 @@ namespace CSMWorld
{ ColumnId_Gender, "Gender" },
{ ColumnId_PcRank, "PC Rank" },
{ ColumnId_ReferenceableId, "Referenceable ID" },
{ ColumnId_ContainerContent, "Content" },
{ ColumnId_ItemCount, "Count" },
{ ColumnId_InventoryItemId, "ID"},
{ ColumnId_CombatState, "Combat" },
{ ColumnId_MagicState, "Magic" },
{ ColumnId_StealthState, "Stealth" },
@ -180,6 +185,22 @@ namespace CSMWorld
{ ColumnId_Vampire, "Vampire" },
{ ColumnId_BodyPartType, "Bodypart Type" },
{ ColumnId_MeshType, "Mesh Type" },
{ ColumnId_ActorInventory, "Inventory" },
{ ColumnId_SpellList, "Spells" },
{ ColumnId_SpellId, "ID"},
{ ColumnId_NpcDestinations, "Destinations" },
{ ColumnId_DestinationCell, "Cell"},
{ ColumnId_PosX, "Dest X"},
{ ColumnId_PosY, "Dest Y"},
{ ColumnId_PosZ, "Dest Z"},
{ ColumnId_RotX, "Rotation X"},
{ ColumnId_RotY, "Rotation Y"},
{ ColumnId_RotZ, "Rotation Z"},
{ ColumnId_Skill, "Skill" },
{ ColumnId_OwnerGlobal, "Owner Global" },
{ ColumnId_DefaultProfile, "Default Profile" },
{ ColumnId_BypassNewGame, "Bypass New Game" },
@ -202,6 +223,57 @@ namespace CSMWorld
{ ColumnId_AreaSound, "Area Sound" },
{ ColumnId_BoltSound, "Bolt Sound" },
{ ColumnId_PathgridPoints, "Points" },
{ ColumnId_PathgridIndex, "Index" },
{ ColumnId_PathgridPosX, "X" },
{ ColumnId_PathgridPosY, "Y" },
{ ColumnId_PathgridPosZ, "Z" },
{ ColumnId_PathgridEdges, "Edges" },
{ ColumnId_PathgridEdgeIndex, "Index" },
{ ColumnId_PathgridEdge0, "Point 0" },
{ ColumnId_PathgridEdge1, "Point 1" },
{ ColumnId_RegionSounds, "Sounds" },
{ ColumnId_SoundName, "Name" },
{ ColumnId_SoundChance, "Chance" },
{ ColumnId_FactionReactions, "Reactions" },
//{ ColumnId_FactionID, "Faction ID" },
{ ColumnId_FactionReaction, "Reaction" },
{ ColumnId_EffectList, "Effects" },
{ ColumnId_EffectId, "Effect" },
//{ ColumnId_EffectAttribute, "Attrib" },
{ ColumnId_EffectRange, "Range" },
{ ColumnId_EffectArea, "Area" },
{ ColumnId_AiPackageList, "Ai Packages" },
{ ColumnId_AiPackageType, "Package" },
{ ColumnId_AiWanderDist, "Wander Dist" },
{ ColumnId_AiDuration, "Duration" },
{ ColumnId_AiWanderToD, "Wander ToD" },
{ ColumnId_AiWanderIdle, "Wander Idle" },
{ ColumnId_AiWanderRepeat, "Wander Repeat" },
{ ColumnId_AiActivateName, "Activate" },
{ ColumnId_AiTargetId, "Target ID" },
{ ColumnId_AiTargetCell, "Target Cell" },
{ ColumnId_PartRefList, "Part Reference" },
{ ColumnId_PartRefType, "Type" },
{ ColumnId_PartRefMale, "Male" },
{ ColumnId_PartRefFemale, "Female" },
{ ColumnId_LevelledList,"Levelled List" },
{ ColumnId_LevelledItemId,"Item ID" },
{ ColumnId_LevelledItemLevel,"Level" },
{ ColumnId_LevelledItemType, "Type" },
{ ColumnId_LevelledItemChanceNone, "Chance None" },
{ ColumnId_PowerList, "Powers" },
{ ColumnId_SkillImpact, "Skills" },
{ ColumnId_InfoList, "Info List" },
{ ColumnId_UseValue1, "Use value 1" },
{ ColumnId_UseValue2, "Use value 2" },
{ ColumnId_UseValue3, "Use value 3" },
@ -228,6 +300,7 @@ namespace CSMWorld
{ ColumnId_Skill4, "Skill 4" },
{ ColumnId_Skill5, "Skill 5" },
{ ColumnId_Skill6, "Skill 6" },
{ ColumnId_Skill7, "Skill 7" },
{ -1, 0 } // end marker
};
@ -261,6 +334,7 @@ namespace
"Combat", "Magic", "Stealth", 0
};
// see ESM::Attribute::AttributeID in <component/esm/attr.hpp>
static const char *sAttributes[] =
{
"Strength", "Intelligence", "Willpower", "Agility", "Speed", "Endurance", "Personality",
@ -353,6 +427,79 @@ namespace
"Alteration", "Conjuration", "Destruction", "Illusion", "Mysticism", "Restoration", 0
};
// impact from magic effects, see ESM::Skill::SkillEnum in <component/esm/loadskil.hpp>
static const char *sSkills[] =
{
"Block", "Armorer", "MediumArmor", "HeavyArmor", "BluntWeapon",
"LongBlade", "Axe", "Spear", "Athletics", "Enchant",
"Destruction", "Alteration", "Illusion", "Conjuration", "Mysticism",
"Restoration", "Alchemy", "Unarmored", "Security", "Sneak",
"Acrobatics", "LightArmor", "ShortBlade", "Marksman", "Mercantile",
"Speechcraft", "HandToHand", 0
};
// range of magic effects, see ESM::RangeType in <component/esm/defs.hpp>
static const char *sEffectRange[] =
{
"Self", "Touch", "Target", 0
};
// magic effect names, see ESM::MagicEffect::Effects in <component/esm/loadmgef.hpp>
static const char *sEffectId[] =
{
"WaterBreathing", "SwiftSwim", "WaterWalking", "Shield", "FireShield",
"LightningShield", "FrostShield", "Burden", "Feather", "Jump",
"Levitate", "SlowFall", "Lock", "Open", "FireDamage",
"ShockDamage", "FrostDamage", "DrainAttribute", "DrainHealth", "DrainMagicka",
"DrainFatigue", "DrainSkill", "DamageAttribute", "DamageHealth", "DamageMagicka",
"DamageFatigue", "DamageSkill", "Poison", "WeaknessToFire", "WeaknessToFrost",
"WeaknessToShock", "WeaknessToMagicka", "WeaknessToCommonDisease", "WeaknessToBlightDisease", "WeaknessToCorprusDisease",
"WeaknessToPoison", "WeaknessToNormalWeapons", "DisintegrateWeapon", "DisintegrateArmor", "Invisibility",
"Chameleon", "Light", "Sanctuary", "NightEye", "Charm",
"Paralyze", "Silence", "Blind", "Sound", "CalmHumanoid",
"CalmCreature", "FrenzyHumanoid", "FrenzyCreature", "DemoralizeHumanoid", "DemoralizeCreature",
"RallyHumanoid", "RallyCreature", "Dispel", "Soultrap", "Telekinesis",
"Mark", "Recall", "DivineIntervention", "AlmsiviIntervention", "DetectAnimal",
"DetectEnchantment", "DetectKey", "SpellAbsorption", "Reflect", "CureCommonDisease",
"CureBlightDisease", "CureCorprusDisease", "CurePoison", "CureParalyzation", "RestoreAttribute",
"RestoreHealth", "RestoreMagicka", "RestoreFatigue", "RestoreSkill", "FortifyAttribute",
"FortifyHealth", "FortifyMagicka", "FortifyFatigue", "FortifySkill", "FortifyMaximumMagicka",
"AbsorbAttribute", "AbsorbHealth", "AbsorbMagicka", "AbsorbFatigue", "AbsorbSkill",
"ResistFire", "ResistFrost", "ResistShock", "ResistMagicka", "ResistCommonDisease",
"ResistBlightDisease", "ResistCorprusDisease", "ResistPoison", "ResistNormalWeapons", "ResistParalysis",
"RemoveCurse", "TurnUndead", "SummonScamp", "SummonClannfear", "SummonDaedroth",
"SummonDremora", "SummonAncestralGhost", "SummonSkeletalMinion", "SummonBonewalker", "SummonGreaterBonewalker",
"SummonBonelord", "SummonWingedTwilight", "SummonHunger", "SummonGoldenSaint", "SummonFlameAtronach",
"SummonFrostAtronach", "SummonStormAtronach", "FortifyAttack", "CommandCreature", "CommandHumanoid",
"BoundDagger", "BoundLongsword", "BoundMace", "BoundBattleAxe", "BoundSpear",
"BoundLongbow", "ExtraSpell", "BoundCuirass", "BoundHelm", "BoundBoots",
"BoundShield", "BoundGloves", "Corprus", "Vampirism", "SummonCenturionSphere",
"SunDamage", "StuntedMagicka", "SummonFabricant", "SummonWolf", "SummonBear",
"SummonBonewolf", "SummonCreature04", "SummonCreature05", 0
};
// see ESM::PartReferenceType in <component/esm/loadarmo.hpp>
static const char *sPartRefType[] =
{
"Head", "Hair", "Neck", "Cuirass", "Groin",
"Skirt", "Right Hand", "Left Hand", "Right Wrist", "Left Wrist",
"Shield", "Right Forearm", "Left Forearm", "Right Upperarm", "Left Upperarm",
"Right Foot", "Left Foot", "Right Ankle", "Left Ankle", "Right Knee",
"Left Knee", "Right Leg", "Left Leg", "Right Pauldron", "Left Pauldron",
"Weapon", "Tail", 0
};
// see the enums in <component/esm/aipackage.hpp>
static const char *sAiPackageType[] =
{
"AI Wander", "AI Travel", "AI Follow", "AI Escort", "AI Activate", 0
};
static const char *sAiWanderRepeat[] =
{
"No", "Yes", 0
};
const char **getEnumNames (CSMWorld::Columns::ColumnId column)
{
switch (column)
@ -375,6 +522,12 @@ namespace
case CSMWorld::Columns::ColumnId_MeshType: return sMeshTypes;
case CSMWorld::Columns::ColumnId_SoundGeneratorType: return sSoundGeneratorType;
case CSMWorld::Columns::ColumnId_School: return sSchools;
case CSMWorld::Columns::ColumnId_SkillImpact: return sSkills;
case CSMWorld::Columns::ColumnId_EffectRange: return sEffectRange;
case CSMWorld::Columns::ColumnId_EffectId: return sEffectId;
case CSMWorld::Columns::ColumnId_PartRefType: return sPartRefType;
case CSMWorld::Columns::ColumnId_AiPackageType: return sAiPackageType;
case CSMWorld::Columns::ColumnId_AiWanderRepeat: return sAiWanderRepeat;
default: return 0;
}

View File

@ -4,6 +4,8 @@
#include <string>
#include <vector>
#include "columnbase.hpp"
namespace CSMWorld
{
namespace Columns
@ -165,35 +167,103 @@ namespace CSMWorld
ColumnId_Rank = 152,
ColumnId_Gender = 153,
ColumnId_PcRank = 154,
ColumnId_ReferenceableId = 156,
ColumnId_CombatState = 157,
ColumnId_MagicState = 158,
ColumnId_StealthState = 159,
ColumnId_EnchantmentType = 160,
ColumnId_Vampire = 161,
ColumnId_BodyPartType = 162,
ColumnId_MeshType = 163,
ColumnId_OwnerGlobal = 164,
ColumnId_DefaultProfile = 165,
ColumnId_BypassNewGame = 166,
ColumnId_GlobalProfile = 167,
ColumnId_RefNumCounter = 168,
ColumnId_RefNum = 169,
ColumnId_Creature = 170,
ColumnId_SoundGeneratorType = 171,
ColumnId_AllowSpellmaking = 172,
ColumnId_AllowEnchanting = 173,
ColumnId_BaseCost = 174,
ColumnId_School = 175,
ColumnId_Particle = 176,
ColumnId_CastingObject = 177,
ColumnId_HitObject = 178,
ColumnId_AreaObject = 179,
ColumnId_BoltObject = 180,
ColumnId_CastingSound = 177,
ColumnId_HitSound = 178,
ColumnId_AreaSound = 179,
ColumnId_BoltSound = 180,
ColumnId_ReferenceableId = 155,
ColumnId_ContainerContent = 156,
ColumnId_ItemCount = 157,
ColumnId_InventoryItemId = 158,
ColumnId_CombatState = 159,
ColumnId_MagicState = 160,
ColumnId_StealthState = 161,
ColumnId_EnchantmentType = 162,
ColumnId_Vampire = 163,
ColumnId_BodyPartType = 164,
ColumnId_MeshType = 165,
ColumnId_ActorInventory = 166,
ColumnId_SpellList = 167,
ColumnId_SpellId = 168,
ColumnId_NpcDestinations = 169,
ColumnId_DestinationCell = 170,
ColumnId_PosX = 171, // these are float
ColumnId_PosY = 172, // these are float
ColumnId_PosZ = 173, // these are float
ColumnId_RotX = 174,
ColumnId_RotY = 175,
ColumnId_RotZ = 176,
ColumnId_Skill = 177,
ColumnId_OwnerGlobal = 178,
ColumnId_DefaultProfile = 179,
ColumnId_BypassNewGame = 180,
ColumnId_GlobalProfile = 181,
ColumnId_RefNumCounter = 182,
ColumnId_RefNum = 183,
ColumnId_Creature = 184,
ColumnId_SoundGeneratorType = 185,
ColumnId_AllowSpellmaking = 186,
ColumnId_AllowEnchanting = 187,
ColumnId_BaseCost = 188,
ColumnId_School = 189,
ColumnId_Particle = 190,
ColumnId_CastingObject = 191,
ColumnId_HitObject = 192,
ColumnId_AreaObject = 193,
ColumnId_BoltObject = 194,
ColumnId_CastingSound = 195,
ColumnId_HitSound = 196,
ColumnId_AreaSound = 197,
ColumnId_BoltSound = 198,
ColumnId_PathgridPoints = 199,
ColumnId_PathgridIndex = 200,
ColumnId_PathgridPosX = 201, // these are int
ColumnId_PathgridPosY = 202, // these are int
ColumnId_PathgridPosZ = 203, // these are int
ColumnId_PathgridEdges = 204,
ColumnId_PathgridEdgeIndex = 205,
ColumnId_PathgridEdge0 = 206,
ColumnId_PathgridEdge1 = 207,
ColumnId_RegionSounds = 208,
ColumnId_SoundName = 209,
ColumnId_SoundChance = 210,
ColumnId_FactionReactions = 211,
//ColumnId_FactionID = 212,
ColumnId_FactionReaction = 213,
ColumnId_EffectList = 214,
ColumnId_EffectId = 215,
//ColumnId_EffectAttribute = 216,
ColumnId_EffectRange = 217,
ColumnId_EffectArea = 218,
ColumnId_AiPackageList = 219,
ColumnId_AiPackageType = 220,
ColumnId_AiWanderDist = 221,
ColumnId_AiDuration = 222,
ColumnId_AiWanderToD = 223,
ColumnId_AiWanderIdle = 224,
ColumnId_AiWanderRepeat = 225,
ColumnId_AiActivateName = 226,
// use ColumnId_PosX, etc for AI destinations
ColumnId_AiTargetId = 227,
ColumnId_AiTargetCell = 228,
ColumnId_PartRefList = 229,
ColumnId_PartRefType = 230,
ColumnId_PartRefMale = 231,
ColumnId_PartRefFemale = 232,
ColumnId_LevelledList = 233,
ColumnId_LevelledItemId = 234,
ColumnId_LevelledItemLevel = 235,
ColumnId_LevelledItemType = 236,
ColumnId_LevelledItemChanceNone = 237,
ColumnId_PowerList = 238,
ColumnId_SkillImpact = 239, // impact from magic effects
ColumnId_InfoList = 240,
// Allocated to a separate value range, so we don't get a collision should we ever need
// to extend the number of use values.
ColumnId_UseValue1 = 0x10000,
@ -227,7 +297,8 @@ namespace CSMWorld
ColumnId_Skill3 = 0x50002,
ColumnId_Skill4 = 0x50003,
ColumnId_Skill5 = 0x50004,
ColumnId_Skill6 = 0x50005
ColumnId_Skill6 = 0x50005,
ColumnId_Skill7 = 0x50006
};
std::string getName (ColumnId column);

View File

@ -1,10 +1,11 @@
#include "commands.hpp"
#include <QAbstractItemModel>
#include "idtable.hpp"
#include "idtree.hpp"
#include <components/misc/stringops.hpp>
#include "nestedtablewrapper.hpp"
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
const QVariant& new_, QUndoCommand* parent)
@ -171,3 +172,75 @@ void CSMWorld::CloneCommand::undo()
{
mModel.removeRow (mModel.getModelIndex (mId, 0).row());
}
CSMWorld::DeleteNestedCommand::DeleteNestedCommand (IdTree& model,
const std::string& id,
int nestedRow,
int parentColumn,
QUndoCommand* parent) :
mId(id),
mModel(model),
mParentColumn(parentColumn),
QUndoCommand(parent),
mNestedRow(nestedRow),
NestedTableStoring(model, id, parentColumn)
{
std::string title =
model.headerData(parentColumn, Qt::Horizontal, Qt::DisplayRole).toString().toUtf8().constData();
setText (("Delete row in " + title + " sub-table of " + mId).c_str());
}
void CSMWorld::DeleteNestedCommand::redo()
{
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
mModel.removeRows (mNestedRow, 1, parentIndex);
}
void CSMWorld::DeleteNestedCommand::undo()
{
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
mModel.setNestedTable(parentIndex, getOld());
}
CSMWorld::AddNestedCommand::AddNestedCommand(IdTree& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent)
: mModel(model),
mId(id),
mNewRow(nestedRow),
mParentColumn(parentColumn),
QUndoCommand(parent),
NestedTableStoring(model, id, parentColumn)
{
std::string title =
model.headerData(parentColumn, Qt::Horizontal, Qt::DisplayRole).toString().toUtf8().constData();
setText (("Add row in " + title + " sub-table of " + mId).c_str());
}
void CSMWorld::AddNestedCommand::redo()
{
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
mModel.addNestedRow (parentIndex, mNewRow);
}
void CSMWorld::AddNestedCommand::undo()
{
const QModelIndex& parentIndex = mModel.getModelIndex(mId, mParentColumn);
mModel.setNestedTable(parentIndex, getOld());
}
CSMWorld::NestedTableStoring::NestedTableStoring(const IdTree& model, const std::string& id, int parentColumn)
: mOld(model.nestedTable(model.getModelIndex(id, parentColumn))) {}
CSMWorld::NestedTableStoring::~NestedTableStoring()
{
delete mOld;
}
const CSMWorld::NestedTableWrapperBase& CSMWorld::NestedTableStoring::getOld() const
{
return *mOld;
}

View File

@ -12,6 +12,7 @@
#include <QModelIndex>
#include "universalid.hpp"
#include "nestedtablewrapper.hpp"
class QModelIndex;
class QAbstractItemModel;
@ -19,8 +20,9 @@ class QAbstractItemModel;
namespace CSMWorld
{
class IdTable;
class IdTable;
class IdTree;
struct RecordBase;
struct NestedTableWrapperBase;
class ModifyCommand : public QUndoCommand
{
@ -139,6 +141,58 @@ namespace CSMWorld
virtual void undo();
};
class NestedTableStoring
{
NestedTableWrapperBase* mOld;
public:
NestedTableStoring(const IdTree& model, const std::string& id, int parentColumn);
~NestedTableStoring();
protected:
const NestedTableWrapperBase& getOld() const;
};
class DeleteNestedCommand : public QUndoCommand, private NestedTableStoring
{
IdTree& mModel;
std::string mId;
int mParentColumn;
int mNestedRow;
public:
DeleteNestedCommand (IdTree& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
virtual void redo();
virtual void undo();
};
class AddNestedCommand : public QUndoCommand, private NestedTableStoring
{
IdTree& mModel;
std::string mId;
int mNewRow;
int mParentColumn;
public:
AddNestedCommand(IdTree& model, const std::string& id, int nestedRow, int parentColumn, QUndoCommand* parent = 0);
virtual void redo();
virtual void undo();
};
}
#endif

View File

@ -12,11 +12,13 @@
#include <components/esm/cellref.hpp>
#include "idtable.hpp"
#include "idtree.hpp"
#include "columnimp.hpp"
#include "regionmap.hpp"
#include "columns.hpp"
#include "resourcesmanager.hpp"
#include "resourcetable.hpp"
#include "nestedcoladapterimp.hpp"
void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type, bool update)
{
@ -62,6 +64,8 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
: mEncoder (encoding), mPathgrids (mCells), mRefs (mCells),
mResourcesManager (resourcesManager), mReader (0), mDialogue (0), mReaderIndex(0)
{
int index = 0;
mGlobals.addColumn (new StringIdColumn<ESM::Global>);
mGlobals.addColumn (new RecordStateColumn<ESM::Global>);
mGlobals.addColumn (new FixedRecordTypeColumn<ESM::Global> (UniversalId::Type_Global));
@ -106,6 +110,14 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mFactions.addColumn (new HiddenColumn<ESM::Faction>);
for (int i=0; i<7; ++i)
mFactions.addColumn (new SkillsColumn<ESM::Faction> (i));
// Faction Reactions
mFactions.addColumn (new NestedParentColumn<ESM::Faction> (Columns::ColumnId_FactionReactions));
index = mFactions.getColumns()-1;
mFactions.addAdapter (std::make_pair(&mFactions.getColumn(index), new FactionReactionsAdapter ()));
mFactions.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_Faction, ColumnBase::Display_String));
mFactions.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_FactionReaction, ColumnBase::Display_Integer));
mRaces.addColumn (new StringIdColumn<ESM::Race>);
mRaces.addColumn (new RecordStateColumn<ESM::Race>);
@ -118,6 +130,12 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mRaces.addColumn (new WeightHeightColumn<ESM::Race> (true, false));
mRaces.addColumn (new WeightHeightColumn<ESM::Race> (false, true));
mRaces.addColumn (new WeightHeightColumn<ESM::Race> (false, false));
// Race spells
mRaces.addColumn (new NestedParentColumn<ESM::Race> (Columns::ColumnId_PowerList));
index = mRaces.getColumns()-1;
mRaces.addAdapter (std::make_pair(&mRaces.getColumn(index), new SpellListAdapter<ESM::Race> ()));
mRaces.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_SpellId, ColumnBase::Display_String));
mSounds.addColumn (new StringIdColumn<ESM::Sound>);
mSounds.addColumn (new RecordStateColumn<ESM::Sound>);
@ -138,6 +156,14 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mRegions.addColumn (new NameColumn<ESM::Region>);
mRegions.addColumn (new MapColourColumn<ESM::Region>);
mRegions.addColumn (new SleepListColumn<ESM::Region>);
// Region Sounds
mRegions.addColumn (new NestedParentColumn<ESM::Region> (Columns::ColumnId_RegionSounds));
index = mRegions.getColumns()-1;
mRegions.addAdapter (std::make_pair(&mRegions.getColumn(index), new RegionSoundListAdapter ()));
mRegions.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_SoundName, ColumnBase::Display_String));
mRegions.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_SoundChance, ColumnBase::Display_Integer));
mBirthsigns.addColumn (new StringIdColumn<ESM::BirthSign>);
mBirthsigns.addColumn (new RecordStateColumn<ESM::BirthSign>);
@ -145,6 +171,13 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mBirthsigns.addColumn (new NameColumn<ESM::BirthSign>);
mBirthsigns.addColumn (new TextureColumn<ESM::BirthSign>);
mBirthsigns.addColumn (new DescriptionColumn<ESM::BirthSign>);
// Birthsign spells
mBirthsigns.addColumn (new NestedParentColumn<ESM::BirthSign> (Columns::ColumnId_PowerList));
index = mBirthsigns.getColumns()-1;
mBirthsigns.addAdapter (std::make_pair(&mBirthsigns.getColumn(index),
new SpellListAdapter<ESM::BirthSign> ()));
mBirthsigns.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_SpellId, ColumnBase::Display_String));
mSpells.addColumn (new StringIdColumn<ESM::Spell>);
mSpells.addColumn (new RecordStateColumn<ESM::Spell>);
@ -155,6 +188,26 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mSpells.addColumn (new FlagColumn<ESM::Spell> (Columns::ColumnId_AutoCalc, 0x1));
mSpells.addColumn (new FlagColumn<ESM::Spell> (Columns::ColumnId_StarterSpell, 0x2));
mSpells.addColumn (new FlagColumn<ESM::Spell> (Columns::ColumnId_AlwaysSucceeds, 0x4));
// Spell effects
mSpells.addColumn (new NestedParentColumn<ESM::Spell> (Columns::ColumnId_EffectList));
index = mSpells.getColumns()-1;
mSpells.addAdapter (std::make_pair(&mSpells.getColumn(index), new EffectsListAdapter<ESM::Spell> ()));
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_EffectId, ColumnBase::Display_EffectId));
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_SkillImpact, ColumnBase::Display_SkillImpact));
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_Attribute, ColumnBase::Display_Attribute));
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_EffectRange, ColumnBase::Display_EffectRange));
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_EffectArea, ColumnBase::Display_String));
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_Duration, ColumnBase::Display_Integer)); // reuse from light
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_MinRange, ColumnBase::Display_Integer)); // reuse from sound
mSpells.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_MaxRange, ColumnBase::Display_Integer)); // reuse from sound
mTopics.addColumn (new StringIdColumn<ESM::Dialogue>);
mTopics.addColumn (new RecordStateColumn<ESM::Dialogue>);
@ -182,6 +235,13 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mTopicInfos.addColumn (new PcRankColumn<Info>);
mTopicInfos.addColumn (new SoundFileColumn<Info>);
mTopicInfos.addColumn (new ResponseColumn<Info>);
// Result script
mTopicInfos.addColumn (new NestedParentColumn<Info> (Columns::ColumnId_InfoList,
ColumnBase::Flag_Dialogue | ColumnBase::Flag_Dialogue_List));
index = mTopicInfos.getColumns()-1;
mTopicInfos.addAdapter (std::make_pair(&mTopicInfos.getColumn(index), new InfoListAdapter ()));
mTopicInfos.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_ScriptText, ColumnBase::Display_ScriptLines));
mJournalInfos.addColumn (new StringIdColumn<Info> (true));
mJournalInfos.addColumn (new RecordStateColumn<Info>);
@ -208,6 +268,27 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mEnchantments.addColumn (new CostColumn<ESM::Enchantment>);
mEnchantments.addColumn (new ChargesColumn2<ESM::Enchantment>);
mEnchantments.addColumn (new AutoCalcColumn<ESM::Enchantment>);
// Enchantment effects
mEnchantments.addColumn (new NestedParentColumn<ESM::Enchantment> (Columns::ColumnId_EffectList));
index = mEnchantments.getColumns()-1;
mEnchantments.addAdapter (std::make_pair(&mEnchantments.getColumn(index),
new EffectsListAdapter<ESM::Enchantment> ()));
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_EffectId, ColumnBase::Display_EffectId));
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_SkillImpact, ColumnBase::Display_SkillImpact));
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_Attribute, ColumnBase::Display_Attribute));
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_EffectRange, ColumnBase::Display_EffectRange));
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_EffectArea, ColumnBase::Display_String));
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_Duration, ColumnBase::Display_Integer)); // reuse from light
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_MinRange, ColumnBase::Display_Integer)); // reuse from sound
mEnchantments.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_MaxRange, ColumnBase::Display_Integer)); // reuse from sound
mBodyParts.addColumn (new StringIdColumn<ESM::BodyPart>);
mBodyParts.addColumn (new RecordStateColumn<ESM::BodyPart>);
@ -254,6 +335,32 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mPathgrids.addColumn (new RecordStateColumn<Pathgrid>);
mPathgrids.addColumn (new FixedRecordTypeColumn<Pathgrid> (UniversalId::Type_Pathgrid));
// new object deleted in dtor of Collection<T,A>
mPathgrids.addColumn (new NestedParentColumn<Pathgrid> (Columns::ColumnId_PathgridPoints));
index = mPathgrids.getColumns()-1;
// new object deleted in dtor of NestedCollection<T,A>
mPathgrids.addAdapter (std::make_pair(&mPathgrids.getColumn(index), new PathgridPointListAdapter ()));
// new objects deleted in dtor of NestableColumn
// WARNING: The order of the columns below are assumed in PathgridPointListAdapter
mPathgrids.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_PathgridIndex, ColumnBase::Display_Integer, false));
mPathgrids.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_PathgridPosX, ColumnBase::Display_Integer));
mPathgrids.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_PathgridPosY, ColumnBase::Display_Integer));
mPathgrids.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_PathgridPosZ, ColumnBase::Display_Integer));
mPathgrids.addColumn (new NestedParentColumn<Pathgrid> (Columns::ColumnId_PathgridEdges));
index = mPathgrids.getColumns()-1;
mPathgrids.addAdapter (std::make_pair(&mPathgrids.getColumn(index), new PathgridEdgeListAdapter ()));
mPathgrids.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_PathgridEdgeIndex, ColumnBase::Display_Integer, false));
mPathgrids.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_PathgridEdge0, ColumnBase::Display_Integer));
mPathgrids.getNestableColumn(index)->addColumn(
new NestedChildColumn (Columns::ColumnId_PathgridEdge1, ColumnBase::Display_Integer));
mStartScripts.addColumn (new StringIdColumn<ESM::StartScript>);
mStartScripts.addColumn (new RecordStateColumn<ESM::StartScript>);
mStartScripts.addColumn (new FixedRecordTypeColumn<ESM::StartScript> (UniversalId::Type_StartScript));
@ -314,25 +421,26 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
addModel (new IdTable (&mGmsts), UniversalId::Type_Gmst);
addModel (new IdTable (&mSkills), UniversalId::Type_Skill);
addModel (new IdTable (&mClasses), UniversalId::Type_Class);
addModel (new IdTable (&mFactions), UniversalId::Type_Faction);
addModel (new IdTable (&mRaces), UniversalId::Type_Race);
addModel (new IdTree (&mFactions, &mFactions), UniversalId::Type_Faction);
addModel (new IdTree (&mRaces, &mRaces), UniversalId::Type_Race);
addModel (new IdTable (&mSounds), UniversalId::Type_Sound);
addModel (new IdTable (&mScripts), UniversalId::Type_Script);
addModel (new IdTable (&mRegions), UniversalId::Type_Region);
addModel (new IdTable (&mBirthsigns), UniversalId::Type_Birthsign);
addModel (new IdTable (&mSpells), UniversalId::Type_Spell);
addModel (new IdTree (&mRegions, &mRegions), UniversalId::Type_Region);
addModel (new IdTree (&mBirthsigns, &mBirthsigns), UniversalId::Type_Birthsign);
addModel (new IdTree (&mSpells, &mSpells), UniversalId::Type_Spell);
addModel (new IdTable (&mTopics), UniversalId::Type_Topic);
addModel (new IdTable (&mJournals), UniversalId::Type_Journal);
addModel (new IdTable (&mTopicInfos, IdTable::Feature_ReorderWithinTopic), UniversalId::Type_TopicInfo);
addModel (new IdTree (&mTopicInfos, &mTopicInfos, IdTable::Feature_ReorderWithinTopic),
UniversalId::Type_TopicInfo);
addModel (new IdTable (&mJournalInfos, IdTable::Feature_ReorderWithinTopic), UniversalId::Type_JournalInfo);
addModel (new IdTable (&mCells, IdTable::Feature_ViewId), UniversalId::Type_Cell);
addModel (new IdTable (&mEnchantments), UniversalId::Type_Enchantment);
addModel (new IdTree (&mEnchantments, &mEnchantments), UniversalId::Type_Enchantment);
addModel (new IdTable (&mBodyParts), UniversalId::Type_BodyPart);
addModel (new IdTable (&mSoundGens), UniversalId::Type_SoundGen);
addModel (new IdTable (&mMagicEffects), UniversalId::Type_MagicEffect);
addModel (new IdTable (&mPathgrids), UniversalId::Type_Pathgrid);
addModel (new IdTree (&mPathgrids, &mPathgrids), UniversalId::Type_Pathgrid);
addModel (new IdTable (&mStartScripts), UniversalId::Type_StartScript);
addModel (new IdTable (&mReferenceables, IdTable::Feature_Preview),
addModel (new IdTree (&mReferenceables, &mReferenceables, IdTable::Feature_Preview),
UniversalId::Type_Referenceable);
addModel (new IdTable (&mRefs, IdTable::Feature_ViewCell | IdTable::Feature_Preview), UniversalId::Type_Reference);
addModel (new IdTable (&mFilters), UniversalId::Type_Filter);

View File

@ -34,6 +34,7 @@
#include "../doc/stage.hpp"
#include "idcollection.hpp"
#include "nestedidcollection.hpp"
#include "universalid.hpp"
#include "cell.hpp"
#include "land.hpp"
@ -41,8 +42,11 @@
#include "refidcollection.hpp"
#include "refcollection.hpp"
#include "infocollection.hpp"
#include "nestedinfocollection.hpp"
#include "pathgrid.hpp"
#ifndef Q_MOC_RUN
#include "subcellcollection.hpp"
#endif
class QAbstractItemModel;
@ -66,23 +70,23 @@ namespace CSMWorld
IdCollection<ESM::GameSetting> mGmsts;
IdCollection<ESM::Skill> mSkills;
IdCollection<ESM::Class> mClasses;
IdCollection<ESM::Faction> mFactions;
IdCollection<ESM::Race> mRaces;
NestedIdCollection<ESM::Faction> mFactions;
NestedIdCollection<ESM::Race> mRaces;
IdCollection<ESM::Sound> mSounds;
IdCollection<ESM::Script> mScripts;
IdCollection<ESM::Region> mRegions;
IdCollection<ESM::BirthSign> mBirthsigns;
IdCollection<ESM::Spell> mSpells;
NestedIdCollection<ESM::Region> mRegions;
NestedIdCollection<ESM::BirthSign> mBirthsigns;
NestedIdCollection<ESM::Spell> mSpells;
IdCollection<ESM::Dialogue> mTopics;
IdCollection<ESM::Dialogue> mJournals;
IdCollection<ESM::Enchantment> mEnchantments;
NestedIdCollection<ESM::Enchantment> mEnchantments;
IdCollection<ESM::BodyPart> mBodyParts;
IdCollection<ESM::MagicEffect> mMagicEffects;
SubCellCollection<Pathgrid> mPathgrids;
IdCollection<ESM::DebugProfile> mDebugProfiles;
IdCollection<ESM::SoundGenerator> mSoundGens;
IdCollection<ESM::StartScript> mStartScripts;
InfoCollection mTopicInfos;
NestedInfoCollection mTopicInfos;
InfoCollection mJournalInfos;
IdCollection<Cell> mCells;
IdCollection<LandTexture> mLandTextures;

View File

@ -1,6 +1,7 @@
#include "idtable.hpp"
#include <stdexcept>
#include "collectionbase.hpp"
#include "columnbase.hpp"
@ -43,6 +44,9 @@ QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation
if (orientation==Qt::Vertical)
return QVariant();
if (orientation != Qt::Horizontal)
throw std::logic_error("Unknown header orientation specified");
if (role==Qt::DisplayRole)
return tr (mIdCollection->getColumn (section).getTitle().c_str());
@ -55,7 +59,7 @@ QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation
return QVariant();
}
bool CSMWorld::IdTable::setData ( const QModelIndex &index, const QVariant &value, int role)
bool CSMWorld::IdTable::setData (const QModelIndex &index, const QVariant &value, int role)
{
if (mIdCollection->getColumn (index.column()).isEditable() && role==Qt::EditRole)
{
@ -129,15 +133,16 @@ void CSMWorld::IdTable::cloneRecord(const std::string& origin,
CSMWorld::UniversalId::Type type)
{
int index = mIdCollection->getAppendIndex (destination);
beginInsertRows (QModelIndex(), index, index);
mIdCollection->cloneRecord(origin, destination, type);
endInsertRows();
}
///This method can return only indexes to the top level table cells
QModelIndex CSMWorld::IdTable::getModelIndex (const std::string& id, int column) const
{
return index (mIdCollection->getIndex (id), column);
return index(mIdCollection->getIndex (id), column);
}
void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& record)
@ -221,6 +226,7 @@ std::pair<CSMWorld::UniversalId, std::string> CSMWorld::IdTable::view (int row)
return std::make_pair (UniversalId (UniversalId::Type_Scene, id), hint);
}
///For top level data/columns
bool CSMWorld::IdTable::isDeleted (const std::string& id) const
{
return getRecord (id).isDeleted();
@ -230,3 +236,8 @@ int CSMWorld::IdTable::getColumnId(int column) const
{
return mIdCollection->getColumn(column).getId();
}
CSMWorld::CollectionBase *CSMWorld::IdTable::idCollection() const
{
return mIdCollection;
}

View File

@ -83,6 +83,10 @@ namespace CSMWorld
virtual bool isDeleted (const std::string& id) const;
virtual int getColumnId(int column) const;
protected:
virtual CollectionBase *idCollection() const;
};
}

View File

@ -0,0 +1,259 @@
#include "idtree.hpp"
#include "nestedtablewrapper.hpp"
#include "collectionbase.hpp"
#include "nestedcollection.hpp"
#include "columnbase.hpp"
// NOTE: parent class still needs idCollection
CSMWorld::IdTree::IdTree (NestedCollection *nestedCollection, CollectionBase *idCollection, unsigned int features)
: IdTable (idCollection, features), mNestedCollection (nestedCollection)
{}
CSMWorld::IdTree::~IdTree()
{}
int CSMWorld::IdTree::rowCount (const QModelIndex & parent) const
{
if (hasChildren(parent))
return mNestedCollection->getNestedRowsCount(parent.row(), parent.column());
return IdTable::rowCount(parent);
}
int CSMWorld::IdTree::columnCount (const QModelIndex & parent) const
{
if (hasChildren(parent))
return mNestedCollection->getNestedColumnsCount(parent.row(), parent.column());
return IdTable::columnCount(parent);
}
QVariant CSMWorld::IdTree::data (const QModelIndex & index, int role) const
{
if (!index.isValid())
return QVariant();
if ((role!=Qt::DisplayRole && role!=Qt::EditRole) || index.row() < 0 || index.column() < 0)
return QVariant();
if (index.internalId() != 0)
{
std::pair<int, int> parentAddress(unfoldIndexAddress(index.internalId()));
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
{
if (section < 0 || section >= idCollection()->getColumns())
return QVariant();
const NestableColumn *parentColumn = mNestedCollection->getNestableColumn(section);
if (orientation==Qt::Vertical)
return QVariant();
if (role==Qt::DisplayRole)
return tr(parentColumn->nestedColumn(subSection).getTitle().c_str());
if (role==ColumnBase::Role_Flags)
return idCollection()->getColumn (section).mFlags;
if (role==ColumnBase::Role_Display)
return parentColumn->nestedColumn(subSection).mDisplayType;
return QVariant();
}
bool CSMWorld::IdTree::setData (const QModelIndex &index, const QVariant &value, int role)
{
if (index.internalId() != 0)
{
if (idCollection()->getColumn(parent(index).column()).isEditable() && role==Qt::EditRole)
{
const std::pair<int, int>& parentAddress(unfoldIndexAddress(index.internalId()));
mNestedCollection->setNestedData(parentAddress.first, parentAddress.second, value, index.row(), index.column());
emit dataChanged (CSMWorld::IdTree::index (parentAddress.first, 0),
CSMWorld::IdTree::index (parentAddress.first, idCollection()->getColumns()-1));
return true;
}
else
return false;
}
return IdTable::setData(index, value, role);
}
Qt::ItemFlags CSMWorld::IdTree::flags (const QModelIndex & index) const
{
if (!index.isValid())
return 0;
if (index.internalId() != 0)
{
std::pair<int, int> parentAddress(unfoldIndexAddress(index.internalId()));
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if (mNestedCollection->getNestableColumn(parentAddress.second)->nestedColumn(index.column()).isEditable())
flags |= Qt::ItemIsEditable;
return flags;
}
else
return IdTable::flags(index);
}
bool CSMWorld::IdTree::removeRows (int row, int count, const QModelIndex& parent)
{
if (parent.isValid())
{
beginRemoveRows (parent, row, row+count-1);
for (int i = 0; i < count; ++i)
{
mNestedCollection->removeNestedRows(parent.row(), parent.column(), row+i);
}
endRemoveRows();
emit dataChanged (CSMWorld::IdTree::index (parent.row(), 0),
CSMWorld::IdTree::index (parent.row(), idCollection()->getColumns()-1));
return true;
}
else
return IdTable::removeRows(row, count, parent);
}
void CSMWorld::IdTree::addNestedRow(const QModelIndex& parent, int position)
{
if (!hasChildren(parent))
throw std::logic_error("Tried to set nested table, but index has no children");
int row = parent.row();
beginInsertRows(parent, position, position);
mNestedCollection->addNestedRow(row, parent.column(), position);
endInsertRows();
emit dataChanged (CSMWorld::IdTree::index (row, 0),
CSMWorld::IdTree::index (row, idCollection()->getColumns()-1));
}
QModelIndex CSMWorld::IdTree::index (int row, int column, const QModelIndex& parent) const
{
unsigned int encodedId = 0;
if (parent.isValid())
{
encodedId = this->foldIndexAddress(parent);
}
if (row<0 || row>=idCollection()->getSize())
return QModelIndex();
if (column<0 || column>=idCollection()->getColumns())
return QModelIndex();
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(unfoldIndexAddress(id));
if (adress.first >= this->rowCount() || adress.second >= this->columnCount())
throw "Parent index is not present in the model";
return createIndex(adress.first, adress.second);
}
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::unfoldIndexAddress (unsigned int id) const
{
if (id == 0)
throw "Attempt to unfold index id of the top level data cell";
--id;
int row = id / this->columnCount();
int column = id - row * this->columnCount();
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)
//
// Also see comments in refidadapter.hpp and refidadapterimp.hpp.
bool CSMWorld::IdTree::hasChildren(const QModelIndex& index) const
{
return (index.isValid() &&
index.internalId() == 0 &&
mNestedCollection->getNestableColumn(index.column())->hasChildren() &&
index.data().isValid());
}
void CSMWorld::IdTree::setNestedTable(const QModelIndex& index, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
if (!hasChildren(index))
throw std::logic_error("Tried to set nested table, but index has no children");
bool removeRowsMode = false;
if (nestedTable.size() != this->nestedTable(index)->size())
{
emit resetStart(this->index(index.row(), 0).data().toString());
removeRowsMode = true;
}
mNestedCollection->setNestedTable(index.row(), index.column(), nestedTable);
emit dataChanged (CSMWorld::IdTree::index (index.row(), 0),
CSMWorld::IdTree::index (index.row(), idCollection()->getColumns()-1));
if (removeRowsMode)
{
emit resetEnd(this->index(index.row(), 0).data().toString());
}
}
CSMWorld::NestedTableWrapperBase* CSMWorld::IdTree::nestedTable(const QModelIndex& index) const
{
if (!hasChildren(index))
throw std::logic_error("Tried to retrive nested table, but index has no children");
return mNestedCollection->nestedTable(index.row(), index.column());
}

View File

@ -0,0 +1,84 @@
#ifndef CSM_WOLRD_IDTREE_H
#define CSM_WOLRD_IDTREE_H
#include "idtable.hpp"
#include "universalid.hpp"
#include "columns.hpp"
/*! \brief
* Class for holding the model. Uses typical qt table abstraction/interface for granting access
* to the individiual fields of the records, Some records are holding nested data (for instance
* inventory list of the npc). In casses like this, table model offers interface to access
* nested data in the qt way - that is specify parent. Since some of those nested data require
* multiple columns to represent informations, single int (default way to index model in the
* qmodelindex) is not sufficiant. Therefore tablemodelindex class can hold two ints for the
* sake of indexing two dimensions of the table. This model does not support multiple levels of
* the nested data. Vast majority of methods makes sense only for the top level data.
*/
namespace CSMWorld
{
class NestedCollection;
struct RecordBase;
struct NestedTableWrapperBase;
class IdTree : public IdTable
{
Q_OBJECT
private:
NestedCollection *mNestedCollection;
// not implemented
IdTree (const IdTree&);
IdTree& operator= (const IdTree&);
unsigned int foldIndexAddress(const QModelIndex& index) const;
std::pair<int, int> unfoldIndexAddress(unsigned int id) const;
public:
IdTree (NestedCollection *nestedCollection, CollectionBase *idCollection, unsigned int features = 0);
///< The ownerships of \a nestedCollecton and \a idCollection are not transferred.
virtual ~IdTree();
virtual int rowCount (const QModelIndex & parent = QModelIndex()) const;
virtual int columnCount (const QModelIndex & parent = QModelIndex()) 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;
virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex());
virtual QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex())
const;
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;
void setNestedTable(const QModelIndex &index, const NestedTableWrapperBase& nestedTable);
void addNestedRow (const QModelIndex& parent, int position);
virtual bool hasChildren (const QModelIndex& index) const;
signals:
void resetStart(const QString& id);
void resetEnd(const QString& id);
};
}
#endif

View File

@ -0,0 +1,531 @@
#include "nestedcoladapterimp.hpp"
#include <components/esm/loadregn.hpp>
#include <components/esm/loadfact.hpp>
#include "idcollection.hpp"
#include "pathgrid.hpp"
#include "info.hpp"
namespace CSMWorld
{
PathgridPointListAdapter::PathgridPointListAdapter () {}
void PathgridPointListAdapter::addRow(Record<Pathgrid>& record, int position) const
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::PointList& points = pathgrid.mPoints;
// blank row
ESM::Pathgrid::Point point;
point.mX = 0;
point.mY = 0;
point.mZ = 0;
point.mAutogenerated = 0;
point.mConnectionNum = 0;
point.mUnknown = 0;
// inserting a point should trigger re-indexing of the edges
//
// FIXME: does not auto refresh edges table view
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
for (;iter != pathgrid.mEdges.end(); ++iter)
{
if ((*iter).mV0 >= position)
(*iter).mV0++;
if ((*iter).mV1 >= position)
(*iter).mV1++;
}
points.insert(points.begin()+position, point);
pathgrid.mData.mS2 += 1; // increment the number of points
record.setModified (pathgrid);
}
void PathgridPointListAdapter::removeRow(Record<Pathgrid>& record, int rowToRemove) const
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::PointList& points = pathgrid.mPoints;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (points.size()))
throw std::runtime_error ("index out of range");
// deleting a point should trigger re-indexing of the edges
// dangling edges are not allowed and hence removed
//
// FIXME: does not auto refresh edges table view
std::vector<ESM::Pathgrid::Edge>::iterator iter = pathgrid.mEdges.begin();
for (; iter != pathgrid.mEdges.end();)
{
if (((*iter).mV0 == rowToRemove) || ((*iter).mV1 == rowToRemove))
iter = pathgrid.mEdges.erase(iter);
else
{
if ((*iter).mV0 > rowToRemove)
(*iter).mV0--;
if ((*iter).mV1 > rowToRemove)
(*iter).mV1--;
++iter;
}
}
points.erase(points.begin()+rowToRemove);
pathgrid.mData.mS2 -= 1; // decrement the number of points
record.setModified (pathgrid);
}
void PathgridPointListAdapter::setTable(Record<Pathgrid>& record,
const NestedTableWrapperBase& nestedTable) const
{
Pathgrid pathgrid = record.get();
pathgrid.mPoints =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mPoints;
pathgrid.mData.mS2 =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mData.mS2;
// also update edges in case points were added/removed
pathgrid.mEdges =
static_cast<const PathgridPointsWrap &>(nestedTable).mRecord.mEdges;
record.setModified (pathgrid);
}
NestedTableWrapperBase* PathgridPointListAdapter::table(const Record<Pathgrid>& record) const
{
// deleted by dtor of NestedTableStoring
return new PathgridPointsWrap(record.get());
}
QVariant PathgridPointListAdapter::getData(const Record<Pathgrid>& record,
int subRowIndex, int subColIndex) const
{
ESM::Pathgrid::Point point = record.get().mPoints[subRowIndex];
switch (subColIndex)
{
case 0: return subRowIndex;
case 1: return point.mX;
case 2: return point.mY;
case 3: return point.mZ;
default: throw std::runtime_error("Pathgrid point subcolumn index out of range");
}
}
void PathgridPointListAdapter::setData(Record<Pathgrid>& record,
const QVariant& value, int subRowIndex, int subColIndex) const
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::Point point = pathgrid.mPoints[subRowIndex];
switch (subColIndex)
{
case 0: return; // return without saving
case 1: point.mX = value.toInt(); break;
case 2: point.mY = value.toInt(); break;
case 3: point.mZ = value.toInt(); break;
default: throw std::runtime_error("Pathgrid point subcolumn index out of range");
}
pathgrid.mPoints[subRowIndex] = point;
record.setModified (pathgrid);
}
int PathgridPointListAdapter::getColumnsCount(const Record<Pathgrid>& record) const
{
return 4;
}
int PathgridPointListAdapter::getRowsCount(const Record<Pathgrid>& record) const
{
return static_cast<int>(record.get().mPoints.size());
}
PathgridEdgeListAdapter::PathgridEdgeListAdapter () {}
// ToDo: seems to be auto-sorted in the dialog table display after insertion
void PathgridEdgeListAdapter::addRow(Record<Pathgrid>& record, int position) const
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::EdgeList& edges = pathgrid.mEdges;
// blank row
ESM::Pathgrid::Edge edge;
edge.mV0 = 0;
edge.mV1 = 0;
// NOTE: inserting a blank edge does not really make sense, perhaps this should be a
// logic_error exception
//
// Currently the code assumes that the end user to know what he/she is doing.
// e.g. Edges come in pairs, from points a->b and b->a
edges.insert(edges.begin()+position, edge);
record.setModified (pathgrid);
}
void PathgridEdgeListAdapter::removeRow(Record<Pathgrid>& record, int rowToRemove) const
{
Pathgrid pathgrid = record.get();
ESM::Pathgrid::EdgeList& edges = pathgrid.mEdges;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (edges.size()))
throw std::runtime_error ("index out of range");
edges.erase(edges.begin()+rowToRemove);
record.setModified (pathgrid);
}
void PathgridEdgeListAdapter::setTable(Record<Pathgrid>& record,
const NestedTableWrapperBase& nestedTable) const
{
Pathgrid pathgrid = record.get();
pathgrid.mEdges =
static_cast<const NestedTableWrapper<ESM::Pathgrid::EdgeList> &>(nestedTable).mNestedTable;
record.setModified (pathgrid);
}
NestedTableWrapperBase* PathgridEdgeListAdapter::table(const Record<Pathgrid>& record) const
{
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<ESM::Pathgrid::EdgeList>(record.get().mEdges);
}
QVariant PathgridEdgeListAdapter::getData(const Record<Pathgrid>& record,
int subRowIndex, int subColIndex) const
{
Pathgrid pathgrid = record.get();
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (pathgrid.mEdges.size()))
throw std::runtime_error ("index out of range");
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
switch (subColIndex)
{
case 0: return subRowIndex;
case 1: return edge.mV0;
case 2: return edge.mV1;
default: throw std::runtime_error("Pathgrid edge subcolumn index out of range");
}
}
// ToDo: detect duplicates in mEdges
void PathgridEdgeListAdapter::setData(Record<Pathgrid>& record,
const QVariant& value, int subRowIndex, int subColIndex) const
{
Pathgrid pathgrid = record.get();
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (pathgrid.mEdges.size()))
throw std::runtime_error ("index out of range");
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
switch (subColIndex)
{
case 0: return; // return without saving
case 1: edge.mV0 = value.toInt(); break;
case 2: edge.mV1 = value.toInt(); break;
default: throw std::runtime_error("Pathgrid edge subcolumn index out of range");
}
pathgrid.mEdges[subRowIndex] = edge;
record.setModified (pathgrid);
}
int PathgridEdgeListAdapter::getColumnsCount(const Record<Pathgrid>& record) const
{
return 3;
}
int PathgridEdgeListAdapter::getRowsCount(const Record<Pathgrid>& record) const
{
return static_cast<int>(record.get().mEdges.size());
}
FactionReactionsAdapter::FactionReactionsAdapter () {}
void FactionReactionsAdapter::addRow(Record<ESM::Faction>& record, int position) const
{
ESM::Faction faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
// blank row
reactions.insert(std::make_pair("", 0));
record.setModified (faction);
}
void FactionReactionsAdapter::removeRow(Record<ESM::Faction>& record, int rowToRemove) const
{
ESM::Faction faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (reactions.size()))
throw std::runtime_error ("index out of range");
// FIXME: how to ensure that the map entries correspond to table indicies?
// WARNING: Assumed that the table view has the same order as std::map
std::map<std::string, int>::iterator iter = reactions.begin();
for(int i = 0; i < rowToRemove; ++i)
iter++;
reactions.erase(iter);
record.setModified (faction);
}
void FactionReactionsAdapter::setTable(Record<ESM::Faction>& record,
const NestedTableWrapperBase& nestedTable) const
{
ESM::Faction faction = record.get();
faction.mReactions =
static_cast<const NestedTableWrapper<std::map<std::string, int> >&>(nestedTable).mNestedTable;
record.setModified (faction);
}
NestedTableWrapperBase* FactionReactionsAdapter::table(const Record<ESM::Faction>& record) const
{
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::map<std::string, int> >(record.get().mReactions);
}
QVariant FactionReactionsAdapter::getData(const Record<ESM::Faction>& record,
int subRowIndex, int subColIndex) const
{
ESM::Faction faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (reactions.size()))
throw std::runtime_error ("index out of range");
// FIXME: how to ensure that the map entries correspond to table indicies?
// WARNING: Assumed that the table view has the same order as std::map
std::map<std::string, int>::const_iterator iter = reactions.begin();
for(int i = 0; i < subRowIndex; ++i)
iter++;
switch (subColIndex)
{
case 0: return QString((*iter).first.c_str());
case 1: return (*iter).second;
default: throw std::runtime_error("Faction reactions subcolumn index out of range");
}
}
void FactionReactionsAdapter::setData(Record<ESM::Faction>& record,
const QVariant& value, int subRowIndex, int subColIndex) const
{
ESM::Faction faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (reactions.size()))
throw std::runtime_error ("index out of range");
// FIXME: how to ensure that the map entries correspond to table indicies?
// WARNING: Assumed that the table view has the same order as std::map
std::map<std::string, int>::iterator iter = reactions.begin();
for(int i = 0; i < subRowIndex; ++i)
iter++;
std::string factionId = (*iter).first;
int reaction = (*iter).second;
switch (subColIndex)
{
case 0:
{
reactions.erase(iter);
reactions.insert(std::make_pair(value.toString().toUtf8().constData(), reaction));
break;
}
case 1:
{
reactions[factionId] = value.toInt();
break;
}
default: throw std::runtime_error("Faction reactions subcolumn index out of range");
}
record.setModified (faction);
}
int FactionReactionsAdapter::getColumnsCount(const Record<ESM::Faction>& record) const
{
return 2;
}
int FactionReactionsAdapter::getRowsCount(const Record<ESM::Faction>& record) const
{
return static_cast<int>(record.get().mReactions.size());
}
RegionSoundListAdapter::RegionSoundListAdapter () {}
void RegionSoundListAdapter::addRow(Record<ESM::Region>& record, int position) const
{
ESM::Region region = record.get();
std::vector<ESM::Region::SoundRef>& soundList = region.mSoundList;
// blank row
ESM::Region::SoundRef soundRef;
soundRef.mSound.assign("");
soundRef.mChance = 0;
soundList.insert(soundList.begin()+position, soundRef);
record.setModified (region);
}
void RegionSoundListAdapter::removeRow(Record<ESM::Region>& record, int rowToRemove) const
{
ESM::Region region = record.get();
std::vector<ESM::Region::SoundRef>& soundList = region.mSoundList;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (soundList.size()))
throw std::runtime_error ("index out of range");
soundList.erase(soundList.begin()+rowToRemove);
record.setModified (region);
}
void RegionSoundListAdapter::setTable(Record<ESM::Region>& record,
const NestedTableWrapperBase& nestedTable) const
{
ESM::Region region = record.get();
region.mSoundList =
static_cast<const NestedTableWrapper<std::vector<ESM::Region::SoundRef> >&>(nestedTable).mNestedTable;
record.setModified (region);
}
NestedTableWrapperBase* RegionSoundListAdapter::table(const Record<ESM::Region>& record) const
{
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::vector<ESM::Region::SoundRef> >(record.get().mSoundList);
}
QVariant RegionSoundListAdapter::getData(const Record<ESM::Region>& record,
int subRowIndex, int subColIndex) const
{
ESM::Region region = record.get();
std::vector<ESM::Region::SoundRef>& soundList = region.mSoundList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (soundList.size()))
throw std::runtime_error ("index out of range");
ESM::Region::SoundRef soundRef = soundList[subRowIndex];
switch (subColIndex)
{
case 0: return QString(soundRef.mSound.toString().c_str());
case 1: return soundRef.mChance;
default: throw std::runtime_error("Region sounds subcolumn index out of range");
}
}
void RegionSoundListAdapter::setData(Record<ESM::Region>& record,
const QVariant& value, int subRowIndex, int subColIndex) const
{
ESM::Region region = record.get();
std::vector<ESM::Region::SoundRef>& soundList = region.mSoundList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (soundList.size()))
throw std::runtime_error ("index out of range");
ESM::Region::SoundRef soundRef = soundList[subRowIndex];
switch (subColIndex)
{
case 0: soundRef.mSound.assign(value.toString().toUtf8().constData()); break;
case 1: soundRef.mChance = static_cast<unsigned char>(value.toInt()); break;
default: throw std::runtime_error("Region sounds subcolumn index out of range");
}
region.mSoundList[subRowIndex] = soundRef;
record.setModified (region);
}
int RegionSoundListAdapter::getColumnsCount(const Record<ESM::Region>& record) const
{
return 2;
}
int RegionSoundListAdapter::getRowsCount(const Record<ESM::Region>& record) const
{
return static_cast<int>(record.get().mSoundList.size());
}
InfoListAdapter::InfoListAdapter () {}
void InfoListAdapter::addRow(Record<Info>& record, int position) const
{
throw std::logic_error ("cannot add a row to a fixed table");
}
void InfoListAdapter::removeRow(Record<Info>& record, int rowToRemove) const
{
throw std::logic_error ("cannot add a row to a fixed table");
}
void InfoListAdapter::setTable(Record<Info>& record,
const NestedTableWrapperBase& nestedTable) const
{
throw std::logic_error ("table operation not supported");
}
NestedTableWrapperBase* InfoListAdapter::table(const Record<Info>& record) const
{
throw std::logic_error ("table operation not supported");
}
QVariant InfoListAdapter::getData(const Record<Info>& record,
int subRowIndex, int subColIndex) const
{
Info info = record.get();
if (subColIndex == 0)
return QString(info.mResultScript.c_str());
else
throw std::runtime_error("Trying to access non-existing column in the nested table!");
}
void InfoListAdapter::setData(Record<Info>& record,
const QVariant& value, int subRowIndex, int subColIndex) const
{
Info info = record.get();
if (subColIndex == 0)
info.mResultScript = value.toString().toStdString();
else
throw std::runtime_error("Trying to access non-existing column in the nested table!");
record.setModified (info);
}
int InfoListAdapter::getColumnsCount(const Record<Info>& record) const
{
return 1;
}
int InfoListAdapter::getRowsCount(const Record<Info>& record) const
{
return 1; // fixed at size 1
}
}

View File

@ -0,0 +1,417 @@
#ifndef CSM_WOLRD_NESTEDCOLADAPTERIMP_H
#define CSM_WOLRD_NESTEDCOLADAPTERIMP_H
#include <QVariant>
#include <components/esm/loadpgrd.hpp>
#include <components/esm/effectlist.hpp>
#include <components/esm/loadmgef.hpp> // for converting magic effect id to string & back
#include <components/esm/loadskil.hpp> // for converting skill names
#include <components/esm/attr.hpp> // for converting attributes
#include "nestedcolumnadapter.hpp"
#include "nestedtablewrapper.hpp"
namespace ESM
{
struct Faction;
struct Region;
}
namespace CSMWorld
{
struct Pathgrid;
struct Info;
struct PathgridPointsWrap : public NestedTableWrapperBase
{
ESM::Pathgrid mRecord;
PathgridPointsWrap(ESM::Pathgrid pathgrid)
: mRecord(pathgrid) {}
virtual ~PathgridPointsWrap() {}
virtual int size() const
{
return mRecord.mPoints.size(); // used in IdTree::setNestedTable()
}
};
class PathgridPointListAdapter : public NestedColumnAdapter<Pathgrid>
{
public:
PathgridPointListAdapter ();
virtual void addRow(Record<Pathgrid>& record, int position) const;
virtual void removeRow(Record<Pathgrid>& record, int rowToRemove) const;
virtual void setTable(Record<Pathgrid>& record,
const NestedTableWrapperBase& nestedTable) const;
virtual NestedTableWrapperBase* table(const Record<Pathgrid>& record) const;
virtual QVariant getData(const Record<Pathgrid>& record,
int subRowIndex, int subColIndex) const;
virtual void setData(Record<Pathgrid>& record,
const QVariant& value, int subRowIndex, int subColIndex) const;
virtual int getColumnsCount(const Record<Pathgrid>& record) const;
virtual int getRowsCount(const Record<Pathgrid>& record) const;
};
class PathgridEdgeListAdapter : public NestedColumnAdapter<Pathgrid>
{
public:
PathgridEdgeListAdapter ();
virtual void addRow(Record<Pathgrid>& record, int position) const;
virtual void removeRow(Record<Pathgrid>& record, int rowToRemove) const;
virtual void setTable(Record<Pathgrid>& record,
const NestedTableWrapperBase& nestedTable) const;
virtual NestedTableWrapperBase* table(const Record<Pathgrid>& record) const;
virtual QVariant getData(const Record<Pathgrid>& record,
int subRowIndex, int subColIndex) const;
virtual void setData(Record<Pathgrid>& record,
const QVariant& value, int subRowIndex, int subColIndex) const;
virtual int getColumnsCount(const Record<Pathgrid>& record) const;
virtual int getRowsCount(const Record<Pathgrid>& record) const;
};
class FactionReactionsAdapter : public NestedColumnAdapter<ESM::Faction>
{
public:
FactionReactionsAdapter ();
virtual void addRow(Record<ESM::Faction>& record, int position) const;
virtual void removeRow(Record<ESM::Faction>& record, int rowToRemove) const;
virtual void setTable(Record<ESM::Faction>& record,
const NestedTableWrapperBase& nestedTable) const;
virtual NestedTableWrapperBase* table(const Record<ESM::Faction>& record) const;
virtual QVariant getData(const Record<ESM::Faction>& record,
int subRowIndex, int subColIndex) const;
virtual void setData(Record<ESM::Faction>& record,
const QVariant& value, int subRowIndex, int subColIndex) const;
virtual int getColumnsCount(const Record<ESM::Faction>& record) const;
virtual int getRowsCount(const Record<ESM::Faction>& record) const;
};
class RegionSoundListAdapter : public NestedColumnAdapter<ESM::Region>
{
public:
RegionSoundListAdapter ();
virtual void addRow(Record<ESM::Region>& record, int position) const;
virtual void removeRow(Record<ESM::Region>& record, int rowToRemove) const;
virtual void setTable(Record<ESM::Region>& record,
const NestedTableWrapperBase& nestedTable) const;
virtual NestedTableWrapperBase* table(const Record<ESM::Region>& record) const;
virtual QVariant getData(const Record<ESM::Region>& record,
int subRowIndex, int subColIndex) const;
virtual void setData(Record<ESM::Region>& record,
const QVariant& value, int subRowIndex, int subColIndex) const;
virtual int getColumnsCount(const Record<ESM::Region>& record) const;
virtual int getRowsCount(const Record<ESM::Region>& record) const;
};
template<typename ESXRecordT>
class SpellListAdapter : public NestedColumnAdapter<ESXRecordT>
{
public:
SpellListAdapter () {}
virtual void addRow(Record<ESXRecordT>& record, int position) const
{
ESXRecordT raceOrBthSgn = record.get();
std::vector<std::string>& spells = raceOrBthSgn.mPowers.mList;
// blank row
std::string spell = "";
spells.insert(spells.begin()+position, spell);
record.setModified (raceOrBthSgn);
}
virtual void removeRow(Record<ESXRecordT>& record, int rowToRemove) const
{
ESXRecordT raceOrBthSgn = record.get();
std::vector<std::string>& spells = raceOrBthSgn.mPowers.mList;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (spells.size()))
throw std::runtime_error ("index out of range");
spells.erase(spells.begin()+rowToRemove);
record.setModified (raceOrBthSgn);
}
virtual void setTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
ESXRecordT raceOrBthSgn = record.get();
raceOrBthSgn.mPowers.mList =
static_cast<const NestedTableWrapper<std::vector<std::string> >&>(nestedTable).mNestedTable;
record.setModified (raceOrBthSgn);
}
virtual NestedTableWrapperBase* table(const Record<ESXRecordT>& record) const
{
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::vector<std::string> >(record.get().mPowers.mList);
}
virtual QVariant getData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
{
ESXRecordT raceOrBthSgn = record.get();
std::vector<std::string>& spells = raceOrBthSgn.mPowers.mList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (spells.size()))
throw std::runtime_error ("index out of range");
std::string spell = spells[subRowIndex];
switch (subColIndex)
{
case 0: return QString(spell.c_str());
default: throw std::runtime_error("Spells subcolumn index out of range");
}
}
virtual void setData(Record<ESXRecordT>& record, const QVariant& value,
int subRowIndex, int subColIndex) const
{
ESXRecordT raceOrBthSgn = record.get();
std::vector<std::string>& spells = raceOrBthSgn.mPowers.mList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (spells.size()))
throw std::runtime_error ("index out of range");
std::string spell = spells[subRowIndex];
switch (subColIndex)
{
case 0: spell = value.toString().toUtf8().constData(); break;
default: throw std::runtime_error("Spells subcolumn index out of range");
}
raceOrBthSgn.mPowers.mList[subRowIndex] = spell;
record.setModified (raceOrBthSgn);
}
virtual int getColumnsCount(const Record<ESXRecordT>& record) const
{
return 1;
}
virtual int getRowsCount(const Record<ESXRecordT>& record) const
{
return static_cast<int>(record.get().mPowers.mList.size());
}
};
template<typename ESXRecordT>
class EffectsListAdapter : public NestedColumnAdapter<ESXRecordT>
{
public:
EffectsListAdapter () {}
virtual void addRow(Record<ESXRecordT>& record, int position) const
{
ESXRecordT magic = record.get();
std::vector<ESM::ENAMstruct>& effectsList = magic.mEffects.mList;
// blank row
ESM::ENAMstruct effect;
effect.mEffectID = 0;
effect.mSkill = -1;
effect.mAttribute = -1;
effect.mRange = 0;
effect.mArea = 0;
effect.mDuration = 0;
effect.mMagnMin = 0;
effect.mMagnMax = 0;
effectsList.insert(effectsList.begin()+position, effect);
record.setModified (magic);
}
virtual void removeRow(Record<ESXRecordT>& record, int rowToRemove) const
{
ESXRecordT magic = record.get();
std::vector<ESM::ENAMstruct>& effectsList = magic.mEffects.mList;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (effectsList.size()))
throw std::runtime_error ("index out of range");
effectsList.erase(effectsList.begin()+rowToRemove);
record.setModified (magic);
}
virtual void setTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
ESXRecordT magic = record.get();
magic.mEffects.mList =
static_cast<const NestedTableWrapper<std::vector<ESM::ENAMstruct> >&>(nestedTable).mNestedTable;
record.setModified (magic);
}
virtual NestedTableWrapperBase* table(const Record<ESXRecordT>& record) const
{
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::vector<ESM::ENAMstruct> >(record.get().mEffects.mList);
}
virtual QVariant getData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
{
ESXRecordT magic = record.get();
std::vector<ESM::ENAMstruct>& effectsList = magic.mEffects.mList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (effectsList.size()))
throw std::runtime_error ("index out of range");
ESM::ENAMstruct effect = effectsList[subRowIndex];
switch (subColIndex)
{
case 0:
{
if (effect.mEffectID >=0 && effect.mEffectID < ESM::MagicEffect::Length)
return effect.mRange;
else
throw std::runtime_error("Magic effects ID unexpected value");
}
case 1: return effect.mSkill;
case 2: return effect.mAttribute;
case 3:
{
if (effect.mRange >=0 && effect.mRange <=2)
return effect.mRange;
else
throw std::runtime_error("Magic effects range unexpected value");
}
case 4: return effect.mArea;
case 5: return effect.mDuration;
case 6: return effect.mMagnMin;
case 7: return effect.mMagnMax;
default: throw std::runtime_error("Magic Effects subcolumn index out of range");
}
}
virtual void setData(Record<ESXRecordT>& record, const QVariant& value,
int subRowIndex, int subColIndex) const
{
ESXRecordT magic = record.get();
std::vector<ESM::ENAMstruct>& effectsList = magic.mEffects.mList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (effectsList.size()))
throw std::runtime_error ("index out of range");
ESM::ENAMstruct effect = effectsList[subRowIndex];
switch (subColIndex)
{
case 0:
{
effect.mEffectID = static_cast<short>(value.toInt());
break;
}
case 1:
{
effect.mSkill = static_cast<signed char>(value.toInt());
break;
}
case 2:
{
effect.mAttribute = static_cast<signed char>(value.toInt());
break;
}
case 3:
{
effect.mRange = value.toInt();
break;
}
case 4: effect.mArea = value.toInt(); break;
case 5: effect.mDuration = value.toInt(); break;
case 6: effect.mMagnMin = value.toInt(); break;
case 7: effect.mMagnMax = value.toInt(); break;
default: throw std::runtime_error("Magic Effects subcolumn index out of range");
}
magic.mEffects.mList[subRowIndex] = effect;
record.setModified (magic);
}
virtual int getColumnsCount(const Record<ESXRecordT>& record) const
{
return 8;
}
virtual int getRowsCount(const Record<ESXRecordT>& record) const
{
return static_cast<int>(record.get().mEffects.mList.size());
}
};
class InfoListAdapter : public NestedColumnAdapter<Info>
{
public:
InfoListAdapter ();
virtual void addRow(Record<Info>& record, int position) const;
virtual void removeRow(Record<Info>& record, int rowToRemove) const;
virtual void setTable(Record<Info>& record,
const NestedTableWrapperBase& nestedTable) const;
virtual NestedTableWrapperBase* table(const Record<Info>& record) const;
virtual QVariant getData(const Record<Info>& record,
int subRowIndex, int subColIndex) const;
virtual void setData(Record<Info>& record,
const QVariant& value, int subRowIndex, int subColIndex) const;
virtual int getColumnsCount(const Record<Info>& record) const;
virtual int getRowsCount(const Record<Info>& record) const;
};
}
#endif // CSM_WOLRD_NESTEDCOLADAPTERIMP_H

View File

@ -0,0 +1,17 @@
#include "nestedcollection.hpp"
CSMWorld::NestedCollection::NestedCollection()
{}
CSMWorld::NestedCollection::~NestedCollection()
{}
int CSMWorld::NestedCollection::getNestedRowsCount(int row, int column) const
{
return 0;
}
int CSMWorld::NestedCollection::getNestedColumnsCount(int row, int column) const
{
return 0;
}

View File

@ -0,0 +1,39 @@
#ifndef CSM_WOLRD_NESTEDCOLLECTION_H
#define CSM_WOLRD_NESTEDCOLLECTION_H
class QVariant;
namespace CSMWorld
{
class NestableColumn;
struct NestedTableWrapperBase;
class NestedCollection
{
public:
NestedCollection();
virtual ~NestedCollection();
virtual void addNestedRow(int row, int col, int position) = 0;
virtual void removeNestedRows(int row, int column, int subRow) = 0;
virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const = 0;
virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) = 0;
virtual NestedTableWrapperBase* nestedTable(int row, int column) const = 0;
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable) = 0;
virtual int getNestedRowsCount(int row, int column) const;
virtual int getNestedColumnsCount(int row, int column) const;
virtual NestableColumn *getNestableColumn(int column) = 0;
};
}
#endif // CSM_WOLRD_NESTEDCOLLECTION_H

View File

@ -0,0 +1,40 @@
#ifndef CSM_WOLRD_NESTEDCOLUMNADAPTER_H
#define CSM_WOLRD_NESTEDCOLUMNADAPTER_H
class QVariant;
namespace CSMWorld
{
struct NestedTableWrapperBase;
template <typename ESXRecordT>
struct Record;
template<typename ESXRecordT>
class NestedColumnAdapter
{
public:
NestedColumnAdapter() {}
virtual ~NestedColumnAdapter() {}
virtual void addRow(Record<ESXRecordT>& record, int position) const = 0;
virtual void removeRow(Record<ESXRecordT>& record, int rowToRemove) const = 0;
virtual void setTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const = 0;
virtual NestedTableWrapperBase* table(const Record<ESXRecordT>& record) const = 0;
virtual QVariant getData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const = 0;
virtual void setData(Record<ESXRecordT>& record, const QVariant& value, int subRowIndex, int subColIndex) const = 0;
virtual int getColumnsCount(const Record<ESXRecordT>& record) const = 0;
virtual int getRowsCount(const Record<ESXRecordT>& record) const = 0;
};
}
#endif // CSM_WOLRD_NESTEDCOLUMNADAPTER_H

View File

@ -0,0 +1,175 @@
#ifndef CSM_WOLRD_NESTEDIDCOLLECTION_H
#define CSM_WOLRD_NESTEDIDCOLLECTION_H
#include <map>
#include <stdexcept>
#include "nestedcollection.hpp"
#include "nestedcoladapterimp.hpp"
namespace ESM
{
class ESMReader;
}
namespace CSMWorld
{
struct NestedTableWrapperBase;
struct Cell;
template<typename T, typename AT>
class IdCollection;
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class NestedIdCollection : public IdCollection<ESXRecordT, IdAccessorT>, public NestedCollection
{
std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>* > mAdapters;
const NestedColumnAdapter<ESXRecordT>& getAdapter(const ColumnBase &column) const;
public:
NestedIdCollection ();
~NestedIdCollection();
virtual void addNestedRow(int row, int column, int position);
virtual void removeNestedRows(int row, int column, int subRow);
virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const;
virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn);
virtual NestedTableWrapperBase* nestedTable(int row, int column) const;
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable);
virtual int getNestedRowsCount(int row, int column) const;
virtual int getNestedColumnsCount(int row, int column) const;
// this method is inherited from NestedCollection, not from Collection<ESXRecordT>
virtual NestableColumn *getNestableColumn(int column);
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<ESXRecordT>* > adapter);
};
template<typename ESXRecordT, typename IdAccessorT>
NestedIdCollection<ESXRecordT, IdAccessorT>::NestedIdCollection ()
{}
template<typename ESXRecordT, typename IdAccessorT>
NestedIdCollection<ESXRecordT, IdAccessorT>::~NestedIdCollection()
{
for (typename std::map<const ColumnBase *, NestedColumnAdapter<ESXRecordT>* >::iterator
iter (mAdapters.begin()); iter!=mAdapters.end(); ++iter)
{
delete (*iter).second;
}
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::addAdapter(std::pair<const ColumnBase*,
NestedColumnAdapter<ESXRecordT>* > adapter)
{
mAdapters.insert(adapter);
}
template<typename ESXRecordT, typename IdAccessorT>
const NestedColumnAdapter<ESXRecordT>& NestedIdCollection<ESXRecordT, IdAccessorT>::getAdapter(const ColumnBase &column) const
{
typename std::map<const ColumnBase *, NestedColumnAdapter<ESXRecordT>* >::const_iterator iter =
mAdapters.find (&column);
if (iter==mAdapters.end())
throw std::logic_error("No such column in the nestedidadapter");
return *iter->second;
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::addNestedRow(int row, int column, int position)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).addRow(record, position);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::removeNestedRows(int row, int column, int subRow)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).removeRow(record, subRow);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
QVariant NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedData (int row,
int column, int subRow, int subColumn) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getData(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), subRow, subColumn);
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedData(int row,
int column, const QVariant& data, int subRow, int subColumn)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setData(
record, data, subRow, subColumn);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestedTableWrapperBase* NestedIdCollection<ESXRecordT, IdAccessorT>::nestedTable(int row,
int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).table(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedTable(int row,
int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setTable(
record, nestedTable);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedRowsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getRowsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedColumnsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getColumnsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestableColumn *NestedIdCollection<ESXRecordT, IdAccessorT>::getNestableColumn(int column)
{
return Collection<ESXRecordT, IdAccessorT>::getNestableColumn(column);
}
}
#endif // CSM_WOLRD_NESTEDIDCOLLECTION_H

View File

@ -0,0 +1,110 @@
#include "nestedinfocollection.hpp"
#include "nestedcoladapterimp.hpp"
namespace CSMWorld
{
NestedInfoCollection::NestedInfoCollection ()
{}
NestedInfoCollection::~NestedInfoCollection()
{
for (std::map<const ColumnBase *, NestedColumnAdapter<Info>* >::iterator
iter (mAdapters.begin()); iter!=mAdapters.end(); ++iter)
{
delete (*iter).second;
}
}
void NestedInfoCollection::addAdapter(std::pair<const ColumnBase*,
NestedColumnAdapter<Info>* > adapter)
{
mAdapters.insert(adapter);
}
const NestedColumnAdapter<Info>& NestedInfoCollection::getAdapter(const ColumnBase &column) const
{
std::map<const ColumnBase *, NestedColumnAdapter<Info>* >::const_iterator iter =
mAdapters.find (&column);
if (iter==mAdapters.end())
throw std::logic_error("No such column in the nestedidadapter");
return *iter->second;
}
void NestedInfoCollection::addNestedRow(int row, int column, int position)
{
Record<Info> record;
record.assign(Collection<Info, IdAccessor<Info> >::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).addRow(record, position);
Collection<Info, IdAccessor<Info> >::setRecord(row, record);
}
void NestedInfoCollection::removeNestedRows(int row, int column, int subRow)
{
Record<Info> record;
record.assign(Collection<Info, IdAccessor<Info> >::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).removeRow(record, subRow);
Collection<Info, IdAccessor<Info> >::setRecord(row, record);
}
QVariant NestedInfoCollection::getNestedData (int row,
int column, int subRow, int subColumn) const
{
return getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).getData(
Collection<Info, IdAccessor<Info> >::getRecord(row), subRow, subColumn);
}
void NestedInfoCollection::setNestedData(int row,
int column, const QVariant& data, int subRow, int subColumn)
{
Record<Info> record;
record.assign(Collection<Info, IdAccessor<Info> >::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).setData(
record, data, subRow, subColumn);
Collection<Info, IdAccessor<Info> >::setRecord(row, record);
}
CSMWorld::NestedTableWrapperBase* NestedInfoCollection::nestedTable(int row,
int column) const
{
return getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).table(
Collection<Info, IdAccessor<Info> >::getRecord(row));
}
void NestedInfoCollection::setNestedTable(int row,
int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
Record<Info> record;
record.assign(Collection<Info, IdAccessor<Info> >::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).setTable(
record, nestedTable);
Collection<Info, IdAccessor<Info> >::setRecord(row, record);
}
int NestedInfoCollection::getNestedRowsCount(int row, int column) const
{
return getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).getRowsCount(
Collection<Info, IdAccessor<Info> >::getRecord(row));
}
int NestedInfoCollection::getNestedColumnsCount(int row, int column) const
{
return getAdapter(Collection<Info, IdAccessor<Info> >::getColumn(column)).getColumnsCount(
Collection<Info, IdAccessor<Info> >::getRecord(row));
}
CSMWorld::NestableColumn *NestedInfoCollection::getNestableColumn(int column)
{
return Collection<Info, IdAccessor<Info> >::getNestableColumn(column);
}
}

View File

@ -0,0 +1,50 @@
#ifndef CSM_WOLRD_NESTEDINFOCOLLECTION_H
#define CSM_WOLRD_NESTEDINFOCOLLECTION_H
#include <map>
#include "infocollection.hpp"
#include "nestedcollection.hpp"
namespace CSMWorld
{
struct NestedTableWrapperBase;
template<typename ESXRecordT>
class NestedColumnAdapter;
class NestedInfoCollection : public InfoCollection, public NestedCollection
{
std::map<const ColumnBase*, NestedColumnAdapter<Info>* > mAdapters;
const NestedColumnAdapter<Info>& getAdapter(const ColumnBase &column) const;
public:
NestedInfoCollection ();
~NestedInfoCollection();
virtual void addNestedRow(int row, int column, int position);
virtual void removeNestedRows(int row, int column, int subRow);
virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const;
virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn);
virtual NestedTableWrapperBase* nestedTable(int row, int column) const;
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable);
virtual int getNestedRowsCount(int row, int column) const;
virtual int getNestedColumnsCount(int row, int column) const;
// this method is inherited from NestedCollection, not from Collection<Info, IdAccessor<Info> >
virtual NestableColumn *getNestableColumn(int column);
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<Info>* > adapter);
};
}
#endif // CSM_WOLRD_NESTEDINFOCOLLECTION_H

View File

@ -0,0 +1,195 @@
#include "nestedtableproxymodel.hpp"
#include <cassert>
#include "idtree.hpp"
CSMWorld::NestedTableProxyModel::NestedTableProxyModel(const QModelIndex& parent,
ColumnBase::Display columnId,
CSMWorld::IdTree* parentModel)
: mParentColumn(parent.column()),
mMainModel(parentModel)
{
const int parentRow = parent.row();
mId = std::string(parentModel->index(parentRow, 0).data().toString().toUtf8());
QAbstractProxyModel::setSourceModel(parentModel);
connect(mMainModel, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
this, SLOT(forwardRowsAboutToInserted(const QModelIndex &, int, int)));
connect(mMainModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
this, SLOT(forwardRowsInserted(const QModelIndex &, int, int)));
connect(mMainModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
this, SLOT(forwardRowsAboutToRemoved(const QModelIndex &, int, int)));
connect(mMainModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
this, SLOT(forwardRowsRemoved(const QModelIndex &, int, int)));
connect(mMainModel, SIGNAL(resetStart(const QString&)),
this, SLOT(forwardResetStart(const QString&)));
connect(mMainModel, SIGNAL(resetEnd(const QString&)),
this, SLOT(forwardResetEnd(const QString&)));
connect(mMainModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
this, SLOT(forwardDataChanged(const QModelIndex &, const QModelIndex &)));
}
QModelIndex CSMWorld::NestedTableProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
{
const QModelIndex& testedParent = mMainModel->parent(sourceIndex);
const QModelIndex& parent = mMainModel->getNestedModelIndex (mId, mParentColumn);
if (testedParent == parent)
{
return createIndex(sourceIndex.row(), sourceIndex.column());
}
else
{
return QModelIndex();
}
}
QModelIndex CSMWorld::NestedTableProxyModel::mapToSource(const QModelIndex& proxyIndex) const
{
const QModelIndex& parent = mMainModel->getNestedModelIndex (mId, mParentColumn);
return mMainModel->index(proxyIndex.row(), proxyIndex.column(), parent);
}
int CSMWorld::NestedTableProxyModel::rowCount(const QModelIndex& index) const
{
assert (!index.isValid());
return mMainModel->rowCount(mMainModel->getModelIndex(mId, mParentColumn));
}
int CSMWorld::NestedTableProxyModel::columnCount(const QModelIndex& parent) const
{
assert (!parent.isValid());
return mMainModel->columnCount(mMainModel->getModelIndex(mId, mParentColumn));
}
QModelIndex CSMWorld::NestedTableProxyModel::index(int row, int column, const QModelIndex& parent) const
{
assert (!parent.isValid());
int rows = mMainModel->rowCount(parent);
int columns = mMainModel->columnCount(parent);
if (row < 0 || row >= rows || column < 0 || column >= columns)
return QModelIndex();
return createIndex(row, column);
}
QModelIndex CSMWorld::NestedTableProxyModel::parent(const QModelIndex& index) const
{
return QModelIndex();
}
QVariant CSMWorld::NestedTableProxyModel::headerData(int section,
Qt::Orientation orientation,
int role) const
{
return mMainModel->nestedHeaderData(mParentColumn, section, orientation, role);
}
QVariant CSMWorld::NestedTableProxyModel::data(const QModelIndex& index, int role) const
{
return mMainModel->data(mapToSource(index), role);
}
// NOTE: Due to mapToSouce(index) the dataChanged() signal resulting from setData() will have the
// source model's index values. The indicies need to be converted to the proxy space values.
// See forwardDataChanged()
bool CSMWorld::NestedTableProxyModel::setData (const QModelIndex & index, const QVariant & value, int role)
{
return mMainModel->setData(mapToSource(index), value, role);
}
Qt::ItemFlags CSMWorld::NestedTableProxyModel::flags(const QModelIndex& index) const
{
return mMainModel->flags(mapToSource(index));
}
std::string CSMWorld::NestedTableProxyModel::getParentId() const
{
return mId;
}
int CSMWorld::NestedTableProxyModel::getParentColumn() const
{
return mParentColumn;
}
CSMWorld::IdTree* CSMWorld::NestedTableProxyModel::model() const
{
return mMainModel;
}
void CSMWorld::NestedTableProxyModel::forwardRowsAboutToInserted(const QModelIndex& parent,
int first, int last)
{
if (indexIsParent(parent))
{
beginInsertRows(QModelIndex(), first, last);
}
}
void CSMWorld::NestedTableProxyModel::forwardRowsInserted(const QModelIndex& parent, int first, int last)
{
if (indexIsParent(parent))
{
endInsertRows();
}
}
bool CSMWorld::NestedTableProxyModel::indexIsParent(const QModelIndex& index)
{
return (index.isValid() &&
index.column() == mParentColumn &&
mMainModel->data(mMainModel->index(index.row(), 0)).toString().toUtf8().constData() == mId);
}
void CSMWorld::NestedTableProxyModel::forwardRowsAboutToRemoved(const QModelIndex& parent,
int first, int last)
{
if (indexIsParent(parent))
{
beginRemoveRows(QModelIndex(), first, last);
}
}
void CSMWorld::NestedTableProxyModel::forwardRowsRemoved(const QModelIndex& parent, int first, int last)
{
if (indexIsParent(parent))
{
endRemoveRows();
}
}
void CSMWorld::NestedTableProxyModel::forwardResetStart(const QString& id)
{
if (id.toUtf8() == mId.c_str())
beginResetModel();
}
void CSMWorld::NestedTableProxyModel::forwardResetEnd(const QString& id)
{
if (id.toUtf8() == mId.c_str())
endResetModel();
}
void CSMWorld::NestedTableProxyModel::forwardDataChanged (const QModelIndex& topLeft,
const QModelIndex& bottomRight)
{
const QModelIndex& parent = mMainModel->getNestedModelIndex (mId, mParentColumn);
if (topLeft.column() <= parent.column() && bottomRight.column() >= parent.column())
{
emit dataChanged(index(0,0),
index(mMainModel->rowCount(parent)-1, mMainModel->columnCount(parent)-1));
}
}

View File

@ -0,0 +1,84 @@
#ifndef CSM_WOLRD_NESTEDTABLEPROXYMODEL_H
#define CSM_WOLRD_NESTEDTABLEPROXYMODEL_H
#include <vector>
#include <QAbstractProxyModel>
#include "universalid.hpp"
#include "columns.hpp"
#include "columnbase.hpp"
/*! \brief
* Proxy model used to connect view in the dialogue into the nested columns of the main model.
*/
namespace CSMWorld
{
class CollectionBase;
struct RecordBase;
class IdTree;
class NestedTableProxyModel : public QAbstractProxyModel
{
Q_OBJECT
const int mParentColumn;
IdTree* mMainModel;
std::string mId;
public:
NestedTableProxyModel(const QModelIndex& parent,
ColumnBase::Display displayType,
IdTree* parentModel);
//parent is the parent of columns to work with. Columnid provides information about the column
std::string getParentId() const;
int getParentColumn() const;
CSMWorld::IdTree* model() const;
virtual QModelIndex mapFromSource(const QModelIndex& sourceIndex) const;
virtual QModelIndex mapToSource(const QModelIndex& proxyIndex) const;
virtual int rowCount(const QModelIndex& parent) const;
virtual int columnCount(const QModelIndex& parent) const;
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
virtual QModelIndex parent(const QModelIndex& index) const;
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;
private:
void setupHeaderVectors(ColumnBase::Display columnId);
bool indexIsParent(const QModelIndex& index);
private slots:
void forwardRowsAboutToInserted(const QModelIndex & parent, int first, int last);
void forwardRowsInserted(const QModelIndex & parent, int first, int last);
void forwardRowsAboutToRemoved(const QModelIndex & parent, int first, int last);
void forwardRowsRemoved(const QModelIndex & parent, int first, int last);
void forwardResetStart(const QString& id);
void forwardResetEnd(const QString& id);
void forwardDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
};
}
#endif

View File

@ -0,0 +1,12 @@
#include "nestedtablewrapper.hpp"
CSMWorld::NestedTableWrapperBase::NestedTableWrapperBase()
{}
CSMWorld::NestedTableWrapperBase::~NestedTableWrapperBase()
{}
int CSMWorld::NestedTableWrapperBase::size() const
{
return -5;
}

View File

@ -0,0 +1,31 @@
#ifndef CSM_WOLRD_NESTEDTABLEWRAPPER_H
#define CSM_WOLRD_NESTEDTABLEWRAPPER_H
namespace CSMWorld
{
struct NestedTableWrapperBase
{
virtual ~NestedTableWrapperBase();
virtual int size() const;
NestedTableWrapperBase();
};
template<typename NestedTable>
struct NestedTableWrapper : public NestedTableWrapperBase
{
NestedTable mNestedTable;
NestedTableWrapper(const NestedTable& nestedTable)
: mNestedTable(nestedTable) {}
virtual ~NestedTableWrapper() {}
virtual int size() const
{
return mNestedTable.size(); //i hope that this will be enough
}
};
}
#endif

View File

@ -1,6 +1,9 @@
#include "refidadapter.hpp"
CSMWorld::RefIdAdapter::RefIdAdapter() {}
CSMWorld::RefIdAdapter::~RefIdAdapter() {}
CSMWorld::NestedRefIdAdapterBase::NestedRefIdAdapterBase() {}
CSMWorld::NestedRefIdAdapterBase::~NestedRefIdAdapterBase() {}

View File

@ -2,6 +2,14 @@
#define CSM_WOLRD_REFIDADAPTER_H
#include <string>
#include <vector>
/*! \brief
* Adapters acts as indirection layer, abstracting details of the record types (in the wrappers) from the higher levels of model.
* Please notice that nested adaptor uses helper classes for actually performing any actions. Different record types require different helpers (needs to be created in the subclass and then fetched via member function).
*
* Important point: don't forget to make sure that getData on the nestedColumn returns true (otherwise code will not treat the index pointing to the column as having childs!
*/
class QVariant;
@ -10,6 +18,8 @@ namespace CSMWorld
class RefIdColumn;
class RefIdData;
struct RecordBase;
struct NestedTableWrapperBase;
class HelperBase;
class RefIdAdapter
{
@ -25,13 +35,45 @@ namespace CSMWorld
virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int idnex)
const = 0;
///< If called on the nest column, should return QVariant(true).
virtual void setData (const RefIdColumn *column, RefIdData& data, int index,
const QVariant& value) const = 0;
///< If the data type does not match an exception is thrown.
virtual std::string getId (const RecordBase& record) const = 0;
virtual void setId(RecordBase& record, const std::string& id) = 0;
virtual void setId(RecordBase& record, const std::string& id) = 0; // used by RefIdCollection::cloneRecord()
};
class NestedRefIdAdapterBase
{
public:
NestedRefIdAdapterBase();
virtual ~NestedRefIdAdapterBase();
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 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 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 NestedTableWrapperBase* nestedTable (const RefIdColumn* column,
const RefIdData& data, int index) const = 0;
};
}

View File

@ -1,10 +1,19 @@
#include "refidadapterimp.hpp"
CSMWorld::PotionRefIdAdapter::PotionRefIdAdapter (const InventoryColumns& columns,
#include <cassert>
#include <stdexcept>
#include <utility>
#include <components/esm/loadcont.hpp>
#include "nestedtablewrapper.hpp"
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,
@ -16,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; // to show nested tables in dialogue subview, see IdTree::hasChildren()
return InventoryRefIdAdapter<ESM::Potion>::getData (column, data, index);
}
@ -69,9 +81,10 @@ void CSMWorld::ApparatusRefIdAdapter::setData (const RefIdColumn *column, RefIdD
CSMWorld::ArmorRefIdAdapter::ArmorRefIdAdapter (const EnchantableColumns& columns,
const RefIdColumn *type, const RefIdColumn *health, const RefIdColumn *armor)
const RefIdColumn *type, const RefIdColumn *health, const RefIdColumn *armor,
const RefIdColumn *partRef)
: EnchantableRefIdAdapter<ESM::Armor> (UniversalId::Type_Armor, columns),
mType (type), mHealth (health), mArmor (armor)
mType (type), mHealth (health), mArmor (armor), mPartRef(partRef)
{}
QVariant CSMWorld::ArmorRefIdAdapter::getData (const RefIdColumn *column,
@ -89,6 +102,9 @@ QVariant CSMWorld::ArmorRefIdAdapter::getData (const RefIdColumn *column,
if (column==mArmor)
return record.get().mData.mArmor;
if (column==mPartRef)
return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
return EnchantableRefIdAdapter<ESM::Armor>::getData (column, data, index);
}
@ -144,8 +160,9 @@ void CSMWorld::BookRefIdAdapter::setData (const RefIdColumn *column, RefIdData&
}
CSMWorld::ClothingRefIdAdapter::ClothingRefIdAdapter (const EnchantableColumns& columns,
const RefIdColumn *type)
: EnchantableRefIdAdapter<ESM::Clothing> (UniversalId::Type_Clothing, columns), mType (type)
const RefIdColumn *type, const RefIdColumn *partRef)
: EnchantableRefIdAdapter<ESM::Clothing> (UniversalId::Type_Clothing, columns), mType (type),
mPartRef(partRef)
{}
QVariant CSMWorld::ClothingRefIdAdapter::getData (const RefIdColumn *column,
@ -157,6 +174,9 @@ QVariant CSMWorld::ClothingRefIdAdapter::getData (const RefIdColumn *column,
if (column==mType)
return record.get().mData.mType;
if (column==mPartRef)
return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
return EnchantableRefIdAdapter<ESM::Clothing>::getData (column, data, index);
}
@ -173,13 +193,14 @@ void CSMWorld::ClothingRefIdAdapter::setData (const RefIdColumn *column, RefIdDa
}
CSMWorld::ContainerRefIdAdapter::ContainerRefIdAdapter (const NameColumns& columns,
const RefIdColumn *weight, const RefIdColumn *organic, const RefIdColumn *respawn)
const RefIdColumn *weight, const RefIdColumn *organic, const RefIdColumn *respawn, const RefIdColumn *content)
: NameRefIdAdapter<ESM::Container> (UniversalId::Type_Container, columns), mWeight (weight),
mOrganic (organic), mRespawn (respawn)
mOrganic (organic), mRespawn (respawn), mContent(content)
{}
QVariant CSMWorld::ContainerRefIdAdapter::getData (const RefIdColumn *column, const RefIdData& data,
int index) const
QVariant CSMWorld::ContainerRefIdAdapter::getData (const RefIdColumn *column,
const RefIdData& data,
int index) const
{
const Record<ESM::Container>& record = static_cast<const Record<ESM::Container>&> (
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Container)));
@ -193,6 +214,9 @@ QVariant CSMWorld::ContainerRefIdAdapter::getData (const RefIdColumn *column, co
if (column==mRespawn)
return (record.get().mFlags & ESM::Container::Respawn)!=0;
if (column==mContent)
return true; // Required to show nested tables in dialogue subview
return NameRefIdAdapter<ESM::Container>::getData (column, data, index);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
#include "refidcollection.hpp"
#include <stdexcept>
@ -9,10 +8,12 @@
#include "refidadapter.hpp"
#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)
: ColumnBase (columnId, displayType, flag), mEditable (editable), mUserEditable (userEditable)
: NestableColumn (columnId, displayType, flag), mEditable (editable), mUserEditable (userEditable)
{}
bool CSMWorld::RefIdColumn::isEditable() const
@ -25,8 +26,7 @@ bool CSMWorld::RefIdColumn::isUserEditable() const
return mUserEditable;
}
const CSMWorld::RefIdAdapter& CSMWorld::RefIdCollection::findAdaptor (UniversalId::Type type) const
const CSMWorld::RefIdAdapter& CSMWorld::RefIdCollection::findAdapter (UniversalId::Type type) const
{
std::map<UniversalId::Type, RefIdAdapter *>::const_iterator iter = mAdapters.find (type);
@ -71,6 +71,32 @@ 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
std::map<UniversalId::Type, NestedRefIdAdapterBase*> effectsMap;
effectsMap.insert(std::make_pair(UniversalId::Type_Potion,
new EffectsRefIdAdapter<ESM::Potion> (UniversalId::Type_Potion)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), effectsMap));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_EffectId, ColumnBase::Display_EffectId));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_SkillImpact, ColumnBase::Display_SkillImpact));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_Attribute, ColumnBase::Display_Attribute));
mColumns.back().addColumn(
new NestedChildColumn (Columns::ColumnId_EffectRange, ColumnBase::Display_EffectRange));
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));
@ -98,6 +124,94 @@ CSMWorld::RefIdCollection::RefIdCollection()
mColumns.push_back (RefIdColumn (Columns::ColumnId_AiAlarm, ColumnBase::Display_Integer));
actorsColumns.mAlarm = &mColumns.back();
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_ActorInventory,
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
actorsColumns.mInventory = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> inventoryMap;
inventoryMap.insert(std::make_pair(UniversalId::Type_Npc,
new NestedInventoryRefIdAdapter<ESM::NPC> (UniversalId::Type_Npc)));
inventoryMap.insert(std::make_pair(UniversalId::Type_Creature,
new NestedInventoryRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), inventoryMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_InventoryItemId, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_ItemCount, CSMWorld::ColumnBase::Display_Integer));
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_SpellList,
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
actorsColumns.mSpells = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> spellsMap;
spellsMap.insert(std::make_pair(UniversalId::Type_Npc,
new NestedSpellRefIdAdapter<ESM::NPC> (UniversalId::Type_Npc)));
spellsMap.insert(std::make_pair(UniversalId::Type_Creature,
new NestedSpellRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), spellsMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_SpellId, CSMWorld::ColumnBase::Display_String));
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_NpcDestinations,
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
actorsColumns.mDestinations = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> destMap;
destMap.insert(std::make_pair(UniversalId::Type_Npc,
new NestedTravelRefIdAdapter<ESM::NPC> (UniversalId::Type_Npc)));
destMap.insert(std::make_pair(UniversalId::Type_Creature,
new NestedTravelRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), destMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_DestinationCell, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PosX, CSMWorld::ColumnBase::Display_Float));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PosY, CSMWorld::ColumnBase::Display_Float));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PosZ, CSMWorld::ColumnBase::Display_Float));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_RotX, CSMWorld::ColumnBase::Display_Float));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_RotY, CSMWorld::ColumnBase::Display_Float));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_RotZ, CSMWorld::ColumnBase::Display_Float));
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_AiPackageList,
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
actorsColumns.mAiPackages = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> aiMap;
aiMap.insert(std::make_pair(UniversalId::Type_Npc,
new ActorAiRefIdAdapter<ESM::NPC> (UniversalId::Type_Npc)));
aiMap.insert(std::make_pair(UniversalId::Type_Creature,
new ActorAiRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), aiMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiPackageType, CSMWorld::ColumnBase::Display_AiPackageType));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiWanderDist, CSMWorld::ColumnBase::Display_Integer));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiDuration, CSMWorld::ColumnBase::Display_Integer));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiWanderToD, CSMWorld::ColumnBase::Display_Integer));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiWanderIdle, CSMWorld::ColumnBase::Display_Integer));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiWanderRepeat, CSMWorld::ColumnBase::Display_YesNo));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiActivateName, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiTargetId, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_AiTargetCell, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PosX, CSMWorld::ColumnBase::Display_Float));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PosY, CSMWorld::ColumnBase::Display_Float));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PosZ, CSMWorld::ColumnBase::Display_Float));
static const struct
{
int mName;
@ -165,6 +279,19 @@ CSMWorld::RefIdCollection::RefIdCollection()
mColumns.push_back (RefIdColumn (Columns::ColumnId_Respawn, ColumnBase::Display_Boolean));
const RefIdColumn *respawn = &mColumns.back();
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_ContainerContent,
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
const RefIdColumn *content = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> contMap;
contMap.insert(std::make_pair(UniversalId::Type_Container,
new NestedInventoryRefIdAdapter<ESM::Container> (UniversalId::Type_Container)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), contMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_InventoryItemId, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_ItemCount, CSMWorld::ColumnBase::Display_Integer));
CreatureColumns creatureColumns (actorsColumns);
mColumns.push_back (RefIdColumn (Columns::ColumnId_CreatureType, ColumnBase::Display_CreatureType));
@ -343,20 +470,68 @@ CSMWorld::RefIdCollection::RefIdCollection()
weaponColumns.mFlags.insert (std::make_pair (&mColumns.back(), sWeaponFlagTable[i].mFlag));
}
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_PartRefList, ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
const RefIdColumn *partRef = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> partMap;
partMap.insert(std::make_pair(UniversalId::Type_Armor,
new BodyPartRefIdAdapter<ESM::Armor> (UniversalId::Type_Armor)));
partMap.insert(std::make_pair(UniversalId::Type_Clothing,
new BodyPartRefIdAdapter<ESM::Clothing> (UniversalId::Type_Clothing)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), partMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PartRefType, CSMWorld::ColumnBase::Display_PartRefType));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PartRefMale, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_PartRefFemale, CSMWorld::ColumnBase::Display_String));
LevListColumns levListColumns (baseColumns);
// Nested table
mColumns.push_back(RefIdColumn (Columns::ColumnId_LevelledList,
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
levListColumns.mLevList = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> levListMap;
levListMap.insert(std::make_pair(UniversalId::Type_CreatureLevelledList,
new NestedLevListRefIdAdapter<ESM::CreatureLevList> (UniversalId::Type_CreatureLevelledList)));
levListMap.insert(std::make_pair(UniversalId::Type_ItemLevelledList,
new NestedLevListRefIdAdapter<ESM::ItemLevList> (UniversalId::Type_ItemLevelledList)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), levListMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_LevelledItemId, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_LevelledItemLevel, CSMWorld::ColumnBase::Display_Integer));
// Nested list
mColumns.push_back(RefIdColumn (Columns::ColumnId_LevelledList,
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue | ColumnBase::Flag_Dialogue_List));
levListColumns.mNestedListLevList = &mColumns.back();
std::map<UniversalId::Type, NestedRefIdAdapterBase*> nestedListLevListMap;
nestedListLevListMap.insert(std::make_pair(UniversalId::Type_CreatureLevelledList,
new NestedListLevListRefIdAdapter<ESM::CreatureLevList> (UniversalId::Type_CreatureLevelledList)));
nestedListLevListMap.insert(std::make_pair(UniversalId::Type_ItemLevelledList,
new NestedListLevListRefIdAdapter<ESM::ItemLevList> (UniversalId::Type_ItemLevelledList)));
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), nestedListLevListMap));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_LevelledItemType, CSMWorld::ColumnBase::Display_String));
mColumns.back().addColumn(
new RefIdColumn (Columns::ColumnId_LevelledItemChanceNone, CSMWorld::ColumnBase::Display_Integer));
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,
new ArmorRefIdAdapter (enchantableColumns, armorType, health, armor)));
new ArmorRefIdAdapter (enchantableColumns, armorType, health, armor, partRef)));
mAdapters.insert (std::make_pair (UniversalId::Type_Book,
new BookRefIdAdapter (enchantableColumns, scroll, attribute)));
mAdapters.insert (std::make_pair (UniversalId::Type_Clothing,
new ClothingRefIdAdapter (enchantableColumns, clothingType)));
new ClothingRefIdAdapter (enchantableColumns, clothingType, partRef)));
mAdapters.insert (std::make_pair (UniversalId::Type_Container,
new ContainerRefIdAdapter (nameColumns, weightCapacity, organic, respawn)));
new ContainerRefIdAdapter (nameColumns, weightCapacity, organic, respawn, content)));
mAdapters.insert (std::make_pair (UniversalId::Type_Creature,
new CreatureRefIdAdapter (creatureColumns)));
mAdapters.insert (std::make_pair (UniversalId::Type_Door,
@ -364,10 +539,10 @@ CSMWorld::RefIdCollection::RefIdCollection()
mAdapters.insert (std::make_pair (UniversalId::Type_Ingredient,
new InventoryRefIdAdapter<ESM::Ingredient> (UniversalId::Type_Ingredient, inventoryColumns)));
mAdapters.insert (std::make_pair (UniversalId::Type_CreatureLevelledList,
new BaseRefIdAdapter<ESM::CreatureLevList> (
UniversalId::Type_CreatureLevelledList, baseColumns)));
new LevelledListRefIdAdapter<ESM::CreatureLevList> (
UniversalId::Type_CreatureLevelledList, levListColumns)));
mAdapters.insert (std::make_pair (UniversalId::Type_ItemLevelledList,
new BaseRefIdAdapter<ESM::ItemLevList> (UniversalId::Type_ItemLevelledList, baseColumns)));
new LevelledListRefIdAdapter<ESM::ItemLevList> (UniversalId::Type_ItemLevelledList, levListColumns)));
mAdapters.insert (std::make_pair (UniversalId::Type_Light,
new LightRefIdAdapter (lightColumns)));
mAdapters.insert (std::make_pair (UniversalId::Type_Lockpick,
@ -391,6 +566,14 @@ CSMWorld::RefIdCollection::~RefIdCollection()
for (std::map<UniversalId::Type, RefIdAdapter *>::iterator iter (mAdapters.begin());
iter!=mAdapters.end(); ++iter)
delete iter->second;
for (std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*> > >::iterator iter (mNestedAdapters.begin());
iter!=mNestedAdapters.end(); ++iter)
{
for (std::map<UniversalId::Type, NestedRefIdAdapterBase *>::iterator it ((iter->second).begin());
it!=(iter->second).end(); ++it)
delete it->second;
}
}
int CSMWorld::RefIdCollection::getSize() const
@ -427,25 +610,51 @@ QVariant CSMWorld::RefIdCollection::getData (int index, int column) const
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index);
const RefIdAdapter& adaptor = findAdaptor (localIndex.second);
const RefIdAdapter& adaptor = findAdapter (localIndex.second);
return adaptor.getData (&mColumns.at (column), mData, localIndex.first);
}
QVariant CSMWorld::RefIdCollection::getNestedData (int row, int column, int subRow, int subColumn) const
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex(row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
return nestedAdapter.getNestedData(&mColumns.at (column), mData, localIndex.first, subRow, subColumn);
}
void CSMWorld::RefIdCollection::setData (int index, int column, const QVariant& data)
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (index);
const RefIdAdapter& adaptor = findAdaptor (localIndex.second);
const RefIdAdapter& adaptor = findAdapter (localIndex.second);
adaptor.setData (&mColumns.at (column), mData, localIndex.first, data);
}
void CSMWorld::RefIdCollection::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn)
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
nestedAdapter.setNestedData(&mColumns.at (column), mData, localIndex.first, data, subRow, subColumn);
return;
}
void CSMWorld::RefIdCollection::removeRows (int index, int count)
{
mData.erase (index, count);
}
void CSMWorld::RefIdCollection::removeNestedRows(int row, int column, int subRow)
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
nestedAdapter.removeNestedRow(&mColumns.at (column), mData, localIndex.first, subRow);
return;
}
void CSMWorld::RefIdCollection::appendBlankRecord (const std::string& id, UniversalId::Type type)
{
mData.appendRecord (type, id, false);
@ -478,7 +687,7 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin,
void CSMWorld::RefIdCollection::appendRecord (const RecordBase& record,
UniversalId::Type type)
{
std::string id = findAdaptor (type).getId (record);
std::string id = findAdapter (type).getId (record);
int index = mData.getAppendIndex (type);
@ -581,3 +790,68 @@ const CSMWorld::RefIdData& CSMWorld::RefIdCollection::getDataSet() const
return mData;
}
int CSMWorld::RefIdCollection::getNestedRowsCount(int row, int column) const
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
return nestedAdapter.getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
}
int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
return nestedAdapter.getNestedColumnsCount(&mColumns.at(column), mData);
}
CSMWorld::NestableColumn *CSMWorld::RefIdCollection::getNestableColumn(int column)
{
return &mColumns.at(column);
}
void CSMWorld::RefIdCollection::addNestedRow(int row, int col, int position)
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(col), localIndex.second);
nestedAdapter.addNestedRow(&mColumns.at(col), mData, localIndex.first, position);
return;
}
void CSMWorld::RefIdCollection::setNestedTable(int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
nestedAdapter.setNestedTable(&mColumns.at(column), mData, localIndex.first, nestedTable);
return;
}
CSMWorld::NestedTableWrapperBase* CSMWorld::RefIdCollection::nestedTable(int row, int column) const
{
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
return nestedAdapter.nestedTable(&mColumns.at(column), mData, localIndex.first);
}
const CSMWorld::NestedRefIdAdapterBase& CSMWorld::RefIdCollection::getNestedAdapter(const CSMWorld::ColumnBase &column, UniversalId::Type type) const
{
for (std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*> > >::const_iterator iter (mNestedAdapters.begin());
iter!=mNestedAdapters.end(); ++iter)
{
if ((iter->first) == &column)
{
std::map<UniversalId::Type, NestedRefIdAdapterBase*>::const_iterator it =
(iter->second).find(type);
if (it == (iter->second).end())
throw std::runtime_error("No such type in the nestedadapters");
return *it->second;
}
}
throw std::runtime_error("No such column in the nestedadapters");
}

View File

@ -7,6 +7,7 @@
#include "columnbase.hpp"
#include "collectionbase.hpp"
#include "nestedcollection.hpp"
#include "refiddata.hpp"
namespace ESM
@ -17,8 +18,10 @@ namespace ESM
namespace CSMWorld
{
class RefIdAdapter;
struct NestedTableWrapperBase;
class NestedRefIdAdapterBase;
class RefIdColumn : public ColumnBase
class RefIdColumn : public NestableColumn
{
bool mEditable;
bool mUserEditable;
@ -26,15 +29,15 @@ namespace CSMWorld
public:
RefIdColumn (int columnId, Display displayType,
int flag = Flag_Table | Flag_Dialogue, bool editable = true,
bool userEditable = true);
int flag = Flag_Table | Flag_Dialogue, bool editable = true,
bool userEditable = true);
virtual bool isEditable() const;
virtual bool isUserEditable() const;
};
class RefIdCollection : public CollectionBase
class RefIdCollection : public CollectionBase, public NestedCollection
{
private:
@ -42,11 +45,15 @@ namespace CSMWorld
std::deque<RefIdColumn> mColumns;
std::map<UniversalId::Type, RefIdAdapter *> mAdapters;
std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*> > > mNestedAdapters;
private:
const RefIdAdapter& findAdaptor (UniversalId::Type) const;
const RefIdAdapter& findAdapter (UniversalId::Type) const;
///< Throws an exception if no adaptor for \a Type can be found.
const NestedRefIdAdapterBase& getNestedAdapter(const ColumnBase &column, UniversalId::Type type) const;
public:
RefIdCollection();
@ -69,7 +76,7 @@ namespace CSMWorld
virtual void removeRows (int index, int count);
virtual void cloneRecord(const std::string& origin,
virtual void cloneRecord(const std::string& origin,
const std::string& destination,
const UniversalId::Type type);
@ -110,11 +117,28 @@ namespace CSMWorld
///
/// \return Success?
virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const;
virtual NestedTableWrapperBase* nestedTable(int row, int column) const;
virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable);
virtual int getNestedRowsCount(int row, int column) const;
virtual int getNestedColumnsCount(int row, int column) const;
NestableColumn *getNestableColumn(int column);
virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn);
virtual void removeNestedRows(int row, int column, int subRow);
virtual void addNestedRow(int row, int col, int position);
void save (int index, ESM::ESMWriter& writer) const;
const RefIdData& getDataSet() const; //I can't figure out a better name for this one :(
const RefIdData& getDataSet() const; //I can't figure out a better name for this one :(
};
}
#endif

View File

@ -231,27 +231,27 @@ namespace CSMWorld
void save (int index, ESM::ESMWriter& writer) const;
//RECORD CONTAINERS ACCESS METHODS
const RefIdDataContainer<ESM::Book>& getBooks() const;
const RefIdDataContainer<ESM::Activator>& getActivators() const;
const RefIdDataContainer<ESM::Potion>& getPotions() const;
const RefIdDataContainer<ESM::Apparatus>& getApparati() const;
const RefIdDataContainer<ESM::Armor>& getArmors() const;
const RefIdDataContainer<ESM::Clothing>& getClothing() const;
const RefIdDataContainer<ESM::Container>& getContainers() const;
const RefIdDataContainer<ESM::Creature>& getCreatures() const;
const RefIdDataContainer<ESM::Door>& getDoors() const;
const RefIdDataContainer<ESM::Ingredient>& getIngredients() const;
const RefIdDataContainer<ESM::CreatureLevList>& getCreatureLevelledLists() const;
const RefIdDataContainer<ESM::ItemLevList>& getItemLevelledList() const;
const RefIdDataContainer<ESM::Light>& getLights() const;
const RefIdDataContainer<ESM::Lockpick>& getLocpicks() const;
const RefIdDataContainer<ESM::Miscellaneous>& getMiscellaneous() const;
const RefIdDataContainer<ESM::NPC>& getNPCs() const;
const RefIdDataContainer<ESM::Weapon >& getWeapons() const;
const RefIdDataContainer<ESM::Probe >& getProbes() const;
const RefIdDataContainer<ESM::Repair>& getRepairs() const;
const RefIdDataContainer<ESM::Static>& getStatics() const;
//RECORD CONTAINERS ACCESS METHODS
const RefIdDataContainer<ESM::Book>& getBooks() const;
const RefIdDataContainer<ESM::Activator>& getActivators() const;
const RefIdDataContainer<ESM::Potion>& getPotions() const;
const RefIdDataContainer<ESM::Apparatus>& getApparati() const;
const RefIdDataContainer<ESM::Armor>& getArmors() const;
const RefIdDataContainer<ESM::Clothing>& getClothing() const;
const RefIdDataContainer<ESM::Container>& getContainers() const;
const RefIdDataContainer<ESM::Creature>& getCreatures() const;
const RefIdDataContainer<ESM::Door>& getDoors() const;
const RefIdDataContainer<ESM::Ingredient>& getIngredients() const;
const RefIdDataContainer<ESM::CreatureLevList>& getCreatureLevelledLists() const;
const RefIdDataContainer<ESM::ItemLevList>& getItemLevelledList() const;
const RefIdDataContainer<ESM::Light>& getLights() const;
const RefIdDataContainer<ESM::Lockpick>& getLocpicks() const;
const RefIdDataContainer<ESM::Miscellaneous>& getMiscellaneous() const;
const RefIdDataContainer<ESM::NPC>& getNPCs() const;
const RefIdDataContainer<ESM::Weapon >& getWeapons() const;
const RefIdDataContainer<ESM::Probe >& getProbes() const;
const RefIdDataContainer<ESM::Repair>& getRepairs() const;
const RefIdDataContainer<ESM::Static>& getStatics() const;
};
}

View File

@ -1,6 +1,8 @@
#ifndef CSM_WOLRD_SUBCOLLECTION_H
#define CSM_WOLRD_SUBCOLLECTION_H
#include "nestedidcollection.hpp"
namespace ESM
{
class ESMReader;
@ -14,7 +16,7 @@ namespace CSMWorld
/// \brief Single type collection of top level records that are associated with cells
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class SubCellCollection : public IdCollection<ESXRecordT, IdAccessorT>
class SubCellCollection : public NestedIdCollection<ESXRecordT, IdAccessorT>
{
const IdCollection<Cell>& mCells;
@ -23,8 +25,6 @@ namespace CSMWorld
public:
SubCellCollection (const IdCollection<Cell>& cells);
};
template<typename ESXRecordT, typename IdAccessorT>
@ -39,7 +39,6 @@ namespace CSMWorld
const IdCollection<Cell>& cells)
: mCells (cells)
{}
}
#endif

View File

@ -94,7 +94,7 @@ void CSVDoc::View::setupEditMenu()
QAction *search = new QAction (tr ("Search"), this);
connect (search, SIGNAL (triggered()), this, SLOT (addSearchSubView()));
edit->addAction (search);
edit->addAction (search);
}
void CSVDoc::View::setupViewMenu()

View File

@ -84,7 +84,13 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
{ CSMWorld::ColumnBase::Display_MeshType, CSMWorld::Columns::ColumnId_MeshType, false },
{ CSMWorld::ColumnBase::Display_Gender, CSMWorld::Columns::ColumnId_Gender, true },
{ CSMWorld::ColumnBase::Display_SoundGeneratorType, CSMWorld::Columns::ColumnId_SoundGeneratorType, false },
{ CSMWorld::ColumnBase::Display_School, CSMWorld::Columns::ColumnId_School, true }
{ CSMWorld::ColumnBase::Display_School, CSMWorld::Columns::ColumnId_School, true },
{ CSMWorld::ColumnBase::Display_SkillImpact, CSMWorld::Columns::ColumnId_SkillImpact, true },
{ CSMWorld::ColumnBase::Display_EffectRange, CSMWorld::Columns::ColumnId_EffectRange, false },
{ CSMWorld::ColumnBase::Display_EffectId, CSMWorld::Columns::ColumnId_EffectId, false },
{ CSMWorld::ColumnBase::Display_PartRefType, CSMWorld::Columns::ColumnId_PartRefType, false },
{ CSMWorld::ColumnBase::Display_AiPackageType, CSMWorld::Columns::ColumnId_AiPackageType, false },
{ CSMWorld::ColumnBase::Display_YesNo, CSMWorld::Columns::ColumnId_AiWanderRepeat, false }
};
for (std::size_t i=0; i<sizeof (sMapping)/sizeof (Mapping); ++i)

View File

@ -17,21 +17,25 @@
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QComboBox>
#include <QScrollArea>
#include <QPushButton>
#include <QToolButton>
#include <QHeaderView>
#include "../../model/world/nestedtableproxymodel.hpp"
#include "../../model/world/columnbase.hpp"
#include "../../model/world/idtable.hpp"
#include "../../model/world/idtree.hpp"
#include "../../model/world/columns.hpp"
#include "../../model/world/record.hpp"
#include "../../model/world/tablemimedata.hpp"
#include "../../model/world/idtree.hpp"
#include "../../model/doc/document.hpp"
#include "../../model/world/commands.hpp"
#include "recordstatusdelegate.hpp"
#include "util.hpp"
#include "tablebottombox.hpp"
#include "nestedtable.hpp"
/*
==============================NotEditableSubDelegate==========================================
*/
@ -136,7 +140,7 @@ void CSVWorld::DialogueDelegateDispatcherProxy::tableMimeDataDropped(const std::
CSMWorld::UniversalId::Type type = data[i].getType();
if (mDisplay == CSMWorld::ColumnBase::Display_Referenceable)
{
if ( type == CSMWorld::UniversalId::Type_Activator
if (type == CSMWorld::UniversalId::Type_Activator
|| type == CSMWorld::UniversalId::Type_Potion
|| type == CSMWorld::UniversalId::Type_Apparatus
|| type == CSMWorld::UniversalId::Type_Armor
@ -172,9 +176,10 @@ void CSVWorld::DialogueDelegateDispatcherProxy::tableMimeDataDropped(const std::
==============================DialogueDelegateDispatcher==========================================
*/
CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, CSMDoc::Document& document) :
CSVWorld::DialogueDelegateDispatcher::DialogueDelegateDispatcher(QObject* parent,
CSMWorld::IdTable* table, CSMDoc::Document& document, QAbstractItemModel *model) :
mParent(parent),
mTable(table),
mTable(model ? model : table),
mDocument (document),
mNotEditableDelegate(table, parent)
{
@ -196,7 +201,8 @@ CSVWorld::CommandDelegate* CSVWorld::DialogueDelegateDispatcher::makeDelegate(CS
return delegate;
}
void CSVWorld::DialogueDelegateDispatcher::editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display)
void CSVWorld::DialogueDelegateDispatcher::editorDataCommited(QWidget* editor,
const QModelIndex& index, CSMWorld::ColumnBase::Display display)
{
setModelData(editor, mTable, index, display);
}
@ -228,12 +234,14 @@ void CSVWorld::DialogueDelegateDispatcher::setEditorData (QWidget* editor, const
}
}
void CSVWorld::DialogueDelegateDispatcher::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
void CSVWorld::DialogueDelegateDispatcher::setModelData(QWidget* editor,
QAbstractItemModel* model, const QModelIndex& index) const
{
setModelData(editor, model, index, CSMWorld::ColumnBase::Display_None);
}
void CSVWorld::DialogueDelegateDispatcher::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const
void CSVWorld::DialogueDelegateDispatcher::setModelData(QWidget* editor,
QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const
{
std::map<int, CommandDelegate*>::const_iterator delegateIt(mDelegates.find(display));
if (delegateIt != mDelegates.end())
@ -242,17 +250,20 @@ void CSVWorld::DialogueDelegateDispatcher::setModelData(QWidget* editor, QAbstra
}
}
void CSVWorld::DialogueDelegateDispatcher::paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
void CSVWorld::DialogueDelegateDispatcher::paint (QPainter* painter,
const QStyleOptionViewItem& option, const QModelIndex& index) const
{
//Does nothing
}
QSize CSVWorld::DialogueDelegateDispatcher::sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const
QSize CSVWorld::DialogueDelegateDispatcher::sizeHint (const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
return QSize(); //silencing warning, otherwise does nothing
}
QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index)
QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::Display display,
const QModelIndex& index)
{
QVariant variant = index.data();
if (!variant.isValid())
@ -267,13 +278,17 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
QWidget* editor = NULL;
if (! (mTable->flags (index) & Qt::ItemIsEditable))
{
return mNotEditableDelegate.createEditor(qobject_cast<QWidget*>(mParent), QStyleOptionViewItem(), index);
return mNotEditableDelegate.createEditor(qobject_cast<QWidget*>(mParent),
QStyleOptionViewItem(), index);
}
std::map<int, CommandDelegate*>::iterator delegateIt(mDelegates.find(display));
if (delegateIt != mDelegates.end())
{
editor = delegateIt->second->createEditor(qobject_cast<QWidget*>(mParent), QStyleOptionViewItem(), index, display);
editor = delegateIt->second->createEditor(qobject_cast<QWidget*>(mParent),
QStyleOptionViewItem(), index, display);
DialogueDelegateDispatcherProxy* proxy = new DialogueDelegateDispatcherProxy(editor, display);
// NOTE: For each entry in CSVWorld::CommandDelegate::createEditor() a corresponding entry
@ -281,10 +296,13 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
if (qobject_cast<DropLineEdit*>(editor))
{
connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited()));
connect(editor, SIGNAL(tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>&, const CSMDoc::Document*)),
proxy, SLOT(tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>&, const CSMDoc::Document*)));
connect(proxy, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
}
else if (qobject_cast<QCheckBox*>(editor))
{
@ -305,7 +323,9 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
else // throw an exception because this is a coding error
throw std::logic_error ("Dialogue editor type missing");
connect(proxy, SIGNAL(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)), this, SLOT(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)));
connect(proxy, SIGNAL(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)),
this, SLOT(editorDataCommited(QWidget*, const QModelIndex&, CSMWorld::ColumnBase::Display)));
mProxys.push_back(proxy); //deleted in the destructor
}
return editor;
@ -323,20 +343,40 @@ CSVWorld::DialogueDelegateDispatcher::~DialogueDelegateDispatcher()
=============================================================EditWidget=====================================================
*/
CSVWorld::EditWidget::~EditWidget()
{
for (unsigned i = 0; i < mNestedModels.size(); ++i)
{
delete mNestedModels[i];
}
delete mNestedTableDispatcher;
}
CSVWorld::EditWidget::EditWidget(QWidget *parent, int row, CSMWorld::IdTable* table, CSMDoc::Document& document, bool createAndDelete) :
mDispatcher(this, table, document),
mNestedTableDispatcher(NULL),
QScrollArea(parent),
mWidgetMapper(NULL),
mNestedTableMapper(NULL),
mMainWidget(NULL),
mDocument (document),
mTable(table)
{
remake (row);
connect(&mDispatcher, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)), this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
connect(&mDispatcher, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
this, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
}
void CSVWorld::EditWidget::remake(int row)
{
for (unsigned i = 0; i < mNestedModels.size(); ++i)
{
delete mNestedModels[i];
}
mNestedModels.clear();
delete mNestedTableDispatcher;
if (mMainWidget)
{
delete mMainWidget;
@ -350,7 +390,13 @@ void CSVWorld::EditWidget::remake(int row)
delete mWidgetMapper;
mWidgetMapper = 0;
}
if (mNestedTableMapper)
{
delete mNestedTableMapper;
mNestedTableMapper = 0;
}
mWidgetMapper = new QDataWidgetMapper (this);
mWidgetMapper->setModel(mTable);
mWidgetMapper->setItemDelegate(&mDispatcher);
@ -360,17 +406,28 @@ void CSVWorld::EditWidget::remake(int row)
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
QFrame* line2 = new QFrame(mMainWidget);
line2->setObjectName(QString::fromUtf8("line"));
line2->setGeometry(QRect(320, 150, 118, 3));
line2->setFrameShape(QFrame::HLine);
line2->setFrameShadow(QFrame::Sunken);
QVBoxLayout *mainLayout = new QVBoxLayout(mMainWidget);
QGridLayout *unlockedLayout = new QGridLayout();
QGridLayout *lockedLayout = new QGridLayout();
mainLayout->addLayout(lockedLayout, 0);
QGridLayout *unlockedLayout = new QGridLayout();
QVBoxLayout *tablesLayout = new QVBoxLayout();
mainLayout->addLayout(lockedLayout, QSizePolicy::Fixed);
mainLayout->addWidget(line, 1);
mainLayout->addLayout(unlockedLayout, 2);
mainLayout->addLayout(unlockedLayout, QSizePolicy::Preferred);
mainLayout->addWidget(line2, 1);
mainLayout->addLayout(tablesLayout, QSizePolicy::Preferred);
mainLayout->addStretch(1);
int unlocked = 0;
int locked = 0;
const int columns = mTable->columnCount();
for (int i=0; i<columns; ++i)
{
int flags = mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Flags).toInt();
@ -380,32 +437,115 @@ void CSVWorld::EditWidget::remake(int row)
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
(mTable->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
mDispatcher.makeDelegate(display);
QWidget *editor = mDispatcher.makeEditor(display, (mTable->index (row, i)));
if (editor)
if (mTable->hasChildren(mTable->index(row, i)) &&
!(flags & CSMWorld::ColumnBase::Flag_Dialogue_List))
{
mWidgetMapper->addMapping (editor, i);
QLabel* label = new QLabel(mTable->headerData (i, Qt::Horizontal).toString(), mMainWidget);
label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
editor->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
if (! (mTable->flags (mTable->index (row, i)) & Qt::ItemIsEditable))
mNestedModels.push_back(new CSMWorld::NestedTableProxyModel (mTable->index(row, i), display, dynamic_cast<CSMWorld::IdTree*>(mTable)));
NestedTable* table = new NestedTable(mDocument, mNestedModels.back(), this);
// FIXME: does not work well when enum delegates are used
//table->resizeColumnsToContents();
table->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::CurrentChanged);
int rows = mTable->rowCount(mTable->index(row, i));
int rowHeight = (rows == 0) ? table->horizontalHeader()->height() : table->rowHeight(0);
int tableMaxHeight = (5 * rowHeight)
+ table->horizontalHeader()->height() + 2 * table->frameWidth();
table->setMinimumHeight(tableMaxHeight);
QLabel* label =
new QLabel (mTable->headerData (i, Qt::Horizontal, Qt::DisplayRole).toString(), mMainWidget);
label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
tablesLayout->addWidget(label);
tablesLayout->addWidget(table);
}
else if (!(flags & CSMWorld::ColumnBase::Flag_Dialogue_List))
{
mDispatcher.makeDelegate (display);
QWidget* editor = mDispatcher.makeEditor (display, (mTable->index (row, i)));
if (editor)
{
lockedLayout->addWidget (label, locked, 0);
lockedLayout->addWidget (editor, locked, 1);
++locked;
} else
{
unlockedLayout->addWidget (label, unlocked, 0);
unlockedLayout->addWidget (editor, unlocked, 1);
++unlocked;
mWidgetMapper->addMapping (editor, i);
QLabel* label = new QLabel (mTable->headerData (i, Qt::Horizontal).toString(), mMainWidget);
label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
editor->setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
if (! (mTable->flags (mTable->index (row, i)) & Qt::ItemIsEditable))
{
lockedLayout->addWidget (label, locked, 0);
lockedLayout->addWidget (editor, locked, 1);
++locked;
}
else
{
unlockedLayout->addWidget (label, unlocked, 0);
unlockedLayout->addWidget (editor, unlocked, 1);
++unlocked;
}
}
}
else
{
mNestedModels.push_back(new CSMWorld::NestedTableProxyModel (
static_cast<CSMWorld::IdTree *>(mTable)->index(row, i),
display, static_cast<CSMWorld::IdTree *>(mTable)));
mNestedTableMapper = new QDataWidgetMapper (this);
mNestedTableMapper->setModel(mNestedModels.back());
// FIXME: lack MIME support?
mNestedTableDispatcher =
new DialogueDelegateDispatcher (this, mTable, mDocument, mNestedModels.back());
mNestedTableMapper->setItemDelegate(mNestedTableDispatcher);
int columnCount =
mTable->columnCount(mTable->getModelIndex (mNestedModels.back()->getParentId(), i));
for (int col = 0; col < columnCount; ++col)
{
int displayRole = mNestedModels.back()->headerData (col,
Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt();
CSMWorld::ColumnBase::Display display =
static_cast<CSMWorld::ColumnBase::Display> (displayRole);
mNestedTableDispatcher->makeDelegate (display);
// FIXME: assumed all columns are editable
QWidget* editor =
mNestedTableDispatcher->makeEditor (display, mNestedModels.back()->index (0, col));
if (editor)
{
mNestedTableMapper->addMapping (editor, col);
std::string disString = mNestedModels.back()->headerData (col,
Qt::Horizontal, Qt::DisplayRole).toString().toStdString();
// Need ot use Qt::DisplayRole in order to get the correct string
// from CSMWorld::Columns
QLabel* label = new QLabel (mNestedModels.back()->headerData (col,
Qt::Horizontal, Qt::DisplayRole).toString(), mMainWidget);
label->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
editor->setSizePolicy (QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
unlockedLayout->addWidget (label, unlocked, 0);
unlockedLayout->addWidget (editor, unlocked, 1);
++unlocked;
}
}
mNestedTableMapper->setCurrentModelIndex(mNestedModels.back()->index(0, 0));
}
}
}
mWidgetMapper->setCurrentModelIndex(mTable->index(row, 0));
if (unlocked == 0)
mainLayout->removeWidget(line);
this->setWidget(mMainWidget);
this->setWidgetResizable(true);
}
@ -421,13 +561,14 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
mMainLayout(NULL),
mUndoStack(document.getUndoStack()),
mTable(dynamic_cast<CSMWorld::IdTable*>(document.getData().getTableModel(id))),
mRow (-1),
mLocked(false),
mDocument(document),
mCommandDispatcher (document, CSMWorld::UniversalId::getParentType (id.getType()))
{
connect(mTable, SIGNAL(dataChanged (const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged(const QModelIndex&)));
mRow = mTable->getModelIndex (id.getId(), 0).row();
changeCurrentId(id.getId());
QWidget *mainWidget = new QWidget(this);
QHBoxLayout *buttonsLayout = new QHBoxLayout;
@ -480,12 +621,12 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
connect(nextButton, SIGNAL(clicked()), this, SLOT(nextId()));
connect(prevButton, SIGNAL(clicked()), this, SLOT(prevId()));
connect(cloneButton, SIGNAL(clicked()), this, SLOT(cloneRequest()));
connect(revertButton, SIGNAL(clicked()), this, SLOT(revertRecord()));
connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteRecord()));
connect(revertButton, SIGNAL(clicked()), &mCommandDispatcher, SLOT(executeRevert()));
connect(deleteButton, SIGNAL(clicked()), &mCommandDispatcher, SLOT(executeDelete()));
mMainLayout = new QVBoxLayout(mainWidget);
mEditWidget = new EditWidget(mainWidget, mRow, mTable, document, false);
mEditWidget = new EditWidget(mainWidget, mTable->getModelIndex(mCurrentId, 0).row(), mTable, document, false);
connect(mEditWidget, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
this, SLOT(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
@ -496,24 +637,27 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
new TableBottomBox (creatorFactory, document.getData(), document.getUndoStack(), id, this));
mBottom->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
connect(mBottom, SIGNAL(requestFocus(const std::string&)), this, SLOT(requestFocus(const std::string&)));
connect(addButton, SIGNAL(clicked()), mBottom, SLOT(createRequest()));
if(!mBottom->canCreateAndDelete())
{
cloneButton->setDisabled(true);
addButton->setDisabled(true);
deleteButton->setDisabled(true);
cloneButton->setDisabled (true);
addButton->setDisabled (true);
deleteButton->setDisabled (true);
}
dataChanged(mTable->index(mRow, 0));
mMainLayout->addLayout(buttonsLayout);
setWidget(mainWidget);
dataChanged(mTable->getModelIndex (mCurrentId, 0));
mMainLayout->addLayout (buttonsLayout);
setWidget (mainWidget);
}
void CSVWorld::DialogueSubView::prevId()
void CSVWorld::DialogueSubView::prevId ()
{
int newRow = mRow - 1;
int newRow = mTable->getModelIndex(mCurrentId, 0).row() - 1;
if (newRow < 0)
{
return;
@ -531,19 +675,23 @@ void CSVWorld::DialogueSubView::prevId()
if (!(state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased))
{
mEditWidget->remake(newRow);
setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (newRow, 2)).toInt()),
mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()));
mRow = newRow;
changeCurrentId(std::string(mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()));
mEditWidget->setDisabled(mLocked);
return;
}
--newRow;
}
}
void CSVWorld::DialogueSubView::nextId()
void CSVWorld::DialogueSubView::nextId ()
{
int newRow = mRow + 1;
int newRow = mTable->getModelIndex(mCurrentId, 0).row() + 1;
if (newRow >= mTable->rowCount())
{
@ -560,13 +708,17 @@ void CSVWorld::DialogueSubView::nextId()
}
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (newRow, 1)).toInt());
if (!(state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased))
if (!(state == CSMWorld::RecordBase::State_Deleted))
{
mEditWidget->remake(newRow);
setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (newRow, 2)).toInt()),
mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()));
mRow = newRow;
mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()));
changeCurrentId(std::string(mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()));
mEditWidget->setDisabled(mLocked);
return;
}
++newRow;
@ -576,28 +728,35 @@ void CSVWorld::DialogueSubView::nextId()
void CSVWorld::DialogueSubView::setEditLock (bool locked)
{
mLocked = locked;
QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (mRow, 1)).toInt());
if (currentIndex.isValid())
{
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (currentIndex.row(), 1)).toInt());
mEditWidget->setDisabled (state==CSMWorld::RecordBase::State_Deleted || locked);
mEditWidget->setDisabled (state==CSMWorld::RecordBase::State_Deleted || locked);
mCommandDispatcher.setEditLock (locked);
}
mCommandDispatcher.setEditLock (locked);
}
void CSVWorld::DialogueSubView::dataChanged(const QModelIndex & index)
void CSVWorld::DialogueSubView::dataChanged (const QModelIndex & index)
{
if (index.row() == mRow)
QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
if (currentIndex.isValid() && index.row() == currentIndex.row())
{
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (mRow, 1)).toInt());
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (currentIndex.row(), 1)).toInt());
mEditWidget->setDisabled (state==CSMWorld::RecordBase::State_Deleted || mLocked);
}
}
void CSVWorld::DialogueSubView::tableMimeDataDropped(QWidget* editor,
const QModelIndex& index,
const CSMWorld::UniversalId& id,
const CSMDoc::Document* document)
void CSVWorld::DialogueSubView::tableMimeDataDropped (QWidget* editor,
const QModelIndex& index,
const CSMWorld::UniversalId& id,
const CSMDoc::Document* document)
{
if (document == &mDocument)
{
@ -605,95 +764,49 @@ void CSVWorld::DialogueSubView::tableMimeDataDropped(QWidget* editor,
}
}
void CSVWorld::DialogueSubView::revertRecord()
{
int rows = mTable->rowCount();
if (!mLocked && mTable->columnCount() > 0 && mRow < mTable->rowCount() )
{
CSMWorld::RecordBase::State state =
static_cast<CSMWorld::RecordBase::State> (mTable->data (mTable->index (mRow, 1)).toInt());
if (state!=CSMWorld::RecordBase::State_BaseOnly)
{
mUndoStack.push(new CSMWorld::RevertCommand(*mTable, mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData()));
}
if (rows != mTable->rowCount())
{
if (mTable->rowCount() == 0)
{
mEditWidget->setDisabled(true); //closing the editor is other option
return;
}
if (mRow >= mTable->rowCount())
{
prevId();
} else {
dataChanged(mTable->index(mRow, 0));
}
}
}
}
void CSVWorld::DialogueSubView::deleteRecord()
{
int rows = mTable->rowCount();
//easier than disabling the button
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (mRow, 1)).toInt());
bool deledetedOrErased = (state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased);
if (!mLocked &&
mTable->columnCount() > 0 &&
!deledetedOrErased &&
mRow < rows &&
mBottom->canCreateAndDelete())
{
mUndoStack.push(new CSMWorld::DeleteCommand(*mTable, mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData()));
if (rows != mTable->rowCount())
{
if (mTable->rowCount() == 0)
{
mEditWidget->setDisabled(true); //closing the editor is other option
return;
}
if (mRow >= mTable->rowCount())
{
prevId();
} else {
dataChanged(mTable->index(mRow, 0));
}
}
}
}
void CSVWorld::DialogueSubView::requestFocus (const std::string& id)
{
mRow = mTable->getModelIndex (id, 0).row();
mEditWidget->remake(mRow);
changeCurrentId(id);
mEditWidget->remake(mTable->getModelIndex (id, 0).row());
}
void CSVWorld::DialogueSubView::cloneRequest ()
{
mBottom->cloneRequest(mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData(),
static_cast<CSMWorld::UniversalId::Type>(mTable->data(mTable->index(mRow, 2)).toInt()));
mBottom->cloneRequest(mCurrentId, static_cast<CSMWorld::UniversalId::Type>(mTable->data(mTable->getModelIndex(mCurrentId, 2)).toInt()));
}
void CSVWorld::DialogueSubView::showPreview ()
{
if ((mTable->getFeatures() & CSMWorld::IdTable::Feature_Preview) &&
mRow < mTable->rowCount())
QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
if (currentIndex.isValid() &&
mTable->getFeatures() & CSMWorld::IdTable::Feature_Preview &&
currentIndex.row() < mTable->rowCount())
{
emit focusId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Preview, mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData()), "");
emit focusId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Preview, mCurrentId), "");
}
}
void CSVWorld::DialogueSubView::viewRecord()
void CSVWorld::DialogueSubView::viewRecord ()
{
if (mRow < mTable->rowCount())
QModelIndex currentIndex(mTable->getModelIndex (mCurrentId, 0));
if (currentIndex.isValid() &&
currentIndex.row() < mTable->rowCount())
{
std::pair<CSMWorld::UniversalId, std::string> params = mTable->view (mRow);
std::pair<CSMWorld::UniversalId, std::string> params = mTable->view (currentIndex.row());
if (params.first.getType()!=CSMWorld::UniversalId::Type_None)
emit focusId (params.first, params.second);
}
}
void CSVWorld::DialogueSubView::changeCurrentId (const std::string& newId)
{
std::vector<std::string> selection;
mCurrentId = std::string(newId);
selection.push_back(mCurrentId);
mCommandDispatcher.setSelection(selection);
}

View File

@ -21,6 +21,7 @@ class QVBoxLayout;
namespace CSMWorld
{
class IdTable;
class NestedTableProxyModel;
}
namespace CSMDoc
@ -38,16 +39,20 @@ namespace CSVWorld
{
const CSMWorld::IdTable* mTable;
public:
NotEditableSubDelegate(const CSMWorld::IdTable* table, QObject * parent = 0);
NotEditableSubDelegate(const CSMWorld::IdTable* table,
QObject * parent = 0);
virtual void setEditorData (QWidget* editor, const QModelIndex& index) const;
virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void paint (QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual QSize sizeHint (const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
virtual QWidget *createEditor (QWidget *parent,
@ -74,16 +79,20 @@ namespace CSVWorld
std::auto_ptr<refWrapper> mIndexWrapper;
public:
DialogueDelegateDispatcherProxy(QWidget* editor, CSMWorld::ColumnBase::Display display);
DialogueDelegateDispatcherProxy(QWidget* editor,
CSMWorld::ColumnBase::Display display);
QWidget* getEditor() const;
public slots:
void editorDataCommited();
void setIndex(const QModelIndex& index);
void tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>& data, const CSMDoc::Document* document);
void tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>& data,
const CSMDoc::Document* document);
signals:
void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display);
void editorDataCommited(QWidget* editor,
const QModelIndex& index,
CSMWorld::ColumnBase::Display display);
void tableMimeDataDropped(QWidget* editor, const QModelIndex& index,
const CSMWorld::UniversalId& id,
@ -98,59 +107,75 @@ namespace CSVWorld
QObject* mParent;
CSMWorld::IdTable* mTable;
QAbstractItemModel* mTable;
CSMDoc::Document& mDocument;
CSMDoc::Document& mDocument;
NotEditableSubDelegate mNotEditableDelegate;
std::vector<DialogueDelegateDispatcherProxy*> mProxys; //once we move to the C++11 we should use unique_ptr
std::vector<DialogueDelegateDispatcherProxy*> mProxys;
//once we move to the C++11 we should use unique_ptr
public:
DialogueDelegateDispatcher(QObject* parent, CSMWorld::IdTable* table, CSMDoc::Document& document);
DialogueDelegateDispatcher(QObject* parent,
CSMWorld::IdTable* table,
CSMDoc::Document& document,
QAbstractItemModel* model = 0);
~DialogueDelegateDispatcher();
CSVWorld::CommandDelegate* makeDelegate(CSMWorld::ColumnBase::Display display);
QWidget* makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index);
///< will return null if delegate is not present, parent of the widget is same as for dispatcher itself
///< will return null if delegate is not present, parent of the widget is
//same as for dispatcher itself
virtual void setEditorData (QWidget* editor, const QModelIndex& index) const;
virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
virtual void setModelData (QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index) const;
virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index, CSMWorld::ColumnBase::Display display) const;
virtual void setModelData (QWidget* editor,
QAbstractItemModel* model, const QModelIndex& index,
CSMWorld::ColumnBase::Display display) const;
virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual void paint (QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const;
virtual QSize sizeHint (const QStyleOptionViewItem& option,
const QModelIndex& index) const;
///< does nothing
private slots:
void editorDataCommited(QWidget* editor, const QModelIndex& index, CSMWorld::ColumnBase::Display display);
void editorDataCommited(QWidget* editor, const QModelIndex& index,
CSMWorld::ColumnBase::Display display);
signals:
void tableMimeDataDropped(QWidget* editor, const QModelIndex& index,
const CSMWorld::UniversalId& id,
const CSMDoc::Document* document);
};
class EditWidget : public QScrollArea
{
Q_OBJECT
QDataWidgetMapper *mWidgetMapper;
QDataWidgetMapper *mNestedTableMapper;
DialogueDelegateDispatcher mDispatcher;
DialogueDelegateDispatcher *mNestedTableDispatcher;
QWidget* mMainWidget;
CSMWorld::IdTable* mTable;
CSMDoc::Document& mDocument;
std::vector<CSMWorld::NestedTableProxyModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor
public:
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table, CSMDoc::Document& document, bool createAndDelete = false);
EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table,
CSMDoc::Document& document, bool createAndDelete = false);
virtual ~EditWidget();
void remake(int row);
@ -168,7 +193,7 @@ namespace CSVWorld
QVBoxLayout* mMainLayout;
CSMWorld::IdTable* mTable;
QUndoStack& mUndoStack;
int mRow;
std::string mCurrentId;
bool mLocked;
const CSMDoc::Document& mDocument;
TableBottomBox* mBottom;
@ -183,6 +208,9 @@ namespace CSVWorld
virtual void setEditLock (bool locked);
private:
void changeCurrentId(const std::string& newCurrent);
private slots:
void nextId();
@ -193,10 +221,6 @@ namespace CSVWorld
void viewRecord();
void revertRecord();
void deleteRecord();
void cloneRequest();
void dataChanged(const QModelIndex & index);

View File

@ -21,7 +21,9 @@ void CSVWorld::EnumDelegate::setModelDataImp (QWidget *editor, QAbstractItemMode
iter!=mValues.end(); ++iter)
if (iter->second==value)
{
addCommands (model, index, iter->first);
// do nothing if the value has not changed
if (model->data(index).toInt() != iter->first)
addCommands (model, index, iter->first);
break;
}
}

View File

@ -0,0 +1,91 @@
#include "nestedtable.hpp"
#include "../../model/world/nestedtableproxymodel.hpp"
#include "../../model/world/universalid.hpp"
#include "../../model/world/commands.hpp"
#include "util.hpp"
#include <QHeaderView>
#include <QContextMenuEvent>
#include <QMenu>
#include <QDebug>
CSVWorld::NestedTable::NestedTable(CSMDoc::Document& document,
CSMWorld::NestedTableProxyModel* model,
QWidget* parent)
: QTableView(parent),
mUndoStack(document.getUndoStack()),
mModel(model)
{
setSelectionBehavior (QAbstractItemView::SelectRows);
setSelectionMode (QAbstractItemView::ExtendedSelection);
horizontalHeader()->setResizeMode (QHeaderView::Interactive);
verticalHeader()->hide();
int columns = model->columnCount(QModelIndex());
for(int i = 0 ; i < columns; ++i)
{
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display> (
model->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate(display,
document,
this);
setItemDelegateForColumn(i, delegate);
}
setModel(model);
setAcceptDrops(true);
mAddNewRowAction = new QAction (tr ("Add new row"), this);
connect(mAddNewRowAction, SIGNAL(triggered()),
this, SLOT(addNewRowActionTriggered()));
mRemoveRowAction = new QAction (tr ("Remove row"), this);
connect(mRemoveRowAction, SIGNAL(triggered()),
this, SLOT(removeRowActionTriggered()));
}
void CSVWorld::NestedTable::dragEnterEvent(QDragEnterEvent *event)
{
}
void CSVWorld::NestedTable::dragMoveEvent(QDragMoveEvent *event)
{
}
void CSVWorld::NestedTable::contextMenuEvent (QContextMenuEvent *event)
{
QModelIndexList selectedRows = selectionModel()->selectedRows();
QMenu menu(this);
if (selectionModel()->selectedRows().size() == 1)
menu.addAction(mRemoveRowAction);
menu.addAction(mAddNewRowAction);
menu.exec (event->globalPos());
}
void CSVWorld::NestedTable::removeRowActionTriggered()
{
mUndoStack.push(new CSMWorld::DeleteNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().begin()->row(),
mModel->getParentColumn()));
}
void CSVWorld::NestedTable::addNewRowActionTriggered()
{
mUndoStack.push(new CSMWorld::AddNestedCommand(*(mModel->model()),
mModel->getParentId(),
selectionModel()->selectedRows().size(),
mModel->getParentColumn()));
}

View File

@ -0,0 +1,53 @@
#ifndef CSV_WORLD_NESTEDTABLE_H
#define CSV_WORLD_NESTEDTABLE_H
#include <QTableView>
#include <QtGui/qevent.h>
class QUndoStack;
class QAction;
class QContextMenuEvent;
namespace CSMWorld
{
class NestedTableProxyModel;
class UniversalId;
}
namespace CSMDoc
{
class Document;
}
namespace CSVWorld
{
class NestedTable : public QTableView
{
Q_OBJECT
QAction *mAddNewRowAction;
QAction *mRemoveRowAction;
QUndoStack& mUndoStack;
CSMWorld::NestedTableProxyModel* mModel;
public:
NestedTable(CSMDoc::Document& document,
CSMWorld::NestedTableProxyModel* model,
QWidget* parent = NULL);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
private:
void contextMenuEvent (QContextMenuEvent *event);
private slots:
void removeRowActionTriggered();
void addNewRowActionTriggered();
};
}
#endif

View File

@ -120,7 +120,7 @@ void CSVWorld::CommandDelegate::setModelDataImp (QWidget *editor, QAbstractItemM
QVariant new_ = hack.getData();
if (model->data (index)!=new_)
if ((model->data (index)!=new_) && (model->flags(index) & Qt::ItemIsEditable))
getUndoStack().push (new CSMWorld::ModifyCommand (*model, index, new_));
}
@ -180,7 +180,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
case CSMWorld::ColumnBase::Display_Float:
{
QDoubleSpinBox *dsb = new QDoubleSpinBox(parent);
dsb->setRange(FLT_MIN, FLT_MAX);
dsb->setRange(-FLT_MAX, FLT_MAX);
dsb->setSingleStep(0.01f);
dsb->setDecimals(3);
return dsb;