Signals | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
dbutils::gui::ConfigDataTableModel Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-01/DatabaseUtils/cxx/include/GUI/ConfigDataTableModel.h"

Inheritance diagram for dbutils::gui::ConfigDataTableModel:

Signals

void aChangeWasMade ()
 
void dataWasSaved ()
 

Public Member Functions

 ConfigDataTableModel (const std::string &tableDefinitionFileName, QObject *parent=0)
 
virtual ~ConfigDataTableModel ()
 
virtual int columnCount (const QModelIndex &parent=QModelIndex()) const
 
virtual QVariant data (const QModelIndex &index, int role) const
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const
 
virtual QModelIndex parent (const QModelIndex &index) const
 
virtual int rowCount (const QModelIndex &parent=QModelIndex()) const
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
virtual bool insertRows (int position, int rows, const QModelIndex &parent=QModelIndex())
 
virtual bool removeRows (int position, int rows, const QModelIndex &parent=QModelIndex())
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
 
virtual bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
 
virtual bool loadData (const std::vector< int64_t > &subsystemConfigIdList)
 
virtual bool hasChanges () const
 
virtual bool saveChanges (const int64_t &subsystemConfigId)
 
virtual bool addInitialRow ()
 
virtual bool addRowAfter (const QModelIndex &index)
 
virtual bool deleteRow (const QModelIndex &index)
 
virtual std::string getTableName () const
 

Protected Member Functions

TreeItem_getItem (const QModelIndex &index) const
 
void _getModifiedItems (TreeItem *baseItem, std::vector< TreeItem * > &list) const
 

Private Attributes

boost::shared_ptr< nova::database::Table_dbTablePtr
 
boost::shared_ptr< TreeItem_rootItem
 
std::vector< std::string_dataColumnNames
 
std::vector< std::string_dataColumnTypes
 

Detailed Description

Definition at line 14 of file ConfigDataTableModel.h.

Constructor & Destructor Documentation

dbutils::gui::ConfigDataTableModel::ConfigDataTableModel ( const std::string tableDefinitionFileName,
QObject *  parent = 0 
)

Definition at line 32 of file ConfigDataTableModel.cpp.

References _dbTablePtr, mkDefs::detName, novadaq::EnvVarCache::getEnvVar(), novadaq::EnvVarCache::getInstance(), and string.

34  : QAbstractItemModel(parent)
35 {
36  _dbTablePtr.reset(new NOVADB::Table(tableDefinitionFileName.c_str()));
38  novadaq::EnvVarCache::getInstance().getEnvVar("NOVADAQ_ENVIRONMENT");
39  _dbTablePtr->SetDetector(detName);
40 
41  std::string dbUser =
42  novadaq::EnvVarCache::getInstance().getEnvVar("CFGMGR_DB_USER");
43  if (dbUser.length() > 0) {
44  _dbTablePtr->SetUser(dbUser);
45  }
46 }
static EnvVarCache & getInstance()
Definition: EnvVarCache.cpp:12
virtual QModelIndex parent(const QModelIndex &index) const
boost::shared_ptr< nova::database::Table > _dbTablePtr
std::string getEnvVar(std::string name)
Definition: EnvVarCache.cpp:33
detName
Definition: mkDefs.py:106
enum BeamMode string
virtual dbutils::gui::ConfigDataTableModel::~ConfigDataTableModel ( )
inlinevirtual

Member Function Documentation

TreeItem * dbutils::gui::ConfigDataTableModel::_getItem ( const QModelIndex &  index) const
protected

Definition at line 487 of file ConfigDataTableModel.cpp.

References _rootItem.

Referenced by addRowAfter(), data(), deleteRow(), index(), insertRows(), parent(), removeRows(), rowCount(), setData(), and ~ConfigDataTableModel().

488 {
489  if (index.isValid()) {
490  TreeItem* item = static_cast<TreeItem*>(index.internalPointer());
491  if (item) return item;
492  }
493  return _rootItem.get();
494 }
boost::shared_ptr< TreeItem > _rootItem
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void dbutils::gui::ConfigDataTableModel::_getModifiedItems ( TreeItem baseItem,
std::vector< TreeItem * > &  list 
) const
protected

Definition at line 496 of file ConfigDataTableModel.cpp.

References dbutils::gui::TreeItem::child(), dbutils::gui::TreeItem::childCount(), compare_h5_caf::idx, dbutils::gui::TreeItem::isDirty(), and dbutils::gui::TreeItem::isNew().

Referenced by ~ConfigDataTableModel().

498 {
499  // add this item to the list if it has been modified
500  if (baseItem->isDirty() || baseItem->isNew()) {list.push_back(baseItem);}
501 
502  // loop over children, if any
503  for (int idx = 0; idx < baseItem->childCount(); ++idx) {
504  TreeItem* childItem = baseItem->child(idx);
505  this->_getModifiedItems(childItem, list);
506  }
507 }
void _getModifiedItems(TreeItem *baseItem, std::vector< TreeItem * > &list) const
void dbutils::gui::ConfigDataTableModel::aChangeWasMade ( )
signal
bool dbutils::gui::ConfigDataTableModel::addInitialRow ( )
virtual

Definition at line 400 of file ConfigDataTableModel.cpp.

References _rootItem, aChangeWasMade(), addRowAfter(), index(), dbutils::gui::TreeItem::markNew(), and fabricate::status.

Referenced by dbutils::gui::ConfigDataTableEditor::addInitialRow(), dbutils::gui::ConfigDataTableEditor::addRow(), and ~ConfigDataTableModel().

401 {
402  QModelIndex parentIndex = this->index(0, 0);
403  beginInsertRows(parentIndex, 0, 0);
404 
405  bool status = _rootItem->insertChildren(0, 1, _rootItem->columnCount());
406  if (status) {
407  TreeItem* childItem = _rootItem->child(0);
408  childItem->markNew();
409  emit aChangeWasMade();
410  }
411 
412  endInsertRows();
413 
414  return status;
415 }
int status
Definition: fabricate.py:1613
boost::shared_ptr< TreeItem > _rootItem
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
bool dbutils::gui::ConfigDataTableModel::addRowAfter ( const QModelIndex &  index)
virtual

Definition at line 418 of file ConfigDataTableModel.cpp.

References _getItem(), _rootItem, aChangeWasMade(), dbutils::gui::TreeItem::childNumber(), dbutils::gui::TreeItem::columnCount(), dbutils::gui::TreeItem::data(), deleteRow(), compare_h5_caf::idx, index(), dbutils::gui::TreeItem::insertChildren(), dbutils::gui::TreeItem::markNew(), parent(), dbutils::gui::TreeItem::setData(), and fabricate::status.

Referenced by addInitialRow(), dbutils::gui::ConfigDataTableEditor::addRow(), and ~ConfigDataTableModel().

419 {
420  if (! baseIndex.isValid()) {return false;}
421 
422  TreeItem *baseItem = this->_getItem(baseIndex);
423  int baseOffset = baseItem->childNumber();
424  int position = baseOffset + 1;
425 
426  QModelIndex parentIndex = this->parent(baseIndex);
427  TreeItem *parentItem = this->_getItem(parentIndex);
428 
429  beginInsertRows(parentIndex, position, position);
430 
431  bool status = parentItem->insertChildren(position, 1,
432  _rootItem->columnCount());
433  if (status) {
434  QModelIndex childIndex = this->index(position, 0, parentIndex);
435  if (childIndex.isValid()) {
436  TreeItem* childItem = this->_getItem(childIndex);
437 
438  for (int idx = 0; idx < parentItem->columnCount(); ++idx) {
439  childItem->setData(idx, baseItem->data(idx));
440  }
441 
442  childItem->markNew();
443  }
444  emit aChangeWasMade();
445  }
446 
447  endInsertRows();
448 
449  return status;
450 }
TreeItem * _getItem(const QModelIndex &index) const
int status
Definition: fabricate.py:1613
boost::shared_ptr< TreeItem > _rootItem
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual QModelIndex parent(const QModelIndex &index) const
int dbutils::gui::ConfigDataTableModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 55 of file ConfigDataTableModel.cpp.

References _rootItem.

Referenced by ~ConfigDataTableModel().

56 {
57  return _rootItem->columnCount();
58 }
boost::shared_ptr< TreeItem > _rootItem
QVariant dbutils::gui::ConfigDataTableModel::data ( const QModelIndex &  index,
int  role 
) const
virtual

Definition at line 60 of file ConfigDataTableModel.cpp.

References _getItem(), dbutils::gui::TreeItem::data(), dbutils::gui::TreeItem::isDirty(), dbutils::gui::TreeItem::isNew(), and rootlogon::yellow.

Referenced by ~ConfigDataTableModel().

61 {
62  if (!index.isValid()) {return QVariant();}
63  //std::cout << "Role = " << role << std::endl;
64 
65  if (role == Qt::BackgroundRole) {
66  TreeItem *item = _getItem(index);
67  if (item->isDirty() || item->isNew()) {
68  QColor yellow("yellow");
69  QBrush brush(yellow);
70  return brush;
71  }
72  }
73 
74  if (role != Qt::DisplayRole && role != Qt::EditRole)
75  return QVariant();
76 
77  TreeItem *item = _getItem(index);
78 
79  return item->data(index.column());
80 }
TreeItem * _getItem(const QModelIndex &index) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
tuple yellow
Definition: rootlogon.py:67
void dbutils::gui::ConfigDataTableModel::dataWasSaved ( )
signal
bool dbutils::gui::ConfigDataTableModel::deleteRow ( const QModelIndex &  index)
virtual

Definition at line 453 of file ConfigDataTableModel.cpp.

References _getItem(), _rootItem, aChangeWasMade(), dbutils::gui::TreeItem::childNumber(), parent(), dbutils::gui::TreeItem::removeChildren(), and fabricate::status.

Referenced by addRowAfter(), dbutils::gui::ConfigDataTableEditor::deleteRow(), and ~ConfigDataTableModel().

454 {
455  if (! baseIndex.isValid()) {return false;}
456 
457  TreeItem *baseItem = this->_getItem(baseIndex);
458  int baseOffset = baseItem->childNumber();
459  int position = baseOffset;
460 
461  QModelIndex parentIndex = this->parent(baseIndex);
462  TreeItem *parentItem = this->_getItem(parentIndex);
463 
464  beginRemoveRows(parentIndex, position, position);
465 
466  bool status = parentItem->removeChildren(position, 1);
467  if (status) {
468  _rootItem->markDirty();
469  emit aChangeWasMade();
470  }
471 
472  endRemoveRows();
473 
474  return status;
475 }
TreeItem * _getItem(const QModelIndex &index) const
int status
Definition: fabricate.py:1613
boost::shared_ptr< TreeItem > _rootItem
virtual QModelIndex parent(const QModelIndex &index) const
Qt::ItemFlags dbutils::gui::ConfigDataTableModel::flags ( const QModelIndex &  index) const
virtual

Definition at line 124 of file ConfigDataTableModel.cpp.

References headerData().

Referenced by ~ConfigDataTableModel().

125 {
126  if (!index.isValid())
127  return 0;
128 
129  return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
130 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
std::string dbutils::gui::ConfigDataTableModel::getTableName ( ) const
virtual

Definition at line 477 of file ConfigDataTableModel.cpp.

References _dbTablePtr.

Referenced by dbutils::gui::ConfigDataTableEditor::getTableName(), and ~ConfigDataTableModel().

478 {
479  return _dbTablePtr->Name();
480 }
boost::shared_ptr< nova::database::Table > _dbTablePtr
bool dbutils::gui::ConfigDataTableModel::hasChanges ( ) const
virtual

Definition at line 316 of file ConfigDataTableModel.cpp.

References _rootItem, compare_h5_caf::idx, dbutils::gui::TreeItem::isDirty(), and dbutils::gui::TreeItem::isNew().

Referenced by dbutils::gui::ConfigDataTableEditor::hasChanges(), and ~ConfigDataTableModel().

317 {
318  if (_rootItem->isDirty()) {return true;}
319 
320  // loop over children, if any
321  for (int idx = 0; idx < _rootItem->childCount(); ++idx) {
322  TreeItem* childItem = _rootItem->child(idx);
323  if (childItem->isDirty() || childItem->isNew()) {return true;}
324  }
325 
326  return false;
327 }
boost::shared_ptr< TreeItem > _rootItem
QVariant dbutils::gui::ConfigDataTableModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
virtual

Definition at line 133 of file ConfigDataTableModel.cpp.

References _rootItem.

Referenced by flags(), and ~ConfigDataTableModel().

134 {
135  if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
136  return _rootItem->data(section);
137 
138  return QVariant();
139 }
boost::shared_ptr< TreeItem > _rootItem
QModelIndex dbutils::gui::ConfigDataTableModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
virtual

Definition at line 82 of file ConfigDataTableModel.cpp.

References _getItem(), and dbutils::gui::TreeItem::child().

Referenced by addInitialRow(), addRowAfter(), loadData(), setData(), and ~ConfigDataTableModel().

84 {
85  if (parent.isValid() && parent.column() != 0) {
86  return QModelIndex();
87  }
88 
89  TreeItem *parentItem = _getItem(parent);
90 
91  TreeItem *childItem = parentItem->child(row);
92  if (childItem)
93  return createIndex(row, column, childItem);
94  else
95  return QModelIndex();
96 }
TreeItem * _getItem(const QModelIndex &index) const
virtual QModelIndex parent(const QModelIndex &index) const
bool dbutils::gui::ConfigDataTableModel::insertRows ( int  position,
int  rows,
const QModelIndex &  parent = QModelIndex() 
)
virtual

Definition at line 141 of file ConfigDataTableModel.cpp.

References _getItem(), _rootItem, aChangeWasMade(), dbutils::gui::TreeItem::insertChildren(), and fabricate::status.

Referenced by loadData(), and ~ConfigDataTableModel().

142 {
143  TreeItem *parentItem = _getItem(parent);
144 
145  beginInsertRows(parent, position, position + rows - 1);
146 
147  bool status = parentItem->insertChildren(position, rows,
148  _rootItem->columnCount());
149  if (status) {
150  emit aChangeWasMade();
151  }
152 
153  endInsertRows();
154 
155  return status;
156 }
TreeItem * _getItem(const QModelIndex &index) const
int status
Definition: fabricate.py:1613
boost::shared_ptr< TreeItem > _rootItem
virtual QModelIndex parent(const QModelIndex &index) const
bool dbutils::gui::ConfigDataTableModel::loadData ( const std::vector< int64_t > &  subsystemConfigIdList)
virtual

Definition at line 223 of file ConfigDataTableModel.cpp.

References _dataColumnNames, _dataColumnTypes, _dbTablePtr, _rootItem, nova::database::Row::Col(), novadaq::HexUtils::format(), nova::database::Column::Get(), index(), insertRows(), nova::database::Column::IsNull(), removeRows(), dbutils::gui::TreeItem::setData(), string, and nova::database::Column::Type().

Referenced by dbutils::gui::ConfigDataTableEditor::loadData(), setHeaderData(), and ~ConfigDataTableModel().

224 {
225  if (! _dbTablePtr->GetConnection()) {return false;}
226  if (! _dbTablePtr->ExistsInDB()) {return false;}
227 
228  // populate the root item with the DB table column names
229  _dataColumnNames.clear();
230  _dataColumnTypes.clear();
231  QVector<QVariant> rootData;
232  std::vector<std::string> columnNames = _dbTablePtr->GetColNames();
233  foreach (std::string colName, columnNames) {
234  if (DBColumnUtils::isInfrastructureColumn(colName)) {
235  continue;
236  }
237  if (DBColumnUtils::
238  isSubsystemConfigReferenceColumn(colName)) {
239  continue;
240  }
241 
242  _dataColumnNames.push_back(colName);
243  QString tmpQString(colName.c_str());
244  rootData << tmpQString;
245  _dataColumnTypes.push_back("unknown");
246  }
247 
248  if (_rootItem.get() != 0) {
249  QModelIndex dummyIndex;
250  this->removeRows(0, _rootItem->childCount(), dummyIndex);
251  }
252  _rootItem.reset(new TreeItem(rootData));
253  QModelIndex rootIndex = this->index(0, 0);
254 
255  // find the relevant DB entries and populate the rest of the data model
256  for (uint32_t cfgIdx = 0; cfgIdx<subsystemConfigIdList.size(); ++cfgIdx) {
257  _dbTablePtr->Clear();
258  _dbTablePtr->SetValidityRange(NamedConfigUtils::SUBSYSCFGID_COLUMN_NAME,
259  subsystemConfigIdList[cfgIdx]);
260  if (! _dbTablePtr->LoadFromDB()) {return false;}
261 
262  if (_dbTablePtr->NRow() > 0) {
263  int initialRowCount = _dbTablePtr->NRow();
264  insertRows(0, initialRowCount, rootIndex);
265 
266  for (int iRow = 0; iRow < initialRowCount; ++iRow) {
267  NOVADB::Row* rowPtr = _dbTablePtr->GetRow(iRow);
268 
269  // add the requested item
270  TreeItem* newItem = _rootItem->child(iRow);
271 
272  for (uint32_t iCol=0; iCol<_dataColumnNames.size(); ++iCol) {
273  std::string colName =
274  boost::to_lower_copy(_dataColumnNames[iCol]);
275 
277  NOVADB::Column* colPtr = rowPtr->Col(colName);
278  if (colPtr->IsNull()) {continue;}
279  if (! colPtr->Get(value)) {return false;}
280  std::string colType = colPtr->Type();
281  _dataColumnTypes[iCol] = colType;
282 
283  if (colType == "bool" || colType == "boolean") {
284  if (value == "t" || value == "1") {
285  value = "true";
286  }
287  else {
288  value = "false";
289  }
290  }
291 
292  if (colName == "mask") {
293  try {
294  if (colType == "bigint") {
295  value = novadaq::HexUtils::format(value, 16);
296  }
297  else {
298  value = novadaq::HexUtils::format(value, 8);
299  }
300  }
301  catch (...) {}
302  }
303 
304  newItem->setData(iCol, QVariant(value.c_str()));
305  }
306  }
307  }
308 
309  break; // TODO - handle a single subsysCfgId better
310  }
311 
312  _dbTablePtr->CloseConnection();
313  return true;
314 }
std::vector< std::string > _dataColumnNames
boost::shared_ptr< TreeItem > _rootItem
std::vector< std::string > _dataColumnTypes
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual bool removeRows(int position, int rows, const QModelIndex &parent=QModelIndex())
const XML_Char int const XML_Char * value
Definition: expat.h:331
virtual bool insertRows(int position, int rows, const QModelIndex &parent=QModelIndex())
bool Get(T &val) const
Definition: Column.h:53
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
boost::shared_ptr< nova::database::Table > _dbTablePtr
bool IsNull() const
Definition: Column.h:39
std::string Type() const
Definition: Column.h:36
Column & Col(int i)
Definition: Row.h:51
enum BeamMode string
QModelIndex dbutils::gui::ConfigDataTableModel::parent ( const QModelIndex &  index) const
virtual

Definition at line 98 of file ConfigDataTableModel.cpp.

References _getItem(), _rootItem, dbutils::gui::TreeItem::childNumber(), and dbutils::gui::TreeItem::parent().

Referenced by addRowAfter(), deleteRow(), and ~ConfigDataTableModel().

99 {
100  if (!index.isValid()) {return QModelIndex();}
101 
102  TreeItem *childItem = _getItem(index);
103  TreeItem *parentItem = childItem->parent();
104 
105  if (parentItem == _rootItem.get())
106  return QModelIndex();
107 
108  return createIndex(parentItem->childNumber(), 0, parentItem);
109 }
TreeItem * _getItem(const QModelIndex &index) const
boost::shared_ptr< TreeItem > _rootItem
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
bool dbutils::gui::ConfigDataTableModel::removeRows ( int  position,
int  rows,
const QModelIndex &  parent = QModelIndex() 
)
virtual

Definition at line 158 of file ConfigDataTableModel.cpp.

References _getItem(), aChangeWasMade(), dbutils::gui::TreeItem::removeChildren(), and fabricate::status.

Referenced by loadData(), setData(), and ~ConfigDataTableModel().

159 {
160  TreeItem *parentItem = _getItem(parent);
161 
162  beginRemoveRows(parent, position, position + rows - 1);
163 
164  bool status = parentItem->removeChildren(position, rows);
165  if (status) {
166  emit aChangeWasMade();
167  }
168 
169  endRemoveRows();
170 
171  return status;
172 }
TreeItem * _getItem(const QModelIndex &index) const
int status
Definition: fabricate.py:1613
virtual QModelIndex parent(const QModelIndex &index) const
int dbutils::gui::ConfigDataTableModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

Definition at line 111 of file ConfigDataTableModel.cpp.

References _getItem(), and dbutils::gui::TreeItem::childCount().

Referenced by dbutils::gui::ConfigDataTableEditor::addInitialRow(), and ~ConfigDataTableModel().

112 {
113  TreeItem *parentItem = _getItem(parent);
114 
115  return parentItem->childCount();
116 }
TreeItem * _getItem(const QModelIndex &index) const
virtual QModelIndex parent(const QModelIndex &index) const
bool dbutils::gui::ConfigDataTableModel::saveChanges ( const int64_t &  subsystemConfigId)
virtual

Definition at line 329 of file ConfigDataTableModel.cpp.

References _dataColumnNames, _dataColumnTypes, _dbTablePtr, _rootItem, dbutils::gui::TreeItem::data(), dataWasSaved(), compare_h5_caf::idx, dbutils::gui::TreeItem::markClean(), dbutils::gui::TreeItem::markOld(), and string.

Referenced by dbutils::gui::ConfigDataTableEditor::saveChanges(), and ~ConfigDataTableModel().

330 {
331  if (! _dbTablePtr->GetConnection()) {return false;}
332  if (! _dbTablePtr->ExistsInDB()) {return false;}
333  _dbTablePtr->SetVerbosity(1);
334 
335  for (int idx = 0; idx < _rootItem->childCount(); ++idx) {
336  TreeItem* childItem = _rootItem->child(idx);
337 
338  boost::shared_ptr<NOVADB::Row> newRow(_dbTablePtr->NewRow());
339  newRow->Set(NamedConfigUtils::SUBSYSCFGID_COLUMN_NAME,
340  subsystemConfigId);
341 
342  for (uint32_t iCol = 0; iCol < _dataColumnNames.size(); ++iCol) {
343  std::string colName = boost::to_lower_copy(_dataColumnNames[iCol]);
344  std::string colType = boost::to_lower_copy(_dataColumnTypes[iCol]);
345 
346  std::string value = childItem->data(iCol).toString().toStdString();
347 
348  if (value.find("0x") != std::string::npos) {
349  try {
350  if (colType == "bigint") {
351  std::istringstream iss(value);
352  uint64_t u64Value;
353  iss >> std::hex >> u64Value;
354  int64_t i64Value = (int64_t) u64Value;
355  value = boost::lexical_cast<std::string>(i64Value);
356  }
357  else if (colType == "integer" || colType == "int") {
358  std::istringstream iss(value);
359  uint32_t u32Value;
360  iss >> std::hex >> u32Value;
361  int32_t i32Value = (int32_t) u32Value;
362  value = boost::lexical_cast<std::string>(i32Value);
363  }
364  }
365  catch (...) {}
366  }
367 
368  if (colType == "bool" || colType == "boolean") {
369  std::string valueCopy = boost::to_lower_copy(value);
370  if (valueCopy == "t" || valueCopy == "true" || valueCopy == "1") {
371  newRow->Set(colName, true);
372  }
373  else {
374  newRow->Set(colName, false);
375  }
376  }
377  else {
378  newRow->Set(colName, value);
379  }
380  }
381 
382  _dbTablePtr->AddRow(newRow.get());
383  }
384 
385  if (! _dbTablePtr->WriteToDB()) {return false;}
386 
387  _rootItem->markClean();
388  for (int idx = 0; idx < _rootItem->childCount(); ++idx) {
389  TreeItem* childItem = _rootItem->child(idx);
390  childItem->markClean();
391  childItem->markOld();
392  }
393  emit dataWasSaved();
394 
395  _dbTablePtr->CloseConnection();
396 
397  return true;
398 }
std::vector< std::string > _dataColumnNames
boost::shared_ptr< TreeItem > _rootItem
std::vector< std::string > _dataColumnTypes
const XML_Char int const XML_Char * value
Definition: expat.h:331
boost::shared_ptr< nova::database::Table > _dbTablePtr
enum BeamMode string
bool dbutils::gui::ConfigDataTableModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Definition at line 174 of file ConfigDataTableModel.cpp.

References _getItem(), aChangeWasMade(), dbutils::gui::TreeItem::childCount(), dbutils::gui::TreeItem::data(), index(), dbutils::gui::TreeItem::markDirty(), removeRows(), fillBadChanDBTables::result, and dbutils::gui::TreeItem::setData().

Referenced by ~ConfigDataTableModel().

177 {
178  if (role != Qt::EditRole)
179  return false;
180 
181  TreeItem *item = _getItem(index);
182  QVariant oldValue = item->data(index.column());
183  if (value == oldValue) {
184  return false;
185  }
186 
187  bool result = item->setData(index.column(), value);
188 
189  if (result) {
190  item->markDirty();
191 
192  if (item->childCount() > 0) {
193  this->removeRows(0, item->childCount(), index);
194  }
195 
196  emit dataChanged(index, index);
197  emit aChangeWasMade();
198  }
199 
200  return result;
201 }
TreeItem * _getItem(const QModelIndex &index) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual bool removeRows(int position, int rows, const QModelIndex &parent=QModelIndex())
const XML_Char int const XML_Char * value
Definition: expat.h:331
bool dbutils::gui::ConfigDataTableModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant &  value,
int  role = Qt::EditRole 
)
virtual

Definition at line 203 of file ConfigDataTableModel.cpp.

References _rootItem, loadData(), and fillBadChanDBTables::result.

Referenced by ~ConfigDataTableModel().

205 {
206  if (role != Qt::EditRole || orientation != Qt::Horizontal)
207  return false;
208 
209  bool result = _rootItem->setData(section, value);
210 
211  if (result)
212  emit headerDataChanged(orientation, section, section);
213 
214  return result;
215 }
boost::shared_ptr< TreeItem > _rootItem
const XML_Char int const XML_Char * value
Definition: expat.h:331

Member Data Documentation

std::vector<std::string> dbutils::gui::ConfigDataTableModel::_dataColumnNames
private

Definition at line 89 of file ConfigDataTableModel.h.

Referenced by loadData(), and saveChanges().

std::vector<std::string> dbutils::gui::ConfigDataTableModel::_dataColumnTypes
private

Definition at line 90 of file ConfigDataTableModel.h.

Referenced by loadData(), and saveChanges().

boost::shared_ptr<nova::database::Table> dbutils::gui::ConfigDataTableModel::_dbTablePtr
private

Definition at line 87 of file ConfigDataTableModel.h.

Referenced by ConfigDataTableModel(), getTableName(), loadData(), and saveChanges().

boost::shared_ptr<TreeItem> dbutils::gui::ConfigDataTableModel::_rootItem
private

The documentation for this class was generated from the following files: