Tome
A generic data editor for games supporting arbitrary input and output formats.
recordtreewidget.h
1 #ifndef RECORDTREEWIDGET_H
2 #define RECORDTREEWIDGET_H
3 
4 #include <QContextMenuEvent>
5 #include <QMimeData>
6 #include <QStack>
7 #include <QTreeWidget>
8 
9 #include "../Model/recordlist.h"
10 
11 namespace Tome
12 {
13  class FacetsController;
14  class FieldDefinitionsController;
15  class ProjectController;
16  class RecordsController;
17  class RecordTreeWidgetItem;
18  class SettingsController;
19 
23  class RecordTreeWidget : public QTreeWidget
24  {
25  Q_OBJECT
26 
27  public:
36  RecordTreeWidget(RecordsController& recordsController,
37  FacetsController& facetsController,
38  FieldDefinitionsController& fieldDefinitionsController,
39  ProjectController& projectController,
40  SettingsController& settingsController);
41 
48  void addRecord(const QVariant& id, const QString& displayName, const QVariant& parentId);
49 
54  QVariant getSelectedRecordId() const;
55 
60  QVariantList getSelectedRecordIds() const;
61 
65  void navigateForward();
66 
70  void navigateBackward();
71 
81  void updateRecord(const QVariant& oldId,
82  const QString& oldDisplayName,
83  const QString& oldEditorIconFieldId,
84  const QVariant& newId,
85  const QString& newDisplayName,
86  const QString& newEditorIconFieldId);
87 
93  void selectRecord(const QVariant& id, const bool addToHistory);
94 
99  void setContextMenuActions(QList<QAction*> actions);
100 
105  void setRecords(const RecordList& records);
106 
111  void removeRecord(const QVariant& id);
112 
113  signals:
121  void progressChanged(const QString title, const QString text, const int currentValue, const int maximumValue) const;
122 
128  void recordReparented(const QVariant& recordId, const QVariant& newParentId);
129 
130  protected:
135  void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
136 
145  bool dropMimeData(QTreeWidgetItem* parent, int index, const QMimeData* data, Qt::DropAction action) Q_DECL_OVERRIDE;
146 
151  void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
152 
153  private slots:
154  void onCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
155 
156  private:
157  FacetsController& facetsController;
158  FieldDefinitionsController& fieldDefinitionsController;
159  ProjectController& projectController;
160  RecordsController& recordsController;
161  SettingsController& settingsController;
162 
163  QStack<QVariant> selectedRecordUndoStack;
164  QStack<QVariant> selectedRecordRedoStack;
165  bool navigating;
166 
167  QList<QAction*> contextMenuActions;
168 
169  RecordTreeWidgetItem* getRecordItem(const QVariant& id);
170  RecordTreeWidgetItem* getSelectedRecordItem() const;
171  QList<RecordTreeWidgetItem*> getSelectedRecordItems() const;
172  void sort();
173  void updateRecordItem(RecordTreeWidgetItem* recordTreeItem);
174  void updateRecordItemRecursively(RecordTreeWidgetItem* recordTreeItem);
175  };
176 }
177 
178 
179 #endif // RECORDTREEWIDGET_H
Definition: commandlineoptions.h:6
Controller for adding, updating and removing field definitions.
Definition: fielddefinitionscontroller.h:15
Controller for adding, updating and removing records.
Definition: recordscontroller.h:21
Controller for accessing user settings.
Definition: settingscontroller.h:12
Shows the record of hierarchy and allows selecting one or more records.
Definition: recordtreewidget.h:23
void selectRecord(const QVariant &id, const bool addToHistory)
Selects the specified record in the hierarchy.
Definition: recordtreewidget.cpp:267
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE
Selects a record in the hierarchy, or clears the current selection.
Definition: recordtreewidget.cpp:407
void addRecord(const QVariant &id, const QString &displayName, const QVariant &parentId)
Adds the specified record to show in the hierarchy.
Definition: recordtreewidget.cpp:44
bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action) Q_DECL_OVERRIDE
Checks whether to reparent a record in the hierarchy by drag & drop.
Definition: recordtreewidget.cpp:370
void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE
Shows the context menu for the current set of selected records.
Definition: recordtreewidget.cpp:358
RecordTreeWidget(RecordsController &recordsController, FacetsController &facetsController, FieldDefinitionsController &fieldDefinitionsController, ProjectController &projectController, SettingsController &settingsController)
Constructs a new widget that shows the record of hierarchy and allows selecting one or more records...
Definition: recordtreewidget.cpp:21
void navigateBackward()
Selects the previous record in the history of selected records.
Definition: recordtreewidget.cpp:133
void navigateForward()
Selects the next record in the history of selected records.
Definition: recordtreewidget.cpp:119
void progressChanged(const QString title, const QString text, const int currentValue, const int maximumValue) const
Progress of the current record operation has changed.
Selectable item in the record hierarchy.
Definition: recordtreewidgetitem.h:11
void recordReparented(const QVariant &recordId, const QVariant &newParentId)
A record has been reparented to another record in the hierarchy.
QVariant getSelectedRecordId() const
Gets the id of the currently selected record.
Definition: recordtreewidget.cpp:65
Controller for validating type facets.
Definition: facetscontroller.h:16
QVariantList getSelectedRecordIds() const
Gets a list of ids of all currently selected records.
Definition: recordtreewidget.cpp:77
Controller for creating, loading and saving projects.
Definition: projectcontroller.h:22
void updateRecord(const QVariant &oldId, const QString &oldDisplayName, const QString &oldEditorIconFieldId, const QVariant &newId, const QString &newDisplayName, const QString &newEditorIconFieldId)
Updates the specified record in the hierarchy.
Definition: recordtreewidget.cpp:147
void removeRecord(const QVariant &id)
Removes the specified record from the hierarchy.
Definition: recordtreewidget.cpp:340
void setContextMenuActions(QList< QAction *> actions)
Sets the list of actions to show in the context menu of the selected records.
Definition: recordtreewidget.cpp:278
void setRecords(const RecordList &records)
Sets the records to show in the hierarchy.
Definition: recordtreewidget.cpp:283