Quark  0.1
QuadTreeModel< T > Class Template Reference

An abstract implementation of a quad-tree data model. More...

#include <QuadTreeModel.h++>

Inheritance diagram for QuadTreeModel< T >:

Signals

void dataChanged ()
 Emitted when the model has changed in some significant way. More...
 
void itemAdded (const QPoint &location)
 Emitted when a new item has been added to the model. More...
 
void itemModified (const QPoint &location)
 Emitted when an item in the model has changed. More...
 
void itemRemoved (const QPoint &location)
 Emitted when an item has been removed from the model. More...
 

Public Member Functions

 QuadTreeModel (const QRect &region, uint maxItemsPerQuad=1)
 Constructs a new QuadTreeModel with the given range and density. More...
 
virtual ~QuadTreeModel ()
 Destructor. More...
 
void clear ()
 Removes all items from the model. More...
 
bool addItem (T *item)
 Adds an item to the model. More...
 
bool removeItem (T *item)
 Removes an item from the model. More...
 
void updateItem (T *item)
 Notifies the model that the given item has changed. More...
 
T * itemAtLocation (const QPoint &location) const
 Returns the item at the given location in the model. More...
 
QList< T * > itemsInRegion (const QRect &region) const
 Returns a list of all items in the model that are within the given region. More...
 
QList< T * > items () const
 Returns all of the items in the model. More...
 
QRect region () const
 Returns the region covered by this model. More...
 
uint itemCount () const
 Returns the number of items in the model. More...
 
bool isEmpty () const
 Tests if the model is empty. More...
 
bool setVisibleRegion (const QRect &visibleRegion)
 Sets the visible region for the model. More...
 
QRect visibleRegion () const
 Returns the current visible region. More...
 

Protected Attributes

uint _maxItemsPerQuad
 
QRect _region
 
QRect _visibleRegion
 
uint _itemCount
 

Detailed Description

template<class T>
class quark::gui::QuadTreeModel< T >

An abstract implementation of a quad-tree data model.

A quad-tree is a data structure that represents a collection of objects which have locations within a 2-D plane. It provides fast lookup of items by coordinate or by rectangular region. Subclasses must implement locationForItem() to return the location (that is, the 2-D coordinates) of a data item.

Template Parameters
TThe type of the objects contained in this model. This type must define a location() method that takes no arguments and returns a QPoint.
Author
Mark Lindner

Constructor & Destructor Documentation

◆ QuadTreeModel()

QuadTreeModel ( const QRect &  region,
uint  maxItemsPerQuad = 1 
)

Constructs a new QuadTreeModel with the given range and density.

Parameters
regionThe region covered by this model.
maxItemsPerQuadThe maximum number of items that a quad can contain before it is subdivided.

◆ ~QuadTreeModel()

virtual ~QuadTreeModel ( )
virtual

Destructor.

Member Function Documentation

◆ addItem()

bool addItem ( T *  item)

Adds an item to the model.

Parameters
itemThe item to add.
Returns
true if the item was added, or false if there is already an item in the model at the location of this item.

◆ clear()

void clear ( )

Removes all items from the model.

◆ dataChanged

void dataChanged ( )
signalinherited

Emitted when the model has changed in some significant way.

◆ isEmpty()

bool isEmpty ( ) const
inlineinherited

Tests if the model is empty.

◆ itemAdded

void itemAdded ( const QPoint &  location)
signalinherited

Emitted when a new item has been added to the model.

Parameters
locationThe item's location.

◆ itemAtLocation()

T* itemAtLocation ( const QPoint &  location) const

Returns the item at the given location in the model.

Parameters
pointThe location.
Returns
The item at the given location, or NULL if there is none.

◆ itemCount()

uint itemCount ( ) const
inlineinherited

Returns the number of items in the model.

◆ itemModified

void itemModified ( const QPoint &  location)
signalinherited

Emitted when an item in the model has changed.

Parameters
locationThe item's location.

◆ itemRemoved

void itemRemoved ( const QPoint &  location)
signalinherited

Emitted when an item has been removed from the model.

Parameters
locationThe item's location.

◆ items()

QList<T *> items ( ) const

Returns all of the items in the model.

◆ itemsInRegion()

QList<T *> itemsInRegion ( const QRect &  region) const

Returns a list of all items in the model that are within the given region.

Parameters
regionThe region.
Returns
The (possibly empty) list of items in the region.

◆ region()

QRect region ( ) const
inlineinherited

Returns the region covered by this model.

◆ removeItem()

bool removeItem ( T *  item)

Removes an item from the model.

Parameters
itemThe item to remove.
Returns
true if the item was removed, or false if the model does not contain this item.

◆ setVisibleRegion()

bool setVisibleRegion ( const QRect &  visibleRegion)
inherited

Sets the visible region for the model.

When a data item is added to, removed from, or changed in the model, the corresponding notification signal will only be emitted if that item's location was within the visible region.

Parameters
Thenew visible region.
Returns
true on success, or false if the specified region is neither empty nor contained within the model's region.

◆ updateItem()

void updateItem ( T *  item)

Notifies the model that the given item has changed.

The model will emit the appropriate signal to notifiy views of the change.

Parameters
itemThe item that changed.

◆ visibleRegion()

QRect visibleRegion ( ) const
inlineinherited

Returns the current visible region.

Member Data Documentation

◆ _itemCount

uint _itemCount
protectedinherited

◆ _maxItemsPerQuad

uint _maxItemsPerQuad
protectedinherited

◆ _region

QRect _region
protectedinherited

◆ _visibleRegion

QRect _visibleRegion
protectedinherited

The documentation for this class was generated from the following file: