ATLAS Offline Software
VP1GeoDBSelection.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Source file for class VP1GeoDBSelection //
8 // //
9 // Description: Dialog for the selection of a geometry database //
10 // //
11 // Author: Sebastian Andreas Merkt (sebastian.andreas.merkt@cern.ch) //
12 // Initial version: August 2017 //
13 // //
15 
17 
18 #include <QPushButton>
19 #include <QGridLayout>
20 #include <QLabel>
21 #include <QComboBox>
22 #include <QFileInfo>
23 
24 #if __GNUC__ >= 14
25 // suppress warning seen in qfutureinterface.h
26 # pragma GCC diagnostic push
27 # pragma GCC diagnostic ignored "-Wtemplate-id-cdtor"
28 #endif
29 #include <QtWidgets>
30 #if __GNUC__ >= 14
31 # pragma GCC diagnostic pop
32 #endif
33 
35 {
36  //Set default dialog size
37  int nWidth = 800;
38  int nHeight = 220;
39  if (parent != NULL)
40  setGeometry(parent->x() + parent->width()/2 - nWidth/2,
41  parent->y() + parent->height()/2 - nHeight/2,
42  nWidth, nHeight);
43  else
44  resize(nWidth, nHeight);
45 
46  //Browse button to select database
47  m_browseButton = new QPushButton(tr("&Browse..."), this);
48  connect(m_browseButton, &QAbstractButton::clicked, this, &VP1GeoDBSelection::on_browseButton_clicked);
49 
50  //Buttonbox to set Open, Cancel buttons
51  m_buttonBox = new QDialogButtonBox(this);
52  m_openButton = m_buttonBox->addButton(tr("&Open"), QDialogButtonBox::AcceptRole);
53  m_cancelButton = m_buttonBox->addButton(tr("&Cancel"),QDialogButtonBox::RejectRole);
54  connect(m_openButton, &QPushButton::clicked, this, &VP1GeoDBSelection::loadDatabase);
55  connect(m_cancelButton, &QPushButton::clicked, this, &VP1GeoDBSelection::reject);
56 
57  //Open QSettings to store path do database
58  QSettings settings("ATLAS", "VP1Light");
59  QString text;
60 
61  //If no db file has been provided via command line argument, the "db/path" value is ""
62  if(settings.value("db/path").toString()==""){
63  m_openButton->setEnabled(false);
64  text = "(*.db)";
65  } else { //If a db file has been provided show it in the combobox
66  text = settings.value("db/path").toString();
67  }
68  //Create the combobox
70 
71  //Create the main layout
72  QGridLayout *mainLayout = new QGridLayout(this);
73  mainLayout->addWidget(new QLabel(tr("Select Geometry Database:")), 0, 0);
74  mainLayout->addWidget(m_directoryComboBox, 1, 0, 1, 2);
75  mainLayout->addWidget(m_browseButton, 1, 4);
76  mainLayout->addWidget(m_buttonBox, 3, 4);
77 
78  m_browseButton->setMinimumWidth(200);
79  m_buttonBox->setMinimumWidth(200);
80  m_browseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
81  m_buttonBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
82 }
83 
84 //Method to create the drop down combobox
85 QComboBox *VP1GeoDBSelection::createComboBox(const QString &text)
86 {
87  QComboBox *comboBox = new QComboBox;
88  comboBox->setMinimumWidth(600);
89  comboBox->setEditable(false);
90  comboBox->addItem(text);
91  comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
92  return comboBox;
93 }
94 
95 //Animate the click
97 {
98  m_openButton->animateClick();
99 }
100 
101 //Open the file selection dialog
103 {
104  m_fileName = QFileDialog::getOpenFileName(this,
105  tr("Select Database"), QDir::currentPath(),
106  tr("DB Files (*.db)"));
107 
108  // Add the selected file to the combobox
109  if (!m_fileName.isEmpty()) {
110  if (m_directoryComboBox->findText(m_fileName) == -1)
112  m_directoryComboBox->setCurrentIndex(m_directoryComboBox->findText(m_fileName));
113 
114  //When valid a database is selected, enable the Open button to confirm
115  m_openButton->setEnabled(true);
116  }
117 
118 }
119 
120 //Check and Save the settings
122 
123  //Save DB path to settings
124  QSettings settings("ATLAS", "VP1Light");
125  settings.setValue("db/path", m_directoryComboBox->itemText(m_directoryComboBox->currentIndex()));
126 
127  //If the selected DB does not exists, go back
128  if (!QFileInfo::exists(m_directoryComboBox->itemText(m_directoryComboBox->currentIndex()))){
129  QMessageBox msgBox;
130  msgBox.setWindowTitle("Virtual Point 1");
131  msgBox.setText("Database does not exist. Please choose another database file.");
132  msgBox.exec();
133  return;
134  }
135  VP1GeoDBSelection::setResult(1);
137 }
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
VP1GeoDBSelection::m_buttonBox
QDialogButtonBox * m_buttonBox
Definition: VP1GeoDBSelection.h:45
VP1GeoDBSelection.h
VP1GeoDBSelection::createComboBox
QComboBox * createComboBox(const QString &text=QString())
Definition: VP1GeoDBSelection.cxx:85
VP1GeoDBSelection::m_openButton
QPushButton * m_openButton
Definition: VP1GeoDBSelection.h:43
VP1GeoDBSelection::m_browseButton
QPushButton * m_browseButton
Definition: VP1GeoDBSelection.h:42
VP1GeoDBSelection::m_directoryComboBox
QComboBox * m_directoryComboBox
Definition: VP1GeoDBSelection.h:41
VP1GeoDBSelection::m_fileName
QString m_fileName
Definition: VP1GeoDBSelection.h:40
VP1GeoDBSelection::on_browseButton_clicked
void on_browseButton_clicked()
Definition: VP1GeoDBSelection.cxx:102
test_pyathena.parent
parent
Definition: test_pyathena.py:15
VP1GeoDBSelection::loadDatabase
void loadDatabase()
Definition: VP1GeoDBSelection.cxx:121
VP1GeoDBSelection::animateFindClick
void animateFindClick()
Definition: VP1GeoDBSelection.cxx:96
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
VP1GeoDBSelection::m_cancelButton
QPushButton * m_cancelButton
Definition: VP1GeoDBSelection.h:44
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
VP1GeoDBSelection::VP1GeoDBSelection
VP1GeoDBSelection(QWidget *parent=0)
Definition: VP1GeoDBSelection.cxx:34