QGIS API Documentation 3.41.0-Master (cea29feecf2)
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:
49 QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *parent SIP_TRANSFERTHIS = nullptr );
50
51 ~QgsTaskManagerWidget() override;
52
53 private slots:
54
55 void modelRowsInserted( const QModelIndex &index, int start, int end );
56 void clicked( const QModelIndex &index );
57
58 private:
59 QgsTaskManager *mManager = nullptr;
60 QTreeView *mTreeView = nullptr;
61 QgsTaskManagerModel *mModel = nullptr;
62};
63
64#ifndef SIP_RUN
65
67
74class GUI_EXPORT QgsTaskManagerFloatingWidget : public QgsFloatingWidget
75{
76 Q_OBJECT
77
78 public:
84 QgsTaskManagerFloatingWidget( QgsTaskManager *manager, QWidget *parent = nullptr );
85};
86
94class GUI_EXPORT QgsTaskManagerStatusBarWidget : public QToolButton
95{
96 Q_OBJECT
97
98 public:
104 QgsTaskManagerStatusBarWidget( QgsTaskManager *manager, QWidget *parent = nullptr );
105
106 QSize sizeHint() const override;
107
108 protected:
109 void changeEvent( QEvent *event ) override;
110
111 private slots:
112
113 void toggleDisplay();
114 void overallProgressChanged( double progress );
115 void countActiveTasksChanged( int count );
116 void allFinished();
117 void showButton();
118
119 private:
120 QgsTaskManagerFloatingWidget *mFloatingWidget = nullptr;
121 QProgressBar *mProgressBar = nullptr;
122 QgsTaskManager *mManager = nullptr;
123};
124
131class GUI_EXPORT QgsTaskManagerModel : public QAbstractItemModel
132{
133 Q_OBJECT
134
135 public:
136 enum Columns
137 {
138 Description = 0,
139 Progress = 1,
140 Status = 2,
141 };
142
143 // *INDENT-OFF*
144
151 enum class CustomRole SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsTaskManagerModel, Roles ) : int
152 {
153 Status SIP_MONKEYPATCH_COMPAT_NAME( StatusRole ) = Qt::UserRole,
154 };
155 Q_ENUM( CustomRole )
156 // *INDENT-ON*
157
158
163 explicit QgsTaskManagerModel( QgsTaskManager *manager, QObject *parent = nullptr );
164
165 //reimplemented QAbstractItemModel methods
166 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
167 QModelIndex parent( const QModelIndex &index ) const override;
168 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
169 int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
170 QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
171 Qt::ItemFlags flags( const QModelIndex &index ) const override;
172 bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
173
178 QgsTask *indexToTask( const QModelIndex &index ) const;
179
180 private slots:
181
182 void taskAdded( long id );
183 void taskDeleted( long id );
184 void progressChanged( long id, double progress );
185 void statusChanged( long id, int status );
186
187 private:
188 enum ToolTipType
189 {
190 ToolTipDescription,
191 ToolTipStatus,
192 ToolTipProgress,
193 };
194
195 QgsTaskManager *mManager = nullptr;
196
197 QList<long> mRowToTaskIdList;
198
199
200 int idToRow( long id ) const;
201 QModelIndex idToIndex( long id, int column ) const;
202 static QString createTooltip( QgsTask *task, ToolTipType type );
203
204 friend class QgsTaskManagerStatusBarWidget;
205};
206
212class GUI_EXPORT QgsTaskStatusWidget : public QWidget
213{
214 Q_OBJECT
215
216 public:
221 QgsTaskStatusWidget( QWidget *parent = nullptr, QgsTask::TaskStatus status = QgsTask::Queued, bool canCancel = true );
222
223
224 QSize sizeHint() const override;
225
226 //bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) override;
227
228 public slots:
229
233 void setStatus( int status );
234
235 signals:
236
240 void cancelClicked();
241
242 protected:
243 void paintEvent( QPaintEvent *e ) override;
244 void mousePressEvent( QMouseEvent *e ) override;
245 void mouseMoveEvent( QMouseEvent *e ) override;
246 void leaveEvent( QEvent *e ) override;
247
248 private:
249 bool mCanCancel;
250 QgsTask::TaskStatus mStatus;
251 bool mInside = false;
252};
253
256
257#endif
258
259#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