Skip to content

Commit

Permalink
Add layout view to layout designer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 4c2447f commit b2a01d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgssettings.h"
#include "qgisapp.h"
#include "qgslogger.h"
#include "qgslayoutview.h"

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
Expand Down Expand Up @@ -55,6 +56,26 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
setDockOptions( dockOptions() | QMainWindow::GroupedDragging ) ;
#endif

//create layout view
QGridLayout *viewLayout = new QGridLayout();
viewLayout->setSpacing( 0 );
viewLayout->setMargin( 0 );
viewLayout->setContentsMargins( 0, 0, 0, 0 );
centralWidget()->layout()->setSpacing( 0 );
centralWidget()->layout()->setMargin( 0 );
centralWidget()->layout()->setContentsMargins( 0, 0, 0, 0 );
mView = new QgsLayoutView();
//mView->setMapCanvas( mQgis->mapCanvas() );
mView->setContentsMargins( 0, 0, 0, 0 );
//mView->setHorizontalRuler( mHorizontalRuler );
//mView->setVerticalRuler( mVerticalRuler );
viewLayout->addWidget( mView, 1, 1 );
//view does not accept focus via tab
mView->setFocusPolicy( Qt::ClickFocus );
mViewFrame->setLayout( viewLayout );
mViewFrame->setContentsMargins( 0, 0, 0, 1 ); // 1 is deliberate!
mView->setFrameShape( QFrame::NoFrame );

connect( mActionClose, &QAction::triggered, this, &QWidget::close );

// populate with initial items...
Expand Down
4 changes: 4 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -21,6 +21,8 @@
#include "qgslayoutdesignerinterface.h"

class QgsLayoutDesignerDialog;
class QgsLayoutView;


class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
Expand Down Expand Up @@ -108,6 +110,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

QActionGroup *mToolsActionGroup = nullptr;

QgsLayoutView *mView = nullptr;


//! Save window state
void saveWindowState();
Expand Down
4 changes: 3 additions & 1 deletion src/gui/layout/qgslayoutview.cpp
Expand Up @@ -21,7 +21,9 @@
QgsLayoutView::QgsLayoutView( QWidget *parent )
: QGraphicsView( parent )
{

setResizeAnchor( QGraphicsView::AnchorViewCenter );
setMouseTracking( true );
viewport()->setMouseTracking( true );
}

QgsLayout *QgsLayoutView::currentLayout()
Expand Down
5 changes: 4 additions & 1 deletion src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -33,6 +33,9 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QFrame" name="mViewFrame">
<property name="mouseTracking">
Expand All @@ -42,7 +45,7 @@
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
</widget>
</item>
Expand Down

0 comments on commit b2a01d8

Please sign in to comment.