Skip to content

Commit 124f738

Browse files
committed
Allow message bar items to be dismissed from QgsMessageBarItem
1 parent 0a02432 commit 124f738

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

python/gui/auto_generated/qgsmessagebaritem.sip.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ returns the duration in second of the message
8282
QString getStyleSheet();
8383
%Docstring
8484
returns the styleSheet
85+
%End
86+
87+
public slots:
88+
89+
void dismiss();
90+
%Docstring
91+
Dismisses the item, removing it from the message bar and deleting
92+
it. Calling this on items which have not been added to a message bar
93+
has no effect.
94+
95+
.. versionadded:: 3.4
8596
%End
8697

8798
signals:

src/gui/qgsmessagebar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ void QgsMessageBar::showItem( QgsMessageBarItem *item )
267267
void QgsMessageBar::pushItem( QgsMessageBarItem *item )
268268
{
269269
resetCountdown();
270+
271+
item->mMessageBar = this;
272+
270273
// avoid duplicated widget
271274
popWidget( item );
272275
showItem( item );

src/gui/qgsmessagebaritem.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ QgsMessageBarItem *QgsMessageBarItem::setDuration( int duration )
269269
return this;
270270
}
271271

272+
void QgsMessageBarItem::dismiss()
273+
{
274+
if ( !mMessageBar )
275+
return;
276+
277+
mMessageBar->popWidget( this );
278+
}
279+
272280
void QgsMessageBarItem::urlClicked( const QUrl &url )
273281
{
274282
QFileInfo file( url.toLocalFile() );

src/gui/qgsmessagebaritem.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
class QTextBrowser;
2929
class QLabel;
30+
class QgsMessageBar;
3031

3132
/**
3233
* \ingroup gui
@@ -91,6 +92,17 @@ class GUI_EXPORT QgsMessageBarItem : public QWidget
9192
//! returns the styleSheet
9293
QString getStyleSheet() { return mStyleSheet; }
9394

95+
public slots:
96+
97+
/**
98+
* Dismisses the item, removing it from the message bar and deleting
99+
* it. Calling this on items which have not been added to a message bar
100+
* has no effect.
101+
*
102+
* \since QGIS 3.4
103+
*/
104+
void dismiss();
105+
94106
signals:
95107
//! emitted when the message level has changed
96108
void styleChanged( const QString &styleSheet );
@@ -112,6 +124,9 @@ class GUI_EXPORT QgsMessageBarItem : public QWidget
112124
QLabel *mLblIcon = nullptr;
113125
QString mStyleSheet;
114126
QTextBrowser *mTextBrowser = nullptr;
127+
QgsMessageBar *mMessageBar = nullptr;
128+
129+
friend class QgsMessageBar;
115130
};
116131

117132
#endif // qgsmessagebaritem_H

0 commit comments

Comments
 (0)