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)
This commit is contained in:
Micha WERLE 2023-08-16 14:50:58 +09:00 committed by Michael Werle
parent e6b5f83d68
commit e21bea8d15
32 changed files with 152 additions and 114 deletions

View File

@ -435,6 +435,8 @@ QColor CustomTheme::commitEditor(CommitEditor color) {
return commitEditor.value("spellignore").value<QColor>();
case CommitEditor::LengthWarning:
return commitEditor.value("lengthwarning").value<QColor>();
default:
throw std::runtime_error("Not Implemented or invalid enum " + std::to_string(static_cast<int>(color)));
}
}
@ -464,6 +466,8 @@ QColor CustomTheme::diff(Diff color) {
return diff.value("warning").value<QColor>();
case Diff::Error:
return diff.value("error").value<QColor>();
default:
throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast<int>(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<int>(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<int>(color)));
}
}

View File

@ -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<int>(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<int>(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<int>(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<int>(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<int>(color)));
}
}

View File

@ -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<int>(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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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<void *>(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<void *>(&props));
lua_setfield(L, LUA_REGISTRYINDEX, "sci_props");
lua_pushlightuserdata(L, reinterpret_cast<void *>(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<void *>(&props));
lua_setfield(L, LUA_REGISTRYINDEX, "sci_props");
lua_pushlightuserdata(L, reinterpret_cast<void *>(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<SciFnDirect>(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(); }

View File

@ -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<ScintillaQt *>(this)->LocationFromPosition(startPos);

View File

@ -105,7 +105,7 @@ public:
QList<Diagnostic> 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;

View File

@ -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<int>(role)));
}
});
}

View File

@ -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

View File

@ -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();

View File

@ -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<int>(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<int>(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<int>(kind)));
}
}

View File

@ -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<int>(field)));
}
}

View File

@ -183,7 +183,7 @@ public:
QList<git::Commit> commits = mLhs->commits(index);
if (mKind == And) {
// Remove commits that don't match the right hand side.
QSet<git::Commit> set = QSet<git::Commit>::fromList(rhs);
QSet<git::Commit> set(rhs.begin(), rhs.end());
QMutableListIterator<git::Commit> 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<git::Commit> set = QSet<git::Commit>::fromList(commits);
QSet<git::Commit> set(commits.begin(), commits.end());
foreach (const git::Commit &commit, rhs) {
if (!set.contains(commit))
commits.append(commit);

View File

@ -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<git::Commit> commits;
git::Commit commit = mWalker.next();
QSet<git::Id> ids = QSet<git::Id>::fromList(mIndex.ids());
QSet<git::Id> 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.

View File

@ -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);
}
}

View File

@ -9,6 +9,7 @@
#include "LogModel.h"
#include "LogEntry.h"
#include <QLocale>
#include <QStyle>
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);
}
}

View File

@ -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<QString>(kKeyFmt.arg(mName, key), value.toString());
default:
throw std::runtime_error("Not Implemented or invalid enum" + std::to_string(static_cast<int>(optionKind(key))));
}
}

View File

@ -110,7 +110,7 @@ bool BlameMargin::event(QEvent *event) {
git::Signature signature = mBlame.signature(index);
if (signature.isValid()) {
email = QString("&lt;%1&gt;").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())

View File

@ -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) {

View File

@ -38,6 +38,7 @@
#include <QNetworkRequest>
#include <QPainter>
#include <QPainterPath>
#include <QPoint>
#include <QPushButton>
#include <QRegularExpression>
#include <QStackedWidget>
@ -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()));

View File

@ -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(' ') *

View File

@ -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;
}

View File

@ -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) {

View File

@ -266,7 +266,7 @@ QVariant ReferenceModel::data(const QModelIndex &index, int role) const {
QString email = QString("&lt;%1&gt;").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));
}

View File

@ -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()) {

View File

@ -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();

View File

@ -916,7 +916,7 @@ ToolBar::ToolBar(MainWindow *parent) : QToolBar(parent) {
addWidget(mode);
using Signal = void (QButtonGroup::*)(int);
auto signal = static_cast<Signal>(&QButtonGroup::buttonClicked);
auto signal = static_cast<Signal>(&QButtonGroup::idClicked);
connect(mModeGroup, signal, [this](int index) {
currentView()->setViewMode(static_cast<RepoView::ViewMode>(index));
});

View File

@ -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();
}

View File

@ -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);

View File

@ -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);

View File

@ -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);