Skip to content

Commit

Permalink
More UI work on reports
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent fc9a451 commit 8eb6aa9
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 44 deletions.
4 changes: 4 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -204,6 +204,8 @@ SET(QGIS_APP_SRCS
layout/qgslayoutscalebarwidget.cpp
layout/qgslayoutshapewidget.cpp
layout/qgslayouttablebackgroundcolorsdialog.cpp
layout/qgsreportfieldgroupsectionwidget.cpp
layout/qgsreportlayoutsectionwidget.cpp
layout/qgsreportorganizerwidget.cpp
layout/qgsreportsectionmodel.cpp

Expand Down Expand Up @@ -425,6 +427,8 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutscalebarwidget.h
layout/qgslayoutshapewidget.h
layout/qgslayouttablebackgroundcolorsdialog.h
layout/qgsreportfieldgroupsectionwidget.h
layout/qgsreportlayoutsectionwidget.h
layout/qgsreportorganizerwidget.h
layout/qgsreportsectionmodel.h

Expand Down
77 changes: 77 additions & 0 deletions src/app/layout/qgsreportfieldgroupsectionwidget.cpp
@@ -0,0 +1,77 @@
/***************************************************************************
qgsreportfieldgroupsectionwidget.cpp
------------------------
begin : December 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsreportfieldgroupsectionwidget.h"
#include "qgsreportsectionfieldgroup.h"
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"

QgsReportSectionFieldGroupWidget::QgsReportSectionFieldGroupWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionFieldGroup *section )
: QWidget( parent )
, mSection( section )
, mDesigner( designer )
{
setupUi( this );

mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, mFieldComboBox, &QgsFieldComboBox::setLayer );
connect( mButtonEditBody, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editBody );

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

connect( mSortAscendingCheckBox, &QCheckBox::toggled, this, &QgsReportSectionFieldGroupWidget::sortAscendingToggled );
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsReportSectionFieldGroupWidget::setLayer );
connect( mFieldComboBox, &QgsFieldComboBox::fieldChanged, this, &QgsReportSectionFieldGroupWidget::setField );
}

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

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

void QgsReportSectionFieldGroupWidget::sortAscendingToggled( bool checked )
{
mSection->setSortAscending( checked );
}

void QgsReportSectionFieldGroupWidget::setLayer( QgsMapLayer *layer )
{
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( layer );
if ( !vl )
return;

mSection->setLayer( vl );
if ( mSection->body() )
mSection->body()->reportContext().setLayer( mSection->layer() );
}

void QgsReportSectionFieldGroupWidget::setField( const QString &field )
{
mSection->setField( field );
}
45 changes: 45 additions & 0 deletions src/app/layout/qgsreportfieldgroupsectionwidget.h
@@ -0,0 +1,45 @@
/***************************************************************************
qgsreportfieldgroupsectionwidget.h
----------------------
begin : December 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSREPORTFIELDGROUPSECTIONWIDGET_H
#define QGSREPORTFIELDGROUPSECTIONWIDGET_H

#include "ui_qgsreportwidgetfieldgroupsectionbase.h"

class QgsLayoutDesignerDialog;
class QgsReportSectionFieldGroup;

class QgsReportSectionFieldGroupWidget: public QWidget, private Ui::QgsReportWidgetFieldGroupSectionBase
{
Q_OBJECT
public:
QgsReportSectionFieldGroupWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionFieldGroup *section );

private slots:

void editBody();
void sortAscendingToggled( bool checked );
void setLayer( QgsMapLayer *layer );
void setField( const QString &field );

private:

QgsReportSectionFieldGroup *mSection = nullptr;
QgsLayoutDesignerDialog *mDesigner = nullptr;

};

#endif // QGSREPORTFIELDGROUPSECTIONWIDGET_H
42 changes: 42 additions & 0 deletions src/app/layout/qgsreportlayoutsectionwidget.cpp
@@ -0,0 +1,42 @@
/***************************************************************************
qgsreportlayoutsectionwidget.cpp
------------------------
begin : December 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsreportlayoutsectionwidget.h"
#include "qgsreportsectionlayout.h"
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"

QgsReportLayoutSectionWidget::QgsReportLayoutSectionWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionLayout *section )
: QWidget( parent )
, mSection( section )
, mDesigner( designer )
{
setupUi( this );

connect( mButtonEditBody, &QPushButton::clicked, this, &QgsReportLayoutSectionWidget::editBody );
}

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

mDesigner->setCurrentLayout( mSection->body() );
}
42 changes: 42 additions & 0 deletions src/app/layout/qgsreportlayoutsectionwidget.h
@@ -0,0 +1,42 @@
/***************************************************************************
qgsreportlayoutsectionwidget.h
----------------------
begin : December 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSREPORTLAYOUTSECTIONWIDGET_H
#define QGSREPORTLAYOUTSECTIONWIDGET_H

#include "ui_qgsreportwidgetlayoutsectionbase.h"

class QgsLayoutDesignerDialog;
class QgsReportSectionLayout;

class QgsReportLayoutSectionWidget: public QWidget, private Ui::QgsReportWidgetLayoutSectionBase
{
Q_OBJECT
public:
QgsReportLayoutSectionWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionLayout *section );

private slots:

void editBody();

private:

QgsReportSectionLayout *mSection = nullptr;
QgsLayoutDesignerDialog *mDesigner = nullptr;

};

#endif // QGSREPORTLAYOUTSECTIONWIDGET_H
27 changes: 26 additions & 1 deletion src/app/layout/qgsreportorganizerwidget.cpp
Expand Up @@ -21,6 +21,8 @@
#include "qgsreportsectionfieldgroup.h"
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"
#include "qgsreportlayoutsectionwidget.h"
#include "qgsreportfieldgroupsectionwidget.h"
#include <QMenu>
#include <QMessageBox>

Expand All @@ -40,9 +42,14 @@ QgsReportOrganizerWidget::QgsReportOrganizerWidget( QWidget *parent, QgsLayoutDe
mViewSections->setModel( mSectionModel );

#ifdef ENABLE_MODELTEST
//new ModelTest( mSectionModel, this );
new ModelTest( mSectionModel, this );
#endif

QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->setMargin( 0 );
vLayout->setSpacing( 0 );
mSettingsFrame->setLayout( vLayout );

mViewSections->setEditTriggers( QAbstractItemView::AllEditTriggers );

QMenu *addMenu = new QMenu( mButtonAddSection );
Expand Down Expand Up @@ -151,4 +158,22 @@ void QgsReportOrganizerWidget::selectionChanged( const QModelIndex &current, con

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

delete mConfigWidget;
if ( QgsReportSectionLayout *section = dynamic_cast< QgsReportSectionLayout * >( parent ) )
{
QgsReportLayoutSectionWidget *widget = new QgsReportLayoutSectionWidget( this, mDesigner, section );
mSettingsFrame->layout()->addWidget( widget );
mConfigWidget = widget;
}
else if ( QgsReportSectionFieldGroup *section = dynamic_cast< QgsReportSectionFieldGroup * >( parent ) )
{
QgsReportSectionFieldGroupWidget *widget = new QgsReportSectionFieldGroupWidget( this, mDesigner, section );
mSettingsFrame->layout()->addWidget( widget );
mConfigWidget = widget;
}
else
{
mConfigWidget = nullptr;
}
}
1 change: 1 addition & 0 deletions src/app/layout/qgsreportorganizerwidget.h
Expand Up @@ -51,6 +51,7 @@ class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrga
QgsReportSectionModel *mSectionModel = nullptr;
QgsMessageBar *mMessageBar;
QgsLayoutDesignerDialog *mDesigner = nullptr;
QWidget *mConfigWidget = nullptr;

};

Expand Down

0 comments on commit 8eb6aa9

Please sign in to comment.