本文整理汇总了C++中QPolygonF::first方法的典型用法代码示例。如果您正苦于以下问题:C++ QPolygonF::first方法的具体用法?C++ QPolygonF::first怎么用?C++ QPolygonF::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPolygonF
的用法示例。
在下文中一共展示了QPolygonF::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: adjust
void LineHandler::adjust()
{
QPolygonF line = mEdge->line();
NodeElement *src = mEdge->src();
NodeElement *dst = mEdge->dst();
if (src && src->isSelected() && dst && dst->isSelected() && !mEdge->isLoop()) {
QPointF offset = mEdge->mapFromItem(src, src->portPos(mEdge->fromPort())) - line.first();
mEdge->setPos(mEdge->pos() + offset);
return;
}
if (src) {
line.first() = mEdge->mapFromItem(src, src->portPos(mEdge->fromPort()));
}
if (dst) {
line.last() = mEdge->mapFromItem(dst, dst->portPos(mEdge->toPort()));
}
mEdge->setLine(line);
if (mEdge->isLoop()) {
mEdge->createLoopEdge();
}
}
示例2: labelPosition
void ClipPainterPrivate::labelPosition(const QPolygonF &polygon, QVector<QPointF> &labelNodes,
LabelPositionFlags labelPositionFlags) const
{
if ( labelPositionFlags.testFlag( LineCenter ) ) {
// The Label at the center of the polyline:
if ( polygon.size() > 0 ) {
const int labelPosition = polygon.size() / 2; // implied: 0 <= labelPosition < polygon.size()
labelNodes << polygon.at( labelPosition );
}
}
if ( polygon.size() > 0 && labelPositionFlags.testFlag( LineStart ) ) {
if ( pointAllowsLabel( polygon.first() ) ) {
labelNodes << polygon.first();
}
// The Label at the start of the polyline:
for ( int it = 1; it < polygon.size(); ++it ) {
const bool currentAllowsLabel = pointAllowsLabel(polygon.at(it));
if ( currentAllowsLabel ) {
// As polygon.size() > 0 it's ensured that it-1 exists.
QPointF node = interpolateLabelPoint( polygon.at( it -1 ), polygon.at( it ),
labelPositionFlags );
if ( node != QPointF( -1.0, -1.0 ) ) {
labelNodes << node;
}
break;
}
}
}
if ( polygon.size() > 1 && labelPositionFlags.testFlag( LineEnd ) ) {
if ( pointAllowsLabel( polygon.at( polygon.size() - 1 ) ) ) {
labelNodes << polygon.at( polygon.size() - 1 );
}
// The Label at the end of the polyline:
for ( int it = polygon.size() - 2; it > 0; --it ) {
const bool currentAllowsLabel = pointAllowsLabel(polygon.at(it));
if ( currentAllowsLabel ) {
QPointF node = interpolateLabelPoint( polygon.at( it + 1 ), polygon.at( it ),
labelPositionFlags );
if ( node != QPointF( -1.0, -1.0 ) ) {
labelNodes << node;
}
break;
}
}
}
}
示例3: createItem
void SMDItem::createItem(QGraphicsItemGroup* inOutItem, bool inIsMainNotGround)
{
auto main = new QGraphicsPolygonItem;
QPolygonF poly;
for (auto point : mComponent->rect().points)
{
poly << QPointF(point.x, - point.y);
}
poly << poly.first();
main->setPolygon(poly);
QColor color = inIsMainNotGround ?
gSettings().layerColor(mComponent->layer())
: gSettings().backgroundColor();
QBrush br(color);
main->setBrush(br);
QPen p(color);
if (!inIsMainNotGround)
{
p.setColor(color);
p.setWidthF(mComponent->groundPlaneDistance() * 2);
p.setJoinStyle(Qt::MiterJoin);
}
main->setPen(p);
inOutItem->addToGroup(main);
}
示例4: modelDataChanged
void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
// Add 2 points to close the polygon.
QPolygonF poly = polygon();
if (poly.isEmpty())
return;
QPointF p1 = poly.first();
QPointF p2 = poly.last();
poly.prepend(QPointF(p1.x(), vAxis->posAtValue(0)));
poly.append(QPointF(p2.x(), vAxis->posAtValue(0)));
setPolygon(poly);
QLinearGradient pat(0, polygon().boundingRect().top(), 0, polygon().boundingRect().bottom());
pat.setColorAt(0, getColor(CALC_CEILING_SHALLOW));
pat.setColorAt(1, getColor(CALC_CEILING_DEEP));
setPen(QPen(QBrush(Qt::NoBrush), 0));
setBrush(pat);
gradientFactor->setX(poly.boundingRect().width() / 2 + poly.boundingRect().x());
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
if (plannerModel->isPlanner()) {
struct diveplan &diveplan = plannerModel->getDiveplan();
gradientFactor->setText(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh));
} else {
gradientFactor->setText(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh));
}
}
示例5: l
void QgsMarkerLineSymbolLayerV2::renderOffsetVertexAlongLine( const QPolygonF &points, int vertex, double distance, QgsSymbolV2RenderContext& context )
{
if ( points.isEmpty() )
return;
QgsRenderContext& rc = context.renderContext();
double origAngle = mMarker->angle();
if ( distance == 0 )
{
// rotate marker (if desired)
if ( mRotateMarker )
{
bool isRing = false;
if ( points.first() == points.last() )
isRing = true;
double angle = markerAngle( points, isRing, vertex );
mMarker->setAngle( origAngle + angle * 180 / M_PI );
}
mMarker->renderPoint( points[vertex], context.feature(), rc, -1, context.selected() );
return;
}
int pointIncrement = distance > 0 ? 1 : -1;
QPointF previousPoint = points[vertex];
int startPoint = distance > 0 ? qMin( vertex + 1, points.count() - 1 ) : qMax( vertex - 1, 0 );
int endPoint = distance > 0 ? points.count() - 1 : 0;
double distanceLeft = qAbs( distance );
for ( int i = startPoint; pointIncrement > 0 ? i <= endPoint : i >= endPoint; i += pointIncrement )
{
const QPointF& pt = points[i];
if ( previousPoint == pt ) // must not be equal!
continue;
// create line segment
MyLine l( previousPoint, pt );
if ( distanceLeft < l.length() )
{
//destination point is in current segment
QPointF markerPoint = previousPoint + l.diffForInterval( distanceLeft );
// rotate marker (if desired)
if ( mRotateMarker )
{
mMarker->setAngle( origAngle + ( l.angle() * 180 / M_PI ) );
}
mMarker->renderPoint( markerPoint, context.feature(), rc, -1, context.selected() );
return;
}
distanceLeft -= l.length();
previousPoint = pt;
}
//didn't find point
return;
}
示例6: paint
//! [4]
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
QWidget *)
{
if (myStartItem->collidesWithItem(myEndItem))
return;
QPen myPen = pen();
myPen.setColor(myColor);
qreal arrowSize = 20;
painter->setPen(myPen);
painter->setBrush(myColor);
//! [4] //! [5]
QLineF centerLine(myStartItem->pos(), myEndItem->pos());
QPolygonF endPolygon = myEndItem->polygon();
QPointF p1 = endPolygon.first() + myEndItem->pos();
QPointF p2;
QPointF intersectPoint;
QLineF polyLine;
for (int i = 1; i < endPolygon.count(); ++i) {
p2 = endPolygon.at(i) + myEndItem->pos();
polyLine = QLineF(p1, p2);
QLineF::IntersectType intersectType =
polyLine.intersect(centerLine, &intersectPoint);
if (intersectType == QLineF::BoundedIntersection)
break;
p1 = p2;
}
setLine(QLineF(intersectPoint, myStartItem->pos()));
//! [5] //! [6]
double angle = ::acos(line().dx() / line().length());
if (line().dy() >= 0)
angle = (Pi * 2) - angle;
QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize,
cos(angle + Pi / 3) * arrowSize);
QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
cos(angle + Pi - Pi / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().p1() << arrowP1 << arrowP2;
//! [6] //! [7]
painter->drawLine(line());
painter->drawPolygon(arrowHead);
if (isSelected()) {
painter->setPen(QPen(myColor, 1, Qt::DashLine));
QLineF myLine = line();
myLine.translate(0, 4.0);
painter->drawLine(myLine);
myLine.translate(0,-8.0);
painter->drawLine(myLine);
}
}
示例7: closePolyline
/*!
\brief Complete a polygon to be a closed polygon including the
area between the original polygon and the baseline.
\param painter Painter
\param xMap X map
\param yMap Y map
\param polygon Polygon to be completed
*/
void QwtPlotCurve::closePolyline( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
QPolygonF &polygon ) const
{
if ( polygon.size() < 2 )
return;
const bool doAlign = QwtPainter::roundingAlignment( painter );
double baseline = d_data->baseline;
if ( orientation() == Qt::Vertical )
{
if ( yMap.transformation()->type() == QwtScaleTransformation::Log10 )
{
if ( baseline < QwtScaleMap::LogMin )
baseline = QwtScaleMap::LogMin;
}
double refY = yMap.transform( baseline );
if ( doAlign )
refY = qRound( refY );
polygon += QPointF( polygon.last().x(), refY );
polygon += QPointF( polygon.first().x(), refY );
}
else
{
if ( xMap.transformation()->type() == QwtScaleTransformation::Log10 )
{
if ( baseline < QwtScaleMap::LogMin )
baseline = QwtScaleMap::LogMin;
}
double refX = xMap.transform( baseline );
if ( doAlign )
refX = qRound( refX );
polygon += QPointF( refX, polygon.last().y() );
polygon += QPointF( refX, polygon.first().y() );
}
}
示例8: flushPolygon
//! Internal, used by the Outline style.
void QwtPlotHistogram::flushPolygon( QPainter *painter,
double baseLine, QPolygonF &polygon ) const
{
if ( polygon.size() == 0 )
return;
if ( orientation() == Qt::Horizontal )
polygon += QPointF( baseLine, polygon.last().y() );
else
polygon += QPointF( polygon.last().x(), baseLine );
if ( d_data->brush.style() != Qt::NoBrush )
{
painter->setPen( Qt::NoPen );
painter->setBrush( d_data->brush );
if ( orientation() == Qt::Horizontal )
{
polygon += QPointF( polygon.last().x(), baseLine );
polygon += QPointF( polygon.first().x(), baseLine );
}
else
{
polygon += QPointF( baseLine, polygon.last().y() );
polygon += QPointF( baseLine, polygon.first().y() );
}
QwtPainter::drawPolygon( painter, polygon );
int resize = polygon.size();
if ( resize > 1 )
resize -= 2;
polygon.resize( resize );
}
if ( d_data->pen.style() != Qt::NoPen )
{
painter->setBrush( Qt::NoBrush );
painter->setPen( d_data->pen );
QwtPainter::drawPolyline( painter, polygon );
}
polygon.clear();
}
示例9: creationPolygonChanged
void CircleItem::creationPolygonChanged(View::CreationEvent event) {
if (event == View::EscapeEvent) {
ViewItem::creationPolygonChanged(event);
return;
}
if (event == View::MousePress) {
const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MousePress));
setPos(poly.first().x(), poly.first().y());
setViewRect(QRectF(0.0, 0.0, 0.0, sizeOfGrip().height()));
setRect(-2,-2,4,4);
view()->scene()->addItem(this);
return;
}
if (event == View::MouseMove) {
const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseMove));
qreal dx = poly.last().x();
qreal dy = poly.last().y();
qreal r = qMax(qreal(2.0),sqrt(dx*dx + dy*dy));
QRectF newRect(-r, -r, 2.0*r, 2.0*r);
setViewRect(newRect);
return;
}
if (event == View::MouseRelease) {
const QPolygonF poly = mapFromScene(view()->creationPolygon(View::MouseRelease));
view()->disconnect(this, SLOT(deleteLater())); //Don't delete ourself
view()->disconnect(this, SLOT(creationPolygonChanged(View::CreationEvent)));
view()->setMouseMode(View::Default);
updateViewItemParent();
emit creationComplete();
return;
}
}
示例10: paint
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
QWidget *)
{
if(!myStartItem || !myEndItem) {
return;
}
if(myEndItem->sceneBoundingRect().contains(p1())) {
return;
}
QPen myPen = pen();
myPen.setColor(myColor);
qreal arrowSize = 5;
painter->setPen(myPen);
painter->setBrush(myColor);
QLineF centerLine(p1(), p2());
QPolygonF endPolygon = myEndItem->mapToScene(myEndItem->shape()).toFillPolygon();
QPointF p1 = endPolygon.first();
QPointF p2;
QPointF intersectPoint;
QLineF polyLine;
for (int i = 1; i < endPolygon.count(); ++i) {
p2 = endPolygon.at(i);
polyLine = QLineF(p1, p2);
QLineF::IntersectType intersectType =
polyLine.intersect(centerLine, &intersectPoint);
if (intersectType == QLineF::BoundedIntersection)
break;
p1 = p2;
}
setLine(QLineF(intersectPoint, this->p1()));
double angle = ::acos(line().dx() / line().length());
if (line().dy() >= 0)
angle = (Pi * 2) - angle;
QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize,
cos(angle + Pi / 3) * arrowSize);
QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
cos(angle + Pi - Pi / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().p1() << arrowP1 << arrowP2;
painter->drawLine(line());
painter->drawPolygon(arrowHead);
}
示例11: if
void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points, QgsSymbolV2RenderContext& context, Placement placement )
{
if ( points.isEmpty() )
return;
QgsRenderContext& rc = context.renderContext();
double origAngle = mMarker->angle();
int i, maxCount;
bool isRing = false;
if ( placement == FirstVertex )
{
i = 0;
maxCount = 1;
}
else if ( placement == LastVertex )
{
i = points.count() - 1;
maxCount = points.count();
}
else
{
i = 0;
maxCount = points.count();
if ( points.first() == points.last() )
isRing = true;
}
for ( ; i < maxCount; ++i )
{
if ( isRing && placement == Vertex && i == points.count() - 1 )
{
continue; // don't draw the last marker - it has been drawn already
}
// rotate marker (if desired)
if ( mRotateMarker )
{
double angle = markerAngle( points, isRing, i );
mMarker->setAngle( origAngle + angle * 180 / M_PI );
}
mMarker->renderPoint( points.at( i ), context.feature(), rc, -1, context.selected() );
}
// restore original rotation
mMarker->setAngle( origAngle );
}
示例12: getDistance
qreal PathSorter::getDistance(const QPolygonF &p1, const QPolygonF &p2)
{
qreal testx1 = p1.last().x();
qreal testy1 = p1.last().y();
qreal testx2 = p2.first().x();
qreal testy2 = p2.first().y();
qreal a = 0.0;
qreal b = 0.0;
double c = 0.0;
if(testx1 >= testx2) a = testx1 - testx2;
else a = testx2 - testx1;
if(testy1 >= testy2) b = testy1 - testy2;
else b = testy2 - testy1;
c = sqrt((double)(a*a+b*b));
return (qreal) c;
}
示例13: slopesX
QPolygonF QwtSplineC1::polygonX( int numPoints, const QPolygonF &points ) const
{
if ( points.size() <= 2 )
return points;
QPolygonF fittedPoints;
const QVector<double> m = slopesX( points );
if ( m.size() != points.size() )
return fittedPoints;
const QPointF *p = points.constData();
const double *s = m.constData();
const double x1 = points.first().x();
const double x2 = points.last().x();
const double delta = ( x2 - x1 ) / ( numPoints - 1 );
double x0, y0;
QwtSplinePolynom polynom;
for ( int i = 0, j = 0; i < numPoints; i++ )
{
double x = x1 + i * delta;
if ( x > x2 )
x = x2;
if ( i == 0 || x > p[j + 1].x() )
{
while ( x > p[j + 1].x() )
j++;
polynom = QwtSplinePolynom::fromSlopes( p[j], s[j], p[j + 1], s[j + 1] );
x0 = p[j].x();
y0 = p[j].y();
}
const double y = y0 + polynom.value( x - x0 );
fittedPoints += QPointF( x, y );
}
return fittedPoints;
}
示例14: getIntersection
QLineF::IntersectType getIntersection (const QLineF& l, const QPolygonF& p, QPointF* intersectPoint)
{
QPointF p1 = p.first();
QPointF p2;
QLineF polyLine;
for ( int i = 1; i < p.count(); ++i)
{
p2 = p.at(i);
polyLine = QLineF( p1, p2);
QLineF::IntersectType intersectType = polyLine.intersect( l, intersectPoint);
if ( intersectType == QLineF::BoundedIntersection)
{
return QLineF::BoundedIntersection;
}
p1 = p2;
}
return QLineF::NoIntersection;
}
示例15: zoomToNode
void QgsNodeEditor::zoomToNode( int idx )
{
double x = mSelectedFeature->vertexMap().at( idx )->point().x();
double y = mSelectedFeature->vertexMap().at( idx )->point().y();
QgsPoint newCenter( x, y );
QgsCoordinateTransform t( mLayer->crs(), mCanvas->mapSettings().destinationCrs() );
QgsPoint tCenter = t.transform( newCenter );
QPolygonF ext = mCanvas->mapSettings().visiblePolygon();
//close polygon
ext.append( ext.first() );
QgsGeometry extGeom( QgsGeometry::fromQPolygonF( ext ) );
QgsGeometry nodeGeom( QgsGeometry::fromPoint( tCenter ) );
if ( !nodeGeom.within( extGeom ) )
{
mCanvas->setCenter( tCenter );
mCanvas->refresh();
}
}