pqExpressionsManager.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 pqExpressionsManager_h
6 #define pqExpressionsManager_h
7 
8 #include "pqComponentsModule.h"
9 
10 #include <memory> // for unique_ptr
11 
12 #include <QString> // for QString
13 
15 {
16 public:
17  pqExpressionsManager() = default;
18  ~pqExpressionsManager() = default;
19 
23  struct pqExpression
24  {
25  pqExpression() = default;
26 
27  pqExpression(const QString& group, const QString& value)
28  : Group(group)
29  , Name("")
30  , Value(value)
31  {
32  }
33 
34  pqExpression(const QString& group, const QString& name, const QString& value)
35  : Group(group)
36  , Name(name)
37  , Value(value)
38  {
39  }
40 
41  bool operator==(const pqExpression& other) const
42  {
43  return this->Value == other.Value && this->Group == other.Group;
44  }
45 
46  // allow to sort by Group then Name then Value
47  bool operator<(const pqExpression& other) const
48  {
49  int compare = this->Group.compare(other.Group, Qt::CaseInsensitive);
50  if (compare != 0)
51  {
52  return compare < 0;
53  }
54 
55  compare = this->Name.compare(other.Name, Qt::CaseInsensitive);
56  if (compare != 0)
57  {
58  if (this->Name.isEmpty())
59  {
60  return false;
61  }
62  if (other.Name.isEmpty())
63  {
64  return true;
65  }
66 
67  return compare < 0;
68  }
69 
70  compare = this->Value.compare(other.Value, Qt::CaseInsensitive);
71  if (compare != 0)
72  {
73  return compare < 0;
74  }
75 
76  return false;
77  }
78 
79  QString Group;
80  QString Name;
81  QString Value;
82  };
83 
87  static QList<pqExpression> getExpressionsFromSettings();
88  static QList<pqExpression> getExpressionsFromSettings(const QString& group);
95  static bool addExpressionToSettings(const QString& group, const QString& value);
99  static void storeToSettings(const QList<pqExpression>& expressions);
100 
104  static constexpr const char* SETTINGS_GROUP() { return "ExpressionsManager"; }
108  static constexpr const char* SETTINGS_KEY() { return "Expressions"; }
112  static constexpr const char* EXPRESSION_GROUP() { return "Expression"; }
116  static constexpr const char* PYTHON_EXPRESSION_GROUP() { return "Python"; }
117 };
118 
119 #endif
static constexpr const char * PYTHON_EXPRESSION_GROUP()
Group for python expressions, like Python Calculator.
pqExpression(const QString &group, const QString &value)
bool operator<(const pqExpression &other) const
#define PQCOMPONENTS_EXPORT
Data structure to handle an expression and its group name.
static constexpr const char * SETTINGS_GROUP()
Name of QSettings group containing the expressions.
pqExpression(const QString &group, const QString &name, const QString &value)
Group
static constexpr const char * SETTINGS_KEY()
Name of QSettings key containing the expression concatenated in one string.
static constexpr const char * EXPRESSION_GROUP()
Group for classic expressions, like Calculator.
bool operator==(const pqExpression &other) const