QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
28 class QWidget;
29 class QGridLayout;
30 class QMenu;
31 class QProgressBar;
32 class QToolButton;
33 class QLabel;
34 class QAction;
35 class QTimer;
36 
37 class QgsMessageBarItem;
38 
42 class GUI_EXPORT QgsMessageBar: public QFrame
43 {
44  Q_OBJECT
45 
46  public:
48  {
49  INFO = 0,
50  WARNING = 1,
51  CRITICAL = 2,
52  SUCCESS = 3
53  };
54 
55  QgsMessageBar( QWidget *parent = nullptr );
56  ~QgsMessageBar();
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:
108  bool popWidget();
109 
113  bool clearWidgets();
114 
121  void pushSuccess( const QString& title, const QString& message );
122 
129  void pushInfo( const QString& title, const QString& message );
130 
137  void pushWarning( const QString& title, const QString& message );
138 
145  void pushCritical( const QString& title, const QString& message );
146 
147  protected:
148  void mousePressEvent( QMouseEvent * e ) override;
149 
150  private:
151  void popItem( QgsMessageBarItem *item );
152  void showItem( QgsMessageBarItem *item );
153  QgsMessageBarItem *mCurrentItem;
155  QMenu *mCloseMenu;
156  QToolButton *mCloseBtn;
157  QGridLayout *mLayout;
158  QLabel *mItemCount;
159  QAction *mActionCloseAll;
160  QTimer *mCountdownTimer;
161  QProgressBar *mCountProgress;
162  QString mCountStyleSheet;
163 
164  private slots:
166  void updateItemCount();
167 
169  void updateCountdown();
170  void resetCountdown();
171 };
172 
173 #endif
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:42
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=5)
convenience method for pushing a message to the bar
Definition: qgsmessagebar.h:90
virtual void mousePressEvent(QMouseEvent *event)
QgsMessageBarItem * currentItem()
Definition: qgsmessagebar.h:94