src/model.h

changeset 1440
265b2e95a8e8
parent 1377
0b9a946002be
equal deleted inserted replaced
1436:241d3e452b32 1440:265b2e95a8e8
71 }; 71 };
72 72
73 /* 73 /*
74 * This class represents a LDraw model, consisting of a vector of objects. It manages LDObject ownership. 74 * This class represents a LDraw model, consisting of a vector of objects. It manages LDObject ownership.
75 */ 75 */
76 class Model : public QAbstractListModel 76 class Model : public QObject
77 { 77 {
78 Q_OBJECT 78 Q_OBJECT
79 79
80 public: 80 public:
81 Model(class DocumentManager* manager); 81 Model(class DocumentManager* manager);
102 QVector<LDObject*>::iterator end(); 102 QVector<LDObject*>::iterator end();
103 QModelIndex indexOf(LDObject* object) const; 103 QModelIndex indexOf(LDObject* object) const;
104 bool isEmpty() const; 104 bool isEmpty() const;
105 class DocumentManager* documentManager() const; 105 class DocumentManager* documentManager() const;
106 IndexGenerator indices() const; 106 IndexGenerator indices() const;
107 LDObject* lookup(const QModelIndex& index) const; 107 LDObject* lookup(const Uuid& index) const;
108 QColor pickingColorForObject(const QModelIndex& objectIndex) const; 108 QColor pickingColorForObject(const Uuid& id) const;
109 QModelIndex objectByPickingColor(const QColor& color) const; 109 QModelIndex objectByPickingColor(const QColor& color) const;
110 Winding winding() const; 110 Winding winding() const;
111 void setWinding(Winding winding); 111 void setWinding(Winding winding);
112 112 int rowOf(const Uuid& id);
113 bool moveRows(
114 const QModelIndex& sourceParent,
115 int sourceRow,
116 int count,
117 const QModelIndex& destinationParent,
118 int destinationChild
119 ) override;
120
121 int rowCount(const QModelIndex& parent) const override;
122 QVariant data(const QModelIndex& index, int role) const override;
123 113
124 signals: 114 signals:
125 void objectAdded(const QModelIndex& object); 115 void objectAdded(const Uuid& object);
126 void aboutToRemoveObject(const QModelIndex& index); 116 void aboutToRemoveObject(const Uuid& index, const LDObject* object);
127 void objectModified(LDObject* object); 117 void objectModified(LDObject* object);
128 void windingChanged(Winding newWinding); 118 void windingChanged(Winding newWinding);
129 void modelChanged(); 119 void modelChanged();
130 120
131 protected: 121 protected:
132 template<typename T, typename... Args> T* constructObject(Args&& ...args); 122 template<typename T, typename... Args> T* constructObject(Args&& ...args);
133 123
134 QVector<LDObject*> _objects; 124 QVector<LDObject*> _objects;
125 QMap<Uuid, LDObject *> _objectsById;
135 QMap<LDObject*, QRgb> pickingColors; 126 QMap<LDObject*, QRgb> pickingColors;
136 QRgb pickingColorCursor = 0x000001; 127 QRgb pickingColorCursor = 0x000001;
137 class DocumentManager* _manager; 128 class DocumentManager* _manager;
138 mutable int _triangleCount = 0; 129 mutable int _triangleCount = 0;
139 mutable bool _needsTriangleRecount; 130 mutable bool _needsTriangleRecount;

mercurial