Skip to content
Permalink
Browse files

More UI work on reports

  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent fc9a451 commit 8eb6aa9281f3d12ef8e96c3707101ca76a01e51a
@@ -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

@@ -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 );
}
@@ -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
@@ -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() );
}
@@ -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
@@ -21,6 +21,8 @@
#include "qgsreportsectionfieldgroup.h"
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"
#include "qgsreportlayoutsectionwidget.h"
#include "qgsreportfieldgroupsectionwidget.h"
#include <QMenu>
#include <QMessageBox>

@@ -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 &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;
}
}
@@ -51,6 +51,7 @@ class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrga
QgsReportSectionModel *mSectionModel = nullptr;
QgsMessageBar *mMessageBar;
QgsLayoutDesignerDialog *mDesigner = nullptr;
QWidget *mConfigWidget = nullptr;

};

0 comments on commit 8eb6aa9

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