Skip to content

Commit

Permalink
Add a messagebar to layout designer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 17, 2017
1 parent b992e87 commit 261492d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/gui/layout/qgslayoutdesignerinterface.sip
Expand Up @@ -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``.
Expand Down
22 changes: 21 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1880,4 +1895,9 @@ void QgsLayoutDesignerDialog::selectItems( const QList<QgsLayoutItem *> items )
}
}

QgsMessageBar *QgsLayoutDesignerDialog::messageBar()
{
return mMessageBar;
}


9 changes: 9 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -42,6 +42,7 @@ class QUndoView;
class QTreeView;
class QgsLayoutItemsListView;
class QgsLayoutPropertiesWidget;
class QgsMessageBar;

class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
Expand All @@ -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:
Expand Down Expand Up @@ -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:

/**
Expand Down Expand Up @@ -286,6 +293,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

QgsLayout *mLayout = nullptr;

QgsMessageBar *mMessageBar = nullptr;

QActionGroup *mToolsActionGroup = nullptr;

QgsLayoutView *mView = nullptr;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/layout/qgslayoutdesignerinterface.h
Expand Up @@ -23,6 +23,7 @@
class QgsLayout;
class QgsLayoutView;
class QgsLayoutItem;
class QgsMessageBar;

/**
* \ingroup gui
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 261492d

Please sign in to comment.