radixtablewidget.hh 1.43 KB
Newer Older
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
#ifndef RADIX_RADIXWIDGETS_EXAMPLE_RADIXTABLEWIDGET_HH_
#define RADIX_RADIXWIDGETS_EXAMPLE_RADIXTABLEWIDGET_HH_

#include <QAbstractTableModel>
#include <QMainWindow>
#include <QWidget>

#include "radixwidgets/tableview.hh"

namespace Ui
{
class MainWindow;
}

struct Contact
{
  QString name;
  QString address;
};

class TableModel : public QAbstractTableModel
{
  Q_OBJECT

  QList<Contact> contacts;

 public:
  TableModel(QObject *parent = 0);
  TableModel(QList<Contact> contacts, QObject *parent = 0);
  int rowCount(const QModelIndex &parent) const override;
  int columnCount(const QModelIndex &parent) const override;
  QVariant data(const QModelIndex &index, int role) const override;
  QVariant headerData(int section, Qt::Orientation orientation,
                      int role) const override;
  Qt::ItemFlags flags(const QModelIndex &index) const override;
  bool setData(const QModelIndex &index, const QVariant &value,
               int role = Qt::EditRole) override;
  bool insertRows(int position, int rows,
                  const QModelIndex &index = QModelIndex()) override;
  bool removeRows(int position, int rows,
                  const QModelIndex &index = QModelIndex()) override;
};
class MainWindow : public QMainWindow
{
  Q_OBJECT

 private:
  radix::TableView *mTableView;
  TableModel *mModel;

 public:
  explicit MainWindow(QWidget *parent = 0);
  ~MainWindow();
};

#endif  // RADIX_RADIXWIDGETS_EXAMPLE_RADIXTABLEWIDGET_HH_