[Tux4kids-commits] r1431 - in tux4kids-admin/trunk: libtux4kidsadmin tux4kids-admin/src
Michał Świtakowski
swistakers-guest at alioth.debian.org
Thu Aug 13 23:52:37 UTC 2009
Author: swistakers-guest
Date: 2009-08-13 23:52:37 +0000 (Thu, 13 Aug 2009)
New Revision: 1431
Added:
tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.cpp
tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.h
Modified:
tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp
tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt
tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp
tux4kids-admin/trunk/tux4kids-admin/src/src.pro
tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp
tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h
Log:
experimenting with custom delegate class
Modified: tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp
===================================================================
--- tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp 2009-08-13 23:36:49 UTC (rev 1430)
+++ tux4kids-admin/trunk/libtux4kidsadmin/studentDir.cpp 2009-08-13 23:52:37 UTC (rev 1431)
@@ -36,8 +36,6 @@
void StudentDirPrivate::loadProfileDirs()
{
- Q_Q(StudentDir);
-
foreach(QString dirName,
mainDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)) {
Modified: tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt 2009-08-13 23:36:49 UTC (rev 1430)
+++ tux4kids-admin/trunk/tux4kids-admin/src/CMakeLists.txt 2009-08-13 23:52:37 UTC (rev 1431)
@@ -25,7 +25,8 @@
editTeacherDialog.cpp
selectStudentWidget.cpp
selectTeacherWidget.cpp
- selectClassWidget.cpp )
+ selectClassWidget.cpp
+ studentTableDelegate.cpp )
SET(TUX4KIDS-ADMIN_MOC_HEADERS
mainWindow.h
@@ -46,7 +47,8 @@
editTeacherDialog.h
selectStudentWidget.h
selectTeacherWidget.h
- selectClassWidget.h )
+ selectClassWidget.h
+ studentTableDelegate.h )
SET(TUX4KIDS-ADMIN_UIS
mainWindow.ui
Modified: tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp 2009-08-13 23:36:49 UTC (rev 1430)
+++ tux4kids-admin/trunk/tux4kids-admin/src/manageStudentsWidget.cpp 2009-08-13 23:52:37 UTC (rev 1431)
@@ -4,6 +4,7 @@
#include "mainController.h"
#include "schoolData.h"
#include "studentDir.h"
+#include "studentTableDelegate.h"
#include <QDebug>
@@ -14,6 +15,10 @@
{
m_ui->setupUi(this);
+ m_ui->studentsTable->setEditTriggers(QAbstractItemView::SelectedClicked
+ | QAbstractItemView::EditKeyPressed);
+ m_ui->studentsTable->setItemDelegateForColumn(StudentTableModel::StudentComputer,
+ new StudentTableDelegate(this));
m_studentTableProxyModel.setSourceModel(mainController->studentTableModel());
m_ui->studentsTable->setModel(&m_studentTableProxyModel);
Modified: tux4kids-admin/trunk/tux4kids-admin/src/src.pro
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/src.pro 2009-08-13 23:36:49 UTC (rev 1430)
+++ tux4kids-admin/trunk/tux4kids-admin/src/src.pro 2009-08-13 23:52:37 UTC (rev 1431)
@@ -24,7 +24,8 @@
editClassDialog.cpp \
selectStudentWidget.cpp \
selectTeacherWidget.cpp \
- selectClassWidget.cpp
+ selectClassWidget.cpp \
+ studentTableDelegate.cpp
HEADERS += mainWindow.h \
mainController.h \
pluginManager.h \
@@ -45,7 +46,8 @@
editClassDialog.h \
selectStudentWidget.h \
selectTeacherWidget.h \
- selectClassWidget.h
+ selectClassWidget.h \
+ studentTableDelegate.h
FORMS += mainWindow.ui \
pluginManagerDialog.ui \
manageStudentsWidget.ui \
Added: tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.cpp (rev 0)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.cpp 2009-08-13 23:52:37 UTC (rev 1431)
@@ -0,0 +1,44 @@
+#include "studentTableDelegate.h"
+#include "studentTableModel.h"
+
+#include <QComboBox>
+#include <QDebug>
+
+StudentTableDelegate::StudentTableDelegate(QObject *parent)
+ : QItemDelegate(parent)
+{
+}
+
+QWidget *StudentTableDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ QComboBox *editor = new QComboBox(parent);
+ return editor;
+}
+
+void StudentTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+ QString data = index.data(Qt::DisplayRole).toString();
+ QComboBox *comboBox = static_cast<QComboBox *>(editor);
+ if (comboBox != 0) {
+ comboBox->addItem(data);
+ comboBox->addItem("Computer 1");
+ comboBox->addItem("Computer 2");
+ }
+}
+
+void StudentTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const
+{
+ QComboBox *comboBox = static_cast<QComboBox *>(editor);
+ if (comboBox != 0) {
+ qDebug() << "data set to" << comboBox->currentText();
+ }
+}
+
+void StudentTableDelegate::updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option, const QModelIndex & index) const
+{
+ editor->setGeometry(option.rect);
+}
Added: tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.h (rev 0)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableDelegate.h 2009-08-13 23:52:37 UTC (rev 1431)
@@ -0,0 +1,22 @@
+#ifndef STUDENTTABLEDELEGATE_H
+#define STUDENTTABLEDELEGATE_H
+
+#include <QItemDelegate>
+
+class StudentTableDelegate : public QItemDelegate
+{
+ Q_OBJECT
+public:
+ StudentTableDelegate(QObject *parent = 0);
+
+ QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ void setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const;
+ void updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option, const
+ QModelIndex &index) const;
+};
+
+#endif // STUDENTTABLEDELEGATE_H
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp 2009-08-13 23:36:49 UTC (rev 1430)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.cpp 2009-08-13 23:52:37 UTC (rev 1431)
@@ -24,7 +24,7 @@
int StudentTableModel::columnCount(const QModelIndex &parent) const
{
- return 3;
+ return 4;
}
QVariant StudentTableModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -40,6 +40,8 @@
return tr("Name");
case StudentLastName:
return tr("Surname");
+ case StudentComputer:
+ return tr("Computer");
}
}
@@ -63,6 +65,8 @@
return m_students.at(index.row())->firstName();
case StudentLastName:
return m_students.at(index.row())->lastName();
+ case StudentComputer:
+ return tr("None");
}
} else if (role == Qt::CheckStateRole) {
if (index.column() == StudentSelected) {
@@ -82,8 +86,11 @@
result = Qt::ItemIsEnabled
| Qt::ItemIsSelectable;
if (index.column() == StudentSelected) {
- result |= (Qt::ItemIsUserCheckable | Qt::ItemIsEditable);
+ result |= Qt::ItemIsUserCheckable;
}
+ if (index.column() == StudentComputer) {
+ result |= Qt::ItemIsEditable;
+ }
return result;
}
Modified: tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h 2009-08-13 23:36:49 UTC (rev 1430)
+++ tux4kids-admin/trunk/tux4kids-admin/src/studentTableModel.h 2009-08-13 23:52:37 UTC (rev 1431)
@@ -33,7 +33,8 @@
enum StudentField {
StudentSelected = 0,
StudentFirstName = 1,
- StudentLastName = 2
+ StudentLastName = 2,
+ StudentComputer = 3
};
protected:
More information about the Tux4kids-commits
mailing list