Skip to content

Commit b2414d8

Browse files
committedNov 7, 2017
Start porting item properties widget
1 parent d3836e5 commit b2414d8

15 files changed

+4629
-7
lines changed
 

‎python/core/layout/qgslayoutitem.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
5353
enum UndoCommand
5454
{
5555
UndoIncrementalMove,
56+
UndoStrokeColor,
57+
UndoStrokeWidth,
58+
UndoBackgroundColor,
59+
UndoOpacity,
60+
UndoSetId,
61+
UndoRotation,
5662
};
5763

5864
explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );

‎python/core/layout/qgslayoutobject.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ class QgsLayoutObject: QObject, QgsExpressionContextGenerator
166166
Refreshes the object, causing a recalculation of any property overrides.
167167
%End
168168

169+
signals:
170+
171+
void changed();
172+
%Docstring
173+
Emitted when the object's properties change.
174+
%End
175+
169176
protected:
170177

171178
bool writeObjectPropertiesToElement( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const;

‎python/gui/layout/qgslayoutitemwidget.sip

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,43 @@ class QgsLayoutItemBaseWidget: QgsPanelWidget
9797

9898
};
9999

100+
101+
class QgsLayoutItemPropertiesWidget: QWidget
102+
{
103+
%Docstring
104+
A widget for controlling the common properties of layout items (e.g. position and size, background, stroke, frame).
105+
This widget can be embedded into other layout item widgets.
106+
.. versionadded:: 3.0
107+
%End
108+
109+
%TypeHeaderCode
110+
#include "qgslayoutitemwidget.h"
111+
%End
112+
public:
113+
QgsLayoutItemPropertiesWidget( QWidget *parent, QgsLayoutItem *item );
114+
115+
QgsLayoutItem::ReferencePoint positionMode() const;
116+
%Docstring
117+
:rtype: QgsLayoutItem.ReferencePoint
118+
%End
119+
120+
void showBackgroundGroup( bool showGroup );
121+
122+
void showFrameGroup( bool showGroup );
123+
124+
protected slots:
125+
void initializeDataDefinedButtons();
126+
%Docstring
127+
Initializes data defined buttons to current atlas coverage layer
128+
%End
129+
void populateDataDefinedButtons();
130+
%Docstring
131+
Sets data defined button state to match item
132+
%End
133+
134+
};
135+
136+
100137
/************************************************************************
101138
* This file has been generated automatically from *
102139
* *

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ SET(QGIS_APP_SRCS
178178
layout/qgslayoutdesignerdialog.cpp
179179
layout/qgslayoutguidewidget.cpp
180180
layout/qgslayoutappmenuprovider.cpp
181+
layout/qgslayoutmapwidget.cpp
181182
layout/qgslayoutpagepropertieswidget.cpp
182183
layout/qgslayoutpropertieswidget.cpp
183184

@@ -373,6 +374,7 @@ SET (QGIS_APP_MOC_HDRS
373374
layout/qgslayoutappmenuprovider.h
374375
layout/qgslayoutdesignerdialog.h
375376
layout/qgslayoutguidewidget.h
377+
layout/qgslayoutmapwidget.h
376378
layout/qgslayoutpagepropertieswidget.h
377379
layout/qgslayoutpropertieswidget.h
378380

‎src/app/layout/qgslayoutapputils.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "qgslayoutitemguiregistry.h"
1919
#include "qgslayoutitemregistry.h"
2020
#include "qgslayoutviewrubberband.h"
21+
#include "qgslayoutmapwidget.h"
22+
#include "qgslayoutitemmap.h"
2123

2224
void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
2325
{
@@ -40,7 +42,11 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
4042

4143
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutItem + 1002, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), nullptr, createRubberBand ) );
4244

43-
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutMap, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ), nullptr, createRubberBand ) );
45+
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutMap, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ),
46+
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
47+
{
48+
return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ) );
49+
}, createRubberBand ) );
4450

4551
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutRectangle, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), nullptr, createRubberBand, QStringLiteral( "shapes" ) ) );
4652
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutEllipse, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicCircle.svg" ) ), nullptr, createEllipseBand, QStringLiteral( "shapes" ) ) );

‎src/app/layout/qgslayoutmapwidget.cpp

Lines changed: 1759 additions & 0 deletions
Large diffs are not rendered by default.

‎src/app/layout/qgslayoutmapwidget.h

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
/***************************************************************************
2+
qgslayoutmapwidget.h
3+
----------------------
4+
begin : October 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSLAYOUTMAPWIDGET_H
19+
#define QGSLAYOUTMAPWIDGET_H
20+
21+
#include "ui_qgslayoutmapwidgetbase.h"
22+
#include "qgslayoutitemwidget.h"
23+
24+
class QgsMapLayer;
25+
class QgsLayoutItemMap;
26+
class QgsLayoutMapGrid;
27+
class QgsLayoutMapOverview;
28+
29+
/**
30+
* \ingroup app
31+
* Input widget for the configuration of QgsLayoutItemMap
32+
*/
33+
class QgsLayoutMapWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutMapWidgetBase
34+
{
35+
Q_OBJECT
36+
37+
public:
38+
explicit QgsLayoutMapWidget( QgsLayoutItemMap *item );
39+
40+
public slots:
41+
void mScaleLineEdit_editingFinished();
42+
void mSetToMapCanvasExtentButton_clicked();
43+
void mViewExtentInCanvasButton_clicked();
44+
void mUpdatePreviewButton_clicked();
45+
void mFollowVisibilityPresetCheckBox_stateChanged( int state );
46+
void mKeepLayerListCheckBox_stateChanged( int state );
47+
void mKeepLayerStylesCheckBox_stateChanged( int state );
48+
void mDrawCanvasItemsCheckBox_stateChanged( int state );
49+
void overviewMapChanged( QgsComposerItem *item );
50+
void mOverviewFrameStyleButton_clicked();
51+
void mOverviewBlendModeComboBox_currentIndexChanged( int index );
52+
void mOverviewInvertCheckbox_toggled( bool state );
53+
void mOverviewCenterCheckbox_toggled( bool state );
54+
55+
void mXMinLineEdit_editingFinished();
56+
void mXMaxLineEdit_editingFinished();
57+
void mYMinLineEdit_editingFinished();
58+
void mYMaxLineEdit_editingFinished();
59+
60+
void mAtlasMarginRadio_toggled( bool checked );
61+
62+
void mAtlasCheckBox_toggled( bool checked );
63+
void mAtlasMarginSpinBox_valueChanged( int value );
64+
void mAtlasFixedScaleRadio_toggled( bool checked );
65+
void mAtlasPredefinedScaleRadio_toggled( bool checked );
66+
67+
void mAddGridPushButton_clicked();
68+
void mRemoveGridPushButton_clicked();
69+
void mGridUpButton_clicked();
70+
void mGridDownButton_clicked();
71+
72+
QgsLayoutMapGrid *currentGrid();
73+
void mDrawGridCheckBox_toggled( bool state );
74+
void mGridListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem *previous );
75+
void mGridListWidget_itemChanged( QListWidgetItem *item );
76+
void mGridPropertiesButton_clicked();
77+
78+
//overviews
79+
void mAddOverviewPushButton_clicked();
80+
void mRemoveOverviewPushButton_clicked();
81+
void mOverviewUpButton_clicked();
82+
void mOverviewDownButton_clicked();
83+
QgsLayoutMapOverview *currentOverview();
84+
void mOverviewCheckBox_toggled( bool state );
85+
void mOverviewListWidget_currentItemChanged( QListWidgetItem *current, QListWidgetItem *previous );
86+
void mOverviewListWidget_itemChanged( QListWidgetItem *item );
87+
void setOverviewItemsEnabled( bool enabled );
88+
void setOverviewItems( const QgsLayoutMapOverview *overview );
89+
void blockOverviewItemsSignals( bool block );
90+
91+
protected:
92+
93+
void addPageToToolbox( QWidget *widget, const QString &name );
94+
95+
//! Sets the current composer map values to the GUI elements
96+
virtual void updateGuiElements();
97+
98+
protected slots:
99+
//! Initializes data defined buttons to current atlas coverage layer
100+
void populateDataDefinedButtons();
101+
102+
private slots:
103+
104+
//! Sets the GUI elements to the values of mPicture
105+
void setGuiElementValues();
106+
107+
//! Enables or disables the atlas margin around feature option depending on coverage layer type
108+
void atlasLayerChanged( QgsVectorLayer *layer );
109+
110+
//! Enables or disables the atlas controls when composer atlas is toggled on/off
111+
void compositionAtlasToggled( bool atlasEnabled );
112+
113+
void aboutToShowKeepLayersVisibilityPresetsMenu();
114+
115+
void followVisibilityPresetSelected( int currentIndex );
116+
void keepLayersVisibilityPresetSelected();
117+
118+
void onMapThemesChanged();
119+
120+
void updateOverviewFrameStyleFromWidget();
121+
void cleanUpOverviewFrameStyleSelector( QgsPanelWidget *container );
122+
123+
void mapCrsChanged( const QgsCoordinateReferenceSystem &crs );
124+
125+
private:
126+
QgsLayoutItemMap *mMapItem = nullptr;
127+
128+
//! Sets extent of composer map from line edits
129+
void updateComposerExtentFromGui();
130+
131+
//! Blocks / unblocks the signals of all GUI elements
132+
void blockAllSignals( bool b );
133+
134+
void rotationChanged( double value );
135+
136+
#if 0 //TODO
137+
void handleChangedFrameDisplay( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::DisplayMode mode );
138+
void handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString &text );
139+
void handleChangedAnnotationPosition( QgsComposerMapGrid::BorderSide border, const QString &text );
140+
void handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, QgsComposerMapGrid::AnnotationDirection direction );
141+
#endif
142+
void insertFrameDisplayEntries( QComboBox *c );
143+
void insertAnnotationDisplayEntries( QComboBox *c );
144+
void insertAnnotationPositionEntries( QComboBox *c );
145+
void insertAnnotationDirectionEntries( QComboBox *c );
146+
147+
#if 0 //TODO
148+
void initFrameDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display );
149+
void initAnnotationDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display );
150+
void initAnnotationPositionBox( QComboBox *c, QgsComposerMapGrid::AnnotationPosition pos );
151+
void initAnnotationDirectionBox( QComboBox *c, QgsComposerMapGrid::AnnotationDirection dir );
152+
#endif
153+
//! Enables or disables the atlas margin and predefined scales radio depending on the atlas coverage layer type
154+
void toggleAtlasScalingOptionsByLayerType();
155+
156+
//! Recalculates the bounds for an atlas map when atlas properties change
157+
void updateMapForAtlas();
158+
159+
//! Is there some predefined scales, globally or as project's options ?
160+
bool hasPredefinedScales() const;
161+
162+
QListWidgetItem *addGridListItem( const QString &id, const QString &name );
163+
164+
void loadGridEntries();
165+
166+
QListWidgetItem *addOverviewListItem( const QString &id, const QString &name );
167+
168+
void loadOverviewEntries();
169+
170+
void updateOverviewFrameSymbolMarker( const QgsLayoutMapOverview *overview );
171+
172+
void storeCurrentLayerSet();
173+
174+
};
175+
176+
#endif

‎src/core/layout/qgslayoutitem.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ bool QgsLayoutItem::readXml( const QDomElement &itemElem, const QDomDocument &do
414414
return false;
415415
}
416416

417-
return readPropertiesFromElement( itemElem, doc, context );
417+
bool result = readPropertiesFromElement( itemElem, doc, context );
418+
emit changed();
419+
update();
420+
return result;
418421
}
419422

420423
QgsAbstractLayoutUndoCommand *QgsLayoutItem::createCommand( const QString &text, int id, QUndoCommand *parent )
@@ -475,6 +478,12 @@ void QgsLayoutItem::setFrameJoinStyle( const Qt::PenJoinStyle style )
475478
emit frameChanged();
476479
}
477480

481+
void QgsLayoutItem::setBackgroundEnabled( bool drawBackground )
482+
{
483+
mBackground = drawBackground;
484+
update();
485+
}
486+
478487
void QgsLayoutItem::setBackgroundColor( const QColor &color )
479488
{
480489
mBackgroundColor = color;
@@ -995,14 +1004,14 @@ void QgsLayoutItem::refreshFrame( bool updateItem )
9951004
//data defined stroke color set?
9961005
bool ok = false;
9971006
QColor frameColor = mDataDefinedProperties.valueAsColor( QgsLayoutObject::FrameColor, createExpressionContext(), mFrameColor, &ok );
998-
QPen itemPen = pen();
1007+
QPen itemPen;
9991008
if ( ok )
10001009
{
1001-
itemPen.setColor( frameColor );
1010+
itemPen = QPen( frameColor );
10021011
}
10031012
else
10041013
{
1005-
itemPen.setColor( mFrameColor );
1014+
itemPen = QPen( mFrameColor );
10061015
}
10071016
itemPen.setJoinStyle( mFrameJoinStyle );
10081017

‎src/core/layout/qgslayoutitem.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
8484
enum UndoCommand
8585
{
8686
UndoIncrementalMove = 1, //!< Layout item incremental movement, e.g. as a result of a keypress
87+
UndoStrokeColor, //!< Stroke color adjustment
88+
UndoStrokeWidth, //!< Stroke width adjustment
89+
UndoBackgroundColor, //!< Background color adjustment
90+
UndoOpacity, //!< Opacity adjustment
91+
UndoSetId, //!< Change item ID
92+
UndoRotation, //!< Rotation adjustment
8793
};
8894

8995
/**
@@ -384,7 +390,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
384390
* \see hasBackground()
385391
* \see setBackgroundColor()
386392
*/
387-
void setBackgroundEnabled( bool drawBackground ) { mBackground = drawBackground; }
393+
void setBackgroundEnabled( bool drawBackground );
388394

389395
/**
390396
* Returns the background color for this item. This is only used if hasBackground()

‎src/core/layout/qgslayoutitemgroup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ bool QgsLayoutItemGroup::readXml( const QDomElement &itemElement, const QDomDocu
279279

280280
resetBoundingRect();
281281

282+
emit changed();
282283
return result;
283284
}
284285

‎src/core/layout/qgslayoutobject.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ class CORE_EXPORT QgsLayoutObject: public QObject, public QgsExpressionContextGe
189189
*/
190190
virtual void refresh() {}
191191

192+
signals:
193+
194+
/**
195+
* Emitted when the object's properties change.
196+
*/
197+
void changed();
198+
192199
protected:
193200

194201
/**

‎src/gui/layout/qgslayoutitemwidget.cpp

Lines changed: 737 additions & 1 deletion
Large diffs are not rendered by default.

‎src/gui/layout/qgslayoutitemwidget.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "qgis_gui.h"
1919
#include "qgslayoutobject.h"
2020
#include "qgspanelwidget.h"
21+
#include "qgslayoutitem.h"
22+
#include "ui_qgslayoutitemwidgetbase.h"
2123
#include <QObject>
2224
#include <QPointer>
2325

@@ -147,4 +149,99 @@ class GUI_EXPORT QgsLayoutItemBaseWidget: public QgsPanelWidget
147149
QgsLayoutConfigObject *mConfigObject = nullptr;
148150
};
149151

152+
153+
/**
154+
* \class QgsLayoutItemPropertiesWidget
155+
* \ingroup gui
156+
* A widget for controlling the common properties of layout items (e.g. position and size, background, stroke, frame).
157+
* This widget can be embedded into other layout item widgets.
158+
* \since QGIS 3.0
159+
*/
160+
class GUI_EXPORT QgsLayoutItemPropertiesWidget: public QWidget, private Ui::QgsLayoutItemWidgetBase
161+
{
162+
Q_OBJECT
163+
public:
164+
QgsLayoutItemPropertiesWidget( QWidget *parent, QgsLayoutItem *item );
165+
166+
QgsLayoutItem::ReferencePoint positionMode() const;
167+
168+
void showBackgroundGroup( bool showGroup );
169+
170+
void showFrameGroup( bool showGroup );
171+
172+
protected slots:
173+
//! Initializes data defined buttons to current atlas coverage layer
174+
void initializeDataDefinedButtons();
175+
//! Sets data defined button state to match item
176+
void populateDataDefinedButtons();
177+
178+
private slots:
179+
180+
/**
181+
* Set the frame color
182+
*/
183+
void mFrameColorButton_colorChanged( const QColor &newFrameColor );
184+
185+
/**
186+
* Set the background color
187+
*/
188+
void mBackgroundColorButton_colorChanged( const QColor &newBackgroundColor );
189+
// void on_mTransparencySlider_valueChanged( int value );
190+
// void on_mTransparencySpinBox_valueChanged( int value );
191+
void mStrokeWidthSpinBox_valueChanged( double d );
192+
void strokeUnitChanged( QgsUnitTypes::LayoutUnit unit );
193+
void mFrameGroupBox_toggled( bool state );
194+
void mFrameJoinStyleCombo_currentIndexChanged( int index );
195+
void mBackgroundGroupBox_toggled( bool state );
196+
void mItemIdLineEdit_editingFinished();
197+
198+
//adjust coordinates in line edits
199+
void mPageSpinBox_valueChanged( int );
200+
void mXPosSpin_valueChanged( double );
201+
void mYPosSpin_valueChanged( double );
202+
void mWidthSpin_valueChanged( double );
203+
void mHeightSpin_valueChanged( double );
204+
205+
void mUpperLeftCheckBox_stateChanged( int state );
206+
void mUpperMiddleCheckBox_stateChanged( int state );
207+
void mUpperRightCheckBox_stateChanged( int state );
208+
void mMiddleLeftCheckBox_stateChanged( int state );
209+
void mMiddleCheckBox_stateChanged( int state );
210+
void mMiddleRightCheckBox_stateChanged( int state );
211+
void mLowerLeftCheckBox_stateChanged( int state );
212+
void mLowerMiddleCheckBox_stateChanged( int state );
213+
void mLowerRightCheckBox_stateChanged( int state );
214+
215+
void mBlendModeCombo_currentIndexChanged( int index );
216+
void opacityChanged( double value );
217+
218+
void mItemRotationSpinBox_valueChanged( double val );
219+
void mExcludeFromPrintsCheckBox_toggled( bool checked );
220+
221+
void setValuesForGuiElements();
222+
//sets the values for all position related (x, y, width, height) elements
223+
void setValuesForGuiPositionElements();
224+
//sets the values for all non-position related elements
225+
void setValuesForGuiNonPositionElements();
226+
227+
void variablesChanged();
228+
void updateVariables();
229+
230+
private:
231+
232+
QgsLayoutItem *mItem = nullptr;
233+
QgsLayoutConfigObject *mConfigObject = nullptr;
234+
235+
bool mFreezeXPosSpin = false;
236+
bool mFreezeYPosSpin = false;
237+
bool mFreezeWidthSpin = false;
238+
bool mFreezeHeightSpin = false;
239+
bool mFreezePageSpin = false;
240+
241+
// void changeItemTransparency( int value );
242+
void changeItemPosition();
243+
244+
};
245+
246+
150247
#endif // QGSLAYOUTITEMWIDGET_H

‎src/ui/layout/qgslayoutitemwidgetbase.ui

Lines changed: 861 additions & 0 deletions
Large diffs are not rendered by default.

‎src/ui/layout/qgslayoutmapwidgetbase.ui

Lines changed: 912 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.