Add a messagebar to layout designer

This commit is contained in:
Nyall Dawson 2017-12-12 19:08:44 +10:00
parent b992e871ee
commit 261492ddca
4 changed files with 42 additions and 1 deletions

View File

@ -46,6 +46,12 @@ Returns the layout view utilized by the designer.
.. seealso:: :py:func:`layout()` .. seealso:: :py:func:`layout()`
%End %End
virtual QgsMessageBar *messageBar() = 0;
%Docstring
Returns the designer's message bar.
:rtype: QgsMessageBar
%End
virtual void selectItems( const QList< QgsLayoutItem * > items ) = 0; virtual void selectItems( const QList< QgsLayoutItem * > items ) = 0;
%Docstring %Docstring
Selects the specified ``items``. Selects the specified ``items``.

View File

@ -93,6 +93,11 @@ QgsLayoutView *QgsAppLayoutDesignerInterface::view()
return mDesigner->view(); return mDesigner->view();
} }
QgsMessageBar *QgsAppLayoutDesignerInterface::messageBar()
{
return mDesigner->messageBar();
}
void QgsAppLayoutDesignerInterface::selectItems( const QList<QgsLayoutItem *> items ) void QgsAppLayoutDesignerInterface::selectItems( const QList<QgsLayoutItem *> items )
{ {
mDesigner->selectItems( items ); mDesigner->selectItems( items );
@ -136,6 +141,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
centralWidget()->layout()->setMargin( 0 ); centralWidget()->layout()->setMargin( 0 );
centralWidget()->layout()->setContentsMargins( 0, 0, 0, 0 ); centralWidget()->layout()->setContentsMargins( 0, 0, 0, 0 );
mMessageBar = new QgsMessageBar( centralWidget() );
mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
static_cast< QGridLayout * >( centralWidget()->layout() )->addWidget( mMessageBar, 0, 0, 1, 1, Qt::AlignTop );
mHorizontalRuler = new QgsLayoutRuler( nullptr, Qt::Horizontal ); mHorizontalRuler = new QgsLayoutRuler( nullptr, Qt::Horizontal );
mVerticalRuler = new QgsLayoutRuler( nullptr, Qt::Vertical ); mVerticalRuler = new QgsLayoutRuler( nullptr, Qt::Vertical );
mRulerLayoutFix = new QWidget(); mRulerLayoutFix = new QWidget();
@ -1520,6 +1529,9 @@ void QgsLayoutDesignerDialog::exportToRaster()
switch ( exporter.exportToImage( fileNExt.first, settings ) ) switch ( exporter.exportToImage( fileNExt.first, settings ) )
{ {
case QgsLayoutExporter::Success: case QgsLayoutExporter::Success:
mMessageBar->pushInfo( tr( "Export layout" ), tr( "Successfully exported layout to %1" ).arg( fileNExt.first ) );
break;
case QgsLayoutExporter::PrintError: case QgsLayoutExporter::PrintError:
break; break;
@ -1614,11 +1626,14 @@ void QgsLayoutDesignerDialog::exportToPdf()
switch ( exporter.exportToPdf( outputFileName, pdfSettings ) ) switch ( exporter.exportToPdf( outputFileName, pdfSettings ) )
{ {
case QgsLayoutExporter::Success: case QgsLayoutExporter::Success:
{
mMessageBar->pushInfo( tr( "Export layout" ), tr( "Successfully exported layout to %1" ).arg( outputFileName ) );
break; break;
}
case QgsLayoutExporter::FileError: case QgsLayoutExporter::FileError:
QMessageBox::warning( this, tr( "Export to PDF" ), QMessageBox::warning( this, tr( "Export to PDF" ),
tr( "Cannot write to %1.\n\nThis file may be open in another application." ).arg( exporter.errorFile() ), tr( "Cannot write to %1.\n\nThis file may be open in another application." ).arg( outputFileName ),
QMessageBox::Ok, QMessageBox::Ok,
QMessageBox::Ok ); QMessageBox::Ok );
break; break;
@ -1880,4 +1895,9 @@ void QgsLayoutDesignerDialog::selectItems( const QList<QgsLayoutItem *> items )
} }
} }
QgsMessageBar *QgsLayoutDesignerDialog::messageBar()
{
return mMessageBar;
}

View File

@ -42,6 +42,7 @@ class QUndoView;
class QTreeView; class QTreeView;
class QgsLayoutItemsListView; class QgsLayoutItemsListView;
class QgsLayoutPropertiesWidget; class QgsLayoutPropertiesWidget;
class QgsMessageBar;
class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{ {
@ -51,6 +52,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog ); QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog );
QgsLayout *layout() override; QgsLayout *layout() override;
QgsLayoutView *view() override; QgsLayoutView *view() override;
QgsMessageBar *messageBar() override;
void selectItems( const QList< QgsLayoutItem * > items ) override; void selectItems( const QList< QgsLayoutItem * > items ) override;
public slots: public slots:
@ -114,6 +116,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/ */
void selectItems( const QList< QgsLayoutItem * > items ); void selectItems( const QList< QgsLayoutItem * > items );
/**
* Returns the designer's message bar.
*/
QgsMessageBar *messageBar();
public slots: public slots:
/** /**
@ -286,6 +293,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
QgsLayout *mLayout = nullptr; QgsLayout *mLayout = nullptr;
QgsMessageBar *mMessageBar = nullptr;
QActionGroup *mToolsActionGroup = nullptr; QActionGroup *mToolsActionGroup = nullptr;
QgsLayoutView *mView = nullptr; QgsLayoutView *mView = nullptr;

View File

@ -23,6 +23,7 @@
class QgsLayout; class QgsLayout;
class QgsLayoutView; class QgsLayoutView;
class QgsLayoutItem; class QgsLayoutItem;
class QgsMessageBar;
/** /**
* \ingroup gui * \ingroup gui
@ -61,6 +62,11 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject
*/ */
virtual QgsLayoutView *view() = 0; virtual QgsLayoutView *view() = 0;
/**
* Returns the designer's message bar.
*/
virtual QgsMessageBar *messageBar() = 0;
/** /**
* Selects the specified \a items. * Selects the specified \a items.
*/ */