Skip to content
Permalink
Browse files

Nicer ui widgets for sections, add missing control for

disabling body sections
  • Loading branch information
nyalldawson committed Jan 2, 2018
1 parent d2c880a commit 51a7efbe4b5f1d940d55f8baa1c7df82ec371385
@@ -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/ );
@@ -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.
@@ -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/ );
@@ -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/;
@@ -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
@@ -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
@@ -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()
@@ -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 );
@@ -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()
@@ -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:
@@ -22,6 +22,7 @@
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"
#include "qgsreportlayoutsectionwidget.h"
#include "qgsreportsectionwidget.h"
#include "qgsreportfieldgroupsectionwidget.h"
#include <QMenu>
#include <QMessageBox>
@@ -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 );
@@ -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 ) )
{
@@ -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;
@@ -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:

0 comments on commit 51a7efb

Please sign in to comment.
You can’t perform that action at this time.