summaryrefslogtreecommitdiffstats
path: root/kanagram/src/leitnersystem.cpp
blob: 3f633526ad46106332a9a8e06d633752219ee372 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//
// C++ Implementation: leitnersystem
//
// Description: 
//
//
// Author: Martin Pfeiffer <martin-pfeiffer-bensheim@web.de>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "leitnersystem.h"
#include <kdebug.h>

LeitnerSystem::LeitnerSystem(QValueList<LeitnerBox>& boxes, QString name)
{
	if( !boxes.empty() )
		m_boxes = boxes;

	if( name.isNull() )
		m_systemName = name;
}

LeitnerSystem::LeitnerSystem()
{
}

LeitnerSystem::~LeitnerSystem()
{
}

QStringList LeitnerSystem::getBoxNameList()
{
	QStringList boxNameList;
	QValueList<LeitnerBox>::iterator it;	


	for(it = m_boxes.begin(); it != m_boxes.end(); ++it)
	{
		boxNameList.append((*it).getBoxName());
	}

	return boxNameList;
}

int LeitnerSystem::getNumberOfBoxes()
{
	return m_boxes.count();
}

LeitnerBox* LeitnerSystem::getBoxWithNumber( int number )
{
	return &m_boxes[ number ];
}

LeitnerBox* LeitnerSystem::getBoxWithName( const QString& name )
{
	QValueList<LeitnerBox>::iterator it;

	for(it = m_boxes.begin(); it != m_boxes.end(); ++it)
	{
		if((*it).getBoxName() == name)
			return &(*it);
	}

	return 0;
}

QString& LeitnerSystem::getSystemName()
{
	return m_systemName;
}

const QString& LeitnerSystem::getNextBox( QString& previousBox )
{
	for( int i = 0; i < m_boxes.count(); i++ )
	{
		if( m_boxes[i].getVocabCount() > 0 )
			return getBox( i );
	}
	
	return QString::null;
}

const QString& LeitnerSystem::getCorrectBox( int box )
{
	return m_boxes[ box ].getCorrectWordBox()->getBoxName();
}

const QString& LeitnerSystem::getWrongBox( int box )
{
	return m_boxes[ box ].getWrongWordBox()->getBoxName();
}

int LeitnerSystem::getWrongBoxNumber( int box )
{
	return getNumber( m_boxes[ box ].getWrongWordBox() );
}

int LeitnerSystem::getCorrectBoxNumber( int box )
{
	return getNumber( m_boxes[ box ].getCorrectWordBox() );
}

void LeitnerSystem::deleteBox( int box )
{
	m_boxes.remove( m_boxes.at( box ) );
}

void LeitnerSystem::deleteBox( LeitnerBox* box )
{
	m_boxes.remove( *box ); 
}

bool LeitnerSystem::insertBox( const QString& name, int correctWordBox, int wrongWordBox )
{
	if( getBoxNameList().contains( name ) != 0 )
		return false;
	
	LeitnerBox tmpBox;
	tmpBox.setBoxName( name );
	tmpBox.setCorrectWordBox( getBoxWithNumber( correctWordBox ) );
	tmpBox.setWrongWordBox( getBoxWithNumber( wrongWordBox ) );
	
	m_boxes.append( tmpBox );
	return true;
}

void LeitnerSystem::setSystemName( const QString& name )
{
	m_systemName = name;
}

int LeitnerSystem::getNumber( LeitnerBox* box )
{
	if( m_boxes.findIndex( *box ) == -1 )
		kdDebug() << "muhaha" << endl;
	return m_boxes.findIndex( *box );
}

bool LeitnerSystem::setBoxName( int box, const QString& name )
{
	if( getBoxWithName( name ) == 0 || getBoxWithName( name ) == getBoxWithNumber( box ) )
	{
		getBoxWithNumber( box )->setBoxName( name );
		
		return true;
	}
	else
		return false;
}

bool LeitnerSystem::setBoxName( LeitnerBox* box, const QString& name )
{
	if( getBoxWithName( name ) == 0 || getBoxWithName( name ) == box )
	{
		box->setBoxName( name );
		
		return true;
	}
	else
		return false;
}

bool LeitnerSystem::insertBox( const QString& name )
{
	if( getBoxNameList().contains( name ) != 0 )
		return false;
	
	LeitnerBox tmpBox;
	tmpBox.setBoxName( name );
	//tmpBox.setVocabCount( count );
		
	m_boxes.append( tmpBox );
	return true;
}

void LeitnerSystem::setCorrectBox( const QString& box, const QString& correctWordBox )
{
	getBoxWithName( box )->setCorrectWordBox( getBoxWithName( correctWordBox ) );
}

void LeitnerSystem::setWrongBox( const QString& box, const QString& wrongWordBox )
{
	getBoxWithName( box )->setWrongWordBox( getBoxWithName( wrongWordBox ) );
}

const QString& LeitnerSystem::getBox( int i )
{
	return getBoxWithNumber( i )->getBoxName();
}