From e21bea8d1587ae479db289832429b044da285090 Mon Sep 17 00:00:00 2001 From: Micha WERLE Date: Wed, 16 Aug 2023 14:50:58 +0900 Subject: [PATCH] chore: fix compiler warnings * add default to switch statements throwing an exception on unhandled case. This removes `control reaches end of non-void function` in many functions. * fix QT5.14 deprecations, which will also make it easier to move to QT6 - fix QSet initialization - rename `endl` -> `Qt::endl` - rename `QString::SkipEmptyParts` -> `Qt::SkipEmptyParts` - and more... * Scintilla editor - add missing `override` - replace deprecated functions * Settings - fix deprecated QDir assignment - code-style: replace assignment with initializers (to match QDir in this file) --- src/app/CustomTheme.cpp | 8 +++++ src/app/Theme.cpp | 10 +++++++ src/conf/Settings.cpp | 53 ++++++++++++++++++---------------- src/cred/CredentialHelper.cpp | 2 +- src/cred/GitCredential.cpp | 18 ++++++------ src/editor/LexLPeg.cpp | 24 +++++++-------- src/editor/ScintillaQt.cpp | 15 +++++----- src/editor/TextEditor.h | 4 +-- src/git/Diff.cpp | 7 +++-- src/git/Remote.cpp | 2 +- src/git/Repository.cpp | 2 +- src/host/Account.cpp | 7 +++++ src/index/Index.cpp | 2 ++ src/index/Query.cpp | 4 +-- src/index/indexer.cpp | 6 ++-- src/index/lexer_test.cpp | 4 +-- src/log/LogModel.cpp | 5 ++-- src/plugins/Plugin.cpp | 5 +++- src/ui/BlameMargin.cpp | 10 +++---- src/ui/CommitList.cpp | 4 +-- src/ui/DetailView.cpp | 26 +++++++++-------- src/ui/DiffView/Comment.cpp | 2 +- src/ui/DiffView/HunkWidget.cpp | 14 ++++----- src/ui/MainWindow.cpp | 2 +- src/ui/ReferenceModel.cpp | 2 +- src/ui/RemoteCallbacks.cpp | 2 +- src/ui/RepoView.cpp | 4 +-- src/ui/ToolBar.cpp | 2 +- test/Submodule.cpp | 4 +-- test/amend.cpp | 4 +-- test/index.cpp | 6 ++-- test/merge.cpp | 6 ++-- 32 files changed, 152 insertions(+), 114 deletions(-) diff --git a/src/app/CustomTheme.cpp b/src/app/CustomTheme.cpp index 9a7ddc7a..749c0228 100644 --- a/src/app/CustomTheme.cpp +++ b/src/app/CustomTheme.cpp @@ -435,6 +435,8 @@ QColor CustomTheme::commitEditor(CommitEditor color) { return commitEditor.value("spellignore").value(); case CommitEditor::LengthWarning: return commitEditor.value("lengthwarning").value(); + default: + throw std::runtime_error("Not Implemented or invalid enum " + std::to_string(static_cast(color))); } } @@ -464,6 +466,8 @@ QColor CustomTheme::diff(Diff color) { return diff.value("warning").value(); case Diff::Error: return diff.value("error").value(); + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } @@ -475,6 +479,8 @@ QColor CustomTheme::heatMap(HeatMap color) { return QColor(heatmap.value("hot").toString()); case HeatMap::Cold: return QColor(heatmap.value("cold").toString()); + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } @@ -490,6 +496,8 @@ QColor CustomTheme::remoteComment(Comment color) { return QColor(comment.value("author").toString()); case Comment::Timestamp: return QColor(comment.value("timestamp").toString()); + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } diff --git a/src/app/Theme.cpp b/src/app/Theme.cpp index e78e3344..ddb7c071 100644 --- a/src/app/Theme.cpp +++ b/src/app/Theme.cpp @@ -163,6 +163,8 @@ QColor Theme::commitEditor(CommitEditor color) { return Qt::gray; case CommitEditor::LengthWarning: return Qt::yellow; + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } @@ -191,6 +193,8 @@ QColor Theme::diff(Diff color) { return "#E8C080"; case Diff::Error: return "#7E494B"; + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } @@ -217,6 +221,8 @@ QColor Theme::diff(Diff color) { return "#FFFF00"; case Diff::Error: return "#FF0000"; + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } @@ -227,6 +233,8 @@ QColor Theme::heatMap(HeatMap color) { case HeatMap::Cold: return mDark ? QPalette().color(QPalette::Inactive, QPalette::Highlight) : QPalette().color(QPalette::Mid); + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } @@ -240,6 +248,8 @@ QColor Theme::remoteComment(Comment color) { return QPalette().color(QPalette::WindowText); case Comment::Timestamp: return QPalette().color(QPalette::WindowText); + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(color))); } } diff --git a/src/conf/Settings.cpp b/src/conf/Settings.cpp index d6c67e92..da65fb82 100644 --- a/src/conf/Settings.cpp +++ b/src/conf/Settings.cpp @@ -23,18 +23,18 @@ namespace { -const QString kIgnoreWsKey = "diff/whitespace/ignore"; -const QString kLastPathKey = "lastpath"; +const QString kIgnoreWsKey("diff/whitespace/ignore"); +const QString kLastPathKey("lastpath"); // Look up variant at key relative to root. QVariant lookup(const QVariantMap &root, const QString &key) { - QStringList list = key.split("/", QString::SkipEmptyParts); + QStringList list(key.split("/", Qt::SkipEmptyParts)); if (list.isEmpty()) return root; - QVariantMap map = root; + QVariantMap map(root); while (map.contains(list.first())) { - QVariant result = map.value(list.takeFirst()); + QVariant result(map.value(list.takeFirst())); if (list.isEmpty()) return result; map = result.toMap(); @@ -63,7 +63,7 @@ QVariant Settings::value(const QString &key, const QVariant &defaultValue) const { QSettings settings; settings.beginGroup(group()); - QVariant result = settings.value(key, defaultValue); + QVariant result(settings.value(key, defaultValue)); settings.endGroup(); return result; } @@ -107,13 +107,13 @@ QString Settings::lexer(const QString &filename) { return "null"; QFileInfo info(filename); - QString name = info.fileName(); - QString suffix = info.suffix().toLower(); + QString name(info.fileName()); + QString suffix(info.suffix().toLower()); // Try all patterns first. - QVariantMap lexers = mDefaults.value("lexers").toMap(); + QVariantMap lexers(mDefaults.value("lexers").toMap()); foreach (const QString &key, lexers.keys()) { - QVariantMap map = lexers.value(key).toMap(); + QVariantMap map(lexers.value(key).toMap()); if (map.contains("patterns")) { foreach (QString pattern, map.value("patterns").toString().split(",")) { QRegExp regExp(pattern, CS, QRegExp::Wildcard); @@ -125,7 +125,7 @@ QString Settings::lexer(const QString &filename) { // Try to match by extension. foreach (const QString &key, lexers.keys()) { - QVariantMap map = lexers.value(key).toMap(); + QVariantMap map(lexers.value(key).toMap()); if (map.contains("extensions")) { foreach (QString ext, map.value("extensions").toString().split(",")) { if (suffix == ext) @@ -138,8 +138,8 @@ QString Settings::lexer(const QString &filename) { } QString Settings::kind(const QString &filename) { - QString key = lexer(filename); - QVariantMap lexers = mDefaults.value("lexers").toMap(); + QString key(lexer(filename)); + QVariantMap lexers(mDefaults.value("lexers").toMap()); return lexers.value(key).toMap().value("name").toString(); } @@ -170,6 +170,9 @@ QString Settings::promptDescription(Prompt::Kind kind) const { case Prompt::Kind::LargeFiles: return tr("Prompt to stage large files"); + + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(kind))); } } @@ -221,10 +224,10 @@ QDir Settings::confDir() { #if !defined(NDEBUG) QDir dir(SRC_CONF_DIR); #else - QDir dir = rootDir(); + QDir dir(rootDir()); if (!dir.cd("Resources")) { if (!dir.cd(CONF_DIR)) - dir = SRC_CONF_DIR; + dir.setPath(SRC_CONF_DIR); } #endif return dir; @@ -232,20 +235,20 @@ QDir Settings::confDir() { QDir Settings::l10nDir() { #if !defined(NDEBUG) - QDir dir = QDir(SRC_L10N_DIR); + QDir dir(QDir(SRC_L10N_DIR)); #else - QDir dir = confDir(); + QDir dir(confDir()); if (!dir.cd("l10n")) { dir = rootDir(); if (!dir.cd(L10N_DIR)) - dir = SRC_L10N_DIR; + dir.setPath(SRC_L10N_DIR); } #endif return dir; } QDir Settings::dictionariesDir() { - QDir dir = confDir(); + QDir dir(confDir()); dir.cd("dictionaries"); return dir; } @@ -254,24 +257,24 @@ QDir Settings::lexerDir() { #if !defined(NDEBUG) QDir dir(SRC_SCINTILLUA_LEXERS_DIR); #else - QDir dir = confDir(); + QDir dir(confDir()); if (!dir.cd("lexers")) { dir = rootDir(); if (!dir.cd(SCINTILLUA_LEXERS_DIR)) - dir = SRC_SCINTILLUA_LEXERS_DIR; + dir.setPath(SRC_SCINTILLUA_LEXERS_DIR); } #endif return dir; } QDir Settings::themesDir() { - QDir dir = confDir(); + QDir dir(confDir()); dir.cd("themes"); return dir; } QDir Settings::pluginsDir() { - QDir dir = confDir(); + QDir dir(confDir()); dir.cd("plugins"); return dir; } @@ -281,8 +284,8 @@ QDir Settings::userDir() { } QDir Settings::tempDir() { - QString name = QCoreApplication::applicationName(); - QDir dir = QDir::temp(); + QString name(QCoreApplication::applicationName()); + QDir dir(QDir::temp()); dir.mkpath(name); dir.cd(name); return dir; diff --git a/src/cred/CredentialHelper.cpp b/src/cred/CredentialHelper.cpp index 9d25d989..b78d345e 100644 --- a/src/cred/CredentialHelper.cpp +++ b/src/cred/CredentialHelper.cpp @@ -98,5 +98,5 @@ void CredentialHelper::log(const QString &text) { return; QString time = QTime::currentTime().toString(Qt::ISODateWithMs); - QTextStream(&file) << time << " - " << text << endl; + QTextStream(&file) << time << " - " << text << Qt::endl; } diff --git a/src/cred/GitCredential.cpp b/src/cred/GitCredential.cpp index cbd01d17..a5b1eab3 100644 --- a/src/cred/GitCredential.cpp +++ b/src/cred/GitCredential.cpp @@ -45,11 +45,11 @@ bool GitCredential::get(const QString &url, QString &username, return false; QTextStream out(&process); - out << "protocol=" << protocol(url) << endl; - out << "host=" << host(url) << endl; + out << "protocol=" << protocol(url) << Qt::endl; + out << "host=" << host(url) << Qt::endl; if (!username.isEmpty()) - out << "username=" << username << endl; - out << endl; + out << "username=" << username << Qt::endl; + out << Qt::endl; process.closeWriteChannel(); process.waitForFinished(); @@ -80,11 +80,11 @@ bool GitCredential::store(const QString &url, const QString &username, return false; QTextStream out(&process); - out << "protocol=" << protocol(url) << endl; - out << "host=" << host(url) << endl; - out << "username=" << username << endl; - out << "password=" << password << endl; - out << endl; + out << "protocol=" << protocol(url) << Qt::endl; + out << "host=" << host(url) << Qt::endl; + out << "username=" << username << Qt::endl; + out << "password=" << password << Qt::endl; + out << Qt::endl; process.closeWriteChannel(); process.waitForFinished(); diff --git a/src/editor/LexLPeg.cpp b/src/editor/LexLPeg.cpp index 662dceac..6ac5ae11 100644 --- a/src/editor/LexLPeg.cpp +++ b/src/editor/LexLPeg.cpp @@ -413,7 +413,7 @@ public: virtual ~LexerLPeg() {} /** Destroys the lexer object. */ - void SCI_METHOD Release() { + void SCI_METHOD Release() override { lua_getfield(L, LUA_REGISTRYINDEX, "sci_lexers"); lua_pushlightuserdata(L, reinterpret_cast(this)); lua_pushnil(L), lua_settable(L, -3), lua_pop(L, 1); // sci_lexers @@ -429,7 +429,7 @@ public: * @param buffer The document interface. */ void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, - int initStyle, IDocument *buffer) { + int initStyle, IDocument *buffer) override { lua_pushlightuserdata(L, reinterpret_cast(&props)); lua_setfield(L, LUA_REGISTRYINDEX, "sci_props"); lua_pushlightuserdata(L, reinterpret_cast(buffer)); @@ -515,7 +515,7 @@ public: * @param buffer The document interface. */ void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, - int initStyle, IDocument *buffer) { + int initStyle, IDocument *buffer) override { lua_pushlightuserdata(L, reinterpret_cast(&props)); lua_setfield(L, LUA_REGISTRYINDEX, "sci_props"); lua_pushlightuserdata(L, reinterpret_cast(buffer)); @@ -552,7 +552,7 @@ public: * @param key The string keyword. * @param val The string value. */ - Sci_Position SCI_METHOD PropertySet(const char *key, const char *value) { + Sci_Position SCI_METHOD PropertySet(const char *key, const char *value) override { const char *val = *value ? value : " "; props.Set(key, val, strlen(key), strlen(val)); // ensure property is cleared return -1; // no need to re-lex @@ -566,7 +566,7 @@ public: * @param arg The argument. * @return void *data */ - void *SCI_METHOD PrivateCall(int code, void *arg) { + void *SCI_METHOD PrivateCall(int code, void *arg) override { switch (code) { case SCI_GETDIRECTFUNCTION: fn = reinterpret_cast(arg); @@ -603,12 +603,12 @@ public: } } - int SCI_METHOD Version() const { return 0; } - const char *SCI_METHOD PropertyNames() { return ""; } - int SCI_METHOD PropertyType(const char *) { return 0; } - const char *SCI_METHOD DescribeProperty(const char *) { return ""; } - const char *SCI_METHOD DescribeWordListSets() { return ""; } - Sci_Position SCI_METHOD WordListSet(int, const char *) { return -1; } + int SCI_METHOD Version() const override { return 0; } + const char *SCI_METHOD PropertyNames() override { return ""; } + int SCI_METHOD PropertyType(const char *) override { return 0; } + const char *SCI_METHOD DescribeProperty(const char *) override { return ""; } + const char *SCI_METHOD DescribeWordListSets() override { return ""; } + Sci_Position SCI_METHOD WordListSet(int, const char *) override { return -1; } int SCI_METHOD LineEndTypesSupported() noexcept override { return SC_LINE_END_TYPE_UNICODE; @@ -636,7 +636,7 @@ public: int SCI_METHOD GetIdentifier() override { return 0; } - const char *SCI_METHOD PropertyGet(const char *key) { return ""; } + const char *SCI_METHOD PropertyGet(const char *key) override { return ""; } /** Constructs a new instance of the lexer. */ static ILexer5 *LexerFactoryLPeg() { return new LexerLPeg(); } diff --git a/src/editor/ScintillaQt.cpp b/src/editor/ScintillaQt.cpp index 82f580f7..bfdf6c3b 100644 --- a/src/editor/ScintillaQt.cpp +++ b/src/editor/ScintillaQt.cpp @@ -185,7 +185,7 @@ void ScintillaQt::paintEvent(QPaintEvent *event) { } void ScintillaQt::wheelEvent(QWheelEvent *event) { - if (event->orientation() == Qt::Horizontal) { + if (event->angleDelta().x() != 0) { if (horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff) event->ignore(); else @@ -194,7 +194,7 @@ void ScintillaQt::wheelEvent(QWheelEvent *event) { if (QApplication::keyboardModifiers() & Qt::ControlModifier) { // Zoom! We play with the font sizes in the styles. // Number of steps/line is ignored, we just care if sizing up or down - if (event->delta() > 0) { + if (event->angleDelta().y() > 0) { KeyCommand(SCI_ZOOMIN); } else { KeyCommand(SCI_ZOOMOUT); @@ -327,8 +327,7 @@ void ScintillaQt::keyPressEvent(QKeyEvent *event) { QString text = event->text(); if (input && !text.isEmpty() && text[0].isPrint()) { - QByteArray utext = text.toUtf8(); - AddCharUTF(utext.data(), utext.size()); + InsertCharacter(text.toStdString(), CharacterSource::directInput); } else { event->ignore(); } @@ -355,7 +354,7 @@ static int modifierTranslated(int sciModifier) { void ScintillaQt::mousePressEvent(QMouseEvent *event) { Point pos = PointFromQPoint(event->pos()); - if (event->button() == Qt::MidButton && + if (event->button() == Qt::MiddleButton && QApplication::clipboard()->supportsSelection()) { SelectionPosition selPos = SPositionFromLocation(pos, false, false, UserVirtualSpace()); @@ -522,7 +521,7 @@ void ScintillaQt::inputMethodEvent(QInputMethodEvent *event) { const QByteArray oneChar = oneCharUTF16.toUtf8(); const int oneCharLen = oneChar.length(); - AddCharUTF(oneChar.data(), oneCharLen); + InsertCharacter(oneChar.toStdString(), CharacterSource::directInput); i += ucWidth; } @@ -605,7 +604,7 @@ void ScintillaQt::inputMethodEvent(QInputMethodEvent *event) { numBytes += oneCharLen; imeCharPos[i + 1] = numBytes; - AddCharUTF(oneChar.data(), oneCharLen); + InsertCharacter(oneChar.toStdString(), CharacterSource::directInput); #ifdef Q_OS_LINUX // Segment marked with imeCaretPos is for target input. @@ -642,7 +641,7 @@ QVariant ScintillaQt::inputMethodQuery(Qt::InputMethodQuery query) const { int line = send(SCI_LINEFROMPOSITION, pos); switch (query) { - case Qt::ImMicroFocus: { + case Qt::ImCursorRectangle: { int startPos = (preeditPos >= 0) ? preeditPos : pos; Point pt = const_cast(this)->LocationFromPosition(startPos); diff --git a/src/editor/TextEditor.h b/src/editor/TextEditor.h index 6d45dfb5..0ae8b7b4 100644 --- a/src/editor/TextEditor.h +++ b/src/editor/TextEditor.h @@ -105,7 +105,7 @@ public: QList diagnostics(int line); void addDiagnostic(int line, const Diagnostic &diag); - sptr_t WndProc(unsigned int message, uptr_t wParam, sptr_t lParam); + sptr_t WndProc(unsigned int message, uptr_t wParam, sptr_t lParam) override; // Make wheel event public. // FIXME: This should be an event filter? @@ -154,7 +154,7 @@ private: int diagnosticMarker(int line); void loadMarkerIcon(Marker marker, const QIcon &icon); void loadMarkerPixmap(Marker marker, const QPixmap &pixmap); - void AddToPopUp(const char *label, int cmd = 0, bool enabled = true); + void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) override; void ContextMenu(Scintilla::Point pt); QString mPath; diff --git a/src/git/Diff.cpp b/src/git/Diff.cpp index c56e5913..8d1c0605 100644 --- a/src/git/Diff.cpp +++ b/src/git/Diff.cpp @@ -108,10 +108,10 @@ QByteArray Diff::print() { QByteArray diff; for (auto file : data.files) { for (auto hunk : file.hunks) { - diff.append(hunk.header); + diff.append(hunk.header.toUtf8()); for (auto line : hunk.lines) - diff.append(line); + diff.append(line.toUtf8()); } } Debug(QString(diff)); @@ -197,6 +197,9 @@ void Diff::sort(SortRole role, Qt::SortOrder order) { return ascending ? (lhsStatus < rhsStatus) : (rhsStatus < lhsStatus); } + + default: + throw std::runtime_error("Unhandled case or invalid enum " + std::to_string(static_cast(role))); } }); } diff --git a/src/git/Remote.cpp b/src/git/Remote.cpp index dab10ddd..46b0d931 100644 --- a/src/git/Remote.cpp +++ b/src/git/Remote.cpp @@ -674,7 +674,7 @@ void Remote::log(const QString &text) { return; QString time = QTime::currentTime().toString(Qt::ISODateWithMs); - QTextStream(&file) << time << " - " << text << endl; + QTextStream(&file) << time << " - " << text << Qt::endl; } } // namespace git diff --git a/src/git/Repository.cpp b/src/git/Repository.cpp index 311b91c9..4de515cf 100644 --- a/src/git/Repository.cpp +++ b/src/git/Repository.cpp @@ -1052,7 +1052,7 @@ QStringList Repository::lfsEnvironment() { Repository::LfsTracking Repository::lfsTracked() { QString output = lfsExecute({"track"}); - QStringList lines = output.split('\n', QString::SkipEmptyParts); + QStringList lines = output.split('\n', Qt::SkipEmptyParts); if (!lines.isEmpty()) lines.removeFirst(); diff --git a/src/host/Account.cpp b/src/host/Account.cpp index 3c7d5310..211f72ef 100644 --- a/src/host/Account.cpp +++ b/src/host/Account.cpp @@ -203,6 +203,9 @@ QString Account::helpText(Kind kind) { case Bitbucket: case Beanstalk: return QString(); + + default: + throw std::runtime_error("Unhandled case or invalid enum " + std::to_string(static_cast(kind))); } } @@ -218,6 +221,8 @@ QString Account::defaultUrl(Kind kind) { return Beanstalk::defaultUrl(); case GitLab: return GitLab::defaultUrl(); + default: + throw std::runtime_error("Unhandled case or invalid enum " + std::to_string(static_cast(kind))); } } @@ -257,6 +262,8 @@ QString Account::kindToString(Kind kind) { return "beanstalk"; case GitLab: return "gitlab"; + default: + throw std::runtime_error("Unhandled case or invalid enum " + std::to_string(static_cast(kind))); } } diff --git a/src/index/Index.cpp b/src/index/Index.cpp index 362162d6..005e207c 100644 --- a/src/index/Index.cpp +++ b/src/index/Index.cpp @@ -442,6 +442,8 @@ QByteArray Index::fieldName(Index::Field field) { return "after"; case Index::Pathspec: return "pathspec"; + default: + throw std::runtime_error("Unhandled case or invalid enum " + std::to_string(static_cast(field))); } } diff --git a/src/index/Query.cpp b/src/index/Query.cpp index 0fbee542..c1ed65a2 100644 --- a/src/index/Query.cpp +++ b/src/index/Query.cpp @@ -183,7 +183,7 @@ public: QList commits = mLhs->commits(index); if (mKind == And) { // Remove commits that don't match the right hand side. - QSet set = QSet::fromList(rhs); + QSet set(rhs.begin(), rhs.end()); QMutableListIterator it(commits); while (it.hasNext()) { if (!set.contains(it.next())) @@ -191,7 +191,7 @@ public: } } else { // Add commits that aren't already in the result set. - QSet set = QSet::fromList(commits); + QSet set(commits.begin(), commits.end()); foreach (const git::Commit &commit, rhs) { if (!set.contains(commit)) commits.append(commit); diff --git a/src/index/indexer.cpp b/src/index/indexer.cpp index 2910f0df..e21362bb 100644 --- a/src/index/indexer.cpp +++ b/src/index/indexer.cpp @@ -105,7 +105,7 @@ void log(QFile *out, const QString &text) { return; QString time = QTime::currentTime().toString(Qt::ISODateWithMs); - QTextStream(out) << time << " - " << text << endl; + QTextStream(out) << time << " - " << text << Qt::endl; } void log(QFile *out, const QString &fmt, const git::Id &id) { @@ -405,7 +405,7 @@ public: int count = 0; QList commits; git::Commit commit = mWalker.next(); - QSet ids = QSet::fromList(mIndex.ids()); + QSet ids(mIndex.ids().begin(), mIndex.ids().end()); while (commit.isValid() && count < 8192) { // Don't index merge commits. if (!commit.isMerge() && !ids.contains(commit.id())) { @@ -440,7 +440,7 @@ public: // Write to disk. log(mOut, "start write"); if (mIndex.write(mWatcher.result()) && mNotify) - QTextStream(stdout) << "write" << endl; + QTextStream(stdout) << "write" << Qt::endl; log(mOut, "end write"); // Restart. diff --git a/src/index/lexer_test.cpp b/src/index/lexer_test.cpp index 4b5881a4..c07f5b56 100644 --- a/src/index/lexer_test.cpp +++ b/src/index/lexer_test.cpp @@ -29,7 +29,7 @@ void print(QTextStream &out, const Lexer::Lexeme &lexeme, int indent = 0) { out << lexeme.text << " - " << lexeme.token; if (lexeme.token < kStyleNames.length()) out << " (" << kStyleNames.at(lexeme.token) << ")"; - out << endl; + out << Qt::endl; } void print(QTextStream &out, Lexer *lexer, int indent = 0) { @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) { // Lex buffer. Lexer *lexer = lexers.value(name); if (lexer->lex(buffer)) { - out << name << " - " << arg << ":" << endl; + out << name << " - " << arg << ":" << Qt::endl; print(out, lexer); } } diff --git a/src/log/LogModel.cpp b/src/log/LogModel.cpp index 4b0bdb8a..66e4c82f 100644 --- a/src/log/LogModel.cpp +++ b/src/log/LogModel.cpp @@ -9,6 +9,7 @@ #include "LogModel.h" #include "LogEntry.h" +#include #include namespace { @@ -74,8 +75,8 @@ QVariant LogModel::data(const QModelIndex &index, int role) const { QDateTime date = entry->timestamp(); QString timestamp = (date.date() == QDate::currentDate()) - ? date.time().toString(Qt::DefaultLocaleShortDate) - : date.toString(Qt::DefaultLocaleShortDate); + ? QLocale().toString(date.time(), QLocale::ShortFormat) + : QLocale().toString(date, QLocale::ShortFormat); text = kTimeFmt.arg(timestamp, text); } } diff --git a/src/plugins/Plugin.cpp b/src/plugins/Plugin.cpp index 53f48e34..7e26ee5b 100644 --- a/src/plugins/Plugin.cpp +++ b/src/plugins/Plugin.cpp @@ -491,7 +491,7 @@ Plugin::Plugin(const QString &file, const git::Repository &repo, // Print error messages to the console. connect(this, &Plugin::error, [](const QString &msg) { - QTextStream(stderr) << "plugin error: " << msg << endl; + QTextStream(stderr) << "plugin error: " << msg << Qt::endl; }); // Load libraries. @@ -612,6 +612,9 @@ QVariant Plugin::optionValue(const QString &key) const { case String: return config().value(kKeyFmt.arg(mName, key), value.toString()); + + default: + throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast(optionKind(key)))); } } diff --git a/src/ui/BlameMargin.cpp b/src/ui/BlameMargin.cpp index c815ddbd..a8b4ea7e 100644 --- a/src/ui/BlameMargin.cpp +++ b/src/ui/BlameMargin.cpp @@ -110,7 +110,7 @@ bool BlameMargin::event(QEvent *event) { git::Signature signature = mBlame.signature(index); if (signature.isValid()) { email = QString("<%1>").arg(signature.email()); - date = signature.date().toString(Qt::DefaultLocaleLongDate); + date = QLocale().toString(signature.date(), QLocale::LongFormat); } if (!name.isEmpty()) @@ -223,8 +223,8 @@ void BlameMargin::paintEvent(QPaintEvent *event) { if (signature.isValid()) { QDateTime dateTime = signature.date(); date = (dateTime.date() == today) - ? dateTime.time().toString(Qt::DefaultLocaleShortDate) - : dateTime.date().toString(Qt::DefaultLocaleShortDate); + ? QLocale().toString(dateTime.time(), QLocale::ShortFormat) + : QLocale().toString(dateTime.date(), QLocale::ShortFormat); time = dateTime.toTime_t(); } @@ -284,8 +284,8 @@ void BlameMargin::paintEvent(QPaintEvent *event) { QDateTime dateTime = signature.date(); QString longDate = (dateTime.date() == today) - ? dateTime.time().toString(Qt::DefaultLocaleLongDate) - : dateTime.date().toString(Qt::DefaultLocaleLongDate); + ? QLocale().toString(dateTime.time(), QLocale::LongFormat) + : QLocale().toString(dateTime.date(), QLocale::LongFormat); QRectF dateRect = regularMetrics.boundingRect(longDate); if (nameRect.width() + dateRect.width() + 4 <= rect.width()) diff --git a/src/ui/CommitList.cpp b/src/ui/CommitList.cpp index c3cb132b..e059b844 100644 --- a/src/ui/CommitList.cpp +++ b/src/ui/CommitList.cpp @@ -791,8 +791,8 @@ public: QDateTime date = commit.committer().date().toLocalTime(); QString timestamp = (date.date() == QDate::currentDate()) - ? date.time().toString(Qt::DefaultLocaleShortDate) - : date.date().toString(Qt::DefaultLocaleShortDate); + ? QLocale().toString(date.time(), QLocale::ShortFormat) + : QLocale().toString(date.date(), QLocale::ShortFormat); int timestampWidth = fm.horizontalAdvance(timestamp); if (compact) { diff --git a/src/ui/DetailView.cpp b/src/ui/DetailView.cpp index b05dee5e..a397735f 100644 --- a/src/ui/DetailView.cpp +++ b/src/ui/DetailView.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -121,7 +122,8 @@ public: mDate = new QLabel(this); mDate->setTextInteractionFlags(kTextFlags); - mSpacing = style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); + mSpacing.setX(style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing)); + mSpacing.setY(style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); } void moveEvent(QMoveEvent *event) override { updateLayout(); } @@ -132,13 +134,13 @@ public: QSize date = mDate->sizeHint(); QSize author = mAuthor->sizeHint(); QSize committer = mCommitter->sizeHint(); - int width = author.width() + date.width() + mSpacing; + int width = author.width() + date.width() + mSpacing.x(); int height; if (mSameAuthorCommitter) height = qMax(qMax(author.height(), committer.height()), date.height()); else height = - qMax(author.height(), date.height()) + committer.height() + mSpacing; + qMax(author.height(), date.height()) + committer.height() + mSpacing.y(); return QSize(width, height); } @@ -152,7 +154,7 @@ public: height = qMax(qMax(author.height(), committer.height()), date.height()); else height = - qMax(author.height(), date.height()) + committer.height() + mSpacing; + qMax(author.height(), date.height()) + committer.height() + mSpacing.y(); return QSize(width, height); } @@ -165,8 +167,8 @@ public: bool wrapped = (width < sizeHint().width()); int unwrappedHeight = mSameAuthorCommitter ? qMax(committer, qMax(author, date)) - : qMax(author + committer + mSpacing, date); - return wrapped ? (author + committer + date + 2 * mSpacing) + : qMax(author + committer + mSpacing.y(), date); + return wrapped ? (author + committer + date + 2 * mSpacing.y()) : unwrappedHeight; } @@ -196,12 +198,12 @@ private: void updateLayout() { mAuthor->move(0, 0); if (mCommitter->isVisible()) - mCommitter->move(0, mAuthor->height() + mSpacing); + mCommitter->move(0, mAuthor->height() + mSpacing.y()); bool wrapped = (width() < sizeHint().width()); int x = wrapped ? 0 : width() - mDate->width(); int y = - wrapped ? mAuthor->height() + mCommitter->height() + 2 * mSpacing : 0; + wrapped ? mAuthor->height() + mCommitter->height() + 2 * mSpacing.y() : 0; mDate->move(x, y); updateGeometry(); } @@ -210,7 +212,7 @@ private: QLabel *mCommitter; QLabel *mDate; - int mSpacing; + QPoint mSpacing; bool mSameAuthorCommitter{false}; }; @@ -348,8 +350,8 @@ public: // Set date range. QDate lastDate = last.committer().date().toLocalTime().date(); QDate firstDate = first.committer().date().toLocalTime().date(); - QString lastDateStr = lastDate.toString(Qt::DefaultLocaleShortDate); - QString firstDateStr = firstDate.toString(Qt::DefaultLocaleShortDate); + QString lastDateStr = QLocale().toString(lastDate, QLocale::ShortFormat); + QString firstDateStr = QLocale().toString(firstDate, QLocale::ShortFormat); QString dateStr = (lastDate == firstDate) ? lastDateStr : kDateRangeFmt.arg(lastDateStr, firstDateStr); @@ -387,7 +389,7 @@ public: QDateTime date = commit.committer().date().toLocalTime(); mHash->setText(brightText(tr("Id:")) + " " + commit.shortId()); mAuthorCommitterDate->setDate( - brightText(date.toString(Qt::DefaultLocaleLongDate))); + brightText(QLocale().toString(date, QLocale::LongFormat))); mAuthorCommitterDate->setAuthorCommitter( kAuthorFmt.arg(author.name(), author.email()), kAuthorFmt.arg(committer.name(), committer.email())); diff --git a/src/ui/DiffView/Comment.cpp b/src/ui/DiffView/Comment.cpp index bc4a2c89..58508a83 100644 --- a/src/ui/DiffView/Comment.cpp +++ b/src/ui/DiffView/Comment.cpp @@ -25,7 +25,7 @@ Comment::Comment(const QDateTime &date, const Account::Comment &comment, QTextCharFormat timestamp; timestamp.setForeground(theme->remoteComment(Theme::Comment::Timestamp)); cursor.setCharFormat(timestamp); - cursor.insertText(date.toString(Qt::DefaultLocaleLongDate)); + cursor.insertText(QLocale().toString(date, QLocale::LongFormat)); QTextBlockFormat indent; indent.setLeftMargin(fontMetrics().horizontalAdvance(' ') * diff --git a/src/ui/DiffView/HunkWidget.cpp b/src/ui/DiffView/HunkWidget.cpp index c7c3b0b2..1619cd0b 100644 --- a/src/ui/DiffView/HunkWidget.cpp +++ b/src/ui/DiffView/HunkWidget.cpp @@ -1125,7 +1125,7 @@ void HunkWidget::createMarkersAndLineNumbers(const Line &line, int lidx, } QString author = comment.author; - QString time = key.toString(Qt::DefaultLocaleLongDate); + QString time = QLocale().toString(key, QLocale::LongFormat); QString body = paragraphs.join('\n'); QString text = author + ' ' + time + '\n' + body; QByteArray styles = @@ -1164,18 +1164,18 @@ QByteArray HunkWidget::hunk() const { int mask = mEditor->markers(i); if (mask & 1 << TextEditor::Marker::Addition) { if (!(mask & 1 << TextEditor::Marker::DiscardMarker)) { - ar.append(mEditor->line(i)); + ar.append(mEditor->line(i).toUtf8()); appended = true; } } else if (mask & 1 << TextEditor::Marker::Deletion) { if (mask & 1 << TextEditor::Marker::DiscardMarker) { // with a discard, a deletion becomes reverted // and the line is still present - ar.append(mEditor->line(i)); + ar.append(mEditor->line(i).toUtf8()); appended = true; } } else { - ar.append(mEditor->line(i)); + ar.append(mEditor->line(i).toUtf8()); appended = true; } @@ -1198,16 +1198,16 @@ QByteArray HunkWidget::apply() { int mask = mEditor->markers(i); if (mask & 1 << TextEditor::Marker::Addition) { if (mask & 1 << TextEditor::Marker::StagedMarker) { - ar.append(mEditor->line(i)); + ar.append(mEditor->line(i).toUtf8()); appended = true; } } else if (mask & 1 << TextEditor::Marker::Deletion) { if (!(mask & 1 << TextEditor::Marker::StagedMarker)) { - ar.append(mEditor->line(i)); + ar.append(mEditor->line(i).toUtf8()); appended = true; } } else { - ar.append(mEditor->line(i)); + ar.append(mEditor->line(i).toUtf8()); appended = true; } diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 97b6c09d..2b469c8f 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -193,7 +193,7 @@ void MainWindow::setSideBarVisible(bool visible) { QTimeLine *timeline = new QTimeLine(250, this); timeline->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward); - timeline->setCurveShape(QTimeLine::LinearCurve); + timeline->setEasingCurve(QEasingCurve(QEasingCurve::Linear)); timeline->setUpdateInterval(20); connect(timeline, &QTimeLine::valueChanged, [this, pos](qreal value) { diff --git a/src/ui/ReferenceModel.cpp b/src/ui/ReferenceModel.cpp index 561673d5..0f08a1c0 100644 --- a/src/ui/ReferenceModel.cpp +++ b/src/ui/ReferenceModel.cpp @@ -266,7 +266,7 @@ QVariant ReferenceModel::data(const QModelIndex &index, int role) const { QString email = QString("<%1>").arg(signature.email()); lines.append(kNowrapFmt.arg(QString("%1 %2").arg(name, email))); - QString date = signature.date().toString(Qt::DefaultLocaleLongDate); + QString date = QLocale().toString(signature.date(), QLocale::LongFormat); lines.append(kNowrapFmt.arg(date)); } diff --git a/src/ui/RemoteCallbacks.cpp b/src/ui/RemoteCallbacks.cpp index 9d3fdf93..90a164c9 100644 --- a/src/ui/RemoteCallbacks.cpp +++ b/src/ui/RemoteCallbacks.cpp @@ -235,7 +235,7 @@ bool RemoteCallbacks::negotiation( QTextStream out(&process); foreach (const git::Remote::PushUpdate &update, updates) out << update.dstName << " " << update.dstId.toString() << " " - << update.srcName << " " << update.srcId.toString() << endl; + << update.srcName << " " << update.srcId.toString() << Qt::endl; process.closeWriteChannel(); if (loop.exec()) { diff --git a/src/ui/RepoView.cpp b/src/ui/RepoView.cpp index 1c850d01..078905b4 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -882,7 +882,7 @@ void RepoView::setLogVisible(bool visible) { QTimeLine *timeline = new QTimeLine(250, this); timeline->setDirection(visible ? QTimeLine::Forward : QTimeLine::Backward); - timeline->setCurveShape(QTimeLine::LinearCurve); + timeline->setEasingCurve(QEasingCurve(QEasingCurve::Linear)); timeline->setUpdateInterval(20); connect(timeline, &QTimeLine::valueChanged, this, [this, pos](qreal value) { @@ -907,7 +907,7 @@ LogEntry *RepoView::error(LogEntry *parent, const QString &action, ? tr("Unable to %1 - %2").arg(action, detail) : tr("Unable to %1 '%2' - %3").arg(action, name, detail); - QStringList items = text.split("\\n", QString::KeepEmptyParts); + QStringList items = text.split("\\n", Qt::KeepEmptyParts); if (items.last() == "\n") items.removeLast(); diff --git a/src/ui/ToolBar.cpp b/src/ui/ToolBar.cpp index 55ffb619..600edf79 100644 --- a/src/ui/ToolBar.cpp +++ b/src/ui/ToolBar.cpp @@ -916,7 +916,7 @@ ToolBar::ToolBar(MainWindow *parent) : QToolBar(parent) { addWidget(mode); using Signal = void (QButtonGroup::*)(int); - auto signal = static_cast(&QButtonGroup::buttonClicked); + auto signal = static_cast(&QButtonGroup::idClicked); connect(mModeGroup, signal, [this](int index) { currentView()->setViewMode(static_cast(index)); }); diff --git a/test/Submodule.cpp b/test/Submodule.cpp index 19f8b275..d796c954 100644 --- a/test/Submodule.cpp +++ b/test/Submodule.cpp @@ -147,14 +147,14 @@ void TestSubmodule::discardFile() { { QFile file(repo.workdir().filePath("README.md")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "Changing readme of main repository" << endl; + QTextStream(&file) << "Changing readme of main repository" << Qt::endl; file.close(); } { QFile file(repo.workdir().filePath("GittyupTestRepo/README.md")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "Changing content of submodule readme" << endl; + QTextStream(&file) << "Changing content of submodule readme" << Qt::endl; file.close(); } diff --git a/test/amend.cpp b/test/amend.cpp index a39c2969..8a7deb4b 100644 --- a/test/amend.cpp +++ b/test/amend.cpp @@ -94,7 +94,7 @@ void TestAmend::testAmendAddFile() { // Add file and refresh. QFile file(mRepo->workdir().filePath("test")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "This will be a test." << endl; + QTextStream(&file) << "This will be a test." << Qt::endl; Test::refresh(view); @@ -139,7 +139,7 @@ void TestAmend::testAmendAddFile() { { QFile file(mRepo->workdir().filePath("test")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "Changes made" << endl; + QTextStream(&file) << "Changes made" << Qt::endl; Test::refresh(view); diff --git a/test/index.cpp b/test/index.cpp index e26c3ff0..b7b0efdc 100644 --- a/test/index.cpp +++ b/test/index.cpp @@ -44,7 +44,7 @@ void TestIndex::stageAddition() { // Add file and refresh. QFile file(mRepo->workdir().filePath("test")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "This is a test." << endl; + QTextStream(&file) << "This is a test." << Qt::endl; RepoView *view = mWindow->currentView(); refresh(view); @@ -135,11 +135,11 @@ void TestIndex::stageDirectory() { QFile file1(dir.filePath("test1")); QVERIFY(file1.open(QFile::WriteOnly)); - QTextStream(&file1) << "This is a test." << endl; + QTextStream(&file1) << "This is a test." << Qt::endl; QFile file2(dir.filePath("test2")); QVERIFY(file2.open(QFile::WriteOnly)); - QTextStream(&file2) << "This is a test." << endl; + QTextStream(&file2) << "This is a test." << Qt::endl; RepoView *view = mWindow->currentView(); refresh(view); diff --git a/test/merge.cpp b/test/merge.cpp index 836ad369..44b93c3e 100644 --- a/test/merge.cpp +++ b/test/merge.cpp @@ -54,7 +54,7 @@ void TestMerge::firstCommit() { // Add file and refresh. QFile file(mRepo->workdir().filePath("test")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "This will be a test." << endl; + QTextStream(&file) << "This will be a test." << Qt::endl; RepoView *view = mWindow->currentView(); refresh(view); @@ -92,7 +92,7 @@ void TestMerge::secondCommit() { QFile file(mRepo->workdir().filePath("test")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "This is a conflict." << endl; + QTextStream(&file) << "This is a conflict." << Qt::endl; refresh(view); @@ -130,7 +130,7 @@ void TestMerge::thirdCommit() { QFile file(mRepo->workdir().filePath("test")); QVERIFY(file.open(QFile::WriteOnly)); - QTextStream(&file) << "This is a test." << endl; + QTextStream(&file) << "This is a test." << Qt::endl; refresh(view);