Skip to content
Permalink
Browse files
Task manager GUI cleanups
  • Loading branch information
nyalldawson committed Dec 5, 2016
1 parent 0dcff44 commit a24690d6db1cb33c0a08702bab52f53644b20373
Showing with 55 additions and 117 deletions.
  1. +1 −104 python/gui/qgstaskmanagerwidget.sip
  2. +42 −4 src/gui/qgstaskmanagerwidget.cpp
  3. +12 −9 src/gui/qgstaskmanagerwidget.h
@@ -2,7 +2,7 @@
* \class QgsTaskManagerWidget
* A widget which displays tasks from a QgsTaskManager and allows for interaction with the manager
* @see QgsTaskManager
* @note introduced in QGIS 2.16
* @note introduced in QGIS 3.0
*/
class QgsTaskManagerWidget : QWidget
{
@@ -19,106 +19,3 @@ class QgsTaskManagerWidget : QWidget

};

/** \ingroup gui
* \class QgsTaskManagerFloatingWidget
* A widget which displays tasks from a QgsTaskManager and allows for interaction with the manager
* @see QgsTaskManager
* @note introduced in QGIS 2.16
*/
class QgsTaskManagerFloatingWidget : QgsFloatingWidget
{
%TypeHeaderCode
#include <qgstaskmanagerwidget.h>
%End

public:

/** Constructor for QgsTaskManagerWidget
* @param manager task manager associated with widget
* @param parent parent widget
*/
QgsTaskManagerFloatingWidget( QgsTaskManager* manager, QWidget* parent = nullptr );

};

/** \ingroup gui
* \class QgsTaskManagerFloatingWidget
* A widget which displays tasks from a QgsTaskManager and allows for interaction with the manager
* @see QgsTaskManager
* @note introduced in QGIS 2.16
*/
class QgsTaskManagerStatusBarWidget : QToolButton
{
%TypeHeaderCode
#include <qgstaskmanagerwidget.h>
%End

public:

/** Constructor for QgsTaskManagerStatusBarWidget
* @param manager task manager associated with widget
* @param parent parent widget
*/
QgsTaskManagerStatusBarWidget( QgsTaskManager* manager, QWidget* parent = nullptr );

};


/** \ingroup gui
* \class QgsTaskManagerModel
* A model representing a QgsTaskManager
* @see QgsTaskManager
* @note introduced in QGIS 2.16
*/
class QgsTaskManagerModel: QAbstractItemModel
{
%TypeHeaderCode
#include <qgstaskmanagerwidget.h>
%End
public:

/** Constructor for QgsTaskManagerModel
* @param manager task manager for model
* @param parent parent object
*/
explicit QgsTaskManagerModel( QgsTaskManager* manager, QObject* parent /TransferThis/ = nullptr );

//reimplemented QAbstractItemModel methods
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
QModelIndex parent( const QModelIndex &index ) const;
int rowCount( const QModelIndex &parent = QModelIndex() ) const;
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
Qt::ItemFlags flags( const QModelIndex & index ) const;
bool setData( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );

/**
* Returns the task associated with a specified model index, or nullptr if no
* task was found.
*/
QgsTask* indexToTask( const QModelIndex& index ) const;

};


/** \ingroup gui
* \class QgsProgressBarDelegate
* A delegate for showing task status within a view. Clicks on the delegate will cause the task to be cancelled (via the model).
* @note introduced in QGIS 2.16
*/
class QgsTaskStatusDelegate : QStyledItemDelegate
{
%TypeHeaderCode
#include <qgstaskmanagerwidget.h>
%End
public:

/** Constructor for QgsTaskStatusDelegate
* @param parent parent object
*/
QgsTaskStatusDelegate( QObject* parent /TransferThis/ = nullptr );

void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const;
bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index );
};
@@ -25,6 +25,7 @@
#include <QToolBar>
#include <QProgressBar>
#include <QAction>
#include <QHeaderView>

//
// QgsTaskManagerWidget
@@ -45,6 +46,11 @@ QgsTaskManagerWidget::QgsTaskManagerWidget( QgsTaskManager *manager, QWidget *pa
mTreeView->setHeaderHidden( true );
mTreeView->setRootIsDecorated( false );
mTreeView->setSelectionBehavior( QAbstractItemView::SelectRows );
mTreeView->setColumnWidth( 2, 28 );
mTreeView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
mTreeView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
mTreeView->header()->setStretchLastSection( false );
mTreeView->header()->setResizeMode( 0, QHeaderView::Stretch );

vLayout->addWidget( mTreeView );

@@ -83,7 +89,7 @@ void QgsTaskManagerWidget::modelRowsInserted( const QModelIndex&, int start, int
}
}


///@cond PRIVATE
//
// QgsTaskManagerModel
//
@@ -170,14 +176,43 @@ QVariant QgsTaskManagerModel::data( const QModelIndex &index, int role ) const
case Progress:
return task->progress();
case Status:
return static_cast<int>( task->status() );
// delegate shows status
return QVariant();
default:
return QVariant();
}

case StatusRole:
return static_cast<int>( task->status() );

case Qt::ToolTipRole:
switch ( index.column() )
{
case Description:
return task->description();
case Progress:
case Status:
{
switch ( task->status() )
{
case QgsTask::Queued:
return tr( "Queued" );
case QgsTask::OnHold:
return tr( "On hold" );
case QgsTask::Running:
return tr( "Running" );
case QgsTask::Complete:
return tr( "Complete" );
case QgsTask::Terminated:
return tr( "Terminated" );
}
return QVariant();
}
default:
return QVariant();
}


default:
return QVariant();
}
@@ -331,7 +366,7 @@ void QgsTaskStatusDelegate::paint( QPainter *painter, const QStyleOptionViewItem
QStyledItemDelegate::paint( painter, option, index );

QIcon icon;
switch ( static_cast< QgsTask::TaskStatus >( index.data().toInt() ) )
switch ( static_cast< QgsTask::TaskStatus >( index.data( QgsTaskManagerModel::StatusRole ).toInt() ) )
{
case QgsTask::Queued:
case QgsTask::OnHold:
@@ -378,17 +413,19 @@ bool QgsTaskStatusDelegate::editorEvent( QEvent *event, QAbstractItemModel *mode
return false;
}


QgsTaskManagerFloatingWidget::QgsTaskManagerFloatingWidget( QgsTaskManager *manager, QWidget *parent )
: QgsFloatingWidget( parent )
{
setLayout( new QVBoxLayout() );
QgsTaskManagerWidget* w = new QgsTaskManagerWidget( manager );
setMinimumSize( w->sizeHint() );
setMinimumSize( 350, 270 );
layout()->addWidget( w );
setStyleSheet( ".QgsTaskManagerFloatingWidget { border-top-left-radius: 8px;"
"border-top-right-radius: 8px; background-color: rgb(0, 0, 0, 70%); }" );
}


QgsTaskManagerStatusBarWidget::QgsTaskManagerStatusBarWidget( QgsTaskManager *manager, QWidget *parent )
: QToolButton( parent )
, mProgressBar( nullptr )
@@ -473,3 +510,4 @@ void QgsTaskManagerStatusBarWidget::showButton()
show();
}
}
///@endcond
@@ -58,12 +58,14 @@ class GUI_EXPORT QgsTaskManagerWidget : public QWidget
QgsTaskManagerModel* mModel;
};

///@cond PRIVATE

/**
* \ingroup gui
* \class QgsTaskManagerFloatingWidget
* A widget which displays tasks from a QgsTaskManager and allows for interaction with the manager.
* @see QgsTaskManager
* \note added in QGIS 2.16
* \note added in QGIS 3.0
*/
class GUI_EXPORT QgsTaskManagerFloatingWidget : public QgsFloatingWidget
{
@@ -116,14 +118,12 @@ class GUI_EXPORT QgsTaskManagerStatusBarWidget : public QToolButton
QgsTaskManager* mManager;
};



/**
* \ingroup gui
* \class QgsTaskManagerModel
* A model representing a QgsTaskManager.
* @see QgsTaskManager
* \note added in QGIS 2.16
* \note added in QGIS 3.0
*/
class GUI_EXPORT QgsTaskManagerModel: public QAbstractItemModel
{
@@ -152,6 +152,12 @@ class GUI_EXPORT QgsTaskManagerModel: public QAbstractItemModel
*/
QgsTask* indexToTask( const QModelIndex& index ) const;

//! Model roles
enum Roles
{
StatusRole = Qt::UserRole, //!< Status role
};

private slots:

void taskAdded( long id );
@@ -168,11 +174,6 @@ class GUI_EXPORT QgsTaskManagerModel: public QAbstractItemModel
Status = 2,
};

enum Roles
{
StatusRole = Qt::UserRole,
};

QgsTaskManager* mManager;

QList< long > mRowToTaskIdList;
@@ -204,4 +205,6 @@ class GUI_EXPORT QgsTaskStatusDelegate : public QStyledItemDelegate
bool editorEvent( QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ) override;
};

///@endcond

#endif //QGSTASKMANAGERWIDGET_H

0 comments on commit a24690d

Please sign in to comment.