SpikeStream Application Library  0.2
ProgressWidget.cpp
Go to the documentation of this file.
00001 #include "ProgressWidget.h"
00002 using namespace spikestream;
00003 
00004 //Qt includes
00005 #include <QDebug>
00006 #include <QMutexLocker>
00007 
00008 
00010 ProgressWidget::ProgressWidget(QWidget* parent) : QWidget(parent) {
00011         QVBoxLayout* mainVerticalBox = new QVBoxLayout(this);
00012         gridLayout = new QGridLayout();
00013         mainVerticalBox->addLayout(gridLayout);
00014         mainVerticalBox->addStretch(5);
00015 }
00016 
00017 
00019 ProgressWidget::~ProgressWidget(){
00020 }
00021 
00022 
00023 /*-------------------------------------------------------------*/
00024 /*-------                 PUBLIC METHODS                 ------*/
00025 /*-------------------------------------------------------------*/
00026 
00028 void ProgressWidget::reset(){
00029         for(int row=0; row<gridLayout->rowCount(); ++row){
00030                 QLayoutItem* label = gridLayout->itemAtPosition(row, 0);
00031                 if(label !=0){
00032                         label->widget()->deleteLater();
00033                 }
00034                 QLayoutItem* bar = gridLayout->itemAtPosition(row, 1);
00035                 if(bar !=0){
00036                         bar->widget()->deleteLater();
00037                 }
00038                 QLayoutItem* details = gridLayout->itemAtPosition(row, 2);
00039                 if(details !=0){
00040                         details->widget()->deleteLater();
00041                 }
00042         }
00043         progressBarMap.clear();
00044         progressDetailsMap.clear();
00045 }
00046 
00047 
00048 /*-------------------------------------------------------------*/
00049 /*-------                 PRIVATE SLOTS                  ------*/
00050 /*-------------------------------------------------------------*/
00051 
00053 void ProgressWidget::timeStepComplete(unsigned int timeStep){
00054         QMutexLocker locker(&mutex);
00055 
00056         if(!progressBarMap.contains(timeStep)){
00057                 qCritical()<<"Time step "<<timeStep<<" is claimed to be complete, but no time step found.";
00058                 return;
00059         }
00060 }
00061 
00062 
00066 void ProgressWidget::updateProgress(const QString& msg, unsigned int timeStep, unsigned int stepsCompleted, unsigned int totalSteps){
00067         QMutexLocker locker(&mutex);
00068 
00069         //Check to see if we have a progress bar for this time step
00070         if(progressBarMap.contains(timeStep)){
00071                 progressBarMap[timeStep]->setMaximum(totalSteps);
00072                 progressBarMap[timeStep]->setValue(stepsCompleted);
00073                 progressDetailsMap[timeStep]->setText(msg);
00074         }
00075         //Add new progress bar
00076         else{
00077                 addProgressBar(timeStep, stepsCompleted, totalSteps);
00078         }
00079 }
00080 
00081 
00082 /*-------------------------------------------------------------*/
00083 /*-------                PRIVATE METHODS                 ------*/
00084 /*-------------------------------------------------------------*/
00085 
00087 void ProgressWidget::addProgressBar(unsigned int timeStep, unsigned int stepsCompleted, unsigned int totalSteps){
00088         if(progressBarMap.contains(timeStep)){
00089                 qCritical()<<"Attempting to add a progress bar for time step "<<timeStep<<" that already exists.";
00090                 return;
00091         }
00092 
00093         //Progress bar
00094         QProgressBar* progBar = new QProgressBar();
00095         progBar->setMinimumSize(100, 15);
00096         progBar->setBaseSize(100, 15);
00097         progBar->setRange(0, totalSteps);
00098         progBar->setValue(stepsCompleted);
00099         gridLayout->addWidget(new QLabel("Time step " + QString::number(timeStep) + ": "), progressBarMap.size(), 0);
00100         gridLayout->addWidget(progBar, progressBarMap.size(), 1);
00101         progressBarMap[timeStep] = progBar;
00102 
00103         //Progress details
00104         QLabel* progDetails = new QLabel();
00105         progDetails->setMinimumSize(300, 15);
00106         progDetails->setBaseSize(300, 15);
00107         gridLayout->addWidget(progDetails, progressDetailsMap.size(), 2);
00108         progressDetailsMap[timeStep] = progDetails;
00109 }
00110 
 All Classes Files Functions Variables Typedefs Friends Defines