Tome
A generic data editor for games supporting arbitrary input and output formats.
Signals | Public Member Functions | List of all members
Tome::RecordsController Class Reference

Controller for adding, updating and removing records. More...

#include <recordscontroller.h>

Inheritance diagram for Tome::RecordsController:

Signals

void progressChanged (const QString title, const QString text, const int currentValue, const int maximumValue)
 Progress of the current record operation has changed. More...
 
void recordAdded (const QVariant &recordId, const QString &recordDisplayName, const QVariant &parentId)
 A new record has been added to the project. More...
 
void recordFieldsChanged (const QVariant &recordId)
 A new field has been added to a record, or one of its fields has been updated or removed. More...
 
void recordRemoved (const QVariant &recordId)
 A record has been removed from the project. More...
 
void recordReparented (const QVariant &recordId, const QVariant &oldParentId, const QVariant &newParentId)
 The parent of a record has changed. More...
 
void recordUpdated (const QVariant &oldId, const QString &oldDisplayName, const QString &oldEditorIconFieldId, const QVariant &newId, const QString &newDisplayName, const QString &newEditorIconFieldId)
 The properties of a record have been updated. More...
 
void recordSetsChanged ()
 A record set has been added to or removed from the project.
 

Public Member Functions

 RecordsController (const FieldDefinitionsController &fieldDefinitionsController, const ProjectController &projectController, const TypesController &typesController)
 Constructs a new controller for adding, updating and removing records. More...
 
const Record addRecord (const QVariant &id, const QString &displayName, const QString &editorIconFieldId, const QStringList &fieldIds, const QString &recordSetName)
 Adds a new record to the specified set. More...
 
void addRecordSet (const RecordSet &recordSet)
 Adds the passed record set to the project. More...
 
const QString computeRecordsHash () const
 Computes an MD5 hash of all current record data. More...
 
const Record duplicateRecord (const QVariant &existingRecordId, const QVariant &newRecordId)
 Duplicats the record with the specified id, including all of its field values. More...
 
const RecordList getAncestors (const QVariant &id) const
 Gets the list of all ancestors of the record with the specified id, direct parent first. More...
 
const RecordList getChildren (const QVariant &id) const
 Gets the list of all records that have the record with the specified id as parent. More...
 
const RecordList getDescendents (const QVariant &id) const
 Gets the list of all records that have the record with the specified id as parent, or any parent that has. More...
 
const QVariant getInheritedFieldValue (const QVariant &id, const QString &fieldId) const
 Gets the value of the specified field for the record with the specified id, as inherited by its parent or any of its ancestors. More...
 
const RecordFieldValueMap getInheritedFieldValues (const QVariant &id) const
 Gets the values of all fields for the record with the specified id, as inherited by its parent or any of its ancestors. More...
 
const QVariant getParentId (const QVariant &id) const
 Gets the id of the parent of the record with the specified id. More...
 
const RecordSetList & getRecordSets () const
 Gets a list of all record sets in the project. More...
 
const RecordgetRecord (const QVariant &id) const
 Returns the record with the specified id. More...
 
const RecordList getRecords () const
 Gets a list of all records in the project. More...
 
const QVariantList getRecordIds () const
 Gets a list of the ids of all records in the project. More...
 
const QString getRecordEditorIconFieldId (const QVariant &id) const
 Gets the id of the field to use as editor icon for the record with the specified id. More...
 
const QStringList getRecordNames () const
 Returns a list of the names of all records of this project. More...
 
const QStringList getRecordSetNames () const
 Gets a list of the names of all record sets in the project. More...
 
const RecordFieldValueMap getRecordFieldValues (const QVariant &id) const
 Returns the map of actual field values of the record with the specified id, including all inherited values. More...
 
const QVariant getRootRecordId (const QVariant &id) const
 Gets the id of the root of the record with the specified id. More...
 
bool hasRecord (const QVariant &id) const
 Checks whether the project has a record with the specified id. More...
 
bool haveTheSameParent (const QVariantList ids) const
 Checks whether all records with the specified ids have the same parent in the record tree. More...
 
bool isAncestorOf (const QVariant &possibleAncestor, const QVariant &recordId) const
 Checks whether the first record is an ancestor of the second one. More...
 
void removeRecord (const QVariant &recordId)
 Removes the record with the specified id from the project. More...
 
void removeRecordSet (const QString &name)
 Removes the record set with the specified name from the project, including all records. More...
 
void revertRecord (const QVariant &recordId)
 Reverts all fields of the record with the specified id to their inherited or default value. More...
 
void reparentRecord (const QVariant &recordId, const QVariant &newParentId)
 Changes the parent of the record with the specified id. More...
 
void setReadOnly (const QVariant &recordId, const bool readOnly)
 Marks the record with the specified id as read-only or not, preventing it from being edited, reparented or removed. More...
 
void setRecordSets (RecordSetList &model)
 Uses the specified list of record sets as model for this controller. More...
 
void updateRecord (const QVariant oldId, const QVariant newId, const QString newDisplayName, const QString newEditorIconFieldId, const QStringList &newFieldIds, const QString &newRecordSetName)
 Updates the properties of the specified record. More...
 
void updateRecordFieldValue (const QVariant &recordId, const QString &fieldId, const QVariant &fieldValue)
 Updates the current value of a record field. More...
 

Detailed Description

Controller for adding, updating and removing records.

Constructor & Destructor Documentation

◆ RecordsController()

RecordsController::RecordsController ( const FieldDefinitionsController fieldDefinitionsController,
const ProjectController projectController,
const TypesController typesController 
)

Constructs a new controller for adding, updating and removing records.

Parameters
fieldDefinitionsControllerController for adding, updating and removing field definitions.
projectControllerController for creating, loading and saving projects.
typesControllerController for adding, updating and removing custom types.

Member Function Documentation

◆ addRecord()

const Record RecordsController::addRecord ( const QVariant &  id,
const QString &  displayName,
const QString &  editorIconFieldId,
const QStringList &  fieldIds,
const QString &  recordSetName 
)

Adds a new record to the specified set.

Exceptions
std::out_of_rangeif the record set could not be found.
std::out_of_rangeif the record id type of the project is invalid.
Parameters
idId of the record to add.
displayNameDisplay name of the record to add.
editorIconFieldIdId of the field to use as editor icon for the record to add.
fieldIdsIds of the fields to add to the new record.
recordSetNameName of the record set to add the new record to.
Returns
Copy of the added record.

◆ addRecordSet()

void RecordsController::addRecordSet ( const RecordSet recordSet)

Adds the passed record set to the project.

Parameters
recordSetRecord set to add.

◆ computeRecordsHash()

const QString RecordsController::computeRecordsHash ( ) const

Computes an MD5 hash of all current record data.

Returns
MD5 hash of all current record data, as hex string.

◆ duplicateRecord()

const Record RecordsController::duplicateRecord ( const QVariant &  existingRecordId,
const QVariant &  newRecordId 
)

Duplicats the record with the specified id, including all of its field values.

Exceptions
std::out_of_rangeif the record id type of the project is invalid.
Parameters
existingRecordIdId of the record to duplicate.
newRecordIdId of the record to add.
Returns
Copy of the duplicated record.

◆ getAncestors()

const RecordList RecordsController::getAncestors ( const QVariant &  id) const

Gets the list of all ancestors of the record with the specified id, direct parent first.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
idId of the record to get the ancestors of.
Returns
List of all ancestors of the record with the specified id, direct parent first.

◆ getChildren()

const RecordList RecordsController::getChildren ( const QVariant &  id) const

Gets the list of all records that have the record with the specified id as parent.

Parameters
idId of the record to get the children of.
Returns
List of all records that have the record with the specified id as parent.

◆ getDescendents()

const RecordList RecordsController::getDescendents ( const QVariant &  id) const

Gets the list of all records that have the record with the specified id as parent, or any parent that has.

Parameters
idId of the record to get the descendants of.
Returns
List of all records that have the record with the specified id as parent, or any parent that has.

◆ getInheritedFieldValue()

const QVariant RecordsController::getInheritedFieldValue ( const QVariant &  id,
const QString &  fieldId 
) const

Gets the value of the specified field for the record with the specified id, as inherited by its parent or any of its ancestors.

Parameters
idId of the record to get the inherited field value of.
fieldIdId of the field to get the inherited field value of.
Returns
Value of the specified field for the record with the specified id, as inherited by its parent or any of its ancestors.

◆ getInheritedFieldValues()

const RecordFieldValueMap RecordsController::getInheritedFieldValues ( const QVariant &  id) const

Gets the values of all fields for the record with the specified id, as inherited by its parent or any of its ancestors.

Parameters
idId of the record to get the inherited field values of.
Returns
Values of the all fields for the record with the specified id, as inherited by its parent or any of its ancestors.

◆ getParentId()

const QVariant RecordsController::getParentId ( const QVariant &  id) const

Gets the id of the parent of the record with the specified id.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
idId of the record to get the parent id of.
Returns
Id of the parent of the record with the specified id, or null if the record is a root of the record tree.

◆ getRecord()

const Record & RecordsController::getRecord ( const QVariant &  id) const

Returns the record with the specified id.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
idId of the record to get.
Returns
Record with the specified id.

◆ getRecordEditorIconFieldId()

const QString RecordsController::getRecordEditorIconFieldId ( const QVariant &  id) const

Gets the id of the field to use as editor icon for the record with the specified id.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
idId of the record to get the editor icon field of.
Returns
Id of the field to use as editor icon for the record with the specified id.

◆ getRecordFieldValues()

const RecordFieldValueMap RecordsController::getRecordFieldValues ( const QVariant &  id) const

Returns the map of actual field values of the record with the specified id, including all inherited values.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
idId of the record the get the map of field values of.
Returns
Map of actual field values of the record with the specified id.

◆ getRecordIds()

const QVariantList RecordsController::getRecordIds ( ) const

Gets a list of the ids of all records in the project.

Returns
List of the ids of all records in the project.

◆ getRecordNames()

const QStringList RecordsController::getRecordNames ( ) const

Returns a list of the names of all records of this project.

Returns
List containing the names of all records of this project.

◆ getRecords()

const RecordList RecordsController::getRecords ( ) const

Gets a list of all records in the project.

Returns
List of all records in the project.

◆ getRecordSetNames()

const QStringList RecordsController::getRecordSetNames ( ) const

Gets a list of the names of all record sets in the project.

Returns
List of the names of all record sets in the project.

◆ getRecordSets()

const RecordSetList & RecordsController::getRecordSets ( ) const

Gets a list of all record sets in the project.

Returns
List of all record sets in the project.

◆ getRootRecordId()

const QVariant RecordsController::getRootRecordId ( const QVariant &  id) const

Gets the id of the root of the record with the specified id.

Parameters
idId of the record to get the root of.
Returns
Id of the root of the record with the specified id, or the specified id itself if the record is a root.

◆ hasRecord()

bool RecordsController::hasRecord ( const QVariant &  id) const

Checks whether the project has a record with the specified id.

Parameters
idId of the record to look for.
Returns
true, if a record with the specified id exists, and false otherwise.

◆ haveTheSameParent()

bool RecordsController::haveTheSameParent ( const QVariantList  ids) const

Checks whether all records with the specified ids have the same parent in the record tree.

Parameters
idsList of ids of the records to check.
Returns
true, if all records with the specified ids have the same parent record, and false otherwise.

◆ isAncestorOf()

bool RecordsController::isAncestorOf ( const QVariant &  possibleAncestor,
const QVariant &  recordId 
) const

Checks whether the first record is an ancestor of the second one.

Parameters
possibleAncestorRecord to check if it is an ancestor.
recordIdRecord to check the ancestors of.
Returns
true, if the first record is an ancestor of the second one, and false otherwise.

◆ progressChanged

void Tome::RecordsController::progressChanged ( const QString  title,
const QString  text,
const int  currentValue,
const int  maximumValue 
)
signal

Progress of the current record operation has changed.

Parameters
titleTitle of the current record operation step.
textDetails of the current record operation step.
currentValueCurrent progress value of the current record operation step.
maximumValueMaximum progress value of the current record operation step.

◆ recordAdded

void Tome::RecordsController::recordAdded ( const QVariant &  recordId,
const QString &  recordDisplayName,
const QVariant &  parentId 
)
signal

A new record has been added to the project.

Parameters
recordIdId of the new record.
recordDisplayNameDisplay name of the new record.
parentIdId of the parent of the new record, or null if its a new root of the record tree.

◆ recordFieldsChanged

void Tome::RecordsController::recordFieldsChanged ( const QVariant &  recordId)
signal

A new field has been added to a record, or one of its fields has been updated or removed.

Parameters
recordIdId of the record whose fields have changed.

◆ recordRemoved

void Tome::RecordsController::recordRemoved ( const QVariant &  recordId)
signal

A record has been removed from the project.

Parameters
recordIdId of the record that has been removed from the project.

◆ recordReparented

void Tome::RecordsController::recordReparented ( const QVariant &  recordId,
const QVariant &  oldParentId,
const QVariant &  newParentId 
)
signal

The parent of a record has changed.

Parameters
recordIdId of the record whose parent has changed.
oldParentIdId of the previous parent of the record.
newParentIdId of the new parent of the record, or null if its a new root of the record tree.

◆ recordUpdated

void Tome::RecordsController::recordUpdated ( const QVariant &  oldId,
const QString &  oldDisplayName,
const QString &  oldEditorIconFieldId,
const QVariant &  newId,
const QString &  newDisplayName,
const QString &  newEditorIconFieldId 
)
signal

The properties of a record have been updated.

Parameters
oldIdPrevious id of the record which has been updated.
oldDisplayNamePrevious display name of the record which has been updated.
oldEditorIconFieldIdPrevious id of the field to use as editor icon for the record which has been updated.
newIdNew id of the record which has been updated.
newDisplayNameNew display name of the record which has been updated.
newEditorIconFieldIdNew id of the field to use as editor icon for the record which has been updated.

◆ removeRecord()

void RecordsController::removeRecord ( const QVariant &  recordId)

Removes the record with the specified id from the project.

Parameters
recordIdId of the record to remove.

◆ removeRecordSet()

void RecordsController::removeRecordSet ( const QString &  name)

Removes the record set with the specified name from the project, including all records.

Parameters
nameName of the record set to remove.

◆ reparentRecord()

void RecordsController::reparentRecord ( const QVariant &  recordId,
const QVariant &  newParentId 
)

Changes the parent of the record with the specified id.

Exceptions
std::out_of_rangeif the record to reparent could not be found.
See also
hasRecord for checking whether the record to reparent exists.
Parameters
recordIdId of the record to change the parent of.
newParentIdId of the new parent of the record.

◆ revertRecord()

void RecordsController::revertRecord ( const QVariant &  recordId)

Reverts all fields of the record with the specified id to their inherited or default value.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
recordIdId of the record to revert.

◆ setReadOnly()

void RecordsController::setReadOnly ( const QVariant &  recordId,
const bool  readOnly 
)

Marks the record with the specified id as read-only or not, preventing it from being edited, reparented or removed.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
recordIdId of the record to make read-only or not.
readOnlyWhether to make the record read-only or not.

◆ setRecordSets()

void RecordsController::setRecordSets ( RecordSetList &  model)

Uses the specified list of record sets as model for this controller.

Exceptions
std::out_of_rangeif the record id type of the project is invalid.
Parameters
modelNew list of record sets to use as model for this controller.

◆ updateRecord()

void RecordsController::updateRecord ( const QVariant  oldId,
const QVariant  newId,
const QString  newDisplayName,
const QString  newEditorIconFieldId,
const QStringList &  newFieldIds,
const QString &  newRecordSetName 
)

Updates the properties of the specified record.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
oldIdCurrent id of the record to update.
newIdNew id of the record to update.
newDisplayNameNew display name of the record to update.
newEditorIconFieldIdNew id of the field to use as editor icon for the record to update.
newFieldIdsIds of the new fields of the record to update.
newRecordSetNameName of the new record set the record should belong to.

◆ updateRecordFieldValue()

void RecordsController::updateRecordFieldValue ( const QVariant &  recordId,
const QString &  fieldId,
const QVariant &  fieldValue 
)

Updates the current value of a record field.

Exceptions
std::out_of_rangeif the record with the specified id could not be found.
See also
hasRecord for checking whether a record with the specified id exists.
Parameters
recordIdId of the record to update the field value of.
fieldIdId of the field to update the value of.
fieldValueNew value of the field to update.

The documentation for this class was generated from the following files: