Skip to content
Permalink
Browse files

Start porting layout settings panel

Readd settings for grid tolerance/spacing/offset
  • Loading branch information
nyalldawson committed Jul 24, 2017
1 parent d0dfec7 commit 55c7cc185e2c638bfa37826103fdcd2bbbe31d34
@@ -159,6 +159,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutdesignerdialog.cpp
layout/qgslayoutappmenuprovider.cpp
layout/qgslayoutpagepropertieswidget.cpp
layout/qgslayoutpropertieswidget.cpp

locator/qgsinbuiltlocatorfilters.cpp
locator/qgslocatoroptionswidget.cpp
@@ -339,6 +340,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutappmenuprovider.h
layout/qgslayoutdesignerdialog.h
layout/qgslayoutpagepropertieswidget.h
layout/qgslayoutpropertieswidget.h

locator/qgsinbuiltlocatorfilters.h
locator/qgslocatoroptionswidget.h
@@ -30,6 +30,7 @@
#include "qgslayoutitemwidget.h"
#include "qgsgui.h"
#include "qgslayoutitemguiregistry.h"
#include "qgslayoutpropertieswidget.h"
#include "qgslayoutruler.h"
#include "qgslayoutaddpagesdialog.h"
#include "qgspanelwidgetstack.h"
@@ -241,6 +242,14 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla

int minDockWidth( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) ) );

setTabPosition( Qt::AllDockWidgetAreas, QTabWidget::North );
mGeneralDock = new QgsDockWidget( tr( "Layout" ), this );
mGeneralDock->setObjectName( QStringLiteral( "LayoutDock" ) );
mGeneralDock->setMinimumWidth( minDockWidth );
mGeneralPropertiesStack = new QgsPanelWidgetStack();
mGeneralDock->setWidget( mGeneralPropertiesStack );
mPanelsMenu->addAction( mGeneralDock->toggleViewAction() );

mItemDock = new QgsDockWidget( tr( "Item properties" ), this );
mItemDock->setObjectName( QStringLiteral( "ItemDock" ) );
mItemDock->setMinimumWidth( minDockWidth );
@@ -249,8 +258,14 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mPanelsMenu->addAction( mItemDock->toggleViewAction() );

addDockWidget( Qt::RightDockWidgetArea, mItemDock );
addDockWidget( Qt::RightDockWidgetArea, mGeneralDock );

createLayoutPropertiesWidget();

mItemDock->show();
mGeneralDock->show();

tabifyDockWidget( mGeneralDock, mItemDock );

restoreWindowState();
}
@@ -269,6 +284,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
{
mLayout = layout;
mView->setCurrentLayout( layout );
createLayoutPropertiesWidget();
}

void QgsLayoutDesignerDialog::setIconSizes( int size )
@@ -592,6 +608,22 @@ void QgsLayoutDesignerDialog::activateNewItemCreationTool( int type )
}
}

void QgsLayoutDesignerDialog::createLayoutPropertiesWidget()
{
if ( !mLayout )
{
return;
}

// update composition widget
QgsLayoutPropertiesWidget *oldCompositionWidget = qobject_cast<QgsLayoutPropertiesWidget *>( mGeneralPropertiesStack->takeMainPanel() );
delete oldCompositionWidget;

QgsLayoutPropertiesWidget *widget = new QgsLayoutPropertiesWidget( mGeneralDock, mLayout );
widget->setDockMode( true );
mGeneralPropertiesStack->setMainPanel( widget );
}

void QgsLayoutDesignerDialog::initializeRegistry()
{
sInitializedRegistry = true;
@@ -191,6 +191,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

QgsDockWidget *mItemDock = nullptr;
QgsPanelWidgetStack *mItemPropertiesStack = nullptr;
QgsDockWidget *mGeneralDock = nullptr;
QgsPanelWidgetStack *mGeneralPropertiesStack = nullptr;

//! Save window state
void saveWindowState();
@@ -201,6 +203,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
//! Switch to new item creation tool, for a new item of the specified \a type.
void activateNewItemCreationTool( int type );

void createLayoutPropertiesWidget();

void initializeRegistry();

};
@@ -0,0 +1,110 @@
/***************************************************************************
qgslayoutpropertieswidget.cpp
-----------------------------
begin : July 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgslayoutpropertieswidget.h"
#include "qgslayout.h"
#include "qgslayoutsnapper.h"

QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout *layout )
: QgsPanelWidget( parent )
, mLayout( layout )
{
setupUi( this );
setPanelTitle( tr( "Layout properties" ) );
blockSignals( true );

updateSnappingElements();

mGridSpacingUnitsCombo->linkToWidget( mGridResolutionSpinBox );
mGridOffsetUnitsComboBox->linkToWidget( mOffsetXSpinBox );
mGridOffsetUnitsComboBox->linkToWidget( mOffsetYSpinBox );

blockSignals( false );

connect( mSnapToleranceSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), this, &QgsLayoutPropertiesWidget::snapToleranceChanged );

connect( mGridOffsetUnitsComboBox, &QgsLayoutUnitsComboBox::changed, this, &QgsLayoutPropertiesWidget::gridOffsetUnitsChanged );
connect( mGridSpacingUnitsCombo, &QgsLayoutUnitsComboBox::changed, this, &QgsLayoutPropertiesWidget::gridResolutionUnitsChanged );
connect( mGridResolutionSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsLayoutPropertiesWidget::gridResolutionChanged );
connect( mOffsetXSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsLayoutPropertiesWidget::gridOffsetXChanged );
connect( mOffsetYSpinBox, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsLayoutPropertiesWidget::gridOffsetYChanged );
}

void QgsLayoutPropertiesWidget::updateSnappingElements()
{
mSnapToleranceSpinBox->setValue( mLayout->snapper().snapTolerance() );

mGridSpacingUnitsCombo->setUnit( mLayout->snapper().gridResolution().units() );
mGridResolutionSpinBox->setValue( mLayout->snapper().gridResolution().length() );

mGridOffsetUnitsComboBox->setUnit( mLayout->snapper().gridOffset().units() );
mOffsetXSpinBox->setValue( mLayout->snapper().gridOffset().x() );
mOffsetYSpinBox->setValue( mLayout->snapper().gridOffset().y() );
}

void QgsLayoutPropertiesWidget::gridResolutionChanged( double d )
{
QgsLayoutMeasurement m = mLayout->snapper().gridResolution();
m.setLength( d );
mLayout->snapper().setGridResolution( m );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridResolutionUnitsChanged( QgsUnitTypes::LayoutUnit unit )
{
QgsLayoutMeasurement m = mLayout->snapper().gridResolution();
m.setUnits( unit );
mLayout->snapper().setGridResolution( m );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridOffsetXChanged( double d )
{
QgsLayoutPoint o = mLayout->snapper().gridOffset();
o.setX( d );
mLayout->snapper().setGridOffset( o );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridOffsetYChanged( double d )
{
QgsLayoutPoint o = mLayout->snapper().gridOffset();
o.setY( d );
mLayout->snapper().setGridOffset( o );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridOffsetUnitsChanged( QgsUnitTypes::LayoutUnit unit )
{
QgsLayoutPoint o = mLayout->snapper().gridOffset();
o.setUnits( unit );
mLayout->snapper().setGridOffset( o );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::snapToleranceChanged( int tolerance )
{
mLayout->snapper().setSnapTolerance( tolerance );
}

void QgsLayoutPropertiesWidget::blockSignals( bool block )
{
mGridResolutionSpinBox->blockSignals( block );
mOffsetXSpinBox->blockSignals( block );
mOffsetYSpinBox->blockSignals( block );
mSnapToleranceSpinBox->blockSignals( block );
}

@@ -0,0 +1,49 @@
/***************************************************************************
qgslayoutpropertieswidget.h
----------------------------
begin : July 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSLAYOUTPROPERTIESWIDGET_H
#define QGSLAYOUTPROPERTIESWIDGET_H

#include "ui_qgslayoutwidgetbase.h"
#include "qgspanelwidget.h"

class QgsLayout;

class QgsLayoutPropertiesWidget: public QgsPanelWidget, private Ui::QgsLayoutWidgetBase
{
Q_OBJECT
public:
QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout *layout );

private slots:

void gridResolutionChanged( double d );
void gridResolutionUnitsChanged( QgsUnitTypes::LayoutUnit unit );
void gridOffsetXChanged( double d );
void gridOffsetYChanged( double d );
void gridOffsetUnitsChanged( QgsUnitTypes::LayoutUnit unit );
void snapToleranceChanged( int tolerance );

private:

QgsLayout *mLayout = nullptr;

void updateSnappingElements();
void blockSignals( bool block );

};

#endif // QGSLAYOUTPROPERTIESWIDGET_H

0 comments on commit 55c7cc1

Please sign in to comment.
You can’t perform that action at this time.