casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TBTableTabs.qo.h
Go to the documentation of this file.
00001 //# TBTableTabs.qo.h: Collection of table backend and display tabs.
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 TBTABLETABS_H_
00028 #define TBTABLETABS_H_
00029 
00030 #include <casaqt/QtBrowser/TBTableTabs.ui.h>
00031 
00032 #include <casaqt/QtBrowser/TBConstants.h>
00033 #include <casaqt/QtBrowser/TBTable.h>
00034 #include <casaqt/QtBrowser/TBDataTab.qo.h>
00035 #include <casaqt/QtBrowser/TBKeywordsTab.qo.h>
00036 #include <casaqt/QtBrowser/TBAction.h>
00037 
00038 #include <QtGui>
00039 
00040 #include <casa/BasicSL/String.h>
00041 
00042 #include <casa/namespace.h>
00043 
00044 namespace casa {
00045 
00046 //# Forward Declarations
00047 class TBBrowser;
00048 class DriverParams;
00049 
00050 // <summary>
00051 // Collection of table backend and display tabs.
00052 // </summary>
00053 //
00054 // <synopsis>
00055 // TBTableTabs keeps track of the underlying TBTable object as well as the
00056 // three tabs associated with its view (data, table keywords, and field
00057 // keywords).  It is the unifying interface over the GUI and non-GUI aspects
00058 // of a table.  Methods called on a TBTableTabs object tend to update the
00059 // backend via the TBTable and then update the GUIs with the new data.
00060 // </synopsis>
00061 
00062 class TBTableTabs : public QWidget, Ui::TableTabs {
00063     Q_OBJECT
00064     
00065 public:
00066     // Constructor that takes the browser parent, the location of the table,
00067     // the driver parameters for opening the table, and whether the table is
00068     // from a TaQL command or not.
00069     TBTableTabs(TBBrowser* b, String filename, DriverParams* dp, bool taql);
00070 
00071     ~TBTableTabs();
00072     
00073 
00074     // Returns true if the table is available, false otherwise.
00075     bool isAvailable();
00076     
00077     // Returns true if the table is currently in editing mode, false otherwise.
00078     bool isEditable();
00079 
00080     // Returns the "name" of this table (which is the last part of the
00081     // filename).
00082     String getName();
00083     
00084     // Returns the location of this table.
00085     String getFileName();
00086 
00087     // Returns the browser associated with this table.
00088     TBBrowser* getBrowser();
00089 
00090     // Returns the data tab associated with this table.
00091     TBDataTab* getDataTab();
00092     
00093     // Returns the table keywords tab associated with this table.
00094     TBTableKeywordsTab* getKeywordsTab();
00095     
00096     // Returns the field keywords tab assicated with this table.
00097     TBFieldKeywordsTab* getFieldKeywordsTab();
00098 
00099     // Returns the QTableWidget used to display table data.
00100     QTableWidget* getTableWidget();
00101     
00102     // Returns the QTableWidget used to display table keywords.
00103     QTableWidget* getTableKeywords();
00104     
00105     // Returns the QTreeWidget used to display the field keywords.
00106     QTreeWidget* getFieldKeywords();
00107 
00108     // Returns the underlying table backend.
00109     TBTable* getTable();
00110     
00111     // Returns the current sort on the table data tab, or an empty list
00112     // if there is none.
00113     vector<pair<String, bool> >* getSortFields();
00114     
00115 
00116     // Loads rows into the table backend and, if successful, updates the three
00117     // GUI displays to reflect the new table data.  Returns whether the
00118     // loading was successful or not.  If the loading was not successful an
00119     // error message is displayed.
00120     bool loadRows(int start = 0, int num = TBConstants::DEFAULT_SELECT_NUM);
00121 
00122     // If the table allows for insertion of rows, the given number of rows
00123     // is inserted at the end of the table and, if successful, the GUI display
00124     // is updated accordingly.  If the insertion was not successful an error
00125     // message is displayed.
00126     void insertRows(int n);
00127 
00128     // Deletes the given rows from the table, if the table allows for deletion
00129     // of rows.  Each element in the vector should be a row number.  If
00130     // successful, the GUI display is updated; otherwise an error message is
00131     // displayed.
00132     void deleteRows(vector<int> r);
00133 
00134     // Clears the current sort on the table data tab.
00135     void clearSort();
00136 
00137     // Sorts the table data tab with the given sort order.  See
00138     // TBDataTab::sortBy().
00139     void sort(vector<pair<String, bool> >& s);
00140 
00141     // Selects and highlights the given row in the data tab.  If the given
00142     // row is not loaded in the table, the user is prompted on whether they
00143     // want to load the appropriate page or not.
00144     void highlight(int row);
00145     
00146 public slots:
00147     // Updates the underlying table with the new data and then updates the
00148     // GUI displays if successful.  The new value is first checked for
00149     // validity.  If the update fails, an error message is displayed.
00150     void dataChanged(int row, int col, String newVal);
00151 
00152     // Sets whether this table is currently in editing mode or not.
00153     void setEditable(bool e);
00154 
00155     // Shows the given widget in the side panel on the table data tab.
00156     void showWidgetInTableSplitter(QWidget* widget, bool isArray = false);
00157 
00158     // Shows the given widget in the side panel on the table keywords tab.
00159     void showWidgetInKeywordSplitter(QWidget* widget);
00160 
00161     // Shows the given widget in the side panel on the field keywords tab.
00162     void showWidgetInFieldKeywordSplitter(QWidget* widget);
00163 
00164     // Shows the given widget in the side panel of the tab that is currently
00165     // selected.
00166     void showWidgetInCurrentSplitter(QWidget* widget);
00167 
00168     // Clears the side panel on the table data tab.
00169     void clearWidgetInTableSplitter();
00170 
00171     // Clears the side panel on the table keywords tab.
00172     void clearWidgetInKeywordSplitter();
00173 
00174     // Clears the side panel on the field keywords tab.
00175     void clearWidgetInFieldKeywordSplitter();
00176 
00177     // Clears the side panel on the currently selected tab.
00178     void clearWidgetInCurrentSplitter();
00179     
00180 private:
00181     // Indicates whether this table is currently available.
00182     bool available;
00183     
00184     // Indicates whether this table is currently in editing mode or not.
00185     bool editable;
00186     
00187     // This table's location.
00188     String filename;
00189     
00190     // This table's name.
00191     String name;
00192     
00193     // Table backend.
00194     TBTable table;
00195     
00196     // Table data tab.
00197     TBDataTab dataTab;
00198     
00199     // Table keywords tab.
00200     TBTableKeywordsTab keywordsTab;
00201     
00202     // Field keywords tab.
00203     TBFieldKeywordsTab fieldKeywordsTab;
00204     
00205     // Reference to parent.
00206     TBBrowser* browser;
00207 };
00208 
00209 }
00210 
00211 #endif /* TBTABLETABS_H_ */