1 #ifndef CSV_WORLD_TABLE_H
2 #define CSV_WORLD_TABLE_H
3 
4 #include <vector>
5 #include <string>
6 
7 #include <QEvent>
8 
9 #include "../../model/filter/node.hpp"
10 #include "../../model/world/columnbase.hpp"
11 #include "../../model/world/universalid.hpp"
12 #include "dragrecordtable.hpp"
13 
14 class QAction;
15 
16 namespace CSMDoc
17 {
18     class Document;
19 }
20 
21 namespace CSMWorld
22 {
23     class IdTableProxyModel;
24     class IdTableBase;
25     class CommandDispatcher;
26 }
27 
28 namespace CSMPrefs
29 {
30     class Setting;
31 }
32 
33 namespace CSVWorld
34 {
35     class CommandDelegate;
36     class TableEditIdAction;
37 
38     ///< Table widget
39     class Table : public DragRecordTable
40     {
41             Q_OBJECT
42 
43             enum DoubleClickAction
44             {
45                 Action_None,
46                 Action_InPlaceEdit,
47                 Action_EditRecord,
48                 Action_View,
49                 Action_Revert,
50                 Action_Delete,
51                 Action_EditRecordAndClose,
52                 Action_ViewAndClose
53             };
54 
55             std::vector<CommandDelegate *> mDelegates;
56             QAction *mEditAction;
57             QAction *mCreateAction;
58             QAction *mCloneAction;
59             QAction *mTouchAction;
60             QAction *mRevertAction;
61             QAction *mDeleteAction;
62             QAction *mMoveUpAction;
63             QAction *mMoveDownAction;
64             QAction *mViewAction;
65             QAction *mPreviewAction;
66             QAction *mExtendedDeleteAction;
67             QAction *mExtendedRevertAction;
68             QAction *mHelpAction;
69             TableEditIdAction *mEditIdAction;
70             CSMWorld::IdTableProxyModel *mProxyModel;
71             CSMWorld::IdTableBase *mModel;
72             int mRecordStatusDisplay;
73             CSMWorld::CommandDispatcher *mDispatcher;
74             std::map<Qt::KeyboardModifiers, DoubleClickAction> mDoubleClickActions;
75             bool mJumpToAddedRecord;
76             bool mUnselectAfterJump;
77 
78         private:
79 
80             void contextMenuEvent (QContextMenuEvent *event) override;
81 
82             void mouseMoveEvent(QMouseEvent *event) override;
83 
84         protected:
85 
86             void mouseDoubleClickEvent (QMouseEvent *event) override;
87 
88         public:
89 
90             Table (const CSMWorld::UniversalId& id, bool createAndDelete,
91                 bool sorting, CSMDoc::Document& document);
92             ///< \param createAndDelete Allow creation and deletion of records.
93             /// \param sorting Allow changing order of rows in the view via column headers.
94 
95             virtual void setEditLock (bool locked);
96 
97             CSMWorld::UniversalId getUniversalId (int row) const;
98 
99             std::vector<std::string> getColumnsWithDisplay(CSMWorld::ColumnBase::Display display) const;
100 
101             std::vector<std::string> getSelectedIds() const;
102 
103             std::vector<CSMWorld::UniversalId> getDraggedRecords() const override;
104 
105         signals:
106 
107             void editRequest (const CSMWorld::UniversalId& id, const std::string& hint);
108 
109             void selectionSizeChanged (int size);
110 
111             void tableSizeChanged (int size, int deleted, int modified);
112             ///< \param size Number of not deleted records
113             /// \param deleted Number of deleted records
114             /// \param modified Number of added and modified records
115 
116             void createRequest();
117 
118             void cloneRequest(const CSMWorld::UniversalId&);
119 
120             void touchRequest(const std::vector<CSMWorld::UniversalId>& ids);
121 
122             void closeRequest();
123 
124             void extendedDeleteConfigRequest(const std::vector<std::string> &selectedIds);
125 
126             void extendedRevertConfigRequest(const std::vector<std::string> &selectedIds);
127 
128         private slots:
129 
130             void editCell();
131 
132             static void openHelp();
133 
134             void editRecord();
135 
136             void cloneRecord();
137 
138             void touchRecord();
139 
140             void moveUpRecord();
141 
142             void moveDownRecord();
143 
144             void moveRecords(QDropEvent *event);
145 
146             void viewRecord();
147 
148             void previewRecord();
149 
150             void executeExtendedDelete();
151 
152             void executeExtendedRevert();
153 
154         public slots:
155 
156             void settingChanged (const CSMPrefs::Setting *setting);
157 
158             void tableSizeUpdate();
159 
160             void selectionSizeUpdate();
161 
162             void requestFocus (const std::string& id);
163 
164             void recordFilterChanged (std::shared_ptr<CSMFilter::Node> filter);
165 
166             void rowAdded(const std::string &id);
167     };
168 }
169 
170 #endif
171