Skip to content

Commit

Permalink
Add icons for report section types, and show pencil 'editing'
Browse files Browse the repository at this point in the history
icon in report organizer for section currently being edited in
the designer

This should help indicate to users which section is currently being
edited and give more visual hints as to exactly what's happening
in the ui.
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent d9fe0d4 commit bf6c95d
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 6 deletions.
5 changes: 5 additions & 0 deletions python/core/layout/qgsabstractreportsection.sip
Expand Up @@ -84,6 +84,11 @@ Returns the section subclass type.
virtual QString description() const = 0;
%Docstring
Returns a user-visible, translated description of the section.
%End

virtual QIcon icon() const = 0;
%Docstring
Returns an icon representing the section.
%End

virtual QgsAbstractReportSection *clone() const = 0 /Factory/;
Expand Down
2 changes: 2 additions & 0 deletions python/core/layout/qgsreportsectionfieldgroup.sip
Expand Up @@ -37,6 +37,8 @@ Note that ownership is not transferred to ``parent``.
virtual QString type() const;
virtual QString description() const;

virtual QIcon icon() const;


QgsLayout *body();
%Docstring
Expand Down
2 changes: 2 additions & 0 deletions python/core/layout/qgsreportsectionlayout.sip
Expand Up @@ -35,6 +35,8 @@ Note that ownership is not transferred to ``parent``.

virtual QString type() const;
virtual QString description() const;
virtual QIcon icon() const;


QgsLayout *body();
%Docstring
Expand Down
7 changes: 6 additions & 1 deletion src/app/layout/qgsreportfieldgroupsectionwidget.cpp
Expand Up @@ -18,9 +18,11 @@
#include "qgsreportsectionfieldgroup.h"
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"
#include "qgsreportorganizerwidget.h"

QgsReportSectionFieldGroupWidget::QgsReportSectionFieldGroupWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionFieldGroup *section )
QgsReportSectionFieldGroupWidget::QgsReportSectionFieldGroupWidget( QgsReportOrganizerWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionFieldGroup *section )
: QWidget( parent )
, mOrganizer( parent )
, mSection( section )
, mDesigner( designer )
{
Expand Down Expand Up @@ -72,6 +74,7 @@ void QgsReportSectionFieldGroupWidget::editHeader()
mSection->header()->reportContext().setLayer( mSection->layer() );
mDesigner->setCurrentLayout( mSection->header() );
mDesigner->setSectionTitle( tr( "%1 Header" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
}

Expand All @@ -89,6 +92,7 @@ void QgsReportSectionFieldGroupWidget::editFooter()
mSection->footer()->reportContext().setLayer( mSection->layer() );
mDesigner->setCurrentLayout( mSection->footer() );
mDesigner->setSectionTitle( tr( "%1 Footer" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
}

Expand All @@ -111,6 +115,7 @@ void QgsReportSectionFieldGroupWidget::editBody()
mSection->body()->reportContext().setLayer( mSection->layer() );
mDesigner->setCurrentLayout( mSection->body() );
mDesigner->setSectionTitle( tr( "%1 Body" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/layout/qgsreportfieldgroupsectionwidget.h
Expand Up @@ -21,12 +21,13 @@

class QgsLayoutDesignerDialog;
class QgsReportSectionFieldGroup;
class QgsReportOrganizerWidget;

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

private slots:

Expand All @@ -42,6 +43,7 @@ class QgsReportSectionFieldGroupWidget: public QWidget, private Ui::QgsReportWid

private:

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

Expand Down
7 changes: 6 additions & 1 deletion src/app/layout/qgsreportlayoutsectionwidget.cpp
Expand Up @@ -18,9 +18,11 @@
#include "qgsreportsectionlayout.h"
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"
#include "qgsreportorganizerwidget.h"

QgsReportLayoutSectionWidget::QgsReportLayoutSectionWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionLayout *section )
QgsReportLayoutSectionWidget::QgsReportLayoutSectionWidget( QgsReportOrganizerWidget *parent, QgsLayoutDesignerDialog *designer, QgsReportSectionLayout *section )
: QWidget( parent )
, mOrganizer( parent )
, mSection( section )
, mDesigner( designer )
{
Expand Down Expand Up @@ -62,6 +64,7 @@ void QgsReportLayoutSectionWidget::editHeader()
{
mDesigner->setCurrentLayout( mSection->header() );
mDesigner->setSectionTitle( tr( "%1 Header" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
}

Expand All @@ -78,6 +81,7 @@ void QgsReportLayoutSectionWidget::editFooter()
{
mDesigner->setCurrentLayout( mSection->footer() );
mDesigner->setSectionTitle( tr( "%1 Footer" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
}

Expand All @@ -97,4 +101,5 @@ void QgsReportLayoutSectionWidget::editBody()

mDesigner->setCurrentLayout( mSection->body() );
mDesigner->setSectionTitle( tr( "%1 Body" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
4 changes: 3 additions & 1 deletion src/app/layout/qgsreportlayoutsectionwidget.h
Expand Up @@ -21,12 +21,13 @@

class QgsLayoutDesignerDialog;
class QgsReportSectionLayout;
class QgsReportOrganizerWidget;

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

private slots:

Expand All @@ -39,6 +40,7 @@ class QgsReportLayoutSectionWidget: public QWidget, private Ui::QgsReportWidgetL

private:

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

Expand Down
5 changes: 5 additions & 0 deletions src/app/layout/qgsreportorganizerwidget.cpp
Expand Up @@ -74,6 +74,11 @@ void QgsReportOrganizerWidget::setMessageBar( QgsMessageBar *bar )
mMessageBar = bar;
}

void QgsReportOrganizerWidget::setEditedSection( QgsAbstractReportSection *section )
{
mSectionModel->setEditedSection( section );
}

void QgsReportOrganizerWidget::addLayoutSection()
{
std::unique_ptr< QgsReportSectionLayout > section = qgis::make_unique< QgsReportSectionLayout >();
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout/qgsreportorganizerwidget.h
Expand Up @@ -25,6 +25,7 @@ class QgsReportSectionModel;
class QgsReport;
class QgsMessageBar;
class QgsLayoutDesignerDialog ;
class QgsAbstractReportSection;

class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrganizerBase
{
Expand All @@ -33,6 +34,7 @@ class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrga
QgsReportOrganizerWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReport *report );

void setMessageBar( QgsMessageBar *bar );
void setEditedSection( QgsAbstractReportSection *section );

private slots:

Expand Down
48 changes: 48 additions & 0 deletions src/app/layout/qgsreportsectionmodel.cpp
Expand Up @@ -58,6 +58,34 @@ QVariant QgsReportSectionModel::data( const QModelIndex &index, int role ) const
break;
}

case Qt::DecorationRole:
switch ( index.column() )
{
case 0:
{
QIcon icon = section->icon();

if ( section == mEditedSection )
{
QPixmap pixmap( icon.pixmap( 16, 16 ) );

QPainter painter( &pixmap );
painter.drawPixmap( 0, 0, 16, 16, QgsApplication::getThemePixmap( "/mActionToggleEditing.svg" ) );
painter.end();

return QIcon( pixmap );
}
else
{
return icon;
}
}

default:
return QVariant();
}
break;

case Qt::TextAlignmentRole:
{
return ( index.column() == 2 || index.column() == 3 ) ? Qt::AlignRight : Qt::AlignLeft;
Expand Down Expand Up @@ -211,6 +239,26 @@ QModelIndex QgsReportSectionModel::indexForSection( QgsAbstractReportSection *se
return findIndex( QModelIndex(), section );
}

void QgsReportSectionModel::setEditedSection( QgsAbstractReportSection *section )
{
QModelIndex oldSection;
if ( mEditedSection )
{
oldSection = indexForSection( mEditedSection );
}

mEditedSection = section;
if ( oldSection.isValid() )
emit dataChanged( oldSection, oldSection, QVector<int>() << Qt::DecorationRole );

if ( mEditedSection )
{
QModelIndex newSection = indexForSection( mEditedSection );
emit dataChanged( newSection, newSection, QVector<int>() << Qt::DecorationRole );
}

}

bool QgsReportSectionModel::removeRows( int row, int count, const QModelIndex &parent )
{
QgsAbstractReportSection *parentSection = sectionForIndex( parent );
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout/qgsreportsectionmodel.h
Expand Up @@ -59,8 +59,11 @@ class QgsReportSectionModel : public QAbstractItemModel

QModelIndex indexForSection( QgsAbstractReportSection *section ) const;

void setEditedSection( QgsAbstractReportSection *section );

private:
QgsReport *mReport = nullptr;
QgsAbstractReportSection *mEditedSection = nullptr;
};

#endif // QGSREPORTSECTIONMODEL_H
6 changes: 5 additions & 1 deletion src/app/layout/qgsreportsectionwidget.cpp
Expand Up @@ -18,9 +18,11 @@
#include "qgsreport.h"
#include "qgslayout.h"
#include "qgslayoutdesignerdialog.h"
#include "qgsreportorganizerwidget.h"

QgsReportSectionWidget::QgsReportSectionWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReport *section )
QgsReportSectionWidget::QgsReportSectionWidget( QgsReportOrganizerWidget *parent, QgsLayoutDesignerDialog *designer, QgsReport *section )
: QWidget( parent )
, mOrganizer( parent )
, mSection( section )
, mDesigner( designer )
{
Expand Down Expand Up @@ -59,6 +61,7 @@ void QgsReportSectionWidget::editHeader()
{
mDesigner->setCurrentLayout( mSection->header() );
mDesigner->setSectionTitle( tr( "Report Header" ) );
mOrganizer->setEditedSection( mSection );
}
}

Expand All @@ -75,6 +78,7 @@ void QgsReportSectionWidget::editFooter()
{
mDesigner->setCurrentLayout( mSection->footer() );
mDesigner->setSectionTitle( tr( "Report Footer" ) );
mOrganizer->setEditedSection( mSection );
}
}

4 changes: 3 additions & 1 deletion src/app/layout/qgsreportsectionwidget.h
Expand Up @@ -21,12 +21,13 @@

class QgsLayoutDesignerDialog;
class QgsReport;
class QgsReportOrganizerWidget;

class QgsReportSectionWidget: public QWidget, private Ui::QgsReportWidgetSectionBase
{
Q_OBJECT
public:
QgsReportSectionWidget( QWidget *parent, QgsLayoutDesignerDialog *designer, QgsReport *section );
QgsReportSectionWidget( QgsReportOrganizerWidget *parent, QgsLayoutDesignerDialog *designer, QgsReport *section );

private slots:

Expand All @@ -37,6 +38,7 @@ class QgsReportSectionWidget: public QWidget, private Ui::QgsReportWidgetSection

private:

QgsReportOrganizerWidget *mOrganizer = nullptr;
QgsReport *mSection = nullptr;
QgsLayoutDesignerDialog *mDesigner = nullptr;

Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgsabstractreportsection.h
Expand Up @@ -96,6 +96,11 @@ class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
*/
virtual QString description() const = 0;

/**
* Returns an icon representing the section.
*/
virtual QIcon icon() const = 0;

/**
* Clones the report section. Ownership of the returned section is
* transferred to the caller.
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgsreportsectionfieldgroup.cpp
Expand Up @@ -30,6 +30,11 @@ QString QgsReportSectionFieldGroup::description() const
return QObject::tr( "Group: %1" ).arg( mField );
}

QIcon QgsReportSectionFieldGroup::icon() const
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconFieldText.svg" ) );
}

QgsReportSectionFieldGroup *QgsReportSectionFieldGroup::clone() const
{
std::unique_ptr< QgsReportSectionFieldGroup > copy = qgis::make_unique< QgsReportSectionFieldGroup >( nullptr );
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgsreportsectionfieldgroup.h
Expand Up @@ -46,6 +46,7 @@ class CORE_EXPORT QgsReportSectionFieldGroup : public QgsAbstractReportSection

QString type() const override { return QStringLiteral( "SectionFieldGroup" ); }
QString description() const override;
QIcon icon() const override;

/**
* Returns the body layout for the section.
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgsreportsectionlayout.cpp
Expand Up @@ -23,6 +23,11 @@ QgsReportSectionLayout::QgsReportSectionLayout( QgsAbstractReportSection *parent
: QgsAbstractReportSection( parent )
{}

QIcon QgsReportSectionLayout::icon() const
{
return QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewComposer.svg" ) );
}

QgsReportSectionLayout *QgsReportSectionLayout::clone() const
{
std::unique_ptr< QgsReportSectionLayout > copy = qgis::make_unique< QgsReportSectionLayout >( nullptr );
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgsreportsectionlayout.h
Expand Up @@ -43,6 +43,7 @@ class CORE_EXPORT QgsReportSectionLayout : public QgsAbstractReportSection

QString type() const override { return QStringLiteral( "SectionLayout" ); }
QString description() const override { return QObject::tr( "Section" ); }
QIcon icon() const override;

/**
* Returns the body layout for the section.
Expand Down

0 comments on commit bf6c95d

Please sign in to comment.