Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Artikulate
Commits
d8378522
Commit
d8378522
authored
Nov 26, 2013
by
Andreas Cord-Landwehr
Browse files
Add model for learning goals.
parent
214b6b76
Changes
5
Hide whitespace changes
Inline
Side-by-side
liblearnerprofile/src/CMakeLists.txt
View file @
d8378522
...
...
@@ -28,6 +28,8 @@ set( learnerprofile_LIB_SRCS
learninggoal.cpp
profilemanager.cpp
storage.cpp
models/learninggoalmodel.cpp
)
kde4_add_library
(
learnerprofile SHARED
${
learnerprofile_LIB_SRCS
}
)
...
...
liblearnerprofile/src/models/learninggoalmodel.cpp
0 → 100644
View file @
d8378522
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"learninggoalmodel.h"
#include
"profilemanager.h"
#include
"learner.h"
#include
<QAbstractListModel>
#include
<QSignalMapper>
#include
<KLocale>
#include
<KDebug>
using
namespace
LearnerProfile
;
// private class LearningGoaModelPrivate
class
LearningGoalModelPrivate
{
public:
LearningGoalModelPrivate
()
:
m_profileManager
(
0
)
,
m_learner
(
0
)
{
}
~
LearningGoalModelPrivate
()
{}
ProfileManager
*
m_profileManager
;
Learner
*
m_learner
;
QList
<
LearningGoal
*>
m_goals
;
};
LearningGoalModel
::
LearningGoalModel
(
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
,
d
(
new
LearningGoalModelPrivate
)
{
QHash
<
int
,
QByteArray
>
roles
;
roles
[
TitleRole
]
=
"title"
;
roles
[
IdRole
]
=
"id"
;
roles
[
DataRole
]
=
"dataRole"
;
setRoleNames
(
roles
);
}
LearningGoalModel
::~
LearningGoalModel
()
{
}
void
LearningGoalModel
::
setProfileManager
(
ProfileManager
*
profileManager
)
{
if
(
d
->
m_profileManager
==
profileManager
)
{
return
;
}
beginResetModel
();
if
(
d
->
m_profileManager
)
{
d
->
m_profileManager
->
disconnect
(
this
);
}
d
->
m_profileManager
=
profileManager
;
if
(
d
->
m_profileManager
)
{
connect
(
d
->
m_profileManager
,
SIGNAL
(
profileAdded
(
Learner
*
,
int
)),
SLOT
(
onLearningGoalAdded
()));
connect
(
d
->
m_profileManager
,
SIGNAL
(
profileAboutToBeRemoved
(
int
)),
SLOT
(
onLearningGoalAboutToBeRemoved
(
int
)));
}
endResetModel
();
emit
profileManagerChanged
();
}
ProfileManager
*
LearningGoalModel
::
profileManager
()
const
{
return
d
->
m_profileManager
;
}
Learner
*
LearningGoalModel
::
learner
()
const
{
return
d
->
m_learner
;
}
void
LearningGoalModel
::
setLearner
(
Learner
*
learner
)
{
if
(
!
learner
)
{
return
;
}
emit
beginResetModel
();
d
->
m_learner
=
learner
;
emit
learnerChanged
();
emit
endResetModel
();
}
QVariant
LearningGoalModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
!
index
.
isValid
())
{
return
QVariant
();
}
if
(
index
.
row
()
>=
d
->
m_goals
.
count
())
{
return
QVariant
();
}
LearningGoal
*
const
goal
=
d
->
m_goals
.
at
(
index
.
row
());
switch
(
role
)
{
case
Qt
::
DisplayRole
:
return
!
goal
->
name
().
isEmpty
()
?
QVariant
(
goal
->
name
())
:
QVariant
(
i18nc
(
"@item:inlistbox:"
,
"unknown"
));
case
Qt
::
ToolTipRole
:
return
QVariant
(
goal
->
name
());
case
TitleRole
:
return
goal
->
name
();
case
IdRole
:
return
goal
->
identifier
();
case
DataRole
:
return
QVariant
::
fromValue
<
QObject
*>
(
goal
);
default:
return
QVariant
();
}
}
int
LearningGoalModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
if
(
parent
.
isValid
())
{
return
0
;
}
return
d
->
m_goals
.
count
();
}
void
LearningGoalModel
::
onLearningGoalAboutToBeAdded
(
LearningGoal
*
goal
,
int
index
)
{
Q_UNUSED
(
index
)
beginInsertRows
(
QModelIndex
(),
d
->
m_goals
.
count
(),
d
->
m_goals
.
count
());
d
->
m_goals
.
append
(
goal
);
}
void
LearningGoalModel
::
onLearningGoalAdded
()
{
endInsertRows
();
}
void
LearningGoalModel
::
onLearningGoalAboutToBeRemoved
(
int
index
)
{
if
(
!
d
->
m_learner
)
{
return
;
}
if
(
index
<
0
||
d
->
m_goals
.
count
()
<=
index
)
{
kWarning
()
<<
"Cannot remove learning goal from model, not registered"
;
return
;
}
beginRemoveRows
(
QModelIndex
(),
index
,
index
);
d
->
m_goals
.
removeAt
(
index
);
endRemoveRows
();
}
QVariant
LearningGoalModel
::
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
)
const
{
if
(
role
!=
Qt
::
DisplayRole
)
{
return
QVariant
();
}
if
(
orientation
==
Qt
::
Vertical
)
{
return
QVariant
(
section
+
1
);
}
return
QVariant
(
i18nc
(
"@title:column"
,
"Learning Goal"
));
}
QVariant
LearningGoalModel
::
learningGoal
(
int
row
)
const
{
return
data
(
index
(
row
,
0
),
LearningGoalModel
::
DataRole
);
}
liblearnerprofile/src/models/learninggoalmodel.h
0 → 100644
View file @
d8378522
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LEARNINGGOALMODEL_H
#define LEARNINGGOALMODEL_H
#include
"../liblearnerprofile_export.h"
#include
<QAbstractListModel>
#include
<QObject>
class
LearningGoalModelPrivate
;
namespace
LearnerProfile
{
class
ProfileManager
;
class
LearningGoal
;
class
Learner
;
class
LIBLEARNERPROFILE_EXPORT
LearningGoalModel
:
public
QAbstractListModel
{
Q_OBJECT
Q_PROPERTY
(
ProfileManager
*
profileManager
READ
profileManager
WRITE
setProfileManager
NOTIFY
profileManagerChanged
)
Q_PROPERTY
(
Learner
*
learner
READ
learner
WRITE
setLearner
NOTIFY
learnerChanged
)
public:
enum
learningGoalRoles
{
TitleRole
=
Qt
::
UserRole
+
1
,
IdRole
,
DataRole
};
explicit
LearningGoalModel
(
QObject
*
parent
=
0
);
virtual
~
LearningGoalModel
();
void
setProfileManager
(
ProfileManager
*
profileManager
);
ProfileManager
*
profileManager
()
const
;
void
setLearner
(
Learner
*
learner
);
Learner
*
learner
()
const
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
=
Qt
::
DisplayRole
)
const
;
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
QVariant
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
=
Qt
::
DisplayRole
)
const
;
Q_INVOKABLE
QVariant
learningGoal
(
int
index
)
const
;
Q_SIGNALS:
void
profileManagerChanged
();
void
learnerChanged
();
private
Q_SLOTS
:
void
onLearningGoalAboutToBeAdded
(
LearningGoal
*
goal
,
int
index
);
void
onLearningGoalAdded
();
void
onLearningGoalAboutToBeRemoved
(
int
index
);
private:
const
QScopedPointer
<
LearningGoalModelPrivate
>
d
;
};
}
#endif // LEARNINGGOALMODEL_H
src/CMakeLists.txt
View file @
d8378522
...
...
@@ -200,6 +200,7 @@ kde4_add_ui_files(artikulate_SRCS
kde4_add_kcfg_files
(
artikulate_SRCS settings.kcfgc
)
kde4_add_executable
(
artikulate
${
artikulate_SRCS
}
)
target_link_libraries
(
artikulate
learnerprofile
${
artikulateTargetLibs
}
)
...
...
src/application.cpp
View file @
d8378522
...
...
@@ -43,7 +43,9 @@
#include
"models/phonemeunitmodel.h"
#include
"models/profilemodel.h"
#include
"models/skeletonmodel.h"
#include
"liblearnerprofile/src/learner.h"
#include
"liblearnerprofile/src/models/learninggoalmodel.h"
#include
<kdeclarative.h>
...
...
@@ -82,6 +84,7 @@ void Application::registerQmlTypes()
qmlRegisterType
<
PhonemeUnitModel
>
(
"artikulate"
,
1
,
0
,
"PhonemeUnitModel"
);
qmlRegisterType
<
ProfileModel
>
(
"artikulate"
,
1
,
0
,
"ProfileModel"
);
qmlRegisterType
<
SkeletonModel
>
(
"artikulate"
,
1
,
0
,
"SkeletonModel"
);
qmlRegisterType
<
LearnerProfile
::
LearningGoalModel
>
(
"artikulate"
,
1
,
0
,
"LearningGoalModel"
);
qmlRegisterType
<
MainWindow
>
(
"artikulate"
,
1
,
0
,
"MainWindow"
);
qmlRegisterType
<
ApplicationBackground
>
(
"artikulate"
,
1
,
0
,
"ApplicationBackground"
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment