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