COPASI API  4.16.103
Static Public Member Functions | Static Private Member Functions | List of all members
CopasiFileDialog Class Reference

#include <CopasiFileDialog.h>

Static Public Member Functions

static QString getOpenFileName (QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
 
static QString getSaveFileName (QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
 
static void openExampleDir ()
 

Static Private Member Functions

static QString StartWith (const QString &startWith)
 

Detailed Description

Definition at line 22 of file CopasiFileDialog.h.

Member Function Documentation

QString CopasiFileDialog::getOpenFileName ( QWidget *  parent = 0,
const char *  name = 0,
const QString &  startWith = QString::null,
const QString &  filter = QString::null,
const QString &  caption = QString::null,
QString *  pSelectedFilter = NULL,
QFileDialog::Options  options = 0 
)
static

Definition at line 63 of file CopasiFileDialog.cpp.

References CDirEntry::dirName(), CCopasiRootContainer::getConfiguration(), CConfigurationFile::setWorkingDirectory(), StartWith(), and TO_UTF8.

Referenced by CQExperimentData::slotFileAdd(), CopasiUI3Window::slotFileOpen(), CopasiUI3Window::slotFunctionDBLoad(), and CopasiUI3Window::slotImportSBML().

70 {
71  QString newFilter = filter;
72 
73  if (filter.indexOf("(*)") < 0)
74  newFilter += ";;Any File (*)";
75 
76  QString newFile = QFileDialog::getOpenFileName(parent,
77  caption,
78  StartWith(startWith),
79  newFilter,
80  pSelectedFilter,
81  options);
82 
83  if (newFile != "")
85 
86  return newFile;
87 }
void setWorkingDirectory(const std::string &workingDirectory)
static std::string dirName(const std::string &path)
Definition: CDirEntry.cpp:135
static CConfigurationFile * getConfiguration()
static QString StartWith(const QString &startWith)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
QString CopasiFileDialog::getSaveFileName ( QWidget *  parent = 0,
const char *  name = 0,
const QString &  startWith = QString::null,
const QString &  filter = QString::null,
const QString &  caption = QString::null,
QString *  pSelectedFilter = NULL,
QFileDialog::Options  options = 0 
)
static

Definition at line 90 of file CopasiFileDialog.cpp.

References CDirEntry::dirName(), CDirEntry::fileName(), FROM_UTF8, CCopasiRootContainer::getConfiguration(), CQMessageBox::information(), CConfigurationFile::setWorkingDirectory(), StartWith(), CDirEntry::suffix(), and TO_UTF8.

Referenced by CQSEDMLFileDialog::getSaveFileName(), CQSBMLFileDialog::getSaveFileName(), PlotWindow::printAsImage(), CQTSSAResultSubWidget::saveDataToFile(), CQBarChart::saveDataToFile(), CQLayoutMainWindow::saveImage(), CQLyapResultWidget::saveToFile(), CQSensResultWidget::saveToFile(), CQReportDefinitionSelect::slotBrowse(), CQParameterOverviewWidget::slotBtnSaveToFile(), CopasiUI3Window::slotCapture(), CopasiUI3Window::slotExportMathModel(), CopasiUI3Window::slotFileSaveAs(), CopasiUI3Window::slotFunctionDBSave(), CQDifferentialEquations::slotSave(), CQSteadyStateResult::slotSave(), CQTimeSeriesWidget::slotSave(), CQMoietiesTaskResult::slotSave(), CMCAResultSubwidget::slotSave(), CLNAResultSubwidget::slotSave(), CQOptimizationResult::slotSave(), CQEFMResultWidget::slotSave(), CQFittingResult::slotSave(), PlotWindow::slotSaveData(), CQExpressionMmlStackedWidget::slotSaveExpression(), and CQNewMainWindow::slotScreenshot().

97 {
98  QString newFile, newFilter = filter;
99  bool fileValid;
100 
101  if (!pSelectedFilter)
102  pSelectedFilter = new QString("");
103 
104  if (filter.indexOf("(*)") < 0)
105  newFilter += ";;Any File (*)";
106 
107  do
108  {
109  fileValid = true;
110  newFile = QFileDialog::getSaveFileName(parent,
111  caption,
112  StartWith(startWith),
113  newFilter, pSelectedFilter,
114  QFileDialog::DontConfirmOverwrite | options);
115 
116  if (newFile != "")
118  else
119  return QString::null;
120 
121  if (pSelectedFilter->indexOf("(*)") >= 0)
122  {
123  QString fileName = FROM_UTF8(CDirEntry::fileName(TO_UTF8(newFile)));
124  QString suffix = FROM_UTF8(CDirEntry::suffix(TO_UTF8(newFile)));
125 
126  if (!suffix.length())
127  {
128  fileValid = true;
129  }
130  else
131  {
132  QRegExp rx("\\.\\S{1,4}$");
133 
134  if (rx.indexIn(fileName) < 0)
135  {
136  CQMessageBox::information(NULL, "Save File Error",
137  "Filename can have an extension 1 to 4 characters long.",
138  QMessageBox::Ok, QMessageBox::Ok);
139  fileValid = false;
140  continue;
141  }
142 
143  QRegExp rxDigits("\\.\\d{1,4}$");
144 
145  if (rxDigits.indexIn(fileName) > 0)
146  {
147  CQMessageBox::information(NULL, "Save File Error",
148  "All characters in the file extension cannot be digits.",
149  QMessageBox::Ok, QMessageBox::Ok);
150  fileValid = false;
151  continue;
152  }
153  }
154  }
155  }
156  while (fileValid == false);
157 
158 #ifdef DEBUG_UI
159 // qDebug() << "user selected Filter = " << usersFilter;
160  qDebug() << "user's Filter = " << *pSelectedFilter;
161 // qDebug() << "correct extension = " << correctExt;
162 // qDebug() << "filename = " << newFile;
163 #endif
164 
165  return newFile;
166 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static std::string fileName(const std::string &path)
Definition: CDirEntry.cpp:119
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void setWorkingDirectory(const std::string &workingDirectory)
static std::string dirName(const std::string &path)
Definition: CDirEntry.cpp:135
static CConfigurationFile * getConfiguration()
static QString StartWith(const QString &startWith)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
static std::string suffix(const std::string &path)
Definition: CDirEntry.cpp:159
void CopasiFileDialog::openExampleDir ( )
static

Definition at line 50 of file CopasiFileDialog.cpp.

References FROM_UTF8, CCopasiRootContainer::getConfiguration(), COptions::getValue(), CQMessageBox::information(), CDirEntry::isDir(), and CConfigurationFile::setWorkingDirectory().

Referenced by CopasiUI3Window::slotFileExamplesCopasiFiles(), and CopasiUI3Window::slotFileExamplesSBMLFiles().

51 {
52  std::string ExampleDir;
53  COptions::getValue("ExampleDir", ExampleDir);
54 
55  if (CDirEntry::isDir(ExampleDir))
57  else
58  CQMessageBox::information(NULL, "Directory Not Found", FROM_UTF8(ExampleDir),
59  QMessageBox::Ok, QMessageBox::Ok);
60 }
static bool isDir(const std::string &path)
Definition: CDirEntry.cpp:65
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void setWorkingDirectory(const std::string &workingDirectory)
static CConfigurationFile * getConfiguration()
static void getValue(const std::string &name, CType &value)
Definition: COptions.h:124
QString CopasiFileDialog::StartWith ( const QString &  startWith)
staticprivate

Definition at line 33 of file CopasiFileDialog.cpp.

References CDirEntry::dirName(), FROM_UTF8, CCopasiRootContainer::getConfiguration(), and TO_UTF8.

Referenced by getOpenFileName(), and getSaveFileName().

34 {
35  QString WorkingDirectory = FROM_UTF8(CCopasiRootContainer::getConfiguration()->getWorkingDirectory());
36 
37  if (startWith.isNull())
38  {
39  return WorkingDirectory;
40  }
41  else if (CDirEntry::dirName(TO_UTF8(startWith)) == "")
42  {
43  return WorkingDirectory + "/" + startWith;
44  }
45 
46  return startWith;
47 }
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
static std::string dirName(const std::string &path)
Definition: CDirEntry.cpp:135
static CConfigurationFile * getConfiguration()
#define TO_UTF8(__x)
Definition: qtUtilities.h:74

The documentation for this class was generated from the following files: