COPASI API  4.16.103
CQSBMLFileDialog.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <QtCore/QRegExp>
16 
17 #include "copasi.h"
18 
19 #include "CQSBMLFileDialog.h"
20 #include "CopasiFileDialog.h"
21 
22 // static
23 std::pair< QString, std::pair< unsigned C_INT32, unsigned C_INT32 > > CQSBMLFileDialog::getSaveFileName(QWidget * parent,
24  const char * name,
25  const QString & startWith,
26  const QString & caption,
27  unsigned int sbmlLevel,
28  unsigned int sbmlVersion)
29 {
30  std::pair< QString, std::pair< unsigned C_INT32, unsigned C_INT32 > > NameAndVersion;
31 
32  QString Filter = "Level 1 Version 1 (*.xml);;"
33  "Level 1 Version 2 (*.xml);;"
34  "Level 2 Version 1 (*.xml);;"
35  "Level 2 Version 2 (*.xml);;"
36  "Level 2 Version 3 (*.xml);;"
37  "Level 2 Version 4 (*.xml);;"
38  "Level 2 Version 5 (*.xml);;"
39  "Level 3 Version 1 (*.xml)";
40 
41  QString SelectedFilter =
42  QString("Level %1 Version %2 (*.xml)").arg(QString::number(sbmlLevel)).arg(QString::number(sbmlVersion));;
43 
44  // The default export is L2V4
45  if (Filter.indexOf(SelectedFilter) == -1)
46  {
47  SelectedFilter = "Level 2 Version 4 (*.xml)";
48  }
49 
50  // We need to avoid the KDE dialog at least under Qt 4.7 and KDE 4.5
51  // See: Bug 1651
52  QFileDialog::Options DontUseNativeDialog = 0;
53 
54 #ifdef Linux
55  DontUseNativeDialog = QFileDialog::DontUseNativeDialog;
56 #endif // Linux
57 
58  NameAndVersion.first =
59  CopasiFileDialog::getSaveFileName(parent, name, startWith, Filter, caption, &SelectedFilter, DontUseNativeDialog);
60 
61  QRegExp Pattern("Level (\\d) Version (\\d) \\(\\*\\.xml\\)");
62 
63  if (Pattern.exactMatch(SelectedFilter))
64  {
65  NameAndVersion.second.first = Pattern.cap(1).toInt();
66  NameAndVersion.second.second = Pattern.cap(2).toInt();
67  }
68  else
69  {
70  NameAndVersion.second.first = 2;
71  NameAndVersion.second.second = 4;
72  }
73 
74  return NameAndVersion;
75 }
static std::pair< QString, std::pair< unsigned C_INT32, unsigned C_INT32 > > getSaveFileName(QWidget *parent, const char *name, const QString &startWith, const QString &caption, unsigned int sbmlLevel=2, unsigned int sbmlVersion=4)
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)