QGIS API Documentation  3.2.0-Bonn (bc43194)
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:
50 
52  QgsMessageBar( QWidget *parent SIP_TRANSFERTHIS = nullptr );
53 
61  void pushItem( QgsMessageBarItem *item SIP_TRANSFER );
62 
70  QgsMessageBarItem *pushWidget( QWidget *widget SIP_TRANSFER, Qgis::MessageLevel level = Qgis::Info, int duration = 0 );
71 
78  bool popWidget( QgsMessageBarItem *item );
79 
81  static QgsMessageBarItem *createMessage( const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
83  static QgsMessageBarItem *createMessage( const QString &title, const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
85  static QgsMessageBarItem *createMessage( QWidget *widget, QWidget *parent = nullptr ) SIP_FACTORY;
86 
88  void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 5 ) { pushMessage( QString(), text, level, duration ); }
90  void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::Info, int duration = 5 );
91 
93  void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::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 
111  bool popWidget();
112 
117  bool clearWidgets();
118 
125  void pushSuccess( const QString &title, const QString &message );
126 
133  void pushInfo( const QString &title, const QString &message );
134 
141  void pushWarning( const QString &title, const QString &message );
142 
149  void pushCritical( const QString &title, const QString &message );
150 
151  protected:
152  void mousePressEvent( QMouseEvent *e ) override;
153 
154  private:
155  void popItem( QgsMessageBarItem *item );
156  void showItem( QgsMessageBarItem *item );
157  QgsMessageBarItem *mCurrentItem = nullptr;
158  QList<QgsMessageBarItem *> mItems;
159  QMenu *mCloseMenu = nullptr;
160  QToolButton *mCloseBtn = nullptr;
161  QGridLayout *mLayout = nullptr;
162  QLabel *mItemCount = nullptr;
163  QAction *mActionCloseAll = nullptr;
164  QTimer *mCountdownTimer = nullptr;
165  QProgressBar *mCountProgress = nullptr;
166  QString mCountStyleSheet;
167 
168  private slots:
170  void updateItemCount();
171 
173  void updateCountdown();
174  void resetCountdown();
175 };
176 
177 #endif
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:78
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:69
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=5)
convenience method for pushing a message to the bar
Definition: qgsmessagebar.h:88
QgsMessageBarItem * currentItem()
Definition: qgsmessagebar.h:95