[Tux4kids-commits] r1212 - in tux4kids-admin/trunk: libtux4kidsadmin tux4kids-admin/src
Michał Świtakowski
swistakers-guest at alioth.debian.org
Wed Jul 15 19:05:39 UTC 2009
Author: swistakers-guest
Date: 2009-07-15 19:05:38 +0000 (Wed, 15 Jul 2009)
New Revision: 1212
Modified:
tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp
tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp
tux4kids-admin/trunk/libtux4kidsadmin/schoolData.h
tux4kids-admin/trunk/libtux4kidsadmin/schoolData_p.h
tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp
tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h
tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp
tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h
tux4kids-admin/trunk/tux4kids-admin/src/errorLog.cpp
tux4kids-admin/trunk/tux4kids-admin/src/errorLog.h
tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
tux4kids-admin/trunk/tux4kids-admin/src/mainController.h
tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp
tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp
tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h
Log:
students visible in a table
Modified: tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/libtux4kidsadmin/profileDir.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -6,6 +6,7 @@
/****************** ProfileDirPrivate *******************/
ProfileDirPrivate::ProfileDirPrivate(QString path)
+ : status(ProfileDir::NoError)
{
mainDir.setPath(path);
if (!mainDir.exists()) {
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolData.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -8,6 +8,7 @@
/****************** SchoolDataPrivate *******************/
SchoolDataPrivate::SchoolDataPrivate(QString path)
+ : status(SchoolData::NoError)
{
mainDir.setPath(path);
if (!mainDir.exists()) {
@@ -16,6 +17,8 @@
}
}
mainDir.setPath(path);
+
+ loadStudentDirs();
}
@@ -34,7 +37,21 @@
return baseName + QString::number(number);
}
+void SchoolDataPrivate::loadStudentDirs()
+{
+ foreach(QString dirName,
+ mainDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) {
+ StudentDir *studentDir = new StudentDir(mainDir.absoluteFilePath(dirName));
+ if (studentDir->status() == StudentDir::NoError) {
+ students.append(studentDir);
+ } else {
+ delete studentDir;
+ }
+ }
+}
+
+
/****************** SchoolData *******************/
SchoolData::SchoolData(QString path, QObject *parent)
@@ -62,7 +79,21 @@
StudentDir *studentDir = new StudentDir(d->mainDir.absoluteFilePath(d->nextStudentDir()));
d->students.append(studentDir);
+ emit studentAdded(studentDir);
return studentDir;
}
+/*const StudentDir & SchoolData::studentDirAt(int index)
+{
+ Q_D(SchoolData);
+ return *(d->students.at(index));
+}
+*/
+
+QList< QPointer<StudentDir> > SchoolData::students() const
+{
+ Q_D(const SchoolData);
+ return d->students;
+}
+
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolData.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolData.h 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolData.h 2009-07-15 19:05:38 UTC (rev 1212)
@@ -2,6 +2,7 @@
#define SCHOOLDATA_H
#include <QObject>
+#include <QPointer>
class QString;
class SchoolDataPrivate;
@@ -21,11 +22,16 @@
Status status() const;
StudentDir *addStudent();
+ //const StudentDir & studentDirAt(int index);
+ QList< QPointer<StudentDir> > students() const;
protected:
SchoolDataPrivate * const d_ptr;
SchoolData(SchoolDataPrivate &dd, QObject *parent = 0);
+signals:
+ void studentAdded(StudentDir *newStudent);
+
private:
Q_DECLARE_PRIVATE(SchoolData)
Q_DISABLE_COPY(SchoolData)
Modified: tux4kids-admin/trunk/libtux4kidsadmin/schoolData_p.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/schoolData_p.h 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/libtux4kidsadmin/schoolData_p.h 2009-07-15 19:05:38 UTC (rev 1212)
@@ -21,6 +21,7 @@
virtual ~SchoolDataPrivate();
QString nextStudentDir() const;
+ void loadStudentDirs();
SchoolData *q_ptr;
Modified: tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -2,10 +2,12 @@
#include "studentDir_p.h"
#include <QString>
+#include <QDebug>
/****************** StudentDirPrivate *******************/
-StudentDirPrivate::StudentDirPrivate(QString path)
+StudentDirPrivate::StudentDirPrivate(QString path) :
+ status(StudentDir::NoError)
{
mainDir.setPath(path);
if (!mainDir.exists()) {
@@ -17,7 +19,7 @@
mainDir.setPath(path);
attributes = new QSettings(path + "/attributes.ini", QSettings::IniFormat);
- if (!attributes->status() != QSettings::NoError) {
+ if (attributes->status() != QSettings::NoError) {
status = StudentDir::InitializationError;
return;
}
@@ -43,6 +45,13 @@
delete d;
}
+StudentDir::Status StudentDir::status() const
+{
+ Q_D(const StudentDir);
+ return d->status;
+}
+
+
QString StudentDir::firstName() const
{
Q_D(const StudentDir);
Modified: tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/libtux4kidsadmin/studentDir.h 2009-07-15 19:05:38 UTC (rev 1212)
@@ -20,6 +20,8 @@
InitializationError = 1
};
+ Status status() const;
+
QString firstName() const;
QString lastName() const;
void setFirstName(const QString &firstName);
Modified: tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -22,6 +22,8 @@
m_ui->applicationList->addItem(testListWidgetItem2);
testListWidgetItem2->setCheckState(Qt::Unchecked);
+ connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
+
}
AddStudentDialog::~AddStudentDialog()
@@ -29,6 +31,16 @@
delete m_ui;
}
+QString AddStudentDialog::firstName() const
+{
+ return m_ui->firstNameEdit->text().simplified();
+}
+
+QString AddStudentDialog::lastName() const
+{
+ return m_ui->lastNameEdit->text().simplified();
+}
+
void AddStudentDialog::addClicked()
{
emit accepted();
Modified: tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h 2009-07-15 19:05:38 UTC (rev 1212)
@@ -14,6 +14,9 @@
AddStudentDialog(QWidget *parent = 0);
~AddStudentDialog();
+ QString firstName() const;
+ QString lastName() const;
+
private:
Ui::AddStudentDialog *m_ui;
Modified: tux4kids-admin/trunk/tux4kids-admin/src/errorLog.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/errorLog.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/errorLog.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -41,7 +41,7 @@
}
}
-void ErrorLog::log(QString message, QString userMessage)
+void ErrorLog::log(const QString &message, const QString &userMessage)
{
instance = ErrorLog::Instance();
Modified: tux4kids-admin/trunk/tux4kids-admin/src/errorLog.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/errorLog.h 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/errorLog.h 2009-07-15 19:05:38 UTC (rev 1212)
@@ -10,7 +10,7 @@
static ErrorLog* Instance();
static void Destroy();
- static void log(QString message, QString userMessage = QString());
+ static void log(const QString &message, const QString &userMessage = QString());
private:
static ErrorLog* instance;
Modified: tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -15,10 +15,12 @@
}
m_schoolData = new SchoolData(QDir::homePath() + "/school_data");
+ m_studentTableModel.setSchoolData(m_schoolData);
}
MainController::~MainController()
{
+ delete m_schoolData;
}
PluginManager *MainController::pluginManager()
@@ -31,4 +33,9 @@
return m_schoolData;
}
+StudentTableModel *MainController::studentTableModel()
+{
+ return &m_studentTableModel;
+}
+
Modified: tux4kids-admin/trunk/tux4kids-admin/src/mainController.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/mainController.h 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/mainController.h 2009-07-15 19:05:38 UTC (rev 1212)
@@ -5,6 +5,7 @@
#include <QList>
#include "pluginManager.h"
+#include "studentTableModel.h"
class SchoolData;
@@ -18,10 +19,12 @@
PluginManager *pluginManager();
SchoolData *schoolData();
+ StudentTableModel *studentTableModel();
private:
PluginManager m_pluginManager;
+ StudentTableModel m_studentTableModel;
QPointer<SchoolData> m_schoolData;
};
Modified: tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -5,6 +5,8 @@
#include "schoolData.h"
#include "studentDir.h"
+#include <QDebug>
+
ManageStudentsWidget::ManageStudentsWidget(MainController *mainController, QWidget *parent) :
QWidget(parent),
m_ui(new Ui::ManageStudentsWidget),
@@ -12,6 +14,8 @@
{
m_ui->setupUi(this);
+ m_ui->studentsTable->setModel(mainController->studentTableModel());
+
m_mainController = mainController;
connect(m_ui->addStudentButton, SIGNAL(clicked()), this, SLOT(addStudentClicked()));
}
@@ -33,7 +37,7 @@
void ManageStudentsWidget::addStudent()
{
StudentDir *studentDir = m_mainController->schoolData()->addStudent();
- studentDir->setFirstName("John");
- studentDir->setLastName("Harry");
+ studentDir->setFirstName(m_addStudentDialog->firstName());
+ studentDir->setLastName(m_addStudentDialog->lastName());
}
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp 2009-07-15 19:05:38 UTC (rev 1212)
@@ -1,12 +1,80 @@
#include "studentTableModel.h"
#include "schoolData.h"
+#include "studentDir.h"
+#include <QDebug>
-StudentTableModel::StudentTableModel(SchoolData *schoolData, QObject *parent)
- : QAbstractTableModel(parent),
- m_schoolData(schoolData)
+StudentTableModel::StudentTableModel(QObject *parent)
+ : QAbstractTableModel(parent)
{
}
StudentTableModel::~StudentTableModel()
{
}
+
+int StudentTableModel::rowCount(const QModelIndex &parent) const
+{
+ return m_students.size();
+}
+
+
+int StudentTableModel::columnCount(const QModelIndex &parent) const
+{
+ return 2;
+}
+
+QVariant StudentTableModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ if (orientation == Qt::Vertical) {
+ return section + 1;
+ } else if (orientation == Qt::Horizontal) {
+ switch (section) {
+ case StudentFirstName:
+ return tr("Name");
+ case StudentLastName:
+ return tr("Surname");
+ }
+ }
+
+ return QVariant();
+}
+
+QVariant StudentTableModel::data(const QModelIndex &index, int role) const
+{
+ if (!index.isValid())
+ return QVariant();
+
+ if (index.row() >= rowCount())
+ return QVariant();
+
+ if (index.column() >= columnCount())
+ return QVariant();
+
+ if (role == Qt::DisplayRole) {
+ switch (index.column()) {
+ case StudentFirstName:
+ return m_students.at(index.row())->firstName();
+ case StudentLastName:
+ return m_students.at(index.row())->lastName();
+ }
+ }
+ return QVariant();
+}
+
+void StudentTableModel::setSchoolData(const SchoolData *schoolData)
+{
+ m_students = schoolData->students();
+ connect(schoolData, SIGNAL(studentAdded(StudentDir*)), this,
+ SLOT(addStudent(StudentDir*)));
+ reset();
+}
+
+void StudentTableModel::addStudent(StudentDir *newStudent)
+{
+ beginInsertRows(QModelIndex(), m_students.size(), m_students.size());
+ m_students.append(newStudent);
+ endInsertRows();
+}
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h 2009-07-15 10:56:17 UTC (rev 1211)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h 2009-07-15 19:05:38 UTC (rev 1212)
@@ -3,19 +3,36 @@
#include <QAbstractTableModel>
#include <QPointer>
+#include <QList>
+class StudentDir;
class SchoolData;
class StudentTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
- StudentTableModel(SchoolData *schoolData, QObject *parent = 0);
+ StudentTableModel(QObject *parent = 0);
~StudentTableModel();
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+ void setSchoolData(const SchoolData *schoolData);
+
protected:
- QPointer<SchoolData> m_schoolData;
+ enum StudentField {
+ StudentFirstName = 0,
+ StudentLastName = 1
+ };
+
+ QList< QPointer<StudentDir> > m_students;
+
+private slots:
+ void addStudent(StudentDir *newStudent);
};
#endif // STUDENTTABLEMODEL_H
More information about the Tux4kids-commits
mailing list