QProgressPanel.qo.h

Go to the documentation of this file.
00001 //# QProgressPanel.qo.h: Convenience class with a label and progress meter.
00002 //# Copyright (C) 2005
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 QPROGRESSPANEL_H_
00028 #define QPROGRESSPANEL_H_
00029 
00030 #include <casaqt/QtBrowser/QProgressPanel.ui.h>
00031 
00032 #include <QtGui>
00033 
00034 #include <casa/BasicSL/String.h>
00035 
00036 namespace casa {
00037 
00038 // <summary>
00039 // Convenience class with a label and progress meter.
00040 // </summary>
00041 //
00042 // <synopsis>
00043 // A QProgressPanel is a convenience class that provides a common
00044 // functionality: displaying a progress meter along with a label.
00045 // QProgressPanel also has two optional buttons: a "Hide" button and a "Close"
00046 // button - pressing either of these buttons sends a signal. <b>Important</b>:
00047 // it is the responsibility of the caller/parent to handle these signals.
00048 // </synopsis>
00049 
00050 class QProgressPanel : public QWidget, Ui::ProgressPanel {
00051     Q_OBJECT
00052 
00053 public:
00054     // Builds a QProgressPanel with the given label and a progress meter at 0%
00055         // completion.  If hideable is true, the optional "Hide" button is shown;
00056         // similarly, if cancelable is true, the optional "Cancel" button is shown.
00057     QProgressPanel(String label, bool hideable = true, bool cancelable = true);
00058 
00059     ~QProgressPanel();
00060 
00061     
00062     // Returns the progress meter (QProgressBar).
00063     QProgressBar* getProgressBar();
00064 
00065     // Returns the label (QLabel).
00066     QLabel* getLabel();
00067 
00068     // Sets the text of the label to the given String.
00069     void setLabel(String newLabel);
00070 
00071 public slots:
00072     // Sets the value of the progress meter to the given value.  Note that the
00073         // progress meter is on a scale of 0 - 100.  Also, due to some weirdness
00074         // with Qt's GUI thread system, calling setValue actually emits a signal
00075         // which is caught by the progress meter rather than setting the value
00076         // directly.
00077     void setValue(int value);
00078 
00079 signals:
00080     // The cancelRequested signal is emitted whenever the "Cancel" button is
00081         // clicked.  If the QProgressPanel was created without the cancel button,
00082         // this signal is never emitted.
00083     void cancelRequested();
00084 
00085     // The hideRequested signal is emitted whenever the "Hide" button is
00086     // clicked.  If the QProgressPanel was created without the hide button,
00087     // this signal is never emitted.
00088     void hideRequested();
00089 
00090     // This is the signal used by setValue() to get around Qt's GUI thread
00091     // issues.
00092     void updateValue(int value);
00093 
00094 private slots:
00095     // Slot to handle the "Cancel" button's clicked() signal.  Emits the
00096         // cancelRequested() signal.
00097     void cancel();
00098 
00099     // Slot to handle the "Hide" button's clicked() signal.  Emits the
00100     // hideRequested() signal.
00101     void hide();
00102 };
00103 
00104 // <summary>
00105 // Wrapper around a QProgressPanel or other QLabel/QProgressBar pairing.
00106 // </summary>
00107 //
00108 // <synopsis>
00109 // A ProgressHelper is a convenience class that provides methods dealing with
00110 // any QLabel/QProgressBar pair.  Progress is seen as a number of steps, and as
00111 // progress is made the "steps" counter increases.
00112 // </synopsis>
00113 
00114 class ProgressHelper {
00115 public:
00116     // Constructor that takes a pointer to a QProgressPanel.  If qpp is NULL,
00117         // the ProgressHelper is invalid.
00118     ProgressHelper(QProgressPanel* qpp);
00119 
00120     // Constructor that takes a reference to a QProgressPanel.
00121     ProgressHelper(QProgressPanel& qpp);
00122 
00123     // Constructor that takes any QLabel and QProgressBar pointers.  If either
00124     // are NULL, the ProgressHelper is invalid.
00125     ProgressHelper(QLabel* label, QProgressBar* pb);
00126 
00127     // Constructor that takes any QLabel and QProgressBar references.
00128     ProgressHelper(QLabel& label, QProgressBar& pb);
00129 
00130     // Copy Constructor.  If ph is NULL, the ProgressHelper is invalid.
00131     ProgressHelper(ProgressHelper* ph);
00132 
00133     // Copy Constructor.
00134     ProgressHelper(ProgressHelper& ph);
00135 
00136     ~ProgressHelper();
00137 
00138     
00139     // Returns the label (QLabel).
00140     QLabel* getLabel();
00141 
00142     // Returns the progress meter (QProgressBar).
00143     QProgressBar* getBar();
00144     
00145     // Set the text of the QLabel to the given String.
00146     void setLabel(String label);
00147     
00148     // Set the total number of steps in the task.
00149     void setSteps(int steps);
00150 
00151     
00152     // Indicates that one step of progress has been made.  The progress meter
00153     // is updated accordingly.
00154     void step();
00155 
00156     // Indicate that the task has been completed; the label and progress meter
00157     // are updated accordingly.
00158     void done();
00159 
00160     // Rest the progress meter and set the label with the given text.
00161     void reset(String newLabel);
00162 
00163 private:
00164     // Indicates whether this object is valid or not.  (See constructors.)
00165     bool valid;
00166     
00167     // Pointer to the label.
00168     QLabel* label;
00169 
00170     // Pointer to the progress meter.
00171     QProgressBar* bar;
00172 
00173     // Steps counter.
00174     int s;
00175 };
00176 
00177 }
00178 
00179 #endif /* QPROGRESSPANEL_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1