From 8eb6aa9281f3d12ef8e96c3707101ca76a01e51a Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 30 Dec 2017 20:19:26 +1000 Subject: [PATCH] More UI work on reports --- src/app/CMakeLists.txt | 4 + .../qgsreportfieldgroupsectionwidget.cpp | 77 ++++++++++ .../layout/qgsreportfieldgroupsectionwidget.h | 45 ++++++ .../layout/qgsreportlayoutsectionwidget.cpp | 42 +++++ src/app/layout/qgsreportlayoutsectionwidget.h | 42 +++++ src/app/layout/qgsreportorganizerwidget.cpp | 27 +++- src/app/layout/qgsreportorganizerwidget.h | 1 + src/ui/layout/qgsreportorganizerwidgetbase.ui | 144 ++++++++++++------ .../qgsreportwidgetfieldgroupsectionbase.ui | 106 +++++++++++++ .../qgsreportwidgetlayoutsectionbase.ui | 65 ++++++++ 10 files changed, 509 insertions(+), 44 deletions(-) create mode 100644 src/app/layout/qgsreportfieldgroupsectionwidget.cpp create mode 100644 src/app/layout/qgsreportfieldgroupsectionwidget.h create mode 100644 src/app/layout/qgsreportlayoutsectionwidget.cpp create mode 100644 src/app/layout/qgsreportlayoutsectionwidget.h create mode 100644 src/ui/layout/qgsreportwidgetfieldgroupsectionbase.ui create mode 100644 src/ui/layout/qgsreportwidgetlayoutsectionbase.ui diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 852457603ced..a59758086e9a 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -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 @@ -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 diff --git a/src/app/layout/qgsreportfieldgroupsectionwidget.cpp b/src/app/layout/qgsreportfieldgroupsectionwidget.cpp new file mode 100644 index 000000000000..64e055564769 --- /dev/null +++ b/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 ); +} diff --git a/src/app/layout/qgsreportfieldgroupsectionwidget.h b/src/app/layout/qgsreportfieldgroupsectionwidget.h new file mode 100644 index 000000000000..e75c3f28f3d2 --- /dev/null +++ b/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 diff --git a/src/app/layout/qgsreportlayoutsectionwidget.cpp b/src/app/layout/qgsreportlayoutsectionwidget.cpp new file mode 100644 index 000000000000..946e55b26e9c --- /dev/null +++ b/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() ); +} diff --git a/src/app/layout/qgsreportlayoutsectionwidget.h b/src/app/layout/qgsreportlayoutsectionwidget.h new file mode 100644 index 000000000000..d1d9c40cafda --- /dev/null +++ b/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 diff --git a/src/app/layout/qgsreportorganizerwidget.cpp b/src/app/layout/qgsreportorganizerwidget.cpp index 48bc3ff3ddfe..c399f2ac5f8d 100644 --- a/src/app/layout/qgsreportorganizerwidget.cpp +++ b/src/app/layout/qgsreportorganizerwidget.cpp @@ -21,6 +21,8 @@ #include "qgsreportsectionfieldgroup.h" #include "qgslayout.h" #include "qgslayoutdesignerdialog.h" +#include "qgsreportlayoutsectionwidget.h" +#include "qgsreportfieldgroupsectionwidget.h" #include #include @@ -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 ); @@ -151,4 +158,22 @@ void QgsReportOrganizerWidget::selectionChanged( const QModelIndex ¤t, 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; + } } diff --git a/src/app/layout/qgsreportorganizerwidget.h b/src/app/layout/qgsreportorganizerwidget.h index 28b1ec29a513..94788bfd41df 100644 --- a/src/app/layout/qgsreportorganizerwidget.h +++ b/src/app/layout/qgsreportorganizerwidget.h @@ -51,6 +51,7 @@ class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrga QgsReportSectionModel *mSectionModel = nullptr; QgsMessageBar *mMessageBar; QgsLayoutDesignerDialog *mDesigner = nullptr; + QWidget *mConfigWidget = nullptr; }; diff --git a/src/ui/layout/qgsreportorganizerwidgetbase.ui b/src/ui/layout/qgsreportorganizerwidgetbase.ui index 481f8cc5c415..8fcf04b4c485 100644 --- a/src/ui/layout/qgsreportorganizerwidgetbase.ui +++ b/src/ui/layout/qgsreportorganizerwidgetbase.ui @@ -97,54 +97,112 @@ - - - - - Edit - - - - - - - Show header - - - - - - - Edit - - - - - - - Show footer - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + QFrame::NoFrame + + + true + + + + + 0 + 0 + 687 + 207 + + + + + + + + + Edit + + + + + + + Show header + + + + + + + Edit + + + + + + + Show footer + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ui/layout/qgsreportwidgetfieldgroupsectionbase.ui b/src/ui/layout/qgsreportwidgetfieldgroupsectionbase.ui new file mode 100644 index 000000000000..0f92ba0798a4 --- /dev/null +++ b/src/ui/layout/qgsreportwidgetfieldgroupsectionbase.ui @@ -0,0 +1,106 @@ + + + QgsReportWidgetFieldGroupSectionBase + + + + 0 + 0 + 705 + 231 + + + + Layout Manager + + + + + + + + Section body + + + + + + + Edit + + + + + + + Layer + + + + + + + + + + Field + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Sort ascending + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + QgsMapLayerComboBox + QComboBox +
qgsmaplayercombobox.h
+
+ + QgsFieldComboBox + QComboBox +
qgsfieldcombobox.h
+
+
+ + + + +
diff --git a/src/ui/layout/qgsreportwidgetlayoutsectionbase.ui b/src/ui/layout/qgsreportwidgetlayoutsectionbase.ui new file mode 100644 index 000000000000..292d1080f3fd --- /dev/null +++ b/src/ui/layout/qgsreportwidgetlayoutsectionbase.ui @@ -0,0 +1,65 @@ + + + QgsReportWidgetLayoutSectionBase + + + + 0 + 0 + 723 + 89 + + + + Layout Manager + + + + + + + + Section body + + + + + + + Edit + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +