casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TBView.h
Go to the documentation of this file.
00001 //# TBView.h: Current "view" or state of the browser that can be serialized.
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 TBVIEW_H_
00028 #define TBVIEW_H_
00029 
00030 #include <vector>
00031 
00032 #include <xercesc/dom/DOM.hpp>
00033 
00034 #include <casa/BasicSL/String.h>
00035 
00036 #include <casa/namespace.h>
00037 using namespace std;
00038 using namespace xercesc;
00039 
00040 namespace casa {
00041 
00042 //# Forward Declarations
00043 class TBFilterRuleSequence;
00044 class TBFormat;
00045 class QFontColor;
00046 
00047 // <summary>
00048 // Current "view" or state of a single table.
00049 // </summary>
00050 //
00051 // <synopsis>
00052 // The TBTableView defines the state of an opened table and includes: the
00053 // location, whether the table is the currently selected table, which
00054 // columns are hidden, the visual index of each column, the loaded rows, the
00055 // row filter (if any), the field formats (if any), and the sort order (if any).
00056 // </synopsis>
00057 
00058 class TBTableView {
00059 public:
00060     // Default Constructor.
00061     TBTableView();
00062 
00063     ~TBTableView();
00064 
00065     
00066     // Location of the table.
00067     String location;
00068     
00069     // Whether the table is currently selected.
00070     bool selected;
00071     
00072     // Whether each column is hidden (true) or not (false).
00073     vector<bool> hidden;
00074     
00075     // The visual index of each column in case they were moved.
00076     vector<int> visInd;
00077     
00078     // The starting number of the loaded rows.
00079     int loadedFrom;
00080     
00081     // The number of loaded rows.
00082     int loadedNum;
00083     
00084     // Row filter, or NULL if there is none.
00085     TBFilterRuleSequence* filter;
00086     
00087     // The format for each field, or NULL if that field has none.
00088     vector<TBFormat*> formats;
00089     
00090     // The current sort order, or an empty list if there is none.
00091     vector<pair<String, bool> > sort;
00092     
00093     // Whether this table is from a TaQL command or not.
00094     bool taql;
00095 };
00096 
00097 // <summary>
00098 // Current "view" or state of the browser that can be serialized.
00099 // </summary>
00100 //
00101 // <synopsis>
00102 // The TBView defines the state of the browser and includes: the last opened
00103 // directory, and the TBTableViews of all currently opened tables.  TBView
00104 // has methods to save to and load from a file on disk.
00105 // </synopsis>
00106 
00107 class TBView {
00108 public:
00109     // Default Constructor.
00110     TBView();
00111 
00112     ~TBView();
00113 
00114     
00115     // Adds the given table view to this view.
00116     void addTableView(TBTableView* view);
00117 
00118     // Returns the list of table views in this view.
00119     vector<TBTableView*>* getTableViews();
00120 
00121     // Sets the last opened directory for this view.
00122     void setLastOpenedDirectory(String str);
00123 
00124     // Returns the last opened directory for this view.
00125     String getLastOpenedDirectory();
00126     
00127     // Gets/Sets the file chooser history limit.
00128     // <group>
00129     int chooserHistoryLimit() const;
00130     void setChooserHistoryLimit(int histLimit);
00131     // </group>
00132 
00133     
00134     // Saves this view in XML format to the given file.
00135     bool saveToFile(String file);
00136 
00137     // Equivalent to saveToFile(defaultFile()).
00138     bool saveToDefaultFile();
00139 
00140     
00141     // Loads the view saved in the given file and returns it.  If the file
00142     // is invalid or there are other problems, NULL is returned.
00143     static TBView* loadFromFile(String file);
00144 
00145     // Equivalent to loadFromFile(defaultFile()).
00146     static TBView* loadFromDefaultFile();
00147     
00148     // Returns the default location to save and load a view:
00149     // TBConstants::dotCasapyDir() + TBConstants::VIEW_SAVE_LOC.
00150     static String defaultFile();
00151 
00152 private:
00153     // Last opened directory.
00154     String lastOpenedDir;
00155     
00156     // File chooser history limit.
00157     int histLimit;
00158     
00159     // Table views.
00160     vector<TBTableView*> views;
00161 
00162     
00163     // Creates an XML element based upon the given QFontColor.
00164     static void fontElem(DOMElement* elem, QFontColor* font);
00165 
00166     // Creates a QFontColor based upon the given XML element.
00167     static QFontColor* fontElem(DOMElement* elem);
00168 };
00169 
00204 }
00205 
00206 #endif /* TBVIEW_H_ */