[Tux4kids-commits] r1286 - tux4kids-admin/trunk/libtux4kidsadmin
Michał Świtakowski
swistakers-guest at alioth.debian.org
Tue Jul 28 20:45:37 UTC 2009
Author: swistakers-guest
Date: 2009-07-28 20:45:37 +0000 (Tue, 28 Jul 2009)
New Revision: 1286
Modified:
tux4kids-admin/trunk/libtux4kidsadmin/class.cpp
tux4kids-admin/trunk/libtux4kidsadmin/class.h
tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp
tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp
tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.h
tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h
tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp
tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h
tux4kids-admin/trunk/libtux4kidsadmin/teacher.cpp
tux4kids-admin/trunk/libtux4kidsadmin/teacher.h
Log:
further sql stuff
Modified: tux4kids-admin/trunk/libtux4kidsadmin/class.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/class.cpp 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/class.cpp 2009-07-28 20:45:37 UTC (rev 1286)
@@ -19,6 +19,7 @@
{
Q_D(Class);
d->name = name;
+ d->q_ptr = this;
}
Class::Class(ClassPrivate &dd)
@@ -56,4 +57,16 @@
d->id = id;
}
+Class &Class::operator=(const Class &other)
+{
+ if (this != &other) {
+ ClassPrivate *tmp = new ClassPrivate();
+ *tmp = *d_ptr;
+ tmp->q_ptr = this;
+ delete d_ptr;
+ d_ptr = tmp;
+ }
+ return *this;
+}
+
Modified: tux4kids-admin/trunk/libtux4kidsadmin/class.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/class.h 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/class.h 2009-07-28 20:45:37 UTC (rev 1286)
@@ -18,10 +18,11 @@
void setName(QString name);
int id() const;
void setId(int id);
+ Class &operator=(const Class&);
protected:
- ClassPrivate * const d_ptr;
+ ClassPrivate * d_ptr;
Class(ClassPrivate &dd);
private:
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp 2009-07-28 20:45:37 UTC (rev 1286)
@@ -21,7 +21,9 @@
loadStudentDirs();
- qDebug() << database.open("/home/swistak/test.db");
+ if (!database.open(path + "/school_database.db")) {
+ status = SchoolData::InitializationError;
+ }
}
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.cpp 2009-07-28 20:45:37 UTC (rev 1286)
@@ -4,10 +4,12 @@
#include "teacher.h"
#include <QSqlQuery>
+#include <QSqlRecord>
#include <QSqlError>
#include <QFile>
#include <QDebug>
#include <QVariant>
+#include <QStringList>
/*********************** SchoolDatabasePrivate ***********************/
@@ -64,7 +66,6 @@
lastError = createClassStudents.lastError().text();
return;
}
-
}
void SchoolDatabasePrivate::addClass(Class &newClass)
@@ -259,6 +260,92 @@
emit q->teacherDeleted(deletedTeacher);
}
+QList<Class> SchoolDatabasePrivate::classList() const
+{
+ QList<Class> result;
+
+ if (!db.isOpen()) {
+ error = true;
+ lastError = QObject::tr("Database is not open");
+ return result;
+ }
+
+ QSqlQuery classList;
+
+ error = false;
+
+ classList.prepare("SELECT name FROM classes;");
+ classList.exec();
+
+ if (!classList.isActive()) {
+ error = true;
+ lastError = classList.lastError().text();
+ return result;
+ }
+
+ QSqlRecord classRec = classList.record();
+
+ while (classList.next()) {
+ int id = classList.value(classRec.indexOf("id")).toInt();
+ QString name = classList.value(classRec.indexOf("name")).toString();
+ Class newClass;
+ newClass.setId(id);
+ newClass.setName(name);
+ result.append(newClass);
+ }
+ return result;
+}
+
+QList<Teacher> SchoolDatabasePrivate::teacherList() const
+{
+ QList<Teacher> result;
+
+ if (!db.isOpen()) {
+ error = true;
+ lastError = QObject::tr("Database is not open");
+ return result;
+ }
+
+ QSqlQuery teacherList;
+
+ error = false;
+
+ teacherList.prepare("SELECT first_name, last_name FROM teachers;");
+ teacherList.exec();
+
+ if (!teacherList.isActive()) {
+ error = true;
+ lastError = teacherList.lastError().text();
+ return result;
+ }
+
+ QSqlRecord teacherRec = teacherList.record();
+
+ while (teacherList.next()) {
+ int id = teacherList.value(teacherRec.indexOf("id")).toInt();
+ QString firstName = teacherList.value(teacherRec.indexOf("first_name")).toString();
+ QString lastName = teacherList.value(teacherRec.indexOf("last_name")).toString();
+ Teacher newTeacher(firstName, lastName);
+ newTeacher.setId(id);
+ //newTeacher.setFirstName(firstName);
+ //newTeacher.setLastName(lastName);
+ result.append(newTeacher);
+ }
+ return result;
+}
+
+void SchoolDatabasePrivate::synchronizeStudents(const QList< QPointer<StudentDir> > &studentList)
+{
+ QStringList existingStudents;
+
+ foreach(StudentDir *studentDir, studentList) {
+ existingStudents.append(studentDir->dirName());
+ }
+
+
+}
+
+
/************************ SchoolDatabase **************************/
SchoolDatabase::SchoolDatabase(QObject *parent)
@@ -353,3 +440,21 @@
d->deleteTeacher(deletedTeacher);
}
+QList<Class>SchoolDatabase::classList() const
+{
+ Q_D(const SchoolDatabase);
+ return d->classList();
+}
+
+QList<Teacher>SchoolDatabase::teacherList() const
+{
+ Q_D(const SchoolDatabase);
+ return d->teacherList();
+}
+
+void SchoolDatabase::synchronizeStudents(const QList< QPointer<StudentDir> > &studentList)
+{
+ Q_D(SchoolDatabase);
+ d->synchronizeStudents(studentList);
+}
+
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.h 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase.h 2009-07-28 20:45:37 UTC (rev 1286)
@@ -2,8 +2,10 @@
#define SCHOOLDATABASE_H
#include <QObject>
+#include <QPointer>
#include "libtux4kidsadmin_global.h"
+#include "studentDir.h"
class SchoolDatabasePrivate;
class Class;
@@ -28,6 +30,10 @@
void updateTeacher(const Teacher &updatedTeacher);
void deleteTeacher(const Teacher &deletedTeacher);
+ QList<Class> classList() const;
+ QList<Teacher> teacherList() const;
+ void synchronizeStudents(const QList< QPointer<StudentDir> > &studentList);
+
protected:
SchoolDatabasePrivate * const d_ptr;
SchoolDatabase(SchoolDatabasePrivate &dd, QObject *parent = 0);
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolDatabase_p.h 2009-07-28 20:45:37 UTC (rev 1286)
@@ -25,12 +25,15 @@
void updateTeacher(const Teacher &updatedTeacher);
void deleteTeacher(const Teacher &deletedTeacher);
+ QList<Class> classList() const;
+ QList<Teacher> teacherList() const;
+ void synchronizeStudents(const QList< QPointer<StudentDir> > &studentList);
SchoolDatabase *q_ptr;
QSqlDatabase db;
- bool error;
- QString lastError;
+ mutable bool error;
+ mutable QString lastError;
};
Modified: tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp 2009-07-28 20:45:37 UTC (rev 1286)
@@ -117,11 +117,18 @@
{
Q_D(StudentDir);
-
ProfileDir *tmp = ProfileDirFactory::instance().create(profileType, profileType, this);
if (tmp != 0) {
d->profiles.append(tmp);
+ return tmp;
}
+
+ return 0;
}
+QString StudentDir::dirName() const
+{
+ Q_D(const StudentDir);
+ return d->mainDir.dirName();
+}
Modified: tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h 2009-07-28 20:45:37 UTC (rev 1286)
@@ -23,6 +23,7 @@
Status status() const;
+ QString dirName() const;
QString firstName() const;
QString lastName() const;
void setFirstName(const QString &firstName);
Modified: tux4kids-admin/trunk/libtux4kidsadmin/teacher.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/teacher.cpp 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/teacher.cpp 2009-07-28 20:45:37 UTC (rev 1286)
@@ -69,3 +69,16 @@
d->id = id;
}
+Teacher &Teacher::operator=(const Teacher &other)
+{
+ if (this != &other) {
+ TeacherPrivate *tmp = new TeacherPrivate();
+ *tmp = *d_ptr;
+ tmp->q_ptr = this;
+ delete d_ptr;
+ d_ptr = tmp;
+ }
+
+ return *this;
+}
+
Modified: tux4kids-admin/trunk/libtux4kidsadmin/teacher.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/teacher.h 2009-07-27 22:39:20 UTC (rev 1285)
+++ tux4kids-admin/trunk/libtux4kidsadmin/teacher.h 2009-07-28 20:45:37 UTC (rev 1286)
@@ -20,10 +20,11 @@
void setFirstName(QString firstName);
void setLastName(QString lastName);
void setId(int id);
+ Teacher &operator=(const Teacher &other);
protected:
- TeacherPrivate * const d_ptr;
+ TeacherPrivate * d_ptr;
Teacher(TeacherPrivate &dd);
private:
More information about the Tux4kids-commits
mailing list