ConfigDataTableModel.h
Go to the documentation of this file.
1 #ifndef DBUTILS_GUI_CONFIGDATATABLEMODEL_H
2 #define DBUTILS_GUI_CONFIGDATATABLEMODEL_H
3 
4 #include <DatabaseUtils/GUI/TreeItem.h>
5 #include <NovaDatabase/Table.h>
6 #include <QtCore/QAbstractItemModel>
7 #include <QtCore/QModelIndex>
8 #include <QtCore/QVariant>
9 #include <boost/shared_ptr.hpp>
10 
11 namespace dbutils {
12 namespace gui {
13 
14 class ConfigDataTableModel : public QAbstractItemModel
15 {
16  Q_OBJECT
17 
18  public:
19 
20  // ************************************************************
21  // constructor/destructor
22  // ************************************************************
23  ConfigDataTableModel(const std::string& tableDefinitionFileName,
24  QObject *parent = 0);
25  virtual ~ConfigDataTableModel() {}
26 
27  // ************************************************************
28  // the following methods do *not* have implementations in
29  // QAbstractItemModel, so they need to be implemented here
30  // (or in subclasses)
31  // ************************************************************
32  virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
33  virtual QVariant data(const QModelIndex &index, int role) const;
34  virtual QModelIndex index(int row, int column,
35  const QModelIndex &parent = QModelIndex()) const;
36  virtual QModelIndex parent(const QModelIndex &index) const;
37  virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
38 
39  // ************************************************************
40  // the following methods *do* have implementations in QAbstractItemModel,
41  // but want to customize the implementation
42  // ************************************************************
43  virtual Qt::ItemFlags flags(const QModelIndex &index) const;
44  virtual QVariant headerData(int section, Qt::Orientation orientation,
45  int role = Qt::DisplayRole) const;
46  virtual bool insertRows(int position, int rows,
47  const QModelIndex &parent = QModelIndex());
48  virtual bool removeRows(int position, int rows,
49  const QModelIndex &parent = QModelIndex());
50  virtual bool setData(const QModelIndex &index, const QVariant &value,
51  int role = Qt::EditRole);
52  virtual bool setHeaderData(int section, Qt::Orientation orientation,
53  const QVariant &value, int role = Qt::EditRole);
54 
55  // ************************************************************
56  // the following methods are unique to this class and its children
57  // ************************************************************
58  virtual bool loadData(const std::vector<int64_t>& subsystemConfigIdList);
59  virtual bool hasChanges() const;
60  virtual bool saveChanges(const int64_t& subsystemConfigId);
61 
62  virtual bool addInitialRow();
63  virtual bool addRowAfter(const QModelIndex& index);
64  virtual bool deleteRow(const QModelIndex& index);
65 
66  virtual std::string getTableName() const;
67 
68  signals:
69 
70  void aChangeWasMade();
71  void dataWasSaved();
72 
73  protected:
74 
75  // ************************************************************
76  // protected methods
77  // ************************************************************
78  TreeItem* _getItem(const QModelIndex &index) const;
79  void _getModifiedItems(TreeItem* baseItem,
80  std::vector<TreeItem*>& list) const;
81 
82  private:
83 
84  // ************************************************************
85  // private data
86  // ************************************************************
87  boost::shared_ptr<nova::database::Table> _dbTablePtr;
88  boost::shared_ptr<TreeItem> _rootItem;
89  std::vector<std::string> _dataColumnNames;
90  std::vector<std::string> _dataColumnTypes;
91 };
92 
93 } // end of namespace gui
94 } // end of namespace dbutils
95 
96 #endif
TreeItem * _getItem(const QModelIndex &index) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
virtual bool deleteRow(const QModelIndex &index)
std::vector< std::string > _dataColumnNames
boost::shared_ptr< TreeItem > _rootItem
virtual bool addRowAfter(const QModelIndex &index)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
std::vector< std::string > _dataColumnTypes
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void _getModifiedItems(TreeItem *baseItem, std::vector< TreeItem * > &list) const
virtual QModelIndex parent(const QModelIndex &index) const
virtual std::string getTableName() const
virtual Qt::ItemFlags flags(const QModelIndex &index) 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 saveChanges(const int64_t &subsystemConfigId)
virtual bool insertRows(int position, int rows, const QModelIndex &parent=QModelIndex())
ConfigDataTableModel(const std::string &tableDefinitionFileName, QObject *parent=0)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
boost::shared_ptr< nova::database::Table > _dbTablePtr
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
virtual QVariant data(const QModelIndex &index, int role) const
virtual bool loadData(const std::vector< int64_t > &subsystemConfigIdList)
enum BeamMode string