Skip to content

Commit fc2ba14

Browse files
committed
[QgsMessageBar] add convenience method to display message with a show more dialog
1 parent b95f5c1 commit fc2ba14

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

python/gui/qgsmessagebar.sip.in

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ convenience method for pushing a message to the bar
7878
convenience method for pushing a message with title to the bar
7979
%End
8080

81+
void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
82+
%Docstring
83+
convenience method for pushing a message to the bar with a detail text which be shown when pressing a "more" button
84+
%End
85+
86+
87+
8188
QgsMessageBarItem *currentItem();
8289

8390
signals:

src/gui/qgsmessagebar.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsmessagebaritem.h"
2020
#include "qgsapplication.h"
2121
#include "qgsmessagelog.h"
22+
#include "qgsmessageviewer.h"
2223

2324
#include <QWidget>
2425
#include <QPalette>
@@ -298,6 +299,32 @@ void QgsMessageBar::pushMessage( const QString &title, const QString &text, Qgis
298299
pushItem( item );
299300
}
300301

302+
void QgsMessageBar::pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level, int duration )
303+
{
304+
QgsMessageViewer *mv = new QgsMessageViewer();
305+
mv->setWindowTitle( title );
306+
mv->setMessageAsPlainText( text + "\n\n" + showMore );
307+
308+
QToolButton *showMoreButton = new QToolButton();
309+
QAction *act = new QAction( showMoreButton );
310+
act->setText( tr( "Show more" ) );
311+
showMoreButton->setStyleSheet( QStringLiteral( "background-color: rgba(255, 255, 255, 0); color: black; text-decoration: underline;" ) );
312+
showMoreButton->setCursor( Qt::PointingHandCursor );
313+
showMoreButton->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred );
314+
showMoreButton->addAction( act );
315+
showMoreButton->setDefaultAction( act );
316+
connect( showMoreButton, &QToolButton::triggered, mv, &QDialog::exec );
317+
connect( showMoreButton, &QToolButton::triggered, showMoreButton, &QObject::deleteLater );
318+
319+
QgsMessageBarItem *item = new QgsMessageBarItem(
320+
title,
321+
text,
322+
showMoreButton,
323+
level,
324+
duration );
325+
pushItem( item );
326+
}
327+
301328
QgsMessageBarItem *QgsMessageBar::createMessage( const QString &text, QWidget *parent )
302329
{
303330
QgsMessageBarItem *item = new QgsMessageBarItem( text, Qgis::Info, 0, parent );

src/gui/qgsmessagebar.h

+7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ class GUI_EXPORT QgsMessageBar: public QFrame
8989
//! convenience method for pushing a message with title to the bar
9090
void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
9191

92+
//! convenience method for pushing a message to the bar with a detail text which be shown when pressing a "more" button
93+
void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
94+
95+
// //! 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
96+
// QgsMessageBarItem( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 0, QWidget *parent SIP_TRANSFERTHIS = nullptr );
97+
98+
9299
QgsMessageBarItem *currentItem() { return mCurrentItem; }
93100

94101
signals:

0 commit comments

Comments
 (0)