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 <QStringList>
15 
16 class QModelIndex;
17 class QPoint;
18 class pqServer;
19 class QShowEvent;
20 
61 class PQCORE_EXPORT pqFileDialog : public QDialog
62 {
63  typedef QDialog Superclass;
64  Q_OBJECT
65 public:
85  enum FileMode
86  {
91  ExistingFilesAndDirectories
92  };
93 
109  pqFileDialog(pqServer* server, QWidget* parent, const QString& title = QString(),
110  const QString& directory = QString(), const QString& filter = QString(),
111  bool supportGroupFiles = true, bool onlyBrowseRemotely = true);
112  ~pqFileDialog() override;
113 
115 
118  void setFileMode(FileMode, vtkTypeUInt32);
119  void setFileMode(FileMode);
121 
123 
126  void setRecentlyUsedExtension(const QString& fileExtension, vtkTypeUInt32 location);
127  void setRecentlyUsedExtension(const QString& fileExtension);
129 
133  QStringList getSelectedFiles(int index = 0);
134 
138  QList<QStringList> getAllSelectedFiles();
139 
143  int getSelectedFilterIndex();
144 
148  void accept() override;
149 
153  bool selectFile(const QString&);
154 
158  void setShowHidden(const bool& hidden);
159 
163  bool getShowHidden();
164 
169  vtkTypeUInt32 getSelectedLocation() const { return this->SelectedLocation; }
170 
172 
176  static QString getSaveFileName(pqServer* server, QWidget* parentWdg,
177  const QString& title = QString(), const QString& directory = QString(),
178  const QString& filter = QString())
179  {
180  const QPair<QString, vtkTypeUInt32> result =
181  pqFileDialog::getSaveFileNameAndLocation(server, parentWdg, title, directory, filter);
182  return result.first;
183  }
184  static QPair<QString, vtkTypeUInt32> getSaveFileNameAndLocation(pqServer* server,
185  QWidget* parentWdg, const QString& title = QString(), const QString& directory = QString(),
186  const QString& filter = QString(), bool supportGroupFiles = false,
187  bool onlyBrowseRemotely = true);
189 Q_SIGNALS:
193  void filesSelected(const QList<QStringList>&);
194 
202  void filesSelected(const QStringList&);
203 
209  void fileAccepted(const QString&);
210 
211 protected:
212  bool acceptExistingFiles();
213  bool acceptDefault(const bool& checkForGrouping);
214 
215  QStringList buildFileGroup(const QString& filename);
216 
217  void showEvent(QShowEvent* showEvent) override;
218 
219 private Q_SLOTS:
220  void onLocationChanged(int fs);
221  void onModelReset();
222  void onNavigate(const QString& = QString());
223  void onNavigateUp();
224  void onNavigateBack();
225  void onNavigateForward();
226  void onNavigateDown(const QModelIndex&);
227  void onFilterChange(const QString&);
228 
229  void onClickedRecent(const QModelIndex&);
230  void onClickedFavorite(const QModelIndex&);
231  void onClickedFile(const QModelIndex&);
232 
233  void onActivateFavorite(const QModelIndex&);
234  void onActivateLocation(const QModelIndex&);
235  void onActivateRecent(const QModelIndex&);
236  void onDoubleClickFile(const QModelIndex&);
237 
238  void onTextEdited(const QString&);
239 
240  void onShowHiddenFiles(const bool& hide);
241 
242  void onShowDetailToggled(bool show);
243 
244  void onGroupFilesToggled(bool group);
245 
246  // Called when the user changes the file selection.
247  void fileSelectionChanged();
248 
249  // Called when the user right-clicks in the file qtreeview
250  void onContextMenuRequested(const QPoint& pos);
251 
252  // Called when the user right-clicks in the favorites qlistview
253  void onFavoritesContextMenuRequested(const QPoint& pos);
254 
255  void AddDirectoryToFavorites(QString const&);
256  void RemoveDirectoryFromFavorites(QString const&);
257  void FilterDirectoryFromFavorites(const QString& filter);
258 
259  void onAddCurrentDirectoryToFavorites();
260  void onRemoveSelectedDirectoriesFromFavorites();
261  void onResetFavoritesToSystemDefault();
262 
263  // Called when the user requests to create a new directory in the cwd
264  void onCreateNewFolder();
265 
269  void addToFilesSelected(const QStringList&);
270 
274  void emitFilesSelectionDone();
275 
281  void updateButtonStates(vtkTypeUInt32 fileSystem);
282 
283 private: // NOLINT(readability-redundant-access-specifiers)
284  pqFileDialog(const pqFileDialog&);
285  pqFileDialog& operator=(const pqFileDialog&);
286 
287  class pqImplementation;
288  QMap<vtkTypeUInt32, pqImplementation*> Implementations;
289  vtkTypeUInt32 SelectedLocation;
290 
291  // returns if true if files are loaded
292  bool acceptInternal(const QStringList& selected_files);
293  QString fixFileExtension(const QString& filename, const QString& filter);
294 
296 
299  void saveState(vtkTypeUInt32 fileSystem);
300  void saveState();
302 
304 
307  void restoreState(vtkTypeUInt32 fileSystem);
308  void restoreState();
310 };
311 
312 #endif // pqFileDialog_h
vtkTypeUInt32 getSelectedLocation() const
Get the location that the selected files/directories belong to.
Definition: pqFileDialog.h:169
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:176
FileMode
choose mode for selecting file/folder.
Definition: pqFileDialog.h:85
Provides a standard file dialog "front-end" for the pqFileDialogModel "back-end", i...
Definition: pqFileDialog.h:61
#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