pqFileDialog.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef pqFileDialog_h
6 #define pqFileDialog_h
7 
8 #include "pqCoreModule.h"
9 
10 #include "vtkType.h" // needed for vtkTypeUInt32
11 
12 #include <QDialog>
13 #include <QMap>
14 #include <QPointer>
15 #include <QStringList>
16 
17 class QModelIndex;
18 class QPoint;
19 class QShowEvent;
20 class pqServer;
21 
62 class PQCORE_EXPORT pqFileDialog : public QDialog
63 {
64  typedef QDialog Superclass;
65  Q_OBJECT
66 public:
86  enum FileMode
87  {
92  ExistingFilesAndDirectories
93  };
94 
110  pqFileDialog(pqServer* server, QWidget* parent, const QString& title = QString(),
111  const QString& directory = QString(), const QString& filter = QString(),
112  bool supportGroupFiles = true, bool onlyBrowseRemotely = true);
113  ~pqFileDialog() override;
114 
116 
119  void setFileMode(FileMode, vtkTypeUInt32);
120  void setFileMode(FileMode);
122 
124 
127  void setRecentlyUsedExtension(const QString& fileExtension, vtkTypeUInt32 location);
128  void setRecentlyUsedExtension(const QString& fileExtension);
130 
134  QStringList getSelectedFiles(int index = 0);
135 
139  QList<QStringList> getAllSelectedFiles();
140 
144  int getSelectedFilterIndex();
145 
149  void accept() override;
150 
154  bool selectFile(const QString&);
155 
159  void setShowHidden(const bool& hidden);
160 
164  bool getShowHidden();
165 
170  vtkTypeUInt32 getSelectedLocation() const { return this->SelectedLocation; }
171 
173 
177  static QString getSaveFileName(pqServer* server, QWidget* parentWdg,
178  const QString& title = QString(), const QString& directory = QString(),
179  const QString& filter = QString())
180  {
181  const QPair<QString, vtkTypeUInt32> result =
182  pqFileDialog::getSaveFileNameAndLocation(server, parentWdg, title, directory, filter);
183  return result.first;
184  }
185  static QPair<QString, vtkTypeUInt32> getSaveFileNameAndLocation(pqServer* server,
186  QWidget* parentWdg, const QString& title = QString(), const QString& directory = QString(),
187  const QString& filter = QString(), bool supportGroupFiles = false,
188  bool onlyBrowseRemotely = true);
190 Q_SIGNALS:
194  void filesSelected(const QList<QStringList>&);
195 
203  void filesSelected(const QStringList&);
204 
210  void fileAccepted(const QString&);
211 
212 protected:
213  bool acceptExistingFiles();
214  bool acceptDefault(const bool& checkForGrouping);
215 
216  QStringList buildFileGroup(const QString& filename);
217 
218  void showEvent(QShowEvent* showEvent) override;
219 
220 private Q_SLOTS:
221  void onLocationChanged(int fs);
222  void onModelReset();
223  void onNavigate(const QString& = QString());
224  void onNavigateUp();
225  void onNavigateBack();
226  void onNavigateForward();
227  void onNavigateDown(const QModelIndex&);
228  void onFilterChange(const QString&);
229 
230  void onClickedRecent(const QModelIndex&);
231  void onClickedFavorite(const QModelIndex&);
232  void onClickedFile(const QModelIndex&);
233 
234  void onActivateFavorite(const QModelIndex&);
235  void onActivateLocation(const QModelIndex&);
236  void onActivateRecent(const QModelIndex&);
237  void onDoubleClickFile(const QModelIndex&);
238 
239  void onTextEdited(const QString&);
240 
241  void onShowHiddenFiles(const bool& hide);
242 
243  void onShowDetailToggled(bool show);
244 
245  void onGroupFilesToggled(bool group);
246 
247  // Called when the user changes the file selection.
248  void fileSelectionChanged();
249 
250  // Called when the user right-clicks in the file qtreeview
251  void onContextMenuRequested(const QPoint& pos);
252 
253  // Called when the user right-clicks in the favorites qlistview
254  void onFavoritesContextMenuRequested(const QPoint& pos);
255 
256  void AddDirectoryToFavorites(QString const&);
257  void RemoveDirectoryFromFavorites(QString const&);
258  void FilterDirectoryFromFavorites(const QString& filter);
259 
260  void onAddCurrentDirectoryToFavorites();
261  void onRemoveSelectedDirectoriesFromFavorites();
262  void onResetFavoritesToSystemDefault();
263 
264  // Called when the user requests to create a new directory in the cwd
265  void onCreateNewFolder();
266 
270  void addToFilesSelected(const QStringList&);
271 
275  void emitFilesSelectionDone();
276 
282  void updateButtonStates(vtkTypeUInt32 fileSystem);
283 
284 private: // NOLINT(readability-redundant-access-specifiers)
285  pqFileDialog(const pqFileDialog&);
286  pqFileDialog& operator=(const pqFileDialog&);
287 
288  class pqImplementation;
289  QMap<vtkTypeUInt32, QPointer<pqImplementation>> Implementations;
290  vtkTypeUInt32 SelectedLocation;
291 
292  QPointer<pqServer> Server;
293  const QString StartDirectory;
294  const QString NameFilter;
295  bool SupportsGroupFiles;
296  vtkTypeUInt32 DefaultLocation;
297  QString RecentlyUsedExtension;
298 
299  void addImplementation(vtkTypeUInt32 location);
300 
301  // returns if true if files are loaded
302  bool acceptInternal(const QStringList& selected_files);
303  QString fixFileExtension(const QString& filename, const QString& filter);
304 
306 
309  void saveState(vtkTypeUInt32 fileSystem);
310  void saveState();
312 
314 
317  void restoreState(vtkTypeUInt32 fileSystem);
318  void restoreState();
320 };
321 
322 #endif // pqFileDialog_h
location
vtkTypeUInt32 getSelectedLocation() const
Get the location that the selected files/directories belong to.
Definition: pqFileDialog.h:170
static QString getSaveFileName(pqServer *server, QWidget *parentWdg, const QString &title=QString(), const QString &directory=QString(), const QString &filter=QString())
static method similar to QFileDialog::getSaveFileName(...) to make it easier to get a file name to sa...
Definition: pqFileDialog.h:177
FileMode
choose mode for selecting file/folder.
Definition: pqFileDialog.h:86
Provides a standard file dialog "front-end" for the pqFileDialogModel "back-end", i...
Definition: pqFileDialog.h:62
#define PQCORE_EXPORT
Definition: pqCoreModule.h:15
static QPair< QString, vtkTypeUInt32 > getSaveFileNameAndLocation(pqServer *server, QWidget *parentWdg, const QString &title=QString(), const QString &directory=QString(), const QString &filter=QString(), bool supportGroupFiles=false, bool onlyBrowseRemotely=true)
static method similar to QFileDialog::getSaveFileName(...) to make it easier to get a file name to sa...
pqServer (should be renamed to pqSession) is a pqServerManagerModelItem subclass that represents a vt...
Definition: pqServer.h:35
title