Skip to content

Commit d92b067

Browse files
committed
Add config widget for polygon/polyline items
1 parent 44fe2a8 commit d92b067

9 files changed

+532
-13
lines changed

src/app/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ SET(QGIS_APP_SRCS
181181
layout/qgslayoutappmenuprovider.cpp
182182
layout/qgslayoutmapwidget.cpp
183183
layout/qgslayoutpagepropertieswidget.cpp
184+
layout/qgslayoutpolygonwidget.cpp
185+
layout/qgslayoutpolylinewidget.cpp
184186
layout/qgslayoutpropertieswidget.cpp
185187
layout/qgslayoutshapewidget.cpp
186188

@@ -379,6 +381,8 @@ SET (QGIS_APP_MOC_HDRS
379381
layout/qgslayoutitemslistview.h
380382
layout/qgslayoutmapwidget.h
381383
layout/qgslayoutpagepropertieswidget.h
384+
layout/qgslayoutpolygonwidget.h
385+
layout/qgslayoutpolylinewidget.h
382386
layout/qgslayoutpropertieswidget.h
383387
layout/qgslayoutshapewidget.h
384388

src/app/layout/qgslayoutapputils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "qgslayoutitemmap.h"
2626
#include "qgslayoutitempolygon.h"
2727
#include "qgslayoutitempolyline.h"
28+
#include "qgslayoutpolygonwidget.h"
29+
#include "qgslayoutpolylinewidget.h"
2830

2931
void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
3032
{
@@ -84,8 +86,7 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
8486
QgsLayoutItemRegistry::LayoutPolygon, QObject::tr( "Polygon" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolygon.svg" ) ),
8587
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
8688
{
87-
return nullptr;
88-
//return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ) );
89+
return new QgsLayoutPolygonWidget( qobject_cast< QgsLayoutItemPolygon * >( item ) );
8990
}, createRubberBand, QStringLiteral( "nodes" ), true );
9091
polygonMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPolygonItem*
9192
{
@@ -101,8 +102,7 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
101102
QgsLayoutItemRegistry::LayoutPolyline, QObject::tr( "Polyline" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolyline.svg" ) ),
102103
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
103104
{
104-
return nullptr;
105-
//return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ) );
105+
return new QgsLayoutPolylineWidget( qobject_cast< QgsLayoutItemPolyline * >( item ) );
106106
}, createRubberBand, QStringLiteral( "nodes" ), true );
107107
polylineMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPathItem*
108108
{
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/***************************************************************************
2+
qgslayoutpolygonwidget.cpp
3+
begin : March 2016
4+
copyright : (C) 2016 Paul Blottiere, Oslandia
5+
email : paul dot blottiere at oslandia dot com
6+
***************************************************************************/
7+
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgslayoutpolygonwidget.h"
18+
#include "qgssymbolselectordialog.h"
19+
#include "qgsstyle.h"
20+
#include "qgslayout.h"
21+
#include "qgssymbollayerutils.h"
22+
#include "qgslayoutitemregistry.h"
23+
24+
QgsLayoutPolygonWidget::QgsLayoutPolygonWidget( QgsLayoutItemPolygon *polygon )
25+
: QgsLayoutItemBaseWidget( nullptr, polygon )
26+
, mPolygon( polygon )
27+
{
28+
setupUi( this );
29+
setPanelTitle( tr( "Polygon properties" ) );
30+
31+
//add widget for general composer item properties
32+
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polygon );
33+
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
34+
mItemPropertiesWidget->showBackgroundGroup( false );
35+
mItemPropertiesWidget->showFrameGroup( false );
36+
mainLayout->addWidget( mItemPropertiesWidget );
37+
38+
mPolygonStyleButton->setSymbolType( QgsSymbol::Fill );
39+
connect( mPolygonStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolygonWidget::symbolChanged );
40+
41+
if ( mPolygon )
42+
{
43+
connect( mPolygon, &QgsLayoutObject::changed, this, &QgsLayoutPolygonWidget::setGuiElementValues );
44+
}
45+
46+
setGuiElementValues();
47+
#if 0 //TODO
48+
mShapeStyleButton->setLayer( atlasCoverageLayer() );
49+
#endif
50+
}
51+
52+
bool QgsLayoutPolygonWidget::setNewItem( QgsLayoutItem *item )
53+
{
54+
if ( item->type() != QgsLayoutItemRegistry::LayoutPolygon )
55+
return false;
56+
57+
mPolygon = qobject_cast< QgsLayoutItemPolygon * >( item );
58+
mItemPropertiesWidget->setItem( mPolygon );
59+
60+
setGuiElementValues();
61+
62+
return true;
63+
}
64+
65+
void QgsLayoutPolygonWidget::setGuiElementValues()
66+
{
67+
if ( !mPolygon )
68+
{
69+
return;
70+
}
71+
72+
whileBlocking( mPolygonStyleButton )->setSymbol( mPolygon->symbol()->clone() );
73+
}
74+
75+
void QgsLayoutPolygonWidget::symbolChanged()
76+
{
77+
if ( !mPolygon )
78+
return;
79+
80+
mPolygon->layout()->undoStack()->beginCommand( mPolygon, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle );
81+
mPolygon->setSymbol( mPolygonStyleButton->clonedSymbol<QgsFillSymbol>() );
82+
mPolygon->layout()->undoStack()->endCommand();
83+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/***************************************************************************
2+
qgslayoutpolygonwidget.h
3+
begin : March 2016
4+
copyright : (C) 2016 Paul Blottiere, Oslandia
5+
email : paul dot blottiere at oslandia dot com
6+
***************************************************************************/
7+
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSLAYOUTPOLYGONWIDGET_H
18+
#define QGSLAYOUTPOLYGONWIDGET_H
19+
20+
#include "ui_qgslayoutpolygonwidgetbase.h"
21+
#include "qgslayoutitemwidget.h"
22+
#include "qgslayoutitempolygon.h"
23+
24+
/**
25+
* Input widget for QgsLayoutItemPolygon
26+
*/
27+
class QgsLayoutPolygonWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutPolygonWidgetBase
28+
{
29+
Q_OBJECT
30+
public:
31+
explicit QgsLayoutPolygonWidget( QgsLayoutItemPolygon *polygon );
32+
33+
protected:
34+
35+
bool setNewItem( QgsLayoutItem *item ) override;
36+
37+
private:
38+
QgsLayoutItemPolygon *mPolygon = nullptr;
39+
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;
40+
41+
//! Sets the GUI elements to the currentValues of mComposerShape
42+
void setGuiElementValues();
43+
44+
private slots:
45+
void symbolChanged();
46+
};
47+
48+
#endif // QGSLAYOUTPOLYGONWIDGET_H
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/***************************************************************************
2+
qgslayoutpolylinewidget.cpp
3+
begin : March 2016
4+
copyright : (C) 2016 Paul Blottiere, Oslandia
5+
email : paul dot blottiere at oslandia dot com
6+
***************************************************************************/
7+
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgslayoutpolylinewidget.h"
18+
#include "qgssymbolselectordialog.h"
19+
#include "qgsstyle.h"
20+
#include "qgssymbollayerutils.h"
21+
#include "qgslayoutitemregistry.h"
22+
#include "qgslayout.h"
23+
24+
QgsLayoutPolylineWidget::QgsLayoutPolylineWidget( QgsLayoutItemPolyline *polyline )
25+
: QgsLayoutItemBaseWidget( nullptr, polyline )
26+
, mPolyline( polyline )
27+
{
28+
setupUi( this );
29+
setPanelTitle( tr( "Polyline properties" ) );
30+
31+
//add widget for general composer item properties
32+
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, polyline );
33+
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
34+
mItemPropertiesWidget->showBackgroundGroup( false );
35+
mItemPropertiesWidget->showFrameGroup( false );
36+
mainLayout->addWidget( mItemPropertiesWidget );
37+
38+
mLineStyleButton->setSymbolType( QgsSymbol::Line );
39+
connect( mLineStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutPolylineWidget::symbolChanged );
40+
41+
if ( mPolyline )
42+
{
43+
connect( mPolyline, &QgsLayoutObject::changed, this, &QgsLayoutPolylineWidget::setGuiElementValues );
44+
}
45+
setGuiElementValues();
46+
47+
#if 0 //TODO
48+
mShapeStyleButton->setLayer( atlasCoverageLayer() );
49+
#endif
50+
}
51+
52+
bool QgsLayoutPolylineWidget::setNewItem( QgsLayoutItem *item )
53+
{
54+
if ( item->type() != QgsLayoutItemRegistry::LayoutPolyline )
55+
return false;
56+
57+
mPolyline = qobject_cast< QgsLayoutItemPolyline * >( item );
58+
mItemPropertiesWidget->setItem( mPolyline );
59+
60+
setGuiElementValues();
61+
62+
return true;
63+
}
64+
65+
66+
void QgsLayoutPolylineWidget::setGuiElementValues()
67+
{
68+
if ( !mPolyline )
69+
return;
70+
71+
whileBlocking( mLineStyleButton )->setSymbol( mPolyline->symbol()->clone() );
72+
}
73+
74+
void QgsLayoutPolylineWidget::symbolChanged()
75+
{
76+
if ( !mPolyline )
77+
return;
78+
79+
mPolyline->layout()->undoStack()->beginCommand( mPolyline, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle );
80+
mPolyline->setSymbol( mLineStyleButton->clonedSymbol<QgsLineSymbol>() );
81+
mPolyline->layout()->undoStack()->endCommand();
82+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/***************************************************************************
2+
qgslayoutpolylinewidget.h
3+
begin : March 2016
4+
copyright : (C) 2016 Paul Blottiere, Oslandia
5+
email : paul dot blottiere at oslandia dot com
6+
***************************************************************************/
7+
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef QGSLAYOUTPOLYLINEWIDGET_H
18+
#define QGSLAYOUTPOLYLINEWIDGET_H
19+
20+
#include "ui_qgslayoutpolylinewidgetbase.h"
21+
#include "qgslayoutitemwidget.h"
22+
#include "qgslayoutitempolyline.h"
23+
24+
/**
25+
* Input widget for QgsLayoutItemPolyline
26+
*/
27+
class QgsLayoutPolylineWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutPolylineWidgetBase
28+
{
29+
Q_OBJECT
30+
public:
31+
explicit QgsLayoutPolylineWidget( QgsLayoutItemPolyline *polyline );
32+
33+
protected:
34+
35+
bool setNewItem( QgsLayoutItem *item ) override;
36+
37+
private:
38+
QgsLayoutItemPolyline *mPolyline = nullptr;
39+
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;
40+
41+
private slots:
42+
43+
//! Sets the GUI elements to the currentValues of mComposerShape
44+
void setGuiElementValues();
45+
46+
private slots:
47+
void symbolChanged();
48+
};
49+
50+
#endif // QGSLAYOUTPOLYLINEWIDGET_H

0 commit comments

Comments
 (0)