Tome
A generic data editor for games supporting arbitrary input and output formats.
recordscontroller.h
1 #ifndef RECORDSCONTROLLER_H
2 #define RECORDSCONTROLLER_H
3 
4 #include <random>
5 
6 #include <QStringList>
7 
8 #include "../Model/recordsetlist.h"
9 
10 
11 namespace Tome
12 {
13  class FieldDefinition;
14  class FieldDefinitionsController;
15  class ProjectController;
16  class TypesController;
17 
21  class RecordsController : public QObject
22  {
23  Q_OBJECT
24 
25  public:
32  RecordsController(const FieldDefinitionsController& fieldDefinitionsController,
33  const ProjectController& projectController,
34  const TypesController& typesController);
35 
49  const Record addRecord(const QVariant& id,
50  const QString& displayName,
51  const QString& editorIconFieldId,
52  const QStringList& fieldIds,
53  const QString& recordSetName);
54 
59  void addRecordSet(const RecordSet& recordSet);
60 
65  const QString computeRecordsHash() const;
66 
76  const Record duplicateRecord(const QVariant& existingRecordId, const QVariant& newRecordId);
77 
88  const RecordList getAncestors(const QVariant& id) const;
89 
95  const RecordList getChildren(const QVariant& id) const;
96 
102  const RecordList getDescendents(const QVariant& id) const;
103 
110  const QVariant getInheritedFieldValue(const QVariant& id, const QString& fieldId) const;
111 
117  const RecordFieldValueMap getInheritedFieldValues(const QVariant& id) const;
118 
129  const QVariant getParentId(const QVariant& id) const;
130 
135  const RecordSetList& getRecordSets() const;
136 
147  const Record& getRecord(const QVariant& id) const;
148 
153  const RecordList getRecords() const;
154 
159  const QVariantList getRecordIds() const;
160 
171  const QString getRecordEditorIconFieldId(const QVariant& id) const;
172 
177  const QStringList getRecordNames() const;
178 
183  const QStringList getRecordSetNames() const;
184 
195  const RecordFieldValueMap getRecordFieldValues(const QVariant& id) const;
196 
202  const QVariant getRootRecordId(const QVariant& id) const;
203 
209  bool hasRecord(const QVariant& id) const;
210 
216  bool haveTheSameParent(const QVariantList ids) const;
217 
224  bool isAncestorOf(const QVariant& possibleAncestor, const QVariant& recordId) const;
225 
230  void removeRecord(const QVariant& recordId);
231 
236  void removeRecordSet(const QString& name);
237 
247  void revertRecord(const QVariant& recordId);
248 
259  void reparentRecord(const QVariant& recordId, const QVariant& newParentId);
260 
271  void setReadOnly(const QVariant& recordId, const bool readOnly);
272 
280  void setRecordSets(RecordSetList& model);
281 
296  void updateRecord(const QVariant oldId,
297  const QVariant newId,
298  const QString newDisplayName,
299  const QString newEditorIconFieldId,
300  const QStringList& newFieldIds,
301  const QString& newRecordSetName);
302 
314  void updateRecordFieldValue(const QVariant& recordId, const QString& fieldId, const QVariant& fieldValue);
315 
316  signals:
324  void progressChanged(const QString title, const QString text, const int currentValue, const int maximumValue);
325 
332  void recordAdded(const QVariant& recordId, const QString& recordDisplayName, const QVariant& parentId);
333 
338  void recordFieldsChanged(const QVariant& recordId);
339 
344  void recordRemoved(const QVariant& recordId);
345 
352  void recordReparented(const QVariant& recordId, const QVariant& oldParentId, const QVariant& newParentId);
353 
363  void recordUpdated(const QVariant& oldId,
364  const QString& oldDisplayName,
365  const QString& oldEditorIconFieldId,
366  const QVariant& newId,
367  const QString& newDisplayName,
368  const QString& newEditorIconFieldId);
369 
373  void recordSetsChanged();
374 
375  private slots:
376  void onFieldAdded(const Tome::FieldDefinition& fieldDefinition);
377  void onFieldRemoved(const Tome::FieldDefinition& fieldDefinition);
378  void onFieldUpdated(const Tome::FieldDefinition& oldFieldDefinition, const Tome::FieldDefinition& newFieldDefinition);
379 
380  private:
381  RecordSetList* model;
382 
383  const FieldDefinitionsController& fieldDefinitionsController;
384  const ProjectController& projectController;
385  const TypesController& typesController;
386 
387  std::mt19937 recordIdGenerator;
388  std::uniform_int_distribution<int> recordIdDistribution;
389 
390  void addRecordField(const QVariant& recordId, const QString& fieldId);
391  int generateIntegerId();
392  const QString generateUuid() const;
393  Record* getRecordById(const QVariant& id) const;
394  void moveFieldToComponent(const QString& fieldId, const QString& oldComponent, const QString& newComponent);
395  void moveRecordToSet(const QVariant& recordId, const QString& recordSetName);
396  void removeRecordField(const QVariant& recordId, const QString& fieldId);
397  void renameRecordField(const QString oldFieldId, const QString newFieldId);
398  QVariant revertFieldValue(const QVariant& recordId, const QString& fieldId);
399  void updateRecordReferences(const QVariant oldReference, const QVariant newReference);
400  void verifyRecordIds();
401  void verifyRecordIntegerIds();
402  void verifyRecordStringIds();
403  void verifyRecordUuids();
404  };
405 }
406 
407 #endif // RECORDSCONTROLLER_H
const RecordList getChildren(const QVariant &id) const
Gets the list of all records that have the record with the specified id as parent.
Definition: recordscontroller.cpp:261
Definition: commandlineoptions.h:6
void reparentRecord(const QVariant &recordId, const QVariant &newParentId)
Changes the parent of the record with the specified id.
Definition: recordscontroller.cpp:623
Controller for adding, updating and removing field definitions.
Definition: fielddefinitionscontroller.h:15
Controller for adding, updating and removing records.
Definition: recordscontroller.h:21
void recordReparented(const QVariant &recordId, const QVariant &oldParentId, const QVariant &newParentId)
The parent of a record has changed.
bool haveTheSameParent(const QVariantList ids) const
Checks whether all records with the specified ids have the same parent in the record tree...
Definition: recordscontroller.cpp:495
const QVariantList getRecordIds() const
Gets a list of the ids of all records in the project.
Definition: recordscontroller.cpp:386
void recordFieldsChanged(const QVariant &recordId)
A new field has been added to a record, or one of its fields has been updated or removed.
void recordAdded(const QVariant &recordId, const QString &recordDisplayName, const QVariant &parentId)
A new record has been added to the project.
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.
Definition: recordscontroller.cpp:400
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.
Definition: recordscontroller.cpp:283
Named set of Tome records.
Definition: recordset.h:11
bool isAncestorOf(const QVariant &possibleAncestor, const QVariant &recordId) const
Checks whether the first record is an ancestor of the second one.
Definition: recordscontroller.cpp:520
bool hasRecord(const QVariant &id) const
Checks whether the project has a record with the specified id.
Definition: recordscontroller.cpp:475
const RecordList getRecords() const
Gets a list of all records in the project.
Definition: recordscontroller.cpp:369
void revertRecord(const QVariant &recordId)
Reverts all fields of the record with the specified id to their inherited or default value...
Definition: recordscontroller.cpp:598
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.
Definition: recordscontroller.cpp:647
void removeRecordSet(const QString &name)
Removes the record set with the specified name from the project, including all records.
Definition: recordscontroller.cpp:580
Field that can be added to a record to hold data.
Definition: fielddefinition.h:15
const QVariant getParentId(const QVariant &id) const
Gets the id of the parent of the record with the specified id.
Definition: recordscontroller.cpp:354
const QStringList getRecordSetNames() const
Gets a list of the names of all record sets in the project.
Definition: recordscontroller.cpp:438
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...
Definition: recordscontroller.cpp:330
const QStringList getRecordNames() const
Returns a list of the names of all records of this project.
Definition: recordscontroller.cpp:424
Controller for adding, updating and removing custom types.
Definition: typescontroller.h:14
const QVariant getRootRecordId(const QVariant &id) const
Gets the id of the root of the record with the specified id.
Definition: recordscontroller.cpp:469
void progressChanged(const QString title, const QString text, const int currentValue, const int maximumValue)
Progress of the current record operation has changed.
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 paren...
Definition: recordscontroller.cpp:313
const Record & getRecord(const QVariant &id) const
Returns the record with the specified id.
Definition: recordscontroller.cpp:364
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.
const QString computeRecordsHash() const
Computes an MD5 hash of all current record data.
Definition: recordscontroller.cpp:123
void updateRecordFieldValue(const QVariant &recordId, const QString &fieldId, const QVariant &fieldValue)
Updates the current value of a record field.
Definition: recordscontroller.cpp:737
Data record that combines the values of various fields.
Definition: record.h:16
void setRecordSets(RecordSetList &model)
Uses the specified list of record sets as model for this controller.
Definition: recordscontroller.cpp:640
const Record duplicateRecord(const QVariant &existingRecordId, const QVariant &newRecordId)
Duplicats the record with the specified id, including all of its field values.
Definition: recordscontroller.cpp:187
void addRecordSet(const RecordSet &recordSet)
Adds the passed record set to the project.
Definition: recordscontroller.cpp:114
Controller for creating, loading and saving projects.
Definition: projectcontroller.h:22
const RecordSetList & getRecordSets() const
Gets a list of all record sets in the project.
Definition: recordscontroller.cpp:359
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.
Definition: recordscontroller.cpp:45
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...
Definition: recordscontroller.cpp:634
RecordsController(const FieldDefinitionsController &fieldDefinitionsController, const ProjectController &projectController, const TypesController &typesController)
Constructs a new controller for adding, updating and removing records.
Definition: recordscontroller.cpp:23
void recordRemoved(const QVariant &recordId)
A record has been removed from the project.
const RecordFieldValueMap getRecordFieldValues(const QVariant &id) const
Returns the map of actual field values of the record with the specified id, including all inherited v...
Definition: recordscontroller.cpp:451
void recordSetsChanged()
A record set has been added to or removed from the project.
void removeRecord(const QVariant &recordId)
Removes the record with the specified id from the project.
Definition: recordscontroller.cpp:541
const RecordList getAncestors(const QVariant &id) const
Gets the list of all ancestors of the record with the specified id, direct parent first...
Definition: recordscontroller.cpp:243