QGIS API Documentation  2.99.0-Master (90ae728)
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 <qgisgui.h>
21 
22 #include <QString>
23 #include <QFrame>
24 #include <QIcon>
25 #include <QColor>
26 #include <QList>
27 #include "qgis_gui.h"
28 
29 class QWidget;
30 class QGridLayout;
31 class QMenu;
32 class QProgressBar;
33 class QToolButton;
34 class QLabel;
35 class QAction;
36 class QTimer;
37 
38 class QgsMessageBarItem;
39 
43 class GUI_EXPORT QgsMessageBar: public QFrame
44 {
45  Q_OBJECT
46 
47  public:
49  {
50  INFO = 0,
51  WARNING = 1,
52  CRITICAL = 2,
53  SUCCESS = 3
54  };
55 
56  QgsMessageBar( QWidget *parent = nullptr );
57 
65  void pushItem( QgsMessageBarItem *item );
66 
73  QgsMessageBarItem *pushWidget( QWidget *widget, MessageLevel level = INFO, int duration = 0 );
74 
80  bool popWidget( QgsMessageBarItem *item );
81 
83  static QgsMessageBarItem* createMessage( const QString &text, QWidget *parent = nullptr );
85  static QgsMessageBarItem* createMessage( const QString &title, const QString &text, QWidget *parent = nullptr );
87  static QgsMessageBarItem* createMessage( QWidget *widget, QWidget *parent = nullptr );
88 
90  void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 5 ) { return pushMessage( QString::null, text, level, duration ); }
92  void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 5 );
93 
94  QgsMessageBarItem *currentItem() { return mCurrentItem; }
95 
96  signals:
98  void widgetAdded( QgsMessageBarItem *item );
99 
101  void widgetRemoved( QgsMessageBarItem *item );
102 
103  public slots:
104 
109  bool popWidget();
110 
114  bool clearWidgets();
115 
122  void pushSuccess( const QString& title, const QString& message );
123 
130  void pushInfo( const QString& title, const QString& message );
131 
138  void pushWarning( const QString& title, const QString& message );
139 
146  void pushCritical( const QString& title, const QString& message );
147 
148  protected:
149  void mousePressEvent( QMouseEvent * e ) override;
150 
151  private:
152  void popItem( QgsMessageBarItem *item );
153  void showItem( QgsMessageBarItem *item );
154  QgsMessageBarItem *mCurrentItem = nullptr;
155  QList<QgsMessageBarItem *> mItems;
156  QMenu *mCloseMenu = nullptr;
157  QToolButton *mCloseBtn = nullptr;
158  QGridLayout *mLayout = nullptr;
159  QLabel *mItemCount = nullptr;
160  QAction *mActionCloseAll = nullptr;
161  QTimer *mCountdownTimer = nullptr;
162  QProgressBar *mCountProgress = nullptr;
163  QString mCountStyleSheet;
164 
165  private slots:
167  void updateItemCount();
168 
170  void updateCountdown();
171  void resetCountdown();
172 };
173 
174 #endif
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:43
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=5)
convenience method for pushing a message to the bar
Definition: qgsmessagebar.h:90
QgsMessageBarItem * currentItem()
Definition: qgsmessagebar.h:94