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

Michał Świtakowski swistakers-guest at alioth.debian.org
Wed Jul 15 19:59:13 UTC 2009


Author: swistakers-guest
Date: 2009-07-15 19:59:10 +0000 (Wed, 15 Jul 2009)
New Revision: 1214

Added:
   tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp
   tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h
Modified:
   tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt
   tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp
   tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h
   tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp
   tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.h
   tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.ui
   tux4kids-admin/trunk/tux4kids-admin/src/src.pro
Log:
sorting students, validading AddStudentDialog

Modified: tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt	2009-07-15 19:56:04 UTC (rev 1213)
+++ tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt	2009-07-15 19:59:10 UTC (rev 1214)
@@ -11,7 +11,8 @@
 	pluginManagerDialog.cpp 
 	manageStudentsWidget.cpp
 	addStudentDialog.cpp
-	studentTableModel.cpp )
+	studentTableModel.cpp 
+	studentTableProxyModel.cpp )
 
 SET(TUX4KIDS-ADMIN_MOC_HEADERS 
 	mainWindow.h
@@ -20,7 +21,8 @@
 	pluginManagerDialog.h 
 	manageStudentsWidget.h
 	addStudentDialog.h
-	studentTableModel.h )
+	studentTableModel.h 
+	studentTableProxyModel.h )
 
 SET(TUX4KIDS-ADMIN_UIS 
 	mainWindow.ui 

Modified: tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp	2009-07-15 19:56:04 UTC (rev 1213)
+++ tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.cpp	2009-07-15 19:59:10 UTC (rev 1214)
@@ -2,6 +2,7 @@
 #include "ui_addStudentDialog.h"
 
 #include <QListWidgetItem>
+#include <QDebug>
 
 AddStudentDialog::AddStudentDialog(QWidget *parent) :
 		QDialog(parent),
@@ -22,7 +23,11 @@
 	m_ui->applicationList->addItem(testListWidgetItem2);
 	testListWidgetItem2->setCheckState(Qt::Unchecked);
 
+	setInvalid();
+
 	connect(m_ui->addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
+	connect(m_ui->firstNameEdit, SIGNAL(textEdited(QString)), this, SLOT(validate()));
+	connect(m_ui->lastNameEdit, SIGNAL(textEdited(QString)), this, SLOT(validate()));
 
 }
 
@@ -47,3 +52,25 @@
 	m_ui->firstNameEdit->clear();
 	m_ui->lastNameEdit->clear();
 }
+
+void AddStudentDialog::validate()
+{
+	if (m_ui->firstNameEdit->text().simplified().isEmpty()
+		|| m_ui->lastNameEdit->text().simplified().isEmpty()) {
+		setInvalid();
+		return;
+	}
+
+	setValid();
+}
+
+void AddStudentDialog::setValid()
+{
+	m_ui->addButton->setEnabled(true);
+}
+
+void AddStudentDialog::setInvalid()
+{
+	m_ui->addButton->setEnabled(false);
+}
+

Modified: tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h	2009-07-15 19:56:04 UTC (rev 1213)
+++ tux4kids-admin/trunk/tux4kids-admin/src/addStudentDialog.h	2009-07-15 19:59:10 UTC (rev 1214)
@@ -20,8 +20,12 @@
 private:
 	Ui::AddStudentDialog *m_ui;
 
+	void setValid();
+	void setInvalid();
+
 private slots:
 	void addClicked();
+	void validate();
 
 };
 

Modified: tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp	2009-07-15 19:56:04 UTC (rev 1213)
+++ tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp	2009-07-15 19:59:10 UTC (rev 1214)
@@ -14,7 +14,8 @@
 {
 	m_ui->setupUi(this);
 
-	m_ui->studentsTable->setModel(mainController->studentTableModel());
+	m_studentTableProxyModel.setSourceModel(mainController->studentTableModel());
+	m_ui->studentsTable->setModel(&m_studentTableProxyModel);
 
 	m_mainController = mainController;
 	connect(m_ui->addStudentButton, SIGNAL(clicked()), this, SLOT(addStudentClicked()));
@@ -23,6 +24,7 @@
 ManageStudentsWidget::~ManageStudentsWidget()
 {
 	delete m_ui;
+	delete m_addStudentDialog;
 }
 
 void ManageStudentsWidget::addStudentClicked()

Modified: tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.h	2009-07-15 19:56:04 UTC (rev 1213)
+++ tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.h	2009-07-15 19:59:10 UTC (rev 1214)
@@ -4,6 +4,7 @@
 #include <QtGui/QWidget>
 #include <QPointer>
 
+#include "studentTableProxyModel.h"
 //#include "mainController.h"
 
 class AddStudentDialog;
@@ -24,6 +25,7 @@
 	Ui::ManageStudentsWidget *m_ui;
 	QPointer<AddStudentDialog> m_addStudentDialog;
 	QPointer<MainController> m_mainController;
+	StudentTableProxyModel m_studentTableProxyModel;
 
 private slots:
 

Modified: tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.ui
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.ui	2009-07-15 19:56:04 UTC (rev 1213)
+++ tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.ui	2009-07-15 19:59:10 UTC (rev 1214)
@@ -17,7 +17,26 @@
    <item>
     <layout class="QVBoxLayout" name="verticalLayout">
      <item>
-      <widget class="QTableView" name="studentsTable"/>
+      <widget class="QTableView" name="studentsTable">
+       <property name="selectionMode">
+        <enum>QAbstractItemView::SingleSelection</enum>
+       </property>
+       <property name="selectionBehavior">
+        <enum>QAbstractItemView::SelectRows</enum>
+       </property>
+       <property name="verticalScrollMode">
+        <enum>QAbstractItemView::ScrollPerPixel</enum>
+       </property>
+       <property name="horizontalScrollMode">
+        <enum>QAbstractItemView::ScrollPerPixel</enum>
+       </property>
+       <property name="gridStyle">
+        <enum>Qt::DashLine</enum>
+       </property>
+       <property name="sortingEnabled">
+        <bool>true</bool>
+       </property>
+      </widget>
      </item>
      <item>
       <widget class="QPushButton" name="addStudentButton">

Modified: tux4kids-admin/trunk/tux4kids-admin/src/src.pro
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/src.pro	2009-07-15 19:56:04 UTC (rev 1213)
+++ tux4kids-admin/trunk/tux4kids-admin/src/src.pro	2009-07-15 19:59:10 UTC (rev 1214)
@@ -11,7 +11,8 @@
     errorLog.cpp \
     manageStudentsWidget.cpp \
     addStudentDialog.cpp \
-    studentTableModel.cpp
+    studentTableModel.cpp \
+    studentTableProxyModel.cpp
 HEADERS += mainWindow.h \
     mainController.h \
     pluginManager.h \
@@ -20,10 +21,11 @@
     errorLog.h \
     manageStudentsWidget.h \
     addStudentDialog.h \
-    studentTableModel.h
+    studentTableModel.h \
+    studentTableProxyModel.h
 FORMS += mainWindow.ui \
     pluginManagerDialog.ui \
     manageStudentsWidget.ui \
     addStudentDialog.ui
-LIBS += -ltux4kidsadmin -L../../libtux4kidsadmin
-
+LIBS += -ltux4kidsadmin \
+    -L../../libtux4kidsadmin

Added: tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp	                        (rev 0)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp	2009-07-15 19:59:10 UTC (rev 1214)
@@ -0,0 +1,16 @@
+#include "studentTableProxyModel.h"
+#include "studentDir.h"
+
+StudentTableProxyModel::StudentTableProxyModel(QObject *parent)
+		: QSortFilterProxyModel(parent)
+{
+}
+
+bool StudentTableProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
+{
+	QVariant leftData = sourceModel()->data(left);
+	QVariant rightData = sourceModel()->data(right);
+	return QString::localeAwareCompare(leftData.toString(),
+					   rightData.toString()) < 0;
+}
+

Added: tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h	                        (rev 0)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h	2009-07-15 19:59:10 UTC (rev 1214)
@@ -0,0 +1,15 @@
+#ifndef STUDENTTABLEPROXYMODEL_H
+#define STUDENTTABLEPROXYMODEL_H
+
+#include <QSortFilterProxyModel>
+
+class StudentTableProxyModel : public QSortFilterProxyModel
+{
+	Q_OBJECT
+public:
+	StudentTableProxyModel(QObject *parent = 0);
+
+	bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
+};
+
+#endif // STUDENTTABLEPROXYMODEL_H




More information about the Tux4kids-commits mailing list