summaryrefslogtreecommitdiffstats
path: root/logic/OneSixVersion.cpp
blob: dc1b5d6ff8cd54d4c6b099000c4078463478f4e0 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "OneSixVersion.h"
#include "OneSixLibrary.h"

QList<QSharedPointer<OneSixLibrary> > OneSixVersion::getActiveNormalLibs()
{
	QList<QSharedPointer<OneSixLibrary> > output;
	for ( auto lib: libraries )
	{
		if (lib->isActive() && !lib->isNative())
		{
			output.append(lib);
		}
	}
	return output;
}

QList<QSharedPointer<OneSixLibrary> > OneSixVersion::getActiveNativeLibs()
{
	QList<QSharedPointer<OneSixLibrary> > output;
	for ( auto lib: libraries )
	{
		if (lib->isActive() && lib->isNative())
		{
			output.append(lib);
		}
	}
	return output;
}


QVariant OneSixVersion::data(const QModelIndex& index, int role) const
{
	if(!index.isValid())
		return QVariant();
	
	int row = index.row();
	int column = index.column();
	
	if(row < 0 || row >= libraries.size())
		return QVariant();
	
	if(role == Qt::DisplayRole)
	{
		switch(column)
		{
			case 0:
				return libraries[row]->name();
			case 1:
				return libraries[row]->type();
			case 2:
				return libraries[row]->version();
			default:
				return QVariant();
		}
	}
	return QVariant();
}

Qt::ItemFlags OneSixVersion::flags(const QModelIndex& index) const
{
	if(!index.isValid())
		return Qt::NoItemFlags;
	int row = index.row();
	if(libraries[row]->isActive())
	{
		return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren;
	}
	else
	{
		return Qt::ItemNeverHasChildren;
	}
	//return QAbstractListModel::flags(index);
}


QVariant OneSixVersion::headerData ( int section, Qt::Orientation orientation, int role ) const
{
	if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
		return QVariant();
	switch (section)
	{
	case 0:
		return QString("Name");
	case 1:
		return QString("Type");
	case 2:
		return QString("Version");
	default:
		return QString();
	}
}

int OneSixVersion::rowCount(const QModelIndex& parent) const
{
	return libraries.size();
}

int OneSixVersion::columnCount(const QModelIndex& parent) const
{
    return 3;
}