Commit bc7d62b5 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Add filtered view.

Per default only show GHNS downloaded courses and only optionally
allow using course repository courses for testing purposes.
parent d77ee022
......@@ -20,10 +20,9 @@
#include "coursefiltermodel.h"
#include "models/coursemodel.h"
#include <QSortFilterProxyModel>
#include <KLocalizedString>
#include <QSortFilterProxyModel>
#include <QVariant>
#include <QDebug>
CourseFilterModel::CourseFilterModel(QObject* parent)
......@@ -47,6 +46,7 @@ void CourseFilterModel::setView(CourseFilterModel::CourseResourceView view)
m_view = view;
invalidateFilter();
emit viewChanged();
emit filteredCountChanged();
}
CourseFilterModel::CourseResourceView CourseFilterModel::view() const
......@@ -54,16 +54,27 @@ CourseFilterModel::CourseResourceView CourseFilterModel::view() const
return m_view;
}
void CourseFilterModel::setCourseModel(CourseModel* courseModel)
void CourseFilterModel::setCourseModel(CourseModel *courseModel)
{
if (courseModel == m_courseModel) {
return;
}
if (m_courseModel) {
disconnect(m_courseModel, &CourseModel::languageChanged,
this, &CourseFilterModel::filteredCountChanged);
disconnect(m_courseModel, &CourseModel::rowCountChanged,
this, &CourseFilterModel::filteredCountChanged);
}
m_courseModel = courseModel;
connect(m_courseModel, &CourseModel::languageChanged,
this, &CourseFilterModel::filteredCountChanged);
connect(m_courseModel, &CourseModel::rowCountChanged,
this, &CourseFilterModel::filteredCountChanged);
setSourceModel(m_courseModel);
sort(0);
emit courseModelChanged();
emit filteredCountChanged();
}
int CourseFilterModel::filteredCount() const
......@@ -71,7 +82,7 @@ int CourseFilterModel::filteredCount() const
return rowCount();
}
bool CourseFilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
bool CourseFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
return QSortFilterProxyModel::lessThan(left, right);
}
......@@ -91,3 +102,8 @@ bool CourseFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourc
return true;
}
}
QVariant CourseFilterModel::course(int row) const
{
return m_courseModel->data(m_courseModel->index(row, 0), CourseModel::DataRole);
}
\ No newline at end of file
......@@ -23,6 +23,7 @@
#include <QSortFilterProxyModel>
class Course;
class CourseModel;
class QSignalMapper;
......@@ -48,8 +49,9 @@ public:
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const Q_DECL_OVERRIDE;
void setView(CourseResourceView view);
CourseResourceView view() const;
Q_INVOKABLE QVariant course(int row) const;
signals:
Q_SIGNALS:
void courseModelChanged();
void viewChanged();
void sortOptionChanged();
......
......@@ -61,12 +61,10 @@ public:
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
Q_INVOKABLE QVariant course(int index) const;
Q_SIGNALS:
void courseChanged(int index);
void resourceManagerChanged();
void languageChanged();
void viewChanged();
void rowCountChanged();
private Q_SLOTS:
......
......@@ -102,21 +102,32 @@ ApplicationWindow {
ComboBox {
id: comboCourse
enabled: {
courseFilterModel.filteredCount == 0 ? false : true
}
Layout.minimumWidth: 200
model: CourseModel {
id: courseModel
resourceManager: g_resourceManager
language: g_trainingSession.language
onLanguageChanged: {
if (courseModel.course(0)) {
g_trainingSession.course = courseModel.course(0)
model: CourseFilterModel {
id: courseFilterModel
view: {
kcfg_UseContributorResources
? CourseFilterModel.AllResources
: CourseFilterModel.OnlyGetHotNewStuffResources
}
courseModel: CourseModel {
id: courseModel
resourceManager: g_resourceManager
language: g_trainingSession.language
onLanguageChanged: {
if (courseFilterModel.course(0)) {
g_trainingSession.course = courseFilterModel.course(0)
}
}
}
}
textRole: "title"
onCurrentIndexChanged: {
if (courseModel.course(currentIndex)) {
g_trainingSession.course = courseModel.course(currentIndex)
if (courseFilterModel.course(currentIndex)) {
g_trainingSession.course = courseFilterModel.course(currentIndex)
}
}
}
......
......@@ -46,7 +46,7 @@ Item {
}
Text {
text: {
if (g_trainingSession.unit == null) {
if (g_trainingSession.unit == null || g_trainingSession.course == null) {
return "";
}
return g_trainingSession.course.i18nTitle
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment