00001 /* 00002 # Copyright (c) 2010 Alexandre LAURENT 00003 # 00004 # Permission is hereby granted, free of charge, to any person obtaining a copy 00005 # of this software and associated documentation files (the "Software"), to deal 00006 # in the Software without restriction, including without limitation the rights 00007 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 # copies of the Software, and to permit persons to whom the Software is 00009 # furnished to do so, subject to the following conditions: 00010 # 00011 # The above copyright notice and this permission notice shall be included in 00012 # all copies or substantial portions of the Software. 00013 # 00014 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 # THE SOFTWARE. 00021 */ 00022 00023 #include "ProgressDialog.hpp" 00024 00025 //#ifndef QT_NO_DEBUG 00026 #include <iostream> 00027 //#endif 00028 00029 extern short unsigned int nbCore; 00030 00031 #ifdef _CALLBACK_QT 00032 ProgressFeedBack pf; 00033 00034 void retourPourcentage(int value) 00035 { 00036 pf.updateValue(value); 00037 } 00038 #endif 00039 00040 ProgressDialog :: ProgressDialog(const QString& title, QWidget* parent /*= 0*/) 00041 :QProgressDialog(tr("Generation of the ") + title, tr("Cancel"), 0, 100, parent) 00042 { 00043 previousValue = 0; 00044 hasToBeChanged = 0; 00045 00046 // Limité aux pourcentages 00047 this->setRange(0, 100); 00048 this->setValue(0); 00049 00050 this->setLabelText(tr("Generation ") + title + QString(": ...")); 00051 00052 // Finalement, on ne peut pas annuler car ... cela n'arrêterait pas le thread 00053 // Solution: Passer un flag dans le thread pour pouvoir l'arrêter ( je parle dans la fonction de Yan ) 00054 this->setCancelButton(0); 00055 00056 #ifndef QT_NO_DEBUG 00057 std::cout << "ProgressDialog created" << std::endl; 00058 #endif 00059 } 00060 00061 ProgressDialog :: ~ProgressDialog(void) 00062 { 00063 00064 #ifndef QT_NO_DEBUG 00065 std::cout << "ProgressDialog deleted" << std::endl; 00066 #endif 00067 } 00068 00069 void ProgressDialog :: progressValue(int newValue) 00070 { 00071 // Cette methode est loin d'être parfaite 00072 // La vraie méthode c'est de passer une variable de progression au thread ( unique à chaque thread ) ( vu que ici on se bat entre tout nos threads pour savoir la progression ) 00073 if ( newValue < previousValue ) 00074 { 00075 this->setValue(newValue); 00076 } 00077 else 00078 { 00079 if ( newValue - this->value() < 3 ) 00080 { 00081 this->setValue(newValue); 00082 } 00083 } 00084 00085 previousValue = newValue; 00086 }