mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-27 00:07:16 -05:00
Allow layout items to be created without rubber bands, e.g. so that
marker items are placed with a single click instead of click-and-drag
This commit is contained in:
parent
632448c447
commit
0fe2ec2f70
@ -310,7 +310,7 @@ void QgsLayoutGuiUtils::registerGuiForKnownItemTypes( QgsMapCanvas *mapCanvas )
|
||||
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
|
||||
{
|
||||
return new QgsLayoutMarkerWidget( qobject_cast< QgsLayoutItemMarker * >( item ) );
|
||||
}, createRubberBand ) );
|
||||
}, nullptr ) );
|
||||
|
||||
// arrow
|
||||
std::unique_ptr< QgsLayoutItemGuiMetadata > arrowMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata>(
|
||||
|
||||
@ -53,6 +53,7 @@ void QgsLayoutViewToolAddItem::layoutPressEvent( QgsLayoutViewMouseEvent *event
|
||||
|
||||
mDrawing = true;
|
||||
mMousePressStartPos = event->pos();
|
||||
mMousePressStartLayoutPos = event->layoutPoint();
|
||||
mRubberBand.reset( QgsGui::layoutItemGuiRegistry()->createItemRubberBand( mItemMetadataId, view() ) );
|
||||
if ( mRubberBand )
|
||||
{
|
||||
@ -85,7 +86,7 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even
|
||||
}
|
||||
mDrawing = false;
|
||||
|
||||
QRectF rect = mRubberBand->finish( event->snappedPoint(), event->modifiers() );
|
||||
QRectF rect = mRubberBand ? mRubberBand->finish( event->snappedPoint(), event->modifiers() ) : QRectF();
|
||||
|
||||
QString undoText;
|
||||
if ( QgsLayoutItemAbstractGuiMetadata *metadata = QgsGui::layoutItemGuiRegistry()->itemMetadata( mItemMetadataId ) )
|
||||
@ -107,7 +108,7 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even
|
||||
|
||||
// click? or click-and-drag?
|
||||
bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() );
|
||||
if ( clickOnly )
|
||||
if ( clickOnly && mRubberBand )
|
||||
{
|
||||
QgsLayoutItemPropertiesDialog dlg( view() );
|
||||
dlg.setLayout( layout() );
|
||||
@ -125,17 +126,25 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if ( mRubberBand )
|
||||
{
|
||||
item->attemptResize( QgsLayoutSize( rect.width(), rect.height(), QgsUnitTypes::LayoutMillimeters ) );
|
||||
item->attemptMove( QgsLayoutPoint( rect.left(), rect.top(), QgsUnitTypes::LayoutMillimeters ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// item type doesn't use rubber bands -- e.g. marker items
|
||||
item->attemptMove( QgsLayoutPoint( mMousePressStartLayoutPos, layout()->units() ) );
|
||||
}
|
||||
|
||||
// record last created item size
|
||||
QgsSettings settings;
|
||||
settings.setValue( QStringLiteral( "LayoutDesigner/lastItemWidth" ), item->sizeWithUnits().width() );
|
||||
settings.setValue( QStringLiteral( "LayoutDesigner/lastItemHeight" ), item->sizeWithUnits().height() );
|
||||
settings.setEnumValue( QStringLiteral( "LayoutDesigner/lastSizeUnit" ), item->sizeWithUnits().units() );
|
||||
if ( mRubberBand )
|
||||
{
|
||||
QgsSettings settings;
|
||||
settings.setValue( QStringLiteral( "LayoutDesigner/lastItemWidth" ), item->sizeWithUnits().width() );
|
||||
settings.setValue( QStringLiteral( "LayoutDesigner/lastItemHeight" ), item->sizeWithUnits().height() );
|
||||
settings.setEnumValue( QStringLiteral( "LayoutDesigner/lastSizeUnit" ), item->sizeWithUnits().units() );
|
||||
}
|
||||
|
||||
QgsGui::layoutItemGuiRegistry()->newItemAddedToLayout( mItemMetadataId, item );
|
||||
|
||||
@ -154,7 +163,8 @@ void QgsLayoutViewToolAddItem::deactivate()
|
||||
if ( mDrawing )
|
||||
{
|
||||
// canceled mid operation
|
||||
mRubberBand->finish();
|
||||
if ( mRubberBand )
|
||||
mRubberBand->finish();
|
||||
mDrawing = false;
|
||||
}
|
||||
QgsLayoutViewTool::deactivate();
|
||||
|
||||
@ -77,6 +77,9 @@ class GUI_EXPORT QgsLayoutViewToolAddItem : public QgsLayoutViewTool
|
||||
//! Start position for mouse press
|
||||
QPoint mMousePressStartPos;
|
||||
|
||||
//! Start position for mouse press in layout coordinates
|
||||
QPointF mMousePressStartLayoutPos;
|
||||
|
||||
//! Start of rubber band creation
|
||||
QPointF mRubberBandStartPos;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user