Optika GUI Toolik  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Optika_GUI.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Optika: A Tool For Developing Parameter Obtaining GUIs
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the
8 // U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com)
38 //
39 // ***********************************************************************
40 // @HEADER
41 #include <QApplication>
42 #include <QtGui>
43 #include <QString>
44 #include "Optika_GUI.hpp"
45 namespace Optika{
46 
47 void getInput(RCP<ParameterList> validParameters, RCP<DependencySheet> dependencySheet, void (*customFunc)(RCP<const ParameterList>)){
48  {
49  using namespace Qt;
50  int argNum=1;
51  char* args[1];
52  std::string appName ="Optika";
53  args[0] = &appName[0];
54  QApplication a(argNum,args);
55  MetaWindow theWindow(validParameters, dependencySheet, customFunc);
56  theWindow.show();
57  a.exec();
58  }
59 }
60 
61 void getInput(
62  const std::string& nameOfXmlFile,
63  RCP<ParameterList>& userInput,
64  void (*customFunc)(RCP<const ParameterList>))
65 {
66  {
67  using namespace Qt;
68  RCP<DependencySheet> depSheet = rcp(new DependencySheet());
69  userInput = getParametersFromXmlFile(nameOfXmlFile, depSheet);
70  int argNum=1;
71  char* args[1];
72  std::string appName ="Optika";
73  args[0] = &appName[0];
74  QApplication a(argNum,args);
75  MetaWindow theWindow(userInput, depSheet, customFunc);
76  theWindow.show();
77  a.exec();
78  }
79 }
80 
82  RCP<ParameterList> validParameters,
83  RCP<DependencySheet> dependencySheet,
84  std::string styleSheetFilePath,
85  std::string iconFilePath,
86  void (*customFunc)(RCP<const ParameterList>)){
87  {
88  using namespace Qt;
89  int argNum=1;
90  char* args[1];
91  std::string appName ="Optika";
92  args[0] = &appName[0];
93  QApplication a(argNum,args);
94  std::string submitText = "Submit and save XML";
95  std::string submitNoSaveText = "Submit";
96  MetaWindow theWindow(validParameters, dependencySheet, customFunc, "", submitText, submitNoSaveText);
97  if(iconFilePath != ""){
98  QIcon windowIcon(QString::fromStdString(iconFilePath));
99  a.setWindowIcon(windowIcon);
100  }
101  if(styleSheetFilePath != ""){
102  QString str;
103  QFile file(QString::fromStdString(styleSheetFilePath));
104  if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
105  QTextStream in(&file);
106  while (!in.atEnd()) {
107  str += in.readLine();
108  }
109  a.setStyleSheet(str);
110  }
111  }
112 
113  theWindow.show();
114  a.exec();
115  }
116 }
117 
119  const std::string& nameOfXmlFile,
120  RCP<ParameterList>& userInput,
121  std::string styleSheetFilePath,
122  std::string iconFilePath,
123  void (*customFunc)(RCP<const ParameterList>))
124 {
125  {
126  using namespace Qt;
127  RCP<DependencySheet> depSheet = rcp(new DependencySheet());
128  userInput = getParametersFromXmlFile(nameOfXmlFile, depSheet);
129  int argNum=1;
130  char* args[1];
131  std::string appName ="Optika";
132  args[0] = &appName[0];
133  QApplication a(argNum,args);
134  std::string submitText = "Submit and save XML";
135  std::string submitNoSaveText = "Submit";
136  MetaWindow theWindow(userInput, depSheet, customFunc, "", submitText, submitNoSaveText);
137  if(iconFilePath != ""){
138  QIcon windowIcon(QString::fromStdString(iconFilePath));
139  a.setWindowIcon(windowIcon);
140  }
141  if(styleSheetFilePath != ""){
142  QString str;
143  QFile file(QString::fromStdString(styleSheetFilePath));
144  if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
145  QTextStream in(&file);
146  while (!in.atEnd()) {
147  str += in.readLine();
148  }
149  a.setStyleSheet(str);
150  }
151  }
152 
153  theWindow.show();
154  a.exec();
155  }
156 }
157 
158 
160  RCP<ParameterList> validParameters,
161  RCP<DependencySheet> dependencySheet,
162  void (*customFunc)(RCP<const ParameterList>)):
163  validParameters(validParameters),
164  dependencySheet(dependencySheet),
165  customFunc(customFunc)
166  {}
167 
169  const std::string& xmlFileName,
170  void (*customFunc)(RCP<const ParameterList>)):
171  customFunc(customFunc)
172 {
173  dependencySheet = rcp(new DependencySheet);
174  validParameters = getParametersFromXmlFile(xmlFileName, dependencySheet);
175 }
176 
178  {
179  using namespace Qt;
180  int argNum=1;
181  char* args[1];
182  std::string appName ="Optika";
183  args[0] = &appName[0];
184  QApplication a(argNum,args);
185  MetaWindow *theWindow;
186  theWindow = new MetaWindow(validParameters, dependencySheet, customFunc);
187  if(title != ""){
188  theWindow->setWindowTitle(QString::fromStdString(title));
189  }
190  if(iconFilePath != ""){
191  QIcon windowIcon(QString::fromStdString(iconFilePath));
192  QApplication::setWindowIcon(windowIcon);
193  }
194  if(styleSheetFilePath != ""){
195  QString str;
196  QFile file(QString::fromStdString(styleSheetFilePath));
197  if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
198  QTextStream in(&file);
199  while (!in.atEnd()) {
200  str += in.readLine();
201  }
202  a.setStyleSheet(str);
203  }
204  }
205  if(aboutInfo != ""){
206  theWindow->setAboutInfo(QString::fromStdString(aboutInfo));
207  }
208  theWindow->setActionButtonText(QString::fromStdString(actionButtonText));
209  theWindow->show();
210  theWindow->activateWindow();
211  a.exec();
212  delete theWindow;
213  }
214 
215 }
216 
217 void OptikaGUI::setWindowTitle(const std::string& title){
218  this->title = title;
219 }
220 
221 void OptikaGUI::setWindowIcon(const std::string& filePath){
222  this->iconFilePath = filePath;
223 }
224 
225 void OptikaGUI::setStyleSheet(const std::string& filePath){
226  this->styleSheetFilePath = filePath;
227 }
228 
230  this->customFunc = customFunc;
231 }
232 
233 void OptikaGUI::setAboutInfo(const std::string& aboutInfo){
234  this->aboutInfo = aboutInfo;
235 }
236 
237 void OptikaGUI::setActionButtonText(const std::string& text){
238  actionButtonText = text;
239 }
240 
242  return title;
243 }
244 
246  return iconFilePath;
247 }
248 
250  return styleSheetFilePath;
251 }
252 
254  return aboutInfo;
255 }
256 
257 }
258 
void setActionButtonText(const std::string &text)
Sets the text in the "action" button".
Definition: Optika_GUI.cpp:237
std::string styleSheetFilePath
File path to the QT style sheet to be used for the GUI.
Definition: Optika_GUI.hpp:300
std::string getAboutInfo()
Gets the information to be added to the about dialog of the GUI.
Definition: Optika_GUI.cpp:253
A collection of functions and an Object that serve as the primary interface to the Optika package all...
std::string aboutInfo
Information to be added to the about dialog of the GUI.
Definition: Optika_GUI.hpp:305
void(* customFunc)(RCP< const ParameterList >)
The custom function to be run whenever the user clicks the action button.
Definition: Optika_GUI.hpp:315
std::string getStyleSheet()
Gets the file path describing the location of the file being used as the QT Style Sheet...
Definition: Optika_GUI.cpp:249
void setCustomFunction(void(*customFunc)(RCP< const ParameterList >))
Sets the custom function to be used in the GUI. When ever the user clicks the action button...
Definition: Optika_GUI.cpp:229
void getInput(RCP< ParameterList > validParameters, RCP< DependencySheet > dependencySheet, void(*customFunc)(RCP< const ParameterList >))
Retreives the input for a Teuchos Parameter List using a GUI. Note the Parameter List will be edited...
Definition: Optika_GUI.cpp:47
void setWindowIcon(const std::string &filePath)
Sets the window icon to the image specified in the filePath.
Definition: Optika_GUI.cpp:221
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::string getWindowTitle()
Gets the window title.
Definition: Optika_GUI.cpp:241
std::string actionButtonText
Text to display in the action button.
Definition: Optika_GUI.hpp:310
std::string title
A string containing the window title.
Definition: Optika_GUI.hpp:290
void setStyleSheet(const std::string &filePath)
Sets the QT style sheet that should be used for the GUI.
Definition: Optika_GUI.cpp:225
void getInputExtraOptions(RCP< ParameterList > validParameters, RCP< DependencySheet > dependencySheet, std::string styleSheetFilePath, std::string iconFilePath, void(*customFunc)(RCP< const ParameterList >))
Retreives the input for a Teuchos Parameter List using a GUI. Note the Parameter List will be edited...
Definition: Optika_GUI.cpp:81
void setWindowTitle(const std::string &title)
Sets the title of the GUI window that is displayed to the user.
Definition: Optika_GUI.cpp:217
OptikaGUI(RCP< ParameterList > validParameters, RCP< DependencySheet > dependencySheet=null, void(*customFunc)(RCP< const ParameterList >)=NULL)
Constructs an OptikaGUI object.
Definition: Optika_GUI.cpp:159
The Main Window that contains all other widgets in the Optika GUI. For all undocumented functions ple...
void exec()
Runs the GUI and gets the user input.
Definition: Optika_GUI.cpp:177
void setAboutInfo(const std::string &aboutInfo)
Adds the information specified to the about dialog of the GUI.
Definition: Optika_GUI.cpp:233
std::string getWindowIcon()
Gets the file path describing the location of the file being used for the window icon.
Definition: Optika_GUI.cpp:245
std::string iconFilePath
File path to the image that should be used as the window icon.
Definition: Optika_GUI.hpp:295