Developer Documentation
Loading...
Searching...
No Matches
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
64namespace ACG {
65
66//== IMPLEMENTATION ==========================================================
67
68
69QString
70getOpenFileName(QWidget* _parent,
71 const QString& _caption,
72 const QString& _filter,
73 const QString& _start)
74{
75
76#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
77 return
78 QFileDialog::getOpenFileName( _parent, // parent
79 _caption, // caption
80 _start, // dir
81 _filter, // filter
82 0, // selected filter
83 0 // options
84 );
85#else
86 return
87 QFileDialog::getOpenFileName( _parent, // parent
88 _caption, // caption
89 _start, // dir
90 _filter, // filter
91 0, // selected filter
92 QFileDialog::Options() // options
93 );
94#endif
95
96}
97
98
99QString
100getOpenMeshName(QWidget* _parent,
101 const QString& _caption,
102 const QString& _start)
103{
104 return
105 ACG::getOpenFileName(_parent,
106 _caption,
107 OpenMesh::IO::IOManager().qt_read_filters().c_str(),
108 _start);
109}
110
111
112//-----------------------------------------------------------------------------
113
114
115QStringList
116getOpenFileNames(QWidget* _parent,
117 const QString& _caption,
118 const QString& _filter,
119 const QString& _start)
120{
121#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
122 return
123 QFileDialog::getOpenFileNames( _parent, // parent
124 _caption, // caption
125 _start, // dir
126 _filter, //_filter
127 0, // selected filter
128 0 // options
129 );
130#else
131 return
132 QFileDialog::getOpenFileNames( _parent, // parent
133 _caption, // caption
134 _start, // dir
135 _filter, //_filter
136 0, // selected filter
137 QFileDialog::Options() // options
138 );
139#endif
140}
141
142
143QStringList
144getOpenMeshNames(QWidget* _parent,
145 const QString& _caption,
146 const QString& _start)
147{
148 return
149 ACG::getOpenFileNames(_parent,
150 _caption,
151 OpenMesh::IO::IOManager().qt_read_filters().c_str(),
152 _start);
153}
154
155
156//-----------------------------------------------------------------------------
157
158
159QString
160getSaveFileName(QWidget* _parent,
161 const QString& _caption,
162 const QString& _filter,
163 bool _askOW,
164 const QString& _start)
165{
166#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
167 QString filename =
168 QFileDialog::getSaveFileName ( _parent, // parent
169 _caption, // caption
170 _start, // dir
171 _filter, // filter,
172 0, // selected filter
173 0 // options
174 );
175#else
176 QString filename =
177 QFileDialog::getSaveFileName ( _parent, // parent
178 _caption, // caption
179 _start, // dir
180 _filter, // filter,
181 0, // selected filter
182 QFileDialog::Options() // options
183 );
184#endif
185
186 if (_askOW && !filename.isEmpty() && QFile(filename).exists())
187 {
188 QString s;
189 s += QString("The file\n ");
190 s += filename;
191 s += QString("\nalready exists.\n\n");
192 s += QString("Do you want to overwrite it?");
193
194 if (QMessageBox::warning(_parent, "Overwrite", s, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) != QMessageBox::Yes)
195 return QString();
196 }
197
198 return filename;
199}
200
201
202QString
203getSaveMeshName(QWidget* _parent,
204 const QString& _caption,
205 bool _askOW,
206 const QString& _start)
207{
208 return
209 ACG::getSaveFileName(_parent,
210 _caption,
212 qt_write_filters().c_str(),
213 _askOW,
214 _start);
215}
216
217
218//=============================================================================
219} // namespace ACG
220//=============================================================================
Namespace providing different geometric functions concerning angles.
_IOManager_ & IOManager()
Definition IOManager.cc:72
QString getOpenFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options)
QString getSaveFileName(const QString &configProperty, QWidget *parent, const QString &caption, const QString &defaultDir, const QString &filter, QString *selectedFilter, QFileDialog::Options options, const QString &defaultSuffix)