[Tux4kids-commits] r1400 - tux4kids-admin/trunk/tux4kids-admin/src

Michał Świtakowski swistakers-guest at alioth.debian.org
Sat Aug 8 20:52:02 UTC 2009


Author: swistakers-guest
Date: 2009-08-08 20:52:02 +0000 (Sat, 08 Aug 2009)
New Revision: 1400

Modified:
   tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.cpp
   tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.h
Log:
synchronization of classes model on teacher change

Modified: tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.cpp	2009-08-08 20:35:48 UTC (rev 1399)
+++ tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.cpp	2009-08-08 20:52:02 UTC (rev 1400)
@@ -1,6 +1,9 @@
 #include "classTableModel.h"
 #include "schoolDatabase.h"
+#include "teacher.h"
 
+#include <QDebug>
+
 ClassTableModel::ClassTableModel(QObject *parent)
 		: QAbstractTableModel(parent)
 {
@@ -94,7 +97,11 @@
 	connect(m_schoolDatabase, SIGNAL(classAdded(Class &)), this, SLOT(addClass(Class &)));
 	connect(m_schoolDatabase, SIGNAL(classUpdated(Class &)), this, SLOT(updateClass(Class &)));
 	connect(m_schoolDatabase, SIGNAL(classDeleted(Class &)), this, SLOT(deleteClass(Class &)));
+	connect(m_schoolDatabase, SIGNAL(teacherAdded(Teacher &)), this, SLOT(addTeacher(Teacher &)));
+	connect(m_schoolDatabase, SIGNAL(teacherUpdated(Teacher &)), this, SLOT(updateTeacher(Teacher &)));
+	connect(m_schoolDatabase, SIGNAL(teacherDeleted(Teacher &)), this, SLOT(deleteTeacher(Teacher &)));
 
+
 	reset();
 }
 
@@ -162,3 +169,29 @@
 	return m_classes[i];
 }
 
+void ClassTableModel::addTeacher(Teacher &teacher)
+{
+	for (int i = 0; i < m_classes.size(); ++i) {
+		if (teacher.classes()->contains(m_classes.at(i))) {
+			m_classes[i].teachers()->append(teacher);
+		}
+	}
+}
+
+void ClassTableModel::updateTeacher(Teacher &teacher)
+{
+	for (int i = 0; i < m_classes.size(); ++i) {
+		m_classes[i].teachers()->removeOne(teacher);
+		if (teacher.classes()->contains(m_classes.at(i))) {
+			m_classes[i].teachers()->append(teacher);
+		}
+	}
+}
+
+void ClassTableModel::deleteTeacher(Teacher &teacher)
+{
+	for (int i = 0; i < m_classes.size(); ++i) {
+		m_classes[i].teachers()->removeOne(teacher);
+	}
+}
+

Modified: tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.h	2009-08-08 20:35:48 UTC (rev 1399)
+++ tux4kids-admin/trunk/tux4kids-admin/src/classTableModel.h	2009-08-08 20:52:02 UTC (rev 1400)
@@ -39,6 +39,10 @@
 	void addClass(Class & newClass);
 	void updateClass(Class &updatedClass);
 	void deleteClass(Class &deletedClass);
+	void addTeacher(Teacher &teacher);
+	void updateTeacher(Teacher &teacher);
+	void deleteTeacher(Teacher &teacher);
+
 };
 
 #endif // CLASSTABLEMODEL_H




More information about the Tux4kids-commits mailing list