Stellarium  0.90.0
PropertyBasedTableModel.hpp
1 /*
2  * Copyright (C) 2012 Stellarium Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17  */
18 
19 #ifndef PROPERTYBASEDTABLEMODEL_H
20 #define PROPERTYBASEDTABLEMODEL_H
21 
22 #include <QAbstractTableModel>
23 
36 class PropertyBasedTableModel : public QAbstractTableModel
37 {
38  Q_OBJECT
39 public:
40  PropertyBasedTableModel(QObject *parent = Q_NULLPTR);
41  virtual ~PropertyBasedTableModel();
42 
49  void init(QList<QObject *>* content, QObject *model, QMap<int, QString> mappings);
50 
51  //Over-rides from QAbstractTableModel
52  virtual QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const;
53 
54  virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
55  virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
56 
57  virtual Qt::ItemFlags flags(const QModelIndex &index) const;
58  virtual bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex());
59  virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole);
60  virtual bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex());
61 
62  void moveRowUp(int position);
63  void moveRowDown(int position);
64 
65 private:
66  QList<QObject *>* content;
67  QMap<int, QString> mappings;
68  QObject* modelObject;
69 };
70 
71 #endif // PROPERTYBASEDTABLEMODEL_H
This class provides a table model for just about any QObject.
void init(QList< QObject * > *content, QObject *model, QMap< int, QString > mappings)
Initializes this instance for use.