casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TBBrowser.qo.h
Go to the documentation of this file.
00001 //# TBBrowser.qo.h: Browser widget for managing opened tables.
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 TBBROWSER_H_
00028 #define TBBROWSER_H_
00029 
00030 #include <casaqt/QtBrowser/TBBrowser.ui.h>
00031 #include <casaqt/QtBrowser/TBAction.h>
00032 
00033 #include <QtGui>
00034 
00035 #include <casa/BasicSL/String.h>
00036 
00037 #include <vector>
00038 
00039 #include <casa/namespace.h>
00040 using namespace std;
00041 
00042 namespace casa {
00043 
00044 //# Forward Declarations
00045 class TBTableTabs;
00046 class QProgressPanel;
00047 class ProgressHelper;
00048 class TBExportThread;
00049 class TBTable;
00050 class TBFilterRuleSequence;
00051 class TBFilterRules;
00052 class DriverParams;
00053 class TBView;
00054 
00055 // <summary>
00056 // Browser widget for managing opened tables.
00057 // <summary>
00058 //
00059 // <synopsis>
00060 // TBBrowser is a container for multiple TBTableTabs.  Its main responsibility
00061 // is to keep these tabs up-to-date and handle their opening and closing.
00062 // TBBrowser is the main interface for the GUI of the table browser and thus
00063 // also provides public methods to operate on opened tables.
00064 // </synopsis>
00065 
00066 class TBBrowser : public QWidget, Ui::Browser {
00067     Q_OBJECT
00068     
00069 public:
00070     // Default Constructor.  Sets up GUI with no tabs or opened tables.
00071     TBBrowser();
00072 
00073     ~TBBrowser();
00074     
00075     
00076     /* Accessors/Mutators */
00077 
00078     // Returns true if the browser is available, false otherwise.
00079     bool isAvailable();
00080 
00081     // Returns the number of tables that are currently opened.
00082     int openedTables();
00083 
00084     // Returns the widget managing the tabs (QTabWidget).
00085     QTabWidget* getTabWidget();
00086 
00087     // Returns the number of performed actions.  See TBActionList::size().
00088     int getNumActions();
00089 
00090     // Returns the number of undone actions.  See TBActionList::undoneSize().
00091     int getNumUndoneActions();
00092 
00093     // Returns the name of the last performed action, or blank if there is
00094     // none.  See TBActionList::lastActionName().
00095     String lastActionName();
00096 
00097     // Returns the name of the last undone action, or blank if there is none.
00098     // See TBActionList::lastUndoneActionName().
00099     String lastUndoneActionName();
00100     
00101     
00102     /* Table Access Methods */
00103 
00104     // Returns the name of the currently selected table, or blank if there is
00105     // none.
00106     String currentlySelectedTableName();
00107     
00108     // Returns the currently selected table.
00109     TBTable* currentlySelectedTable();
00110     
00111     // Returns the currently selected table tab.
00112     TBTableTabs* currentlySelectedTableTabs();
00113 
00114     // Returns the names of all opened tables.
00115     vector<String> openedTableNames();
00116     
00117     // Returns the TBTableTabs for the table with the given name.
00118     TBTableTabs* table(String name);
00119     
00120     // Returns the index of the indicated table tabs, or -1 if the pointer is
00121     // invalid.
00122     int indexOf(TBTableTabs* tt);
00123     
00124     // Return the table at index i, or NULL if the index is invalid.
00125     TBTableTabs* tableAt(int i);
00126     
00127     
00128     /* Table Operation Methods */
00129     
00130     // Opens a table tab from the given file, with the given parameters.  Loads
00131     // rows from start to (start + num).  If the DriverParameters are NULL,
00132     // the default is used.
00133     int openTable(String filename, DriverParams* dp = NULL, int start = 0,
00134                   int num = TBConstants::DEFAULT_SELECT_NUM);
00135     
00136     // Opens a table tab from the given file, with the given parameters.  Loads
00137     // rows from start to (start + num).  If the DriverParameters are NULL,
00138     // the default is used.
00139     int openTable(String filename, bool taql, DriverParams* dp = NULL,
00140                   int start = 0, int num = TBConstants::DEFAULT_SELECT_NUM);
00141     
00142     // Closes the currently selected table and returns its name.
00143     String closeTable();
00144 
00145     // Closes the table at the given tab index and returns its name.
00146     String closeTable(int index);
00147     
00148     // Closes the table with the given name and returns whether the close
00149     // succeeded or not.
00150     bool closeTable(String name);
00151 
00152     // Returns the column (field) names for the table at the given index.
00153     QStringList getColumnsAt(unsigned int index);
00154 
00155     // Returns true if the indicated column on the indicated tab is hidden,
00156     // false otherwise.
00157     bool columnIsHidden(unsigned int index, int col);
00158 
00159     // Sets whether the indicated column on the currently selected tab is
00160     // hidden.
00161     void setColumnHidden(int col, bool hidden);
00162     
00163     // Sets whether the indicated column on the indicated tab is hidden.
00164     void setColumnHidden(unsigned int index, int col, bool hidden);
00165     
00166     // Exports the currently selected table to VOTable XML format to the given
00167     // filename.  See TBTable::exportVOTable().
00168     void exportVOTable(String file);
00169     
00170     // Returns true if the table at the given index has a find rule entered,
00171     // false otherwise.
00172     bool findRuleAvailable(int index);
00173     
00174     // Shows a find dialog, and connects the signal to run the find rules as
00175     // indicated.
00176     void find();
00177 
00178     // If the currently selected table has a find rule, finds the next row that
00179     // passes the rule.  The second parameter is used to control the
00180     // wrap-around search such that the search will go through each row exactly
00181     // once.
00182     void findNext(bool second = false);
00183 
00184     // If the currently selected table has a find rule, finds the previous row
00185     // that passes the rule.  The second parameter is used to control the
00186     // wrap-around search such that the search will go through each row exactly
00187     // once.
00188     void findPrev(bool second = false);
00189 
00190     // Returns true if the table at the given index has a filter, false
00191     // otherwise.
00192     bool filterAvailable(int index);
00193 
00194     // Shows a filter rules dialog in the side panel of the currently selected
00195     // table and connects its signal such that when the user clicks the
00196     // "Filter" button, the filter is run on the table.
00197     void filterOnFields();
00198 
00199     // Clears the filter on the currently selected table.
00200     void clearFilterOnFields();
00201     
00202     // Returns the filter for the table at the indicated index, or NULL if
00203     // there is none.
00204     TBFilterRuleSequence* filterAt(int index);
00205     
00206     // Displays a format dialog for the currently selected table for the field
00207     // at index i, and connects the signal to format the display accordingly.
00208     void formatDisplay(int i);
00209 
00210     // Shows a table information panel in the side panel of the currently
00211     // selected table.
00212     void viewTableInfo();
00213     
00214     // Sort the currently selected table by the indicated fields.
00215     void sort(vector<pair<String, bool> >& s);
00216 
00217     // Sort the table at index i with the fields in s.  Each entry in s should
00218     // be a field name paired with a bool indicating whether the sort order is
00219     // ascending.  See TBTableTabs::sort().
00220     void sort(int i, vector<pair<String, bool> >& s);
00221 
00222     
00223     /* Action Methods */
00224     
00225     // Does the specified action and returns the result.  See
00226     // TBActionList::doAction().
00227     Result doAction(TBAction* action);
00228 
00229     // Undoes the last performed action and returns the result.  See
00230     // TBActionList::undoAction().
00231     Result undoAction();
00232 
00233     // Redoes the last undone action and returns the result.  See
00234     // TBActionList::redoAction().
00235     Result redoAction();
00236 
00237 
00238     /* Progress Methods */
00239 
00240     // Adds a QProgressPanel to the front of the browser and dims the GUI
00241     // behind the progress panel, then returns the QProgressPanel.
00242     QProgressPanel* addProgressPanel(String label, bool hideable,
00243                                      bool cancelable);
00244 
00245     // Removes the given QProgressPanel from the browser and restores it to
00246     // its fully-enabled state.
00247     void removeProgressPanel(QProgressPanel* panel);
00248 
00249     // Shows the progress frame on the bottom of the browser and returns a
00250     // ProgressHelper encapsulating it.
00251     ProgressHelper* enableProgressFrame(String label);
00252 
00253     // Hides the progress frame on the bottom of the browser.
00254     void disableProgressFrame();
00255     
00256     
00257     /* Miscellaneous Browser Methods */
00258 
00259     // Returns true if a background task is currently running, false otherwise.
00260     bool bgTaskIsRunning();
00261 
00262     // Returns the current view of the browser.  See TBView.
00263     TBView* view();
00264 
00265     // Shows the given view in the browser.  See TBView.
00266     void showView(TBView* view);
00267 
00268 public slots:
00269     // Displays the given error in a dialog to the user.
00270     void displayError(String message);
00271     
00272     // Opens a TaQL table with the given command.  See openTable().
00273     void openTaQL(String command);
00274 
00275     // Opens the subtable located at the given filename, and load the rows such
00276     // that row r can be selected.
00277     void followReference(String subtable, int r);
00278 
00279     // Removes all actions associated with the given widget.
00280     void removeActionsAssociatedWithWidget(QWidget* widget);
00281 
00282     // Removes all actions associated with the given object.
00283     void removeActionsAssociatedWith(void* widget);
00284 
00285 signals:
00286     // This signal is emitted when a new table is opened and its tab added.
00287     // The String parameter holds the name of the newly opened table.
00288     void tableOpened(String name, String fullpath);
00289 
00290     // This signal is emitted when a table is closed and its tab removed.
00291     // The String parameter holds the name of the table that was closed.
00292     void tableClosed(String name);
00293 
00294     // This signal is emitted whenever an action is performed.  The
00295     // TBAction parameter points to the action that was performed.
00296     void actionPerformed(TBAction* action);
00297 
00298     // This signal is emitted whenever the latest action was undone.
00299     void actionUndone();
00300 
00301     // This signal is emitted whenever the latest undone action was redone.
00302     void actionRedone();
00303 
00304     // This signal is emitted whenever a task thread has completed.
00305     void threadIsFinished();
00306 
00307     // This signal is emitted whenever the user enters a find rule for the
00308     // currently selected table.
00309     void findRuleAvailable();
00310     
00311     // This signal is emitted whenever the user enters a filter rule for the
00312     // table with the given index.
00313     void filterRuleAvailable(int index);
00314     
00315     // This signal is emitted whenever the user clears the filter rule for the
00316     // table with the given index.
00317     void filterRuleCleared(int index);
00318 
00319     // This signal is emitted whenever the tab is changed.  The int parameter
00320     // indicates the new current tab index.
00321     void tabChanged(int tableIndex);
00322     
00323 private:
00324     // Indicates whether the browser is available.
00325     bool available;
00326 
00327     // Holds the opened tables.
00328     vector<TBTableTabs*> tables;
00329 
00330     // Error dialog.
00331     QErrorMessage* errorDialog;
00332 
00333     // Actions, both performed and undone.
00334     TBActionList actions;
00335 
00336     // The current progress panel, or NULL if there is none.
00337     QProgressPanel* progressPanel;
00338 
00339     // The current export thread, or NULL if there is none.
00340     TBExportThread* exportThread;
00341 
00342     // Find rules for all opened tables.
00343     vector<TBFilterRuleSequence*> currentFindRules;
00344 
00345     // Filters for all opened tables.
00346     vector<TBFilterRuleSequence*> currentFilters;
00347 
00348     // Indicates whether a background task is currently running or not.
00349     bool bgTaskRunning;
00350 
00351     // Indicates whether an export thread is both active and hidden or not.
00352     bool exportHidden;
00353 
00354     
00355     // Enable or disable the widgets based upon availability.
00356     void updateEnabled();
00357     
00358     // Adds a table tab from the given file, with the given parameters.  Loads
00359     // rows from start to (start + num).  If the DriverParameters are NULL,
00360     // the default is used.
00361     int addTable(String filename, bool taql, DriverParams* dp, int start,
00362                   int num);
00363     
00364 private slots:
00365     // Slot to close the currently opened table.
00366     void doCloseTable();
00367 
00368     // Slot for when a task thread has finished.
00369     void threadFinished();
00370 
00371     // Slot for hiding a task thread in the background.
00372     void hideThread();
00373 
00374     // Slot for when the user has entered a filter rule.  Applies the given
00375     // TBFilterRulesSequence to the currently selected table.
00376     void filterRulesEntered(TBFilterRuleSequence* rules);
00377 
00378     // Slot for when the user has entered a search rule.  Searches the
00379     // currently selected table for a row that passes and, if one is found
00380     // on the currently loaded pages, selects that row.
00381     void findRulesEntered(TBFilterRuleSequence* rules, TBFilterRules* rDialog);
00382 
00383     // Slot for when the QTabWidget detects a change in tab.  Emits the
00384     // tabChanged() signal.
00385     void tabChange(int index);
00386 };
00387 
00388 }
00389 
00390 #endif /* TBBROWSER_H_*/