Blame view

src/tablemodel/tablemodel.h 2.21 KB
1dce31e3   Peter M. Groen   Setting up tablem...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  #pragma once
  
  // Qt
  #include <QAbstractTableModel>
  
  // Local
  #include "modeldataitem.h"
  
  namespace osdev {
  namespace components {
  namespace datamodels {
  
  /*!
   * \brief   The TableModelBase class is the generic way of presenting a table in memory.
   *          It can be attached to different view-objects in a GUI.
   */
  class TableModelBase : public QAbstractTableModel
  {
      Q_OBJECT
  
  public:
      TableModelBase(QObject *parent = nullptr);
      int                 rowCount(const QModelIndex &parent = QModelIndex()) const override;
      int                 columnCount(const QModelIndex &parent = QModelIndex()) const override;
      QVariant            headerData(int section, Qt::Orientation orientation, int role) const override;
      QVariant            data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
  
      void                addHeaderColumn(const QString &headerName, const QString &db_field_name = QString());
  
      QStringList         getHeaderNames();
      QString             getHeaderFieldByName( const QString &headerName) const;
      QString             getHeaderColumnByField( const QString &db_field_name ) const;
      QString             getHeaderFieldByIndex( int index ) const;
      QString             getHeaderNameByIndex( int index ) const;
      int                 getHeaderIndexByName( const QString &header_name ) const;
  
      bool                setHeaderData( int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole ) override;
      void                setKeyFields( const QStringList &key_fields );
      const QStringList&  getKeyFields() { return m_keyFields; }
  
      // void fillList(const &DataObject &data_object);
      // void addRecord(const ModelDataItem &data_item);
  
      void                clear();
  
      QString             exportDataAsString();
      QStringList         exportDataAsList();
  
  signals:
      void                signalHideLoading();
  
  private:    // Members ( Giggity! )
      QStringList                     m_keyFields;
      QList<QPair<QString, QString>>  m_headers;
      QStringList                     m_keyList;
      QHash<QString, ModelDataItem>   m_qhModelData;
  
  };
  
  }       // End namespace datamodels
  }       // End namespace components
  }       // End namespace osdev