QGIS API Documentation  3.0.2-Girona (307d082)
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.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  private slots:
117 
118  void toggleDisplay();
119  void overallProgressChanged( double progress );
120  void countActiveTasksChanged( int count );
121  void allFinished();
122  void showButton();
123 
124  private:
125 
126  QgsTaskManagerFloatingWidget *mFloatingWidget = nullptr;
127  QProgressBar *mProgressBar = nullptr;
128  QgsTaskManager *mManager = nullptr;
129 };
130 
138 class 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 
156  explicit QgsTaskManagerModel( QgsTaskManager *manager, QObject *parent = nullptr );
157 
158  //reimplemented QAbstractItemModel methods
159  QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
160  QModelIndex parent( const QModelIndex &index ) const override;
161  int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
162  int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
163  QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
164  Qt::ItemFlags flags( const QModelIndex &index ) const override;
165  bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
166 
171  QgsTask *indexToTask( const QModelIndex &index ) const;
172 
174  enum Roles
175  {
176  StatusRole = Qt::UserRole,
177  };
178 
179  private slots:
180 
181  void taskAdded( long id );
182  void taskDeleted( long id );
183  void progressChanged( long id, double progress );
184  void statusChanged( long id, int status );
185 
186  private:
187 
188  QgsTaskManager *mManager = nullptr;
189 
190  QList< long > mRowToTaskIdList;
191 
192 
193  int idToRow( long id ) const;
194  QModelIndex idToIndex( long id, int column ) const;
195 };
196 
203 class GUI_EXPORT QgsTaskStatusWidget : public QWidget
204 {
205  Q_OBJECT
206 
207  public:
208 
213  QgsTaskStatusWidget( QWidget *parent = nullptr, QgsTask::TaskStatus status = QgsTask::Queued, bool canCancel = true );
214 
215 
216  QSize sizeHint() const override;
217 
218  //bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) override;
219 
220  public slots:
221 
225  void setStatus( int status );
226 
227  signals:
228 
232  void cancelClicked();
233 
234  protected:
235 
236  void paintEvent( QPaintEvent *e ) override;
237  void mousePressEvent( QMouseEvent *e ) override;
238  void mouseMoveEvent( QMouseEvent *e ) override;
239  void leaveEvent( QEvent *e ) override;
240 
241  private:
242 
243  bool mCanCancel;
244  QgsTask::TaskStatus mStatus;
245  bool mInside = false;
246 };
247 
250 
251 #endif
252 
253 #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...