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 VIEWERSHELL_H 00011 #define VIEWERSHELL_H 00012 00013 #include "AttachmentPtr.h" 00014 #include "ExecutableShell.h" 00015 00016 /** 00017 * \cond INTERNAL 00018 */ 00019 namespace boost 00020 { 00021 class any; 00022 } 00023 /// \endcond 00024 class QWidget; 00025 class ApplicationServices; 00026 00027 /** 00028 * \ingroup ShellModule 00029 * A base class for plug-ins with modeless dialogs. 00030 * 00031 * This class contains functionality to properly destroy modeless 00032 * dialogs in a plug-in. The default functionality of the class 00033 * sets the destroy after execute flag to false so that the modeless 00034 * dialog will not be destroyed when execute() successfully returns 00035 * and the allow multiple instances flag to false so that only one 00036 * modeless widget is available at any time. 00037 * 00038 * The abort() method is used to register a PlugInCallback with 00039 * DesktopServices to destroy the viewer widget. Derived plug-in 00040 * classes should therefore provide an implementation for the 00041 * getWidget() method to return a pointer to the modeless dialog or 00042 * other viewer widget. 00043 * 00044 * Derived plug-in classes must call the abort() method when the 00045 * executable should be destroyed. 00046 * This typically occurs in an overridden QWidget::closeEvent() 00047 * method in the modeless dialog or when the executable has detected an error 00048 * and needs to close. 00049 * 00050 * @see ExecutableShell 00051 */ 00052 class ViewerShell : public ExecutableShell 00053 { 00054 public: 00055 /** 00056 * Creates a viewer plug-in. 00057 * 00058 * The constructor sets the plug-in type to PlugInManagerServices::ViewerType() and sets the plug-in 00059 * to not be destroyed after execution. 00060 * 00061 * @see getType(), isDestroyedAfterExecute() 00062 */ 00063 ViewerShell(); 00064 00065 /** 00066 * Destroys the viewer plug-in. 00067 */ 00068 ~ViewerShell(); 00069 00070 /** 00071 * @copydoc Executable::getInputSpecification() 00072 * 00073 * @default The default implementation does not set any args in the arg 00074 * list and returns \b true. 00075 */ 00076 bool getInputSpecification(PlugInArgList*& pArgList); 00077 00078 /** 00079 * @copydoc Executable::getOutputSpecification() 00080 * 00081 * @default The default implementation does not set any args in the arg 00082 * list and returns \b true. 00083 */ 00084 bool getOutputSpecification(PlugInArgList*& pArgList); 00085 00086 /** 00087 * Destroys the viewer dialog or widget. 00088 * 00089 * To perform specialized cleanup, this method should be overridden to 00090 * perform the cleanup before calling the base class to destroy the viewer 00091 * widget. 00092 * 00093 * @default The default implementation of this method creates a 00094 * PlugInCallback based on the widget returned from getWidget() 00095 * and registers it with DesktopServices. When the callback is 00096 * executed, the widget is hidden and then destroyed. 00097 * 00098 * @return Returns \b true if the plug-in callback was successfully 00099 * registered with DesktopServices for the viewer widget, 00100 * otherwise returns \b false. 00101 * 00102 * @see PlugInCallback, DesktopServices::registerCallback() 00103 */ 00104 bool abort(); 00105 00106 /** 00107 * This slot is called when the ApplicationWindow closes. 00108 * 00109 * The viewer widget is deleted so that proper cleanup order is 00110 * preserved if the viewer is active during application shutdown. 00111 * 00112 * @param subject 00113 * This should be the DesktopServices pointer. 00114 * @param signal 00115 * DesktopServices::ApplicationWindowClosed 00116 * @param data 00117 * Invalid 00118 */ 00119 void cleanupWidget(Subject& subject, const std::string& signal, const boost::any& data); 00120 00121 protected: 00122 /** 00123 * Returns the viewer widget. 00124 * A value of NULL implies that no viewer widget needs to be destroyed. 00125 * 00126 * The viewer widget is typically a modeless dialog, but can be any QWidget. 00127 * This method is called by the default implementation of the abort() method 00128 * to destroy the widget. A derived plug-in should implement this method to 00129 * return a pointer to the widget so that it can be destroyed. 00130 * 00131 * @return A pointer to the viewer widget as a QWidget. 00132 * 00133 * @see abort() 00134 */ 00135 virtual QWidget* getWidget() const = 0; 00136 00137 AttachmentPtr<ApplicationServices> mpAppSvcsAttachment; 00138 00139 private: 00140 ViewerShell(const ViewerShell& rhs); 00141 ViewerShell& operator=(const ViewerShell& rhs); 00142 }; 00143 00144 #endif