Skip to content

Commit

Permalink
Merge pull request #41 from UltraStar-Deluxe/fix_most_clazy_issues
Browse files Browse the repository at this point in the history
Fix most clazy issues.
  • Loading branch information
bohning authored Sep 14, 2024
2 parents 859e442 + f4301c2 commit 442c326
Show file tree
Hide file tree
Showing 33 changed files with 245 additions and 238 deletions.
16 changes: 8 additions & 8 deletions src/QUMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void QUMainWindow::initWindow() {
windowIcon.addFile(":/icons/UltraStar-Manager128.png", QSize(128, 128));

setWindowIcon(windowIcon);
setWindowTitle(QString("%1%2").arg(tr("UltraStar Manager")).arg(WIP_TEXT));
setWindowTitle(QString("%1%2").arg(tr("UltraStar Manager"), WIP_TEXT));
resize(1000, 500);

addDockWidget(Qt::LeftDockWidgetArea, detailsDock);
Expand Down Expand Up @@ -743,25 +743,25 @@ void QUMainWindow::editSongSetFileLink(QTreeWidgetItem *item, int column) {
if( songItem->icon(MP3_COLUMN).isNull()
&& QUSongSupport::allowedAudioFiles().contains(fileScheme, Qt::CaseInsensitive)
&& column == MP3_COLUMN ) {
logSrv->add(QString(tr("Audio file changed from \"%1\" to: \"%2\".")).arg(song->mp3()).arg(songItem->text(FOLDER_COLUMN)), QU::Information);
logSrv->add(QString(tr("Audio file changed from \"%1\" to: \"%2\".")).arg(song->mp3(), songItem->text(FOLDER_COLUMN)), QU::Information);
song->setInfo(MP3_TAG, songItem->text(FOLDER_COLUMN));
song->save();
} else if( songItem->icon(COVER_COLUMN).isNull()
&& QUSongSupport::allowedImageFiles().contains(fileScheme, Qt::CaseInsensitive)
&& column == COVER_COLUMN ) {
logSrv->add(QString(tr("Cover changed from \"%1\" to: \"%2\".")).arg(song->cover()).arg(songItem->text(FOLDER_COLUMN)), QU::Information);
logSrv->add(QString(tr("Cover changed from \"%1\" to: \"%2\".")).arg(song->cover(), songItem->text(FOLDER_COLUMN)), QU::Information);
song->setInfo(COVER_TAG, songItem->text(FOLDER_COLUMN));
song->save();
} else if( songItem->icon(BACKGROUND_COLUMN).isNull()
&& QUSongSupport::allowedImageFiles().contains(fileScheme, Qt::CaseInsensitive)
&& column == BACKGROUND_COLUMN ) {
logSrv->add(QString(tr("Background changed from \"%1\" to: \"%2\".")).arg(song->background()).arg(songItem->text(FOLDER_COLUMN)), QU::Information);
logSrv->add(QString(tr("Background changed from \"%1\" to: \"%2\".")).arg(song->background(), songItem->text(FOLDER_COLUMN)), QU::Information);
song->setInfo(BACKGROUND_TAG, songItem->text(FOLDER_COLUMN));
song->save();
} else if( songItem->icon(VIDEO_COLUMN).isNull()
&& QUSongSupport::allowedVideoFiles().contains(fileScheme, Qt::CaseInsensitive)
&& column == VIDEO_COLUMN ) {
logSrv->add(QString(tr("Video file changed from \"%1\" to: \"%2\".")).arg(song->video()).arg(songItem->text(FOLDER_COLUMN)), QU::Information);
logSrv->add(QString(tr("Video file changed from \"%1\" to: \"%2\".")).arg(song->video(), songItem->text(FOLDER_COLUMN)), QU::Information);
song->setInfo(VIDEO_TAG, songItem->text(FOLDER_COLUMN));
song->save();
}
Expand Down Expand Up @@ -792,7 +792,7 @@ void QUMainWindow::editSongSetDetail(QTableWidgetItem *item) {

// save changes for each song
foreach(QUSongItem *songItem, selectedItems) {
dlg.update(QString("%1 - %2").arg(songItem->song()->artist()).arg(songItem->song()->title()));
dlg.update(QString("%1 - %2").arg(songItem->song()->artist(), songItem->song()->title()));
if(dlg.cancelled()) break;

// delete medley tags if CALCMEDLEY_TAG is set to OFF
Expand Down Expand Up @@ -835,7 +835,7 @@ void QUMainWindow::editSongApplyTasks() {
QUSongFile *song = songItem->song();
itemExpandedStates.append(songItem->isExpanded());

dlg.update(QString("%1 - %2").arg(song->artist()).arg(song->title()));
dlg.update(QString("%1 - %2").arg(song->artist(), song->title()));
if(dlg.cancelled()) break;

songDB->ignoreChangesForSong(song);
Expand Down Expand Up @@ -942,7 +942,7 @@ void QUMainWindow::saveLog() {
out.setGenerateByteOrderMark(true);

for(int row = 0; row < log->count(); ++row) {
out << QString("%1 %2").arg(log->item(row)->data(Qt::UserRole).toString()).arg(log->item(row)->text()) << Qt::endl;
out << QString("%1 %2").arg(log->item(row)->data(Qt::UserRole).toString(), log->item(row)->text()) << Qt::endl;
}
file.close();

Expand Down
29 changes: 19 additions & 10 deletions src/QUSongSupport.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "QUSongSupport.h"
#include "QUSongSupport.h"
#include "QUSongInterface.h"

#include <QMap>
Expand Down Expand Up @@ -488,39 +488,48 @@ QStringList QUSongSupport::availableSongYears() {
}

QString QUSongSupport::defaultInputEncoding() {
return registryKey("defaultInputEncoding", "CP1252").first();
QStringList result = registryKey("defaultInputEncoding", "CP1252");
return result.first();
}

int QUSongSupport::mediumMp3Quality() {
return registryKey("mediumMp3Quality", "96").first().toInt();
QStringList result = registryKey("mediumMp3Quality", "96");
return result.first().toInt();
}

int QUSongSupport::highMp3Quality() {
return registryKey("highMp3Quality", "128").first().toInt();
QStringList result = registryKey("highMp3Quality", "128");
return result.first().toInt();
}

int QUSongSupport::mediumCoverQuality() {
return registryKey("mediumCoverQuality", "400 x 400").first().toInt();
QStringList result = registryKey("mediumCoverQuality", "400 x 400");
return result.first().toInt();
}

int QUSongSupport::highCoverQuality() {
return registryKey("highCoverQuality", "600 x 600").first().toInt();
QStringList result = registryKey("highCoverQuality", "600 x 600");
return result.first().toInt();
}

int QUSongSupport::mediumBackgroundQuality() {
return registryKey("mediumBackgroundQuality", "1280 x 720").first().toInt();
QStringList result = registryKey("mediumBackgroundQuality", "1280 x 720");
return result.first().toInt();
}

int QUSongSupport::highBackgroundQuality() {
return registryKey("highBackgroundQuality", "1920 x 1080").first().toInt();
QStringList result = registryKey("highBackgroundQuality", "1920 x 1080");
return result.first().toInt();
}

int QUSongSupport::mediumVideoQuality() {
return registryKey("mediumVideoQuality", "1280 x 720").first().toInt();
QStringList result = registryKey("mediumVideoQuality", "1280 x 720");
return result.first().toInt();
}

int QUSongSupport::highVideoQuality() {
return registryKey("highVideoQuality", "1920 x 1080").first().toInt();
QStringList result = registryKey("highVideoQuality", "1920 x 1080");
return result.first().toInt();
}

/*!
Expand Down
24 changes: 15 additions & 9 deletions src/QUStringSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ QString QUStringSupport::withoutUnsupportedCharacters(const QString &text) {
// replace asterixes by dashes
cleanText.replace('*', '-');
// remove everything else: '\', ':', '*', '?', '"', '|', '<', '>', '^'
cleanText.remove(QRegularExpression("[\\\\:\\*\\?\"\\|<>\\^]"));
static const QRegularExpression regex("[\\\\:\\*\\?\"\\|<>\\^]");
cleanText.remove(regex);

bool dotsRemoved = false;

Expand Down Expand Up @@ -52,8 +53,8 @@ QString QUStringSupport::withoutPathDelimiters(const QString &text) {
* Remove all "folder tags" like [SC], [VIDEO], a.s.o. from the given text.
*/
QString QUStringSupport::withoutFolderTags(const QString &text) {
QRegularExpression rx("\\[.*\\]", QRegularExpression::InvertedGreedinessOption);
return QString(text).remove(rx).trimmed();
static const QRegularExpression regex("\\[.*\\]", QRegularExpression::InvertedGreedinessOption);
return QString(text).remove(regex).trimmed();
}

/*!
Expand Down Expand Up @@ -109,12 +110,17 @@ QString QUStringSupport::simplifiedQueryString(const QString &text) {
QString result = text;

// remove any additions in parentheses
result.remove(QRegularExpression("\\(.*\\)"));
static const QRegularExpression regex1("\\(.*\\)");
result.remove(regex1);
// remove additional artists listed as 'feat.', 'ft.', 'with' or 'vs.'/'vs'
result.remove(QRegularExpression(" feat\\. .*"));
result.remove(QRegularExpression(" ft\\. .*"));
result.remove(QRegularExpression(" with .*"));
result.remove(QRegularExpression(" vs\\.? .*"));
static const QRegularExpression regex2(" feat\\. .*");
result.remove(regex2);
static const QRegularExpression regex3(" ft\\. .*");
result.remove(regex3);
static const QRegularExpression regex4(" with .*");
result.remove(regex4);
static const QRegularExpression regex5(" vs\\.? .*");
result.remove(regex5);
// remove the ampersand character
result.replace(" & ", " ");
// remove the plus character
Expand All @@ -129,7 +135,7 @@ QString QUStringSupport::simplifiedQueryString(const QString &text) {
}

QStringList QUStringSupport::extractTags(const QString &text) {
QRegularExpression rx = QRegularExpression("\\[([^\\]]+)\\]");
static const QRegularExpression rx = QRegularExpression("\\[([^\\]]+)\\]");
QRegularExpressionMatchIterator i = rx.globalMatch(text);

QStringList tags;
Expand Down
12 changes: 7 additions & 5 deletions src/filter/QUMetaphoneString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
#include <QRegularExpression>

bool QUMetaphoneString::isSlavoGermanic() {
return contains(QRegularExpression("W|K|CZ|WITZ"));
static const QRegularExpression regex("W|K|CZ|WITZ");
return contains(regex);
}

bool QUMetaphoneString::hasVowel(int at) {
if( (at < 0) || (at >= _length) )
return false;

return QRegularExpression(QRegularExpression::anchoredPattern("[AEIOUY]")).match(mid(at, 1)).hasMatch();
static const QRegularExpression regex(QRegularExpression::anchoredPattern("[AEIOUY]"));
return regex.match(mid(at, 1)).hasMatch();
}


Expand Down Expand Up @@ -815,9 +817,9 @@ bool QUMetaphoneString::equal(QString token1, QString token2, bool ignoreEmpty)
// replace "lonely, unimportant" words
token1.append(' '); token1.prepend(' ');
token2.append(' '); token2.prepend(' ');
QRegularExpression rx(" THE | DER | DIE | DAS | A | AN | EIN ");
token1.replace(rx, " ");
token2.replace(rx, " ");
static const QRegularExpression regex(" THE | DER | DIE | DAS | A | AN | EIN ");
token1.replace(regex, " ");
token2.replace(regex, " ");

token1 = token1.simplified().trimmed();
token2 = token2.simplified().trimmed();
Expand Down
9 changes: 5 additions & 4 deletions src/lyricseditor/QULyricsEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ void QULyricsEdit::initLyrics() {
setItem(index, 0, timeItem);
setRowHeight(index, 16);

if(!line->notes().isEmpty() && bpm != 0.0) { // show timestamps
auto notes = line->notes();
if(!notes.isEmpty() && bpm != 0.0) { // show timestamps
if(!_song->isRelative()) {
beats = line->notes().first()->timestamp();
beats = notes.first()->timestamp();
} else {
beats += line->notes().first()->timestamp();
beats += notes.first()->timestamp();
}

int seconds = qMax(0, int((beats / (bpm * 4)) * 60 + gap));
Expand All @@ -88,7 +89,7 @@ void QULyricsEdit::initLyrics() {
.arg(int(seconds % 60), 2, 10, QChar('0')));

if(_song->isRelative())
beats += line->inTime() - line->notes().first()->timestamp();
beats += line->inTime() - notes.first()->timestamp();
}

index++;
Expand Down
2 changes: 1 addition & 1 deletion src/lyricseditor/QULyricsEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ QULyricsEditorDialog::QULyricsEditorDialog(QUSongFile *song, QWidget *parent): Q
connect(searchEdit, SIGNAL(textEdited(QString)), this, SLOT(search(QString)));

textLbl->setText(tr("Edit each syllable of each line and <b>fix spelling</b> or <b>wrong whitespaces</b> manually."));
this->setWindowTitle(QString(tr("Edit Lyrics: \"%1 - %2\"")).arg(song->artist()).arg(song->title()));
this->setWindowTitle(QString(tr("Edit Lyrics: \"%1 - %2\"")).arg(song->artist(), song->title()));
songLbl->setText(song->songFileInfo().fileName());
}

Expand Down
5 changes: 3 additions & 2 deletions src/mediaplayer/QUAutoCue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ void QUAutoCue::reset(const QList<QUSongLineInterface*> &lines, double bpm, doub
int lineNumber = 0;
foreach(QUSongLineInterface *line, lines) {
int last = 0;
foreach(QUSongNoteInterface *note, line->notes()) {
if(note != line->notes().first()) {
auto notes = line->notes();
foreach(QUSongNoteInterface *note, notes) {
if(note != notes.first()) {
if(last == note->timestamp()) // no space
_cueList.pop_back();
}
Expand Down
4 changes: 2 additions & 2 deletions src/mediaplayer/QUMediaPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void QUMediaPlayer::play() {
_freeIndices.removeAll(_currentSongIndex);

if(!info.isValid()) {
logSrv->add(tr("[Media Player] The song \"%1 - %2\" has no valid audio file.").arg(info.artist).arg(info.title), QU::Warning);
logSrv->add(tr("[Media Player] The song \"%1 - %2\" has no valid audio file.").arg(info.artist, info.title), QU::Warning);
loopBtn->setChecked(false); // avoid endless-loops
next();
return;
Expand Down Expand Up @@ -296,7 +296,7 @@ void QUMediaPlayer::updateInfoLabel(QUMediaPlayer::States state) {
return; // invalid index

QUSongInfo info = _songs.at(_currentSongIndex);
currentSongLbl->setText(QString("%1<br><b>%2</b>").arg(info.artist).arg(info.title));
currentSongLbl->setText(QString("%1<br><b>%2</b>").arg(info.artist, info.title));
infoIconLbl->setToolTip(
QString(tr("Bitrate: <b>%1</b> kbit/s<br>Channels: <b>%2</b><br>Sample Rate: <b>%3</b> kHz"))
.arg(info.bitrate)
Expand Down
10 changes: 5 additions & 5 deletions src/playlist/QUPlaylistDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void QUPlaylistDatabase::connectAllPlaylists() {
dlg.show();

foreach(QUPlaylistFile *playlist, _playlists) {
dlg.update(QString("%1 (%2)").arg(playlist->name()).arg(playlist->fileInfo().fileName()));
dlg.update(QString("%1 (%2)").arg(playlist->name(), playlist->fileInfo().fileName()));
playlist->connectSongs();
}

Expand All @@ -75,7 +75,7 @@ void QUPlaylistDatabase::disconnectAllPlaylists() {
dlg.show();

foreach(QUPlaylistFile *playlist, _playlists) {
dlg.update(QString("%1 (%2)").arg(playlist->name()).arg(playlist->fileInfo().fileName()));
dlg.update(QString("%1 (%2)").arg(playlist->name(), playlist->fileInfo().fileName()));
playlist->disconnectSongs();
}

Expand Down Expand Up @@ -133,7 +133,7 @@ void QUPlaylistDatabase::save() {
QString(
tr("Save playlist \"%1\" as...")).arg(playlist->name()),
dir().path(),
QString(tr("UltraStar Playlists (%1);;Vocaluxe Playlists (%2)")).arg(QUSongSupport::allowedUltraStarPlaylistFiles().join(" ")).arg(QUSongSupport::allowedVocaluxePlaylistFiles().join(" ")));
QString(tr("UltraStar Playlists (%1);;Vocaluxe Playlists (%2)")).arg(QUSongSupport::allowedUltraStarPlaylistFiles().join(" "), QUSongSupport::allowedVocaluxePlaylistFiles().join(" ")));

if(!filePath.isEmpty()) {
playlist->setFileInfo(QFileInfo(filePath));
Expand Down Expand Up @@ -177,7 +177,7 @@ bool QUPlaylistDatabase::hasUnsavedChanges() const {
dlg.show();

foreach(QUPlaylistFile *playlist, playlists()) {
dlg.update(QString("%1 (%2)").arg(playlist->name()).arg(playlist->fileInfo().fileName()));
dlg.update(QString("%1 (%2)").arg(playlist->name(), playlist->fileInfo().fileName()));

if(playlist->hasUnsavedChanges())
return true;
Expand All @@ -192,7 +192,7 @@ void QUPlaylistDatabase::saveUnsavedChanges() {
dlg.show();

foreach(QUPlaylistFile *playlist, playlists()) {
dlg.update(QString("%1 (%2)").arg(playlist->name()).arg(playlist->fileInfo().fileName()));
dlg.update(QString("%1 (%2)").arg(playlist->name(), playlist->fileInfo().fileName()));

if(playlist->hasUnsavedChanges())
playlist->save();
Expand Down
10 changes: 5 additions & 5 deletions src/playlist/QUPlaylistFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ bool QUPlaylistFile::save() {
uint num = 1;
foreach(QUPlaylistEntry *entry, _playlist) {
if(!entry->song())
logSrv->add(QString(tr("Warning! The playlist entry \"%1 - %2\" will NOT be found by Vocaluxe/UltraStar!")).arg(entry->artistLink()).arg(entry->titleLink()), QU::Warning);
logSrv->add(QString(tr("Warning! The playlist entry \"%1 - %2\" will NOT be found by Vocaluxe/UltraStar!")).arg(entry->artistLink(), entry->titleLink()), QU::Warning);
else
entry->setLinks(entry->song()->artist(), entry->song()->title());

Expand Down Expand Up @@ -115,19 +115,19 @@ bool QUPlaylistFile::save() {
}

// write name of playlist
_out << QString("#%1: %2\n").arg(NAME_TAG).arg(_name);
_out << QString("#%1: %2\n").arg(NAME_TAG, _name);
_nameChanged = false;
_playlistChanged = false;

// write song links
_out << QString("#%1:\n").arg(SONGS_TAG);
foreach(QUPlaylistEntry *entry, _playlist) {
if(!entry->song())
logSrv->add(QString(tr("Warning! The playlist entry \"%1 - %2\" will NOT be found by UltraStar!")).arg(entry->artistLink()).arg(entry->titleLink()), QU::Warning);
logSrv->add(QString(tr("Warning! The playlist entry \"%1 - %2\" will NOT be found by UltraStar!")).arg(entry->artistLink(), entry->titleLink()), QU::Warning);
else
entry->setLinks(entry->song()->artist(), entry->song()->title());

_out << QString("%1 : %2\n").arg(entry->artistLink()).arg(entry->titleLink());
_out << QString("%1 : %2\n").arg(entry->artistLink(), entry->titleLink());
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ bool QUPlaylistFile::addEntry(QUSongFile *song) {

foreach(QUPlaylistEntry *entry, _playlist) { // TODO: a progressbar helpful?! (for big playlists)
if(song == entry->song()) {
logSrv->add(QString(tr("The song \"%1 - %2\" is already in the current playlist. It was not added.")).arg(song->artist()).arg(song->title()), QU::Warning);
logSrv->add(QString(tr("The song \"%1 - %2\" is already in the current playlist. It was not added.")).arg(song->artist(), song->title()), QU::Warning);
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/playlistdetails/QUPlayList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void QUPlayList::setGameModeMedley() {
if(entry->song()->hasMedley()) {
entry->setGameMode(GAMEMODE_MEDLEY);
} else {
logSrv->add(QString(tr("Unable to set game mode to 'Medley'. The playlist entry \"%1 - %2\" does NOT have a medley section!")).arg(entry->artistLink()).arg(entry->titleLink()), QU::Warning);
logSrv->add(QString(tr("Unable to set game mode to 'Medley'. The playlist entry \"%1 - %2\" does NOT have a medley section!")).arg(entry->artistLink(), entry->titleLink()), QU::Warning);
}
}
update();
Expand All @@ -128,7 +128,7 @@ void QUPlayList::setGameModeDuet() {
if(entry->song()->isDuet()) {
entry->setGameMode(GAMEMODE_DUET);
} else {
logSrv->add(QString(tr("Unable to set game mode to 'Duet'. The playlist entry \"%1 - %2\" is NOT a duet!")).arg(entry->artistLink()).arg(entry->titleLink()), QU::Warning);
logSrv->add(QString(tr("Unable to set game mode to 'Duet'. The playlist entry \"%1 - %2\" is NOT a duet!")).arg(entry->artistLink(), entry->titleLink()), QU::Warning);
}
}
update();
Expand Down
4 changes: 2 additions & 2 deletions src/playlistdetails/QUPlayListItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ void QUPlayListItem::updateData() {
f.setBold(false);

if(entry()->song()) {
this->setText(QString("%1. %2 - %3").arg(listWidget()->row(this) + 1).arg(entry()->song()->artist()).arg(entry()->song()->title()));
this->setText(QString("%1. %2 - %3").arg(listWidget()->row(this) + 1).arg(entry()->song()->artist(), entry()->song()->title()));
this->setForeground(Qt::black);

if(entry()->hasUnsavedChanges())
f.setBold(true);

} else {
this->setText(QString("%1. %2 - %3 (not found)").arg(listWidget()->row(this) + 1).arg(entry()->artistLink()).arg(entry()->titleLink()));
this->setText(QString("%1. %2 - %3 (not found)").arg(listWidget()->row(this) + 1).arg(entry()->artistLink(), entry()->titleLink()));
this->setForeground(Qt::gray);
}

Expand Down
Loading

0 comments on commit 442c326

Please sign in to comment.