[Tux4kids-commits] r1371 - in tux4kids-admin/trunk: libtux4kidsadmin tux4kids-admin/src
Michał Świtakowski
swistakers-guest at alioth.debian.org
Wed Aug 5 18:04:31 UTC 2009
Author: swistakers-guest
Date: 2009-08-05 18:04:30 +0000 (Wed, 05 Aug 2009)
New Revision: 1371
Modified:
tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp
tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp
tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h
tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.cpp
tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.h
tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.cpp
tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.h
tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.cpp
tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.h
Log:
adding classes almost works
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp 2009-08-05 18:04:30 UTC (rev 1371)
@@ -112,6 +112,6 @@
SchoolDatabase *SchoolData::schoolDatabase()
{
Q_D(SchoolData);
- return &d->database;
+ return &(d->database);
}
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp 2009-08-05 18:04:30 UTC (rev 1371)
@@ -258,6 +258,8 @@
lastError = insertClass.lastError().text();
return;
} else {
+ db.transaction();
+
QSqlQuery getClassId;
getClassId.prepare("SELECT MAX(id) FROM classes;");
getClassId.exec();
@@ -277,9 +279,69 @@
Q_Q(SchoolDatabase);
emit q->classAdded(newClass);
}
+
+ if (addClassStudents(newClass)) {
+ addClassTeachers(newClass);
+ }
+ db.commit();
}
}
+bool SchoolDatabasePrivate::addClassTeachers(const Class &newClass)
+{
+ foreach (Teacher teacher, newClass.teachers()) {
+
+ QSqlQuery addTeacher;
+ addTeacher.prepare("INSERT INTO class_teachers(id_class, id_teacher) VALUES(:id_class, :id_teacher);");
+ addTeacher.bindValue(":id_class", newClass.id());
+ addTeacher.bindValue(":id_teacher", teacher.id());
+ addTeacher.exec();
+ if (!addTeacher.isActive()) {
+ error = true;
+ lastError = addTeacher.lastError().text();
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool SchoolDatabasePrivate::addClassStudents(const Class &newClass)
+{
+ foreach (QString studentDirName, newClass.students()) {
+ QSqlQuery findStudentId;
+ findStudentId.prepare("SELECT id FROM students WHERE profile_name = :profile_name;");
+ findStudentId.bindValue(":profileName", studentDirName);
+ findStudentId.exec();
+ if (!findStudentId.isActive()) {
+ error = true;
+ lastError = findStudentId.lastError().text();
+ return false;
+ }
+ if (!findStudentId.first()) {
+ error = true;
+ lastError = "Multiple profile_name-s in database";
+ return false;
+ }
+
+
+ int studentId = findStudentId.value(0).toInt();
+
+ QSqlQuery addStudent;
+ addStudent.prepare("INSERT INTO class_students(id_class, id_student) VALUES(:id_class, :id_student);");
+ addStudent.bindValue(":id_class", newClass.id());
+ addStudent.bindValue(":id_student", studentId);
+ addStudent.exec();
+ if (!addStudent.isActive()) {
+ error = true;
+ lastError = addStudent.lastError().text();
+ return false;
+ }
+ }
+
+ return true;
+}
+
void SchoolDatabasePrivate::updateClass(const Class &updatedClass)
{
if (!db.isOpen()) {
@@ -594,6 +656,7 @@
: QObject(parent),
d_ptr(new SchoolDatabasePrivate())
{
+ d_ptr->q_ptr = this;
}
SchoolDatabase::SchoolDatabase(SchoolDatabasePrivate &dd, QObject *parent)
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h 2009-08-05 18:04:30 UTC (rev 1371)
@@ -26,6 +26,9 @@
void updateTeacher(const Teacher &updatedTeacher);
void deleteTeacher(const Teacher &deletedTeacher);
+ bool addClassTeachers(const Class &newClass);
+ bool addClassStudents(const Class &newClass);
+
QList<Class> classList() const;
QList<Teacher> teacherList() const;
void synchronizeStudents(const QList< QPointer<StudentDir> > &studentList);
Modified: tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.cpp 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.cpp 2009-08-05 18:04:30 UTC (rev 1371)
@@ -1,19 +1,28 @@
#include "editClassDialog.h"
#include "ui_editClassDialog.h"
#include "selectStudentWidget.h"
+#include "selectTeacherWidget.h"
+#include "schoolData.h"
#include "class.h"
#include <QPushButton>
-EditClassDialog::EditClassDialog(QWidget *parent) :
+EditClassDialog::EditClassDialog(SchoolData *schoolData, QWidget *parent) :
QDialog(parent),
m_ui(new Ui::EditClassDialog)
{
m_ui->setupUi(this);
+ m_schoolData = schoolData;
+
m_selectStudentWidget = new SelectStudentWidget(this);
+ m_selectStudentWidget->studentTableModel()->setSchoolData(m_schoolData);
m_ui->verticalLayout->insertWidget(1, m_selectStudentWidget);
+ m_selectTeacherWidget = new SelectTeacherWidget(this);
+ m_selectTeacherWidget->teacherTableModel()->setSchoolDatabase(m_schoolData->schoolDatabase());
+ m_ui->verticalLayout->insertWidget(2, m_selectTeacherWidget);
+
connect(m_ui->nameEdit, SIGNAL(textEdited(QString)), this, SLOT(validate()));
connect(m_ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept()));
connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
@@ -46,7 +55,7 @@
result.setName(m_ui->nameEdit->text());
result.setStudents(m_selectStudentWidget->studentTableModel()->selectedStudentsDirNames());
- //result.setTeachers();
+ result.setTeachers(m_selectTeacherWidget->teacherTableModel()->selectedTeachers());
return result;
}
Modified: tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.h 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/tux4kids-admin/src/editClassDialog.h 2009-08-05 18:04:30 UTC (rev 1371)
@@ -12,12 +12,14 @@
class Class;
class SelectStudentWidget;
+class SchoolData;
+class SelectTeacherWidget;
class EditClassDialog : public QDialog
{
Q_OBJECT
public:
- EditClassDialog(QWidget *parent = 0);
+ EditClassDialog(SchoolData *schoolData, QWidget *parent = 0);
~EditClassDialog();
Class getClass() const;
@@ -26,6 +28,8 @@
private:
Ui::EditClassDialog *m_ui;
SelectStudentWidget *m_selectStudentWidget;
+ SelectTeacherWidget *m_selectTeacherWidget;
+ SchoolData *m_schoolData;
bool isValid() const;
Modified: tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.cpp 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.cpp 2009-08-05 18:04:30 UTC (rev 1371)
@@ -2,13 +2,16 @@
#include "ui_manageClassesWidget.h"
#include "editClassDialog.h"
#include "mainController.h"
+#include "schoolData.h"
+#include "schoolDatabase.h"
#include <QDebug>
ManageClassesWidget::ManageClassesWidget(MainController *mainController, QWidget *parent) :
QWidget(parent),
m_ui(new Ui::ManageClassesWidget),
- m_mainController(mainController)
+ m_mainController(mainController),
+ m_schoolDatabase(mainController->schoolData()->schoolDatabase())
{
m_ui->setupUi(this);
@@ -30,7 +33,7 @@
void ManageClassesWidget::addClicked()
{
if (m_addClassDialog == 0) {
- m_addClassDialog = new EditClassDialog(this);
+ m_addClassDialog = new EditClassDialog(m_mainController->schoolData(), this);
connect(m_addClassDialog, SIGNAL(accepted()), this, SLOT(addAccepted()));
connect(m_addClassDialog, SIGNAL(rejected()), this, SLOT(addRejected()));
}
@@ -40,7 +43,7 @@
void ManageClassesWidget::editClicked()
{
if (m_editClassDialog == 0) {
- m_editClassDialog = new EditClassDialog(this);
+ m_editClassDialog = new EditClassDialog(m_mainController->schoolData(), this);
connect(m_editClassDialog, SIGNAL(accepted()), this, SLOT(editAccepted()));
connect(m_editClassDialog, SIGNAL(rejected()), this, SLOT(editRejected()));
}
@@ -55,6 +58,11 @@
void ManageClassesWidget::addAccepted()
{
qDebug() << "add accepted";
+ Class newClass = m_addClassDialog->getClass();
+ m_schoolDatabase->addClass(newClass);
+ if (m_schoolDatabase->error()) {
+ qDebug() << m_schoolDatabase->lastError();
+ }
}
void ManageClassesWidget::addRejected()
Modified: tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.h 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/tux4kids-admin/src/manageClassesWidget.h 2009-08-05 18:04:30 UTC (rev 1371)
@@ -12,6 +12,7 @@
class MainController;
class EditClassDialog;
+class SchoolDatabase;
class ManageClassesWidget : public QWidget
{
@@ -24,6 +25,7 @@
Ui::ManageClassesWidget *m_ui;
QPointer<MainController> m_mainController;
+ QPointer<SchoolDatabase> m_schoolDatabase;
QPointer<EditClassDialog> m_addClassDialog;
QPointer<EditClassDialog> m_editClassDialog;
ClassTableProxyModel m_classTableProxyModel;
Modified: tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.cpp 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.cpp 2009-08-05 18:04:30 UTC (rev 1371)
@@ -19,7 +19,7 @@
delete m_ui;
}
-TeacherTableModel *SelectTeacherWidget::studentTableModel()
+TeacherTableModel *SelectTeacherWidget::teacherTableModel()
{
return &m_teacherTableModel;
}
Modified: tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.h 2009-08-05 16:42:16 UTC (rev 1370)
+++ tux4kids-admin/trunk/tux4kids-admin/src/selectTeacherWidget.h 2009-08-05 18:04:30 UTC (rev 1371)
@@ -17,7 +17,7 @@
public:
SelectTeacherWidget(QWidget *parent = 0);
~SelectTeacherWidget();
- TeacherTableModel *studentTableModel();
+ TeacherTableModel *teacherTableModel();
private:
Ui::SelectTeacherWidget *m_ui;
More information about the Tux4kids-commits
mailing list