QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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:
66 QgsMessageBar( QWidget *parent SIP_TRANSFERTHIS = nullptr );
67
74 void pushItem( QgsMessageBarItem *item SIP_TRANSFER );
75
85 QgsMessageBarItem *pushWidget( QWidget *widget SIP_TRANSFER, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = 0 );
86
94 bool popWidget( QgsMessageBarItem *item );
95
104 static QgsMessageBarItem *createMessage( const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
105
114 static QgsMessageBarItem *createMessage( const QString &title, const QString &text, QWidget *parent = nullptr ) SIP_FACTORY;
115
124 static QgsMessageBarItem *createMessage( QWidget *widget, QWidget *parent = nullptr ) SIP_FACTORY;
125
136 void pushMessage( const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
137
148 void pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
149
161 void pushMessage( const QString &title, const QString &text, const QString &showMore, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1 );
162
166 QgsMessageBarItem *currentItem();
167
173 QList<QgsMessageBarItem *> items();
174
179 static int defaultMessageTimeout( Qgis::MessageLevel level = Qgis::MessageLevel::NoLevel );
180
181 signals:
182
187
192
193 public slots:
194
201 bool popWidget();
202
208 bool clearWidgets();
209
217 void pushSuccess( const QString &title, const QString &message );
218
226 void pushInfo( const QString &title, const QString &message );
227
235 void pushWarning( const QString &title, const QString &message );
236
244 void pushCritical( const QString &title, const QString &message );
245
246 protected:
247 void mousePressEvent( QMouseEvent *e ) override;
248
249 private:
250 void popItem( QgsMessageBarItem *item );
251 void showItem( QgsMessageBarItem *item );
252 QgsMessageBarItem *mCurrentItem = nullptr;
253 QList<QgsMessageBarItem *> mItems;
254 QMenu *mCloseMenu = nullptr;
255 QToolButton *mCloseBtn = nullptr;
256 QGridLayout *mLayout = nullptr;
257 QLabel *mItemCount = nullptr;
258 QAction *mActionCloseAll = nullptr;
259 QTimer *mCountdownTimer = nullptr;
260 QProgressBar *mCountProgress = nullptr;
261 QString mCountStyleSheet;
263
264 static constexpr int MAX_ITEMS = 100;
265
266 void removeLowestPriorityOldestItem();
267
268 private slots:
270 void updateItemCount();
271
273 void updateCountdown();
274 void resetCountdown();
275
276 friend class TestQgsMessageBar;
277};
278
279#endif
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
@ NoLevel
No level.
Definition qgis.h:159
@ Info
Information message.
Definition qgis.h:155
Represents an item shown within a QgsMessageBar widget.
A bar for displaying non-blocking messages to the user.
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