mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Start on ui for configuring reports
This commit is contained in:
parent
6db24327f2
commit
c9ddc9fda0
@ -69,6 +69,11 @@ Note that ownership is not transferred to ``parent``.
|
||||
virtual QString type() const = 0;
|
||||
%Docstring
|
||||
Returns the section subclass type.
|
||||
%End
|
||||
|
||||
virtual QString description() const = 0;
|
||||
%Docstring
|
||||
Returns a user-visible, translated description of the section.
|
||||
%End
|
||||
|
||||
virtual QgsAbstractReportSection *clone() const = 0 /Factory/;
|
||||
|
@ -39,6 +39,7 @@ Note that ownership is not transferred to ``project``.
|
||||
%End
|
||||
|
||||
virtual QString type() const;
|
||||
virtual QString description() const;
|
||||
virtual QIcon icon() const;
|
||||
|
||||
virtual QgsProject *layoutProject() const;
|
||||
|
@ -35,6 +35,8 @@ Note that ownership is not transferred to ``parent``.
|
||||
%End
|
||||
|
||||
virtual QString type() const;
|
||||
virtual QString description() const;
|
||||
|
||||
|
||||
QgsLayout *body();
|
||||
%Docstring
|
||||
|
@ -34,6 +34,7 @@ Note that ownership is not transferred to ``parent``.
|
||||
%End
|
||||
|
||||
virtual QString type() const;
|
||||
virtual QString description() const;
|
||||
|
||||
QgsLayout *body();
|
||||
%Docstring
|
||||
|
@ -204,6 +204,8 @@ SET(QGIS_APP_SRCS
|
||||
layout/qgslayoutscalebarwidget.cpp
|
||||
layout/qgslayoutshapewidget.cpp
|
||||
layout/qgslayouttablebackgroundcolorsdialog.cpp
|
||||
layout/qgsreportorganizerwidget.cpp
|
||||
layout/qgsreportsectionmodel.cpp
|
||||
|
||||
locator/qgsinbuiltlocatorfilters.cpp
|
||||
locator/qgslocatoroptionswidget.cpp
|
||||
@ -423,6 +425,8 @@ SET (QGIS_APP_MOC_HDRS
|
||||
layout/qgslayoutscalebarwidget.h
|
||||
layout/qgslayoutshapewidget.h
|
||||
layout/qgslayouttablebackgroundcolorsdialog.h
|
||||
layout/qgsreportorganizerwidget.h
|
||||
layout/qgsreportsectionmodel.h
|
||||
|
||||
locator/qgsinbuiltlocatorfilters.h
|
||||
locator/qgslocatoroptionswidget.h
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include "qgslayoutatlaswidget.h"
|
||||
#include "qgslayoutpagecollection.h"
|
||||
#include "qgsreport.h"
|
||||
#include "qgsreportorganizerwidget.h"
|
||||
#include "ui_qgssvgexportoptions.h"
|
||||
#include <QShortcut>
|
||||
#include <QComboBox>
|
||||
@ -646,6 +647,9 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
|
||||
mAtlasDock = new QgsDockWidget( tr( "Atlas" ), this );
|
||||
mAtlasDock->setObjectName( QStringLiteral( "AtlasDock" ) );
|
||||
|
||||
mReportDock = new QgsDockWidget( tr( "Report" ), this );
|
||||
mReportDock->setObjectName( QStringLiteral( "ReportDock" ) );
|
||||
|
||||
const QList<QDockWidget *> docks = findChildren<QDockWidget *>();
|
||||
for ( QDockWidget *dock : docks )
|
||||
{
|
||||
@ -658,6 +662,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
|
||||
addDockWidget( Qt::RightDockWidgetArea, mUndoDock );
|
||||
addDockWidget( Qt::RightDockWidgetArea, mItemsDock );
|
||||
addDockWidget( Qt::RightDockWidgetArea, mAtlasDock );
|
||||
addDockWidget( Qt::RightDockWidgetArea, mReportDock );
|
||||
|
||||
createLayoutPropertiesWidget();
|
||||
|
||||
@ -665,6 +670,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
|
||||
mItemDock->show();
|
||||
mGeneralDock->show();
|
||||
mAtlasDock->show();
|
||||
mReportDock->show();
|
||||
mItemsDock->show();
|
||||
|
||||
tabifyDockWidget( mGeneralDock, mUndoDock );
|
||||
@ -672,6 +678,7 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
|
||||
tabifyDockWidget( mGeneralDock, mItemDock );
|
||||
tabifyDockWidget( mItemDock, mItemsDock );
|
||||
tabifyDockWidget( mItemDock, mAtlasDock );
|
||||
tabifyDockWidget( mItemDock, mReportDock );
|
||||
|
||||
toggleActions( false );
|
||||
|
||||
@ -739,6 +746,19 @@ void QgsLayoutDesignerDialog::setMasterLayout( QgsMasterLayoutInterface *layout
|
||||
mMenuAtlas = nullptr;
|
||||
mAtlasToolbar->hide();
|
||||
}
|
||||
|
||||
if ( dynamic_cast< QgsReport * >( layout ) )
|
||||
{
|
||||
createReportWidget();
|
||||
}
|
||||
else
|
||||
{
|
||||
// ideally we'd only create mReportDock in createReportWidget() -
|
||||
// but if we do that, then it's always brought to the focus
|
||||
// in tab widgets
|
||||
mReportDock->hide();
|
||||
mPanelsMenu->removeAction( mReportDock->toggleViewAction() );
|
||||
}
|
||||
}
|
||||
|
||||
QgsMasterLayoutInterface *QgsLayoutDesignerDialog::masterLayout()
|
||||
@ -2680,7 +2700,7 @@ void QgsLayoutDesignerDialog::createLayoutPropertiesWidget()
|
||||
|
||||
void QgsLayoutDesignerDialog::createAtlasWidget()
|
||||
{
|
||||
QgsPrintLayout *printLayout = qobject_cast< QgsPrintLayout * >( mLayout );
|
||||
QgsPrintLayout *printLayout = dynamic_cast< QgsPrintLayout * >( mMasterLayout );
|
||||
QgsLayoutAtlas *atlas = printLayout->atlas();
|
||||
QgsLayoutAtlasWidget *atlasWidget = new QgsLayoutAtlasWidget( mAtlasDock, printLayout );
|
||||
atlasWidget->setMessageBar( mMessageBar );
|
||||
@ -2700,6 +2720,16 @@ void QgsLayoutDesignerDialog::createAtlasWidget()
|
||||
toggleAtlasControls( atlas->enabled() && atlas->coverageLayer() );
|
||||
}
|
||||
|
||||
void QgsLayoutDesignerDialog::createReportWidget()
|
||||
{
|
||||
QgsReport *report = dynamic_cast< QgsReport * >( mMasterLayout );
|
||||
QgsReportOrganizerWidget *reportWidget = new QgsReportOrganizerWidget( mReportDock, this, report );
|
||||
reportWidget->setMessageBar( mMessageBar );
|
||||
mReportDock->setWidget( reportWidget );
|
||||
|
||||
mPanelsMenu->addAction( mReportDock->toggleViewAction() );
|
||||
}
|
||||
|
||||
void QgsLayoutDesignerDialog::initializeRegistry()
|
||||
{
|
||||
sInitializedRegistry = true;
|
||||
|
@ -373,6 +373,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
|
||||
QgsDockWidget *mItemsDock = nullptr;
|
||||
QgsLayoutItemsListView *mItemsTreeView = nullptr;
|
||||
|
||||
QgsDockWidget *mReportDock = nullptr;
|
||||
|
||||
QAction *mUndoAction = nullptr;
|
||||
QAction *mRedoAction = nullptr;
|
||||
//! Copy/cut/paste actions
|
||||
@ -406,6 +408,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
|
||||
|
||||
void createLayoutPropertiesWidget();
|
||||
void createAtlasWidget();
|
||||
void createReportWidget();
|
||||
|
||||
void initializeRegistry();
|
||||
|
||||
|
154
src/app/layout/qgsreportorganizerwidget.cpp
Normal file
154
src/app/layout/qgsreportorganizerwidget.cpp
Normal file
@ -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() );
|
||||
}
|
59
src/app/layout/qgsreportorganizerwidget.h
Normal file
59
src/app/layout/qgsreportorganizerwidget.h
Normal file
@ -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
|
211
src/app/layout/qgsreportsectionmodel.cpp
Normal file
211
src/app/layout/qgsreportsectionmodel.cpp
Normal file
@ -0,0 +1,211 @@
|
||||
/***************************************************************************
|
||||
qgsreportsectionmodel.cpp
|
||||
---------------------
|
||||
begin : December 2017
|
||||
copyright : (C) 2017 by Nyall Dawso
|
||||
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 "qgsreportsectionmodel.h"
|
||||
|
||||
#ifdef ENABLE_MODELTEST
|
||||
#include "modeltest.h"
|
||||
#endif
|
||||
|
||||
QgsReportSectionModel::QgsReportSectionModel( QgsReport *report, QObject *parent )
|
||||
: QAbstractItemModel( parent )
|
||||
, mReport( report )
|
||||
{
|
||||
}
|
||||
|
||||
Qt::ItemFlags QgsReportSectionModel::flags( const QModelIndex &index ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return 0;
|
||||
|
||||
return QAbstractItemModel::flags( index );
|
||||
}
|
||||
|
||||
QVariant QgsReportSectionModel::data( const QModelIndex &index, int role ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return QVariant();
|
||||
|
||||
QgsAbstractReportSection *section = sectionForIndex( index );
|
||||
if ( !section )
|
||||
return QVariant();
|
||||
|
||||
switch ( role )
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
case Qt::ToolTipRole:
|
||||
{
|
||||
switch ( index.column() )
|
||||
{
|
||||
case 0:
|
||||
return section->description();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::TextAlignmentRole:
|
||||
{
|
||||
return ( index.column() == 2 || index.column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
|
||||
}
|
||||
|
||||
case Qt::EditRole:
|
||||
{
|
||||
switch ( index.column() )
|
||||
{
|
||||
case 0:
|
||||
return section->type();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant QgsReportSectionModel::headerData( int section, Qt::Orientation orientation, int role ) const
|
||||
{
|
||||
if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 && section <= 0 )
|
||||
{
|
||||
QStringList lst;
|
||||
lst << tr( "Section" );
|
||||
return lst[section];
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int QgsReportSectionModel::rowCount( const QModelIndex &parent ) const
|
||||
{
|
||||
QgsAbstractReportSection *parentSection = nullptr;
|
||||
if ( parent.column() > 0 )
|
||||
return 0;
|
||||
|
||||
if ( !parent.isValid() )
|
||||
parentSection = mReport;
|
||||
else
|
||||
parentSection = sectionForIndex( parent );
|
||||
|
||||
return parentSection->childCount();
|
||||
}
|
||||
|
||||
int QgsReportSectionModel::columnCount( const QModelIndex & ) const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
QModelIndex QgsReportSectionModel::index( int row, int column, const QModelIndex &parent ) const
|
||||
{
|
||||
if ( !hasIndex( row, column, parent ) )
|
||||
return QModelIndex();
|
||||
|
||||
QgsAbstractReportSection *parentSection = nullptr;
|
||||
|
||||
if ( !parent.isValid() )
|
||||
parentSection = mReport;
|
||||
else
|
||||
parentSection = sectionForIndex( parent );
|
||||
|
||||
QgsAbstractReportSection *childSection = parentSection->childSection( row );
|
||||
if ( childSection )
|
||||
return createIndex( row, column, childSection );
|
||||
else
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex QgsReportSectionModel::parent( const QModelIndex &index ) const
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return QModelIndex();
|
||||
|
||||
QgsAbstractReportSection *childSection = sectionForIndex( index );
|
||||
QgsAbstractReportSection *parentSection = childSection->parentSection();
|
||||
|
||||
if ( parentSection == mReport )
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex( parentSection->row(), 0, parentSection );
|
||||
}
|
||||
|
||||
bool QgsReportSectionModel::setData( const QModelIndex &index, const QVariant &value, int role )
|
||||
{
|
||||
if ( !index.isValid() )
|
||||
return false;
|
||||
|
||||
QgsAbstractReportSection *section = sectionForIndex( index );
|
||||
( void )section;
|
||||
( void )value;
|
||||
|
||||
if ( role != Qt::EditRole )
|
||||
return false;
|
||||
|
||||
switch ( index.column() )
|
||||
{
|
||||
case 0:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
emit dataChanged( index, index );
|
||||
return true;
|
||||
}
|
||||
|
||||
QgsAbstractReportSection *QgsReportSectionModel::sectionForIndex( const QModelIndex &index ) const
|
||||
{
|
||||
return static_cast<QgsAbstractReportSection *>( index.internalPointer() );
|
||||
}
|
||||
|
||||
bool QgsReportSectionModel::removeRows( int row, int count, const QModelIndex &parent )
|
||||
{
|
||||
QgsAbstractReportSection *parentSection = sectionForIndex( parent );
|
||||
|
||||
if ( row < 0 || row >= parentSection->childCount() )
|
||||
return false;
|
||||
|
||||
beginRemoveRows( parent, row, row + count - 1 );
|
||||
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
if ( row < parentSection->childCount() )
|
||||
{
|
||||
parentSection->removeChildAt( row );
|
||||
}
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QgsReportSectionModel::addSection( const QModelIndex &parent, std::unique_ptr<QgsAbstractReportSection> section )
|
||||
{
|
||||
QgsAbstractReportSection *parentSection = sectionForIndex( parent );
|
||||
if ( !parentSection )
|
||||
return;
|
||||
|
||||
beginInsertRows( parent, parentSection->childCount(), parentSection->childCount() );
|
||||
parentSection->appendChild( section.release() );
|
||||
endInsertRows();
|
||||
}
|
||||
|
63
src/app/layout/qgsreportsectionmodel.h
Normal file
63
src/app/layout/qgsreportsectionmodel.h
Normal file
@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
qgsreportsectionmodel.h
|
||||
---------------------
|
||||
begin : December 2017
|
||||
copyright : (C) 2017 by Nyall Dawso
|
||||
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 QGSREPORTSECTIONMODEL_H
|
||||
#define QGSREPORTSECTIONMODEL_H
|
||||
|
||||
#include "qgis.h"
|
||||
#include "qgsreport.h"
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
/**
|
||||
* \ingroup app
|
||||
* \class QgsReportSectionModel
|
||||
* \brief A model for managing the sections in a QgsReport.
|
||||
* \since QGIS 3.0
|
||||
*/
|
||||
class QgsReportSectionModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor for QgsReportSectionModel, for the specified \a report.
|
||||
*/
|
||||
QgsReportSectionModel( QgsReport *report, QObject *parent );
|
||||
|
||||
Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
||||
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
|
||||
QVariant headerData( int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole ) const override;
|
||||
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
|
||||
int columnCount( const QModelIndex & = QModelIndex() ) const override;
|
||||
|
||||
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
|
||||
QModelIndex parent( const QModelIndex &index ) const override;
|
||||
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
|
||||
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
|
||||
|
||||
void addSection( const QModelIndex &parent, std::unique_ptr< QgsAbstractReportSection > section );
|
||||
|
||||
/**
|
||||
* Returns the report section for the given \a index.
|
||||
*/
|
||||
QgsAbstractReportSection *sectionForIndex( const QModelIndex &index ) const;
|
||||
|
||||
private:
|
||||
QgsReport *mReport = nullptr;
|
||||
};
|
||||
|
||||
#endif // QGSREPORTSECTIONMODEL_H
|
@ -85,6 +85,11 @@ class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
|
||||
*/
|
||||
virtual QString type() const = 0;
|
||||
|
||||
/**
|
||||
* Returns a user-visible, translated description of the section.
|
||||
*/
|
||||
virtual QString description() const = 0;
|
||||
|
||||
/**
|
||||
* Clones the report section. Ownership of the returned section is
|
||||
* transferred to the caller.
|
||||
|
@ -53,6 +53,7 @@ class CORE_EXPORT QgsReport : public QObject, public QgsAbstractReportSection, p
|
||||
QgsReport( QgsProject *project );
|
||||
|
||||
QString type() const override { return QStringLiteral( "SectionReport" ); }
|
||||
QString description() const override { return QObject::tr( "Report" ); }
|
||||
QIcon icon() const override;
|
||||
QgsProject *layoutProject() const override { return mProject; }
|
||||
QgsReport *clone() const override SIP_FACTORY;
|
||||
|
@ -25,6 +25,11 @@ QgsReportSectionFieldGroup::QgsReportSectionFieldGroup( QgsAbstractReportSection
|
||||
|
||||
}
|
||||
|
||||
QString QgsReportSectionFieldGroup::description() const
|
||||
{
|
||||
return QObject::tr( "Group: %1" ).arg( mField );
|
||||
}
|
||||
|
||||
QgsReportSectionFieldGroup *QgsReportSectionFieldGroup::clone() const
|
||||
{
|
||||
std::unique_ptr< QgsReportSectionFieldGroup > copy = qgis::make_unique< QgsReportSectionFieldGroup >( nullptr );
|
||||
|
@ -45,6 +45,7 @@ class CORE_EXPORT QgsReportSectionFieldGroup : public QgsAbstractReportSection
|
||||
QgsReportSectionFieldGroup( QgsAbstractReportSection *parentSection = nullptr );
|
||||
|
||||
QString type() const override { return QStringLiteral( "SectionFieldGroup" ); }
|
||||
QString description() const override;
|
||||
|
||||
/**
|
||||
* Returns the body layout for the section.
|
||||
|
@ -42,6 +42,7 @@ class CORE_EXPORT QgsReportSectionLayout : public QgsAbstractReportSection
|
||||
QgsReportSectionLayout( QgsAbstractReportSection *parentSection = nullptr );
|
||||
|
||||
QString type() const override { return QStringLiteral( "SectionLayout" ); }
|
||||
QString description() const override { return QObject::tr( "Section" ); }
|
||||
|
||||
/**
|
||||
* Returns the body layout for the section.
|
||||
|
150
src/ui/layout/qgsreportorganizerwidgetbase.ui
Normal file
150
src/ui/layout/qgsreportorganizerwidgetbase.ui
Normal file
@ -0,0 +1,150 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QgsReportOrganizerBase</class>
|
||||
<widget class="QWidget" name="QgsReportOrganizerBase">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>723</width>
|
||||
<height>520</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>425</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Layout Manager</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeView" name="mViewSections">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="allColumnsShowFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="headerMinimumSectionSize">
|
||||
<number>100</number>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="mButtonAddSection">
|
||||
<property name="toolTip">
|
||||
<string>Add rule</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mButtonRemoveSection">
|
||||
<property name="toolTip">
|
||||
<string>Remove selected rules</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="mButtonEditFooter">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="mCheckShowHeader">
|
||||
<property name="text">
|
||||
<string>Show header</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="mButtonEditHeader">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="mCheckShowFooter">
|
||||
<property name="text">
|
||||
<string>Show footer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../images/images.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user