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

Clazy fixes

parent dee3a9f7
......@@ -83,14 +83,14 @@ void TestCourseFiles::fileLoadSaveCompleteness()
manager.addCourse(QUrl::fromLocalFile(QStringLiteral("data/courses/de.xml")));
// test to encure further logic
QVERIFY(manager.courseResources(manager.languageResources().first()->language()).count() == 1);
QVERIFY(manager.courseResources(manager.languageResources().constFirst()->language()).count() == 1);
Course *testCourse = manager.courseResources(manager.languageResources().first()->language()).first()->course();
Course *testCourse = manager.courseResources(manager.languageResources().constFirst()->language()).constFirst()->course();
QTemporaryFile outputFile;
outputFile.open();
QUrl oldFileName = testCourse->file();
testCourse->setFile(QUrl::fromLocalFile(outputFile.fileName()));
testCourse->setLanguage(manager.languageResources().first()->language());
testCourse->setLanguage(manager.languageResources().constFirst()->language());
testCourse->sync();
testCourse->setFile(oldFileName); // restore for later tests
......@@ -101,7 +101,7 @@ void TestCourseFiles::fileLoadSaveCompleteness()
//TODO this only works, since the resource manager not checks uniqueness of course ids!
manager.addCourse(QUrl::fromLocalFile(outputFile.fileName()));
Course *compareCourse = manager.courseResources(manager.languageResources().first()->language()).last()->course();
Course *compareCourse = manager.courseResources(manager.languageResources().constFirst()->language()).constLast()->course();
// test that we actually call the different files
QVERIFY(testCourse->file().toLocalFile() != compareCourse->file().toLocalFile());
......@@ -112,14 +112,14 @@ void TestCourseFiles::fileLoadSaveCompleteness()
QVERIFY(testCourse->language()->id() == compareCourse->language()->id());
QVERIFY(testCourse->unitList().count() == compareCourse->unitList().count());
Unit *testUnit = testCourse->unitList().first();
Unit *compareUnit = compareCourse->unitList().first();
Unit *testUnit = testCourse->unitList().constFirst();
Unit *compareUnit = compareCourse->unitList().constFirst();
QVERIFY(testUnit->id() == compareUnit->id());
QVERIFY(testUnit->foreignId() == compareUnit->foreignId());
QVERIFY(testUnit->title() == compareUnit->title());
QVERIFY(testUnit->phraseList().count() == compareUnit->phraseList().count());
Phrase *testPhrase = testUnit->phraseList().first();
Phrase *testPhrase = testUnit->phraseList().constFirst();
Phrase *comparePhrase = new Phrase(this);
// Note that this actually means that we DO NOT respect phrase orders by list order!
foreach (Phrase *phrase, compareUnit->phraseList()) {
......
......@@ -75,7 +75,7 @@ void Learner::setIdentifier(int identifier)
QString Learner::imageUrl() const
{
QString path = d->imagePath();
if (!QFileInfo(path).exists()) {
if (!QFileInfo::exists(path)) {
return QString();
}
return "file://" + path;
......@@ -84,7 +84,7 @@ QString Learner::imageUrl() const
void Learner::clearImage()
{
const QString path {d->imagePath()};
if (!QFileInfo(path).exists()) {
if (!QFileInfo::exists(path)) {
return;
}
QFile file;
......@@ -96,7 +96,7 @@ void Learner::clearImage()
void Learner::importImage(const QString &path)
{
if (!QFileInfo(path).exists()) {
if (!QFileInfo::exists(path)) {
qCWarning(LIBLEARNER_LOG) << "image path points to a non-existing file, aborting: " << path;
return;
}
......
......@@ -71,7 +71,7 @@ void LearningGoal::setName(const QString &name)
return;
}
d->m_name = name;
nameChanged();
emit nameChanged();
}
QString LearningGoal::identifier() const
......
......@@ -136,7 +136,7 @@ void LearningGoalModel::setLearner(Learner *learner)
if (!learner) {
return;
}
emit beginResetModel();
beginResetModel();
if (d->m_learner) {
learner->disconnect(this);
}
......@@ -150,7 +150,7 @@ void LearningGoalModel::setLearner(Learner *learner)
connect(learner, &Learner::goalAboutToBeRemoved, this,
&LearningGoalModel::onLearningGoalAboutToBeRemoved);
emit learnerChanged();
emit endResetModel();
endResetModel();
}
QVariant LearningGoalModel::data(const QModelIndex &index, int role) const
......
......@@ -57,7 +57,7 @@ QString Storage::errorMessage() const
void Storage::raiseError(const QSqlError &error)
{
m_errorMessage = QStringLiteral("%1 : %2").arg(error.driverText()).arg(error.databaseText());
m_errorMessage = QStringLiteral("%1 : %2").arg(error.driverText(), error.databaseText());
emit errorMessageChanged();
}
......
......@@ -28,7 +28,6 @@ QtMultimediaCaptureBackend::QtMultimediaCaptureBackend(QObject *parent)
: CaptureBackendInterface(parent)
, m_recorder(new QAudioRecorder)
{
QString selectedInput = m_recorder->defaultAudioInput();
QAudioEncoderSettings audioSettings;
audioSettings.setCodec(QStringLiteral("audio/vorbis"));
audioSettings.setQuality(QMultimedia::HighQuality);
......
......@@ -161,7 +161,7 @@ void Course::addUnit(Unit *unit)
emit unitAboutToBeAdded(unit, m_unitList.length());
m_unitList.append(unit);
connect(unit, &Unit::modified, [=]() {
connect(unit, &Unit::modified, this, [=]() {
setModified(true);
});
......@@ -226,42 +226,36 @@ Phrase * Course::createPhrase(Unit *unit)
QList< Unit* > Course::phonemeUnitList(PhonemeGroup *phonemeGroup) const
{
QList<Unit*> list;
QList< QPair<Phoneme*,Unit*> >::ConstIterator iter = m_phonemeUnitList.value(phonemeGroup).constBegin();
while (iter != m_phonemeUnitList.value(phonemeGroup).constEnd()) {
list.append(iter->second);
++iter;
for (const auto &group : m_phonemeUnitList.value(phonemeGroup)) {
list.append(group.second);
}
return list;
}
Unit * Course::phonemeUnit(Phoneme *phoneme) const
{
foreach (PhonemeGroup *group, m_phonemeUnitList.keys()) {
m_phonemeUnitList.value(group);
QList< QPair<Phoneme*,Unit*> >::ConstIterator iter = m_phonemeUnitList.value(group).constBegin();
while (iter != m_phonemeUnitList.value(group).constEnd()) {
if (iter->first == phoneme) {
return iter->second;
for (auto group = m_phonemeUnitList.keyBegin(); group != m_phonemeUnitList.keyEnd(); ++group) {
m_phonemeUnitList.value(*group);
for (const auto &phonemeUnit : m_phonemeUnitList.value(*group)) {
if (phonemeUnit.first == phoneme) {
return phonemeUnit.second;
}
++iter;
}
}
return 0;
return nullptr;
}
PhonemeGroup * Course::phonemeGroup(Unit *unit) const
{
foreach (PhonemeGroup *group, m_phonemeUnitList.keys()) {
m_phonemeUnitList.value(group);
QList< QPair<Phoneme*,Unit*> >::ConstIterator iter = m_phonemeUnitList.value(group).constBegin();
while (iter != m_phonemeUnitList.value(group).constEnd()) {
if (iter->second == unit) {
return group;
for (auto group = m_phonemeUnitList.keyBegin(); group != m_phonemeUnitList.keyEnd(); ++group) {
m_phonemeUnitList.value(*group);
for (const auto &phonemeUnit : m_phonemeUnitList.value(*group)) {
if (phonemeUnit.second == unit) {
return *group;
}
++iter;
}
}
return 0;
return nullptr;
}
void Course::addPhonemeGroup(PhonemeGroup *phonemeGroup)
......@@ -301,7 +295,7 @@ void Course::setModified(bool modified)
void Course::sync()
{
if (!m_file.isValid() || m_file.isEmpty() || m_resource == 0) {
if (!m_file.isValid() || m_file.isEmpty() || m_resource == nullptr) {
qCritical() << "Path" << m_file.toLocalFile() << "not valid, aborting sync operation.";
return;
}
......@@ -325,13 +319,11 @@ void Course::registerPhrasePhonemes(Phrase *phrase)
}
// either add phrase to existing unit or register a new one
bool phraseRegistered = false;
QList< QPair<Phoneme*,Unit*> >::ConstIterator iter = m_phonemeUnitList.value(group).constBegin();
while (iter != m_phonemeUnitList.value(group).constEnd()) {
if (iter->first->id() == phoneme->id()) {
iter->second->addPhrase(phrase);
for (const auto &phonemeUnit : m_phonemeUnitList.value(group)) {
if (phonemeUnit.first->id() == phoneme->id()) {
phonemeUnit.second->addPhrase(phrase);
phraseRegistered = true;
}
++iter;
}
// otherwise, need to create a new unit
if (phraseRegistered == false) {
......
......@@ -59,7 +59,8 @@ QList<QObject *> DrawerTrainingActions::actions() const
return QList<QObject *>();
}
QList<QObject *> actions;
for (const auto &action : m_session->trainingActions()) {
const auto trainingActions = m_session->trainingActions();
for (const auto &action : qAsConst(trainingActions)) {
actions.append(qobject_cast<QObject*>(action));
}
return actions;
......
......@@ -98,7 +98,7 @@ void EditorSession::setSkeleton(Skeleton *skeleton)
Language *language = m_language;
if (!m_language) {
language = m_resourceManager->languageResources().first()->language();
language = m_resourceManager->languageResources().constFirst()->language();
}
if (m_skeleton) {
......@@ -168,7 +168,7 @@ void EditorSession::setCourse(Course *course)
}
m_course = course;
if (m_course && !m_course->unitList().isEmpty()) {
setUnit(m_course->unitList().first());
setUnit(m_course->unitList().constFirst());
} else {
setUnit(nullptr);
}
......@@ -189,7 +189,7 @@ void EditorSession::setUnit(Unit *unit)
// different than above, do not directly enter phrases
// but first show editing information for units
setPhrase(nullptr);
return unitChanged();
emit unitChanged();
}
void EditorSession::setPhrase(Phrase *phrase)
......@@ -201,7 +201,7 @@ void EditorSession::setPhrase(Phrase *phrase)
setUnit(phrase->unit());
}
m_phrase = phrase;
return phraseChanged();
emit phraseChanged();
}
Phrase * EditorSession::phrase() const
......@@ -243,7 +243,7 @@ Phrase * EditorSession::nextPhrase() const
if (nextUnit->phraseList().isEmpty()) {
return nullptr;
}
return nextUnit->phraseList().first();
return nextUnit->phraseList().constFirst();
}
}
return nullptr;
......
......@@ -91,7 +91,6 @@ void ResourceManager::loadCourseResources()
// traverse all language directories for each course
foreach (const QFileInfo &langInfo, courseLangDirList) {
QString languageId = langInfo.fileName();
QDir courseLangDir = QDir(langInfo.absoluteFilePath());
courseLangDir.setFilter(QDir::Files);
QStringList nameFilters;
......@@ -414,10 +413,10 @@ Course * ResourceManager::createCourse(Language *language, Skeleton *skeleton)
{
// set path
QString path = QStringLiteral("%1/%2/%3/%4/%4.xml")
.arg(Settings::courseRepositoryPath())
.arg(QStringLiteral("courses"))
.arg(skeleton->id())
.arg(language->id());
.arg(Settings::courseRepositoryPath(),
QStringLiteral("courses"),
skeleton->id(),
language->id());
CourseResource * courseRes = new CourseResource(this, QUrl::fromLocalFile(path));
Q_ASSERT(courseRes);
......
......@@ -60,7 +60,7 @@ void TrainingSession::setCourse(Course *course)
}
m_course = course;
if (m_course && m_course->unitList().count() > 0) {
setUnit(m_course->unitList().first());
setUnit(m_course->unitList().constFirst());
}
// lazy loading of training data
......@@ -101,9 +101,9 @@ void TrainingSession::setUnit(Unit *unit)
}
m_unit = unit;
if (m_unit && m_unit->phraseList().count() > 0) {
setPhrase(m_unit->phraseList().first());
setPhrase(m_unit->phraseList().constFirst());
}
return unitChanged();
emit unitChanged();
}
TrainingAction * TrainingSession::activeAction() const
......@@ -244,7 +244,7 @@ void TrainingSession::updateGoal()
QVector<TrainingAction *> TrainingSession::trainingActions()
{
// cleanup
for (const auto &action : m_actions) {
for (const auto &action : qAsConst(m_actions)) {
action->deleteLater();
}
m_actions.clear();
......@@ -253,9 +253,11 @@ QVector<TrainingAction *> TrainingSession::trainingActions()
return QVector<TrainingAction *>();
}
for (const auto &unit : m_course->unitList()) {
const auto unitList = m_course->unitList();
for (const auto &unit : qAsConst(unitList)) {
auto action = new TrainingAction(unit->title());
for (const auto &phrase : unit->phraseList()) {
const auto phraseList = unit->phraseList();
for (const auto &phrase : qAsConst(phraseList)) {
if (phrase->sound().isEmpty()) {
continue;
}
......
......@@ -91,15 +91,15 @@ MainWindow::MainWindow()
}
// connect to QML signals;
connect(rootObjects().first(), SIGNAL(triggerSettingsDialog()),
connect(rootObjects().constFirst(), SIGNAL(triggerSettingsDialog()),
this, SLOT(showSettingsDialog()));
connect(rootObjects().first(), SIGNAL(triggerAction(QString)),
connect(rootObjects().constFirst(), SIGNAL(triggerAction(QString)),
this, SLOT(triggerAction(QString)));
connect(rootObjects().first(), SIGNAL(switchMenuBarVisibility()),
connect(rootObjects().constFirst(), SIGNAL(switchMenuBarVisibility()),
this, SLOT(switchMenuBarVisibility()));
// set font for the phrase in trainer to default from kcfg file
QObject *phraseText = rootObjects().first()->findChild<QObject*>(QStringLiteral("phraseText"));
QObject *phraseText = rootObjects().constFirst()->findChild<QObject*>(QStringLiteral("phraseText"));
if (phraseText) {
phraseText->setProperty("font", Settings::trainingPhraseFont());
}
......@@ -176,12 +176,11 @@ void MainWindow::showSettingsDialog()
void MainWindow::updateTrainingPhraseFont()
{
QObject *phraseText = rootObjects().first()->findChild<QObject*>(QStringLiteral("phraseText"));
QObject *phraseText = rootObjects().constFirst()->findChild<QObject*>(QStringLiteral("phraseText"));
if (!phraseText) {
qCDebug(ARTIKULATE_LOG) << "no phraseText context object found, aborting";
return;
}
QFont f = phraseText->property("font").value<QFont>();
phraseText->setProperty("font", Settings::trainingPhraseFont());
}
......
......@@ -99,7 +99,7 @@ MainWindowEditor::MainWindowEditor()
statusBar()->setEnabled(true);
QLabel *repositoryLabel = new QLabel;
repositoryLabel->setText(i18n("Course Repository: %1", m_resourceManager->repositoryUrl()));
connect(m_resourceManager, &ResourceManager::repositoryChanged, [=]() {
connect(m_resourceManager, &ResourceManager::repositoryChanged, this, [=]() {
repositoryLabel->setText(i18n("Course Repository: %1", m_resourceManager->repositoryUrl()));
});
statusBar()->insertWidget(0, repositoryLabel);
......@@ -127,7 +127,7 @@ void MainWindowEditor::setupActions()
settingsAction->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
QAction *exportAction = new QAction(i18nc("@item:inmenu", "Export GHNS Files"), this);
connect(exportAction, &QAction::triggered, [=]() {
connect(exportAction, &QAction::triggered, this, [=]() {
QPointer<QDialog> dialog = new ExportGhnsDialog(m_resourceManager);
dialog->exec();
});
......@@ -144,7 +144,7 @@ void MainWindowEditor::showSettingsDialog()
if (KConfigDialog::showDialog(QStringLiteral("settings"))) {
return;
}
QPointer<KConfigDialog> dialog = new KConfigDialog(0, QStringLiteral("settings"), Settings::self());
QPointer<KConfigDialog> dialog = new KConfigDialog(nullptr, QStringLiteral("settings"), Settings::self());
ResourcesDialogPage *resourceDialog = new ResourcesDialogPage(m_resourceManager);
SoundDeviceDialogPage *soundDialog = new SoundDeviceDialogPage();
......
......@@ -95,11 +95,11 @@ Language * CourseModel::language() const
void CourseModel::setLanguage(Language *language)
{
emit beginResetModel();
beginResetModel();
m_language = language;
m_resources = m_resourceManager->courseResources(m_language);
emit languageChanged();
emit endResetModel();
endResetModel();
emit rowCountChanged();
}
......
......@@ -195,17 +195,17 @@ void LanguageResourceModel::setView(LanguageModel::LanguageResourceView view)
if (m_view == view) {
return;
}
emit beginResetModel();
beginResetModel();
m_view = view;
updateResources();
emit endResetModel();
endResetModel();
}
void LanguageResourceModel::updateDisplayedLanguages()
{
emit beginResetModel();
beginResetModel();
updateResources();
emit endResetModel();
endResetModel();
}
LanguageModel::LanguageResourceView LanguageResourceModel::view() const
......
......@@ -53,12 +53,10 @@ Language * PhonemeModel::language() const
void PhonemeModel::setLanguage(Language *language)
{
emit beginResetModel();
beginResetModel();
m_language = language;
emit languageChanged();
emit endResetModel();
endResetModel();
}
QVariant PhonemeModel::data(const QModelIndex& index, int role) const
......
......@@ -108,7 +108,7 @@ bool PhraseFilterModel::filterAcceptsRow(int source_row, const QModelIndex &sour
int result = true;
if (m_hideNotRecorded || m_hideExcluded) {
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
bool notRecorded = sourceModel()->data(index, PhraseListModel::SoundFileRole).value<QUrl>().isEmpty();
bool notRecorded = sourceModel()->data(index, PhraseListModel::SoundFileRole).toUrl().isEmpty();
bool excluded = sourceModel()->data(index, PhraseListModel::ExcludedRole).toBool();
result = !(notRecorded || excluded);
}
......
......@@ -39,7 +39,7 @@ ResourcesDialogPage::ResourcesDialogPage(ResourceManager *m_resourceManager)
ui = new Ui::ResourcesDialogPage;
ui->setupUi(this);
connect(ui->buttonSelectCourseRepository, &QToolButton::clicked, [=](){
connect(ui->buttonSelectCourseRepository, &QToolButton::clicked, this, [=](){
const QString dir = QFileDialog::getExistingDirectory(this,
i18n("Open Repository Directory"),
QString(),
......
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