1 /* 2 * OpenClonk, http://www.openclonk.org 3 * 4 * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/ 5 * Copyright (c) 2013, The OpenClonk Team and contributors 6 * 7 * Distributed under the terms of the ISC license; see accompanying file 8 * "COPYING" for details. 9 * 10 * "Clonk" is a registered trademark of Matthes Bender, used with permission. 11 * See accompanying file "TRADEMARK" for details. 12 * 13 * To redistribute this file separately, substitute the full license texts 14 * for the above references. 15 */ 16 17 /* List of loaded definitions */ 18 19 #ifndef INC_C4ConsoleQtDefinitionListViewer 20 #define INC_C4ConsoleQtDefinitionListViewer 21 #ifdef WITH_QT_EDITOR 22 23 #include "C4Include.h" // needed for automoc 24 #include "editor/C4ConsoleGUI.h" // for glew.h 25 #include "script/C4Value.h" 26 #include "editor/C4ConsoleQt.h" 27 28 // Prop list view implemented as a model view 29 class C4ConsoleQtDefinitionListModel : public QAbstractItemModel 30 { 31 Q_OBJECT 32 33 mutable int32_t last_row_count{0}; 34 35 // Tree structure of definition list 36 struct DefListNode 37 { 38 std::vector<std::unique_ptr<DefListNode> > items; 39 C4Def *def{nullptr}; 40 StdCopyStrBuf name, filename; 41 int32_t idx{0}; 42 DefListNode *parent{nullptr}; 43 44 DefListNode() = default; 45 void SortByName(); // sort self and children 46 }; 47 std::unique_ptr<DefListNode> root; 48 49 public: 50 C4ConsoleQtDefinitionListModel(); 51 ~C4ConsoleQtDefinitionListModel() override; 52 53 // Refresh definition list (on initialization or e.g. after ReloadDef) 54 void ReInit(); 55 void EnsureInit(); 56 void OnItemRemoved(class C4Def *def); 57 58 // Callback from EditCursor when selection was changed e.g. from property window 59 void SetSelection(C4Def *new_selection); 60 61 class C4Def *GetDefByModelIndex(const QModelIndex &idx); 62 const char *GetNameByModelIndex(const QModelIndex &idx); 63 QModelIndex GetModelIndexByItem(class C4Def *def) const; 64 65 public: 66 int rowCount(const QModelIndex & parent = QModelIndex()) const override; 67 int columnCount(const QModelIndex & parent = QModelIndex()) const override; 68 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; 69 QModelIndex index(int row, int column, const QModelIndex &parent) const override; 70 QModelIndex parent(const QModelIndex &index) const override; 71 72 // signal callback when user changed selection in dialogue 73 void OnSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected); 74 }; 75 76 #endif // WITH_QT_EDITOR 77 #endif // INC_C4ConsoleQtObjectListViewer 78