00001 //# PlotMSThread.qo.h: Threading classes for PlotMS. 00002 //# Copyright (C) 2009 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: $ 00027 #ifndef PLOTMSTHREAD_QO_H_ 00028 #define PLOTMSTHREAD_QO_H_ 00029 00030 #include <plotms/Threads/ThreadController.h> 00031 #include <QObject> 00032 00033 namespace casa { 00034 00035 class QtProgressWidget; 00036 00037 // Abstract class to control a threaded operation from the GUI. 00038 // Classes that want to run PlotMSThreads should: 00039 // 1) Provide a QtProgressWidget in the main (GUI) thread. 00040 // 2) Connect the finishedOperation() signal to a slot as needed. 00041 // 3) Call startOperation() to start the thread. 00042 // 4) Call the post-thread method after completion, if there is one. 00043 00044 class PlotMSThread : public QObject, public ThreadController { 00045 Q_OBJECT 00046 00047 public: 00048 // Constructor which takes the progress widget to use, and an optional 00049 // post-thread method that should be called when the thread is finished. 00050 PlotMSThread( QtProgressWidget* progress, 00051 PMSPTMethod postThreadMethod = NULL, 00052 PMSPTObject postThreadObject = NULL); 00053 00054 // Destructor. 00055 virtual ~PlotMSThread(); 00056 00057 00058 // ABSTRACT METHODS // 00059 00060 // Abstract method which does the operation. IMPORTANT: subclasses MUST 00061 // emit the finished() signal when finished. 00062 virtual void startOperation() = 0; 00063 00064 00065 // IMPLEMENTED METHODS // 00066 virtual void finished(); 00067 00068 //Overridden from BackgroundThread in order to update the progress 00069 //widget on the GUI thread. 00070 virtual void initializeProgress(const String& operationName); 00071 virtual void setProgress(unsigned int progress, const String& status); 00072 virtual void finishProgress(); 00073 00074 int getId(); 00075 virtual QString getName() const = 0; 00076 virtual bool isCacheThread() const; 00077 00078 signals: 00079 // This signal MUST be emitted after start() has been called, and when the 00080 // operation has finished. The thread parameter points to the thread that 00081 // has just completed. 00082 void finishedOperation(PlotMSThread* thread); 00083 void updateProgress(unsigned int value, const QString& statusStr ); 00084 void initProgress(const QString& operationName ); 00085 void finalizeProgress(); 00086 00087 protected: 00088 //Allows subclasses to override and do any clean-up they need to 00089 //once the background thread has completed. 00090 virtual void threadFinished(){} 00091 //Signal that clean-up and thread work is done. 00092 void signalFinishedOperation( PlotMSThread* thread ); 00093 00094 protected slots: 00095 // For when the user requests "cancel" for the thread. 00096 void cancelThread(); 00097 00098 private slots: 00099 // For when the user requests "background" for the thread. 00100 void backgroundThread(); 00101 00102 // For when the user requests "pause" for the thread. 00103 void pauseThread(); 00104 00105 // For when the user requests "resume" for the thread. 00106 void resumeThread(); 00107 00108 private: 00109 int id; 00110 00111 }; 00112 } 00113 00114 #endif /* PLOTMSTHREAD_QO_H_ */