[Tux4kids-commits] r1422 - tux4kids-admin/trunk/tux4kids-admin/src
Michał Świtakowski
swistakers-guest at alioth.debian.org
Wed Aug 12 21:12:38 UTC 2009
Author: swistakers-guest
Date: 2009-08-12 21:12:38 +0000 (Wed, 12 Aug 2009)
New Revision: 1422
Modified:
tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.cpp
tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.h
tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.ui
tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp
tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h
tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp
tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h
Log:
improved search in SelectStudentWidget
Modified: tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.cpp 2009-08-12 20:32:43 UTC (rev 1421)
+++ tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.cpp 2009-08-12 21:12:38 UTC (rev 1422)
@@ -9,8 +9,19 @@
m_studentTableProxyModel.setSourceModel(&m_studentTableModel);
m_ui->studentTable->setModel(&m_studentTableProxyModel);
+
+ m_ui->filterKeyCombo->addItem(tr("Everything"),
+ StudentTableProxyModel::Everything);
+ m_ui->filterKeyCombo->addItem(tr("First name"),
+ StudentTableProxyModel::FirstName);
+ m_ui->filterKeyCombo->addItem(tr("Last name"),
+ StudentTableProxyModel::LastName);
+ m_ui->filterKeyCombo->addItem(tr("Class"),
+ StudentTableProxyModel::ClassName);
+
connect(m_ui->clearButton, SIGNAL(clicked()), m_ui->searchEdit, SLOT(clear()));
connect(m_ui->searchEdit, SIGNAL(textEdited(QString)), this, SLOT(searchEdited()));
+ connect(m_ui->filterKeyCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(filterKeyColumnChanged(int)));
connect(&m_searchTimer, SIGNAL(timeout()), this, SLOT(updateFilter()));
}
@@ -34,3 +45,8 @@
m_studentTableProxyModel.setFilterRegExp(m_ui->searchEdit->text());
}
+void SelectStudentWidget::filterKeyColumnChanged(int index)
+{
+ m_studentTableProxyModel.setFilterKeyColumn(m_ui->filterKeyCombo->itemData(index).toInt());
+}
+
Modified: tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.h 2009-08-12 20:32:43 UTC (rev 1421)
+++ tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.h 2009-08-12 21:12:38 UTC (rev 1422)
@@ -30,6 +30,7 @@
private slots:
void searchEdited();
void updateFilter();
+ void filterKeyColumnChanged(int index);
};
Modified: tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.ui
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.ui 2009-08-12 20:32:43 UTC (rev 1421)
+++ tux4kids-admin/trunk/tux4kids-admin/src/selectStudentWidget.ui 2009-08-12 21:12:38 UTC (rev 1422)
@@ -28,6 +28,9 @@
<item>
<widget class="QLineEdit" name="searchEdit"/>
</item>
+ <item>
+ <widget class="QComboBox" name="filterKeyCombo"/>
+ </item>
</layout>
</item>
<item>
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp 2009-08-12 20:32:43 UTC (rev 1421)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp 2009-08-12 21:12:38 UTC (rev 1422)
@@ -189,3 +189,8 @@
}
}
+StudentDir *StudentTableModel::studentAt(int i)
+{
+ return m_students.at(i);
+}
+
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h 2009-08-12 20:32:43 UTC (rev 1421)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h 2009-08-12 21:12:38 UTC (rev 1422)
@@ -26,6 +26,7 @@
QList<StudentDir *> selectedStudents() const;
void setSelectedStudents(const QStringList &selectedStudentsDirNames);
void clearSelection();
+ StudentDir *studentAt(int i);
void setSchoolData(SchoolData *schoolData);
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp 2009-08-12 20:32:43 UTC (rev 1421)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.cpp 2009-08-12 21:12:38 UTC (rev 1422)
@@ -1,7 +1,10 @@
#include "studentTableProxyModel.h"
#include "studentTableModel.h"
#include "studentDir.h"
+#include "class.h"
+#include <QList>
+
StudentTableProxyModel::StudentTableProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
@@ -25,11 +28,33 @@
bool StudentTableProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
- QModelIndex indexFirstName = sourceModel()->index(sourceRow, StudentTableModel::StudentFirstName, sourceParent);
- QModelIndex indexLastName = sourceModel()->index(sourceRow, StudentTableModel::StudentLastName, sourceParent);
+ StudentTableModel *tableModel =
+ qobject_cast<StudentTableModel *>(sourceModel());
+ if (tableModel == 0) {
+ return true;
+ }
+ StudentDir *student = tableModel->studentAt(sourceRow);
- return sourceModel()->data(indexFirstName).toString().contains(filterRegExp())
- || sourceModel()->data(indexLastName).toString().contains(filterRegExp());
+ if (filterKeyColumn() == Everything) {
+ foreach (Class c, *student->classes()) {
+ if (c.name().contains(filterRegExp())) {
+ return true;
+ }
+ }
+ return student->firstName().contains(filterRegExp())
+ || student->lastName().contains(filterRegExp());
+ } else if (filterKeyColumn() == FirstName) {
+ return student->firstName().contains(filterRegExp());
+ } else if (filterKeyColumn() == LastName) {
+ return student->lastName().contains(filterRegExp());
+ } else if (filterKeyColumn() == ClassName) {
+ foreach (Class c, *student->classes()) {
+ if (c.name().contains(filterRegExp())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h 2009-08-12 20:32:43 UTC (rev 1421)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableProxyModel.h 2009-08-12 21:12:38 UTC (rev 1422)
@@ -7,10 +7,18 @@
{
Q_OBJECT
public:
+ enum FilterKey {
+ Everything = 0,
+ FirstName = 1,
+ LastName = 2,
+ ClassName = 3
+ };
+
StudentTableProxyModel(QObject *parent = 0);
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
+
};
#endif // STUDENTTABLEPROXYMODEL_H
More information about the Tux4kids-commits
mailing list