pqCoreUtilities.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 #ifndef pqCoreUtilities_h
5 #define pqCoreUtilities_h
6 
7 #include "pqCoreModule.h"
8 #include "pqEventDispatcher.h"
9 
10 #include <QDir>
11 #include <QEventLoop>
12 #include <QFile>
13 #include <QFileInfo>
14 #include <QMessageBox>
15 #include <QPointer>
16 #include <QString>
17 #include <QStringList>
18 #include <QWidget>
19 
20 class QPalette;
21 class vtkObject;
22 
28 {
29  Q_OBJECT;
30  typedef QObject Superclass;
31 
32 public:
33  pqCoreUtilitiesEventHelper(QObject* parent);
34  ~pqCoreUtilitiesEventHelper() override;
35 
36 Q_SIGNALS:
37  void eventInvoked(vtkObject*, unsigned long, void*);
38 
39 private:
40  Q_DISABLE_COPY(pqCoreUtilitiesEventHelper)
41 
42  void executeEvent(vtkObject*, unsigned long, void*);
43  class pqInternal;
44  pqInternal* Interal;
45  friend class pqCoreUtilities;
46 };
47 
52 class PQCORE_EXPORT pqCoreUtilities : public QObject
53 {
54  Q_OBJECT
55 public:
62  static void setMainWidget(QWidget* widget) { pqCoreUtilities::MainWidget = widget; }
63  static QWidget* mainWidget()
64  {
65  if (!pqCoreUtilities::MainWidget)
66  {
67  pqCoreUtilities::MainWidget = pqCoreUtilities::findMainWindow();
68  }
69  return pqCoreUtilities::MainWidget;
70  }
71 
75  static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents)
76  {
77  pqEventDispatcher::processEvents(flags);
78  }
79 
86  static QString getParaViewUserDirectory();
87 
91  static QString getParaViewApplicationDirectory();
92 
98  static QString getParaViewApplicationDataDirectory();
99 
104  static QStringList findParaviewPaths(
105  QString directoryOrFileName, bool lookupInAppDir, bool lookupInUserDir);
106  static QString getNoneExistingFileName(QString expectedFilePath);
107 
117  static unsigned long connect(vtkObject* vtk_object, int vtk_event_id, QObject* qobject,
118  const char* signal_or_slot, Qt::ConnectionType type = Qt::AutoConnection);
119 
138  static bool promptUser(const QString& settingsKey, QMessageBox::Icon icon, const QString& title,
139  const QString& message, QMessageBox::StandardButtons buttons, QWidget* parentWdg = nullptr);
140 
147  static QMessageBox::Button promptUserGeneric(const QString& title, const QString& message,
148  QMessageBox::Icon icon, QMessageBox::StandardButtons buttons, QWidget* parentWidget);
149 
159  static QString number(double value, int lowExponent = -6, int highExponent = 20);
160 
165  static QString formatFullNumber(double value);
166 
168 
171  // Format with given precision and notation and shortAccurate flag
172  static QString formatDouble(double value, int notation, bool shortAccurate, int precision,
173  int fullLowExponent = -6, int fullHighExponent = 20);
174 
175  // Format with RealNumberDisplayed settings
176  static QString formatNumber(double value);
177 
178  // Format with AnimationTime settings
179  static QString formatTime(double value);
181 
187  static QString formatMemoryFromKiBValue(double memoryInKB, int precision = 2);
188 
194  static void initializeClickMeButton(QAbstractButton* button);
195 
200  static void setPaletteHighlightToOk(QPalette& palette);
201 
206  static void setPaletteHighlightToWarning(QPalette& palette);
207 
212  static void setPaletteHighlightToCritical(QPalette& palette);
213 
218  static void removeRecursively(QDir dir);
219 
224  static void remove(const QString& filePath);
225 
226 private:
227  static QWidget* findMainWindow();
228  static QPointer<QWidget> MainWidget;
229 };
230 
231 #endif
type
dir
static QWidget * mainWidget()
#define PQCORE_EXPORT
Definition: pqCoreModule.h:15
connect
value
INTERNAL CLASS (DO NOT USE).
pqCoreUtilities is a collection of arbitrary utility functions that can be used by the application...
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Call QApplication::processEvents plus make sure the testing framework is.
static void setMainWidget(QWidget *widget)
When popping up dialogs, it&#39;s generally better if we set the parent widget for those dialogs to be th...
title