Skip to content

Commit

Permalink
Use messagebar for atlas messages instead of message box
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent b759697 commit 171f402
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
55 changes: 33 additions & 22 deletions src/app/layout/qgslayoutatlaswidget.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout/qgslayoutatlaswidget.h
Expand Up @@ -18,6 +18,7 @@

class QgsPrintLayout;
class QgsLayoutAtlas;
class QgsMessageBar;

/**
* \ingroup app
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -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();

Expand Down
9 changes: 9 additions & 0 deletions src/core/layout/qgslayoutatlas.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit 171f402

Please sign in to comment.