casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
QtIndexChooser.qo.h
Go to the documentation of this file.
00001 //# QtIndexChooser.qo.h: Simple widget for choosing an index.
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 QTINDEXCHOOSER_QO_H_
00028 #define QTINDEXCHOOSER_QO_H_
00029 
00030 #include <casaqt/QtUtilities/QtIndexChooser.ui.h>
00031 
00032 #include <casa/BasicSL/String.h>
00033 
00034 #include <vector>
00035 
00036 #include <casa/namespace.h>
00037 using namespace std;
00038 
00039 namespace casa {
00040 
00041 // Widget that allows the user to pick an index, with a number of choices on
00042 // how the index can be chosen.  (See Type enum.)
00043 class QtIndexChooser : public QWidget, Ui::IndexChooser {
00044     Q_OBJECT
00045     
00046 public:
00047     // Static //
00048     
00049     // The type of the chooser; i.e., how the user picks the index.
00050     enum Type {
00051         NAME,    // Display a chooser that shows names associated with indices.
00052         ROW_COL, // Display a row and column spinner box.
00053         INDEX    // Display an index spinner box.
00054     };
00055     
00056     
00057     // Non-Static //
00058     
00059     // Constructor which takes the type and an optional parent widget.
00060     QtIndexChooser(Type type, QWidget* parent = NULL);
00061     
00062     // Destructor.
00063     ~QtIndexChooser();
00064     
00065     
00066     // Returns the currently set index on the widget.
00067     unsigned int index() const;
00068     
00069     // Sets the type to the given, resizing if indicated.
00070     void setType(Type type, bool resizeToHint = true);
00071     
00072     // Only valid if type is NAME.  Sets the name for the given index and makes
00073     // it available in the GUI.
00074     void setName(unsigned int index, const String& name);
00075     
00076     // Only valid if type is NAME.  Sets the available names to the given.
00077     // <group>
00078     void setNames(const vector<String>& names);
00079     void setNames(const vector<unsigned int>& indices,
00080             const vector<String>& names);
00081     void setNames(const map<unsigned int, String>& names);
00082     void setNames(const map<String, unsigned int>& names);
00083     // </group>
00084     
00085     // Only valid if type is ROW_COL.  Sets the number of rows and columns.
00086     void setRowsCols(unsigned int nRows, unsigned int nCols);
00087     
00088     // Only valid if type is INDEX.  Sets the maximum index (inclusive).
00089     void setMaxIndex(unsigned int maxIndex);
00090     
00091 signals:
00092     // Emitted when the index changes, and contains the new index value.
00093     void indexChanged(unsigned int newIndex);
00094     
00095 private:
00096     // Type.
00097     Type itsType_;
00098     
00099     // Name/Index map.
00100     QMap<QString, unsigned int> itsNames_;
00101     
00102 private:
00103     // Sets up the name chooser for the currently set name/index mappings.
00104     void setupNameChooser();
00105     
00106 private slots:    
00107     // Slot for when the index changes.
00108     void indexChanged_() { emit indexChanged(index()); }
00109 };
00110 
00111 }
00112 
00113 #endif /* QTINDEXCHOOSER_QO_H_ */