ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
graphics
VP1
VP1Base
src
VP1QtUtils.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
7
// //
8
// Implementation of class VP1QtUtils //
9
// //
10
// Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11
// Initial version: April 2008 //
12
// Update: October 2017 //
13
// Sebastian A. Merkt (sebastian.andreas.merkt@cern.ch //
14
// //
16
17
#include "
VP1Base/VP1QtUtils.h
"
18
#include "
VP1Base/VP1Msg.h
"
19
#include <cstdlib>
//For setenv/unsetenv
20
#include <QImage>
21
#include <QColor>
22
#include <QSettings>
23
#include <QCoreApplication>
24
25
26
//____________________________________________________________________
27
bool
VP1QtUtils::expertSettingIsSet
(
const
QString&
type
,
const
QString& name)
28
{
29
bool
set
;
30
if
(
type
==
"general"
){
31
QSettings generalSettings(
"ATLAS"
,
"VP1Light"
);
32
set
= !generalSettings.value(name).toString().isEmpty();
33
}
else
{
34
QSettings expertSettings(QCoreApplication::applicationDirPath()+
"/../vp1.ini"
, QSettings::NativeFormat);
35
set
= !expertSettings.value(name).toString().isEmpty();
36
}
37
if
(
VP1Msg::verbose
())
38
VP1Msg::messageVerbose
(
"VP1QtUtils::expertSettingIsSet called for variable '"
+name+
"'. Returning "
+
VP1Msg::str
(
set
));
39
return
set
;
40
}
41
42
//____________________________________________________________________
43
QString
VP1QtUtils::expertSettingValue
(
const
QString&
type
,
const
QString& name)
44
{
45
QString env;
46
if
(
type
==
"general"
){
47
QSettings generalSettings(
"ATLAS"
,
"VP1Light"
);
48
env = generalSettings.value(name).toString();
49
}
else
{
50
QSettings expertSettings(QCoreApplication::applicationDirPath()+
"/../vp1.ini"
, QSettings::NativeFormat);
51
env = expertSettings.value(name).toString();
52
}
53
QString val(env.isNull() ?
""
: std::move(env));
54
if
(
VP1Msg::verbose
())
55
VP1Msg::messageVerbose
(
"VP1QtUtils::expertSettingValue called for variable '"
+name+
"'. Returning '"
+ val+
"'."
);
56
return
val;
57
}
58
59
//____________________________________________________________________
60
bool
VP1QtUtils::expertSettingIsOn
(
const
QString&
type
,
const
QString& name)
61
{
62
QString env;
63
if
(
type
==
"general"
){
64
QSettings generalSettings(
"ATLAS"
,
"VP1Light"
);
65
env = generalSettings.value(name).toString();
66
}
else
{
67
QSettings expertSettings(QCoreApplication::applicationDirPath()+
"/../vp1.ini"
, QSettings::NativeFormat);
68
env = expertSettings.value(name).toString();
69
}
70
QString val(env.isNull() ?
""
: std::move(env) );
71
bool
ison =
true
;
72
if
(val==
""
||val==
"0"
)
73
ison =
false
;
74
else
if
(0==QString::compare(val,
"false"
,Qt::CaseInsensitive))
75
ison =
false
;
76
else
if
(0==QString::compare(val,
"off"
,Qt::CaseInsensitive))
77
ison =
false
;
78
else
if
(0==QString::compare(val,
"no"
,Qt::CaseInsensitive))
79
ison =
false
;
80
if
(
VP1Msg::verbose
())
81
VP1Msg::messageVerbose
(
"VP1QtUtils::expertSettingIsOn called for variable '"
+name+
"'. Returning "
+
VP1Msg::str
(ison)+
"."
);
82
return
ison;
83
}
84
85
//____________________________________________________________________
86
void
VP1QtUtils::setExpertSetting
(
const
QString&
type
,
const
QString& name,
const
QString& content )
87
{
88
if
(name.isEmpty()) {
89
VP1Msg::messageDebug
(
"VP1QtUtils::setEnvironmentVariable WARNING: called with empty variable name!"
);
90
return
;
91
}
92
93
if
(
VP1Msg::verbose
())
94
VP1Msg::messageVerbose
(
"VP1QtUtils::setEnvironmentVariable: Setting variable '"
+name+
"' to value '"
+content+
"'."
);
95
96
if
(
type
==
"general"
){
97
QSettings generalSettings(
"ATLAS"
,
"VP1Light"
);
98
generalSettings.setValue(name, content);
99
}
else
{
100
QSettings expertSettings(QCoreApplication::applicationDirPath()+
"/../vp1.ini"
, QSettings::NativeFormat);
101
expertSettings.setValue(name, content);
102
}
103
}
104
105
106
107
//____________________________________________________________________
108
bool
VP1QtUtils::environmentVariableIsSet
(
const
QString& name)
109
{
110
const
bool
set
= !qgetenv(name.toStdString().c_str()).isNull();
111
if
(
VP1Msg::verbose
())
112
VP1Msg::messageVerbose
(
"VP1QtUtils::environmentVariableIsSet called for variable '"
+name+
"'. Returning "
+
VP1Msg::str
(
set
));
113
return
set
;
114
}
115
116
//____________________________________________________________________
117
QString
VP1QtUtils::environmentVariableValue
(
const
QString& name)
118
{
119
QByteArray env = qgetenv(name.toStdString().c_str());
120
QString val(env.isNull() ?
""
: QString ( env ));
121
if
(
VP1Msg::verbose
())
122
VP1Msg::messageVerbose
(
"VP1QtUtils::environmentVariableValue called for variable '"
+name+
"'. Returning '"
+ val+
"'."
);
123
return
val;
124
}
125
126
//____________________________________________________________________
127
bool
VP1QtUtils::environmentVariableIsOn
(
const
QString& name)
128
{
129
QByteArray env = qgetenv(name.toStdString().c_str());
130
QString val(env.isNull() ?
""
: QString ( env ));
131
bool
ison =
true
;
132
if
(val==
""
||val==
"0"
)
133
ison =
false
;
134
else
if
(0==QString::compare(val,
"false"
,Qt::CaseInsensitive))
135
ison =
false
;
136
else
if
(0==QString::compare(val,
"off"
,Qt::CaseInsensitive))
137
ison =
false
;
138
else
if
(0==QString::compare(val,
"no"
,Qt::CaseInsensitive))
139
ison =
false
;
140
if
(
VP1Msg::verbose
())
141
VP1Msg::messageVerbose
(
"VP1QtUtils::environmentVariableIsOn called for variable '"
+name+
"'. Returning "
+
VP1Msg::str
(ison)+
"."
);
142
return
ison;
143
}
144
145
//____________________________________________________________________
146
void
VP1QtUtils::setEnvironmentVariable
(
const
QString& name,
const
QString& content )
147
{
148
if
(name.isEmpty()) {
149
VP1Msg::messageDebug
(
"VP1QtUtils::setEnvironmentVariable WARNING: called with empty variable name!"
);
150
return
;
151
}
152
153
if
(
VP1Msg::verbose
())
154
VP1Msg::messageVerbose
(
"VP1QtUtils::setEnvironmentVariable: Setting variable '"
+name+
"' to value '"
+content+
"'."
);
155
156
//Don't see any Qt function for this, so we go directly to the stdlib call:
157
::setenv(name.toStdString().c_str(),content.toStdString().c_str(),1
/*override present value*/
);
158
}
159
160
//____________________________________________________________________
161
void
VP1QtUtils::unsetEnvironmentVariable
(
const
QString& name )
162
{
163
if
(name.isEmpty()) {
164
VP1Msg::messageDebug
(
"VP1QtUtils::unsetEnvironmentVariable WARNING: called with empty variable name!"
);
165
return
;
166
}
167
//Don't see any Qt function for this, so we go directly to the stdlib call:
168
169
if
(
VP1Msg::verbose
())
170
VP1Msg::messageVerbose
(
"VP1QtUtils::unsetEnvironmentVariable: Unsetting variable '"
+name+
"'."
);
171
172
::unsetenv(name.toStdString().c_str());
173
}
174
175
//____________________________________________________________________
176
QImage
VP1QtUtils::fadeImage
(QImage img0, QImage img1,
double
fadefact ) {
177
if
(fadefact<0.0||fadefact>1.0||img0.isNull()||img1.isNull()||img0.width()!=img1.width()||img0.height()!=img1.height())
178
return
QImage();
179
if
(fadefact==0)
180
return
img0;
181
if
(fadefact==1)
182
return
img1;
183
QImage img = img0;
184
double
oneminusfadefact(1.0-fadefact);
185
const
int
w(img.width()),
h
(img.height());
186
for
(
int
iw = 0; iw<w; ++iw)
187
for
(
int
ih = 0; ih<
h
; ++ih) {
188
QColor col0(img0.pixel(iw,ih));
189
QColor col1(img1.pixel(iw,ih));
190
img.setPixel ( iw,ih,QColor::fromRgbF(col0.redF()*oneminusfadefact + col1.redF()*fadefact,
191
col0.greenF()*oneminusfadefact + col1.greenF()*fadefact,
192
col0.blueF()*oneminusfadefact + col1.blueF()*fadefact).rgb() );
193
}
194
return
img;
195
}
VP1Msg.h
VP1QtUtils.h
h
Header file for AthHistogramAlgorithm.
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition
VP1Msg.cxx:84
VP1Msg::verbose
static bool verbose()
Definition
VP1Msg.h:31
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition
VP1Msg.cxx:39
VP1QtUtils::environmentVariableIsOn
static bool environmentVariableIsOn(const QString &name)
Definition
VP1QtUtils.cxx:127
VP1QtUtils::setExpertSetting
static void setExpertSetting(const QString &type, const QString &name, const QString &content)
Definition
VP1QtUtils.cxx:86
VP1QtUtils::expertSettingIsSet
static bool expertSettingIsSet(const QString &type, const QString &name)
Definition
VP1QtUtils.cxx:27
VP1QtUtils::fadeImage
static QImage fadeImage(QImage img0, QImage img1, double fadefact)
Definition
VP1QtUtils.cxx:176
VP1QtUtils::expertSettingValue
static QString expertSettingValue(const QString &type, const QString &name)
Definition
VP1QtUtils.cxx:43
VP1QtUtils::environmentVariableIsSet
static bool environmentVariableIsSet(const QString &name)
Definition
VP1QtUtils.cxx:108
VP1QtUtils::environmentVariableValue
static QString environmentVariableValue(const QString &name)
Definition
VP1QtUtils.cxx:117
VP1QtUtils::unsetEnvironmentVariable
static void unsetEnvironmentVariable(const QString &name)
Definition
VP1QtUtils.cxx:161
VP1QtUtils::expertSettingIsOn
static bool expertSettingIsOn(const QString &type, const QString &name)
Definition
VP1QtUtils.cxx:60
VP1QtUtils::setEnvironmentVariable
static void setEnvironmentVariable(const QString &name, const QString &content)
Definition
VP1QtUtils.cxx:146
VP1String::str
static QString str(const QString &s)
Definition
VP1String.h:49
set
STL class.
type
Generated on
for ATLAS Offline Software by
1.17.0