QGIS API Documentation  2.99.0-Master (9fdd060)
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 
45 class GUI_EXPORT QgsMessageBar: public QFrame
46 {
47  Q_OBJECT
48 
49  public:
51  {
52  INFO = 0,
53  WARNING = 1,
54  CRITICAL = 2,
55  SUCCESS = 3
56  };
57 
58  QgsMessageBar( QWidget *parent SIP_TRANSFERTHIS = 0 );
59 
67  void pushItem( QgsMessageBarItem *item SIP_TRANSFER );
68 
76  QgsMessageBarItem *pushWidget( QWidget *widget SIP_TRANSFER, MessageLevel level = INFO, int duration = 0 );
77 
84  bool popWidget( QgsMessageBarItem *item );
85 
87  static QgsMessageBarItem *createMessage( const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
89  static QgsMessageBarItem *createMessage( const QString &title, const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
91  static QgsMessageBarItem *createMessage( QWidget *widget, QWidget *parent = nullptr ) SIP_FACTORY;
92 
94  void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 5 ) { return pushMessage( QString(), text, level, duration ); }
96  void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 5 );
97 
98  QgsMessageBarItem *currentItem() { return mCurrentItem; }
99 
100  signals:
102  void widgetAdded( QgsMessageBarItem *item );
103 
105  void widgetRemoved( QgsMessageBarItem *item );
106 
107  public slots:
108 
114  bool popWidget();
115 
120  bool clearWidgets();
121 
128  void pushSuccess( const QString &title, const QString &message );
129 
136  void pushInfo( const QString &title, const QString &message );
137 
144  void pushWarning( const QString &title, const QString &message );
145 
152  void pushCritical( const QString &title, const QString &message );
153 
154  protected:
155  void mousePressEvent( QMouseEvent *e ) override;
156 
157  private:
158  void popItem( QgsMessageBarItem *item );
159  void showItem( QgsMessageBarItem *item );
160  QgsMessageBarItem *mCurrentItem = nullptr;
161  QList<QgsMessageBarItem *> mItems;
162  QMenu *mCloseMenu = nullptr;
163  QToolButton *mCloseBtn = nullptr;
164  QGridLayout *mLayout = nullptr;
165  QLabel *mItemCount = nullptr;
166  QAction *mActionCloseAll = nullptr;
167  QTimer *mCountdownTimer = nullptr;
168  QProgressBar *mCountProgress = nullptr;
169  QString mCountStyleSheet;
170 
171  private slots:
173  void updateItemCount();
174 
176  void updateCountdown();
177  void resetCountdown();
178 };
179 
180 #endif
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=5)
convenience method for pushing a message to the bar
Definition: qgsmessagebar.h:94
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsMessageBarItem * currentItem()
Definition: qgsmessagebar.h:98