Skip to content

Commit

Permalink
[QgsMessageBar] add convenience method to display message with a show…
Browse files Browse the repository at this point in the history
… more dialog
  • Loading branch information
3nids committed Feb 28, 2018
1 parent b95f5c1 commit fc2ba14
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/gui/qgsmessagebar.sip.in
Expand Up @@ -78,6 +78,13 @@ convenience method for pushing a message to the bar
convenience method for pushing a message with title to the bar
%End

void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
%Docstring
convenience method for pushing a message to the bar with a detail text which be shown when pressing a "more" button
%End



QgsMessageBarItem *currentItem();

signals:
Expand Down
27 changes: 27 additions & 0 deletions src/gui/qgsmessagebar.cpp
Expand Up @@ -19,6 +19,7 @@
#include "qgsmessagebaritem.h"
#include "qgsapplication.h"
#include "qgsmessagelog.h"
#include "qgsmessageviewer.h"

#include <QWidget>
#include <QPalette>
Expand Down Expand Up @@ -298,6 +299,32 @@ void QgsMessageBar::pushMessage( const QString &title, const QString &text, Qgis
pushItem( item );
}

void QgsMessageBar::pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level, int duration )
{
QgsMessageViewer *mv = new QgsMessageViewer();
mv->setWindowTitle( title );
mv->setMessageAsPlainText( text + "\n\n" + showMore );

QToolButton *showMoreButton = new QToolButton();
QAction *act = new QAction( showMoreButton );
act->setText( tr( "Show more" ) );
showMoreButton->setStyleSheet( QStringLiteral( "background-color: rgba(255, 255, 255, 0); color: black; text-decoration: underline;" ) );
showMoreButton->setCursor( Qt::PointingHandCursor );
showMoreButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
showMoreButton->addAction( act );
showMoreButton->setDefaultAction( act );
connect( showMoreButton, &QToolButton::triggered, mv, &QDialog::exec );
connect( showMoreButton, &QToolButton::triggered, showMoreButton, &QObject::deleteLater );

QgsMessageBarItem *item = new QgsMessageBarItem(
title,
text,
showMoreButton,
level,
duration );
pushItem( item );
}

QgsMessageBarItem *QgsMessageBar::createMessage( const QString &text, QWidget *parent )
{
QgsMessageBarItem *item = new QgsMessageBarItem( text, Qgis::Info, 0, parent );
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmessagebar.h
Expand Up @@ -89,6 +89,13 @@ class GUI_EXPORT QgsMessageBar: public QFrame
//! convenience method for pushing a message with title to the bar
void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );

//! convenience method for pushing a message to the bar with a detail text which be shown when pressing a "more" button
void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );

// //! make out a widget containing a message to be displayed on the bar with a detail text which be shown when pressing a "more" button
// QgsMessageBarItem( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 0, QWidget *parent SIP_TRANSFERTHIS = nullptr );


QgsMessageBarItem *currentItem() { return mCurrentItem; }

signals:
Expand Down

0 comments on commit fc2ba14

Please sign in to comment.