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