1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef TrenchBroom_EntityAttributeGridTable 21 #define TrenchBroom_EntityAttributeGridTable 22 23 #include "StringUtils.h" 24 #include "Model/ModelTypes.h" 25 #include "View/ViewTypes.h" 26 27 #include <wx/grid.h> 28 29 #include <vector> 30 31 namespace TrenchBroom { 32 namespace View { 33 class EntityAttributeGridTable : public wxGridTableBase { 34 private: 35 class AttributeRow { 36 public: 37 typedef std::vector<AttributeRow> List; 38 private: 39 String m_name; 40 String m_value; 41 bool m_nameMutable; 42 bool m_valueMutable; 43 String m_tooltip; 44 bool m_default; 45 46 size_t m_maxCount; 47 size_t m_count; 48 bool m_multi; 49 public: 50 AttributeRow(); 51 AttributeRow(const String& name, const String& value, bool nameMutable, bool valueMutable, const String& tooltip, bool i_default, size_t maxCount); 52 53 const String& name() const; 54 const String& value() const; 55 bool nameMutable() const; 56 bool valueMutable() const; 57 const String& tooltip() const; 58 bool isDefault() const; 59 60 void merge(const String& i_valuec, bool nameMutable, bool valueMutable); 61 bool multi() const; 62 bool subset() const; 63 void reset(); 64 }; 65 66 class RowManager { 67 private: 68 AttributeRow::List m_rows; 69 size_t m_defaultRowCount; 70 public: 71 size_t totalRowCount() const; 72 size_t defaultRowCount() const; 73 size_t attributeRowCount() const; 74 75 bool isAttributeRow(size_t rowIndex) const; 76 bool isDefaultRow(size_t rowIndex) const; 77 78 size_t indexOf(const String& name) const; 79 80 const String& name(size_t rowIndex) const; 81 const String& value(size_t rowIndex) const; 82 bool nameMutable(size_t rowIndex) const; 83 bool valueMutable(size_t rowIndex) const; 84 const String& tooltip(size_t rowIndex) const; 85 bool multi(size_t rowIndex) const; 86 bool subset(size_t rowIndex) const; 87 const StringList names(size_t rowIndex, size_t count) const; 88 89 void updateRows(const Model::AttributableNodeList& attributables, bool showDefaultProperties); 90 StringList insertRows(size_t rowIndex, size_t count, const Model::AttributableNodeList& attributables); 91 void deleteRows(size_t rowIndex, size_t count); 92 private: 93 static AttributeRow::List::iterator findRow(AttributeRow::List& rows, const String& name); 94 static AttributeRow::List::const_iterator findRow(const AttributeRow::List& rows, const String& name); 95 96 StringList newAttributeNames(size_t count, const Model::AttributableNodeList& attributables) const; 97 }; 98 99 MapDocumentWPtr m_document; 100 RowManager m_rows; 101 bool m_ignoreUpdates; 102 bool m_showDefaultRows; 103 wxColor m_readonlyCellColor; 104 wxColor m_specialCellColor; 105 public: 106 EntityAttributeGridTable(MapDocumentWPtr document); 107 108 int GetNumberRows(); 109 int GetNumberAttributeRows() const; 110 int GetNumberCols(); 111 112 wxString GetValue(int row, int col); 113 void SetValue(int row, int col, const wxString& value); 114 115 void Clear(); 116 bool InsertRows(size_t pos = 0, size_t numRows = 1); 117 bool AppendRows(size_t numRows = 1); 118 bool DeleteRows(size_t pos = 0, size_t numRows = 1); 119 120 wxString GetColLabelValue(int col); 121 wxGridCellAttr* GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind); 122 123 void update(); 124 String tooltip(wxGridCellCoords cellCoords) const; 125 Model::AttributeName attributeName(int row) const; 126 int rowForName(const Model::AttributeName& name) const; 127 bool canRemove(int row); 128 129 bool showDefaultRows() const; 130 void setShowDefaultRows(bool showDefaultRows); 131 private: 132 void renameAttribute(size_t rowIndex, const String& newName, const Model::AttributableNodeList& attributables); 133 void updateAttribute(size_t rowIndex, const String& newValue, const Model::AttributableNodeList& attributables); 134 135 void notifyRowsUpdated(size_t pos, size_t numRows = 1); 136 void notifyRowsInserted(size_t pos = 0, size_t numRows = 1); 137 void notifyRowsAppended(size_t numRows = 1); 138 void notifyRowsDeleted(size_t pos = 0, size_t numRows = 1); 139 }; 140 } 141 } 142 143 #endif /* defined(TrenchBroom_EntityAttributeGridTable) */ 144