diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..488bc46c7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: +- repo: https://github.com/pre-commit/mirrors-clang-format + rev: v13.0.1 + hooks: + - id: clang-format + args: [ -i ] + diff --git a/README.md b/README.md index 408a6f45f..9d5a7c0fd 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,15 @@ branch. Create pull requests against the `master` branch. Follow the [seven guidelines](https://chris.beams.io/posts/git-commit/) to writing a great commit message. +Prior to committing a change, please use `cl-format.sh` to ensure your code +adheres to the formatting conventions for this project. You can also use the +`setup-env.sh` script to install a pre-commit hook which will automatically +run `clang-format` against all modified files. + +Prior to pushing a change, please ensure you run the unit tests to avoid any +regressions. These are found in `/test` and can be run using +`ctest`. + License ------- diff --git a/setup-env.sh b/setup-env.sh new file mode 100755 index 000000000..dde64c1e8 --- /dev/null +++ b/setup-env.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "`dirname "$0"`" + +PRE_COMMIT=${SCRIPT_DIR}/.venv/bin/pre-commit + +pre_commit() { + # Set up pre-commit hook + if [ ! -f "${PRE_COMMIT}" ]; then + pushd ${SCRIPT_DIR} + python3 -m venv .venv + .venv/bin/pip install pre-commit + popd + fi + ${PRE_COMMIT} install +} + +remove_pre_commt() { + if [ -f "${PRE_COMMIT}" ]; then + ${PRE_COMMIT} uninstall + fi +} + +if [ $# -eq 0 ]; then + set -- --help +fi + +for arg in "$@"; do + case $arg in + pre_commit | pre-commit | install_pre_commit | install-pre-commit) + pre_commit + ;; + remove_pre_commit | remove-pre-commit | uninstall_pre_commit | uninstall-pre-commit) + remove_pre_commit + ;; + *) + echo "USAGE $0 [commands]" + echo " Commands:" + echo " install-pre-commit - installs pre-commit hooks" + echo " uninstall-pre-commit - removes pre-commit hooks" + ;; + esac +done diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a370e7b1..8e880c255 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +add_compile_options(-Werror=switch) +# Uncomment to compile with more warnings add_compile_options(-Wall) Uncomment +# to compile with even more warnings add_compile_options(-Wextra) TODO: +# currently there are too many unused parameters which overwhelms the warning +# output with `-Wall`. So let's leave fixing these for later. +add_compile_options(-Wno-unused-parameter) + add_subdirectory(util) add_subdirectory(cli) add_subdirectory(conf) diff --git a/src/app/CustomTheme.cpp b/src/app/CustomTheme.cpp index 9a7ddc7a6..b23138d51 100644 --- a/src/app/CustomTheme.cpp +++ b/src/app/CustomTheme.cpp @@ -436,6 +436,8 @@ QColor CustomTheme::commitEditor(CommitEditor color) { case CommitEditor::LengthWarning: return commitEditor.value("lengthwarning").value(); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor CustomTheme::diff(Diff color) { @@ -465,6 +467,8 @@ QColor CustomTheme::diff(Diff color) { case Diff::Error: return diff.value("error").value(); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor CustomTheme::heatMap(HeatMap color) { @@ -476,6 +480,8 @@ QColor CustomTheme::heatMap(HeatMap color) { case HeatMap::Cold: return QColor(heatmap.value("cold").toString()); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor CustomTheme::remoteComment(Comment color) { @@ -491,6 +497,8 @@ QColor CustomTheme::remoteComment(Comment color) { case Comment::Timestamp: return QColor(comment.value("timestamp").toString()); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor CustomTheme::star() { diff --git a/src/app/Theme.cpp b/src/app/Theme.cpp index e78e33448..628842462 100644 --- a/src/app/Theme.cpp +++ b/src/app/Theme.cpp @@ -101,7 +101,14 @@ QColor Theme::badge(BadgeRole role, BadgeState state) { case BadgeState::Head: return QPalette().color(QPalette::HighlightedText); - default: + case BadgeState::Normal: // fall through + case BadgeState::Conflicted: // fall through + case BadgeState::Notification: // fall through + case BadgeState::Modified: // fall through + case BadgeState::Added: // fall through + case BadgeState::Deleted: // fall through + case BadgeState::Untracked: // fall through + case BadgeState::Renamed: // fall through return QPalette().color(QPalette::WindowText); } @@ -164,6 +171,8 @@ QColor Theme::commitEditor(CommitEditor color) { case CommitEditor::LengthWarning: return Qt::yellow; } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor Theme::diff(Diff color) { @@ -192,6 +201,8 @@ QColor Theme::diff(Diff color) { case Diff::Error: return "#7E494B"; } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } switch (color) { @@ -218,6 +229,8 @@ QColor Theme::diff(Diff color) { case Diff::Error: return "#FF0000"; } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor Theme::heatMap(HeatMap color) { @@ -228,6 +241,8 @@ QColor Theme::heatMap(HeatMap color) { return mDark ? QPalette().color(QPalette::Inactive, QPalette::Highlight) : QPalette().color(QPalette::Mid); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor Theme::remoteComment(Comment color) { @@ -241,6 +256,8 @@ QColor Theme::remoteComment(Comment color) { case Comment::Timestamp: return QPalette().color(QPalette::WindowText); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(color))); } QColor Theme::star() { return QPalette().color(QPalette::Highlight); } diff --git a/src/conf/Settings.cpp b/src/conf/Settings.cpp index d6c67e92c..6c2de3c36 100644 --- a/src/conf/Settings.cpp +++ b/src/conf/Settings.cpp @@ -10,6 +10,7 @@ #include "Settings.h" #include "ConfFile.h" #include "Debug.h" +#include "qtsupport.h" #include #include #include @@ -23,18 +24,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 +64,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 +108,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 +126,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 +139,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(); } @@ -171,6 +172,8 @@ QString Settings::promptDescription(Prompt::Kind kind) const { case Prompt::Kind::LargeFiles: return tr("Prompt to stage large files"); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(kind))); } void Settings::setHotkey(const QString &action, const QString &hotkey) { @@ -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 9d25d989f..f9bc061c4 100644 --- a/src/cred/CredentialHelper.cpp +++ b/src/cred/CredentialHelper.cpp @@ -10,6 +10,7 @@ #include "CredentialHelper.h" #include "Cache.h" #include "GitCredential.h" +#include "qtsupport.h" #include "Store.h" #include "conf/Settings.h" #include "git/Config.h" @@ -98,5 +99,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 cbd01d179..43db5c700 100644 --- a/src/cred/GitCredential.cpp +++ b/src/cred/GitCredential.cpp @@ -8,6 +8,7 @@ // #include "GitCredential.h" +#include "qtsupport.h" #include #include #include @@ -45,11 +46,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 +81,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/dialogs/ExternalToolsDialog.cpp b/src/dialogs/ExternalToolsDialog.cpp index 9e81575f5..20efa76b0 100644 --- a/src/dialogs/ExternalToolsDialog.cpp +++ b/src/dialogs/ExternalToolsDialog.cpp @@ -85,7 +85,7 @@ QVBoxLayout *ExternalToolsDialog::createUserDefinedLayout(const QString &type) { table->resizeColumnsToContents(); }); - connect(footer, &Footer::minusClicked, [this, table, model] { + connect(footer, &Footer::minusClicked, [table, model] { QModelIndexList indexes = table->selectionModel()->selectedRows(0); foreach (const QModelIndex &index, indexes) model->remove(index.data(Qt::DisplayRole).toString()); diff --git a/src/dialogs/StartDialog.cpp b/src/dialogs/StartDialog.cpp index 0504259f7..51ac0ebf0 100644 --- a/src/dialogs/StartDialog.cpp +++ b/src/dialogs/StartDialog.cpp @@ -698,7 +698,7 @@ void StartDialog::updateButtons() { open->setEnabled(false); } else { Account *account = parent.data(AccountRole).value(); - if (Repository *repo = index.data(RepositoryRole).value()) { + if (nullptr != index.data(RepositoryRole).value()) { if (account->repositoryPath(index.row()).isEmpty()) clone = true; } else { diff --git a/src/dialogs/ThemeDialog.cpp b/src/dialogs/ThemeDialog.cpp index c5ca00cb4..58fcb45be 100644 --- a/src/dialogs/ThemeDialog.cpp +++ b/src/dialogs/ThemeDialog.cpp @@ -62,7 +62,7 @@ class ThemeButton : public QPushButton { case Theme::Dark: Settings::instance()->setValue(Setting::Id::ColorTheme, "Dark"); break; - default: + case Theme::Default: Settings::instance()->setValue(Setting::Id::ColorTheme, "Default"); break; } diff --git a/src/editor/LexLPeg.cpp b/src/editor/LexLPeg.cpp index 662dceacc..af3c9991b 100644 --- a/src/editor/LexLPeg.cpp +++ b/src/editor/LexLPeg.cpp @@ -413,7 +413,7 @@ class LexerLPeg : public ILexer5 { 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 @@ class LexerLPeg : public ILexer5 { * @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 @@ class LexerLPeg : public ILexer5 { * @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,8 @@ class LexerLPeg : public ILexer5 { * @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 +567,7 @@ class LexerLPeg : public ILexer5 { * @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 +604,12 @@ class LexerLPeg : public ILexer5 { } } - 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 +637,7 @@ class LexerLPeg : public ILexer5 { 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/PlatQt.cpp b/src/editor/PlatQt.cpp index 5d866e2d6..e054f5cec 100644 --- a/src/editor/PlatQt.cpp +++ b/src/editor/PlatQt.cpp @@ -128,7 +128,7 @@ void SurfaceImpl::Polygon(Point *pts, size_t npts, ColourDesired fore, PenColour(fore); QVarLengthArray qpts(npts); - for (int i = 0; i < npts; i++) + for (size_t i = 0; i < npts; i++) qpts[i] = QPoint(pts[i].x, pts[i].y); QPainter *painter = GetPainter(); @@ -306,7 +306,7 @@ void SurfaceImpl::MeasureWidths(Font &font, std::string_view s, QTextLine tl = tlay.createLine(); tlay.endLayout(); - int i = 0; + size_t i = 0; int ui = 0; int fit = su.size(); const unsigned char *us = reinterpret_cast(s.data()); @@ -468,9 +468,6 @@ void Window::SetCursor(Cursor curs) { case cursorText: shape = Qt::IBeamCursor; break; - case cursorArrow: - shape = Qt::ArrowCursor; - break; case cursorUp: shape = Qt::UpArrowCursor; break; diff --git a/src/editor/ScintillaQt.cpp b/src/editor/ScintillaQt.cpp index 82f580f78..5df0cc9f9 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()); @@ -440,6 +439,7 @@ void ScintillaQt::dragEnterEvent(QDragEnterEvent *event) { } void ScintillaQt::dragLeaveEvent(QDragLeaveEvent *event) { + Q_UNUSED(event); SetDragPosition(SelectionPosition(Sci::invalidPosition)); } @@ -520,9 +520,8 @@ void ScintillaQt::inputMethodEvent(QInputMethodEvent *event) { const unsigned int ucWidth = commitStr.at(i).isHighSurrogate() ? 2 : 1; const QString oneCharUTF16 = commitStr.mid(i, ucWidth); const QByteArray oneChar = oneCharUTF16.toUtf8(); - const int oneCharLen = oneChar.length(); - AddCharUTF(oneChar.data(), oneCharLen); + InsertCharacter(oneChar.toStdString(), CharacterSource::directInput); i += ucWidth; } @@ -568,7 +567,7 @@ void ScintillaQt::inputMethodEvent(QInputMethodEvent *event) { indicator = SC_INDICATOR_CONVERTED; break; - default: + case QTextCharFormat::DashDotDotLine: indicator = SC_INDICATOR_UNKNOWN; } @@ -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); @@ -691,9 +690,23 @@ QVariant ScintillaQt::inputMethodQuery(Qt::InputMethodQuery query) const { return buffer.constData(); } - default: - return QVariant(); + case Qt::ImEnabled: // fall through + case Qt::ImAnchorPosition: // fall through + case Qt::ImHints: // fall through + case Qt::ImMaximumTextLength: // fall through + case Qt::ImPreferredLanguage: // fall through + case Qt::ImAbsolutePosition: // fall through + case Qt::ImTextBeforeCursor: // fall through + case Qt::ImTextAfterCursor: // fall through + case Qt::ImEnterKeyType: // fall through + case Qt::ImAnchorRectangle: // fall through + case Qt::ImInputItemClipRectangle: // fall through + case Qt::ImPlatformData: // fall through + case Qt::ImQueryInput: // fall through + case Qt::ImQueryAll: // fall through + break; } + return QVariant(); } void ScintillaQt::PasteFromMode(QClipboard::Mode clipboardMode) { diff --git a/src/editor/TextEditor.cpp b/src/editor/TextEditor.cpp index c53c0bb5c..1a4b87731 100644 --- a/src/editor/TextEditor.cpp +++ b/src/editor/TextEditor.cpp @@ -43,7 +43,9 @@ QPixmap stagedUnstagedIcon(const bool &checked, const QColor &background, QRect(QPoint(0, 0), QSize(fontHeight - 2, fontHeight - 2))); } +#if defined(FLATPAK) const float textHeightFactorCheckBoxSize = 2.0; +#endif } // namespace diff --git a/src/editor/TextEditor.h b/src/editor/TextEditor.h index 6d45dfb5a..0ae8b7b43 100644 --- a/src/editor/TextEditor.h +++ b/src/editor/TextEditor.h @@ -105,7 +105,7 @@ class TextEditor : public Scintilla::ScintillaIFace { 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 @@ class TextEditor : public Scintilla::ScintillaIFace { 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 c56e5913f..a85ae545d 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)); @@ -198,6 +198,8 @@ void Diff::sort(SortRole role, Qt::SortOrder order) { : (rhsStatus < lhsStatus); } } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(role))); }); } diff --git a/src/git/Patch.cpp b/src/git/Patch.cpp index 0543c5ae3..913104e4c 100644 --- a/src/git/Patch.cpp +++ b/src/git/Patch.cpp @@ -195,7 +195,7 @@ QByteArray Patch::header(int hidx) const { const git_diff_hunk *hunk = nullptr; int result = git_patch_get_hunk(&hunk, nullptr, d.data(), hidx); - return !result ? hunk->header : QByteArray(); + return (GIT_OK == result) ? hunk->header : QByteArray(); } const git_diff_hunk *Patch::header_struct(int hidx) const { @@ -204,7 +204,7 @@ const git_diff_hunk *Patch::header_struct(int hidx) const { const git_diff_hunk *hunk = nullptr; int result = git_patch_get_hunk(&hunk, nullptr, d.data(), hidx); - return hunk; + return (GIT_OK == result) ? hunk : nullptr; } int Patch::lineCount(int hidx) const { @@ -235,7 +235,7 @@ char Patch::lineOrigin(int hidx, int ln) const { const git_diff_line *line = nullptr; int result = git_patch_get_line_in_hunk(&line, d.data(), hidx, ln); - return !result ? line->origin : GIT_DIFF_LINE_CONTEXT; + return (GIT_OK == result) ? line->origin : GIT_DIFF_LINE_CONTEXT; } int Patch::lineNumber(int hidx, int ln, Diff::File file) const { @@ -256,7 +256,7 @@ git_off_t Patch::contentOffset(int hidx) const { const git_diff_line *line = nullptr; int result = git_patch_get_line_in_hunk(&line, d.data(), hidx, 0); // TODO: line index 0? - return result == 0 ? line->content_offset : 0; + return (GIT_OK == result) ? line->content_offset : 0; } QByteArray Patch::lineContent(int hidx, int ln) const { @@ -265,7 +265,8 @@ QByteArray Patch::lineContent(int hidx, int ln) const { const git_diff_line *line = nullptr; int result = git_patch_get_line_in_hunk(&line, d.data(), hidx, ln); - return !result ? QByteArray(line->content, line->content_len) : QByteArray(); + return (GIT_OK == result) ? QByteArray(line->content, line->content_len) + : QByteArray(); } Patch::ConflictResolution Patch::conflictResolution(int hidx) { @@ -435,6 +436,7 @@ void Patch::apply(QList> &image, int hidx, int start_line, break; default: + // no-op break; } } diff --git a/src/git/Rebase.cpp b/src/git/Rebase.cpp index c323ae895..a19574f62 100644 --- a/src/git/Rebase.cpp +++ b/src/git/Rebase.cpp @@ -36,8 +36,8 @@ const git_rebase_operation *Rebase::operation(size_t index) { } bool Rebase::hasNext() const { - int index = currentIndex(); - int count = git_rebase_operation_entrycount(d.data()); + size_t index = currentIndex(); + size_t count = git_rebase_operation_entrycount(d.data()); return (count > 0 && (index == GIT_REBASE_NO_OPERATION || index < count - 1)); } diff --git a/src/git/Remote.cpp b/src/git/Remote.cpp index dab10dddb..dfd1013ba 100644 --- a/src/git/Remote.cpp +++ b/src/git/Remote.cpp @@ -11,6 +11,7 @@ #include "Branch.h" #include "Config.h" #include "Id.h" +#include "qtsupport.h" #include "TagRef.h" #include "git2/buffer.h" #include "git2/clone.h" @@ -444,9 +445,10 @@ int Remote::Callbacks::transfer(const git_indexer_progress *stats, case Resolve: return cbs->resolve(stats->total_deltas, stats->indexed_deltas) ? 0 : -1; - default: + case Update: return 0; } + return 0; } int Remote::Callbacks::update(const char *name, const git_oid *a, @@ -674,7 +676,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 311b91c99..e224b9464 100644 --- a/src/git/Repository.cpp +++ b/src/git/Repository.cpp @@ -18,6 +18,7 @@ #include "FilterList.h" #include "Index.h" #include "Patch.h" +#include "qtsupport.h" #include "Rebase.h" #include "Reference.h" #include "Remote.h" @@ -487,7 +488,7 @@ QStringList Repository::existingTags() const { QStringList list; - for (int i = 0; i < array.count; i++) { + for (size_t i = 0; i < array.count; i++) { list.append(array.strings[i]); } @@ -628,6 +629,7 @@ Commit Repository::commit(const Signature &author, const Signature &committer, break; default: + // no-op break; } @@ -744,7 +746,7 @@ QList Repository::remotes() const { return QList(); QList remotes; - for (int i = 0; i < names.count; ++i) { + for (size_t i = 0; i < names.count; ++i) { if (Remote remote = lookupRemote(names.strings[i])) remotes.append(remote); } @@ -932,7 +934,6 @@ void Repository::rebaseContinue(const QString &commitMessage) { } } // Loop over rebase operations. - int count = r.count(); while (r.hasNext()) { git::Commit before = r.next(); if (!before.isValid()) { @@ -1052,7 +1053,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 3c7d53103..0e2af7030 100644 --- a/src/host/Account.cpp +++ b/src/host/Account.cpp @@ -30,8 +30,8 @@ const QString kThemeIconFmt = ":/%1_%2.png"; } // namespace Account::Account(const QString &username) - : mMgr(new QNetworkAccessManager()), mUsername(username), - mError(new AccountError(this)), mProgress(new AccountProgress(this)) { + : mUsername(username), mError(new AccountError(this)), + mProgress(new AccountProgress(this)), mMgr(new QNetworkAccessManager()) { QObject::connect( mMgr, &QNetworkAccessManager::sslErrors, [this](QNetworkReply *reply, const QList &errors) { @@ -204,6 +204,8 @@ QString Account::helpText(Kind kind) { case Beanstalk: return QString(); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(kind))); } QString Account::defaultUrl(Kind kind) { @@ -219,6 +221,8 @@ QString Account::defaultUrl(Kind kind) { case GitLab: return GitLab::defaultUrl(); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(kind))); } Account::Kind Account::kindFromString(const QString &kind, bool *ok) { @@ -258,6 +262,8 @@ QString Account::kindToString(Kind kind) { case GitLab: return "gitlab"; } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(kind))); } void Account::startProgress() { diff --git a/src/index/GenericLexer.cpp b/src/index/GenericLexer.cpp index 6851e9102..d0ea3dc23 100644 --- a/src/index/GenericLexer.cpp +++ b/src/index/GenericLexer.cpp @@ -93,7 +93,19 @@ Lexer::Lexeme GenericLexer::next() { } break; - default: + case Comment: // fall through + case Keyword: // fall through + case Operator: // fall through + case Error: // fall through + case Preprocessor: // fall through + case Constant: // fall through + case Variable: // fall through + case Function: // fall through + case Class: // fall through + case Type: // fall through + case Label: // fall through + case Regex: // fall through + case Embedded: // fall through Q_ASSERT(false); } } diff --git a/src/index/Index.cpp b/src/index/Index.cpp index 362162d6a..d48ad5d8d 100644 --- a/src/index/Index.cpp +++ b/src/index/Index.cpp @@ -182,7 +182,7 @@ bool Index::write(PostingMap map) { quint32 postCount = readVInt(postIn); bool end = (newIt == newEnd || newIt.key() != it->key); postings.reserve(postCount + (!end ? newIt.value().size() : 0)); - for (int i = 0; i < postCount; ++i) { + for (quint32 i = 0; i < postCount; ++i) { quint32 proxPos; Posting posting; posting.id = readVInt(postIn); @@ -243,7 +243,7 @@ QList Index::commits(const QString &filter) const { // Sort by commit date. QList commits = query->commits(this); std::sort(commits.begin(), commits.end(), - [this](const git::Commit &lhs, const git::Commit &rhs) { + [](const git::Commit &lhs, const git::Commit &rhs) { return (lhs.committer().date() > rhs.committer().date()); }); @@ -288,7 +288,7 @@ QList Index::postings(const Term &term, bool positional) const { // Read list. QList postings; quint32 postCount = readVInt(in); - for (int i = 0; i < postCount; ++i) { + for (quint32 i = 0; i < postCount; ++i) { quint32 proxPos; Posting posting; posting.id = readVInt(in); @@ -331,7 +331,7 @@ QList Index::postings(const Predicate &pred, // Read list. quint32 postCount = readVInt(in); - for (int i = 0; i < postCount; ++i) { + for (quint32 i = 0; i < postCount; ++i) { quint32 proxPos; Posting posting; posting.id = readVInt(in); @@ -373,7 +373,7 @@ QMap Index::fieldMap(const QString &prefix) const { // Read list. QString name = it->key; quint32 postCount = readVInt(in); - for (int i = 0; i < postCount; ++i) { + for (quint32 i = 0; i < postCount; ++i) { quint8 field; quint32 proxPos; readVInt(in); // Discard id. @@ -443,6 +443,8 @@ QByteArray Index::fieldName(Index::Field field) { case Index::Pathspec: return "pathspec"; } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(field))); } QDir Index::indexDir(const git::Repository &repo) { @@ -506,7 +508,7 @@ void Index::readPositions(QDataStream &in, QVector &positions) { quint32 prev = 0; quint32 count = readVInt(in); positions.reserve(count); - for (int i = 0; i < count; ++i) { + for (quint32 i = 0; i < count; ++i) { // Convert to absolute from delta. quint32 position = prev + readVInt(in); positions.append(position); diff --git a/src/index/Query.cpp b/src/index/Query.cpp index 0fbee5429..11d143085 100644 --- a/src/index/Query.cpp +++ b/src/index/Query.cpp @@ -182,16 +182,24 @@ class BooleanQuery : public Query { QList rhs = mRhs->commits(index); QList commits = mLhs->commits(index); if (mKind == And) { - // Remove commits that don't match the right hand side. +// Remove commits that don't match the right hand side. +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QSet set(rhs.begin(), rhs.end()); +#else QSet set = QSet::fromList(rhs); +#endif QMutableListIterator it(commits); while (it.hasNext()) { if (!set.contains(it.next())) it.remove(); } } else { - // Add commits that aren't already in the result set. +// Add commits that aren't already in the result set. +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QSet set(commits.begin(), commits.end()); +#else QSet set = QSet::fromList(commits); +#endif 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 2910f0dfe..b6473a171 100644 --- a/src/index/indexer.cpp +++ b/src/index/indexer.cpp @@ -10,6 +10,7 @@ #include "Index.h" #include "GenericLexer.h" #include "LPegLexer.h" +#include "qtsupport.h" #include "conf/Settings.h" #include "git/Config.h" #include "git/Index.h" @@ -105,7 +106,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) { @@ -148,7 +149,22 @@ void index(const Lexer::Lexeme &lexeme, Intermediate::FieldMap &fields, case Lexer::Comment: field |= Index::Comment; break; - default: + case Lexer::Nothing: // fall through + case Lexer::Whitespace: // fall through + case Lexer::Number: // fall through + case Lexer::Keyword: // fall through + case Lexer::Identifier: // fall through + case Lexer::Operator: // fall through + case Lexer::Error: // fall through + case Lexer::Preprocessor: // fall through + case Lexer::Constant: // fall through + case Lexer::Variable: // fall through + case Lexer::Function: // fall through + case Lexer::Class: // fall through + case Lexer::Type: // fall through + case Lexer::Label: // fall through + case Lexer::Regex: // fall through + case Lexer::Embedded: // fall through break; } @@ -172,7 +188,13 @@ void index(const Lexer::Lexeme &lexeme, Intermediate::FieldMap &fields, break; // Ignore everything else. - default: + case Lexer::Nothing: // fall through + case Lexer::Whitespace: // fall through + case Lexer::Number: // fall through + case Lexer::Operator: // fall through + case Lexer::Error: // fall through + case Lexer::Regex: // fall through + case Lexer::Embedded: // fall through break; } } @@ -331,7 +353,7 @@ class Map { QFile *mOut; int mContextLines = 3; - int mTermLimit = 1000000; + quint32 mTermLimit = 1000000; }; class Reduce { @@ -405,7 +427,12 @@ class Indexer : public QObject, public QAbstractNativeEventFilter { int count = 0; QList commits; git::Commit commit = mWalker.next(); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QSet ids(mIndex.ids().begin(), mIndex.ids().end()); +#else QSet ids = QSet::fromList(mIndex.ids()); +#endif while (commit.isValid() && count < 8192) { // Don't index merge commits. if (!commit.isMerge() && !ids.contains(commit.id())) { @@ -440,7 +467,7 @@ class Indexer : public QObject, public QAbstractNativeEventFilter { // 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. @@ -450,10 +477,14 @@ class Indexer : public QObject, public QAbstractNativeEventFilter { bool nativeEventFilter(const QByteArray &type, void *message, long *result) override { + Q_UNUSED(result); #ifdef Q_OS_WIN MSG *msg = static_cast(message); if (msg->message == WM_CLOSE) cancel(); +#else + Q_UNUSED(type); + Q_UNUSED(message); #endif return false; diff --git a/src/index/lexer_test.cpp b/src/index/lexer_test.cpp index 4b5881a49..4bfaba096 100644 --- a/src/index/lexer_test.cpp +++ b/src/index/lexer_test.cpp @@ -9,6 +9,7 @@ #include "GenericLexer.h" #include "LPegLexer.h" +#include "qtsupport.h" #include "conf/Settings.h" #include #include @@ -29,7 +30,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) { @@ -65,7 +66,13 @@ void print(QTextStream &out, Lexer *lexer, int indent = 0) { break; // Ignore everything else. - default: + case Lexer::Whitespace: // fall through + case Lexer::Nothing: // fall through + case Lexer::Number: // fall through + case Lexer::Operator: // fall through + case Lexer::Error: // fall through + case Lexer::Regex: // fall through + case Lexer::Embedded: break; } } @@ -102,7 +109,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 4b0bdb8ad..66e4c82fd 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 53f48e341..54190c1f3 100644 --- a/src/plugins/Plugin.cpp +++ b/src/plugins/Plugin.cpp @@ -8,6 +8,7 @@ // #include "Plugin.h" +#include "qtsupport.h" #include "conf/Settings.h" #include "editor/TextEditor.h" #include "git/Config.h" @@ -491,7 +492,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. @@ -613,6 +614,8 @@ QVariant Plugin::optionValue(const QString &key) const { case String: return config().value(kKeyFmt.arg(mName, key), value.toString()); } + throw std::runtime_error("unreachable; value=" + + std::to_string(static_cast(optionKind(key)))); } Plugin::OptionKind Plugin::optionKind(const QString &key) const { diff --git a/src/qtsupport.h b/src/qtsupport.h new file mode 100644 index 000000000..43b56c778 --- /dev/null +++ b/src/qtsupport.h @@ -0,0 +1,17 @@ +/// Backwards compatibility for older versions of QT +/// Several symbols have been deprecated in QT5.14 and moved to new +/// namespaces. This file provides support for older versions of QT. + +#include +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) +namespace Qt { +static auto endl = ::endl; +static auto KeepEmptyParts = QString::KeepEmptyParts; +static auto SkipEmptyParts = QString::SkipEmptyParts; +} // namespace Qt + +// QButtonGroup::buttonClicked is deprecated in favor of QButtonGroup::idClicked +#define idClicked buttonClicked +#endif \ No newline at end of file diff --git a/src/ui/BlameMargin.cpp b/src/ui/BlameMargin.cpp index c815ddbde..a8b4ea7ec 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 c3cb132b7..e018ee322 100644 --- a/src/ui/CommitList.cpp +++ b/src/ui/CommitList.cpp @@ -791,8 +791,8 @@ class CommitDelegate : public QStyledItemDelegate { 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) { @@ -1186,6 +1186,7 @@ CommitList::CommitList(Index *index, QWidget *parent) connect(model, &CommitModel::statusFinished, [this, model](bool visible) { mRestoreSelection = true; // Reset to default // Fake a selection notification if the diff is visible and selected. + // FIXME: Should we reference `model` or `this->mModel` here? if (visible && selectionModel()->isSelected(mModel->index(0, 0))) resetSelection(); @@ -1239,6 +1240,7 @@ git::Diff CommitList::selectedDiff() const { DebugRefresh("Selected indices count: " << indexes.count()); for (const auto &index : indexes) { const auto &id = index.data(CommitRole).value().shortId(); + (void)id; // Unused in release builds DebugRefresh("Commit: " << id); } if (indexes.isEmpty()) diff --git a/src/ui/DetailView.cpp b/src/ui/DetailView.cpp index b05dee5e9..5dbc86af9 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 @@ class AuthorCommitterDate : public QWidget { 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 @@ class AuthorCommitterDate : public QWidget { 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; + height = qMax(author.height(), date.height()) + committer.height() + + mSpacing.y(); return QSize(width, height); } @@ -151,8 +153,8 @@ class AuthorCommitterDate : public QWidget { if (mSameAuthorCommitter) height = qMax(qMax(author.height(), committer.height()), date.height()); else - height = - qMax(author.height(), date.height()) + committer.height() + mSpacing; + height = qMax(author.height(), date.height()) + committer.height() + + mSpacing.y(); return QSize(width, height); } @@ -165,8 +167,8 @@ class AuthorCommitterDate : public QWidget { 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,13 @@ class AuthorCommitterDate : public QWidget { 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; + int y = wrapped + ? mAuthor->height() + mCommitter->height() + 2 * mSpacing.y() + : 0; mDate->move(x, y); updateGeometry(); } @@ -210,7 +213,7 @@ class AuthorCommitterDate : public QWidget { QLabel *mCommitter; QLabel *mDate; - int mSpacing; + QPoint mSpacing; bool mSameAuthorCommitter{false}; }; @@ -348,8 +351,9 @@ class CommitDetail : public QFrame { // 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 +391,7 @@ class CommitDetail : public QFrame { 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/DiffTreeModel.cpp b/src/ui/DiffTreeModel.cpp index c80cd2b60..a722705c6 100644 --- a/src/ui/DiffTreeModel.cpp +++ b/src/ui/DiffTreeModel.cpp @@ -430,10 +430,7 @@ void Node::addChild(const QStringList &pathPart, int patchIndex, git::Index::StagedState Node::stageState(const git::Index &idx, ParentStageState searchingState) const { - if (!hasChildren()) - return idx.isStaged(path(true)); - - git::Index::StagedState childState; + git::Index::StagedState childState = idx.isStaged(path(true)); for (auto child : mChildren) { childState = child->stageState(idx, searchingState); diff --git a/src/ui/DiffView/Comment.cpp b/src/ui/DiffView/Comment.cpp index bc4a2c89d..58508a839 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/FileWidget.cpp b/src/ui/DiffView/FileWidget.cpp index 2d02aa67d..0947deffa 100644 --- a/src/ui/DiffView/FileWidget.cpp +++ b/src/ui/DiffView/FileWidget.cpp @@ -85,7 +85,7 @@ _FileWidget::Header::Header(const git::Diff &diff, const git::Patch &patch, git::RepositoryNotifier *notifier = patch.repo().notifier(); connect(notifier, &git::RepositoryNotifier::lfsLocksChanged, this, - [this, patch, lfsLockButton] { + [patch, lfsLockButton] { bool locked = patch.repo().lfsIsLocked(patch.name()); lfsLockButton->setText(locked ? FileWidget::tr("Unlock") : FileWidget::tr("Lock")); @@ -560,10 +560,7 @@ void FileWidget::updatePatch(const git::Patch &patch, const git::Patch &staged, int hunkCount = patch.count(); for (int hidx = 0; hidx < hunkCount; ++hidx) { HunkWidget *hunk = addHunk(mDiff, patch, staged, hidx, lfs, submodule); - int startLine = patch.lineNumber(hidx, 0, git::Diff::OldFile); - // hunk->header()->check()->setChecked(stagedHunks.contains(startLine)); - // // not correct, because it could also only a part of the hunk staged - // (single lines) + patch.lineNumber(hidx, 0, git::Diff::OldFile); mHunkLayout->addWidget(hunk); } } else { @@ -786,7 +783,7 @@ void FileWidget::discard() { : FileWidget::tr("Discard Changes"); QPushButton *discard = dialog->addButton(button, QMessageBox::AcceptRole); connect(discard, &QPushButton::clicked, - [this, untracked] { emit discarded(mModelIndex); }); + [this] { emit discarded(mModelIndex); }); dialog->exec(); } diff --git a/src/ui/DiffView/HunkWidget.cpp b/src/ui/DiffView/HunkWidget.cpp index c7c3b0b26..d21b24411 100644 --- a/src/ui/DiffView/HunkWidget.cpp +++ b/src/ui/DiffView/HunkWidget.cpp @@ -497,8 +497,6 @@ void HunkWidget::unstageSelected(int startLine, int end, bool emitSignal) { void HunkWidget::discardDialog(int startLine, int end) { QString name = mPatch.name(); - int line = mPatch.lineNumber(mIndex, 0, git::Diff::NewFile); - QString title = HunkWidget::tr("Discard selected lines?"); QString text = mPatch.isUntracked() @@ -785,7 +783,7 @@ void HunkWidget::load(git::Patch &staged, bool force) { mHeader->theirsButton()->click(); break; - default: + case git::Patch::Unresolved: break; } } @@ -1125,7 +1123,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 +1162,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 +1196,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/EditorWindow.cpp b/src/ui/EditorWindow.cpp index 12ec3ce91..e59307bb3 100644 --- a/src/ui/EditorWindow.cpp +++ b/src/ui/EditorWindow.cpp @@ -98,6 +98,7 @@ void EditorWindow::closeEvent(QCloseEvent *event) { editor->save(); break; default: + // no-op break; } } diff --git a/src/ui/FileContextMenu.cpp b/src/ui/FileContextMenu.cpp index 9c46b9baf..b7e184b24 100644 --- a/src/ui/FileContextMenu.cpp +++ b/src/ui/FileContextMenu.cpp @@ -71,7 +71,14 @@ void handlePath(const git::Repository &repo, const QString &path, untracked.append(path); break; - default: + case GIT_DELTA_UNMODIFIED: // fall through + case GIT_DELTA_ADDED: // fall through + case GIT_DELTA_RENAMED: // fall through + case GIT_DELTA_COPIED: // fall through + case GIT_DELTA_IGNORED: // fall through + case GIT_DELTA_TYPECHANGE: // fall through + case GIT_DELTA_UNREADABLE: // fall through + case GIT_DELTA_CONFLICTED: // fall through break; } } @@ -115,7 +122,8 @@ FileContextMenu::FileContextMenu(RepoView *view, const QStringList &files, mergeTools.append(tool); break; - default: + case ExternalTool::Show: // fall through + case ExternalTool::Edit: Q_ASSERT(false); break; } diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 97b6c09d9..2b469c8f4 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/MenuBar.cpp b/src/ui/MenuBar.cpp index 9c7549006..39f8b3865 100644 --- a/src/ui/MenuBar.cpp +++ b/src/ui/MenuBar.cpp @@ -364,7 +364,7 @@ MenuBar::MenuBar(QWidget *parent) : QMenuBar(parent) { mRedo = edit->addAction(tr("Redo")); redoHotkey.use(mRedo); - connect(mRedo, &QAction::triggered, [this] { + connect(mRedo, &QAction::triggered, [] { QWidget *widget = QApplication::focusWidget(); if (TextEditor *editor = qobject_cast(widget)) { editor->redo(); @@ -984,6 +984,7 @@ void MenuBar::updateCutCopyPaste() { mPaste->setEnabled(canPaste); mFindSelection->setEnabled(editor->hasSelectedText()); } else if (LogView *logView = qobject_cast(widget)) { + (void)logView; // unused mCopy->setEnabled(true); } } diff --git a/src/ui/ReferenceModel.cpp b/src/ui/ReferenceModel.cpp index 561673d5e..5dbd29b3d 100644 --- a/src/ui/ReferenceModel.cpp +++ b/src/ui/ReferenceModel.cpp @@ -266,7 +266,8 @@ 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/ReferenceView.cpp b/src/ui/ReferenceView.cpp index 96ddf87de..84b3b39df 100644 --- a/src/ui/ReferenceView.cpp +++ b/src/ui/ReferenceView.cpp @@ -321,7 +321,7 @@ void ReferenceView::contextMenuEvent(QContextMenuEvent *event) { git::Remote remote = ref.repo().defaultRemote(); if (remote.isValid()) { menu.addAction(tr("Push Tag to %1").arg(remote.name()), - [this, ref, view, remote] { view->push(remote, ref); }); + [ref, view, remote] { view->push(remote, ref); }); } } diff --git a/src/ui/RemoteCallbacks.cpp b/src/ui/RemoteCallbacks.cpp index 9d3fdf932..b5ba06069 100644 --- a/src/ui/RemoteCallbacks.cpp +++ b/src/ui/RemoteCallbacks.cpp @@ -7,6 +7,7 @@ // Author: Jason Haslam // +#include "qtsupport.h" #include "RemoteCallbacks.h" #include "conf/Settings.h" #include "cred/CredentialHelper.h" @@ -235,7 +236,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 1c850d015..b9ee24368 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -17,6 +17,7 @@ #include "MainWindow.h" #include "MenuBar.h" #include "PathspecWidget.h" +#include "qtsupport.h" #include "ReferenceWidget.h" #include "RemoteCallbacks.h" #include "SearchField.h" @@ -882,7 +883,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 +908,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(); @@ -1457,7 +1458,7 @@ void RepoView::rebaseAboutToRebase(const git::Rebase rebase, QString beforeText = before.link(); QString step = tr("%1/%2").arg(currIndex).arg(rebase.count()); QString text = tr("%1 - %2").arg(step, beforeText); - LogEntry *entry = mRebase->addEntry(text, tr("Apply")); + mRebase->addEntry(text, tr("Apply")); } void RepoView::rebaseConflict(const git::Rebase rebase) { @@ -2787,14 +2788,15 @@ void RepoView::refresh() { refresh(true); } void RepoView::refresh(bool restoreSelection) { // Fake head update. - uint32_t counter = 0; auto dtw = findChild(); - if (dtw) - counter = dtw->setDiffCounter(); - if (mRepo.head().isValid()) + if (dtw) { + dtw->setDiffCounter(); + } + if (mRepo.head().isValid()) { DebugRefresh("Head name: " << mRepo.head().name()); - else + } else { DebugRefresh("Head invalid"); + } DebugRefresh("time: " << QDateTime::currentDateTime() << " Set diff counter: " << counter); emit mRepo.notifier()->referenceUpdated(mRepo.head(), restoreSelection); diff --git a/src/ui/RepoView.h b/src/ui/RepoView.h index fd9cbf2c9..6040ea863 100644 --- a/src/ui/RepoView.h +++ b/src/ui/RepoView.h @@ -41,7 +41,7 @@ class PathspecWidget; class ReferenceWidget; class RemoteCallbacks; class ToolBar; -class ContributorInfo; +struct ContributorInfo; namespace git { class Result; diff --git a/src/ui/SideBar.cpp b/src/ui/SideBar.cpp index 53e9bf104..e64b94cbb 100644 --- a/src/ui/SideBar.cpp +++ b/src/ui/SideBar.cpp @@ -709,7 +709,7 @@ SideBar::SideBar(TabWidget *tabs, QWidget *parent) : QWidget(parent) { QAction *clone = plusMenu->addAction(tr("Clone Repository")); connect(clone, &QAction::triggered, [this] { CloneDialog *dialog = new CloneDialog(CloneDialog::Clone, this); - connect(dialog, &CloneDialog::accepted, [this, dialog] { + connect(dialog, &CloneDialog::accepted, [dialog] { if (MainWindow *window = MainWindow::open(dialog->path())) window->currentView()->addLogEntry(dialog->message(), dialog->messageTitle()); @@ -733,7 +733,7 @@ SideBar::SideBar(TabWidget *tabs, QWidget *parent) : QWidget(parent) { QAction *init = plusMenu->addAction(tr("Initialize New Repository")); connect(init, &QAction::triggered, [this] { CloneDialog *dialog = new CloneDialog(CloneDialog::Init, this); - connect(dialog, &CloneDialog::accepted, [this, dialog] { + connect(dialog, &CloneDialog::accepted, [dialog] { if (MainWindow *window = MainWindow::open(dialog->path())) window->currentView()->addLogEntry(dialog->message(), dialog->messageTitle()); @@ -811,7 +811,7 @@ SideBar::SideBar(TabWidget *tabs, QWidget *parent) : QWidget(parent) { QAction *clear = contextMenu->addAction(tr("Clear All Recent")); connect(clear, &QAction::triggered, - [this] { RecentRepositories::instance()->clear(); }); + [] { RecentRepositories::instance()->clear(); }); QAction *showFullPath = contextMenu->addAction(tr("Show Full Path")); bool recentChecked = settings.value("start/recent/fullpath").toBool(); diff --git a/src/ui/TabWidget.cpp b/src/ui/TabWidget.cpp index d308d180c..7c48264ec 100644 --- a/src/ui/TabWidget.cpp +++ b/src/ui/TabWidget.cpp @@ -42,7 +42,7 @@ class DefaultWidget : public QFrame { addButton(QIcon(":/clone.png"), tr("Clone repository")); connect(clone, &QPushButton::clicked, [this] { CloneDialog *dialog = new CloneDialog(CloneDialog::Clone, this); - connect(dialog, &CloneDialog::accepted, [this, dialog] { + connect(dialog, &CloneDialog::accepted, [dialog] { if (MainWindow *window = MainWindow::open(dialog->path())) window->currentView()->addLogEntry(dialog->message(), dialog->messageTitle()); @@ -68,7 +68,7 @@ class DefaultWidget : public QFrame { addButton(QIcon(":/new.png"), tr("Initialize new repository")); connect(init, &QPushButton::clicked, [this] { CloneDialog *dialog = new CloneDialog(CloneDialog::Init, this); - connect(dialog, &CloneDialog::accepted, [this, dialog] { + connect(dialog, &CloneDialog::accepted, [dialog] { if (MainWindow *window = MainWindow::open(dialog->path())) window->currentView()->addLogEntry(dialog->message(), dialog->messageTitle()); diff --git a/src/ui/TemplateDialog.cpp b/src/ui/TemplateDialog.cpp index fde7a8be2..554783d1e 100644 --- a/src/ui/TemplateDialog.cpp +++ b/src/ui/TemplateDialog.cpp @@ -296,7 +296,7 @@ void TemplateDialog::exportTemplates(QString filename) { } QString templatesStr; - for (const auto tmpl : mNew) { + for (const auto &tmpl : mNew) { QString name = tmpl.name; QString value = tmpl.value; value = value.replace(QStringLiteral("\n"), QStringLiteral("\\n")); diff --git a/src/ui/ToolBar.cpp b/src/ui/ToolBar.cpp index 55ffb6196..2be9e76fe 100644 --- a/src/ui/ToolBar.cpp +++ b/src/ui/ToolBar.cpp @@ -10,6 +10,7 @@ #include "ToolBar.h" #include "History.h" #include "MainWindow.h" +#include "qtsupport.h" #include "RepoView.h" #include "SearchField.h" #include "app/Application.h" @@ -695,7 +696,6 @@ class FileManagerButton : public Button { initStyleOption(&opt); QColor color = opt.palette.buttonText().color(); - QColor light = (isEnabled() && isActiveWindow()) ? color.lighter() : color; QPainter painter(this); painter.setPen(QPen(color, 1.0)); @@ -883,7 +883,7 @@ ToolBar::ToolBar(MainWindow *parent) : QToolBar(parent) { QAction *appConfigAction = configMenu->addAction(tr("Application settings")); connect(appConfigAction, &QAction::triggered, - [this] { SettingsDialog::openSharedInstance(); }); + [] { SettingsDialog::openSharedInstance(); }); addWidget(new Spacer(4, this)); @@ -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/src/ui/TreeProxy.cpp b/src/ui/TreeProxy.cpp index 18a081c15..f956c3a6b 100644 --- a/src/ui/TreeProxy.cpp +++ b/src/ui/TreeProxy.cpp @@ -24,7 +24,7 @@ const QString kLinkFmt = "%2"; } // namespace TreeProxy::TreeProxy(bool staged, QObject *parent) - : mStaged(staged), QSortFilterProxyModel(parent) {} + : QSortFilterProxyModel(parent), mStaged(staged) {} TreeProxy::~TreeProxy() {} diff --git a/src/ui/TreeProxy.h b/src/ui/TreeProxy.h index 3dd012958..2e8d75ae2 100644 --- a/src/ui/TreeProxy.h +++ b/src/ui/TreeProxy.h @@ -31,6 +31,7 @@ class TreeProxy : public QSortFilterProxyModel { void enableFilter(bool enable) { mFilter = enable; } private: + using QSortFilterProxyModel::setData; bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; bool mStaged{ diff --git a/src/update/Updater.cpp b/src/update/Updater.cpp index 4c693c594..8731d3eb6 100644 --- a/src/update/Updater.cpp +++ b/src/update/Updater.cpp @@ -65,7 +65,7 @@ Updater::Download::~Download() { delete mFile; } Updater::Updater(QObject *parent) : QObject(parent) { // Set up connections. connect(&mMgr, &QNetworkAccessManager::sslErrors, this, &Updater::sslErrors); - connect(this, &Updater::upToDate, [this] { + connect(this, &Updater::upToDate, [] { UpToDateDialog dialog; dialog.exec(); }); diff --git a/src/watcher/RepositoryWatcher_linux.cpp b/src/watcher/RepositoryWatcher_linux.cpp index 3466ce6bc..f79755ea7 100644 --- a/src/watcher/RepositoryWatcher_linux.cpp +++ b/src/watcher/RepositoryWatcher_linux.cpp @@ -90,7 +90,7 @@ class RepositoryWatcherPrivate : public QThread { ignored = false; // Start watching new directories. - int mask = (IN_CREATE | IN_ISDIR); + uint32_t mask = (IN_CREATE | IN_ISDIR); if ((event->mask & mask) == mask) watch(path); } diff --git a/src/watcher/RepositoryWatcher_win.cpp b/src/watcher/RepositoryWatcher_win.cpp index 7c9d2ed35..043965b16 100644 --- a/src/watcher/RepositoryWatcher_win.cpp +++ b/src/watcher/RepositoryWatcher_win.cpp @@ -67,6 +67,7 @@ class RepositoryWatcherPrivate : public QThread { break; default: + // no-op break; // FIXME: Report error? } } diff --git a/test/Submodule.cpp b/test/Submodule.cpp index 19f8b2752..f66915aa5 100644 --- a/test/Submodule.cpp +++ b/test/Submodule.cpp @@ -9,6 +9,7 @@ #include "Test.h" +#include "qtsupport.h" #include "dialogs/CloneDialog.h" #include "ui/MainWindow.h" #include "ui/RepoView.h" @@ -147,14 +148,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 a39c2969f..475aebee6 100644 --- a/test/amend.cpp +++ b/test/amend.cpp @@ -1,5 +1,6 @@ #include "Test.h" +#include "qtsupport.h" #include "git/Signature.h" #include "git/Reference.h" #include "git/Tree.h" @@ -94,7 +95,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 +140,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 e26c3ff0b..c6592afe6 100644 --- a/test/index.cpp +++ b/test/index.cpp @@ -7,6 +7,7 @@ // Author: Jason Haslam // +#include "qtsupport.h" #include "Test.h" #include "ui/DoubleTreeWidget.h" #include "ui/MainWindow.h" @@ -44,7 +45,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 +136,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 836ad3690..1210703d0 100644 --- a/test/merge.cpp +++ b/test/merge.cpp @@ -7,6 +7,7 @@ // Author: Shane Gramlich // +#include "qtsupport.h" #include "Test.h" #include "ui/MainWindow.h" #include "ui/DetailView.h" @@ -54,7 +55,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 +93,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 +131,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);