-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6db2432
commit c9ddc9f
Showing
17 changed files
with
697 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/*************************************************************************** | ||
qgsreportorganizerwidget.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 "qgsreportorganizerwidget.h" | ||
#include "qgsreport.h" | ||
#include "qgsreportsectionmodel.h" | ||
#include "qgsreportsectionlayout.h" | ||
#include "qgsreportsectionfieldgroup.h" | ||
#include "qgslayout.h" | ||
#include "qgslayoutdesignerdialog.h" | ||
#include <QMenu> | ||
#include <QMessageBox> | ||
|
||
#ifdef ENABLE_MODELTEST | ||
#include "modeltest.h" | ||
#endif | ||
|
||
QgsReportOrganizerWidget::QgsReportOrganizerWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReport *report ) | ||
: QgsPanelWidget( parent ) | ||
, mReport( report ) | ||
, mDesigner( designer ) | ||
{ | ||
setupUi( this ); | ||
setPanelTitle( tr( "Report" ) ); | ||
|
||
mSectionModel = new QgsReportSectionModel( mReport, mViewSections ); | ||
mViewSections->setModel( mSectionModel ); | ||
|
||
#ifdef ENABLE_MODELTEST | ||
//new ModelTest( mSectionModel, this ); | ||
#endif | ||
|
||
mViewSections->setEditTriggers( QAbstractItemView::AllEditTriggers ); | ||
|
||
QMenu *addMenu = new QMenu( mButtonAddSection ); | ||
QAction *layoutSection = new QAction( tr( "Single section" ), addMenu ); | ||
addMenu->addAction( layoutSection ); | ||
connect( layoutSection, &QAction::triggered, this, &QgsReportOrganizerWidget::addLayoutSection ); | ||
QAction *fieldGroupSection = new QAction( tr( "Field group" ), addMenu ); | ||
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 ); | ||
connect( mButtonRemoveSection, &QPushButton::clicked, this, &QgsReportOrganizerWidget::removeSection ); | ||
} | ||
|
||
void QgsReportOrganizerWidget::setMessageBar( QgsMessageBar *bar ) | ||
{ | ||
mMessageBar = bar; | ||
} | ||
|
||
void QgsReportOrganizerWidget::addLayoutSection() | ||
{ | ||
std::unique_ptr< QgsReportSectionLayout > section = qgis::make_unique< QgsReportSectionLayout >(); | ||
mSectionModel->addSection( mViewSections->currentIndex(), std::move( section ) ); | ||
} | ||
|
||
void QgsReportOrganizerWidget::addFieldGroupSection() | ||
{ | ||
std::unique_ptr< QgsReportSectionFieldGroup > section = qgis::make_unique< QgsReportSectionFieldGroup >(); | ||
mSectionModel->addSection( mViewSections->currentIndex(), std::move( section ) ); | ||
} | ||
|
||
void QgsReportOrganizerWidget::removeSection() | ||
{ | ||
QgsAbstractReportSection *section = mSectionModel->sectionForIndex( mViewSections->currentIndex() ); | ||
if ( dynamic_cast< QgsReport * >( section ) ) | ||
return; //report cannot be removed | ||
|
||
int res = QMessageBox::question( this, tr( "Remove Section" ), | ||
tr( "Are you sure you want to remove the report section?" ), | ||
QMessageBox::Yes | QMessageBox::No, QMessageBox::No ); | ||
if ( res == QMessageBox::No ) | ||
return; | ||
|
||
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 ¤t, const QModelIndex & ) | ||
{ | ||
QgsAbstractReportSection *parent = mSectionModel->sectionForIndex( current ); | ||
if ( !parent ) | ||
parent = mReport; | ||
|
||
whileBlocking( mCheckShowHeader )->setChecked( parent->headerEnabled() ); | ||
whileBlocking( mCheckShowFooter )->setChecked( parent->footerEnabled() ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*************************************************************************** | ||
qgsreportorganizerwidget.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 QGSREPORTORGANIZERWIDGET_H | ||
#define QGSREPORTORGANIZERWIDGET_H | ||
|
||
#include "ui_qgsreportorganizerwidgetbase.h" | ||
#include "qgspanelwidget.h" | ||
#include <QStyledItemDelegate> | ||
|
||
class QgsReportSectionModel; | ||
class QgsReport; | ||
class QgsMessageBar; | ||
class QgsLayoutDesignerDialog ; | ||
|
||
class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrganizerBase | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsReportOrganizerWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReport *report ); | ||
|
||
void setMessageBar( QgsMessageBar *bar ); | ||
|
||
private slots: | ||
|
||
void addLayoutSection(); | ||
void addFieldGroupSection(); | ||
void removeSection(); | ||
void toggleHeader( bool enabled ); | ||
void toggleFooter( bool enabled ); | ||
void editHeader(); | ||
void editFooter(); | ||
void selectionChanged( const QModelIndex ¤t, const QModelIndex &previous ); | ||
|
||
private: | ||
|
||
QgsReport *mReport = nullptr; | ||
QgsReportSectionModel *mSectionModel = nullptr; | ||
QgsMessageBar *mMessageBar; | ||
QgsLayoutDesignerDialog *mDesigner = nullptr; | ||
|
||
}; | ||
|
||
|
||
|
||
#endif // QGSREPORTORGANIZERWIDGET_H |
Oops, something went wrong.