QGIS API Documentation  2.99.0-Master (f867b65)
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 
44 class GUI_EXPORT QgsMessageBar: public QFrame
45 {
46  Q_OBJECT
47 
48  public:
50  {
51  INFO = 0,
52  WARNING = 1,
53  CRITICAL = 2,
54  SUCCESS = 3
55  };
56 
57  QgsMessageBar( QWidget *parent SIP_TRANSFERTHIS = 0 );
58 
66  void pushItem( QgsMessageBarItem *item SIP_TRANSFER );
67 
74  QgsMessageBarItem *pushWidget( QWidget *widget SIP_TRANSFER, MessageLevel level = INFO, int duration = 0 );
75 
81  bool popWidget( QgsMessageBarItem *item );
82 
84  static QgsMessageBarItem *createMessage( const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
86  static QgsMessageBarItem *createMessage( const QString &title, const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
88  static QgsMessageBarItem *createMessage( QWidget *widget, QWidget *parent = nullptr ) SIP_FACTORY;
89 
91  void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 5 ) { return pushMessage( QString(), text, level, duration ); }
93  void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 5 );
94 
95  QgsMessageBarItem *currentItem() { return mCurrentItem; }
96 
97  signals:
99  void widgetAdded( QgsMessageBarItem *item );
100 
102  void widgetRemoved( QgsMessageBarItem *item );
103 
104  public slots:
105 
110  bool popWidget();
111 
115  bool clearWidgets();
116 
123  void pushSuccess( const QString &title, const QString &message );
124 
131  void pushInfo( const QString &title, const QString &message );
132 
139  void pushWarning( const QString &title, const QString &message );
140 
147  void pushCritical( const QString &title, const QString &message );
148 
149  protected:
150  void mousePressEvent( QMouseEvent *e ) override;
151 
152  private:
153  void popItem( QgsMessageBarItem *item );
154  void showItem( QgsMessageBarItem *item );
155  QgsMessageBarItem *mCurrentItem = nullptr;
156  QList<QgsMessageBarItem *> mItems;
157  QMenu *mCloseMenu = nullptr;
158  QToolButton *mCloseBtn = nullptr;
159  QGridLayout *mLayout = nullptr;
160  QLabel *mItemCount = nullptr;
161  QAction *mActionCloseAll = nullptr;
162  QTimer *mCountdownTimer = nullptr;
163  QProgressBar *mCountProgress = nullptr;
164  QString mCountStyleSheet;
165 
166  private slots:
168  void updateItemCount();
169 
171  void updateCountdown();
172  void resetCountdown();
173 };
174 
175 #endif
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:44
void pushMessage(const QString &text, MessageLevel level=INFO, int duration=5)
convenience method for pushing a message to the bar
Definition: qgsmessagebar.h:91
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:69
QgsMessageBarItem * currentItem()
Definition: qgsmessagebar.h:95