casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TBViewArray.qo.h
Go to the documentation of this file.
00001 //# TBViewArray.qo.h: Widget for viewing array data in TBArray format.
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 TBVIEWARRAY_H_
00028 #define TBVIEWARRAY_H_
00029 
00030 #include <casaqt/QtBrowser/TBViewArray.ui.h>
00031 #include <casaqt/QtBrowser/TBArrayPanel.ui.h>
00032 #include <casaqt/QtBrowser/TBBrowser.qo.h>
00033 
00034 #include <vector>
00035 
00036 #include <QtGui>
00037 
00038 #include <casa/BasicSL/String.h>
00039 
00040 #include <casa/namespace.h>
00041 using namespace std;
00042 
00043 namespace casa {
00044 
00045 //# Forward Declarations
00046 class TBTableTabs;
00047 class TBArray;
00048 class TBTable;
00049 class TBSlicer;
00050 class TBFormat;
00051 class QFontColor;
00052 class QCloseableWidget;
00053 class TBArrayData;
00054 class TBData;
00055 class TBDataRecord;
00056 
00057 // <summary>
00058 // Widget for viewing array data in TBArray format.
00059 // </summary>
00060 //
00061 // <synopsis>
00062 // A TBViewArray displays potentially multi-dimensional array data in a
00063 // QTableWidget.  If the array has dimensionality greater than two, a
00064 // TBSlicer is used to control the array slice.
00065 // </synopsis>
00066 
00067 class TBViewArray : public QWidget, Ui::ViewArray {
00068     Q_OBJECT
00069 
00070 public:    
00071     // Constructor which takes the table parent, the "indices" where this array
00072     // is located, the array to view, the location in the table (if applicable,
00073     // and whether this array should be editable or not.  The top of the
00074     // array view will have a label that says "[table name][first, second] =
00075     // [type] array of size [size]."  For keyword arrays, row and col are
00076     // irrelevant and editable should be false.
00077     TBViewArray(TBTableTabs* tt, String first, String second, TBArrayData* arr,
00078                 int row, int col, bool editable);
00079 
00080     ~TBViewArray();
00081     
00082     
00083     // Returns the array that is being displayed.
00084     TBArrayData* getArrayData();    
00085     
00086     // Sets whether the arrays being viewed should release their data when
00087     // closed or not.
00088     void setShouldRelease(bool b);
00089         
00090 
00091     // Returns the data at the given coordinates, or NULL if the coordinates
00092     // are invalid.    
00093     TBData* dataAt(vector<int> d);
00094 
00095     // Sets the data at the given coordinates to the given value WITHOUT
00096     // updating the table backend.  If format is true, then any current
00097     // format is applied to the new value.    
00098     void setDataAt(vector<int> d, TBData& newVal, bool format = true);
00099 
00100     // Applies the given format to the array cells.
00101     void applyFormat(TBFormat* f);
00102 
00103     // Clears the current format from the array cells and applies the given
00104     // QFontColor (which should be the default table cell font and color).
00105     void clearFormat(QFontColor* f);
00106     
00107 protected:
00108     // Catches the right-click event to allow for copying.
00109     void contextMenuEvent(QContextMenuEvent* event);
00110     
00111 private:
00112     // Table backend.
00113     // <group>
00114     TBTableTabs* tTabs;
00115     TBTable* t;
00116     // </group>
00117     
00118     // Array being displayed.    
00119     TBArrayData* array;
00120 
00121     // Flag to indicate whether GUI-generated events are "genuine."
00122     bool update;
00123     
00124     // Slicer for arrays with dimensionality greater than two.
00125     TBSlicer* slicer;
00126     
00127     // Current slice for arrays with dimensionality greater than two.
00128     vector<int> currentSlice;
00129     
00130     // Indicates whether this array is allowed to be edited.  Data arrays
00131     // should be true while keyword arrays should be false.
00132     bool editable;
00133     
00134     // Background for unselected cells.
00135     QBrush unselectedBackground;
00136     
00137     // Background for selected cells.
00138     QBrush selectedBackground;
00139     
00140     // List of cells that are on the same row or column as the currently
00141     // selected cell.
00142     vector<QTableWidgetItem*> selectedCells;
00143     
00144     // Current format.
00145     TBFormat* format;
00146     
00147     // Indicates whether the underlying array data should be released when
00148     // the view is closed or not.
00149     bool shouldRelease;
00150     
00151     // Row of data array.
00152     int row;
00153     
00154     // Column of data array.
00155     int col;
00156 
00157     
00158     // Sets up the GUI components with the given parameters for the label.
00159     void setup(String first, String second);
00160 
00161     // Returns the array-relevant coordinates corresponding to the given
00162     // indices. 
00163     vector<int> currentCell(int row, int col);
00164     
00165     // Relabels the table headers to be 0- rather than 1-based.
00166     void relabelHeaders();
00167 
00168 private slots:
00169     // Slot for when the user changes data in the array.  If the edit is
00170     // valid, a TBEditArrayDataAction is generated and sent to the browser
00171     // for execution.
00172     void dataChanged(int row, int col);
00173 
00174     // Slot for when the slicer changes (for arrays with dimensionality
00175     // greater than two).
00176     void sliceChanged(vector<int> newSlice);
00177 
00178     // Slot for when an array cell is clicked.  Updates cells in the same
00179     // row or column with a "selected" background.
00180     void cellClicked(int row, int col);
00181 
00182     // Slot for when an array cell is double-clicked.  If the array is
00183     // editable and the table is currently in editing mode, the user is then
00184     // allowed to edit the cell data.
00185     void cellDoubleClicked(int row, int col);
00186     
00187     // Slot for copying the currently selected text into the system clipboard.
00188     void copyData();
00189 };
00190 
00191 // <summary>
00192 // Panel that can hold multiple TBViewArray widgets.
00193 // </summary>
00194 //
00195 // <synopsis>
00196 // TBArrayPanel is the widget that is actually shown in the side panel and
00197 // consists of one or more TBViewArray widgets.  When the user double-clicks
00198 // on another array, it is added to the TBArrayPanel.  When the panel is
00199 // closed, it closes all the TBViewArray widgets as well.
00200 // </synopsis>
00201 
00202 class TBArrayPanel : public QWidget, Ui::ArrayPanel {
00203     Q_OBJECT
00204     
00205 public:
00206     // Constructor that takes the table backend.
00207     TBArrayPanel(TBTableTabs* tt);
00208 
00209     ~TBArrayPanel();
00210 
00211     
00212     // Adds the given TBViewArray widget to this panel and returns whether it
00213     // succeeded or not.  If the given array is already being displayed (see
00214     // TBArray::sameLocationAs(), false is returned.
00215     bool addArray(TBViewArray* array, int colIndex);
00216     
00217     // Calls setShouldRelease on all TBViewArrays in this panel.
00218     void setShouldRelease(bool b);
00219     
00220     // Applies the given format to any TBViewArray with the given index.
00221     void applyFormat(TBFormat* format, int colIndex);
00222 
00223 public slots:
00224     // Removes any actions in the browser that are associated with any
00225     // of the arrays in this panel.
00226     void removeActionsAssociatedWithArrays();
00227 
00228 signals:
00229     // This signal is emitted when the user presses "close" on all the
00230     // currently opened arrays in this panel.  The caller should then close
00231     // the panel itself.
00232     void allArraysClosed();
00233     
00234 private:
00235     // Table backend.
00236     TBTableTabs* ttabs;
00237     
00238     // List of opened arrays.
00239     vector<TBViewArray*> arrays;
00240     
00241     // List of wrapper widgets.
00242     vector<QCloseableWidget*> widgets;
00243     
00244     // Array indices.
00245     vector<int> indices;
00246     
00247     // Splitter to hold the opened arrays.
00248     QSplitter splitter;
00249     
00250     
00251     // Removes any actions in the browser that are associate with the given
00252     // array in this panel.
00253     void removeActionsAssociatedWithArray(TBViewArray* array);
00254     
00255 private slots:
00256     // Slot for when the user closes an individual array.
00257     void closeRequested(QWidget* widget);
00258 };
00259 
00260 
00261 // <summary>
00262 // Widget for viewing record data.
00263 // </summary>
00264 //
00265 // <synopsis>
00266 // A TBViewRecord displays data in a TBDataRecord format, which uses an
00267 // underlying Record object.  The record is displayed in a table, and the
00268 // values can also be another table (for arrays or sub-records).
00269 // </synopsis>
00270 
00271 class TBViewRecord : public QWidget, Ui::ViewArray {
00272     Q_OBJECT
00273 
00274 public:
00275     // Constructor which takes the table parent, the record to display, and the
00276     // "indices" to display in the label.
00277     TBViewRecord(TBTableTabs* tt, TBDataRecord* r, String first,
00278                  String second = "");
00279     
00280     ~TBViewRecord();
00281     
00282 private:
00283     // Table parent.
00284     TBTableTabs* tt;
00285     
00286     // Displayed record.
00287     Record& record;
00288     
00289     // Fills the given table with the given parameters.
00290     void fill(QTableWidget& table, Record& r, String first, String second);
00291 };
00292 
00293 }
00294 
00295 #endif /* TBVIEWARRAY_H_ */