Qt 4.8
Private Functions | Static Private Functions | List of all members
QMdi::MinOverlapPlacer Class Reference

#include <qmdiarea_p.h>

Inheritance diagram for QMdi::MinOverlapPlacer:
QMdi::Placer

Private Functions

QPoint place (const QSize &size, const QList< QRect > &rects, const QRect &domain) const
 Places the rectangle defined by 'size' relative to 'rects' and 'domain' so that it overlaps 'rects' as little as possible and 'domain' as much as possible. More...
 

Static Private Functions

static int accumulatedOverlap (const QRect &source, const QList< QRect > &rects)
 Calculates the accumulated overlap (intersection area) between 'source' and 'rects'. More...
 
static QPoint findBestPlacement (const QRect &domain, const QList< QRect > &rects, QList< QRect > &source)
 Finds among the rectangles in 'source' the best placement. More...
 
static void findMaxOverlappers (const QRect &domain, const QList< QRect > &source, QList< QRect > &result)
 Finds all rectangles in 'source' that overlaps 'domain' by the maximum overlap area between 'domain' and any rectangle in 'source'. More...
 
static QRect findMinOverlapRect (const QList< QRect > &source, const QList< QRect > &rects)
 Finds among 'source' the rectangle with the minimum accumulated overlap with the rectangles in 'rects'. More...
 
static void findNonInsiders (const QRect &domain, QList< QRect > &source, QList< QRect > &result)
 Finds all rectangles in 'source' not completely inside 'domain'. More...
 
static void getCandidatePlacements (const QSize &size, const QList< QRect > &rects, const QRect &domain, QList< QRect > &candidates)
 Gets candidates for the final placement. More...
 

Additional Inherited Members

- Public Functions inherited from QMdi::Placer
virtual ~Placer ()
 

Detailed Description

Definition at line 123 of file qmdiarea_p.h.

Functions

◆ accumulatedOverlap()

int MinOverlapPlacer::accumulatedOverlap ( const QRect source,
const QList< QRect > &  rects 
)
staticprivate

Calculates the accumulated overlap (intersection area) between 'source' and 'rects'.

Warning
This function is not part of the public interface.

Definition at line 434 of file qmdiarea.cpp.

435 {
436  int accOverlap = 0;
437  foreach (const QRect &rect, rects) {
438  QRect intersection = source.intersected(rect);
439  accOverlap += intersection.width() * intersection.height();
440  }
441  return accOverlap;
442 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:481
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ findBestPlacement()

QPoint MinOverlapPlacer::findBestPlacement ( const QRect domain,
const QList< QRect > &  rects,
QList< QRect > &  source 
)
staticprivate

Finds among the rectangles in 'source' the best placement.

Warning
This function is not part of the public interface. Here, 'best' means the placement that overlaps the rectangles in 'rects' as little as possible while at the same time being as much as possible inside 'domain'.

Definition at line 553 of file qmdiarea.cpp.

555 {
556  QList<QRect> nonInsiders;
557  findNonInsiders(domain, source, nonInsiders);
558 
559  if (!source.empty())
560  return findMinOverlapRect(source, rects).topLeft();
561 
562  QList<QRect> maxOverlappers;
563  findMaxOverlappers(domain, nonInsiders, maxOverlappers);
564  return findMinOverlapRect(maxOverlappers, rects).topLeft();
565 }
bool empty() const
This function is provided for STL compatibility.
Definition: qlist.h:304
static void findNonInsiders(const QRect &domain, QList< QRect > &source, QList< QRect > &result)
Finds all rectangles in &#39;source&#39; not completely inside &#39;domain&#39;.
Definition: qmdiarea.cpp:506
static QRect findMinOverlapRect(const QList< QRect > &source, const QList< QRect > &rects)
Finds among &#39;source&#39; the rectangle with the minimum accumulated overlap with the rectangles in &#39;rects...
Definition: qmdiarea.cpp:453
static void findMaxOverlappers(const QRect &domain, const QList< QRect > &source, QList< QRect > &result)
Finds all rectangles in &#39;source&#39; that overlaps &#39;domain&#39; by the maximum overlap area between &#39;domain&#39; ...
Definition: qmdiarea.cpp:527
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ findMaxOverlappers()

void MinOverlapPlacer::findMaxOverlappers ( const QRect domain,
const QList< QRect > &  source,
QList< QRect > &  result 
)
staticprivate

Finds all rectangles in 'source' that overlaps 'domain' by the maximum overlap area between 'domain' and any rectangle in 'source'.

Warning
This function is not part of the public interface. The result is stored in 'result'.

Definition at line 527 of file qmdiarea.cpp.

529 {
530  int maxOverlap = -1;
531  foreach (const QRect &srcRect, source) {
532  QRect intersection = domain.intersected(srcRect);
533  const int overlap = intersection.width() * intersection.height();
534  if (overlap >= maxOverlap || maxOverlap == -1) {
535  if (overlap > maxOverlap) {
536  maxOverlap = overlap;
537  result.clear();
538  }
539  result << srcRect;
540  }
541  }
542 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:481
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ findMinOverlapRect()

QRect MinOverlapPlacer::findMinOverlapRect ( const QList< QRect > &  source,
const QList< QRect > &  rects 
)
staticprivate

Finds among 'source' the rectangle with the minimum accumulated overlap with the rectangles in 'rects'.

Warning
This function is not part of the public interface.

Definition at line 453 of file qmdiarea.cpp.

454 {
455  int minAccOverlap = -1;
456  QRect minAccOverlapRect;
457  foreach (const QRect &srcRect, source) {
458  const int accOverlap = accumulatedOverlap(srcRect, rects);
459  if (accOverlap < minAccOverlap || minAccOverlap == -1) {
460  minAccOverlap = accOverlap;
461  minAccOverlapRect = srcRect;
462  }
463  }
464  return minAccOverlapRect;
465 }
static int accumulatedOverlap(const QRect &source, const QList< QRect > &rects)
Calculates the accumulated overlap (intersection area) between &#39;source&#39; and &#39;rects&#39;.
Definition: qmdiarea.cpp:434
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ findNonInsiders()

void MinOverlapPlacer::findNonInsiders ( const QRect domain,
QList< QRect > &  source,
QList< QRect > &  result 
)
staticprivate

Finds all rectangles in 'source' not completely inside 'domain'.

Warning
This function is not part of the public interface. The result is stored in 'result' and also removed from 'source'.

Definition at line 506 of file qmdiarea.cpp.

508 {
509  QMutableListIterator<QRect> it(source);
510  while (it.hasNext()) {
511  const QRect srcRect = it.next();
512  if (!domain.contains(srcRect)) {
513  result << srcRect;
514  it.remove();
515  }
516  }
517 }
#define it(className, varName)
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ getCandidatePlacements()

void MinOverlapPlacer::getCandidatePlacements ( const QSize size,
const QList< QRect > &  rects,
const QRect domain,
QList< QRect > &  candidates 
)
staticprivate

Gets candidates for the final placement.

Warning
This function is not part of the public interface.

Definition at line 474 of file qmdiarea.cpp.

476 {
477  QSet<int> xset;
478  QSet<int> yset;
479  xset << domain.left() << domain.right() - size.width() + 1;
480  yset << domain.top();
481  if (domain.bottom() - size.height() + 1 >= 0)
482  yset << domain.bottom() - size.height() + 1;
483  foreach (const QRect &rect, rects) {
484  xset << rect.right() + 1;
485  yset << rect.bottom() + 1;
486  }
487 
488  QList<int> xlist = xset.values();
489  qSort(xlist.begin(), xlist.end());
490  QList<int> ylist = yset.values();
491  qSort(ylist.begin(), ylist.end());
492 
493  foreach (int y, ylist)
494  foreach (int x, xlist)
495  candidates << QRect(QPoint(x, y), size);
496 }
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
int width() const
Returns the width.
Definition: qsize.h:126
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QList< T > values() const
Definition: qset.h:232

◆ place()

QPoint MinOverlapPlacer::place ( const QSize size,
const QList< QRect > &  rects,
const QRect domain 
) const
privatevirtual

Places the rectangle defined by 'size' relative to 'rects' and 'domain' so that it overlaps 'rects' as little as possible and 'domain' as much as possible.

Warning
This function is not part of the public interface.

Returns the position of the resulting rectangle.

Implements QMdi::Placer.

Definition at line 577 of file qmdiarea.cpp.

579 {
580  if (size.isEmpty() || !domain.isValid())
581  return QPoint();
582  foreach (const QRect &rect, rects) {
583  if (!rect.isValid())
584  return QPoint();
585  }
586 
587  QList<QRect> candidates;
588  getCandidatePlacements(size, rects, domain, candidates);
589  return findBestPlacement(domain, rects, candidates);
590 }
static void getCandidatePlacements(const QSize &size, const QList< QRect > &rects, const QRect &domain, QList< QRect > &candidates)
Gets candidates for the final placement.
Definition: qmdiarea.cpp:474
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isEmpty() const
Returns true if either of the width and height is less than or equal to 0; otherwise returns false...
Definition: qsize.h:120
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
static QPoint findBestPlacement(const QRect &domain, const QList< QRect > &rects, QList< QRect > &source)
Finds among the rectangles in &#39;source&#39; the best placement.
Definition: qmdiarea.cpp:553
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

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