casa
$Rev:20696$
|
00001 //# TBFormat.qo.h: Rules used to format displayed values for fields. 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 TBFORMAT_H_ 00028 #define TBFORMAT_H_ 00029 00030 #include <casaqt/QtBrowser/TBFormat.ui.h> 00031 #include <casaqt/QtBrowser/TBConstants.h> 00032 00033 #include <QtGui> 00034 00035 #include <casa/BasicSL/String.h> 00036 00037 #include <casa/namespace.h> 00038 using namespace std; 00039 00040 namespace casa { 00041 00042 //# Forward Declarations 00043 class TBData; 00044 00045 // <summary> 00046 // QFont color is a convenience class containing a QFont and a QColor. 00047 // <summary> 00048 00049 class QFontColor { 00050 public: 00051 // Constructor that takes a QFont and a QColor. 00052 QFontColor(QFont f, QColor c); 00053 00054 // Copy Constructor. 00055 QFontColor(const QFontColor& fc); 00056 00057 ~QFontColor(); 00058 00059 00060 // Font. 00061 QFont font; 00062 00063 // Color. 00064 QColor color; 00065 }; 00066 00067 // <summary> 00068 // Rules used to format displayed values for fields. 00069 // <summary> 00070 // 00071 // <synopsis> 00072 // A TBFormat contains all information necessary to format a displayed value. 00073 // A format consists of different options depending on the type of the value 00074 // being formatted. For example, an integer value could be in scientific 00075 // notation and could have a different font style for negative and positive 00076 // numbers. Generally speaking, a format has two parts: type-specific options 00077 // such as scientific notation or date format, and font options. Some types 00078 // may have multiple font options (i.e., one for negative values and one for 00079 // non-negative values). 00080 // </synopsis> 00081 00082 class TBFormat { 00083 public: 00084 // Default Constructor. 00085 TBFormat(); 00086 00087 ~TBFormat(); 00088 00089 00090 // Returns the QFontColor that is applied to all values (i.e., regardless 00091 // of negative or positive etc.). If this format has value-dependent 00092 // QFontColors, this will return NULL. 00093 QFontColor* getAllFont(); 00094 00095 // Sets the QFontColor to be used on all values. 00096 void setAllFont(QFontColor* fc); 00097 00098 // Returns the QFontColors used for different values; the order depends on 00099 // the type. For example, for a format applied to integers the 00100 // non-negative QFontColor is first. If there is a format for all 00101 // values, this will return an empty vector. 00102 vector<QFontColor*>* getFonts(); 00103 00104 // Sets the value-dependent QFontColors to the values in the given vector. 00105 void setFonts(vector<QFontColor*>* f); 00106 00107 // Adds a font to the end of the value-dependent QFontColor vector. 00108 void addFont(QFontColor* fc); 00109 00110 // Returns the date format if this format applies to a date, a blank string 00111 // otherwise. See TBConstants::dateFormatIsValid(). 00112 String getDateFormat(); 00113 00114 // Sets the date format for this format. See 00115 // TBConstants::dateFormatIsValid(). 00116 void setDateFormat(String d); 00117 00118 // Returns the boolean format. If this format is not for a boolean value, 00119 // this operation is undefined. 00120 BooleanFormat getBoolFormat(); 00121 00122 // Sets the boolean format. 00123 void setBoolFormat(BooleanFormat f); 00124 00125 // Returns true if this format's scientific format is on, false otherwise. 00126 bool getScientificFormat(); 00127 00128 // Sets the scientific format flag. 00129 void setScientificFormat(bool sf); 00130 00131 // Returns the number of decimal places for this format. If there is an 00132 // unlimited number of decimal places, or this format doesn't apply to 00133 // decimals, -1 is returned. 00134 int getDecimalPlaces(); 00135 00136 // Sets the number of decimal places for this format. 00137 void setDecimalPlaces(int dp); 00138 00139 // Returns the vector threshold for this format. A vector threshold, when 00140 // applied to one-dimensional arrays, will "hide" the values in the array 00141 // and display the shape instead IF the size is greater than the specified 00142 // threshold. If the threshold is unlimited, or this format does not apply 00143 // to array types, -1 is returned. 00144 int getVectorThreshold(); 00145 00146 // Sets the vector threshold of this format. See getVectorThreshold(). 00147 void setVectorThreshold(int v); 00148 00149 00150 // Applies this format to the display value in the given QTableWidgetItem. 00151 // The pre-format data and the type must also be provided. 00152 void applyTo(QTableWidgetItem* item, TBData* data); 00153 00154 private: 00155 // The QFontColor to apply to all values, or NULL if there are 00156 // value-dependent QFontColors. 00157 QFontColor* allFont; 00158 00159 // The vector of value-dependent QFontColors (can be empty). 00160 vector<QFontColor*> fonts; 00161 00162 // The number of decimal places to display, or -1 for unlimited. 00163 int decimalPlaces; 00164 00165 // Whether scientific format should be used. 00166 bool scientificFormat; 00167 00168 // The format for boolean values. 00169 BooleanFormat boolFormat; 00170 00171 // The format for displaying dates. See TBConstants::dateFormatIsValid(). 00172 String dateFormat; 00173 00174 // The vector threshold, or -1 for unlimited. 00175 int vectorThreshold; 00176 }; 00177 00178 // <summary> 00179 // Widget for entering format rules for a given field. 00180 // <summary> 00181 // 00182 // <synopsis> 00183 // A TBFormatter is a dialog that can be used to get format rules from the 00184 // user. The user can then command either to clear the format (and remove all 00185 // formatting) or to set the format for a given field. Important: this 00186 // behavior is implemented through the use of signals, which means that it is 00187 // the caller's/parent's responsibility for handling the signals and applying 00188 // the formats as needed. 00189 // </synopsis> 00190 00191 class TBFormatter : public QDialog, Ui::Format { 00192 Q_OBJECT 00193 00194 public: 00195 // Constructor that takes the field name, type, and index to be formatted, 00196 // along with the default (unformatted) QFontColor and an optional pointer 00197 // to the parent widget. If the parent pointer is NULL, this will be 00198 // displayed as a dialog; otherwise it can be displayed inside the parent. 00199 TBFormatter(String field, String type, int index, QFontColor font, 00200 QWidget* parent = NULL); 00201 00202 ~TBFormatter(); 00203 00204 00205 // Sets the displayed format to the given format. 00206 void setFormat(TBFormat* f); 00207 00208 signals: 00209 // This signal is emitted when the user clicks the "Clear Format" 00210 // button. The parent/caller should then remove the format for the field 00211 // with the specified index. 00212 void clearRequested(int index); 00213 00214 // This signal is emitted when the user enters a format and then clicks 00215 // the "Set Format" button. The parent/caller should then set the format 00216 // for the specified field to the specified format. 00217 void setRequested(int index, TBFormat* format); 00218 00219 private: 00220 // Field being formatted. 00221 String field; 00222 00223 // Type of the field being formatted. 00224 String type; 00225 00226 // Index of the field being formatted. 00227 int index; 00228 00229 // Vector of QFontColors for value-dependent formats. 00230 vector<QFontColor*> fonts; 00231 00232 // Flag indicating whether any GUI-generated events are "genuine." 00233 bool update; 00234 00235 00236 // Collects the QFontColor information currently set in the GUI and returns 00237 // it. 00238 QFontColor* getFont(); 00239 00240 // Sets the displayed font and color information to the given QFontColor. 00241 void setFontColor(QFontColor* color); 00242 00243 private slots: 00244 // Slot for when the user wants a color chooser. Opens a QColorDialog. 00245 void changeColor(); 00246 00247 // Slot for when the user clicks the "Clear Format" button. Emits the 00248 // clearFormat() signal and closes the window. 00249 void clearFormat(); 00250 00251 // Slot for when the user clicks the "Set Format" button. Collects the 00252 // format information from the widget, emits the setRequested() signal, 00253 // and closes the window. 00254 void setFormat(); 00255 00256 // Slot for when the user clicks the "apply to all" checkbox. If the all 00257 // box is checked, the list of value-dependent formats is disabled. 00258 void applyAllTurned(bool on); 00259 00260 // Slot for when the user clicks in the value-dependent format list. The 00261 // selected format is displayed in the widget. 00262 void applySelectionChanged(int newIndex); 00263 00264 // Slot for when the user changes a font or color parameter. The 00265 // QFontColor in the value-dependent vector is updated accordingly. 00266 void valuesChanged(); 00267 00268 private: 00269 // Unlimited decimals constant. 00270 static const int UNLIMITED_DECIMALS; 00271 }; 00272 00273 } 00274 00275 #endif /* TBFORMAT_H_ */