casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBFormat.qo.h
Go to the documentation of this file.
1 //# TBFormat.qo.h: Rules used to format displayed values for fields.
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef TBFORMAT_H_
28 #define TBFORMAT_H_
29 
30 #include <casaqt/QtBrowser/TBFormat.ui.h>
32 
33 #include <QtGui>
34 
35 #include <casa/BasicSL/String.h>
36 
37 namespace casa {
38 
39 //# Forward Declarations
40 class TBData;
41 
42 // <summary>
43 // QFont color is a convenience class containing a QFont and a QColor.
44 // <summary>
45 
46 class QFontColor {
47 public:
48  // Constructor that takes a QFont and a QColor.
49  QFontColor(QFont f, QColor c);
50 
51  // Copy Constructor.
52  QFontColor(const QFontColor& fc);
53 
54  ~QFontColor();
55 
56 
57  // Font.
58  QFont font;
59 
60  // Color.
61  QColor color;
62 };
63 
64 // <summary>
65 // Rules used to format displayed values for fields.
66 // <summary>
67 //
68 // <synopsis>
69 // A TBFormat contains all information necessary to format a displayed value.
70 // A format consists of different options depending on the type of the value
71 // being formatted. For example, an integer value could be in scientific
72 // notation and could have a different font style for negative and positive
73 // numbers. Generally speaking, a format has two parts: type-specific options
74 // such as scientific notation or date format, and font options. Some types
75 // may have multiple font options (i.e., one for negative values and one for
76 // non-negative values).
77 // </synopsis>
78 
79 class TBFormat {
80 public:
81  // Default Constructor.
82  TBFormat();
83 
84  ~TBFormat();
85 
86 
87  // Returns the QFontColor that is applied to all values (i.e., regardless
88  // of negative or positive etc.). If this format has value-dependent
89  // QFontColors, this will return NULL.
91 
92  // Sets the QFontColor to be used on all values.
93  void setAllFont(QFontColor* fc);
94 
95  // Returns the QFontColors used for different values; the order depends on
96  // the type. For example, for a format applied to integers the
97  // non-negative QFontColor is first. If there is a format for all
98  // values, this will return an empty vector.
99  std::vector<QFontColor*>* getFonts();
100 
101  // Sets the value-dependent QFontColors to the values in the given vector.
102  void setFonts(std::vector<QFontColor*>* f);
103 
104  // Adds a font to the end of the value-dependent QFontColor vector.
105  void addFont(QFontColor* fc);
106 
107  // Returns the date format if this format applies to a date, a blank string
108  // otherwise. See TBConstants::dateFormatIsValid().
110 
111  // Sets the date format for this format. See
112  // TBConstants::dateFormatIsValid().
114 
115  // Returns the boolean format. If this format is not for a boolean value,
116  // this operation is undefined.
118 
119  // Sets the boolean format.
121 
122  // Returns true if this format's scientific format is on, false otherwise.
123  bool getScientificFormat();
124 
125  // Sets the scientific format flag.
126  void setScientificFormat(bool sf);
127 
128  // Returns the number of decimal places for this format. If there is an
129  // unlimited number of decimal places, or this format doesn't apply to
130  // decimals, -1 is returned.
131  int getDecimalPlaces();
132 
133  // Sets the number of decimal places for this format.
134  void setDecimalPlaces(int dp);
135 
136  // Returns the vector threshold for this format. A vector threshold, when
137  // applied to one-dimensional arrays, will "hide" the values in the array
138  // and display the shape instead IF the size is greater than the specified
139  // threshold. If the threshold is unlimited, or this format does not apply
140  // to array types, -1 is returned.
141  int getVectorThreshold();
142 
143  // Sets the vector threshold of this format. See getVectorThreshold().
144  void setVectorThreshold(int v);
145 
146 
147  // Applies this format to the display value in the given QTableWidgetItem.
148  // The pre-format data and the type must also be provided.
149  void applyTo(QTableWidgetItem* item, TBData* data);
150 
151 private:
152  // The QFontColor to apply to all values, or NULL if there are
153  // value-dependent QFontColors.
155 
156  // The vector of value-dependent QFontColors (can be empty).
157  std::vector<QFontColor*> fonts;
158 
159  // The number of decimal places to display, or -1 for unlimited.
161 
162  // Whether scientific format should be used.
164 
165  // The format for boolean values.
167 
168  // The format for displaying dates. See TBConstants::dateFormatIsValid().
170 
171  // The vector threshold, or -1 for unlimited.
173 };
174 
175 // <summary>
176 // Widget for entering format rules for a given field.
177 // <summary>
178 //
179 // <synopsis>
180 // A TBFormatter is a dialog that can be used to get format rules from the
181 // user. The user can then command either to clear the format (and remove all
182 // formatting) or to set the format for a given field. Important: this
183 // behavior is implemented through the use of signals, which means that it is
184 // the caller's/parent's responsibility for handling the signals and applying
185 // the formats as needed.
186 // </synopsis>
187 
188 class TBFormatter : public QDialog, Ui::Format {
189  Q_OBJECT
190 
191 public:
192  // Constructor that takes the field name, type, and index to be formatted,
193  // along with the default (unformatted) QFontColor and an optional pointer
194  // to the parent widget. If the parent pointer is NULL, this will be
195  // displayed as a dialog; otherwise it can be displayed inside the parent.
197  QWidget* parent = NULL);
198 
199  ~TBFormatter();
200 
201 
202  // Sets the displayed format to the given format.
203  void setFormat(TBFormat* f);
204 
205 signals:
206  // This signal is emitted when the user clicks the "Clear casacore::Format"
207  // button. The parent/caller should then remove the format for the field
208  // with the specified index.
209  void clearRequested(int index);
210 
211  // This signal is emitted when the user enters a format and then clicks
212  // the "Set casacore::Format" button. The parent/caller should then set the format
213  // for the specified field to the specified format.
214  void setRequested(int index, TBFormat* format);
215 
216 private:
217  // Field being formatted.
219 
220  // Type of the field being formatted.
222 
223  // Index of the field being formatted.
224  int index;
225 
226  // casacore::Vector of QFontColors for value-dependent formats.
227  std::vector<QFontColor*> fonts;
228 
229  // Flag indicating whether any GUI-generated events are "genuine."
230  bool update;
231 
232 
233  // Collects the QFontColor information currently set in the GUI and returns
234  // it.
235  QFontColor* getFont();
236 
237  // Sets the displayed font and color information to the given QFontColor.
239 
240 private slots:
241  // Slot for when the user wants a color chooser. Opens a QColorDialog.
242  void changeColor();
243 
244  // Slot for when the user clicks the "Clear casacore::Format" button. Emits the
245  // clearFormat() signal and closes the window.
246  void clearFormat();
247 
248  // Slot for when the user clicks the "Set casacore::Format" button. Collects the
249  // format information from the widget, emits the setRequested() signal,
250  // and closes the window.
251  void setFormat();
252 
253  // Slot for when the user clicks the "apply to all" checkbox. If the all
254  // box is checked, the list of value-dependent formats is disabled.
255  void applyAllTurned(bool on);
256 
257  // Slot for when the user clicks in the value-dependent format list. The
258  // selected format is displayed in the widget.
259  void applySelectionChanged(int newIndex);
260 
261  // Slot for when the user changes a font or color parameter. The
262  // QFontColor in the value-dependent vector is updated accordingly.
263  void valuesChanged();
264 
265 private:
266  // Unlimited decimals constant.
267  static const int UNLIMITED_DECIMALS;
268 };
269 
270 }
271 
272 #endif /* TBFORMAT_H_ */
void setBoolFormat(tb::BooleanFormat f)
Sets the boolean format.
Widget for entering format rules for a given field.
Definition: TBFormat.qo.h:188
void setVectorThreshold(int v)
Sets the vector threshold of this format.
void clearFormat()
Slot for when the user clicks the &quot;Clear casacore::Format&quot; button.
void applyAllTurned(bool on)
Slot for when the user clicks the &quot;apply to all&quot; checkbox.
int vectorThreshold
The vector threshold, or -1 for unlimited.
Definition: TBFormat.qo.h:172
casacore::String field
Field being formatted.
Definition: TBFormat.qo.h:218
casacore::Data types used for loaded data.
Definition: TBData.h:51
void addFont(QFontColor *fc)
Adds a font to the end of the value-dependent QFontColor vector.
std::vector< QFontColor * > * getFonts()
Returns the QFontColors used for different values; the order depends on the type. ...
int getDecimalPlaces()
Returns the number of decimal places for this format.
void applyTo(QTableWidgetItem *item, TBData *data)
Applies this format to the display value in the given QTableWidgetItem.
void clearRequested(int index)
This signal is emitted when the user clicks the &quot;Clear casacore::Format&quot; button.
void setRequested(int index, TBFormat *format)
This signal is emitted when the user enters a format and then clicks the &quot;Set casacore::Format&quot; butto...
void applySelectionChanged(int newIndex)
Slot for when the user clicks in the value-dependent format list.
void setFonts(std::vector< QFontColor * > *f)
Sets the value-dependent QFontColors to the values in the given vector.
void setFormat()
Slot for when the user clicks the &quot;Set casacore::Format&quot; button.
QFont font
Font.
Definition: TBFormat.qo.h:58
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
QFontColor * getFont()
Collects the QFontColor information currently set in the GUI and returns it.
QColor color
Color.
Definition: TBFormat.qo.h:61
int index
Index of the field being formatted.
Definition: TBFormat.qo.h:224
std::vector< QFontColor * > fonts
casacore::Vector of QFontColors for value-dependent formats.
Definition: TBFormat.qo.h:227
bool update
Flag indicating whether any GUI-generated events are &quot;genuine.&quot;.
Definition: TBFormat.qo.h:230
QFontColor * getAllFont()
Returns the QFontColor that is applied to all values (i.e., regardless of negative or positive etc...
void setDateFormat(casacore::String d)
Sets the date format for this format.
Rules used to format displayed values for fields.
Definition: TBFormat.qo.h:79
int decimalPlaces
The number of decimal places to display, or -1 for unlimited.
Definition: TBFormat.qo.h:160
void setScientificFormat(bool sf)
Sets the scientific format flag.
casacore::String getDateFormat()
Returns the date format if this format applies to a date, a blank string otherwise.
QFontColor(QFont f, QColor c)
Constructor that takes a QFont and a QColor.
QFontColor * allFont
The QFontColor to apply to all values, or NULL if there are value-dependent QFontColors.
Definition: TBFormat.qo.h:154
TBFormatter(casacore::String field, casacore::String type, int index, QFontColor font, QWidget *parent=NULL)
Constructor that takes the field name, type, and index to be formatted, along with the default (unfor...
casacore::String dateFormat
The format for displaying dates.
Definition: TBFormat.qo.h:169
void setDecimalPlaces(int dp)
Sets the number of decimal places for this format.
casacore::String type
Type of the field being formatted.
Definition: TBFormat.qo.h:221
tb::BooleanFormat boolFormat
The format for boolean values.
Definition: TBFormat.qo.h:166
int getVectorThreshold()
Returns the vector threshold for this format.
void setAllFont(QFontColor *fc)
Sets the QFontColor to be used on all values.
void changeColor()
Slot for when the user wants a color chooser.
static const int UNLIMITED_DECIMALS
Unlimited decimals constant.
Definition: TBFormat.qo.h:267
void valuesChanged()
Slot for when the user changes a font or color parameter.
bool getScientificFormat()
Returns true if this format&#39;s scientific format is on, false otherwise.
const Double c
Fundamental physical constants (SI units):
std::vector< QFontColor * > fonts
The vector of value-dependent QFontColors (can be empty).
Definition: TBFormat.qo.h:157
String: the storage and methods of handling collections of characters.
Definition: String.h:223
BooleanFormat
Enum listing the format for boolean values: &quot;true/false&quot;, &quot;t/f&quot;, &quot;1/0&quot;, etc.
Definition: TBConstants.h:67
void setFontColor(QFontColor *color)
Sets the displayed font and color information to the given QFontColor.
bool scientificFormat
Whether scientific format should be used.
Definition: TBFormat.qo.h:163
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the color(i.e.,"000000"for black) and
tb::BooleanFormat getBoolFormat()
Returns the boolean format.
TBFormat()
Default Constructor.
QFont color is a convenience class containing a QFont and a QColor.
Definition: TBFormat.qo.h:47