32 tile->setParentItem(
this);
36 setFlag(QGraphicsItem::ItemSendsGeometryChanges,
true);
46 m_rect = mapRectFromParent(m_parent_rect);
52 std::list<QPolygonF> polygons;
53 for (
auto row : m_tiles) {
54 for (
Tile* tile : row) {
55 polygons.push_back(mapToParent(tile->GetPolygon()));
61 QVariant RegularTiling::itemChange(GraphicsItemChange change,
const QVariant &value)
63 if (change == QGraphicsItem::ItemTransformHasChanged || change == QGraphicsItem::ItemRotationHasChanged) {
64 m_rect = mapRectFromParent(m_parent_rect);
68 return QGraphicsItem::itemChange(change, value);
71 void RegularTiling::ResizeTileRow(std::list<Tile*> &row)
73 auto tile_rect = [
this] (Tile *tile) -> QRectF {
return mapRectFromItem(tile, tile->GetPolygon().boundingRect()); };
76 while (tile_rect(row.front()).right() > m_rect.left()) {
77 row.push_front(row.front()->Left());
79 while(tile_rect(row.back()).left() < m_rect.right()) {
80 row.push_back(row.back()->Right());
84 while(tile_rect(row.front()).right() < m_rect.left()) {
88 while (tile_rect(row.back()).left() > m_rect.right()) {
93 assert( !row.empty() &&
"Number of tiles on a row should stay greater or equal to 1");
96 void RegularTiling::ResizeTiles()
98 auto tile_rect = [
this] (Tile *tile) -> QRectF {
return mapRectFromItem(tile, tile->GetPolygon().boundingRect()); };
99 auto row_rect = [
this, tile_rect] (
const std::list<Tile*> &row) -> QRectF { QRectF rect = tile_rect(row.front());
for (Tile *tile : row) rect.united(tile_rect(tile));
return rect; };
100 auto delete_row = [] (Tile *tile) ->
bool {
delete tile;
return true; };
102 for (
auto &row : m_tiles) {
107 while (row_rect(m_tiles.front()).bottom() > m_rect.top()) {
108 m_tiles.push_front({ m_tiles.front().front()->Up() });
109 ResizeTileRow(m_tiles.front());
111 while(row_rect(m_tiles.back()).top() < m_rect.bottom()) {
112 m_tiles.push_back({ m_tiles.back().front()->Down() });
113 ResizeTileRow(m_tiles.back());
117 while(row_rect(m_tiles.front()).bottom() < m_rect.top()) {
118 m_tiles.front().remove_if(delete_row);
121 while (row_rect(m_tiles.back()).top() > m_rect.bottom()) {
122 m_tiles.back().remove_if(delete_row);
126 assert( !m_tiles.empty() &&
"Number of tile rows should stay greater or equal to 1");
RegularTiling(Tile *seed, const QRectF &rect, QGraphicsItem *parent=nullptr)
Constructor.
Namespace for SimPT tissue editor package.
void SetRectangle(const QRectF &rect)
The rectangle the tiling should overlay.
Interface for RegularTiling.
std::list< QPolygonF > GetPolygons() const
Get the polygons associated with this tiling.
see the online Qt documentation
Abstract base class for cell pattern tiles.
virtual ~RegularTiling()
Destructor.
see the online Qt documentation