Skip to content
Permalink
Browse files

[QgsMessageBar] add convenience method to display message with a show…

… more dialog
  • Loading branch information
3nids committed Feb 28, 2018
1 parent b95f5c1 commit fc2ba14154dcae739b60333f5b099313fda4fa7f
Showing with 41 additions and 0 deletions.
  1. +7 −0 python/gui/qgsmessagebar.sip.in
  2. +27 −0 src/gui/qgsmessagebar.cpp
  3. +7 −0 src/gui/qgsmessagebar.h
@@ -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:
@@ -19,6 +19,7 @@
#include "qgsmessagebaritem.h"
#include "qgsapplication.h"
#include "qgsmessagelog.h"
#include "qgsmessageviewer.h"

#include <QWidget>
#include <QPalette>
@@ -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 );
@@ -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:

0 comments on commit fc2ba14

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