mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
[QgsMessageBar] add convenience method to display message with a show more dialog
This commit is contained in:
parent
b95f5c1a15
commit
fc2ba14154
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user