QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
30class QWidget;
31class QGridLayout;
32class QMenu;
33class QProgressBar;
34class QToolButton;
35class QLabel;
36class QAction;
37class QTimer;
38
40
60class GUI_EXPORT QgsMessageBar: public QFrame
61{
62 Q_OBJECT
63
64 public:
65
67 QgsMessageBar( QWidget *parent SIP_TRANSFERTHIS = nullptr );
68
75 void pushItem( QgsMessageBarItem *item SIP_TRANSFER );
76
86 QgsMessageBarItem *pushWidget( QWidget *widget SIP_TRANSFER, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 0 );
87
95 bool popWidget( QgsMessageBarItem *item );
96
105 static QgsMessageBarItem *createMessage( const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
106
115 static QgsMessageBarItem *createMessage( const QString &title, const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
116
125 static QgsMessageBarItem *createMessage( QWidget *widget, QWidget *parent = nullptr ) SIP_FACTORY;
126
137 void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
138
149 void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
150
162 void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
163
167 QgsMessageBarItem *currentItem();
168
174 QList<QgsMessageBarItem *> items();
175
180 static int defaultMessageTimeout( Qgis::MessageLevel level = Qgis::MessageLevel::NoLevel );
181
182 signals:
183
188
193
194 public slots:
195
202 bool popWidget();
203
209 bool clearWidgets();
210
218 void pushSuccess( const QString &title, const QString &message );
219
227 void pushInfo( const QString &title, const QString &message );
228
236 void pushWarning( const QString &title, const QString &message );
237
245 void pushCritical( const QString &title, const QString &message );
246
247 protected:
248 void mousePressEvent( QMouseEvent *e ) override;
249
250 private:
251 void popItem( QgsMessageBarItem *item );
252 void showItem( QgsMessageBarItem *item );
253 QgsMessageBarItem *mCurrentItem = nullptr;
254 QList<QgsMessageBarItem *> mItems;
255 QMenu *mCloseMenu = nullptr;
256 QToolButton *mCloseBtn = nullptr;
257 QGridLayout *mLayout = nullptr;
258 QLabel *mItemCount = nullptr;
259 QAction *mActionCloseAll = nullptr;
260 QTimer *mCountdownTimer = nullptr;
261 QProgressBar *mCountProgress = nullptr;
262 QString mCountStyleSheet;
263 Qgis::MessageLevel mPrevLevel = Qgis::MessageLevel::NoLevel;
264
265 static constexpr int MAX_ITEMS = 100;
266
267 void removeLowestPriorityOldestItem();
268
269 private slots:
271 void updateItemCount();
272
274 void updateCountdown();
275 void resetCountdown();
276
277 friend class TestQgsMessageBar;
278};
279
280#endif
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:99
Represents an item shown within a QgsMessageBar widget.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
void widgetAdded(QgsMessageBarItem *item)
Emitted whenever an item is added to the bar.
void widgetRemoved(QgsMessageBarItem *item)
Emitted whenever an item was removed from the bar.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76