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