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()`
%End
virtual QgsMessageBar *messageBar() = 0;
%Docstring
Returns the designer's message bar.
:rtype: QgsMessageBar
%End
virtual void selectItems( const QList< QgsLayoutItem * > items ) = 0;
%Docstring
Selects the specified ``items``.

View File

@ -93,6 +93,11 @@ QgsLayoutView *QgsAppLayoutDesignerInterface::view()
return mDesigner->view();
}
QgsMessageBar *QgsAppLayoutDesignerInterface::messageBar()
{
return mDesigner->messageBar();
}
void QgsAppLayoutDesignerInterface::selectItems( const QList<QgsLayoutItem *> items )
{
mDesigner->selectItems( items );
@ -136,6 +141,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
centralWidget()->layout()->setMargin( 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 );
mVerticalRuler = new QgsLayoutRuler( nullptr, Qt::Vertical );
mRulerLayoutFix = new QWidget();
@ -1520,6 +1529,9 @@ void QgsLayoutDesignerDialog::exportToRaster()
switch ( exporter.exportToImage( fileNExt.first, settings ) )
{
case QgsLayoutExporter::Success:
mMessageBar->pushInfo( tr( "Export layout" ), tr( "Successfully exported layout to %1" ).arg( fileNExt.first ) );
break;
case QgsLayoutExporter::PrintError:
break;
@ -1614,11 +1626,14 @@ void QgsLayoutDesignerDialog::exportToPdf()
switch ( exporter.exportToPdf( outputFileName, pdfSettings ) )
{
case QgsLayoutExporter::Success:
{
mMessageBar->pushInfo( tr( "Export layout" ), tr( "Successfully exported layout to %1" ).arg( outputFileName ) );
break;
}
case QgsLayoutExporter::FileError:
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 );
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 QgsLayoutItemsListView;
class QgsLayoutPropertiesWidget;
class QgsMessageBar;
class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
@ -51,6 +52,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog );
QgsLayout *layout() override;
QgsLayoutView *view() override;
QgsMessageBar *messageBar() override;
void selectItems( const QList< QgsLayoutItem * > items ) override;
public slots:
@ -114,6 +116,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void selectItems( const QList< QgsLayoutItem * > items );
/**
* Returns the designer's message bar.
*/
QgsMessageBar *messageBar();
public slots:
/**
@ -286,6 +293,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
QgsLayout *mLayout = nullptr;
QgsMessageBar *mMessageBar = nullptr;
QActionGroup *mToolsActionGroup = nullptr;
QgsLayoutView *mView = nullptr;

View File

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