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