CustomTabWidget.cpp
Go to the documentation of this file.
1 #include <DatabaseUtils/GUI/CustomTabWidget.h>
2 #include <DatabaseUtils/GUI/CustomTabBehaviors.h>
3 #include <DatabaseUtils/GUI/Changeable.h>
4 #include <DatabaseUtils/GUI/Storeable.h>
5 #include <boost/shared_ptr.hpp>
6 #include <QtGui/QProgressDialog>
7 #include <QtGui/QTabBar>
8 
9 namespace dbutils {
10 namespace gui {
11 
13 CustomTabWidget(QWidget *parent) : QTabWidget(parent), _isTopLevel(false)
14 {
15 }
16 
17 int CustomTabWidget::addTab(QWidget* page, const QString& label)
18 {
19  connect(page, SIGNAL(aChangeWasMade()), this, SLOT(reactToDataChange()));
20  connect(page, SIGNAL(dataWasSaved()), this, SLOT(reactToDataSave()));
21 
22  return QTabWidget::addTab(page, label);
23 }
24 
26 {
27  bool status = true;
28 
29  boost::shared_ptr<QProgressDialog> progressBar;
30  if (_isTopLevel) {
31  progressBar.reset(new QProgressDialog("Loading data...", "Close", 0,
32  this->count(), this));
33  progressBar->setWindowModality(Qt::WindowModal);
34  progressBar->setMinimumDuration(250);
35  }
36 
37  for (int idx = 0; idx < this->count(); ++idx) {
38  if (_isTopLevel) {progressBar->setValue(idx);}
39  QWidget* theWidget = widget(idx);
40  Storeable* storeableObject = dynamic_cast<Storeable*>(theWidget);
41  if (! storeableObject->loadData(idSpec)) {status = false;}
42  }
43  if (_isTopLevel) {progressBar->setValue(this->count());}
44 
45  return status;
46 }
47 
49 {
50  for (int idx = 0; idx < this->count(); ++idx) {
51  QWidget* theWidget = widget(idx);
52  Changeable* changeableObject = dynamic_cast<Changeable*>(theWidget);
53  if (changeableObject->hasChanges()) {return true;}
54  }
55  return false;
56 }
57 
59 {
60  bool status = true;
61  for (int idx = 0; idx < this->count(); ++idx) {
62  QWidget* theWidget = widget(idx);
63  Changeable* changeableObject = dynamic_cast<Changeable*>(theWidget);
64  if (! changeableObject->addInitialRow()) {status = false;}
65  }
66  return status;
67 }
68 
70 saveChanges(const dbutils::daqconfig::IDSpec& oldGlobalIdSpec,
71  const dbutils::daqconfig::IDSpec& newGlobalIdSpec,
72  const dbutils::daqconfig::GlobalNameSpec& newGlobalNameSpec)
73 {
74  if (! hasChanges()) {return true;}
75 
76  boost::shared_ptr<QProgressDialog> progressBar;
77  if (_isTopLevel) {
78  progressBar.reset(new QProgressDialog("Loading data...", "Close", 0,
79  this->count(), this));
80  progressBar->setWindowModality(Qt::WindowModal);
81  progressBar->setMinimumDuration(250);
82  }
83 
84  bool status = true;
85  for (int idx = 0; idx < this->count(); ++idx) {
86  if (_isTopLevel) {progressBar->setValue(idx);}
87  QWidget* theWidget = widget(idx);
88  Storeable* storeableObject = dynamic_cast<Storeable*>(theWidget);
89  if (! storeableObject->saveChanges(oldGlobalIdSpec,
90  newGlobalIdSpec,
91  newGlobalNameSpec)) {
92  status = false;
93  }
94  }
95  if (_isTopLevel) {progressBar->setValue(this->count());}
96  return status;
97 }
98 
100 {
101  CustomTabBehaviors::updateTabTextColors(this, this->tabBar());
102  emit aChangeWasMade();
103 }
104 
106 {
107  CustomTabBehaviors::updateTabTextColors(this, this->tabBar());
108  emit dataWasSaved();
109 }
110 
111 } // end of namespace gui
112 } // end of namespace dbutils
def progressBar(value, endvalue, docdb_id, bar_length=40)
Definition: bp_utils.py:6
int status
Definition: fabricate.py:1613
virtual bool addInitialRow()=0
bool saveChanges(const dbutils::daqconfig::IDSpec &oldGlobalIdSpec, const dbutils::daqconfig::IDSpec &newGlobalIdSpec, const dbutils::daqconfig::GlobalNameSpec &newGlobalNameSpec)
CustomTabWidget(QWidget *parent=0)
const char * label
void updateTabTextColors(QTabWidget *tabWidget, QTabBar *tabBar)
def connect(endpoint="tcp://127.0.0.1:5555")
Definition: g4zmq.py:15
virtual bool hasChanges() const =0
virtual bool saveChanges(const dbutils::daqconfig::IDSpec &oldIdSpec, const dbutils::daqconfig::IDSpec &newIdSpec, const dbutils::daqconfig::GlobalNameSpec &newNameSpec)=0
bool loadData(const dbutils::daqconfig::IDSpec &idSpec)
virtual bool loadData(const dbutils::daqconfig::IDSpec &idSpec)=0
int addTab(QWidget *page, const QString &label)