QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgstaskmanagerwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstaskmanagerwidget.h
3 ----------------------
4 begin : April 2016
5 copyright : (C) 2016 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
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 QGSTASKMANAGERWIDGET_H
18#define QGSTASKMANAGERWIDGET_H
19
20#include "qgsfloatingwidget.h"
21#include "qgis_sip.h"
22#include "qgstaskmanager.h"
23#include <QStyledItemDelegate>
24#include <QToolButton>
25#include "qgis_gui.h"
26
27class QgsTaskManager;
28class QgsTask;
29class QTreeView;
30class QProgressBar;
31class QgsTaskManagerModel;
32
39class GUI_EXPORT QgsTaskManagerWidget : public QWidget
40{
41 Q_OBJECT
42
43 public:
44
50 QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *parent SIP_TRANSFERTHIS = nullptr );
51
52 ~QgsTaskManagerWidget() override;
53
54 private slots:
55
56 void modelRowsInserted( const QModelIndex &index, int start, int end );
57 void clicked( const QModelIndex &index );
58
59 private:
60
61 QgsTaskManager *mManager = nullptr;
62 QTreeView *mTreeView = nullptr;
63 QgsTaskManagerModel *mModel = nullptr;
64};
65
66#ifndef SIP_RUN
67
69
76class GUI_EXPORT QgsTaskManagerFloatingWidget : public QgsFloatingWidget
77{
78 Q_OBJECT
79
80 public:
81
87 QgsTaskManagerFloatingWidget( QgsTaskManager *manager, QWidget *parent = nullptr );
88
89};
90
98class GUI_EXPORT QgsTaskManagerStatusBarWidget : public QToolButton
99{
100 Q_OBJECT
101
102 public:
103
109 QgsTaskManagerStatusBarWidget( QgsTaskManager *manager, QWidget *parent = nullptr );
110
111 QSize sizeHint() const override;
112
113 protected:
114
115 void changeEvent( QEvent *event ) override;
116
117 private slots:
118
119 void toggleDisplay();
120 void overallProgressChanged( double progress );
121 void countActiveTasksChanged( int count );
122 void allFinished();
123 void showButton();
124
125 private:
126
127 QgsTaskManagerFloatingWidget *mFloatingWidget = nullptr;
128 QProgressBar *mProgressBar = nullptr;
129 QgsTaskManager *mManager = nullptr;
130};
131
138class GUI_EXPORT QgsTaskManagerModel: public QAbstractItemModel
139{
140 Q_OBJECT
141
142 public:
143
144 enum Columns
145 {
146 Description = 0,
147 Progress = 1,
148 Status = 2,
149 };
150
151 // *INDENT-OFF*
152
159 enum class CustomRole SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsTaskManagerModel, Roles ) : int
160 {
161 Status SIP_MONKEYPATCH_COMPAT_NAME(StatusRole) = Qt::UserRole,
162 };
163 Q_ENUM( CustomRole )
164 // *INDENT-ON*
165
166
171 explicit QgsTaskManagerModel( QgsTaskManager *manager, QObject *parent = nullptr );
172
173 //reimplemented QAbstractItemModel methods
174 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
175 QModelIndex parent( const QModelIndex &index ) const override;
176 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
177 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
178 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
179 Qt::ItemFlags flags( const QModelIndex &index ) const override;
180 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
181
186 QgsTask *indexToTask( const QModelIndex &index ) const;
187
188 private slots:
189
190 void taskAdded( long id );
191 void taskDeleted( long id );
192 void progressChanged( long id, double progress );
193 void statusChanged( long id, int status );
194
195 private:
196
197 enum ToolTipType
198 {
199 ToolTipDescription,
200 ToolTipStatus,
201 ToolTipProgress,
202 };
203
204 QgsTaskManager *mManager = nullptr;
205
206 QList< long > mRowToTaskIdList;
207
208
209 int idToRow( long id ) const;
210 QModelIndex idToIndex( long id, int column ) const;
211 static QString createTooltip( QgsTask *task, ToolTipType type );
212
213 friend class QgsTaskManagerStatusBarWidget;
214};
215
221class GUI_EXPORT QgsTaskStatusWidget : public QWidget
222{
223 Q_OBJECT
224
225 public:
226
231 QgsTaskStatusWidget( QWidget *parent = nullptr, QgsTask::TaskStatus status = QgsTask::Queued, bool canCancel = true );
232
233
234 QSize sizeHint() const override;
235
236 //bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) override;
237
238 public slots:
239
243 void setStatus( int status );
244
245 signals:
246
250 void cancelClicked();
251
252 protected:
253
254 void paintEvent( QPaintEvent *e ) override;
255 void mousePressEvent( QMouseEvent *e ) override;
256 void mouseMoveEvent( QMouseEvent *e ) override;
257 void leaveEvent( QEvent *e ) override;
258
259 private:
260
261 bool mCanCancel;
262 QgsTask::TaskStatus mStatus;
263 bool mInside = false;
264};
265
268
269#endif
270
271#endif //QGSTASKMANAGERWIDGET_H
A QWidget subclass for creating widgets which float outside of the normal Qt layout system.
A widget which displays tasks from a QgsTaskManager and allows for interaction with the manager.
Task manager for managing a set of long-running QgsTask tasks.
Abstract base class for long running background tasks.
TaskStatus
Status of tasks.
@ Queued
Task is queued and has not begun.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273