summaryrefslogtreecommitdiffstats
path: root/smtreemodel.h
blob: 698a2ce259201bbae57f45aed86376137c855f24 (plain)
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
/*
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version
  2 of the License, or (at your option) any later version.
*/

#ifndef SMTREEMODEL_H
#define SMTREEMODEL_H

#include <QAbstractItemModel>
#include <QStringList>

class SmTreeItem;

class SmTreeModel : public QAbstractItemModel {
	Q_OBJECT
	public:
		explicit SmTreeModel(const QStringList &headers, QObject *parent = 0);
		~SmTreeModel();

		// counts
		int rowCount(const QModelIndex &parent) const;
		int columnCount(const QModelIndex &parent) const;

		// index, parent and flags
		QModelIndex index(int row, int column, const QModelIndex &parent) const;
		QModelIndex parent(const QModelIndex &child) const;
		Qt::ItemFlags flags(const QModelIndex &index) const;

		// headers + data
		QVariant headerData(int section, Qt::Orientation orientation, int role) const;
		bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role);
		QVariant data(const QModelIndex &index, int role) const;
		bool setData(const QModelIndex &index, const QVariant &value, int role);
		bool setRoot(SmTreeItem *rootItem);

		// row manipulation
		bool insertRows(int row, int count, const QModelIndex &parent);
		bool removeRows(int row, int count, const QModelIndex &parent);
		bool addRow(const QList<QVariant> &data, const QModelIndex &parent);


	private:
		SmTreeItem *itemAt(const QModelIndex &index) const;
		QStringList mHeaders;
		SmTreeItem *mRootItem;
};

#endif