Fix obsolete code.

This commit is contained in:
Martin Rotter 2020-05-04 10:07:07 +02:00
parent 3d2abecc67
commit f1b3184aaa
14 changed files with 53 additions and 43 deletions

View file

@ -43,8 +43,11 @@ void FeedDownloader::updateAvailableFeeds() {
} }
while (!m_feeds.isEmpty()) { while (!m_feeds.isEmpty()) {
connect(m_feeds.first(), &Feed::messagesObtained, this, &FeedDownloader::oneFeedUpdateFinished, connect(m_feeds.first(),
(Qt::ConnectionType)(Qt::UniqueConnection | Qt::AutoConnection)); &Feed::messagesObtained,
this,
&FeedDownloader::oneFeedUpdateFinished,
Qt::ConnectionType(Qt::UniqueConnection | Qt::AutoConnection));
if (m_threadPool->tryStart(m_feeds.first())) { if (m_threadPool->tryStart(m_feeds.first())) {
m_feeds.removeFirst(); m_feeds.removeFirst();
@ -150,11 +153,9 @@ void FeedDownloadResults::appendUpdatedFeed(const QPair<QString, int>& feed) {
} }
void FeedDownloadResults::sort() { void FeedDownloadResults::sort() {
qSort(m_updatedFeeds.begin(), m_updatedFeeds.end(), FeedDownloadResults::lessThan); std::sort(m_updatedFeeds.begin(), m_updatedFeeds.end(), [](const QPair<QString, int>& lhs, const QPair<QString, int>& rhs) {
} return lhs.second > rhs.second;
});
bool FeedDownloadResults::lessThan(const QPair<QString, int>& lhs, const QPair<QString, int>& rhs) {
return lhs.second > rhs.second;
} }
void FeedDownloadResults::clear() { void FeedDownloadResults::clear() {

View file

@ -23,8 +23,6 @@ class FeedDownloadResults {
void sort(); void sort();
void clear(); void clear();
static bool lessThan(const QPair<QString, int>& lhs, const QPair<QString, int>& rhs);
private: private:
// QString represents title if the feed, int represents count of newly downloaded messages. // QString represents title if the feed, int represents count of newly downloaded messages.

View file

@ -48,7 +48,9 @@ void DynamicShortcutsWidget::updateShortcuts() {
void DynamicShortcutsWidget::populate(QList<QAction*> actions) { void DynamicShortcutsWidget::populate(QList<QAction*> actions) {
m_actionBindings.clear(); m_actionBindings.clear();
qSort(actions.begin(), actions.end(), DynamicShortcutsWidget::lessThan); std::sort(actions.begin(), actions.end(), [](QAction* lhs, QAction* rhs) {
return QString::localeAwareCompare(lhs->text().replace(QL1S("&"), QString()), rhs->text().replace(QL1S("&"), QString())) < 0;
});
int row_id = 0; int row_id = 0;
// FIXME: Maybe separate actions into "categories". Each category will start with label. // FIXME: Maybe separate actions into "categories". Each category will start with label.
@ -93,7 +95,3 @@ void DynamicShortcutsWidget::populate(QList<QAction*> actions) {
m_layout->setRowStretch(row_id, 1); m_layout->setRowStretch(row_id, 1);
m_layout->setColumnStretch(1, 1); m_layout->setColumnStretch(1, 1);
} }
bool DynamicShortcutsWidget::lessThan(QAction* lhs, QAction* rhs) {
return QString::localeAwareCompare(lhs->text().replace(QL1S("&"), QString()), rhs->text().replace(QL1S("&"), QString())) < 0;
}

View file

@ -38,9 +38,6 @@ class DynamicShortcutsWidget : public QWidget {
signals: signals:
void setupChanged(); void setupChanged();
private:
static bool lessThan(QAction* lhs, QAction* rhs);
private: private:
QGridLayout* m_layout; QGridLayout* m_layout;

View file

@ -9,7 +9,11 @@ void SqueezeLabel::paintEvent(QPaintEvent* event) {
m_squeezedTextCache = text(); m_squeezedTextCache = text();
QFontMetrics fm = fontMetrics(); QFontMetrics fm = fontMetrics();
#if QT_VERSION >= 0x050B00 // Qt >= 5.11.0
if (fm.horizontalAdvance(m_squeezedTextCache) > contentsRect().width()) {
#else
if (fm.width(m_squeezedTextCache) > contentsRect().width()) { if (fm.width(m_squeezedTextCache) > contentsRect().width()) {
#endif
setText(fm.elidedText(text(), Qt::ElideMiddle, width())); setText(fm.elidedText(text(), Qt::ElideMiddle, width()));
} }
} }

View file

@ -9,7 +9,7 @@ class SqueezeLabel : public QLabel {
Q_OBJECT Q_OBJECT
public: public:
explicit SqueezeLabel(QWidget* parent = 0); explicit SqueezeLabel(QWidget* parent = nullptr);
protected: protected:
void paintEvent(QPaintEvent* event); void paintEvent(QPaintEvent* event);

View file

@ -24,7 +24,7 @@ AutoSaver::~AutoSaver() {
} }
void AutoSaver::changeOccurred() { void AutoSaver::changeOccurred() {
if (m_firstChange.isNull()) { if (!m_firstChange.isValid()) {
m_firstChange.start(); m_firstChange.start();
} }
@ -48,7 +48,7 @@ void AutoSaver::timerEvent(QTimerEvent* event) {
void AutoSaver::saveIfNeccessary() { void AutoSaver::saveIfNeccessary() {
if (m_timer.isActive()) { if (m_timer.isActive()) {
m_timer.stop(); m_timer.stop();
m_firstChange = QTime(); m_firstChange.invalidate();
if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) { if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) {
qWarning("AutoSaver: error invoking slot save() on parent."); qWarning("AutoSaver: error invoking slot save() on parent.");

View file

@ -4,8 +4,8 @@
#define AUTOSAVER_H #define AUTOSAVER_H
#include <QBasicTimer> #include <QBasicTimer>
#include <QElapsedTimer>
#include <QObject> #include <QObject>
#include <QTime>
class AutoSaver : public QObject { class AutoSaver : public QObject {
Q_OBJECT Q_OBJECT
@ -24,7 +24,7 @@ class AutoSaver : public QObject {
private: private:
QBasicTimer m_timer; QBasicTimer m_timer;
QTime m_firstChange; QElapsedTimer m_firstChange;
}; };
#endif // AUTOSAVER_H #endif // AUTOSAVER_H

View file

@ -104,8 +104,18 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString&
} }
} }
else if (database.lastError().isValid()) { else if (database.lastError().isValid()) {
// Connection failed, do cleanup and return specific error code. auto nat = database.lastError().nativeErrorCode();
return static_cast<MySQLError>(database.lastError().number()); bool nat_converted = false;
auto nat_int = nat.toInt(&nat_converted);
if (nat_converted) {
return static_cast<MySQLError>(nat_int);
}
else {
qWarning("Failed to recognize MySQL error code: '%s'.", qPrintable(nat));
return MySQLError::MySQLUnknownError;
}
} }
else { else {
return MySQLError::MySQLUnknownError; return MySQLError::MySQLUnknownError;

View file

@ -30,7 +30,11 @@ int TextFactory::stringWidth(const QString& string, const QFontMetrics& metrics)
int width = 0; int width = 0;
foreach (const QString& line, lines) { foreach (const QString& line, lines) {
#if QT_VERSION >= 0x050B00 // Qt >= 5.11.0
int line_width = metrics.horizontalAdvance(line);
#else
int line_width = metrics.width(line); int line_width = metrics.width(line);
#endif
if (line_width > width) { if (line_width > width) {
width = line_width; width = line_width;

View file

@ -15,12 +15,6 @@ class TextFactory {
TextFactory(); TextFactory();
public: public:
// Returns true if lhs is smaller than rhs if case-insensitive string comparison is used.
static inline bool isCaseInsensitiveLessThan(const QString& lhs, const QString& rhs) {
return lhs.toLower() < rhs.toLower();
}
static int stringHeight(const QString& string, const QFontMetrics& metrics); static int stringHeight(const QString& string, const QFontMetrics& metrics);
static int stringWidth(const QString& string, const QFontMetrics& metrics); static int stringWidth(const QString& string, const QFontMetrics& metrics);

View file

@ -9,6 +9,7 @@
#include "gui/tabcontent.h" #include "gui/tabcontent.h"
#include <QDateTime> #include <QDateTime>
#include <QElapsedTimer>
#include <QFile> #include <QFile>
#include <QNetworkReply> #include <QNetworkReply>
@ -27,7 +28,7 @@ class DownloadItem : public QWidget {
public: public:
// Constructors. // Constructors.
explicit DownloadItem(QNetworkReply* reply = 0, QWidget* parent = 0); explicit DownloadItem(QNetworkReply* reply = 0, QWidget* parent = nullptr);
virtual ~DownloadItem(); virtual ~DownloadItem();
bool downloading() const; bool downloading() const;
@ -67,7 +68,7 @@ class DownloadItem : public QWidget {
QFile m_output; QFile m_output;
QNetworkReply* m_reply; QNetworkReply* m_reply;
qint64 m_bytesReceived; qint64 m_bytesReceived;
QTime m_downloadTime; QElapsedTimer m_downloadTime;
QTime m_lastProgressTime; QTime m_lastProgressTime;
bool m_requestFileName; bool m_requestFileName;
bool m_startedSaving; bool m_startedSaving;
@ -95,7 +96,7 @@ class DownloadManager : public TabContent {
Q_ENUM(RemovePolicy) Q_ENUM(RemovePolicy)
explicit DownloadManager(QWidget* parent = 0); explicit DownloadManager(QWidget* parent = nullptr);
virtual ~DownloadManager(); virtual ~DownloadManager();
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
@ -159,7 +160,7 @@ class DownloadModel : public QAbstractListModel {
friend class DownloadManager; friend class DownloadManager;
public: public:
explicit DownloadModel(DownloadManager* download_manager, QObject* parent = 0); explicit DownloadModel(DownloadManager* download_manager, QObject* parent = nullptr);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const; int rowCount(const QModelIndex& parent = QModelIndex()) const;

View file

@ -22,15 +22,15 @@ void CacheForServiceRoot::addMessageStatesToCache(const QList<Message>& ids_of_m
// Store changes, they will be sent to server later. // Store changes, they will be sent to server later.
list_act.append(ids_of_messages); list_act.append(ids_of_messages);
QSet<Message> set_act = list_act.toSet(); QSet<Message> set_act(list_act.begin(), list_act.end());
QSet<Message> set_other = list_other.toSet(); QSet<Message> set_other(list_other.begin(), list_other.end());
// Now, we want to remove all IDS from list_other, which are contained in list. // Now, we want to remove all IDS from list_other, which are contained in list.
set_other -= set_act; set_other -= set_act;
list_act.clear(); list_act.clear();
list_act.append(set_act.toList()); list_act.append(set_act.values());
list_other.clear(); list_other.clear();
list_other.append(set_other.toList()); list_other.append(set_other.values());
m_cacheSaveMutex->unlock(); m_cacheSaveMutex->unlock();
} }
@ -43,15 +43,15 @@ void CacheForServiceRoot::addMessageStatesToCache(const QStringList& ids_of_mess
// Store changes, they will be sent to server later. // Store changes, they will be sent to server later.
list_act.append(ids_of_messages); list_act.append(ids_of_messages);
QSet<QString> set_act = list_act.toSet(); QSet<QString> set_act(list_act.begin(), list_act.end());
QSet<QString> set_other = list_other.toSet(); QSet<QString> set_other(list_other.begin(), list_other.end());
// Now, we want to remove all IDS from list_other, which are contained in list. // Now, we want to remove all IDS from list_other, which are contained in list.
set_other -= set_act; set_other -= set_act;
list_act.clear(); list_act.clear();
list_act.append(set_act.toList()); list_act.append(set_act.values());
list_other.clear(); list_other.clear();
list_other.append(set_other.toList()); list_other.append(set_other.values());
m_cacheSaveMutex->unlock(); m_cacheSaveMutex->unlock();
} }

View file

@ -330,7 +330,10 @@ void FormFeedDetails::initialize() {
} }
// Sort encodings and add them. // Sort encodings and add them.
qSort(encoded_encodings.begin(), encoded_encodings.end(), TextFactory::isCaseInsensitiveLessThan); std::sort(encoded_encodings.begin(), encoded_encodings.end(), [](const QString& lhs, const QString& rhs) {
return lhs.toLower() < rhs.toLower();
});
m_ui->m_cmbEncoding->addItems(encoded_encodings); m_ui->m_cmbEncoding->addItems(encoded_encodings);
// Setup menu & actions for icon selection. // Setup menu & actions for icon selection.