|
24 | 24 | #include "qgslayoutviewrubberband.h" |
25 | 25 | #include "qgsgui.h" |
26 | 26 | #include "qgslayoutitemguiregistry.h" |
| 27 | +#include "qgslayoutnewitempropertiesdialog.h" |
| 28 | +#include "qgssettings.h" |
27 | 29 | #include <QGraphicsRectItem> |
28 | 30 | #include <QPen> |
29 | 31 | #include <QBrush> |
@@ -81,13 +83,37 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even |
81 | 83 |
|
82 | 84 | QRectF rect = mRubberBand->finish( event->layoutPoint(), event->modifiers() ); |
83 | 85 |
|
| 86 | + QgsLayoutItem *item = QgsApplication::layoutItemRegistry()->createItem( mItemType, layout() ); |
| 87 | + |
84 | 88 | // click? or click-and-drag? |
85 | 89 | bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() ); |
86 | | - Q_UNUSED( clickOnly ); |
| 90 | + if ( clickOnly ) |
| 91 | + { |
| 92 | + QgsLayoutNewItemPropertiesDialog dlg( view() ); |
| 93 | + dlg.setInitialItemPosition( event->layoutPoint() ); |
| 94 | + if ( dlg.exec() ) |
| 95 | + { |
| 96 | + item->attemptResize( dlg.itemSize() ); |
| 97 | + item->attemptMove( dlg.itemPosition() ); |
| 98 | + } |
| 99 | + else |
| 100 | + { |
| 101 | + delete item; |
| 102 | + return; |
| 103 | + } |
| 104 | + } |
| 105 | + else |
| 106 | + { |
| 107 | + item->attemptResize( QgsLayoutSize( rect.width(), rect.height(), QgsUnitTypes::LayoutMillimeters ) ); |
| 108 | + item->attemptMove( QgsLayoutPoint( rect.left(), rect.top(), QgsUnitTypes::LayoutMillimeters ) ); |
| 109 | + } |
| 110 | + |
| 111 | + // record last created item size |
| 112 | + QgsSettings settings; |
| 113 | + settings.setValue( QStringLiteral( "LayoutDesigner/lastItemWidth" ), item->sizeWithUnits().width() ); |
| 114 | + settings.setValue( QStringLiteral( "LayoutDesigner/lastItemHeight" ), item->sizeWithUnits().height() ); |
| 115 | + |
87 | 116 |
|
88 | | - QgsLayoutItem *item = QgsApplication::layoutItemRegistry()->createItem( mItemType, layout() ); |
89 | | - item->attemptResize( QgsLayoutSize( rect.width(), rect.height(), QgsUnitTypes::LayoutMillimeters ) ); |
90 | | - item->attemptMove( QgsLayoutPoint( rect.left(), rect.top(), QgsUnitTypes::LayoutMillimeters ) ); |
91 | 117 | layout()->addItem( item ); |
92 | 118 | } |
93 | 119 |
|
|
0 commit comments