Skip to content

Commit

Permalink
Nicer ui widgets for sections, add missing control for
Browse files Browse the repository at this point in the history
disabling body sections
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent d2c880a commit 51a7efb
Show file tree
Hide file tree
Showing 19 changed files with 543 additions and 153 deletions.
31 changes: 31 additions & 0 deletions python/core/layout/qgsreportsectionfieldgroup.sip
Expand Up @@ -43,6 +43,10 @@ Note that ownership is not transferred to ``parent``.
Returns the body layout for the section.

.. seealso:: :py:func:`setBody()`

.. seealso:: :py:func:`bodyEnabled()`

.. seealso:: :py:func:`setBodyEnabled()`
%End

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

.. seealso:: :py:func:`body()`

.. seealso:: :py:func:`bodyEnabled()`

.. seealso:: :py:func:`setBodyEnabled()`
%End

bool bodyEnabled() const;
%Docstring
Returns true if the body for the section is enabled.

.. seealso:: :py:func:`setBodyEnabled()`

.. seealso:: :py:func:`body()`

.. seealso:: :py:func:`setBody()`
%End

void setBodyEnabled( bool enabled );
%Docstring
Sets whether the body for the section is ``enabled``.

.. seealso:: :py:func:`bodyEnabled()`

.. seealso:: :py:func:`body()`

.. seealso:: :py:func:`setBody()`
%End


QgsVectorLayer *layer();
%Docstring
Returns the vector layer associated with this section.
Expand Down
30 changes: 30 additions & 0 deletions python/core/layout/qgsreportsectionlayout.sip
Expand Up @@ -41,6 +41,10 @@ Note that ownership is not transferred to ``parent``.
Returns the body layout for the section.

.. seealso:: :py:func:`setBody()`

.. seealso:: :py:func:`bodyEnabled()`

.. seealso:: :py:func:`setBodyEnabled()`
%End

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

.. seealso:: :py:func:`body()`

.. seealso:: :py:func:`bodyEnabled()`

.. seealso:: :py:func:`setBodyEnabled()`
%End

bool bodyEnabled() const;
%Docstring
Returns true if the body for the section is enabled.

.. seealso:: :py:func:`setBodyEnabled()`

.. seealso:: :py:func:`body()`

.. seealso:: :py:func:`setBody()`
%End

void setBodyEnabled( bool enabled );
%Docstring
Sets whether the body for the section is ``enabled``.

.. seealso:: :py:func:`bodyEnabled()`

.. seealso:: :py:func:`body()`

.. seealso:: :py:func:`setBody()`
%End

virtual QgsReportSectionLayout *clone() const /Factory/;
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -208,6 +208,7 @@ SET(QGIS_APP_SRCS
layout/qgsreportlayoutsectionwidget.cpp
layout/qgsreportorganizerwidget.cpp
layout/qgsreportsectionmodel.cpp
layout/qgsreportsectionwidget.cpp

locator/qgsinbuiltlocatorfilters.cpp
locator/qgslocatoroptionswidget.cpp
Expand Down Expand Up @@ -431,6 +432,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgsreportlayoutsectionwidget.h
layout/qgsreportorganizerwidget.h
layout/qgsreportsectionmodel.h
layout/qgsreportsectionwidget.h

locator/qgsinbuiltlocatorfilters.h
locator/qgslocatoroptionswidget.h
Expand Down
56 changes: 56 additions & 0 deletions src/app/layout/qgsreportfieldgroupsectionwidget.cpp
Expand Up @@ -29,14 +29,70 @@ QgsReportSectionFieldGroupWidget::QgsReportSectionFieldGroupWidget( QWidget *par
mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, mFieldComboBox, &QgsFieldComboBox::setLayer );
connect( mButtonEditBody, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editBody );
connect( mButtonEditHeader, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editHeader );
connect( mButtonEditFooter, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editFooter );

mLayerComboBox->setLayer( section->layer() );
mFieldComboBox->setField( section->field() );
mSortAscendingCheckBox->setChecked( section->sortAscending() );

mCheckShowHeader->setChecked( section->headerEnabled() );
mCheckShowFooter->setChecked( section->footerEnabled() );
mCheckShowBody->setChecked( section->bodyEnabled() );

connect( mSortAscendingCheckBox, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::sortAscendingToggled );
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsReportSectionFieldGroupWidget::setLayer );
connect( mFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsReportSectionFieldGroupWidget::setField );
connect( mCheckShowHeader, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::toggleHeader );
connect( mCheckShowFooter, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::toggleFooter );
connect( mCheckShowBody, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::toggleBody );
}

void QgsReportSectionFieldGroupWidget::toggleHeader( bool enabled )
{
mSection->setHeaderEnabled( enabled );
}

void QgsReportSectionFieldGroupWidget::toggleFooter( bool enabled )
{
mSection->setFooterEnabled( enabled );
}

void QgsReportSectionFieldGroupWidget::editHeader()
{
if ( !mSection->header() )
{
std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( mSection->project() );
header->initializeDefaults();
mSection->setHeader( header.release() );
}

if ( mSection->header() )
{
mSection->header()->reportContext().setLayer( mSection->layer() );
mDesigner->setCurrentLayout( mSection->header() );
}
}

void QgsReportSectionFieldGroupWidget::editFooter()
{
if ( !mSection->footer() )
{
std::unique_ptr< QgsLayout > footer = qgis::make_unique< QgsLayout >( mSection->project() );
footer->initializeDefaults();
mSection->setFooter( footer.release() );
}

if ( mSection->footer() )
{
mSection->footer()->reportContext().setLayer( mSection->layer() );
mDesigner->setCurrentLayout( mSection->footer() );
}
}

void QgsReportSectionFieldGroupWidget::toggleBody( bool enabled )
{
mSection->setBodyEnabled( enabled );
}

void QgsReportSectionFieldGroupWidget::editBody()
Expand Down
5 changes: 5 additions & 0 deletions src/app/layout/qgsreportfieldgroupsectionwidget.h
Expand Up @@ -30,6 +30,11 @@ class QgsReportSectionFieldGroupWidget: public QWidget, private Ui::QgsReportWid

private slots:

void toggleHeader( bool enabled );
void toggleFooter( bool enabled );
void editHeader();
void editFooter();
void toggleBody( bool enabled );
void editBody();
void sortAscendingToggled( bool checked );
void setLayer( QgsMapLayer *layer );
Expand Down
55 changes: 55 additions & 0 deletions src/app/layout/qgsreportlayoutsectionwidget.cpp
Expand Up @@ -27,6 +27,61 @@ QgsReportLayoutSectionWidget::QgsReportLayoutSectionWidget( QWidget *parent, Qgs
setupUi( this );

connect( mButtonEditBody, &QPushButton::clicked, this, &QgsReportLayoutSectionWidget::editBody );
connect( mButtonEditHeader, &QPushButton::clicked, this, &QgsReportLayoutSectionWidget::editHeader );
connect( mButtonEditFooter, &QPushButton::clicked, this, &QgsReportLayoutSectionWidget::editFooter );

mCheckShowHeader->setChecked( section->headerEnabled() );
mCheckShowFooter->setChecked( section->footerEnabled() );
mCheckShowBody->setChecked( section->bodyEnabled() );

connect( mCheckShowHeader, &QCheckBox::toggled, this, &QgsReportLayoutSectionWidget::toggleHeader );
connect( mCheckShowFooter, &QCheckBox::toggled, this, &QgsReportLayoutSectionWidget::toggleFooter );
connect( mCheckShowBody, &QCheckBox::toggled, this, &QgsReportLayoutSectionWidget::toggleBody );
}

void QgsReportLayoutSectionWidget::toggleHeader( bool enabled )
{
mSection->setHeaderEnabled( enabled );
}

void QgsReportLayoutSectionWidget::toggleFooter( bool enabled )
{
mSection->setFooterEnabled( enabled );
}

void QgsReportLayoutSectionWidget::editHeader()
{
if ( !mSection->header() )
{
std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( mSection->project() );
header->initializeDefaults();
mSection->setHeader( header.release() );
}

if ( mSection->header() )
{
mDesigner->setCurrentLayout( mSection->header() );
}
}

void QgsReportLayoutSectionWidget::editFooter()
{
if ( !mSection->footer() )
{
std::unique_ptr< QgsLayout > footer = qgis::make_unique< QgsLayout >( mSection->project() );
footer->initializeDefaults();
mSection->setFooter( footer.release() );
}

if ( mSection->footer() )
{
mDesigner->setCurrentLayout( mSection->footer() );
}
}

void QgsReportLayoutSectionWidget::toggleBody( bool enabled )
{
mSection->setBodyEnabled( enabled );
}

void QgsReportLayoutSectionWidget::editBody()
Expand Down
5 changes: 5 additions & 0 deletions src/app/layout/qgsreportlayoutsectionwidget.h
Expand Up @@ -30,6 +30,11 @@ class QgsReportLayoutSectionWidget: public QWidget, private Ui::QgsReportWidgetL

private slots:

void toggleHeader( bool enabled );
void toggleFooter( bool enabled );
void editHeader();
void editFooter();
void toggleBody( bool enabled );
void editBody();

private:
Expand Down
62 changes: 7 additions & 55 deletions src/app/layout/qgsreportorganizerwidget.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"
#include "qgsreportlayoutsectionwidget.h"
#include "qgsreportsectionwidget.h"
#include "qgsreportfieldgroupsectionwidget.h"
#include <QMenu>
#include <QMessageBox>
Expand Down Expand Up @@ -61,10 +62,6 @@ QgsReportOrganizerWidget::QgsReportOrganizerWidget( QWidget *parent, QgsLayoutDe
addMenu->addAction( fieldGroupSection );
connect( fieldGroupSection, &QAction::triggered, this, &QgsReportOrganizerWidget::addFieldGroupSection );

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

mButtonAddSection->setMenu( addMenu );
Expand Down Expand Up @@ -109,63 +106,12 @@ void QgsReportOrganizerWidget::removeSection()
mSectionModel->removeRow( mViewSections->currentIndex().row(), mViewSections->currentIndex().parent() );
}

void QgsReportOrganizerWidget::toggleHeader( bool enabled )
{
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
if ( !parent )
parent = mReport;
parent->setHeaderEnabled( enabled );
}

void QgsReportOrganizerWidget::toggleFooter( bool enabled )
{
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
if ( !parent )
parent = mReport;
parent->setFooterEnabled( enabled );
}

void QgsReportOrganizerWidget::editHeader()
{
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
if ( !parent )
parent = mReport;

if ( !parent->header() )
{
std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( mReport->layoutProject() );
header->initializeDefaults();
parent->setHeader( header.release() );
}

mDesigner->setCurrentLayout( parent->header() );
}

void QgsReportOrganizerWidget::editFooter()
{
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( mViewSections->currentIndex() );
if ( !parent )
parent = mReport;

if ( !parent->footer() )
{
std::unique_ptr< QgsLayout > footer = qgis::make_unique< QgsLayout >( mReport->layoutProject() );
footer->initializeDefaults();
parent->setFooter( footer.release() );
}

mDesigner->setCurrentLayout( parent->footer() );
}

void QgsReportOrganizerWidget::selectionChanged( const QModelIndex &current, const QModelIndex & )
{
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( current );
if ( !parent )
parent = mReport;

whileBlocking( mCheckShowHeader )->setChecked( parent->headerEnabled() );
whileBlocking( mCheckShowFooter )->setChecked( parent->footerEnabled() );

delete mConfigWidget;
if ( QgsReportSectionLayout *section = dynamic_cast< QgsReportSectionLayout * >( parent ) )
{
Expand All @@ -179,6 +125,12 @@ void QgsReportOrganizerWidget::selectionChanged( const QModelIndex &current, con
mSettingsFrame->layout()->addWidget( widget );
mConfigWidget = widget;
}
else if ( QgsReport *section = dynamic_cast< QgsReport * >( parent ) )
{
QgsReportSectionWidget *widget = new QgsReportSectionWidget( this, mDesigner, section );
mSettingsFrame->layout()->addWidget( widget );
mConfigWidget = widget;
}
else
{
mConfigWidget = nullptr;
Expand Down
4 changes: 0 additions & 4 deletions src/app/layout/qgsreportorganizerwidget.h
Expand Up @@ -39,10 +39,6 @@ class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrga
void addLayoutSection();
void addFieldGroupSection();
void removeSection();
void toggleHeader( bool enabled );
void toggleFooter( bool enabled );
void editHeader();
void editFooter();
void selectionChanged( const QModelIndex &current, const QModelIndex &previous );

private:
Expand Down

0 comments on commit 51a7efb

Please sign in to comment.