Skip to content

Commit b2a01d8

Browse files
committed
Add layout view to layout designer
1 parent 4c2447f commit b2a01d8

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/app/layout/qgslayoutdesignerdialog.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgssettings.h"
2121
#include "qgisapp.h"
2222
#include "qgslogger.h"
23+
#include "qgslayoutview.h"
2324

2425
QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
2526
: QgsLayoutDesignerInterface( dialog )
@@ -55,6 +56,26 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
5556
setDockOptions( dockOptions() | QMainWindow::GroupedDragging ) ;
5657
#endif
5758

59+
//create layout view
60+
QGridLayout *viewLayout = new QGridLayout();
61+
viewLayout->setSpacing( 0 );
62+
viewLayout->setMargin( 0 );
63+
viewLayout->setContentsMargins( 0, 0, 0, 0 );
64+
centralWidget()->layout()->setSpacing( 0 );
65+
centralWidget()->layout()->setMargin( 0 );
66+
centralWidget()->layout()->setContentsMargins( 0, 0, 0, 0 );
67+
mView = new QgsLayoutView();
68+
//mView->setMapCanvas( mQgis->mapCanvas() );
69+
mView->setContentsMargins( 0, 0, 0, 0 );
70+
//mView->setHorizontalRuler( mHorizontalRuler );
71+
//mView->setVerticalRuler( mVerticalRuler );
72+
viewLayout->addWidget( mView, 1, 1 );
73+
//view does not accept focus via tab
74+
mView->setFocusPolicy( Qt::ClickFocus );
75+
mViewFrame->setLayout( viewLayout );
76+
mViewFrame->setContentsMargins( 0, 0, 0, 1 ); // 1 is deliberate!
77+
mView->setFrameShape( QFrame::NoFrame );
78+
5879
connect( mActionClose, &QAction::triggered, this, &QWidget::close );
5980

6081
// populate with initial items...

src/app/layout/qgslayoutdesignerdialog.h

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "qgslayoutdesignerinterface.h"
2222

2323
class QgsLayoutDesignerDialog;
24+
class QgsLayoutView;
25+
2426

2527
class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
2628
{
@@ -108,6 +110,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
108110

109111
QActionGroup *mToolsActionGroup = nullptr;
110112

113+
QgsLayoutView *mView = nullptr;
114+
111115

112116
//! Save window state
113117
void saveWindowState();

src/gui/layout/qgslayoutview.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
QgsLayoutView::QgsLayoutView( QWidget *parent )
2222
: QGraphicsView( parent )
2323
{
24-
24+
setResizeAnchor( QGraphicsView::AnchorViewCenter );
25+
setMouseTracking( true );
26+
viewport()->setMouseTracking( true );
2527
}
2628

2729
QgsLayout *QgsLayoutView::currentLayout()

src/ui/layout/qgslayoutdesignerbase.ui

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
<property name="bottomMargin">
3434
<number>0</number>
3535
</property>
36+
<property name="spacing">
37+
<number>0</number>
38+
</property>
3639
<item row="0" column="0">
3740
<widget class="QFrame" name="mViewFrame">
3841
<property name="mouseTracking">
@@ -42,7 +45,7 @@
4245
<enum>QFrame::StyledPanel</enum>
4346
</property>
4447
<property name="frameShadow">
45-
<enum>QFrame::Raised</enum>
48+
<enum>QFrame::Plain</enum>
4649
</property>
4750
</widget>
4851
</item>

0 commit comments

Comments
 (0)