cmtkQtProgress.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //  Copyright 2004-2009 SRI International
00005 //
00006 //  This file is part of the Computational Morphometry Toolkit.
00007 //
00008 //  http://www.nitrc.org/projects/cmtk/
00009 //
00010 //  The Computational Morphometry Toolkit is free software: you can
00011 //  redistribute it and/or modify it under the terms of the GNU General Public
00012 //  License as published by the Free Software Foundation, either version 3 of
00013 //  the License, or (at your option) any later version.
00014 //
00015 //  The Computational Morphometry Toolkit is distributed in the hope that it
00016 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00017 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License along
00021 //  with the Computational Morphometry Toolkit.  If not, see
00022 //  <http://www.gnu.org/licenses/>.
00023 //
00024 //  $Revision: 2398 $
00025 //
00026 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00027 //
00028 //  $LastChangedBy: torstenrohlfing $
00029 //
00030 */
00031 
00032 #include <Qt/cmtkQtProgress.h>
00033 
00034 #include <qapplication.h>
00035 #include <qprogressbar.h>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 
00044 QtProgress::QtProgress
00045 ( QWidget *const parentWindow ) 
00046 {
00047   ParentWindow = parentWindow;
00048   ProgressBar = NULL;
00049   ProgressDialog = NULL;
00050   this->m_ProgressWidgetMode = PROGRESS_DIALOG;
00051 }
00052 
00053 void
00054 QtProgress
00055 ::BeginVirtual( const double start, const double end, const double increment, const std::string& taskName )
00056 {
00057   this->Superclass::BeginVirtual( start, end, increment, taskName );
00058 
00059   if ( this->IsTopLevel() )
00060     {
00061     if ( ProgressBar ) 
00062       {
00063       ProgressBar->setRange( 0, 100 );
00064       ProgressBar->show();
00065       }
00066     
00067     if ( ! ProgressDialog )
00068       ProgressDialog = new QProgressDialog( taskName.c_str(), "Cancel", 0, 100, ParentWindow, Qt::Dialog );
00069     
00070     ProgressDialog->setWindowModality(Qt::WindowModal);
00071     ProgressDialog->setModal( true );
00072     ProgressDialog->setMinimumDuration( 100 );
00073     ProgressDialog->show();
00074     ProgressDialog->setRange( 0, 100 );
00075     
00076     qApp->processEvents();
00077     }
00078 
00079   Progress::SetProgressInstance( this );
00080 }
00081 
00082 Progress::ResultEnum
00083 QtProgress::UpdateProgress()
00084 {
00085   const int percent = static_cast<int>( 100 * this->GetFractionComplete() );
00086   if ( ProgressBar )
00087     ProgressBar->setValue( percent );
00088   if ( ProgressDialog )
00089     ProgressDialog->setValue( percent );
00090 
00091   qApp->processEvents();
00092 
00093   Progress::ResultEnum result = Progress::OK;
00094   if ( ProgressDialog )
00095     if ( ProgressDialog->wasCanceled() )
00096       result = Progress::INTERRUPT;
00097 
00098   return result;
00099 }
00100 
00101 void
00102 QtProgress::DoneVirtual()
00103 {
00104   if ( this->IsTopLevel() )
00105     {
00106     if ( ProgressBar )
00107       ProgressBar->reset();
00108     
00109     if ( ProgressDialog )
00110       ProgressDialog->hide();
00111     }
00112 }
00113 
00114 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines