summaryrefslogtreecommitdiffstats
path: root/gui/instancemodel.h
blob: 3938da45d8db2ed1787787c3e88e181e694a1192 (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
#pragma once

#include <QAbstractListModel>
#include "kcategorizedsortfilterproxymodel.h"
#include "lists/InstanceList.h"
#include <QIcon>

class InstanceModel : public QAbstractListModel
{
	Q_OBJECT
public:
	enum AdditionalRoles
	{
		InstancePointerRole = 0x34B1CB48 ///< Return pointer to real instance
	};
	explicit InstanceModel ( const InstanceList& instances,
	                         QObject *parent = 0 );

	QModelIndex  index ( int row, int column = 0,
	                     const QModelIndex& parent = QModelIndex() ) const;
	int rowCount ( const QModelIndex& parent = QModelIndex() ) const;
	QVariant data ( const QModelIndex& index, int role ) const;
	Qt::ItemFlags flags ( const QModelIndex& index ) const;

public slots:
	void onInstanceAdded(int index);
	void onInstanceChanged(int index);
	void onInvalidated();

private:
	const InstanceList* m_instances;
	int currentInstancesNumber;
};

class InstanceProxyModel : public KCategorizedSortFilterProxyModel
{
public:
	explicit InstanceProxyModel ( QObject *parent = 0 );

protected:
	virtual bool subSortLessThan ( const QModelIndex& left, const QModelIndex& right ) const;
};