Quark  0.1
QuadTreeModel.h++
Go to the documentation of this file.
1 
2 #ifndef __libquark_gui_QuadTreeModel_hxx
3 #define __libquark_gui_QuadTreeModel_hxx
4 
5 #include <QDebug>
6 #include <QList>
7 #include <QPoint>
8 #include <QRect>
9 
10 #include <quark/Algorithms.h++>
12 
13 namespace quark {
14 namespace gui {
15 
28 template<class T> class QuadTreeModel : public QuadTreeModelBase
29 {
30  public:
31 
39  QuadTreeModel(const QRect &region, uint maxItemsPerQuad = 1);
40 
42  virtual ~QuadTreeModel();
43 
45  void clear();
46 
54  bool addItem(T *item);
55 
63  bool removeItem(T *item);
64 
71  void updateItem(T *item);
72 
80  T* itemAtLocation(const QPoint &location) const;
81 
89  QList<T *> itemsInRegion(const QRect &region) const;
90 
92  QList<T *> items() const;
93 
94  private:
95 
96  struct Node;
97 
98  bool addItemToNode(Node *node, T *item);
99  bool removeItemFromNode(Node *node, T *item);
100  void findItemsInRegionAtNode(Node *node, const QRect &region,
101  QList<T *> &list) const;
102  T *itemAtPointInNode(Node *node, const QPoint &point) const;
103 
104  static bool lessThan(const T *a, const T *b);
105 
106  Node *_root;
107  QList<T *> _items;
108 };
109 
110 #include <quark/QuadTreeModelImpl.h++>
111 
112 } // namespace gui
113 } // namespace quark
114 
115 #endif __libquark_gui_QuadTreeModel_hxx
QuadTreeModel(const QRect &region, uint maxItemsPerQuad=1)
Constructs a new QuadTreeModel with the given range and density.
A non-parameterized abstract base class for quad-tree models.
Definition: QuadTreeModelBase.h++:17
T * itemAtLocation(const QPoint &location) const
Returns the item at the given location in the model.
virtual ~QuadTreeModel()
Destructor.
bool removeItem(T *item)
Removes an item from the model.
QList< T * > itemsInRegion(const QRect &region) const
Returns a list of all items in the model that are within the given region.
QRect region() const
Returns the region covered by this model.
Definition: QuadTreeModelBase.h++:27
void updateItem(T *item)
Notifies the model that the given item has changed.
void clear()
Removes all items from the model.
Definition: BarChartView.h++:6
bool addItem(T *item)
Adds an item to the model.
An abstract implementation of a quad-tree data model.
Definition: QuadTreeModel.h++:28
QList< T * > items() const
Returns all of the items in the model.