QGIS API Documentation  3.6.0-Noosa (5873452)
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 
27 class QgsTaskManager;
28 class QgsTask;
29 class QTreeView;
30 class QProgressBar;
31 class QgsTaskManagerModel;
32 
40 class GUI_EXPORT QgsTaskManagerWidget : public QWidget
41 {
42  Q_OBJECT
43 
44  public:
45 
51  QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *parent SIP_TRANSFERTHIS = nullptr );
52 
53  ~QgsTaskManagerWidget() override;
54 
55  private slots:
56 
57  void modelRowsInserted( const QModelIndex &index, int start, int end );
58  void clicked( const QModelIndex &index );
59 
60  private:
61 
62  QgsTaskManager *mManager = nullptr;
63  QTreeView *mTreeView = nullptr;
64  QgsTaskManagerModel *mModel = nullptr;
65 };
66 
67 #ifndef SIP_RUN
68 
70 
78 class GUI_EXPORT QgsTaskManagerFloatingWidget : public QgsFloatingWidget
79 {
80  Q_OBJECT
81 
82  public:
83 
89  QgsTaskManagerFloatingWidget( QgsTaskManager *manager, QWidget *parent = nullptr );
90 
91 };
92 
101 class GUI_EXPORT QgsTaskManagerStatusBarWidget : public QToolButton
102 {
103  Q_OBJECT
104 
105  public:
106 
112  QgsTaskManagerStatusBarWidget( QgsTaskManager *manager, QWidget *parent = nullptr );
113 
114  QSize sizeHint() const override;
115 
116  protected:
117 
118  void changeEvent( QEvent *event ) override;
119 
120  private slots:
121 
122  void toggleDisplay();
123  void overallProgressChanged( double progress );
124  void countActiveTasksChanged( int count );
125  void allFinished();
126  void showButton();
127 
128  private:
129 
130  QgsTaskManagerFloatingWidget *mFloatingWidget = nullptr;
131  QProgressBar *mProgressBar = nullptr;
132  QgsTaskManager *mManager = nullptr;
133 };
134 
142 class GUI_EXPORT QgsTaskManagerModel: public QAbstractItemModel
143 {
144  Q_OBJECT
145 
146  public:
147 
148  enum Columns
149  {
150  Description = 0,
151  Progress = 1,
152  Status = 2,
153  };
154 
160  explicit QgsTaskManagerModel( QgsTaskManager *manager, QObject *parent = nullptr );
161 
162  //reimplemented QAbstractItemModel methods
163  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
164  QModelIndex parent( const QModelIndex &index ) const override;
165  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
166  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
167  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
168  Qt::ItemFlags flags( const QModelIndex &index ) const override;
169  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
170 
175  QgsTask *indexToTask( const QModelIndex &index ) const;
176 
178  enum Roles
179  {
180  StatusRole = Qt::UserRole,
181  };
182 
183  private slots:
184 
185  void taskAdded( long id );
186  void taskDeleted( long id );
187  void progressChanged( long id, double progress );
188  void statusChanged( long id, int status );
189 
190  private:
191 
192  enum ToolTipType
193  {
194  ToolTipDescription,
195  ToolTipStatus,
196  ToolTipProgress,
197  };
198 
199  QgsTaskManager *mManager = nullptr;
200 
201  QList< long > mRowToTaskIdList;
202 
203 
204  int idToRow( long id ) const;
205  QModelIndex idToIndex( long id, int column ) const;
206  static QString createTooltip( QgsTask *task, ToolTipType type );
207 
208  friend class QgsTaskManagerStatusBarWidget;
209 };
210 
217 class GUI_EXPORT QgsTaskStatusWidget : public QWidget
218 {
219  Q_OBJECT
220 
221  public:
222 
227  QgsTaskStatusWidget( QWidget *parent = nullptr, QgsTask::TaskStatus status = QgsTask::Queued, bool canCancel = true );
228 
229 
230  QSize sizeHint() const override;
231 
232  //bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) override;
233 
234  public slots:
235 
239  void setStatus( int status );
240 
241  signals:
242 
246  void cancelClicked();
247 
248  protected:
249 
250  void paintEvent( QPaintEvent *e ) override;
251  void mousePressEvent( QMouseEvent *e ) override;
252  void mouseMoveEvent( QMouseEvent *e ) override;
253  void leaveEvent( QEvent *e ) override;
254 
255  private:
256 
257  bool mCanCancel;
258  QgsTask::TaskStatus mStatus;
259  bool mInside = false;
260 };
261 
264 
265 #endif
266 
267 #endif //QGSTASKMANAGERWIDGET_H
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
A QWidget subclass for creating widgets which float outside of the normal Qt layout system...
TaskStatus
Status of tasks.
Abstract base class for long running background tasks.
Task manager for managing a set of long-running QgsTask tasks.
Task is queued and has not begun.
A widget which displays tasks from a QgsTaskManager and allows for interaction with the manager...