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

Make training session more intelligent.

If course/unit is set, also set the first phrase in it.
This initializes the training session and avoids an empty screen.
parent d4df7386
......@@ -62,8 +62,10 @@ void TrainingSession::setCourse(Course *course)
if (m_course == course) {
return;
}
setUnit(nullptr);
m_course = course;
if (m_course && m_course->unitList().count() > 0) {
setUnit(m_course->unitList().first());
}
emit courseChanged();
}
......@@ -78,6 +80,9 @@ void TrainingSession::setUnit(Unit *unit)
return;
}
m_unit = unit;
if (m_unit && m_unit->phraseList().count() > 0) {
setPhrase(m_unit->phraseList().first());
}
return unitChanged();
}
......
......@@ -155,7 +155,7 @@ int PhraseModel::columnCount(const QModelIndex &parent) const
QModelIndex PhraseModel::parent(const QModelIndex &child) const
{
if (!child.internalPointer()) {
if (!child.internalPointer() || !m_course) {
return QModelIndex();
}
Unit *parent = static_cast<Unit*>(child.internalPointer());
......@@ -191,7 +191,7 @@ QModelIndex PhraseModel::indexPhrase(Phrase *phrase) const
QModelIndex PhraseModel::indexUnit(Unit *unit) const
{
if (!unit) {
if (!unit || !m_course) {
return QModelIndex();
}
return createIndex(m_course->unitList().indexOf(unit), 0);
......
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