TabbedSetOfTableEditors.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/GUI/TabbedSetOfTableEditors.h>
2 #include <DatabaseUtils/GUI/ConfigDataTableEditor.h>
3 #include <DatabaseUtils/GUI/CustomTabBehaviors.h>
4 #include <DatabaseUtils/DAQConfig/NamedConfigUtils.h>
5 #include <QtGui/QProgressDialog>
6 
7 using namespace dbutils::daqconfig;
8 
9 namespace dbutils {
10 namespace gui {
11 
12 TabbedSetOfTableEditors::
13 TabbedSetOfTableEditors(const std::string& subsystemName,
14  const std::string& configType,
15  const std::vector<std::string>& tableDefinitionList,
16  QWidget *parent) : QTabWidget(parent),
17  _isTopLevel(false)
18 {
19  _subsystemName = subsystemName;
20  _configType = configType;
21  _tableDefinitionList = tableDefinitionList;
22 
23  for (uint32_t idx = 0; idx < _tableDefinitionList.size(); ++idx) {
25  ConfigDataTableEditor* editor =
26  new ConfigDataTableEditor(filename, this);
27  this->addTab(editor, editor->getTableName().c_str());
28 
29  connect(editor, SIGNAL(aChangeWasMade()),
30  this, SLOT(reactToEditorDataChange()));
31  connect(editor, SIGNAL(dataWasSaved()),
32  this, SLOT(reactToDataSave()));
33  }
34 }
35 
38 {
39  if (idSpec.getConfigId() == -1) {return false;}
40 
41  boost::shared_ptr<QProgressDialog> progressBar;
42  if (_isTopLevel) {
43  progressBar.reset(new QProgressDialog("Loading data...", "Close", 0,
44  this->count(), this));
45  progressBar->setWindowModality(Qt::WindowModal);
46  progressBar->setMinimumDuration(250);
47  }
48 
49  std::vector<int64_t> subsystemConfigIdList;
50  if (! NamedConfigUtils::
51  getSubsystemConfigIdAncestryFromGlobalId(idSpec,
54  subsystemConfigIdList)) {
55  return false;
56  }
57 
58  bool status = true;
59  for (int idx = 0; idx < this->count(); ++idx) {
60  if (_isTopLevel) {progressBar->setValue(idx);}
61  QWidget* theWidget = widget(idx);
62  ConfigDataTableEditor* editor =
63  static_cast<ConfigDataTableEditor*>(theWidget);
64  if (! editor->loadData(subsystemConfigIdList)) {status = false;}
65  this->setTabText(idx, editor->getTableName().c_str());
66  }
67  if (_isTopLevel) {progressBar->setValue(this->count());}
68 
69  return status;
70 }
71 
73 {
74  for (int idx = 0; idx < this->count(); ++idx) {
75  QWidget* theWidget = widget(idx);
76  ConfigDataTableEditor* editor =
77  static_cast<ConfigDataTableEditor*>(theWidget);
78  if (editor->hasChanges()) {return true;}
79  }
80  return false;
81 }
82 
84 saveChanges(const dbutils::daqconfig::IDSpec& oldGlobalIdSpec,
85  const dbutils::daqconfig::IDSpec& newGlobalIdSpec,
86  const dbutils::daqconfig::GlobalNameSpec& newGlobalNameSpec)
87 {
88  if (! this->hasChanges()) {return true;}
89 
90  boost::shared_ptr<QProgressDialog> progressBar;
91  if (_isTopLevel) {
92  progressBar.reset(new QProgressDialog("Loading data...", "Close", 0,
93  this->count(), this));
94  progressBar->setWindowModality(Qt::WindowModal);
95  progressBar->setMinimumDuration(250);
96  }
97 
98  // ** create the new subsystem named configuration ***
99  std::vector<int64_t> existingSubystemConfigIdList;
100  if (! NamedConfigUtils::
101  getSubsystemConfigIdAncestryFromGlobalId(oldGlobalIdSpec,
103  existingSubystemConfigIdList)) {
104  std::cerr << "ERROR: unable to fetch the existing named subsystem "
105  << "configurations." << std::endl;
106  return false;
107  }
108  int64_t oldSubsystemConfigId = existingSubystemConfigIdList[0];
109  IDSpec oldSubsystemIdSpec(oldSubsystemConfigId, IDSpec::SUBSYSTEM,
110  (oldGlobalIdSpec.isDAQConfiguration() ?
111  IDSpec::DAQ : IDSpec::SLOWCONTROLS));
112 
114  if (newGlobalNameSpec.getConfigName() != "InitialGlobalConfig" &&
115  newGlobalNameSpec.getConfigName() != "ColdDetectorSettings") {
116  std::string newName = newGlobalNameSpec.getConfigName() + "_" +
117  _subsystemName + "_" + _configType;
118  paramSet.put(NamedConfigUtils::NAME_COLUMN_NAME, newName);
119  }
120  paramSet.put(NamedConfigUtils::DCMOPMODE_COLUMN_NAME,
121  newGlobalNameSpec.getDCMOpMode());
122  paramSet.put(NamedConfigUtils::DESCRIPTION_COLUMN_NAME,
123  "New values from the Configuration Editor GUI.");
124  paramSet.put(NamedConfigUtils::GLOBALCFGID_COLUMN_NAME,
125  boost::lexical_cast<std::string>
126  (newGlobalIdSpec.getConfigId()));
127  int64_t subsystemConfigId;
128  novadaq::Status resultStatus =
129  NamedConfigUtils::copySubsystemConfig(oldSubsystemIdSpec, true,
130  paramSet, "", true,
131  subsystemConfigId);
132  if (resultStatus.code ==
133  NamedConfigUtils::COPY_FOUND_UPDATE_IN_PROGRESS) {
134  std::cerr << "Unable to create a copy of the named "
135  << "subsystem configuration with ID = "
136  << oldSubsystemConfigId
137  << ": the creation of a new configuration is "
138  << "already in progress ("
139  << resultStatus.message << ")"
140  << std::endl;
141  return false;
142  }
143  else if (resultStatus.code ==
144  NamedConfigUtils::COPY_FOUND_INTERMEDIATE_UPDATE) {
145  std::cerr << "Unable to create a copy of the named "
146  << "subsystem configuration with ID = "
147  << oldSubsystemConfigId
148  << ": intermediate changes would be overwritten by "
149  << "this change (" << resultStatus.message << ")"
150  << std::endl;
151  return false;
152  }
153  else if (resultStatus.code != NamedConfigUtils::COPY_SUCCEEDED) {
154  std::cerr << "Unable to create a copy of the named "
155  << "subsystem configuration with ID = "
156  << oldSubsystemConfigId
157  << ": " << resultStatus.message
158  << std::endl;
159  return false;
160  }
161 
162  bool status = true;
163  for (int idx = 0; idx < this->count(); ++idx) {
164  if (_isTopLevel) {progressBar->setValue(idx);}
165  QWidget* theWidget = widget(idx);
166  ConfigDataTableEditor* editor =
167  static_cast<ConfigDataTableEditor*>(theWidget);
168  if (! editor->saveChanges(oldSubsystemConfigId, subsystemConfigId)) {
169  status = false;
170  }
171  }
172 
173  IDSpec subsystemIdSpec(subsystemConfigId, IDSpec::SUBSYSTEM,
174  (oldGlobalIdSpec.isDAQConfiguration() ?
175  IDSpec::DAQ : IDSpec::SLOWCONTROLS));
176  if (status) {
177  NamedConfigUtils::markConfigDone(subsystemIdSpec, true);
178  }
179  else {
180  NamedConfigUtils::markConfigDone(subsystemIdSpec, false);
181  }
182  if (_isTopLevel) {progressBar->setValue(this->count());}
183 
184  return status;
185 }
186 
188 {
189  bool status = true;
190  for (int idx = 0; idx < this->count(); ++idx) {
191  QWidget* theWidget = widget(idx);
192  ConfigDataTableEditor* editor =
193  static_cast<ConfigDataTableEditor*>(theWidget);
194  if (! editor->addInitialRow()) {status = false;}
195  }
196  return status;
197 }
198 
200 {
201  CustomTabBehaviors::updateTabTextColors(this, this->tabBar());
202  emit aChangeWasMade();
203 }
204 
206 {
207  CustomTabBehaviors::updateTabTextColors(this, this->tabBar());
208  emit dataWasSaved();
209 }
210 
211 } // end of namespace gui
212 } // end of namespace dbutils
bool saveChanges(const int64_t &oldSubsystemConfigId, const int64_t &subsystemConfigId)
def progressBar(value, endvalue, docdb_id, bar_length=40)
Definition: bp_utils.py:6
int status
Definition: fabricate.py:1613
int64_t getConfigId() const
Definition: IDSpec.h:36
void put(const std::string &key, const std::string &value)
int32_t code
Definition: Status.h:22
OStream cerr
Definition: OStream.cxx:7
bool loadData(const dbutils::daqconfig::IDSpec &idSpec)
string filename
Definition: shutoffs.py:106
bool loadData(const std::vector< int64_t > &subsystemConfigIdList)
bool saveChanges(const dbutils::daqconfig::IDSpec &oldGlobalIdSpec, const dbutils::daqconfig::IDSpec &newGlobalIdSpec, const dbutils::daqconfig::GlobalNameSpec &newGlobalNameSpec)
void updateTabTextColors(QTabWidget *tabWidget, QTabBar *tabBar)
def connect(endpoint="tcp://127.0.0.1:5555")
Definition: g4zmq.py:15
std::string getDCMOpMode() const
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::string message
Definition: Status.h:24
std::string getConfigName() const
std::vector< std::string > _tableDefinitionList
bool isDAQConfiguration() const
Definition: IDSpec.h:41