00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef PLOTWIDGET_H 00011 #define PLOTWIDGET_H 00012 00013 #include "ColorType.h" 00014 #include "SessionItem.h" 00015 #include "Subject.h" 00016 #include "TypesFile.h" 00017 00018 #include <string> 00019 00020 class Axis; 00021 class Classification; 00022 class Font; 00023 class PlotSet; 00024 class PlotView; 00025 class QImage; 00026 class QWidget; 00027 00028 /** 00029 * A widget to display plot and associated information. 00030 * 00031 * The plot widget contains a plot view and several additional widgets to 00032 * display information about the plot. The plot widget contains a title, the 00033 * plot view, classification markings, axes, and a legend. The axes are 00034 * displayed only for Cartesian plots and not polar plots. 00035 * 00036 * When the user right-clicks in the plot widget, a \ref contextmenus 00037 * "context menu" is invoked allowing the user to change the display 00038 * characteristics of the widget. 00039 * 00040 * @warning The PlotView::signalAboutToShowContextMenu() signal is not 00041 * emitted when the user right-clicks in the plot widget. 00042 * 00043 * This subclass of Subject will notify upon the following conditions: 00044 * - The plot is renamed. 00045 * - The plot is deleted. 00046 * - The background color changes. 00047 * - The classification text label position changes. 00048 * - The classification text label color changes. 00049 * - The classification text label font changes. 00050 * - The classification text label text changes. 00051 * - The organization text label position changes. 00052 * - The organization text label color changes. 00053 * - The organization text label font changes. 00054 * - The organization text label text changes. 00055 * - The title text changes. 00056 * - The title text font changes. 00057 * - The legend background color changes. 00058 * - The user right-clicks in the widget to invoke a context menu. 00059 * - Everything else documented in Subject. 00060 * 00061 * @see PlotView 00062 */ 00063 class PlotWidget : public SessionItem, public Subject 00064 { 00065 public: 00066 /** 00067 * Emitted with boost::any<ContextMenu*> when the user right-clicks to 00068 * invoke a context menu. 00069 * 00070 * This signal provides a means by which an object can be notified when a 00071 * context menu is invoked by the user clicking inside a plot widget. To 00072 * receive notification for when a context menu is invoked when the user 00073 * clicks on any session item, attach to the 00074 * DesktopServices::signalAboutToShowContextMenu() signal instead. 00075 * 00076 * This signal is emitted after getContextMenuActions() is called and 00077 * after the DesktopServices::signalAboutToShowContextMenu() signal is 00078 * emitted, but before the context menu is shown to give attached objects a 00079 * chance to add or modify the context menu that will be displayed to the 00080 * user. 00081 * 00082 * The ContextMenu pointer value is guaranteed to be non-\c NULL. The 00083 * session items vector in the context menu contains the plot widget and 00084 * the plot view. 00085 * 00086 * @see \ref callingsequence "Context menu calling sequence" 00087 */ 00088 SIGNAL_METHOD(PlotWidget, AboutToShowContextMenu) 00089 00090 /** 00091 * @copydoc SessionItem::getContextMenuActions() 00092 * 00093 * @default The default implementation returns the context menu actions 00094 * listed \ref plotwidget "here". The default actions can be 00095 * removed or additional actions can be added by attaching to the 00096 * signalAboutToShowContextMenu() signal. 00097 */ 00098 virtual std::list<ContextMenuAction> getContextMenuActions() const = 0; 00099 00100 /** 00101 * Returns the plot widget as a Qt widget. 00102 * 00103 * This method returns the plot widget as a Qt widget, which can then be used 00104 * to add the plot widget to a custom dialog or widget layout. 00105 * 00106 * @return A pointer to the plot widget. 00107 */ 00108 virtual const QWidget* getWidget() const = 0; 00109 00110 /** 00111 * Returns the plot widget as a Qt widget. 00112 * 00113 * This method returns the plot widget as a Qt widget, which can then be used 00114 * to add the plot widget to a custom dialog or widget layout. 00115 * 00116 * @return A pointer to the plot widget. 00117 */ 00118 virtual QWidget* getWidget() = 0; 00119 00120 /** 00121 * Returns the plot set that contains this plot widget. 00122 * 00123 * @return A pointer to the plot set. \b NULL is returned if this plot 00124 * widget is not contained in a plot set. 00125 * 00126 * @see PlotSet 00127 */ 00128 virtual PlotSet* getPlotSet() const = 0; 00129 00130 /** 00131 * Returns the plot view inside of the widget. 00132 * 00133 * @return A pointer to the plot view. 00134 * 00135 * @see PlotView 00136 */ 00137 virtual PlotView* getPlot() const = 0; 00138 00139 /** 00140 * Sets the background color of the plot widget. 00141 * 00142 * This method sets the background color of the plot widget, but does not 00143 * set the background color of the plot area or the legend. 00144 * 00145 * @param backgroundColor 00146 * The new plot widget background color, which must be valid. 00147 * 00148 * @notify This method will notify Subject::signalModified(). 00149 * 00150 * @see setLegendBackgroundColor(), PlotView::setBackgroundColor() 00151 */ 00152 virtual void setBackgroundColor(const ColorType& backgroundColor) = 0; 00153 00154 /** 00155 * Returns the background color of the plot widget. 00156 * 00157 * The background color of the plot widget is separate from the background 00158 * color of the plot area and legend. 00159 * 00160 * @return The current background color of the plot widget. 00161 * 00162 * @see getLegendBackgroundColor(), PlotView::getBackgroundColor() 00163 */ 00164 virtual ColorType getBackgroundColor() const = 0; 00165 00166 /** 00167 * Sets the position of the classification label. The position value is maintained by the plot view even though 00168 * the PlotWidget actually draws the classification text. The new position is set in the plot view. 00169 * 00170 * @param ePosition 00171 * The position of the label. 00172 * 00173 * @notify This method will notify Subject::signalModified() if the 00174 * position is different from the previous position. 00175 * 00176 * @warning If the classification text label position and the organization 00177 * text label position contain an overlap (i.e.: both labels are 00178 * set to appear in the same location), the color and font of the 00179 * classification text will be used for display in the overlapping 00180 * areas (the color and font of the organization text will be ignored). 00181 * 00182 * @see PositionType, View::setClassificationPosition() 00183 */ 00184 virtual void setClassificationPosition(PositionType ePosition) = 0; 00185 00186 /** 00187 * Gets the position of the classification label. The position value is maintained by the plot view even though 00188 * the PlotWidget actually draws the classification text at the position stored in the plot view. 00189 * 00190 * @return The position of the label. 00191 * 00192 * @see PositionType, View::getClassificationPosition() 00193 */ 00194 virtual PositionType getClassificationPosition() const = 0; 00195 00196 /** 00197 * Sets the classification for this plot widget. 00198 * 00199 * This method is a convenience method that sets the classification of the 00200 * PlotView. 00201 * 00202 * @param pClassification 00203 * A pointer to the classification object from which to set the 00204 * widget's text markings. The classification text is cleared if 00205 * the given classification object pointer is \b NULL or if the 00206 * object is invalid. 00207 * 00208 * @notify This method will notify Subject::signalModified(). 00209 * 00210 * @see View::setClassification(), Classification 00211 */ 00212 virtual void setClassification(const Classification* pClassification) = 0; 00213 00214 /** 00215 * Returns a pointer to the plot widget's classification object. 00216 * 00217 * The classification object documents how the data in the plot widget is 00218 * to be handled and/or restricted. 00219 * 00220 * This is a convenience method that returns the classification object that 00221 * is stored in the PlotView object. 00222 * 00223 * @return A pointer to the plot widget's classification object. 00224 * 00225 * @see View::getClassification(), Classification 00226 */ 00227 virtual Classification* getClassification() = 0; 00228 00229 /** 00230 * Returns read-only access to the plot widget's classification object. 00231 * 00232 * The classification object documents how the data in the plot widget is 00233 * to be handled and/or restricted. 00234 * 00235 * This is a convenience method that returns the classification object that 00236 * is stored in the PlotView object. 00237 * 00238 * @return A const pointer to the plot widgets's classification object. 00239 * The classification represented by the returned pointer should 00240 * not be modified. To modify the values, call the non-const 00241 * version of getClassification() instead. 00242 * 00243 * @see View::getClassification(), Classification 00244 */ 00245 virtual const Classification* getClassification() const = 0; 00246 00247 /** 00248 * Returns a text string containing the classification text of the plot 00249 * widget. 00250 * 00251 * @return A string containing the classification text. 00252 */ 00253 virtual std::string getClassificationText() const = 0; 00254 00255 /** 00256 * Sets the font for the classification text. 00257 * 00258 * @param font 00259 * The new classification font. 00260 * 00261 * @notify This method will notify Subject::signalModified(). 00262 */ 00263 virtual void setClassificationFont(const Font& font) = 0; 00264 00265 /** 00266 * Returns read-only access to the classification text font. 00267 * 00268 * @return The current classification text font. To modify the font 00269 * values, call setClassificationFont() instead. 00270 */ 00271 virtual const Font& getClassificationFont() const = 0; 00272 00273 /** 00274 * Sets the classification text label color. 00275 * 00276 * @param classificationColor 00277 * The new classification text label color. 00278 * 00279 * @notify This method will notify Subject::signalModified(). 00280 */ 00281 virtual void setClassificationColor(const ColorType& classificationColor) = 0; 00282 00283 /** 00284 * Returns the color of the classification text label. 00285 * 00286 * @return The classification text label color. 00287 */ 00288 virtual ColorType getClassificationColor() const = 0; 00289 00290 /** 00291 * Sets the position of the organization label. 00292 * 00293 * @param ePosition 00294 * The position of the label. 00295 * 00296 * @notify This method will notify Subject::signalModified() if the 00297 * position is different from the previous position. 00298 * 00299 * @warning If the classification text label position and the organization 00300 * text label position contain an overlap (i.e.: both labels are 00301 * set to appear in the same location), the color and font of the 00302 * classification text will be used for display in the overlapping 00303 * areas (the color and font of the organization text will be ignored). 00304 * 00305 * @see PositionType 00306 */ 00307 virtual void setOrganizationPosition(PositionType ePosition) = 0; 00308 00309 /** 00310 * Gets the position of the organization label. 00311 * 00312 * @return The position of the label. 00313 * 00314 * @see PositionType 00315 */ 00316 virtual PositionType getOrganizationPosition() const = 0; 00317 00318 /** 00319 * Sets the organization text label. 00320 * 00321 * @param strOrganization 00322 * The text label. 00323 * 00324 * @notify This method will notify Subject::signalModified(). 00325 */ 00326 virtual void setOrganizationText(const std::string& strOrganization) = 0; 00327 00328 /** 00329 * Gets the organization text label. 00330 * 00331 * @return The text label. 00332 */ 00333 virtual std::string getOrganizationText() const = 0; 00334 00335 /** 00336 * Sets the font for the organization text. 00337 * 00338 * @param font 00339 * The new organization font. 00340 * 00341 * @notify This method will notify Subject::signalModified(). 00342 */ 00343 virtual void setOrganizationFont(const Font& font) = 0; 00344 00345 /** 00346 * Returns read-only access to the organization text font. 00347 * 00348 * @return The current organization text font. To modify the font 00349 * values, call setOrganizationFont() instead. 00350 */ 00351 virtual const Font& getOrganizationFont() const = 0; 00352 00353 /** 00354 * Sets the organization label color. 00355 * 00356 * @param clrOrganization 00357 * The new label color. 00358 * 00359 * @notify This method will notify Subject::signalModified(). 00360 */ 00361 virtual void setOrganizationColor(const ColorType& clrOrganization) = 0; 00362 00363 /** 00364 * Gets the organization label color. 00365 * 00366 * @return The label color. 00367 */ 00368 virtual ColorType getOrganizationColor() const = 0; 00369 00370 /** 00371 * Sets the plot title text. 00372 * 00373 * The plot title appears above the plot view and below the classification 00374 * and organization text. 00375 * 00376 * @param title 00377 * The new title text. 00378 * 00379 * @notify This method will notify Subject::signalModified() if the given 00380 * title is different than the current title. 00381 */ 00382 virtual void setTitle(const std::string& title) = 0; 00383 00384 /** 00385 * Returns the plot title text. 00386 * 00387 * @return The plot title. 00388 */ 00389 virtual std::string getTitle() const = 0; 00390 00391 /** 00392 * Sets the font for the title text. 00393 * 00394 * @param font 00395 * The new title font. 00396 * 00397 * @notify This method will notify Subject::signalModified() if the given 00398 * font is different than the current font. 00399 */ 00400 virtual void setTitleFont(const Font& font) = 0; 00401 00402 /** 00403 * Returns read-only access to the title text font. 00404 * 00405 * @return The current title text font. To modify the font values, call 00406 * setTitleFont() instead. 00407 */ 00408 virtual const Font& getTitleFont() const = 0; 00409 00410 /** 00411 * Toggles the display state of an axis widget. 00412 * 00413 * This method shows or hides an axis widget if a CartesianPlot is 00414 * displayed. This method does nothing if a PolarPlot is displayed. 00415 * 00416 * @param axis 00417 * The position for which to show or hide the axis. 00418 * @param bShow 00419 * Set this parameter to \b true to show the axis or to 00420 * \b false to hide the axis. 00421 */ 00422 virtual void showAxis(AxisPosition axis, bool bShow) = 0; 00423 00424 /** 00425 * Queries the display state of an axis widget. 00426 * 00427 * This method queries the display state of an axis widget if a 00428 * CartesianPlot is displayed. 00429 * 00430 * @param axis 00431 * The position for which to query the axis display state. 00432 * 00433 * @return Returns \b true if the axis in the given position is shown, or 00434 * returns \b false if the axis is hidden or if a PolarPlot is 00435 * displayed. 00436 */ 00437 virtual bool isAxisShown(AxisPosition axis) const = 0; 00438 00439 /** 00440 * Retrieves an axis widget. 00441 * 00442 * @param axis 00443 * The position for which to get the axis. 00444 * 00445 * @return Returns a pointer to the axis widget in the given position. 00446 * This method always returns \c NULL if a PolarPlot is displayed. 00447 */ 00448 virtual Axis* getAxis(AxisPosition axis) const = 0; 00449 00450 /** 00451 * Sets the display state of the plot legend. 00452 * 00453 * @param bShow 00454 * Set this value to \b true to show the legend or to \b false to 00455 * hide the legend. 00456 */ 00457 virtual void showLegend(bool bShow) = 0; 00458 00459 /** 00460 * Queries the display state of the plot legend. 00461 * 00462 * @return Returns \b true if the legend is displayed, or \b false if the 00463 * legend is hidden. 00464 */ 00465 virtual bool isLegendShown() const = 0; 00466 00467 /** 00468 * Sets the background color of the legend. 00469 * 00470 * This method sets the background color of the legend, which is separate 00471 * from the background color of the plot widget and plot area. 00472 * 00473 * @param backgroundColor 00474 * The new legend background color, which must be valid. 00475 * 00476 * @notify This method will notify Subject::signalModified(). 00477 * 00478 * @see setBackgroundColor(), PlotView::setBackgroundColor() 00479 */ 00480 virtual void setLegendBackgroundColor(const ColorType& backgroundColor) = 0; 00481 00482 /** 00483 * Returns the background color of the legend. 00484 * 00485 * The background color of the legend is separate from the background 00486 * color of the plot widget and plot area. 00487 * 00488 * @return The current background color of the legend. 00489 * 00490 * @see getBackgroundColor(), PlotView::getBackgroundColor() 00491 */ 00492 virtual ColorType getLegendBackgroundColor() const = 0; 00493 00494 /** 00495 * Retrieves an image of the plot widget. 00496 * 00497 * This method retrieves the image data for the plot widget. This is 00498 * similar to taking a screen snapshot of the widget. 00499 * 00500 * @param image 00501 * A Qt image reference that is populated with the current plot 00502 * widget image. If a null image is passed in, the size of the 00503 * image will be equal to the size of the plot widget in screen 00504 * pixels. Otherwise, the widget will be scaled to the image size 00505 * when generating the image data. 00506 * 00507 * @return Returns \b true if a valid image was successfully retrieved, 00508 * otherwise returns \b false. 00509 */ 00510 virtual bool getCurrentImage(QImage& image) = 0; 00511 00512 /** 00513 * Sends the current widget image to the printer. 00514 * 00515 * @param bPrintDialog 00516 * Set this value to \b true to display the print options dialog 00517 * before printing. 00518 */ 00519 virtual void print(bool bPrintDialog = true) = 0; 00520 00521 protected: 00522 /** 00523 * This object should be destroyed by calling PlotSet::deletePlot() or 00524 * DesktopServices::deletePlotWidget(). 00525 */ 00526 virtual ~PlotWidget() {} 00527 }; 00528 00529 #endif