Commit 8c9c2596 authored by Mike Kremer's avatar Mike Kremer
Browse files

Threads can now either show their own widget (if blocking) or appear in the process manager window.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8597 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8d662d7d
...@@ -54,27 +54,16 @@ ...@@ -54,27 +54,16 @@
#include "Core.hh" #include "Core.hh"
#include <OpenFlipper/widgets/processManagerWidget/BlockingWidget.hh>
//== IMPLEMENTATION ========================================================== //== IMPLEMENTATION ==========================================================
// A job has been started by a plugin // A job has been started by a plugin
void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max, bool _blocking) { void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max, bool _blocking) {
std::cerr << "StartJob: " << _jobId.toStdString() << " " << _description.toStdString() << " " << _min << " " << _max << " " << _blocking <<std::endl; std::cerr << "StartJob: " << _jobId.toStdString() << " " << _description.toStdString() << " " << _min << " " << _max << " " << _blocking <<std::endl;
// Create process manager window if it has not been created before // Create job information
if(!processManager_) {
processManager_ = new ProcessManagerWidget();
// Connect cancel buttons to local slot for further treatment
connect(processManager_, SIGNAL(cancelJobRequested(QString)),
this, SLOT(slotJobCancelRequested(QString)));
}
// Add new item
processManager_->addJob(_jobId, _description, _min, _max);
// Show window
processManager_->show();
JobInfo* info = new JobInfo(); JobInfo* info = new JobInfo();
info->id = _jobId; info->id = _jobId;
info->description = _description; info->description = _description;
...@@ -82,8 +71,42 @@ void Core::slotStartJob( QString _jobId, QString _description , int _min , int _ ...@@ -82,8 +71,42 @@ void Core::slotStartJob( QString _jobId, QString _description , int _min , int _
info->minSteps = _min; info->minSteps = _min;
info->maxSteps = _max; info->maxSteps = _max;
info->blocking = _blocking; info->blocking = _blocking;
// Add job to local job list
currentJobs.push_back(info); currentJobs.push_back(info);
// Don't show process status in process manager
// if blocking is enabled
if(_blocking) {
// Create blocking widget
BlockingWidget* widget = new BlockingWidget(_jobId, _description,
_min, _max);
// Connect cancel buttons to local slot for further treatment
connect(widget, SIGNAL(cancelRequested(QString)),
this, SLOT(slotJobCancelRequested(QString)));
info->blockingWidget = widget;
// Show blocking widget
widget->show();
} else {
// Create process manager window if it has not been created before
if(!processManager_) {
processManager_ = new ProcessManagerWidget();
// Connect cancel buttons to local slot for further treatment
connect(processManager_, SIGNAL(cancelJobRequested(QString)),
this, SLOT(slotJobCancelRequested(QString)));
}
// Add new item
processManager_->addJob(_jobId, _description, _min, _max);
// Show window
processManager_->show();
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -109,7 +132,17 @@ void Core::slotSetJobState(QString _jobId, int _value ) { ...@@ -109,7 +132,17 @@ void Core::slotSetJobState(QString _jobId, int _value ) {
if ( getJob(_jobId, id) ) { if ( getJob(_jobId, id) ) {
currentJobs[id]->currentStep = _value; currentJobs[id]->currentStep = _value;
processManager_->updateStatus(_jobId, _value);
// Update gui
if(!currentJobs[id]->blocking)
processManager_->updateStatus(_jobId, _value);
else {
BlockingWidget* w = 0;
w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
if(w != 0) {
w->updateStatus(_value);
}
}
} }
} }
...@@ -121,7 +154,17 @@ void Core::slotSetJobName(QString _jobId, QString _name ) { ...@@ -121,7 +154,17 @@ void Core::slotSetJobName(QString _jobId, QString _name ) {
if ( getJob(_jobId, id) ) { if ( getJob(_jobId, id) ) {
currentJobs[id]->id = _name; currentJobs[id]->id = _name;
processManager_->setJobName(_jobId, _name);
// Update gui
if(!currentJobs[id]->blocking)
processManager_->setJobName(_jobId, _name);
else {
BlockingWidget* w = 0;
w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
if(w != 0) {
w->setJobId(_name);
}
}
} }
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -132,7 +175,17 @@ void Core::slotSetJobDescription(QString _jobId, QString _text ) { ...@@ -132,7 +175,17 @@ void Core::slotSetJobDescription(QString _jobId, QString _text ) {
if ( getJob(_jobId, id) ) { if ( getJob(_jobId, id) ) {
currentJobs[id]->description = _text; currentJobs[id]->description = _text;
processManager_->setJobDescription(_jobId, _text);
// Update gui
if(!currentJobs[id]->blocking)
processManager_->setJobDescription(_jobId, _text);
else {
BlockingWidget* w = 0;
w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
if(w != 0) {
w->setJobDescription(_text);
}
}
} }
} }
...@@ -143,8 +196,20 @@ void Core::slotCancelJob(QString _jobId ) { ...@@ -143,8 +196,20 @@ void Core::slotCancelJob(QString _jobId ) {
int id; int id;
if ( getJob(_jobId, id) ) { if ( getJob(_jobId, id) ) {
processManager_->removeJob(_jobId);
currentJobs.removeAt(id); // Update gui
if(!currentJobs[id]->blocking)
processManager_->removeJob(_jobId);
else {
BlockingWidget* w = 0;
w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
if(w != 0) {
w->hide();
delete w;
}
}
currentJobs.removeAt(id);
} }
} }
...@@ -155,7 +220,19 @@ void Core::slotFinishJob(QString _jobId ) { ...@@ -155,7 +220,19 @@ void Core::slotFinishJob(QString _jobId ) {
int id; int id;
if ( getJob(_jobId, id) ) { if ( getJob(_jobId, id) ) {
processManager_->removeJob(_jobId);
// Update gui
if(!currentJobs[id]->blocking)
processManager_->removeJob(_jobId);
else {
BlockingWidget* w = 0;
w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
if(w != 0) {
w->hide();
delete w;
}
}
currentJobs.removeAt(id); currentJobs.removeAt(id);
} }
} }
...@@ -167,6 +244,7 @@ void Core::slotFinishJob(QString _jobId ) { ...@@ -167,6 +244,7 @@ void Core::slotFinishJob(QString _jobId ) {
void Core::slotJobCancelRequested(QString /*_jobId*/) { void Core::slotJobCancelRequested(QString /*_jobId*/) {
// Cancel job still to be implemented... // Cancel job still to be implemented...
std::cerr << "Cancel requested!" << std::endl;
} }
//============================================================================= //=============================================================================
...@@ -40,6 +40,7 @@ JobInfo::JobInfo() : ...@@ -40,6 +40,7 @@ JobInfo::JobInfo() :
currentStep(0), currentStep(0),
minSteps(0), minSteps(0),
maxSteps(100), maxSteps(100),
blocking(false) blocking(false),
blockingWidget(0)
{ {
} }
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <OpenFlipper/common/GlobalDefines.hh> #include <OpenFlipper/common/GlobalDefines.hh>
#include <QString> #include <QString>
#include <QWidget>
/** \brief Job Information class /** \brief Job Information class
* *
...@@ -54,6 +55,7 @@ class DLLEXPORT JobInfo { ...@@ -54,6 +55,7 @@ class DLLEXPORT JobInfo {
int minSteps; int minSteps;
int maxSteps; int maxSteps;
bool blocking; bool blocking;
QWidget* blockingWidget;
}; };
......
#ifndef BLOCKINGWIDGET_HH
#define BLOCKINGWIDGET_HH
#include "processManagerWidget.hh"
class BlockingWidget : public QWidget {
Q_OBJECT
signals:
void cancelRequested(QString _jobId);
private slots:
void cancelPressed() {
JobCancelButton* button = 0;
button = dynamic_cast<JobCancelButton*>(QObject::sender());
if(button != 0) {
emit cancelRequested(button->jobId());
}
};
public:
BlockingWidget(QString _jobId, QString _description,
int _minSteps, int _maxSteps, QWidget* _parent = 0) : QWidget(_parent),
layout_(0),
description_(0),
progress_(0),
cancelButton_(0) {
setWindowTitle(_jobId);
// Set window size
QSize size(300, 150);
resize(size);
layout_ = new QVBoxLayout();
description_ = new QLabel(_description);
layout_->addWidget(description_);
progress_ = new QProgressBar();
progress_->setMinimum(_minSteps);
progress_->setMaximum(_maxSteps);
progress_->setValue(0);
progress_->setTextVisible(true);
layout_->addWidget(progress_);
cancelButton_ = new JobCancelButton("Cancel", _jobId, this);
layout_->addWidget(cancelButton_);
setLayout(layout_);
// Connect cancel button
connect(cancelButton_, SIGNAL(pressed()), this, SLOT(cancelPressed()));
};
void updateStatus(int _value) { progress_->setValue(_value); };
void setJobId(QString _jobId) { setWindowTitle(_jobId); };
void setJobDescription(QString _description) { description_->setText(_description); };
private:
QVBoxLayout* layout_;
QLabel* description_;
QProgressBar* progress_;
JobCancelButton* cancelButton_;
};
#endif // BLOCKINGWIDGET_HH
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
// Set job's id // Set job's id
void setJobId(const QString& _jobId) { jobId_ = _jobId; }; void setJobId(const QString& _jobId) { jobId_ = _jobId; };
// Set job's id // Get job's id
QString jobId() { return jobId_; } QString jobId() { return jobId_; }
private: private:
...@@ -89,11 +89,6 @@ class ProcessManagerWidget : public QWidget, public Ui::ProcessManagerWidget ...@@ -89,11 +89,6 @@ class ProcessManagerWidget : public QWidget, public Ui::ProcessManagerWidget
ProcessManagerWidget(QWidget* parent = 0) : QWidget(parent) { ProcessManagerWidget(QWidget* parent = 0) : QWidget(parent) {
setupUi(this); setupUi(this);
/*itemModel_ = new ProcessItemModel();
// set model
this->processList->setModel(itemModel_);*/
}; };
virtual ~ProcessManagerWidget() {}; virtual ~ProcessManagerWidget() {};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment