Skip to content
Permalink
Browse files

Use messagebar for atlas messages instead of message box

  • Loading branch information
nyalldawson committed Dec 19, 2017
1 parent b759697 commit 171f402ab0b19f34b7a954ccd14cb2f7b2c27525
@@ -16,13 +16,13 @@

#include <QComboBox>
#include <QImageWriter>
#include <QMessageBox>

#include "qgslayoutatlaswidget.h"
#include "qgsprintlayout.h"
#include "qgslayoutatlas.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgslayoutundostack.h"
#include "qgsmessagebar.h"

QgsLayoutAtlasWidget::QgsLayoutAtlasWidget( QWidget *parent, QgsPrintLayout *layout )
: QWidget( parent )
@@ -68,6 +68,11 @@ QgsLayoutAtlasWidget::QgsLayoutAtlasWidget( QWidget *parent, QgsPrintLayout *lay
updateGuiElements();
}

void QgsLayoutAtlasWidget::setMessageBar( QgsMessageBar *bar )
{
mMessageBar = bar;
}

void QgsLayoutAtlasWidget::mUseAtlasCheckBox_stateChanged( int state )
{
if ( state == Qt::Checked )
@@ -108,12 +113,10 @@ void QgsLayoutAtlasWidget::mAtlasFilenamePatternEdit_editingFinished()
if ( !mAtlas->setFilenameExpression( mAtlasFilenamePatternEdit->text(), error ) )
{
//expression could not be set
QMessageBox::warning( this
, tr( "Could not evaluate filename pattern" )
, tr( "Could not set filename pattern as '%1'.\nParser error:\n%2" )
.arg( mAtlasFilenamePatternEdit->text(),
error )
);
mMessageBar->pushWarning( tr( "Atlas" ),
tr( "Could not set filename expression to '%1'.\nParser error:\n%2" )
.arg( mAtlasFilenamePatternEdit->text(),
error ) );
}
mLayout->undoStack()->endCommand();
}
@@ -141,12 +144,9 @@ void QgsLayoutAtlasWidget::mAtlasFilenameExpressionButton_clicked()
if ( !mAtlas->setFilenameExpression( expression, error ) )
{
//expression could not be set
QMessageBox::warning( this
, tr( "Could not evaluate filename pattern" )
, tr( "Could not set filename pattern as '%1'.\nParser error:\n%2" )
.arg( expression,
error )
);
mMessageBar->pushWarning( tr( "Atlas" ), tr( "Could not set filename expression to '%1'.\nParser error:\n%2" )
.arg( expression,
error ) );
}
mLayout->undoStack()->endCommand();
}
@@ -205,20 +205,15 @@ void QgsLayoutAtlasWidget::changesSortFeatureExpression( const QString &expressi

void QgsLayoutAtlasWidget::updateAtlasFeatures()
{
#if 0 //TODO
bool updated = mAtlas->updateFeatures();
if ( !updated )
{
QMessageBox::warning( nullptr, tr( "Atlas preview" ),
tr( "No matching atlas features found!" ),
QMessageBox::Ok,
QMessageBox::Ok );
mMessageBar->pushInfo( tr( "Atlas" ),
tr( "No matching atlas features found!" ) );

//Perhaps atlas preview should be disabled now? If so, it may get annoying if user is editing
//the filter expression and it keeps disabling itself.
return;
}
#endif
}

void QgsLayoutAtlasWidget::mAtlasFeatureFilterCheckBox_stateChanged( int state )
@@ -256,7 +251,15 @@ void QgsLayoutAtlasWidget::mAtlasFeatureFilterEdit_editingFinished()
{
QString error;
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Filter" ) );
mAtlas->setFilterExpression( mAtlasFeatureFilterEdit->text(), error );

if ( !mAtlas->setFilterExpression( mAtlasFeatureFilterEdit->text(), error ) )
{
//expression could not be set
mMessageBar->pushWarning( tr( "Atlas" ), tr( "Could not set filter expression to '%1'.\nParser error:\n%2" )
.arg( mAtlasFeatureFilterEdit->text(),
error ) );
}

mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}
@@ -282,7 +285,15 @@ void QgsLayoutAtlasWidget::mAtlasFeatureFilterButton_clicked()
mAtlasFeatureFilterEdit->setText( expression );
QString error;
mLayout->undoStack()->beginCommand( mAtlas, tr( "Change Atlas Filter" ) );
mAtlas->setFilterExpression( mAtlasFeatureFilterEdit->text(), error );
if ( !mAtlas->setFilterExpression( mAtlasFeatureFilterEdit->text(), error ) )
{
//expression could not be set
mMessageBar->pushWarning( tr( "Atlas" ),
tr( "Could not set filter expression to '%1'.\nParser error:\n%2" )
.arg( mAtlasFeatureFilterEdit->text(),
error )
);
}
mLayout->undoStack()->endCommand();
updateAtlasFeatures();
}
@@ -18,6 +18,7 @@

class QgsPrintLayout;
class QgsLayoutAtlas;
class QgsMessageBar;

/**
* \ingroup app
@@ -28,6 +29,7 @@ class QgsLayoutAtlasWidget: public QWidget, private Ui::QgsLayoutAtlasWidgetBase
Q_OBJECT
public:
QgsLayoutAtlasWidget( QWidget *parent, QgsPrintLayout *layout );
void setMessageBar( QgsMessageBar *bar );

private slots:
void mUseAtlasCheckBox_stateChanged( int state );
@@ -50,6 +52,7 @@ class QgsLayoutAtlasWidget: public QWidget, private Ui::QgsLayoutAtlasWidgetBase
private:
QgsPrintLayout *mLayout = nullptr;
QgsLayoutAtlas *mAtlas = nullptr;
QgsMessageBar *mMessageBar = nullptr;

void blockAllSignals( bool b );
void checkLayerType( QgsVectorLayer *layer );
@@ -2219,6 +2219,7 @@ void QgsLayoutDesignerDialog::createAtlasWidget()
QgsPrintLayout *printLayout = qobject_cast< QgsPrintLayout * >( mLayout );
QgsLayoutAtlas *atlas = printLayout->atlas();
QgsLayoutAtlasWidget *atlasWidget = new QgsLayoutAtlasWidget( mGeneralDock, printLayout );
atlasWidget->setMessageBar( mMessageBar );
mAtlasDock->setWidget( atlasWidget );
mAtlasDock->show();

@@ -162,7 +162,16 @@ QString QgsLayoutAtlas::nameForPage( int pageNumber ) const

bool QgsLayoutAtlas::setFilterExpression( const QString &expression, QString &errorString )
{
errorString.clear();
mFilterExpression = expression;

QgsExpression filterExpression( mFilterExpression );
if ( filterExpression.hasParserError() )
{
errorString = filterExpression.parserErrorString();
return false;
}

return true;
}

0 comments on commit 171f402

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