Skip to content

Commit

Permalink
Add config widget for polygon/polyline items
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 44fe2a8 commit d92b067
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -181,6 +181,8 @@ SET(QGIS_APP_SRCS
layout/qgslayoutappmenuprovider.cpp
layout/qgslayoutmapwidget.cpp
layout/qgslayoutpagepropertieswidget.cpp
layout/qgslayoutpolygonwidget.cpp
layout/qgslayoutpolylinewidget.cpp
layout/qgslayoutpropertieswidget.cpp
layout/qgslayoutshapewidget.cpp

Expand Down Expand Up @@ -379,6 +381,8 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutitemslistview.h
layout/qgslayoutmapwidget.h
layout/qgslayoutpagepropertieswidget.h
layout/qgslayoutpolygonwidget.h
layout/qgslayoutpolylinewidget.h
layout/qgslayoutpropertieswidget.h
layout/qgslayoutshapewidget.h

Expand Down
8 changes: 4 additions & 4 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -25,6 +25,8 @@
#include "qgslayoutitemmap.h"
#include "qgslayoutitempolygon.h"
#include "qgslayoutitempolyline.h"
#include "qgslayoutpolygonwidget.h"
#include "qgslayoutpolylinewidget.h"

void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
{
Expand Down Expand Up @@ -84,8 +86,7 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
QgsLayoutItemRegistry::LayoutPolygon, QObject::tr( "Polygon" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolygon.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return nullptr;
//return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ) );
return new QgsLayoutPolygonWidget( qobject_cast< QgsLayoutItemPolygon * >( item ) );
}, createRubberBand, QStringLiteral( "nodes" ), true );
polygonMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPolygonItem*
{
Expand All @@ -101,8 +102,7 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
QgsLayoutItemRegistry::LayoutPolyline, QObject::tr( "Polyline" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolyline.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return nullptr;
//return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ) );
return new QgsLayoutPolylineWidget( qobject_cast< QgsLayoutItemPolyline * >( item ) );
}, createRubberBand, QStringLiteral( "nodes" ), true );
polylineMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPathItem*
{
Expand Down
83 changes: 83 additions & 0 deletions src/app/layout/qgslayoutpolygonwidget.cpp
@@ -0,0 +1,83 @@
/***************************************************************************
qgslayoutpolygonwidget.cpp
begin : March 2016
copyright : (C) 2016 Paul Blottiere, Oslandia
email : paul dot blottiere at oslandia 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 "qgslayoutpolygonwidget.h"
#include "qgssymbolselectordialog.h"
#include "qgsstyle.h"
#include "qgslayout.h"
#include "qgssymbollayerutils.h"
#include "qgslayoutitemregistry.h"

QgsLayoutPolygonWidget::QgsLayoutPolygonWidget( QgsLayoutItemPolygon *polygon )
: QgsLayoutItemBaseWidget( nullptr, polygon )
, mPolygon( polygon )
{
setupUi( this );
setPanelTitle( tr( "Polygon properties" ) );

//add widget for general composer item properties
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polygon );
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
mItemPropertiesWidget->showBackgroundGroup( false );
mItemPropertiesWidget->showFrameGroup( false );
mainLayout->addWidget( mItemPropertiesWidget );

mPolygonStyleButton->setSymbolType( QgsSymbol::Fill );
connect( mPolygonStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolygonWidget::symbolChanged );

if ( mPolygon )
{
connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
}

setGuiElementValues();
#if 0 //TODO
mShapeStyleButton->setLayer( atlasCoverageLayer() );
#endif
}

bool QgsLayoutPolygonWidget::setNewItem( QgsLayoutItem *item )
{
if ( item->type() != QgsLayoutItemRegistry::LayoutPolygon )
return false;

mPolygon = qobject_cast< QgsLayoutItemPolygon * >( item );
mItemPropertiesWidget->setItem( mPolygon );

setGuiElementValues();

return true;
}

void QgsLayoutPolygonWidget::setGuiElementValues()
{
if ( !mPolygon )
{
return;
}

whileBlocking( mPolygonStyleButton )->setSymbol( mPolygon->symbol()->clone() );
}

void QgsLayoutPolygonWidget::symbolChanged()
{
if ( !mPolygon )
return;

mPolygon->layout()->undoStack()->beginCommand( mPolygon, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle );
mPolygon->setSymbol( mPolygonStyleButton->clonedSymbol<QgsFillSymbol>() );
mPolygon->layout()->undoStack()->endCommand();
}
48 changes: 48 additions & 0 deletions src/app/layout/qgslayoutpolygonwidget.h
@@ -0,0 +1,48 @@
/***************************************************************************
qgslayoutpolygonwidget.h
begin : March 2016
copyright : (C) 2016 Paul Blottiere, Oslandia
email : paul dot blottiere at oslandia 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 QGSLAYOUTPOLYGONWIDGET_H
#define QGSLAYOUTPOLYGONWIDGET_H

#include "ui_qgslayoutpolygonwidgetbase.h"
#include "qgslayoutitemwidget.h"
#include "qgslayoutitempolygon.h"

/**
* Input widget for QgsLayoutItemPolygon
*/
class QgsLayoutPolygonWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutPolygonWidgetBase
{
Q_OBJECT
public:
explicit QgsLayoutPolygonWidget( QgsLayoutItemPolygon *polygon );

protected:

bool setNewItem( QgsLayoutItem *item ) override;

private:
QgsLayoutItemPolygon *mPolygon = nullptr;
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;

//! Sets the GUI elements to the currentValues of mComposerShape
void setGuiElementValues();

private slots:
void symbolChanged();
};

#endif // QGSLAYOUTPOLYGONWIDGET_H
82 changes: 82 additions & 0 deletions src/app/layout/qgslayoutpolylinewidget.cpp
@@ -0,0 +1,82 @@
/***************************************************************************
qgslayoutpolylinewidget.cpp
begin : March 2016
copyright : (C) 2016 Paul Blottiere, Oslandia
email : paul dot blottiere at oslandia 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 "qgslayoutpolylinewidget.h"
#include "qgssymbolselectordialog.h"
#include "qgsstyle.h"
#include "qgssymbollayerutils.h"
#include "qgslayoutitemregistry.h"
#include "qgslayout.h"

QgsLayoutPolylineWidget::QgsLayoutPolylineWidget( QgsLayoutItemPolyline *polyline )
: QgsLayoutItemBaseWidget( nullptr, polyline )
, mPolyline( polyline )
{
setupUi( this );
setPanelTitle( tr( "Polyline properties" ) );

//add widget for general composer item properties
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polyline );
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
mItemPropertiesWidget->showBackgroundGroup( false );
mItemPropertiesWidget->showFrameGroup( false );
mainLayout->addWidget( mItemPropertiesWidget );

mLineStyleButton->setSymbolType( QgsSymbol::Line );
connect( mLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolylineWidget::symbolChanged );

if ( mPolyline )
{
connect( mPolyline, &QgsLayoutObject::changed, this, &QgsLayoutPolylineWidget::setGuiElementValues );
}
setGuiElementValues();

#if 0 //TODO
mShapeStyleButton->setLayer( atlasCoverageLayer() );
#endif
}

bool QgsLayoutPolylineWidget::setNewItem( QgsLayoutItem *item )
{
if ( item->type() != QgsLayoutItemRegistry::LayoutPolyline )
return false;

mPolyline = qobject_cast< QgsLayoutItemPolyline * >( item );
mItemPropertiesWidget->setItem( mPolyline );

setGuiElementValues();

return true;
}


void QgsLayoutPolylineWidget::setGuiElementValues()
{
if ( !mPolyline )
return;

whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
}

void QgsLayoutPolylineWidget::symbolChanged()
{
if ( !mPolyline )
return;

mPolyline->layout()->undoStack()->beginCommand( mPolyline, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle );
mPolyline->setSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
mPolyline->layout()->undoStack()->endCommand();
}
50 changes: 50 additions & 0 deletions src/app/layout/qgslayoutpolylinewidget.h
@@ -0,0 +1,50 @@
/***************************************************************************
qgslayoutpolylinewidget.h
begin : March 2016
copyright : (C) 2016 Paul Blottiere, Oslandia
email : paul dot blottiere at oslandia 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 QGSLAYOUTPOLYLINEWIDGET_H
#define QGSLAYOUTPOLYLINEWIDGET_H

#include "ui_qgslayoutpolylinewidgetbase.h"
#include "qgslayoutitemwidget.h"
#include "qgslayoutitempolyline.h"

/**
* Input widget for QgsLayoutItemPolyline
*/
class QgsLayoutPolylineWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutPolylineWidgetBase
{
Q_OBJECT
public:
explicit QgsLayoutPolylineWidget( QgsLayoutItemPolyline *polyline );

protected:

bool setNewItem( QgsLayoutItem *item ) override;

private:
QgsLayoutItemPolyline *mPolyline = nullptr;
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;

private slots:

//! Sets the GUI elements to the currentValues of mComposerShape
void setGuiElementValues();

private slots:
void symbolChanged();
};

#endif // QGSLAYOUTPOLYLINEWIDGET_H

0 comments on commit d92b067

Please sign in to comment.