Developer Documentation
QtFileDialog.cc
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 //=============================================================================
47 //
48 // CLASS QtFileDialog - IMPLEMENTATION
49 //
50 //=============================================================================
51 
52 //== INCLUDES =================================================================
53 
54 #include "QtFileDialog.hh"
55 
56 #include <OpenMesh/Core/IO/IOManager.hh>
57 
58 #include <QFileDialog>
59 #include <QMessageBox>
60 
61 
62 //== NAMESPACES ===============================================================
63 
64 namespace ACG {
65 
66 //== IMPLEMENTATION ==========================================================
67 
68 
69 QString
70 getOpenFileName(QWidget* _parent,
71  const QString& _caption,
72  const QString& _filter,
73  const QString& _start)
74 {
75  return
76  QFileDialog::getOpenFileName( _parent, // parent
77  _caption, // caption
78  _start, // dir
79  _filter, // filter
80  0, // selected filter
81  0 // options
82  );
83 }
84 
85 
86 QString
87 getOpenMeshName(QWidget* _parent,
88  const QString& _caption,
89  const QString& _start)
90 {
91  return
92  ACG::getOpenFileName(_parent,
93  _caption,
94  OpenMesh::IO::IOManager().qt_read_filters().c_str(),
95  _start);
96 }
97 
98 
99 //-----------------------------------------------------------------------------
100 
101 
102 QStringList
103 getOpenFileNames(QWidget* _parent,
104  const QString& _caption,
105  const QString& _filter,
106  const QString& _start)
107 {
108  return
109  QFileDialog::getOpenFileNames( _parent, // parent
110  _caption, // caption
111  _start, // dir
112  _filter, //_filter
113  0, // selected filter
114  0 // options
115  );
116 }
117 
118 
119 QStringList
120 getOpenMeshNames(QWidget* _parent,
121  const QString& _caption,
122  const QString& _start)
123 {
124  return
125  ACG::getOpenFileNames(_parent,
126  _caption,
127  OpenMesh::IO::IOManager().qt_read_filters().c_str(),
128  _start);
129 }
130 
131 
132 //-----------------------------------------------------------------------------
133 
134 
135 QString
136 getSaveFileName(QWidget* _parent,
137  const QString& _caption,
138  const QString& _filter,
139  bool _askOW,
140  const QString& _start)
141 {
142  QString filename =
143  QFileDialog::getSaveFileName ( _parent, // parent
144  _caption, // caption
145  _start, // dir
146  _filter, // filter,
147  0, // selected filter
148  0 // options
149  );
150 
151  if (_askOW && !filename.isEmpty() && QFile(filename).exists())
152  {
153  QString s;
154  s += QString("The file\n ");
155  s += filename;
156  s += QString("\nalready exists.\n\n");
157  s += QString("Do you want to overwrite it?");
158 
159  if (QMessageBox::warning(_parent, "Overwrite", s,
160  QMessageBox::Yes | QMessageBox::Default,
161  QMessageBox::No | QMessageBox::Escape)
162  != QMessageBox::Yes)
163  return QString();
164  }
165 
166  return filename;
167 }
168 
169 
170 QString
171 getSaveMeshName(QWidget* _parent,
172  const QString& _caption,
173  bool _askOW,
174  const QString& _start)
175 {
176  return
177  ACG::getSaveFileName(_parent,
178  _caption,
180  qt_write_filters().c_str(),
181  _askOW,
182  _start);
183 }
184 
185 
186 //=============================================================================
187 } // namespace ACG
188 //=============================================================================
Namespace providing different geometric functions concerning angles.
QString getOpenFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
_IOManager_ & IOManager()
Definition: IOManager.cc:72
QString getSaveFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QString &defaultSuffix)