Skip to content

Commit

Permalink
Code guideline changes. Fix to maxOS download window crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
qt-training committed Jan 28, 2019
1 parent 9f657fd commit 4482b65
Show file tree
Hide file tree
Showing 37 changed files with 416 additions and 424 deletions.
48 changes: 24 additions & 24 deletions lib/tmcclient/course.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void Course::setId(int id)
/*!
Sets the course name to \a name.
*/
void Course::setName(QString name)
void Course::setName(const QString &name)
{
m_name = name;
}
Expand All @@ -88,7 +88,7 @@ QString Course::getTitle() const
return m_title;
}

void Course::setTitle(QString title)
void Course::setTitle(const QString &title)
{
m_title = title;
}
Expand Down Expand Up @@ -125,15 +125,15 @@ Exercise Course::getExercise(const int id)
If no such \l Exercise object is found in the \l Course object's collection,
the function returns a new \l Exercise object instantiated by \l Exercise::Exercise().
*/
Exercise Course::getExercise(const Exercise ex)
Exercise Course::getExercise(const Exercise &ex)
{
return m_exercises.value(ex.getId(), Exercise());
}

/*!
Adds parameter \a ex to the \l Course object's \l Exercise collection.
*/
void Course::addExercise(const Exercise ex)
void Course::addExercise(const Exercise &ex)
{
m_exercises.insert(ex.getId(), ex);
}
Expand All @@ -142,7 +142,7 @@ void Course::addExercise(const Exercise ex)
Returns \c true if the \l Course object's collection contains an \l Exercise
object with the same ID as that of parameter \a ex; otherwise returns \c false.
*/
bool Course::hasExercise(Exercise ex)
bool Course::hasExercise(const Exercise &ex)
{
return m_exercises.contains(ex.getId());
}
Expand All @@ -153,7 +153,7 @@ bool Course::hasExercise(Exercise ex)
The ID and name fields of the \l Course object are set to the values
extracted from \a jsonCourse.
*/
Course Course::fromJson(const QJsonObject jsonCourse)
Course Course::fromJson(const QJsonObject &jsonCourse)
{
Course course;
course.setTitle(jsonCourse["title"].toString());
Expand All @@ -168,12 +168,12 @@ Course Course::fromJson(const QJsonObject jsonCourse)
object includes setting the course name and ID to the values specified in \a
settings. If \a settings doesn't contain the appropriate values, defaults are used.
*/
Course Course::fromQSettings(QSettings *settings)
Course Course::fromQSettings(QSettings &settings)
{
Course course;
course.setName(settings->value("courseName", "").toString());
course.setTitle(settings->value("courseTitle", "").toString());
course.setId(settings->value("courseId", -1).toInt());
course.setName(settings.value("courseName", "").toString());
course.setTitle(settings.value("courseTitle", "").toString());
course.setId(settings.value("courseId", -1).toInt());
return course;
}

Expand All @@ -182,11 +182,11 @@ Course Course::fromQSettings(QSettings *settings)
the \l Course parameter \a c into the \l {http://doc.qt.io/qt-5/qsettings.html}
{QSettings} object pointed to by parameter \a settings.
*/
void Course::toQSettings(QSettings *settings, Course c)
void Course::toQSettings(QSettings &settings, const Course &c)
{
settings->setValue("courseName", c.getName());
settings->setValue("courseTitle", c.getTitle());
settings->setValue("courseId", c.getId());
settings.setValue("courseName", c.getName());
settings.setValue("courseTitle", c.getTitle());
settings.setValue("courseId", c.getId());
}

/*!
Expand All @@ -197,19 +197,19 @@ void Course::toQSettings(QSettings *settings, Course c)
list, they are preserved. Any new exercises from \a settings are added
to the existing ones.
*/
void Course::exerciseListFromQSettings(QSettings *settings)
{
settings->beginGroup(m_name);
QStringList exerciseList = settings->childGroups();
foreach (QString exercise, exerciseList) {
settings->beginGroup(exercise);
if (!QDir(settings->value("location", "?").toString()).exists() ) {
settings->endGroup();
void Course::exerciseListFromQSettings(QSettings &settings)
{
settings.beginGroup(m_name);
QStringList exerciseList = settings.childGroups();
for (const QString &exercise : exerciseList) {
settings.beginGroup(exercise);
if (!QDir(settings.value("location", "?").toString()).exists() ) {
settings.endGroup();
continue;
}
Exercise ex = Exercise::fromQSettings(settings, exercise);
settings->endGroup();
settings.endGroup();
addExercise(ex);
}
settings->endGroup();
settings.endGroup();
}
20 changes: 10 additions & 10 deletions lib/tmcclient/course.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ class Course
bool operator!=(const Course &other) const;
bool operator!() const;
explicit operator bool() const;

void setId(int id);
void setName(QString name);
void setName(const QString &name);
int getId() const;
QString getName() const;
QString getTitle() const;
void setTitle(QString title);
void setTitle(const QString &title);
Exercise getExercise(const int id);
Exercise getExercise(const Exercise ex);
void addExercise(const Exercise ex);
Exercise getExercise(const Exercise &ex);
void addExercise(const Exercise &ex);
QMap<int, Exercise> getExercises();
bool hasExercise(Exercise ex);
static Course fromJson(const QJsonObject jsonCourse);
static Course fromQSettings(QSettings *settings);
static void toQSettings(QSettings *settings, Course c);
void exerciseListFromQSettings(QSettings *settings);
bool hasExercise(const Exercise &ex);
static Course fromJson(const QJsonObject &jsonCourse);
static Course fromQSettings(QSettings &settings);
static void toQSettings(QSettings &settings, const Course &c);
void exerciseListFromQSettings(QSettings &settings);

private:
int m_id;
QString m_name;
Expand Down
50 changes: 25 additions & 25 deletions lib/tmcclient/exercise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Exercise::Exercise()
m_unzipped = false;
}

Exercise::Exercise(int id, QString name)
Exercise::Exercise(int id, const QString &name)
{
m_id = id;
m_name = name;
Expand Down Expand Up @@ -179,15 +179,15 @@ void Exercise::setId(int id)
/*!
Sets the exercise name to \a name.
*/
void Exercise::setName(QString name)
void Exercise::setName(const QString &name)
{
m_name = name;
}

/*!
Sets the directory location of the exercise to \a location.
*/
void Exercise::setLocation(QString location)
void Exercise::setLocation(const QString &location)
{
m_location = location;
}
Expand All @@ -196,7 +196,7 @@ void Exercise::setLocation(QString location)
Sets the TMC exercise checksum field of the \l Exercise object
to \a checksum.
*/
void Exercise::setChecksum(QString checksum)
void Exercise::setChecksum(const QString &checksum)
{
m_checksum = checksum;
}
Expand Down Expand Up @@ -246,19 +246,19 @@ void Exercise::setUnzipped(bool zipped)
is used as a prefix in forming the key names with \l
{http://doc.qt.io/qt-5/qsettings.html#beginGroup} {QSettings::beginGroup()}.
*/
void Exercise::saveQSettings(QSettings *settings, const QString courseName)
void Exercise::saveQSettings(QSettings &settings, const QString &courseName)
{
settings->beginGroup(courseName);
settings->beginGroup(m_name);
settings->setValue("id", m_id);
settings->setValue("checksum", m_checksum);
settings->setValue("location", m_location);
settings->setValue("deadline", m_deadline);
settings->setValue("state", m_state);
settings->setValue("downloaded", m_downloaded);
settings->setValue("unzipped", m_unzipped);
settings->endGroup();
settings->endGroup();
settings.beginGroup(courseName);
settings.beginGroup(m_name);
settings.setValue("id", m_id);
settings.setValue("checksum", m_checksum);
settings.setValue("location", m_location);
settings.setValue("deadline", m_deadline);
settings.setValue("state", m_state);
settings.setValue("downloaded", m_downloaded);
settings.setValue("unzipped", m_unzipped);
settings.endGroup();
settings.endGroup();
}

/*!
Expand All @@ -271,15 +271,15 @@ void Exercise::saveQSettings(QSettings *settings, const QString courseName)
parameter in the calling function using
\l {http://doc.qt.io/qt-5/qsettings.html#beginGroup} {QSettings::beginGroup()}.
*/
Exercise Exercise::fromQSettings(QSettings *settings, QString exerciseName)
Exercise Exercise::fromQSettings(QSettings &settings, const QString &exerciseName)
{
Exercise ex = Exercise(settings->value("id").toInt(), exerciseName);
ex.setChecksum(settings->value("checksum").toString());
ex.setLocation(settings->value("location").toString());
ex.setDeadline(settings->value("deadline").toString());
ex.setState(State(settings->value("state", 0).toInt()));
ex.setDownloaded(settings->value("downloaded", false).toBool());
ex.setUnzipped(settings->value("unzipped", false).toBool());
Exercise ex = Exercise(settings.value("id").toInt(), exerciseName);
ex.setChecksum(settings.value("checksum").toString());
ex.setLocation(settings.value("location").toString());
ex.setDeadline(settings.value("deadline").toString());
ex.setState(State(settings.value("state", 0).toInt()));
ex.setDownloaded(settings.value("downloaded", false).toBool());
ex.setUnzipped(settings.value("unzipped", false).toBool());
return ex;
}

Expand All @@ -291,7 +291,7 @@ Exercise Exercise::fromQSettings(QSettings *settings, QString exerciseName)
and \l {Exercise::getDlDate()} {deadline} fields to the values extracted from
\a jsonExercise.
*/
Exercise Exercise::fromJson(const QJsonObject jsonExercise)
Exercise Exercise::fromJson(const QJsonObject &jsonExercise)
{
Exercise fromJson = Exercise(jsonExercise["id"].toInt(),
jsonExercise["name"].toString());
Expand Down
15 changes: 7 additions & 8 deletions lib/tmcclient/exercise.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Exercise
{
public:
Exercise();
Exercise(int id, QString name);
Exercise(int id,const QString &name);

enum State {
None,
Expand All @@ -25,9 +25,9 @@ class Exercise
bool operator<(const Exercise &other) const;

void setId(int id);
void setName(QString name);
void setLocation(QString location);
void setChecksum(QString checksum);
void setName(const QString &name);
void setLocation(const QString &location);
void setChecksum(const QString &checksum);
void setDeadline(const QString &date);
void setState(State state);
void setDownloaded(bool downloaded);
Expand All @@ -45,13 +45,12 @@ class Exercise
bool isUnzipped() const;
QMap<int, Submission> getSubmissions() const;

void saveQSettings(QSettings *settings, const QString courseName);
static Exercise fromQSettings(QSettings *settings, QString exerciseName);
static Exercise fromJson(const QJsonObject jsonExercise);
void saveQSettings(QSettings &settings, const QString &courseName);
static Exercise fromQSettings(QSettings &settings, const QString &exerciseName);
static Exercise fromJson(const QJsonObject &jsonExercise);

private:
QMap<int, Submission> m_submissions;

QString m_name;
QString m_location;
QString m_checksum;
Expand Down
18 changes: 9 additions & 9 deletions lib/tmcclient/organization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Organization::Organization()
m_slug = "";
}

Organization::Organization(QString name, QString slug) :
Organization::Organization(const QString &name, const QString &slug) :
m_name(name),
m_slug(slug)
{
Expand Down Expand Up @@ -79,7 +79,7 @@ QString Organization::getSlug() const
/*!
Adds the \l Course parameter \a c to the collection of the organization's courses.
*/
void Organization::addCourse(Course c)
void Organization::addCourse(const Course &c)
{
m_courses.append(c);
}
Expand All @@ -100,10 +100,10 @@ QList<Course> Organization::getCourses()
The main purpose of the function is to preserve the user-selected organization
between sessions.
*/
Organization Organization::fromQSettings(QSettings *settings)
Organization Organization::fromQSettings(QSettings &settings)
{
return Organization(settings->value("orgName", "").toString(),
settings->value("orgSlug", "").toString());
return Organization(settings.value("orgName", "").toString(),
settings.value("orgSlug", "").toString());
}

/*!
Expand All @@ -112,10 +112,10 @@ Organization Organization::fromQSettings(QSettings *settings)
\a org in the \l {http://doc.qt.io/qt-5/qsettings.html} {QSettings}
parameter \a settings.
*/
void Organization::toQSettings(QSettings *settings, Organization org)
void Organization::toQSettings(QSettings &settings, const Organization &org)
{
settings->setValue("orgName", org.getName());
settings->setValue("orgSlug", org.getSlug());
settings.setValue("orgName", org.getName());
settings.setValue("orgSlug", org.getSlug());
}

/*!
Expand All @@ -125,7 +125,7 @@ void Organization::toQSettings(QSettings *settings, Organization org)
fields of the \l Organization object are set to the values extracted from
\a jsonOrg.
*/
Organization Organization::fromJson(const QJsonObject jsonOrg)
Organization Organization::fromJson(const QJsonObject &jsonOrg)
{
Organization fromJson = Organization(
jsonOrg["name"].toString(),
Expand Down
10 changes: 5 additions & 5 deletions lib/tmcclient/organization.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ class Organization
{
public:
Organization();
Organization(QString name, QString slug);
Organization(const QString &name, const QString &slug);
bool operator==(const Organization &other) const;
bool operator!=(const Organization &other) const;
bool operator!() const;

QString getName() const;
QString getSlug() const;
void addCourse(Course c);
void addCourse(const Course &c);
QList<Course> getCourses();

static Organization fromQSettings(QSettings *settings);
static Organization fromJson(const QJsonObject jsonOrg);
static void toQSettings(QSettings *settings, Organization org);
static Organization fromQSettings(QSettings &settings);
static Organization fromJson(const QJsonObject &jsonOrg);
static void toQSettings(QSettings &settings, const Organization &org);

private:
QString m_name;
Expand Down
2 changes: 1 addition & 1 deletion lib/tmcclient/submission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Submission Submission::fromJson(const int id, const QJsonObject jsonSubmission)
submission.setStatus(Status::Fail);
QList<TestCase> testCases;
QJsonArray jsonCases = jsonSubmission["test_cases"].toArray();
foreach (QJsonValue jsonCase, jsonCases) {
for (QJsonValue jsonCase : jsonCases) {
testCases << TestCase::fromJson(jsonCase.toObject());
}
submission.setTestCases(testCases);
Expand Down
Loading

0 comments on commit 4482b65

Please sign in to comment.