Skip to content
Permalink
Browse files

Fix layout designer does not respect layout settings

  • Loading branch information
nyalldawson committed Jan 16, 2018
1 parent 2797853 commit 343c070adf15425e23ee1fba19394265173b569a
Showing with 198 additions and 42 deletions.
  1. +5 −0 python/core/layout/qgsabstractreportsection.sip
  2. +5 −0 python/core/layout/qgslayout.sip
  3. +5 −0 python/core/layout/qgslayoutgridsettings.sip
  4. +4 −0 python/core/layout/qgsmasterlayoutinterface.sip
  5. +2 −0 python/core/layout/qgsprintlayout.sip
  6. +2 −0 python/core/layout/qgsreport.sip
  7. +2 −0 python/core/layout/qgsreportsectionfieldgroup.sip
  8. +2 −0 python/core/layout/qgsreportsectionlayout.sip
  9. +5 −0 src/app/layout/qgslayoutdesignerdialog.cpp
  10. +3 −2 src/app/qgisapp.cpp
  11. +31 −32 src/app/qgsoptions.cpp
  12. +8 −0 src/core/layout/qgsabstractreportsection.cpp
  13. +5 −0 src/core/layout/qgsabstractreportsection.h
  14. +6 −0 src/core/layout/qgslayout.cpp
  15. +5 −0 src/core/layout/qgslayout.h
  16. +40 −0 src/core/layout/qgslayoutgridsettings.cpp
  17. +5 −0 src/core/layout/qgslayoutgridsettings.h
  18. +1 −1 src/core/layout/qgslayoutitemlabel.cpp
  19. +1 −1 src/core/layout/qgslayoutitemmapgrid.cpp
  20. +1 −1 src/core/layout/qgslayoutitemscalebar.cpp
  21. +3 −0 src/core/layout/qgslayoutsnapper.cpp
  22. +1 −1 src/core/layout/qgslayouttable.cpp
  23. +4 −0 src/core/layout/qgsmasterlayoutinterface.h
  24. +5 −0 src/core/layout/qgsprintlayout.cpp
  25. +1 −0 src/core/layout/qgsprintlayout.h
  26. +5 −0 src/core/layout/qgsreport.cpp
  27. +1 −0 src/core/layout/qgsreport.h
  28. +7 −0 src/core/layout/qgsreportsectionfieldgroup.cpp
  29. +1 −0 src/core/layout/qgsreportsectionfieldgroup.h
  30. +7 −0 src/core/layout/qgsreportsectionlayout.cpp
  31. +1 −0 src/core/layout/qgsreportsectionlayout.h
  32. +1 −1 src/core/qgslegendstyle.cpp
  33. +23 −3 src/ui/layout/qgslayoutdesignerbase.ui
@@ -332,6 +332,11 @@ Stores the section state in a DOM element.
Sets the item state from a DOM element.

.. seealso:: :py:func:`writeXml`
%End

virtual void reloadSettings();
%Docstring
Refreshes the section when global layout related options change.
%End

protected:
@@ -330,6 +330,11 @@ to grid appearance, spacing and offsets.
%End


void reloadSettings();
%Docstring
Refreshes the layout when global layout related options change.
%End

QgsLayoutGuideCollection &guides();
%Docstring
Returns a reference to the layout's guide collection, which manages page snap guides.
@@ -107,6 +107,11 @@ Returns the style used for drawing the page/snap grids.
.. seealso:: :py:func:`setStyle`

.. seealso:: :py:func:`pen`
%End

void loadFromSettings();
%Docstring
Loads grid settings from the application layout settings.
%End

virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
@@ -99,6 +99,10 @@ Sets the layout's state from a DOM element. ``layoutElement`` is the DOM node co
.. seealso:: :py:func:`writeLayoutXml`
%End

virtual void updateSettings() = 0;
%Docstring
Refreshes the layout when global layout related options change.
%End
};


@@ -55,6 +55,8 @@ Returns the print layout's atlas.

virtual QgsExpressionContext createExpressionContext() const;

virtual void updateSettings();


signals:

@@ -54,6 +54,8 @@ Note that ownership is not transferred to ``project``.

virtual bool readLayoutXml( const QDomElement &layoutElement, const QDomDocument &document, const QgsReadWriteContext &context );

virtual void updateSettings();


signals:

@@ -142,6 +142,8 @@ ascending, or false for descending sort.

virtual void setParentSection( QgsAbstractReportSection *parentSection );

virtual void reloadSettings();


protected:

@@ -89,6 +89,8 @@ Sets whether the body for the section is ``enabled``.

virtual QgsLayout *nextBody( bool &ok );

virtual void reloadSettings();


protected:

@@ -234,6 +234,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla

connect( mActionPageSetup, &QAction::triggered, this, &QgsLayoutDesignerDialog::pageSetup );

connect( mActionOptions, &QAction::triggered, this, [ = ]
{
QgisApp::instance()->showOptionsDialog( this, QString( "mOptionsPageComposer" ) );
} );

mView = new QgsLayoutView();
//mView->setMapCanvas( mQgis->mapCanvas() );
mView->setContentsMargins( 0, 0, 0, 0 );
@@ -9707,9 +9707,10 @@ void QgisApp::showOptionsDialog( QWidget *parent, const QString &currentPage )
//update any open compositions so they reflect new composer settings
//we have to push the changes to the compositions here, because compositions
//have no access to qgisapp and accordingly can't listen in to changes
Q_FOREACH ( QgsComposition *c, QgsProject::instance()->layoutManager()->compositions() )
const QList< QgsMasterLayoutInterface * > layouts = QgsProject::instance()->layoutManager()->layouts() ;
for ( QgsMasterLayoutInterface *layout : layouts )
{
c->updateSettings();
layout->updateSettings();
}

//do we need this? TS
@@ -767,40 +767,39 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
}

//
// Composer settings
// Layout settings
//

//default composer font
//default layout font
mComposerFontComboBox->blockSignals( true );

QString composerFontFamily = mSettings->value( QStringLiteral( "/Composer/defaultFont" ) ).toString();
QString layoutFontFamily = mSettings->value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();

QFont *tempComposerFont = new QFont( composerFontFamily );
QFont tempLayoutFont( layoutFontFamily );
// is exact family match returned from system?
if ( tempComposerFont->family() == composerFontFamily )
if ( tempLayoutFont.family() == layoutFontFamily )
{
mComposerFontComboBox->setCurrentFont( *tempComposerFont );
mComposerFontComboBox->setCurrentFont( tempLayoutFont );
}
delete tempComposerFont;

mComposerFontComboBox->blockSignals( false );

//default composer grid color
//default layout grid color
int gridRed, gridGreen, gridBlue, gridAlpha;
gridRed = mSettings->value( QStringLiteral( "/Composer/gridRed" ), 190 ).toInt();
gridGreen = mSettings->value( QStringLiteral( "/Composer/gridGreen" ), 190 ).toInt();
gridBlue = mSettings->value( QStringLiteral( "/Composer/gridBlue" ), 190 ).toInt();
gridAlpha = mSettings->value( QStringLiteral( "/Composer/gridAlpha" ), 100 ).toInt();
gridRed = mSettings->value( QStringLiteral( "LayoutDesigner/gridRed" ), 190, QgsSettings::Gui ).toInt();
gridGreen = mSettings->value( QStringLiteral( "LayoutDesigner/gridGreen" ), 190, QgsSettings::Gui ).toInt();
gridBlue = mSettings->value( QStringLiteral( "LayoutDesigner/gridBlue" ), 190, QgsSettings::Gui ).toInt();
gridAlpha = mSettings->value( QStringLiteral( "LayoutDesigner/gridAlpha" ), 100, QgsSettings::Gui ).toInt();
QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
mGridColorButton->setColor( gridColor );
mGridColorButton->setColorDialogTitle( tr( "Select Grid Color" ) );
mGridColorButton->setAllowOpacity( true );
mGridColorButton->setContext( QStringLiteral( "gui" ) );
mGridColorButton->setDefaultColor( QColor( 190, 190, 190, 100 ) );

//default composer grid style
//default layout grid style
QString gridStyleString;
gridStyleString = mSettings->value( QStringLiteral( "/Composer/gridStyle" ), "Dots" ).toString();
gridStyleString = mSettings->value( QStringLiteral( "LayoutDesigner/gridStyle" ), "Dots", QgsSettings::Gui ).toString();
mGridStyleComboBox->insertItem( 0, tr( "Solid" ) );
mGridStyleComboBox->insertItem( 1, tr( "Dots" ) );
mGridStyleComboBox->insertItem( 2, tr( "Crosses" ) );
@@ -819,10 +818,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
}

//grid and guide defaults
mGridResolutionSpinBox->setValue( mSettings->value( QStringLiteral( "/Composer/defaultSnapGridResolution" ), 10.0 ).toDouble() );
mSnapToleranceSpinBox->setValue( mSettings->value( QStringLiteral( "/Composer/defaultSnapTolerancePixels" ), 5 ).toInt() );
mOffsetXSpinBox->setValue( mSettings->value( QStringLiteral( "/Composer/defaultSnapGridOffsetX" ), 0 ).toDouble() );
mOffsetYSpinBox->setValue( mSettings->value( QStringLiteral( "/Composer/defaultSnapGridOffsetY" ), 0 ).toDouble() );
mGridResolutionSpinBox->setValue( mSettings->value( QStringLiteral( "LayoutDesigner/defaultSnapGridResolution" ), 10.0, QgsSettings::Gui ).toDouble() );
mSnapToleranceSpinBox->setValue( mSettings->value( QStringLiteral( "LayoutDesigner/defaultSnapTolerancePixels" ), 5, QgsSettings::Gui ).toInt() );
mOffsetXSpinBox->setValue( mSettings->value( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetX" ), 0, QgsSettings::Gui ).toDouble() );
mOffsetYSpinBox->setValue( mSettings->value( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetY" ), 0, QgsSettings::Gui ).toDouble() );

//
// Locale settings
@@ -1457,38 +1456,38 @@ void QgsOptions::saveOptions()
}

//
// Composer settings
// Layout settings
//

//default font
QString composerFont = mComposerFontComboBox->currentFont().family();
mSettings->setValue( QStringLiteral( "/Composer/defaultFont" ), composerFont );
QString layoutFont = mComposerFontComboBox->currentFont().family();
mSettings->setValue( QStringLiteral( "LayoutDesigner/defaultFont" ), layoutFont, QgsSettings::Gui );

//grid color
mSettings->setValue( QStringLiteral( "/Composer/gridRed" ), mGridColorButton->color().red() );
mSettings->setValue( QStringLiteral( "/Composer/gridGreen" ), mGridColorButton->color().green() );
mSettings->setValue( QStringLiteral( "/Composer/gridBlue" ), mGridColorButton->color().blue() );
mSettings->setValue( QStringLiteral( "/Composer/gridAlpha" ), mGridColorButton->color().alpha() );
mSettings->setValue( QStringLiteral( "LayoutDesigner/gridRed" ), mGridColorButton->color().red(), QgsSettings::Gui );
mSettings->setValue( QStringLiteral( "LayoutDesigner/gridGreen" ), mGridColorButton->color().green(), QgsSettings::Gui );
mSettings->setValue( QStringLiteral( "LayoutDesigner/gridBlue" ), mGridColorButton->color().blue(), QgsSettings::Gui );
mSettings->setValue( QStringLiteral( "LayoutDesigner/gridAlpha" ), mGridColorButton->color().alpha(), QgsSettings::Gui );

//grid style
if ( mGridStyleComboBox->currentText() == tr( "Solid" ) )
{
mSettings->setValue( QStringLiteral( "/Composer/gridStyle" ), "Solid" );
mSettings->setValue( QStringLiteral( "LayoutDesigner/gridStyle" ), "Solid", QgsSettings::Gui );
}
else if ( mGridStyleComboBox->currentText() == tr( "Dots" ) )
{
mSettings->setValue( QStringLiteral( "/Composer/gridStyle" ), "Dots" );
mSettings->setValue( QStringLiteral( "LayoutDesigner/gridStyle" ), "Dots", QgsSettings::Gui );
}
else if ( mGridStyleComboBox->currentText() == tr( "Crosses" ) )
{
mSettings->setValue( QStringLiteral( "/Composer/gridStyle" ), "Crosses" );
mSettings->setValue( QStringLiteral( "LayoutDesigner/gridStyle" ), "Crosses", QgsSettings::Gui );
}

//grid and guide defaults
mSettings->setValue( QStringLiteral( "/Composer/defaultSnapGridResolution" ), mGridResolutionSpinBox->value() );
mSettings->setValue( QStringLiteral( "/Composer/defaultSnapTolerancePixels" ), mSnapToleranceSpinBox->value() );
mSettings->setValue( QStringLiteral( "/Composer/defaultSnapGridOffsetX" ), mOffsetXSpinBox->value() );
mSettings->setValue( QStringLiteral( "/Composer/defaultSnapGridOffsetY" ), mOffsetYSpinBox->value() );
mSettings->setValue( QStringLiteral( "LayoutDesigner/defaultSnapGridResolution" ), mGridResolutionSpinBox->value(), QgsSettings::Gui );
mSettings->setValue( QStringLiteral( "LayoutDesigner/defaultSnapTolerancePixels" ), mSnapToleranceSpinBox->value(), QgsSettings::Gui );
mSettings->setValue( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetX" ), mOffsetXSpinBox->value(), QgsSettings::Gui );
mSettings->setValue( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetY" ), mOffsetYSpinBox->value(), QgsSettings::Gui );

//
// Locale settings
@@ -164,6 +164,14 @@ bool QgsAbstractReportSection::readXml( const QDomElement &element, const QDomDo
return result;
}

void QgsAbstractReportSection::reloadSettings()
{
if ( mHeader )
mHeader->reloadSettings();
if ( mFooter )
mFooter->reloadSettings();
}

QString QgsAbstractReportSection::filePath( const QString &baseFilePath, const QString &extension )
{
QString base = QStringLiteral( "%1_%2" ).arg( baseFilePath ).arg( mSectionNumber, 4, 10, QChar( '0' ) );
@@ -303,6 +303,11 @@ class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
*/
bool readXml( const QDomElement &sectionElement, const QDomDocument &document, const QgsReadWriteContext &context );

/**
* Refreshes the section when global layout related options change.
*/
virtual void reloadSettings();

protected:

//! Report sub-sections
@@ -358,6 +358,12 @@ const QgsLayoutReportContext &QgsLayout::reportContext() const
return *mReportContext;
}

void QgsLayout::reloadSettings()
{
mGridSettings.loadFromSettings();
mPageCollection->redraw();
}

QgsLayoutGuideCollection &QgsLayout::guides()
{
return mPageCollection->guides();
@@ -393,6 +393,11 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
*/
SIP_SKIP const QgsLayoutGridSettings &gridSettings() const { return mGridSettings; }

/**
* Refreshes the layout when global layout related options change.
*/
void reloadSettings();

/**
* Returns a reference to the layout's guide collection, which manages page snap guides.
*/
@@ -20,13 +20,15 @@
#include "qgsproject.h"
#include "qgslayoutundostack.h"
#include "qgslayoutpagecollection.h"
#include "qgssettings.h"

QgsLayoutGridSettings::QgsLayoutGridSettings( QgsLayout *layout )
: mGridResolution( QgsLayoutMeasurement( 10 ) )
, mLayout( layout )
{
mGridPen = QPen( QColor( 190, 190, 190, 100 ), 0 );
mGridPen.setCosmetic( true );
loadFromSettings();
}

QgsLayout *QgsLayoutGridSettings::layout()
@@ -48,6 +50,44 @@ void QgsLayoutGridSettings::setOffset( const QgsLayoutPoint offset )
mLayout->undoStack()->endCommand();
}

void QgsLayoutGridSettings::loadFromSettings()
{
//read grid style, grid color and pen width from settings
QgsSettings s;

QString gridStyleString;
gridStyleString = s.value( QStringLiteral( "LayoutDesigner/gridStyle" ), "Dots", QgsSettings::Gui ).toString();

int gridRed, gridGreen, gridBlue, gridAlpha;
gridRed = s.value( QStringLiteral( "LayoutDesigner/gridRed" ), 190, QgsSettings::Gui ).toInt();
gridGreen = s.value( QStringLiteral( "LayoutDesigner/gridGreen" ), 190, QgsSettings::Gui ).toInt();
gridBlue = s.value( QStringLiteral( "LayoutDesigner/gridBlue" ), 190, QgsSettings::Gui ).toInt();
gridAlpha = s.value( QStringLiteral( "LayoutDesigner/gridAlpha" ), 100, QgsSettings::Gui ).toInt();
QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );

mGridPen.setColor( gridColor );
mGridPen.setWidthF( 0 );
mGridPen.setCosmetic( true );

if ( gridStyleString == QLatin1String( "Dots" ) )
{
mGridStyle = StyleDots;
}
else if ( gridStyleString == QLatin1String( "Crosses" ) )
{
mGridStyle = StyleCrosses;
}
else
{
mGridStyle = StyleLines;
}

mGridResolution = QgsLayoutMeasurement( s.value( QStringLiteral( "LayoutDesigner/defaultSnapGridResolution" ), 10.0, QgsSettings::Gui ).toDouble(), QgsUnitTypes::LayoutMillimeters );
// mSnapToleranceSpinBox->setValue( mSettings->value( QStringLiteral( "LayoutDesigner/defaultSnapTolerancePixels" ), 5, QgsSettings::Gui ).toInt() );
mGridOffset = QgsLayoutPoint( s.value( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetX" ), 0, QgsSettings::Gui ).toDouble(),
s.value( QStringLiteral( "LayoutDesigner/defaultSnapGridOffsetY" ), 0, QgsSettings::Gui ).toDouble(), QgsUnitTypes::LayoutMillimeters );
}

bool QgsLayoutGridSettings::writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext & ) const
{
QDomElement element = document.createElement( QStringLiteral( "Grid" ) );
@@ -109,6 +109,11 @@ class CORE_EXPORT QgsLayoutGridSettings : public QgsLayoutSerializableObject
*/
Style style() const { return mGridStyle; }

/**
* Loads grid settings from the application layout settings.
*/
void loadFromSettings();

/**
* Stores the grid's state in a DOM element. The \a parentElement should refer to the parent layout's DOM element.
* \see readXml()
@@ -51,7 +51,7 @@ QgsLayoutItemLabel::QgsLayoutItemLabel( QgsLayout *layout )

//get default composer font from settings
QgsSettings settings;
QString defaultFontString = settings.value( QStringLiteral( "Composer/defaultFont" ) ).toString();
QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
if ( !defaultFontString.isEmpty() )
{
mFont.setFamily( defaultFontString );
@@ -162,7 +162,7 @@ QgsLayoutItemMapGrid::QgsLayoutItemMapGrid( const QString &name, QgsLayoutItemMa
{
//get default layout font from settings
QgsSettings settings;
QString defaultFontString = settings.value( QStringLiteral( "Composer/defaultFont" ) ).toString();
QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
if ( !defaultFontString.isEmpty() )
{
mGridAnnotationFont.setFamily( defaultFontString );
@@ -375,7 +375,7 @@ void QgsLayoutItemScaleBar::applyDefaultSettings()

//get default composer font from settings
QgsSettings settings;
QString defaultFontString = settings.value( QStringLiteral( "Composer/defaultFont" ) ).toString();
QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
QFont f;
if ( !defaultFontString.isEmpty() )
{
@@ -19,10 +19,13 @@
#include "qgsreadwritecontext.h"
#include "qgsproject.h"
#include "qgslayoutpagecollection.h"
#include "qgssettings.h"

QgsLayoutSnapper::QgsLayoutSnapper( QgsLayout *layout )
: mLayout( layout )
{
QgsSettings s;
mTolerance = s.value( QStringLiteral( "LayoutDesigner/defaultSnapTolerancePixels" ), 5, QgsSettings::Gui ).toInt();
}

QgsLayout *QgsLayoutSnapper::layout()

0 comments on commit 343c070

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