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 
97  static QStringList findParaviewPaths(
98  QString directoryOrFileName, bool lookupInAppDir, bool lookupInUserDir);
99  static QString getNoneExistingFileName(QString expectedFilePath);
100 
110  static unsigned long connect(vtkObject* vtk_object, int vtk_event_id, QObject* qobject,
111  const char* signal_or_slot, Qt::ConnectionType type = Qt::AutoConnection);
112 
131  static bool promptUser(const QString& settingsKey, QMessageBox::Icon icon, const QString& title,
132  const QString& message, QMessageBox::StandardButtons buttons, QWidget* parentWdg = nullptr);
133 
140  static QMessageBox::Button promptUserGeneric(const QString& title, const QString& message,
141  QMessageBox::Icon icon, QMessageBox::StandardButtons buttons, QWidget* parentWidget);
142 
152  static QString number(double value, int lowExponent = -6, int highExponent = 20);
153 
158  static QString formatFullNumber(double value);
159 
161 
164  // Format with given precision and notation and shortAccurate flag
165  static QString formatDouble(double value, int notation, bool shortAccurate, int precision,
166  int fullLowExponent = -6, int fullHighExponent = 20);
167 
168  // Format with RealNumberDisplayed settings
169  static QString formatNumber(double value);
170 
171  // Format with AnimationTime settings
172  static QString formatTime(double value);
174 
180  static QString formatMemoryFromKiBValue(double memoryInKB, int precision = 2);
181 
187  static void initializeClickMeButton(QAbstractButton* button);
188 
193  static void setPaletteHighlightToOk(QPalette& palette);
194 
199  static void setPaletteHighlightToWarning(QPalette& palette);
200 
205  static void setPaletteHighlightToCritical(QPalette& palette);
206 
211  static void removeRecursively(QDir dir);
212 
217  static void remove(const QString& filePath);
218 
219 private:
220  static QWidget* findMainWindow();
221  static QPointer<QWidget> MainWidget;
222 };
223 
224 #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