8#include "ClipPainter.h"
12#include "MarbleDebug.h"
18class ClipPainterPrivate
21 explicit ClipPainterPrivate( ClipPainter * parent );
43 inline int sector(
const QPointF & point )
const;
50 inline void initClipRect();
52 inline void clipPolyObject (
const QPolygonF & sourcePolygon,
56 inline void clipMultiple(
QPolygonF & clippedPolyObject,
59 inline void clipOnce(
QPolygonF & clippedPolyObject,
62 inline void clipOnceCorner(
QPolygonF & clippedPolyObject,
66 bool isClosed )
const;
67 inline void clipOnceEdge(
QPolygonF & clippedPolyObject,
70 bool isClosed )
const;
76 bool pointAllowsLabel(
const QPointF &point)
const;
85 qreal m_labelAreaMargin;
87 int m_debugPenBatchColor;
88 int m_debugBrushBatchColor;
89 int m_debugPolygonsLevel;
90 bool m_debugBatchRender;
100 :
QPainter( pd ), d( new ClipPainterPrivate( this ) )
109ClipPainter::ClipPainter()
110 : d( new ClipPainterPrivate( this ) )
115ClipPainter::~ClipPainter()
121void ClipPainter::setScreenClip(
bool enable)
123 d->m_doClip = enable;
127bool ClipPainter::hasScreenClip()
const
133void ClipPainter::drawPolygon (
const QPolygonF & polygon,
140 d->clipPolyObject( polygon, clippedPolyObjects,
true );
142 for(
const QPolygonF & clippedPolyObject: clippedPolyObjects ) {
143 if ( clippedPolyObject.size() > 2 ) {
145 if (d->m_debugPolygonsLevel) {
157 d->debugDrawNodes( clippedPolyObject );
166 if (d->m_debugPolygonsLevel) {
178 d->debugDrawNodes( polygon );
186void ClipPainter::drawPolyline(
const QPolygonF & polygon )
192 d->clipPolyObject( polygon, clippedPolyObjects,
false );
194 for(
const QPolygonF & clippedPolyObject: clippedPolyObjects ) {
195 if ( clippedPolyObject.size() > 1 ) {
196 if (d->m_debugPolygonsLevel) {
208 d->debugDrawNodes( clippedPolyObject );
217 if (d->m_debugPolygonsLevel) {
229 d->debugDrawNodes( polygon );
244 d->clipPolyObject( polygon, clippedPolyObjects,
false );
246 for(
const QPolygonF & clippedPolyObject: clippedPolyObjects ) {
247 if (d->m_debugPolygonsLevel) {
259 d->debugDrawNodes( clippedPolyObject );
267 if (d->m_debugPolygonsLevel) {
279 d->debugDrawNodes( polygon );
285 d->labelPosition( polygon, labelNodes, positionFlags );
292 d->labelPosition(polygon, labelNodes, labelPositionFlags);
295void ClipPainter::setPen(
const QColor &color) {
296 if (d->m_debugBatchRender) {
303 if (d->m_debugBatchRender) {
309void ClipPainter::setPen(
const QPen & pen) {
310 if (d->m_debugBatchRender) {
317 d->m_debugPenBatchColor++;
318 d->m_debugPenBatchColor %= 14;
330void ClipPainter::setBrush(
const QBrush & brush) {
331 if (d->m_debugBatchRender) {
337 d->m_debugBrushBatchColor++;
338 d->m_debugBrushBatchColor %= 20;
353 if ( labelPositionFlags.
testFlag( LineCenter ) ) {
355 if ( polygon.
size() > 0 ) {
356 const int labelPosition = polygon.
size() / 2;
357 labelNodes << polygon.
at( labelPosition );
361 if ( polygon.
size() > 0 && labelPositionFlags.
testFlag( LineStart ) ) {
362 if ( pointAllowsLabel( polygon.
first() ) ) {
363 labelNodes << polygon.
first();
367 for (
int it = 1; it < polygon.
size(); ++it ) {
368 const bool currentAllowsLabel = pointAllowsLabel(polygon.
at(it));
370 if ( currentAllowsLabel ) {
372 QPointF node = interpolateLabelPoint( polygon.
at( it -1 ), polygon.
at( it ),
373 labelPositionFlags );
374 if ( node !=
QPointF( -1.0, -1.0 ) ) {
382 if ( polygon.
size() > 1 && labelPositionFlags.
testFlag( LineEnd ) ) {
383 if ( pointAllowsLabel( polygon.
at( polygon.
size() - 1 ) ) ) {
384 labelNodes << polygon.
at( polygon.
size() - 1 );
388 for (
int it = polygon.
size() - 2; it > 0; --it ) {
389 const bool currentAllowsLabel = pointAllowsLabel(polygon.
at(it));
391 if ( currentAllowsLabel ) {
392 QPointF node = interpolateLabelPoint( polygon.
at( it + 1 ), polygon.
at( it ),
393 labelPositionFlags );
394 if ( node !=
QPointF( -1.0, -1.0 ) ) {
403bool ClipPainterPrivate::pointAllowsLabel(
const QPointF &point)
const
405 return point.
x() > m_labelAreaMargin && point.
x() < q->
viewport().
width() - m_labelAreaMargin
406 && point.
y() > m_labelAreaMargin && point.
y() < q->
viewport().
height() - m_labelAreaMargin;
409QPointF ClipPainterPrivate::interpolateLabelPoint(
const QPointF &previousPoint,
413 qreal m = _m( previousPoint, currentPoint );
414 if ( previousPoint.
x() <= m_labelAreaMargin ) {
415 if ( labelPositionFlags.
testFlag( IgnoreXMargin ) ) {
418 return QPointF( m_labelAreaMargin,
419 previousPoint.
y() + ( m_labelAreaMargin - previousPoint.
x() ) * m );
421 else if ( previousPoint.
x() >= q->
viewport().
width() - m_labelAreaMargin ) {
422 if ( labelPositionFlags.
testFlag( IgnoreXMargin ) ) {
427 ( previousPoint.
x() - q->
viewport().
width() + m_labelAreaMargin ) * m );
430 if ( previousPoint.
y() <= m_labelAreaMargin ) {
431 if ( labelPositionFlags.
testFlag( IgnoreYMargin ) ) {
434 return QPointF( previousPoint.
x() + ( m_labelAreaMargin - previousPoint.
y() ) / m,
437 else if ( previousPoint.
y() >= q->
viewport().
height() - m_labelAreaMargin ) {
438 if ( labelPositionFlags.
testFlag( IgnoreYMargin ) ) {
442 ( previousPoint.
y() - q->
viewport().
height() + m_labelAreaMargin ) / m,
451ClipPainterPrivate::ClipPainterPrivate( ClipPainter * parent )
461 m_labelAreaMargin(10.0),
462 m_debugPenBatchColor(0),
463 m_debugBrushBatchColor(0),
464 m_debugPolygonsLevel(0),
465 m_debugBatchRender(false)
470void ClipPainterPrivate::initClipRect ()
472 qreal penHalfWidth = q->
pen().
widthF() / 2.0 + 1.0;
474 m_left = -penHalfWidth;
475 m_right = (qreal)(q->
device()->
width()) + penHalfWidth;
476 m_top = -penHalfWidth;
477 m_bottom = (qreal)(q->
device()->
height()) + penHalfWidth;
482 qreal divisor =
end.x() -
start.x();
483 if ( std::fabs( divisor ) < 0.000001 ) {
494QPointF ClipPainterPrivate::clipTop( qreal m,
const QPointF & point )
const
496 return QPointF( ( m_top - point.
y() ) / m + point.
x(), m_top );
499QPointF ClipPainterPrivate::clipLeft( qreal m,
const QPointF & point )
const
501 return QPointF( m_left, ( m_left - point.
x() ) * m + point.
y() );
504QPointF ClipPainterPrivate::clipBottom( qreal m,
const QPointF & point )
const
506 return QPointF( ( m_bottom - point.
y() ) / m + point.
x(), m_bottom );
509QPointF ClipPainterPrivate::clipRight( qreal m,
const QPointF & point )
const
511 return QPointF( m_right, ( m_right - point.
x() ) * m + point.
y() );
514int ClipPainterPrivate::sector(
const QPointF & point )
const
529 if ( point.
x() < m_left )
531 else if ( point.
x() > m_right )
535 if ( point.
y() < m_top )
537 else if ( point.
y() > m_bottom )
542 return ySector + xSector;
546void ClipPainterPrivate::clipPolyObject (
const QPolygonF & polygon,
564 bool processingLastNode =
false;
566 while ( itPoint != itEndPoint ) {
567 m_currentPoint = (*itPoint);
571 m_currentSector = sector( m_currentPoint );
574 if ( itPoint == itStartPoint && processingLastNode ==
false ) {
576 m_previousPoint = polygon.
last();
579 m_previousSector = sector( m_previousPoint );
582 m_previousSector = m_currentSector;
587 if ( m_currentSector != m_previousSector ) {
588 if ( m_currentSector == 4 || m_previousSector == 4 ) {
593 clipOnce( clippedPolyObject, clippedPolyObjects, isClosed );
600 clipMultiple( clippedPolyObject, clippedPolyObjects, isClosed );
603 m_previousSector = m_currentSector;
607 if ( m_currentSector == 4 ) {
609 clippedPolyObject << m_currentPoint;
611 ++(m_debugNodeCount);
615 m_previousPoint = m_currentPoint;
620 if ( processingLastNode ) {
625 if ( itPoint == itEndPoint && isClosed ) {
626 itPoint = itStartPoint;
627 processingLastNode =
true;
632 if ( !clippedPolyObject.
isEmpty() ) {
633 clippedPolyObjects << clippedPolyObject;
638void ClipPainterPrivate::clipMultiple(
QPolygonF & clippedPolyObject,
642 Q_UNUSED( clippedPolyObjects )
648 qreal m = _m( m_previousPoint, m_currentPoint );
650 switch ( m_currentSector ) {
652 if ( m_previousSector == 5 ) {
653 QPointF pointRight = clipRight( m, m_previousPoint );
654 QPointF pointTop = clipTop( m, m_currentPoint );
655 QPointF pointLeft = clipLeft( m, m_currentPoint );
657 if ( pointRight.
y() > m_top ) {
658 clippedPolyObject << pointRight;
660 clippedPolyObject <<
QPointF( m_right, m_top );
662 if ( pointTop.
x() >= m_left && pointTop.
x() < m_right )
663 clippedPolyObject << pointTop;
664 if ( pointLeft.
y() > m_top )
665 clippedPolyObject << pointLeft;
667 else if ( m_previousSector == 7 ) {
668 QPointF pointBottom = clipBottom( m, m_previousPoint );
669 QPointF pointTop = clipTop( m, m_currentPoint );
670 QPointF pointLeft = clipLeft( m, m_currentPoint );
672 if ( pointBottom.
x() > m_left ) {
673 clippedPolyObject << pointBottom;
675 clippedPolyObject <<
QPointF( m_left, m_bottom );
677 if ( pointLeft.
y() >= m_top && pointLeft.
y() < m_bottom )
678 clippedPolyObject << pointLeft;
679 if ( pointTop.
x() > m_left )
680 clippedPolyObject << pointTop;
682 else if ( m_previousSector == 8 ) {
683 QPointF pointBottom = clipBottom( m, m_previousPoint );
684 QPointF pointRight = clipRight( m, m_previousPoint );
685 QPointF pointTop = clipTop( m, m_currentPoint );
686 QPointF pointLeft = clipLeft( m, m_currentPoint );
688 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
689 clippedPolyObject << pointBottom;
690 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
691 clippedPolyObject << pointRight;
692 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
693 clippedPolyObject << pointTop;
694 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
695 clippedPolyObject << pointLeft;
697 if ( pointBottom.x() <= m_left && pointLeft.y() >= m_bottom )
698 clippedPolyObject <<
QPointF( m_left, m_bottom );
699 if ( pointTop.x() >= m_right && pointRight.y() <= m_top )
700 clippedPolyObject <<
QPointF( m_right, m_top );
703 clippedPolyObject <<
QPointF( m_left, m_top );
707 if ( m_previousSector == 3 ) {
708 QPointF pointLeft = clipLeft( m, m_previousPoint );
709 QPointF pointTop = clipTop( m, m_currentPoint );
711 if ( pointLeft.
y() > m_top ) {
712 clippedPolyObject << pointLeft;
714 clippedPolyObject <<
QPointF( m_left, m_top );
716 if ( pointTop.
x() > m_left )
717 clippedPolyObject << pointTop;
719 else if ( m_previousSector == 5 ) {
720 QPointF pointRight = clipRight( m, m_previousPoint );
721 QPointF pointTop = clipTop( m, m_currentPoint );
723 if ( pointRight.
y() > m_top ) {
724 clippedPolyObject << pointRight;
726 clippedPolyObject <<
QPointF( m_right, m_top );
728 if ( pointTop.
x() < m_right )
729 clippedPolyObject << pointTop;
731 else if ( m_previousSector == 6 ) {
732 QPointF pointBottom = clipBottom( m, m_previousPoint );
733 QPointF pointLeft = clipLeft( m, m_previousPoint );
734 QPointF pointTop = clipTop( m, m_currentPoint );
736 if ( pointBottom.
x() > m_left )
737 clippedPolyObject << pointBottom;
738 if ( pointLeft.
y() > m_top && pointLeft.
y() <= m_bottom )
739 clippedPolyObject << pointLeft;
740 if ( pointTop.
x() > m_left ) {
741 clippedPolyObject << pointTop;
743 clippedPolyObject <<
QPointF( m_left, m_top );
746 else if ( m_previousSector == 7 ) {
747 clippedPolyObject << clipBottom( m, m_previousPoint );
748 clippedPolyObject << clipTop( m, m_currentPoint );
750 else if ( m_previousSector == 8 ) {
751 QPointF pointBottom = clipBottom( m, m_previousPoint );
752 QPointF pointRight = clipRight( m, m_previousPoint );
753 QPointF pointTop = clipTop( m, m_currentPoint );
755 if ( pointBottom.
x() < m_right )
756 clippedPolyObject << pointBottom;
757 if ( pointRight.
y() > m_top && pointRight.
y() <= m_bottom )
758 clippedPolyObject << pointRight;
759 if ( pointTop.
x() < m_right ) {
760 clippedPolyObject << pointTop;
762 clippedPolyObject <<
QPointF( m_right, m_top );
768 if ( m_previousSector == 3 ) {
769 QPointF pointLeft = clipLeft( m, m_previousPoint );
770 QPointF pointTop = clipTop( m, m_currentPoint );
771 QPointF pointRight = clipRight( m, m_currentPoint );
773 if ( pointLeft.
y() > m_top ) {
774 clippedPolyObject << pointLeft;
776 clippedPolyObject <<
QPointF( m_left, m_top );
778 if ( pointTop.
x() > m_left && pointTop.
x() <= m_right )
779 clippedPolyObject << pointTop;
780 if ( pointRight.
y() > m_top )
781 clippedPolyObject << pointRight;
783 else if ( m_previousSector == 7 ) {
784 QPointF pointBottom = clipBottom( m, m_previousPoint );
785 QPointF pointTop = clipTop( m, m_currentPoint );
786 QPointF pointRight = clipRight( m, m_currentPoint );
788 if ( pointBottom.
x() < m_right ) {
789 clippedPolyObject << pointBottom;
791 clippedPolyObject <<
QPointF( m_right, m_bottom );
793 if ( pointRight.
y() >= m_top && pointRight.
y() < m_bottom )
794 clippedPolyObject << pointRight;
795 if ( pointTop.
x() < m_right )
796 clippedPolyObject << pointTop;
798 else if ( m_previousSector == 6 ) {
799 QPointF pointBottom = clipBottom( m, m_previousPoint );
800 QPointF pointLeft = clipLeft( m, m_currentPoint );
801 QPointF pointTop = clipTop( m, m_currentPoint );
802 QPointF pointRight = clipRight( m, m_previousPoint );
804 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
805 clippedPolyObject << pointBottom;
806 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
807 clippedPolyObject << pointLeft;
808 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
809 clippedPolyObject << pointTop;
810 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
811 clippedPolyObject << pointRight;
813 if ( pointBottom.x() >= m_right && pointRight.y() >= m_bottom )
814 clippedPolyObject <<
QPointF( m_right, m_bottom );
815 if ( pointTop.x() <= m_left && pointLeft.y() <= m_top )
816 clippedPolyObject <<
QPointF( m_left, m_top );
819 clippedPolyObject <<
QPointF( m_right, m_top );
823 if ( m_previousSector == 7 ) {
824 QPointF pointBottom = clipBottom( m, m_previousPoint );
825 QPointF pointLeft = clipLeft( m, m_currentPoint );
827 if ( pointBottom.
x() > m_left )
828 clippedPolyObject << pointBottom;
829 if ( pointLeft.
y() < m_bottom ) {
830 clippedPolyObject << pointLeft;
832 clippedPolyObject <<
QPointF( m_left, m_bottom );
835 else if ( m_previousSector == 1 ) {
836 QPointF pointTop = clipTop( m, m_previousPoint );
837 QPointF pointLeft = clipLeft( m, m_currentPoint );
839 if ( pointTop.
x() > m_left )
840 clippedPolyObject << pointTop;
841 if ( pointLeft.
y() > m_top ) {
842 clippedPolyObject << pointLeft;
844 clippedPolyObject <<
QPointF( m_left, m_top );
847 else if ( m_previousSector == 8 ) {
848 QPointF pointRight = clipRight( m, m_previousPoint );
849 QPointF pointBottom = clipBottom( m, m_previousPoint );
850 QPointF pointLeft = clipLeft( m, m_currentPoint );
852 if ( pointRight.
y() < m_bottom )
853 clippedPolyObject << pointRight;
854 if ( pointBottom.
x() > m_left && pointBottom.
x() <= m_right )
855 clippedPolyObject << pointBottom;
856 if ( pointLeft.
y() < m_bottom ) {
857 clippedPolyObject << pointLeft;
859 clippedPolyObject <<
QPointF( m_left, m_bottom );
862 else if ( m_previousSector == 5 ) {
863 clippedPolyObject << clipRight( m, m_previousPoint );
864 clippedPolyObject << clipLeft( m, m_currentPoint );
866 else if ( m_previousSector == 2 ) {
867 QPointF pointRight = clipRight( m, m_previousPoint );
868 QPointF pointTop = clipTop( m, m_previousPoint );
869 QPointF pointLeft = clipLeft( m, m_currentPoint );
871 if ( pointRight.
y() > m_top )
872 clippedPolyObject << pointRight;
873 if ( pointTop.
x() > m_left && pointTop.
x() <= m_right )
874 clippedPolyObject << pointTop;
875 if ( pointLeft.
y() > m_top ) {
876 clippedPolyObject << pointLeft;
878 clippedPolyObject <<
QPointF( m_left, m_top );
884 if ( m_previousSector == 7 ) {
885 QPointF pointBottom = clipBottom( m, m_previousPoint );
886 QPointF pointRight = clipRight( m, m_currentPoint );
888 if ( pointBottom.
x() < m_right )
889 clippedPolyObject << pointBottom;
890 if ( pointRight.
y() < m_bottom ) {
891 clippedPolyObject << pointRight;
893 clippedPolyObject <<
QPointF( m_right, m_bottom );
896 else if ( m_previousSector == 1 ) {
897 QPointF pointTop = clipTop( m, m_previousPoint );
898 QPointF pointRight = clipRight( m, m_currentPoint );
900 if ( pointTop.
x() < m_right )
901 clippedPolyObject << pointTop;
902 if ( pointRight.
y() > m_top ) {
903 clippedPolyObject << pointRight;
905 clippedPolyObject <<
QPointF( m_right, m_top );
908 else if ( m_previousSector == 6 ) {
909 QPointF pointLeft = clipLeft( m, m_previousPoint );
910 QPointF pointBottom = clipBottom( m, m_previousPoint );
911 QPointF pointRight = clipRight( m, m_currentPoint );
913 if ( pointLeft.
y() < m_bottom )
914 clippedPolyObject << pointLeft;
915 if ( pointBottom.
x() >= m_left && pointBottom.
x() < m_right )
916 clippedPolyObject << pointBottom;
917 if ( pointRight.
y() < m_bottom ) {
918 clippedPolyObject << pointRight;
920 clippedPolyObject <<
QPointF( m_right, m_bottom );
923 else if ( m_previousSector == 3 ) {
924 clippedPolyObject << clipLeft( m, m_previousPoint );
925 clippedPolyObject << clipRight( m, m_currentPoint );
927 else if ( m_previousSector == 0 ) {
928 QPointF pointLeft = clipLeft( m, m_previousPoint );
929 QPointF pointTop = clipTop( m, m_previousPoint );
930 QPointF pointRight = clipRight( m, m_currentPoint );
932 if ( pointLeft.
y() > m_top )
933 clippedPolyObject << pointLeft;
934 if ( pointTop.
x() >= m_left && pointTop.
x() < m_right )
935 clippedPolyObject << pointTop;
936 if ( pointRight.
y() > m_top ) {
937 clippedPolyObject << pointRight;
939 clippedPolyObject <<
QPointF( m_right, m_top );
945 if ( m_previousSector == 5 ) {
946 QPointF pointRight = clipRight( m, m_previousPoint );
947 QPointF pointBottom = clipBottom( m, m_currentPoint );
948 QPointF pointLeft = clipLeft( m, m_currentPoint );
950 if ( pointRight.
y() < m_bottom ) {
951 clippedPolyObject << pointRight;
953 clippedPolyObject <<
QPointF( m_right, m_bottom );
955 if ( pointBottom.
x() >= m_left && pointBottom.
x() < m_right )
956 clippedPolyObject << pointBottom;
957 if ( pointLeft.
y() < m_bottom )
958 clippedPolyObject << pointLeft;
960 else if ( m_previousSector == 1 ) {
961 QPointF pointTop = clipTop( m, m_previousPoint );
962 QPointF pointLeft = clipLeft( m, m_currentPoint );
963 QPointF pointBottom = clipBottom( m, m_currentPoint );
965 if ( pointTop.
x() > m_left ) {
966 clippedPolyObject << pointTop;
968 clippedPolyObject <<
QPointF( m_left, m_top );
970 if ( pointLeft.
y() > m_top && pointLeft.
y() <= m_bottom )
971 clippedPolyObject << pointLeft;
972 if ( pointBottom.
x() > m_left )
973 clippedPolyObject << pointBottom;
975 else if ( m_previousSector == 2 ) {
976 QPointF pointTop = clipTop( m, m_currentPoint );
977 QPointF pointRight = clipRight( m, m_previousPoint );
978 QPointF pointBottom = clipBottom( m, m_previousPoint );
979 QPointF pointLeft = clipLeft( m, m_currentPoint );
981 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
982 clippedPolyObject << pointTop;
983 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
984 clippedPolyObject << pointRight;
985 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
986 clippedPolyObject << pointBottom;
987 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
988 clippedPolyObject << pointLeft;
990 if ( pointBottom.x() >= m_right && pointRight.y() >= m_bottom )
991 clippedPolyObject <<
QPointF( m_right, m_bottom );
992 if ( pointTop.x() <= m_left && pointLeft.y() <= m_top )
993 clippedPolyObject <<
QPointF( m_left, m_top );
996 clippedPolyObject <<
QPointF( m_left, m_bottom );
1000 if ( m_previousSector == 3 ) {
1001 QPointF pointLeft = clipLeft( m, m_previousPoint );
1002 QPointF pointBottom = clipBottom( m, m_currentPoint );
1004 if ( pointLeft.
y() < m_bottom ) {
1005 clippedPolyObject << pointLeft;
1007 clippedPolyObject <<
QPointF( m_left, m_bottom );
1009 if ( pointBottom.
x() > m_left )
1010 clippedPolyObject << pointBottom;
1012 else if ( m_previousSector == 5 ) {
1013 QPointF pointRight = clipRight( m, m_previousPoint );
1014 QPointF pointBottom = clipBottom( m, m_currentPoint );
1016 if ( pointRight.
y() < m_bottom ) {
1017 clippedPolyObject << pointRight;
1019 clippedPolyObject <<
QPointF( m_right, m_bottom );
1021 if ( pointBottom.
x() < m_right )
1022 clippedPolyObject << pointBottom;
1024 else if ( m_previousSector == 0 ) {
1025 QPointF pointTop = clipTop( m, m_previousPoint );
1026 QPointF pointLeft = clipLeft( m, m_previousPoint );
1027 QPointF pointBottom = clipBottom( m, m_currentPoint );
1029 if ( pointTop.
x() > m_left )
1030 clippedPolyObject << pointTop;
1031 if ( pointLeft.
y() >= m_top && pointLeft.
y() < m_bottom )
1032 clippedPolyObject << pointLeft;
1033 if ( pointBottom.
x() > m_left ) {
1034 clippedPolyObject << pointBottom;
1036 clippedPolyObject <<
QPointF( m_left, m_bottom );
1039 else if ( m_previousSector == 1 ) {
1040 clippedPolyObject << clipTop( m, m_previousPoint );
1041 clippedPolyObject << clipBottom( m, m_currentPoint );
1043 else if ( m_previousSector == 2 ) {
1044 QPointF pointTop = clipTop( m, m_previousPoint );
1045 QPointF pointRight = clipRight( m, m_previousPoint );
1046 QPointF pointBottom = clipBottom( m, m_currentPoint );
1048 if ( pointTop.
x() < m_right )
1049 clippedPolyObject << pointTop;
1050 if ( pointRight.
y() >= m_top && pointRight.
y() < m_bottom )
1051 clippedPolyObject << pointRight;
1052 if ( pointBottom.
x() < m_right ) {
1053 clippedPolyObject << pointBottom;
1055 clippedPolyObject <<
QPointF( m_right, m_bottom );
1061 if ( m_previousSector == 3 ) {
1062 QPointF pointLeft = clipLeft( m, m_previousPoint );
1063 QPointF pointBottom = clipBottom( m, m_currentPoint );
1064 QPointF pointRight = clipRight( m, m_currentPoint );
1066 if ( pointLeft.
y() < m_bottom ) {
1067 clippedPolyObject << pointLeft;
1069 clippedPolyObject <<
QPointF( m_left, m_bottom );
1071 if ( pointBottom.
x() > m_left && pointBottom.
x() <= m_right )
1072 clippedPolyObject << pointBottom;
1073 if ( pointRight.
y() < m_bottom )
1074 clippedPolyObject << pointRight;
1076 else if ( m_previousSector == 1 ) {
1077 QPointF pointTop = clipTop( m, m_previousPoint );
1078 QPointF pointRight = clipRight( m, m_currentPoint );
1079 QPointF pointBottom = clipBottom( m, m_currentPoint );
1081 if ( pointTop.
x() < m_right ) {
1082 clippedPolyObject << pointTop;
1084 clippedPolyObject <<
QPointF( m_right, m_top );
1086 if ( pointRight.
y() > m_top && pointRight.
y() <= m_bottom )
1087 clippedPolyObject << pointRight;
1088 if ( pointBottom.
x() < m_right )
1089 clippedPolyObject << pointBottom;
1091 else if ( m_previousSector == 0 ) {
1092 QPointF pointTop = clipTop( m, m_currentPoint );
1093 QPointF pointLeft = clipLeft( m, m_currentPoint );
1094 QPointF pointBottom = clipBottom( m, m_previousPoint );
1095 QPointF pointRight = clipRight( m, m_previousPoint );
1097 if ( pointTop.
x() > m_left && pointTop.
x() < m_right )
1098 clippedPolyObject << pointTop;
1099 if ( pointLeft.
y() > m_top && pointLeft.
y() < m_bottom )
1100 clippedPolyObject << pointLeft;
1101 if ( pointBottom.
x() > m_left && pointBottom.
x() < m_right )
1102 clippedPolyObject << pointBottom;
1103 if ( pointRight.
y() > m_top && pointRight.
y() < m_bottom )
1104 clippedPolyObject << pointRight;
1106 if ( pointBottom.x() <= m_left && pointLeft.y() >= m_bottom )
1107 clippedPolyObject <<
QPointF( m_left, m_bottom );
1108 if ( pointTop.x() >= m_right && pointRight.y() <= m_top )
1109 clippedPolyObject <<
QPointF( m_right, m_top );
1112 clippedPolyObject <<
QPointF( m_right, m_bottom );
1120void ClipPainterPrivate::clipOnceCorner(
QPolygonF & clippedPolyObject,
1124 bool isClosed )
const
1126 Q_UNUSED( clippedPolyObjects )
1127 Q_UNUSED( isClosed )
1129 if ( m_currentSector == 4) {
1131 clippedPolyObject << corner;
1132 clippedPolyObject << point;
1135 clippedPolyObject << point;
1136 clippedPolyObject << corner;
1140void ClipPainterPrivate::clipOnceEdge(
QPolygonF & clippedPolyObject,
1143 bool isClosed )
const
1145 if ( m_currentSector == 4) {
1150 clippedPolyObject << point;
1154 clippedPolyObject << point;
1156 clippedPolyObjects << clippedPolyObject;
1161void ClipPainterPrivate::clipOnce(
QPolygonF & clippedPolyObject,
1169 qreal m = _m( m_previousPoint, m_currentPoint );
1172 int offscreenpos = ( m_currentSector == 4 ) ? m_previousSector : m_currentSector;
1175 switch ( offscreenpos ) {
1177 point = clipTop( m, m_previousPoint );
1178 if ( point.
x() < m_left ) {
1179 point = clipLeft( m, point );
1181 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_left, m_top ), point, isClosed );
1184 point = clipTop( m, m_previousPoint );
1185 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1188 point = clipTop( m, m_previousPoint );
1189 if ( point.
x() > m_right ) {
1190 point = clipRight( m, point );
1192 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_right, m_top ), point, isClosed );
1195 point = clipLeft( m, m_previousPoint );
1196 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1199 point = clipRight( m, m_previousPoint );
1200 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1203 point = clipBottom( m, m_previousPoint );
1204 if ( point.
x() < m_left ) {
1205 point = clipLeft( m, point );
1207 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_left, m_bottom ), point, isClosed );
1210 point = clipBottom( m, m_previousPoint );
1211 clipOnceEdge( clippedPolyObject, clippedPolyObjects, point, isClosed );
1214 point = clipBottom( m, m_previousPoint );
1215 if ( point.
x() > m_right ) {
1216 point = clipRight( m, point );
1218 clipOnceCorner( clippedPolyObject, clippedPolyObjects,
QPointF( m_right, m_bottom ), point, isClosed );
1226void ClipPainter::setDebugPolygonsLevel(
int level ) {
1227 d->m_debugPolygonsLevel =
level;
1230void ClipPainter::setDebugBatchRender(
bool enabled ) {
1231 d->m_debugBatchRender = enabled;
1235void ClipPainterPrivate::debugDrawNodes(
const QPolygonF & polygon )
1242 q->setBrush(
QBrush(
"#40FF0000"));
1250 for (; itPoint != itEndPoint; ++itPoint ) {
1254 if ( itPoint == itStartPoint || itPoint == itStartPoint + 1 || itPoint == itStartPoint + 2 ) {
1256 q->setBrush(
QBrush(
"#4000FF00"));
1257 if ( itPoint == itStartPoint ) {
1258 q->
drawRect( itPoint->x() - 6.0, itPoint->y() - 6.0 , 12.0, 12.0 );
1260 else if ( itPoint == itStartPoint + 1 ) {
1261 q->
drawRect( itPoint->x() - 4.0, itPoint->y() - 4.0 , 8.0, 8.0 );
1264 q->
drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 );
1267 q->setBrush(
QBrush(
"#40FF0000"));
1269 else if ( itPoint == itEndPoint - 1 || itPoint == itEndPoint - 2 || itPoint == itEndPoint - 3 ) {
1271 q->setBrush(
QBrush(
"#400000FF"));
1272 if ( itPoint == itEndPoint - 3 ) {
1273 q->
drawRect( itPoint->x() - 6.0, itPoint->y() - 6.0 , 12.0, 12.0 );
1275 else if ( itPoint == itEndPoint - 2 ) {
1276 q->
drawRect( itPoint->x() - 4.0, itPoint->y() - 4.0 , 8.0, 8.0 );
1279 q->
drawRect( itPoint->x() - 2.0, itPoint->y() - 2.0 , 4.0, 4.0 );
1282 q->setBrush(
QBrush(
"#400000FF"));
1285 q->
drawRect( itPoint->x() - 4, itPoint->y() - 4 , 8.0, 8.0 );
1287 if (m_debugPolygonsLevel == 2) {
Q_SCRIPTABLE Q_NOREPLY void start()
QStringView level(QStringView ifopt)
const QList< QKeySequence > & end()
Binds a QML item to a specific geodetic location in screen coordinates.
const QColor & color() const const
void setColor(Qt::GlobalColor color)
bool testFlag(Enum flag) const const
const_reference at(qsizetype i) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
bool isEmpty() const const
qsizetype size() const const
const QBrush & brush() const const
QPaintDevice * device() const const
void drawPolygon(const QPoint *points, int pointCount, Qt::FillRule fillRule)
void drawPolyline(const QPoint *points, int pointCount)
void drawRect(const QRect &rectangle)
void drawText(const QPoint &position, const QString &text)
const QPen & pen() const const
void setBrush(Qt::BrushStyle style)
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
void setRenderHint(RenderHint hint, bool on)
QRect viewport() const const
QColor color() const const
void setColor(const QColor &color)
qreal widthF() const const
QString number(double n, char format, int precision)