QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmessagebar.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmessagebar.h - description
3  -------------------
4  begin : June 2012
5  copyright : (C) 2012 by Giuseppe Sucameli
6  email : sucameli at faunalia dot it
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSMESSAGEBAR_H
18 #define QGSMESSAGEBAR_H
19 
20 #include "qgsguiutils.h"
21 #include "qgis.h"
22 
23 #include <QString>
24 #include <QFrame>
25 #include <QIcon>
26 #include <QColor>
27 #include <QList>
28 #include "qgis_gui.h"
29 
30 class QWidget;
31 class QGridLayout;
32 class QMenu;
33 class QProgressBar;
34 class QToolButton;
35 class QLabel;
36 class QAction;
37 class QTimer;
38 
39 class QgsMessageBarItem;
40 
60 class GUI_EXPORT QgsMessageBar: public QFrame
61 {
62  Q_OBJECT
63 
64  public:
65 
67  QgsMessageBar( QWidget *parent SIP_TRANSFERTHIS = nullptr );
68 
75  void pushItem( QgsMessageBarItem *item SIP_TRANSFER );
76 
86  QgsMessageBarItem *pushWidget( QWidget *widget SIP_TRANSFER, Qgis::MessageLevel level = Qgis::Info, int duration = 0 );
87 
95  bool popWidget( QgsMessageBarItem *item );
96 
105  static QgsMessageBarItem *createMessage( const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
106 
115  static QgsMessageBarItem *createMessage( const QString &title, const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
116 
125  static QgsMessageBarItem *createMessage( QWidget *widget, QWidget *parent = nullptr ) SIP_FACTORY;
126 
136  void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
137 
147  void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
148 
159  void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
160 
164  QgsMessageBarItem *currentItem();
165 
171  QList<QgsMessageBarItem *> items();
172 
173  signals:
174 
179 
184 
185  public slots:
186 
193  bool popWidget();
194 
200  bool clearWidgets();
201 
210  void pushSuccess( const QString &title, const QString &message );
211 
220  void pushInfo( const QString &title, const QString &message );
221 
230  void pushWarning( const QString &title, const QString &message );
231 
240  void pushCritical( const QString &title, const QString &message );
241 
242  protected:
243  void mousePressEvent( QMouseEvent *e ) override;
244 
245  private:
246  void popItem( QgsMessageBarItem *item );
247  void showItem( QgsMessageBarItem *item );
248  QgsMessageBarItem *mCurrentItem = nullptr;
249  QList<QgsMessageBarItem *> mItems;
250  QMenu *mCloseMenu = nullptr;
251  QToolButton *mCloseBtn = nullptr;
252  QGridLayout *mLayout = nullptr;
253  QLabel *mItemCount = nullptr;
254  QAction *mActionCloseAll = nullptr;
255  QTimer *mCountdownTimer = nullptr;
256  QProgressBar *mCountProgress = nullptr;
257  QString mCountStyleSheet;
258  Qgis::MessageLevel mPrevLevel = Qgis::MessageLevel::None;
259 
260  static constexpr int MAX_ITEMS = 100;
261 
262  void removeLowestPriorityOldestItem();
263 
264  private slots:
266  void updateItemCount();
267 
269  void updateCountdown();
270  void resetCountdown();
271 
272  friend class TestQgsMessageBar;
273 };
274 
275 #endif
QgsMessageBar::widgetAdded
void widgetAdded(QgsMessageBarItem *item)
Emitted whenever an item is added to the bar.
qgis.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
Qgis::Info
@ Info
Definition: qgis.h:90
QgsMessageBarItem
Represents an item shown within a QgsMessageBar widget.
Definition: qgsmessagebaritem.h:39
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:89
qgsguiutils.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsMessageBar::widgetRemoved
void widgetRemoved(QgsMessageBarItem *item)
Emitted whenever an item was removed from the bar.