QgsLayoutMeasurement QgsLayoutMeasurement::decodeMeasurement( const QString &string ) { QStringList parts = string.split( ',' ); if ( parts.count() != 2 ) { return QgsLayoutMeasurement( 0 ); } return QgsLayoutMeasurement( parts[0].toDouble(), QgsUnitTypes::decodeLayoutUnit( parts[1] ) ); }
double QgsLayoutItemHtml::htmlUnitsToLayoutUnits() { if ( !mLayout ) { return 1.0; } return mLayout->convertToLayoutUnits( QgsLayoutMeasurement( mLayout->context().dpi() / 72.0, QgsUnitTypes::LayoutMillimeters ) ); //webkit seems to assume a standard dpi of 96 }
double QgsLayoutItemLabel::htmlUnitsToLayoutUnits() { if ( !mLayout ) { return 1.0; } //TODO : fix this more precisely so that the label's default text size is the same with or without "display as html" return mLayout->convertToLayoutUnits( QgsLayoutMeasurement( mLayout->renderContext().dpi() / 72.0, QgsUnitTypes::LayoutMillimeters ) ); //webkit seems to assume a standard dpi of 72 }
void QgsLayoutItemPropertiesWidget::strokeUnitChanged( QgsUnitTypes::LayoutUnit unit ) { if ( !mItem ) { return; } mItem->layout()->undoStack()->beginCommand( mItem, tr( "Change Frame Stroke Width" ), QgsLayoutItem::UndoStrokeWidth ); mItem->setFrameStrokeWidth( QgsLayoutMeasurement( mStrokeWidthSpinBox->value(), unit ) ); mItem->layout()->undoStack()->endCommand(); }
void QgsLayoutItemPropertiesWidget::mStrokeWidthSpinBox_valueChanged( double d ) { if ( !mItem ) { return; } mItem->layout()->undoStack()->beginCommand( mItem, tr( "Change Frame Stroke Width" ), QgsLayoutItem::UndoStrokeWidth ); mItem->setFrameStrokeWidth( QgsLayoutMeasurement( d, mStrokeUnitsComboBox->unit() ) ); mItem->layout()->undoStack()->endCommand(); }
void QgsLayoutItemScaleBar::resizeToMinimumWidth() { if ( !mStyle ) return; double widthMM = mStyle->calculateBoxSize( mSettings, createScaleContext() ).width(); QgsLayoutSize currentSize = sizeWithUnits(); currentSize.setWidth( mLayout->renderContext().measurementConverter().convert( QgsLayoutMeasurement( widthMM, QgsUnitTypes::LayoutMillimeters ), currentSize.units() ).length() ); attemptResize( currentSize ); update(); emit changed(); }
bool QgsLayoutItemShape::readPropertiesFromElement( const QDomElement &element, const QDomDocument &, const QgsReadWriteContext &context ) { mShape = static_cast< Shape >( element.attribute( QStringLiteral( "shapeType" ), QStringLiteral( "0" ) ).toInt() ); if ( element.hasAttribute( QStringLiteral( "cornerRadiusMeasure" ) ) ) mCornerRadius = QgsLayoutMeasurement::decodeMeasurement( element.attribute( QStringLiteral( "cornerRadiusMeasure" ), QStringLiteral( "0" ) ) ); else mCornerRadius = QgsLayoutMeasurement( element.attribute( QStringLiteral( "cornerRadius" ), QStringLiteral( "0" ) ).toDouble() ); QDomElement shapeStyleSymbolElem = element.firstChildElement( QStringLiteral( "symbol" ) ); if ( !shapeStyleSymbolElem.isNull() ) { mShapeStyleSymbol.reset( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( shapeStyleSymbolElem, context ) ); } return true; }
QgsLayoutMeasurement QgsLayoutMeasurement::operator/( const double v ) const { return QgsLayoutMeasurement( mLength / v, mUnits ); }
void QgsLayoutRuler::mouseReleaseEvent( QMouseEvent *event ) { if ( event->button() == Qt::LeftButton ) { if ( mDraggingGuide ) { QApplication::restoreOverrideCursor(); QPointF layoutPoint = convertLocalPointToLayout( event->pos() ); // delete guide if it ends outside of page QgsLayoutItemPage *page = mDraggingGuide->page(); bool deleteGuide = false; switch ( mDraggingGuide->orientation() ) { case Qt::Horizontal: if ( layoutPoint.y() < page->scenePos().y() || layoutPoint.y() > page->scenePos().y() + page->rect().height() ) deleteGuide = true; break; case Qt::Vertical: if ( layoutPoint.x() < page->scenePos().x() || layoutPoint.x() > page->scenePos().x() + page->rect().width() ) deleteGuide = true; break; } if ( deleteGuide ) { mView->currentLayout()->guides().removeGuide( mDraggingGuide ); } mDraggingGuide = nullptr; } else { mCreatingGuide = false; QApplication::restoreOverrideCursor(); delete mGuideItem; mGuideItem = nullptr; // check that cursor left the ruler switch ( mOrientation ) { case Qt::Horizontal: { if ( event->pos().y() <= height() ) return; break; } case Qt::Vertical: { if ( event->pos().x() <= width() ) return; break; } } QgsLayout *layout = mView->currentLayout(); // create guide QPointF scenePos = convertLocalPointToLayout( event->pos() ); QgsLayoutItemPage *page = layout->pageCollection()->pageAtPoint( scenePos ); if ( !page ) return; // dragged outside of a page std::unique_ptr< QgsLayoutGuide > guide; switch ( mOrientation ) { case Qt::Horizontal: { //mouse is creating a horizontal guide double posOnPage = layout->pageCollection()->positionOnPage( scenePos ).y(); guide.reset( new QgsLayoutGuide( Qt::Horizontal, QgsLayoutMeasurement( posOnPage, layout->units() ), page ) ); break; } case Qt::Vertical: { //mouse is creating a vertical guide guide.reset( new QgsLayoutGuide( Qt::Vertical, QgsLayoutMeasurement( scenePos.x(), layout->units() ), page ) ); break; } } mView->currentLayout()->guides().addGuide( guide.release() ); } } else if ( event->button() == Qt::RightButton ) { if ( mMenu ) mMenu->popup( event->globalPos() ); } }
QgsLayoutMeasurement QgsLayout::convertFromLayoutUnits( const double length, const QgsUnitTypes::LayoutUnit unit ) const { return mRenderContext->measurementConverter().convert( QgsLayoutMeasurement( length, mUnits ), unit ); }