Skip to content

Commit 51a7efb

Browse files
committedJan 5, 2018
Nicer ui widgets for sections, add missing control for
disabling body sections
1 parent d2c880a commit 51a7efb

19 files changed

+543
-153
lines changed
 

‎python/core/layout/qgsreportsectionfieldgroup.sip

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ Note that ownership is not transferred to ``parent``.
4343
Returns the body layout for the section.
4444

4545
.. seealso:: :py:func:`setBody()`
46+
47+
.. seealso:: :py:func:`bodyEnabled()`
48+
49+
.. seealso:: :py:func:`setBodyEnabled()`
4650
%End
4751

4852
void setBody( QgsLayout *body /Transfer/ );
@@ -51,8 +55,35 @@ Sets the ``body`` layout for the section. Ownership of ``body``
5155
is transferred to the report section.
5256

5357
.. seealso:: :py:func:`body()`
58+
59+
.. seealso:: :py:func:`bodyEnabled()`
60+
61+
.. seealso:: :py:func:`setBodyEnabled()`
5462
%End
5563

64+
bool bodyEnabled() const;
65+
%Docstring
66+
Returns true if the body for the section is enabled.
67+
68+
.. seealso:: :py:func:`setBodyEnabled()`
69+
70+
.. seealso:: :py:func:`body()`
71+
72+
.. seealso:: :py:func:`setBody()`
73+
%End
74+
75+
void setBodyEnabled( bool enabled );
76+
%Docstring
77+
Sets whether the body for the section is ``enabled``.
78+
79+
.. seealso:: :py:func:`bodyEnabled()`
80+
81+
.. seealso:: :py:func:`body()`
82+
83+
.. seealso:: :py:func:`setBody()`
84+
%End
85+
86+
5687
QgsVectorLayer *layer();
5788
%Docstring
5889
Returns the vector layer associated with this section.

‎python/core/layout/qgsreportsectionlayout.sip

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Note that ownership is not transferred to ``parent``.
4141
Returns the body layout for the section.
4242

4343
.. seealso:: :py:func:`setBody()`
44+
45+
.. seealso:: :py:func:`bodyEnabled()`
46+
47+
.. seealso:: :py:func:`setBodyEnabled()`
4448
%End
4549

4650
void setBody( QgsLayout *body /Transfer/ );
@@ -49,6 +53,32 @@ Sets the ``body`` layout for the section. Ownership of ``body``
4953
is transferred to the report section.
5054

5155
.. seealso:: :py:func:`body()`
56+
57+
.. seealso:: :py:func:`bodyEnabled()`
58+
59+
.. seealso:: :py:func:`setBodyEnabled()`
60+
%End
61+
62+
bool bodyEnabled() const;
63+
%Docstring
64+
Returns true if the body for the section is enabled.
65+
66+
.. seealso:: :py:func:`setBodyEnabled()`
67+
68+
.. seealso:: :py:func:`body()`
69+
70+
.. seealso:: :py:func:`setBody()`
71+
%End
72+
73+
void setBodyEnabled( bool enabled );
74+
%Docstring
75+
Sets whether the body for the section is ``enabled``.
76+
77+
.. seealso:: :py:func:`bodyEnabled()`
78+
79+
.. seealso:: :py:func:`body()`
80+
81+
.. seealso:: :py:func:`setBody()`
5282
%End
5383

5484
virtual QgsReportSectionLayout *clone() const /Factory/;

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ SET(QGIS_APP_SRCS
208208
layout/qgsreportlayoutsectionwidget.cpp
209209
layout/qgsreportorganizerwidget.cpp
210210
layout/qgsreportsectionmodel.cpp
211+
layout/qgsreportsectionwidget.cpp
211212

212213
locator/qgsinbuiltlocatorfilters.cpp
213214
locator/qgslocatoroptionswidget.cpp
@@ -431,6 +432,7 @@ SET (QGIS_APP_MOC_HDRS
431432
layout/qgsreportlayoutsectionwidget.h
432433
layout/qgsreportorganizerwidget.h
433434
layout/qgsreportsectionmodel.h
435+
layout/qgsreportsectionwidget.h
434436

435437
locator/qgsinbuiltlocatorfilters.h
436438
locator/qgslocatoroptionswidget.h

‎src/app/layout/qgsreportfieldgroupsectionwidget.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,70 @@ QgsReportSectionFieldGroupWidget::QgsReportSectionFieldGroupWidget( QWidget *par
2929
mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
3030
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, mFieldComboBox, &QgsFieldComboBox::setLayer );
3131
connect( mButtonEditBody, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editBody );
32+
connect( mButtonEditHeader, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editHeader );
33+
connect( mButtonEditFooter, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editFooter );
3234

3335
mLayerComboBox->setLayer( section->layer() );
3436
mFieldComboBox->setField( section->field() );
3537
mSortAscendingCheckBox->setChecked( section->sortAscending() );
3638

39+
mCheckShowHeader->setChecked( section->headerEnabled() );
40+
mCheckShowFooter->setChecked( section->footerEnabled() );
41+
mCheckShowBody->setChecked( section->bodyEnabled() );
42+
3743
connect( mSortAscendingCheckBox, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::sortAscendingToggled );
3844
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsReportSectionFieldGroupWidget::setLayer );
3945
connect( mFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsReportSectionFieldGroupWidget::setField );
46+
connect( mCheckShowHeader, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::toggleHeader );
47+
connect( mCheckShowFooter, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::toggleFooter );
48+
connect( mCheckShowBody, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::toggleBody );
49+
}
50+
51+
void QgsReportSectionFieldGroupWidget::toggleHeader( bool enabled )
52+
{
53+
mSection->setHeaderEnabled( enabled );
54+
}
55+
56+
void QgsReportSectionFieldGroupWidget::toggleFooter( bool enabled )
57+
{
58+
mSection->setFooterEnabled( enabled );
59+
}
60+
61+
void QgsReportSectionFieldGroupWidget::editHeader()
62+
{
63+
if ( !mSection->header() )
64+
{
65+
std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( mSection->project() );
66+
header->initializeDefaults();
67+
mSection->setHeader( header.release() );
68+
}
69+
70+
if ( mSection->header() )
71+
{
72+
mSection->header()->reportContext().setLayer( mSection->layer() );
73+
mDesigner->setCurrentLayout( mSection->header() );
74+
}
75+
}
76+
77+
void QgsReportSectionFieldGroupWidget::editFooter()
78+
{
79+
if ( !mSection->footer() )
80+
{
81+
std::unique_ptr< QgsLayout > footer = qgis::make_unique< QgsLayout >( mSection->project() );
82+
footer->initializeDefaults();
83+
mSection->setFooter( footer.release() );
84+
}
85+
86+
if ( mSection->footer() )
87+
{
88+
mSection->footer()->reportContext().setLayer( mSection->layer() );
89+
mDesigner->setCurrentLayout( mSection->footer() );
90+
}
91+
}
92+
93+
void QgsReportSectionFieldGroupWidget::toggleBody( bool enabled )
94+
{
95+
mSection->setBodyEnabled( enabled );
4096
}
4197

4298
void QgsReportSectionFieldGroupWidget::editBody()

‎src/app/layout/qgsreportfieldgroupsectionwidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class QgsReportSectionFieldGroupWidget: public QWidget, private Ui::QgsReportWid
3030

3131
private slots:
3232

33+
void toggleHeader( bool enabled );
34+
void toggleFooter( bool enabled );
35+
void editHeader();
36+
void editFooter();
37+
void toggleBody( bool enabled );
3338
void editBody();
3439
void sortAscendingToggled( bool checked );
3540
void setLayer( QgsMapLayer *layer );

‎src/app/layout/qgsreportlayoutsectionwidget.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,61 @@ QgsReportLayoutSectionWidget::QgsReportLayoutSectionWidget( QWidget *parent, Qgs
2727
setupUi( this );
2828

2929
connect( mButtonEditBody, &QPushButton::clicked, this, &QgsReportLayoutSectionWidget::editBody );
30+
connect( mButtonEditHeader, &QPushButton::clicked, this, &QgsReportLayoutSectionWidget::editHeader );
31+
connect( mButtonEditFooter, &QPushButton::clicked, this, &QgsReportLayoutSectionWidget::editFooter );
32+
33+
mCheckShowHeader->setChecked( section->headerEnabled() );
34+
mCheckShowFooter->setChecked( section->footerEnabled() );
35+
mCheckShowBody->setChecked( section->bodyEnabled() );
36+
37+
connect( mCheckShowHeader, &QCheckBox::toggled, this, &QgsReportLayoutSectionWidget::toggleHeader );
38+
connect( mCheckShowFooter, &QCheckBox::toggled, this, &QgsReportLayoutSectionWidget::toggleFooter );
39+
connect( mCheckShowBody, &QCheckBox::toggled, this, &QgsReportLayoutSectionWidget::toggleBody );
40+
}
41+
42+
void QgsReportLayoutSectionWidget::toggleHeader( bool enabled )
43+
{
44+
mSection->setHeaderEnabled( enabled );
45+
}
46+
47+
void QgsReportLayoutSectionWidget::toggleFooter( bool enabled )
48+
{
49+
mSection->setFooterEnabled( enabled );
50+
}
51+
52+
void QgsReportLayoutSectionWidget::editHeader()
53+
{
54+
if ( !mSection->header() )
55+
{
56+
std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( mSection->project() );
57+
header->initializeDefaults();
58+
mSection->setHeader( header.release() );
59+
}
60+
61+
if ( mSection->header() )
62+
{
63+
mDesigner->setCurrentLayout( mSection->header() );
64+
}
65+
}
66+
67+
void QgsReportLayoutSectionWidget::editFooter()
68+
{
69+
if ( !mSection->footer() )
70+
{
71+
std::unique_ptr< QgsLayout > footer = qgis::make_unique< QgsLayout >( mSection->project() );
72+
footer->initializeDefaults();
73+
mSection->setFooter( footer.release() );
74+
}
75+
76+
if ( mSection->footer() )
77+
{
78+
mDesigner->setCurrentLayout( mSection->footer() );
79+
}
80+
}
81+
82+
void QgsReportLayoutSectionWidget::toggleBody( bool enabled )
83+
{
84+
mSection->setBodyEnabled( enabled );
3085
}
3186

3287
void QgsReportLayoutSectionWidget::editBody()

‎src/app/layout/qgsreportlayoutsectionwidget.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class QgsReportLayoutSectionWidget: public QWidget, private Ui::QgsReportWidgetL
3030

3131
private slots:
3232

33+
void toggleHeader( bool enabled );
34+
void toggleFooter( bool enabled );
35+
void editHeader();
36+
void editFooter();
37+
void toggleBody( bool enabled );
3338
void editBody();
3439

3540
private:

‎src/app/layout/qgsreportorganizerwidget.cpp

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgslayout.h"
2323
#include "qgslayoutdesignerdialog.h"
2424
#include "qgsreportlayoutsectionwidget.h"
25+
#include "qgsreportsectionwidget.h"
2526
#include "qgsreportfieldgroupsectionwidget.h"
2627
#include <QMenu>
2728
#include <QMessageBox>
@@ -61,10 +62,6 @@ QgsReportOrganizerWidget::QgsReportOrganizerWidget( QWidget *parent, QgsLayoutDe
6162
addMenu->addAction( fieldGroupSection );
6263
connect( fieldGroupSection, &QAction::triggered, this, &QgsReportOrganizerWidget::addFieldGroupSection );
6364

64-
connect( mCheckShowHeader, &QCheckBox::toggled, this, &QgsReportOrganizerWidget::toggleHeader );
65-
connect( mCheckShowFooter, &QCheckBox::toggled, this, &QgsReportOrganizerWidget::toggleFooter );
66-
connect( mButtonEditHeader, &QPushButton::clicked, this, &QgsReportOrganizerWidget::editHeader );
67-
connect( mButtonEditFooter, &QPushButton::clicked, this, &QgsReportOrganizerWidget::editFooter );
6865
connect( mViewSections->selectionModel(), &QItemSelectionModel::currentChanged, this, &QgsReportOrganizerWidget::selectionChanged );
6966

7067
mButtonAddSection->setMenu( addMenu );
@@ -109,63 +106,12 @@ void QgsReportOrganizerWidget::removeSection()
109106
mSectionModel->removeRow( mViewSections->currentIndex().row(), mViewSections->currentIndex().parent() );
110107
}
111108

112-
void QgsReportOrganizerWidget::toggleHeader( bool enabled )
113-
{
114-
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
115-
if ( !parent )
116-
parent = mReport;
117-
parent->setHeaderEnabled( enabled );
118-
}
119-
120-
void QgsReportOrganizerWidget::toggleFooter( bool enabled )
121-
{
122-
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
123-
if ( !parent )
124-
parent = mReport;
125-
parent->setFooterEnabled( enabled );
126-
}
127-
128-
void QgsReportOrganizerWidget::editHeader()
129-
{
130-
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
131-
if ( !parent )
132-
parent = mReport;
133-
134-
if ( !parent->header() )
135-
{
136-
std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( mReport->layoutProject() );
137-
header->initializeDefaults();
138-
parent->setHeader( header.release() );
139-
}
140-
141-
mDesigner->setCurrentLayout( parent->header() );
142-
}
143-
144-
void QgsReportOrganizerWidget::editFooter()
145-
{
146-
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
147-
if ( !parent )
148-
parent = mReport;
149-
150-
if ( !parent->footer() )
151-
{
152-
std::unique_ptr< QgsLayout > footer = qgis::make_unique< QgsLayout >( mReport->layoutProject() );
153-
footer->initializeDefaults();
154-
parent->setFooter( footer.release() );
155-
}
156-
157-
mDesigner->setCurrentLayout( parent->footer() );
158-
}
159-
160109
void QgsReportOrganizerWidget::selectionChanged( const QModelIndex &current, const QModelIndex & )
161110
{
162111
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( current );
163112
if ( !parent )
164113
parent = mReport;
165114

166-
whileBlocking( mCheckShowHeader )->setChecked( parent->headerEnabled() );
167-
whileBlocking( mCheckShowFooter )->setChecked( parent->footerEnabled() );
168-
169115
delete mConfigWidget;
170116
if ( QgsReportSectionLayout *section = dynamic_cast< QgsReportSectionLayout * >( parent ) )
171117
{
@@ -179,6 +125,12 @@ void QgsReportOrganizerWidget::selectionChanged( const QModelIndex &current, con
179125
mSettingsFrame->layout()->addWidget( widget );
180126
mConfigWidget = widget;
181127
}
128+
else if ( QgsReport *section = dynamic_cast< QgsReport * >( parent ) )
129+
{
130+
QgsReportSectionWidget *widget = new QgsReportSectionWidget( this, mDesigner, section );
131+
mSettingsFrame->layout()->addWidget( widget );
132+
mConfigWidget = widget;
133+
}
182134
else
183135
{
184136
mConfigWidget = nullptr;

‎src/app/layout/qgsreportorganizerwidget.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrga
3939
void addLayoutSection();
4040
void addFieldGroupSection();
4141
void removeSection();
42-
void toggleHeader( bool enabled );
43-
void toggleFooter( bool enabled );
44-
void editHeader();
45-
void editFooter();
4642
void selectionChanged( const QModelIndex &current, const QModelIndex &previous );
4743

4844
private:

0 commit comments

Comments
 (0)
Please sign in to comment.