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