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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1