Skip to content
Permalink
Browse files

Add icons for report section types, and show pencil 'editing'

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 bf6c95d5756a834f443de38f51ce501fd595d516
@@ -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/;
@@ -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
@@ -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
@@ -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 )
{
@@ -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 );
}
}

@@ -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 );
}
}

@@ -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 );
}
}

@@ -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:

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

private:

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

@@ -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 )
{
@@ -62,6 +64,7 @@ void QgsReportLayoutSectionWidget::editHeader()
{
mDesigner->setCurrentLayout( mSection->header() );
mDesigner->setSectionTitle( tr( "%1 Header" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
}

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

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

mDesigner->setCurrentLayout( mSection->body() );
mDesigner->setSectionTitle( tr( "%1 Body" ).arg( mSection->description() ) );
mOrganizer->setEditedSection( mSection );
}
@@ -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:

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

private:

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

@@ -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 >();
@@ -25,6 +25,7 @@ class QgsReportSectionModel;
class QgsReport;
class QgsMessageBar;
class QgsLayoutDesignerDialog ;
class QgsAbstractReportSection;

class QgsReportOrganizerWidget: public QgsPanelWidget, private Ui::QgsReportOrganizerBase
{
@@ -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:

@@ -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;
@@ -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 );
@@ -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
@@ -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 )
{
@@ -59,6 +61,7 @@ void QgsReportSectionWidget::editHeader()
{
mDesigner->setCurrentLayout( mSection->header() );
mDesigner->setSectionTitle( tr( "Report Header" ) );
mOrganizer->setEditedSection( mSection );
}
}

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

@@ -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:

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

private:

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

@@ -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.
@@ -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 );
@@ -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.
@@ -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 );
@@ -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.

0 comments on commit bf6c95d

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