QGIS API Documentation  3.20.0-Odense (decaadbb31)
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::MessageLevel::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 
137  void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
138 
149  void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
150 
162  void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
163 
167  QgsMessageBarItem *currentItem();
168 
174  QList<QgsMessageBarItem *> items();
175 
180  static int defaultMessageTimeout( Qgis::MessageLevel level = Qgis::MessageLevel::NoLevel );
181 
182  signals:
183 
188 
193 
194  public slots:
195 
202  bool popWidget();
203 
209  bool clearWidgets();
210 
219  void pushSuccess( const QString &title, const QString &message );
220 
229  void pushInfo( const QString &title, const QString &message );
230 
239  void pushWarning( const QString &title, const QString &message );
240 
249  void pushCritical( const QString &title, const QString &message );
250 
251  protected:
252  void mousePressEvent( QMouseEvent *e ) override;
253 
254  private:
255  void popItem( QgsMessageBarItem *item );
256  void showItem( QgsMessageBarItem *item );
257  QgsMessageBarItem *mCurrentItem = nullptr;
258  QList<QgsMessageBarItem *> mItems;
259  QMenu *mCloseMenu = nullptr;
260  QToolButton *mCloseBtn = nullptr;
261  QGridLayout *mLayout = nullptr;
262  QLabel *mItemCount = nullptr;
263  QAction *mActionCloseAll = nullptr;
264  QTimer *mCountdownTimer = nullptr;
265  QProgressBar *mCountProgress = nullptr;
266  QString mCountStyleSheet;
267  Qgis::MessageLevel mPrevLevel = Qgis::MessageLevel::NoLevel;
268 
269  static constexpr int MAX_ITEMS = 100;
270 
271  void removeLowestPriorityOldestItem();
272 
273  private slots:
275  void updateItemCount();
276 
278  void updateCountdown();
279  void resetCountdown();
280 
281  friend class TestQgsMessageBar;
282 };
283 
284 #endif
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:105
Represents an item shown within a QgsMessageBar widget.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
void widgetAdded(QgsMessageBarItem *item)
Emitted whenever an item is added to the bar.
void widgetRemoved(QgsMessageBarItem *item)
Emitted whenever an item was removed from the bar.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76