From f207f57bd5bb8593a86c50c46331b792211b9ab4 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sat, 26 Nov 2022 01:51:22 +0100 Subject: [PATCH] Various Qt6 fixes --- .flatpak-manifest.json | 4 ++-- src/actionshandler.h | 3 ++- src/chatdocumenthandler.cpp | 14 +++++++++----- src/chatdocumenthandler.h | 18 +++--------------- src/completionmodel.cpp | 24 ++++++++++++------------ src/completionmodel.h | 20 +++++++++++++++----- src/completionproxymodel.cpp | 4 ++++ src/login.cpp | 4 ++-- src/messagefiltermodel.cpp | 2 +- 9 files changed, 50 insertions(+), 43 deletions(-) diff --git a/.flatpak-manifest.json b/.flatpak-manifest.json index 530c84573..e4f169641 100644 --- a/.flatpak-manifest.json +++ b/.flatpak-manifest.json @@ -136,8 +136,8 @@ "sources": [ { "type": "archive", - "url": "https://github.com/danvratil/qcoro/archive/refs/tags/v0.4.0.tar.gz", - "sha256": "0e68b3f0ce7bf521ffbdd731464d2d60d8d7a39a749b551ed26855a1707d86d1", + "url": "https://github.com/danvratil/qcoro/archive/refs/tags/v0.7.0.tar.gz", + "sha256": "23ef0217926e67c8d2eb861cf91617da2f7d8d5a9ae6c62321b21448b1669210", "x-checker-data": { "type": "anitya", "project-id": 236236, diff --git a/src/actionshandler.h b/src/actionshandler.h index 6daf7a655..3435c0a75 100644 --- a/src/actionshandler.h +++ b/src/actionshandler.h @@ -7,7 +7,8 @@ #include -class NeoChatRoom; +#include "neochatroom.h" + class CustomEmojiModel; class NeoChatRoom; diff --git a/src/chatdocumenthandler.cpp b/src/chatdocumenthandler.cpp index 9f13e3c82..6526a0476 100644 --- a/src/chatdocumenthandler.cpp +++ b/src/chatdocumenthandler.cpp @@ -135,7 +135,11 @@ int ChatDocumentHandler::completionStartIndex() const return 0; } - const auto &cursor = cursorPosition(); +#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) + const long long cursor = cursorPosition(); +#else + const auto cursor = cursorPosition(); +#endif const auto &text = m_room->chatBoxText(); auto start = std::min(cursor, text.size()) - 1; while (start > -1) { @@ -199,7 +203,7 @@ void ChatDocumentHandler::setRoom(NeoChatRoom *room) void ChatDocumentHandler::complete(int index) { - if (m_completionModel->autoCompletionType() == ChatDocumentHandler::User) { + if (m_completionModel->autoCompletionType() == CompletionModel::User) { auto name = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::Text).toString(); auto id = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::Subtitle).toString(); auto text = m_room->chatBoxText(); @@ -213,7 +217,7 @@ void ChatDocumentHandler::complete(int index) cursor.setKeepPositionOnInsert(true); m_room->mentions()->push_back({cursor, name, 0, 0, id}); m_highlighter->rehighlight(); - } else if (m_completionModel->autoCompletionType() == ChatDocumentHandler::Command) { + } else if (m_completionModel->autoCompletionType() == CompletionModel::Command) { auto command = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::ReplacedText).toString(); auto text = m_room->chatBoxText(); auto at = text.lastIndexOf(QLatin1Char('/')); @@ -221,7 +225,7 @@ void ChatDocumentHandler::complete(int index) cursor.setPosition(at); cursor.setPosition(cursorPosition(), QTextCursor::KeepAnchor); cursor.insertText(QStringLiteral("/%1 ").arg(command)); - } else if (m_completionModel->autoCompletionType() == ChatDocumentHandler::Room) { + } else if (m_completionModel->autoCompletionType() == CompletionModel::Room) { auto alias = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::Subtitle).toString(); auto text = m_room->chatBoxText(); auto at = text.lastIndexOf(QLatin1Char('#'), cursorPosition() - 1); @@ -234,7 +238,7 @@ void ChatDocumentHandler::complete(int index) cursor.setKeepPositionOnInsert(true); m_room->mentions()->push_back({cursor, alias, 0, 0, alias}); m_highlighter->rehighlight(); - } else if (m_completionModel->autoCompletionType() == ChatDocumentHandler::Emoji) { + } else if (m_completionModel->autoCompletionType() == CompletionModel::Emoji) { auto shortcode = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::ReplacedText).toString(); auto text = m_room->chatBoxText(); auto at = text.lastIndexOf(QLatin1Char(':')); diff --git a/src/chatdocumenthandler.h b/src/chatdocumenthandler.h index bba636236..8dbc8a2aa 100644 --- a/src/chatdocumenthandler.h +++ b/src/chatdocumenthandler.h @@ -4,16 +4,15 @@ #pragma once #include - +#include #include +#include "completionmodel.h" #include "userlistmodel.h" class QTextDocument; -class QQuickTextDocument; class NeoChatRoom; class SyntaxHighlighter; -class CompletionModel; class ChatDocumentHandler : public QObject { @@ -28,15 +27,6 @@ class ChatDocumentHandler : public QObject Q_PROPERTY(NeoChatRoom *room READ room NOTIFY roomChanged) public: - enum AutoCompletionType { - User, - Room, - Emoji, - Command, - None, - }; - Q_ENUM(AutoCompletionType) - explicit ChatDocumentHandler(QObject *parent = nullptr); [[nodiscard]] QQuickTextDocument *document() const; @@ -80,9 +70,7 @@ private: SyntaxHighlighter *m_highlighter = nullptr; - AutoCompletionType m_completionType = None; + CompletionModel::AutoCompletionType m_completionType = CompletionModel::None; CompletionModel *m_completionModel = nullptr; }; - -Q_DECLARE_METATYPE(ChatDocumentHandler::AutoCompletionType); diff --git a/src/completionmodel.cpp b/src/completionmodel.cpp index 89606eeea..750108b68 100644 --- a/src/completionmodel.cpp +++ b/src/completionmodel.cpp @@ -42,7 +42,7 @@ void CompletionModel::setText(const QString &text, const QString &fullText) int CompletionModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); - if (m_autoCompletionType == ChatDocumentHandler::None) { + if (m_autoCompletionType == None) { return 0; } return m_filterModel->rowCount(); @@ -54,7 +54,7 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const return {}; } auto filterIndex = m_filterModel->index(index.row(), 0); - if (m_autoCompletionType == ChatDocumentHandler::User) { + if (m_autoCompletionType == User) { if (role == Text) { return m_filterModel->data(filterIndex, UserListModel::NameRole); } @@ -66,7 +66,7 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const } } - if (m_autoCompletionType == ChatDocumentHandler::Command) { + if (m_autoCompletionType == Command) { if (role == Text) { return m_filterModel->data(filterIndex, ActionsModel::Prefix).toString() + QStringLiteral(" ") + m_filterModel->data(filterIndex, ActionsModel::Parameters).toString(); @@ -81,7 +81,7 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const return m_filterModel->data(filterIndex, ActionsModel::Prefix); } } - if (m_autoCompletionType == ChatDocumentHandler::Room) { + if (m_autoCompletionType == Room) { if (role == Text) { return m_filterModel->data(filterIndex, RoomListModel::DisplayNameRole); } @@ -92,7 +92,7 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const return m_filterModel->data(filterIndex, RoomListModel::AvatarRole); } } - if (m_autoCompletionType == ChatDocumentHandler::Emoji) { + if (m_autoCompletionType == Emoji) { if (role == Text) { return m_filterModel->data(filterIndex, CustomEmojiModel::DisplayRole); } @@ -125,7 +125,7 @@ void CompletionModel::updateCompletion() m_filterModel->setSecondaryFilterRole(UserListModel::NameRole); m_filterModel->setFullText(m_fullText); m_filterModel->setFilterText(m_text); - m_autoCompletionType = ChatDocumentHandler::User; + m_autoCompletionType = User; m_filterModel->invalidate(); } else if (text().startsWith(QLatin1Char('/'))) { m_filterModel->setSourceModel(&ActionsModel::instance()); @@ -133,10 +133,10 @@ void CompletionModel::updateCompletion() m_filterModel->setSecondaryFilterRole(-1); m_filterModel->setFullText(m_fullText); m_filterModel->setFilterText(m_text.mid(1)); - m_autoCompletionType = ChatDocumentHandler::Command; + m_autoCompletionType = Command; m_filterModel->invalidate(); } else if (text().startsWith(QLatin1Char('#'))) { - m_autoCompletionType = ChatDocumentHandler::Room; + m_autoCompletionType = Room; m_filterModel->setSourceModel(m_roomListModel); m_filterModel->setFilterRole(RoomListModel::CanonicalAliasRole); m_filterModel->setSecondaryFilterRole(RoomListModel::DisplayNameRole); @@ -146,15 +146,15 @@ void CompletionModel::updateCompletion() } else if (text().startsWith(QLatin1Char(':')) && (m_fullText.indexOf(QLatin1Char(':'), 1) == -1 || (m_fullText.indexOf(QLatin1Char(' ')) != -1 && m_fullText.indexOf(QLatin1Char(':'), 1) > m_fullText.indexOf(QLatin1Char(' '), 1)))) { - m_autoCompletionType = ChatDocumentHandler::Emoji; m_filterModel->setSourceModel(m_emojiModel); + m_autoCompletionType = Emoji; m_filterModel->setFilterRole(CustomEmojiModel::Name); m_filterModel->setSecondaryFilterRole(-1); m_filterModel->setFullText(m_fullText); m_filterModel->setFilterText(m_text); m_filterModel->invalidate(); } else { - m_autoCompletionType = ChatDocumentHandler::None; + m_autoCompletionType = None; } beginResetModel(); endResetModel(); @@ -171,12 +171,12 @@ void CompletionModel::setRoom(NeoChatRoom *room) Q_EMIT roomChanged(); } -ChatDocumentHandler::AutoCompletionType CompletionModel::autoCompletionType() const +CompletionModel::AutoCompletionType CompletionModel::autoCompletionType() const { return m_autoCompletionType; } -void CompletionModel::setAutoCompletionType(ChatDocumentHandler::AutoCompletionType autoCompletionType) +void CompletionModel::setAutoCompletionType(AutoCompletionType autoCompletionType) { m_autoCompletionType = autoCompletionType; Q_EMIT autoCompletionTypeChanged(); diff --git a/src/completionmodel.h b/src/completionmodel.h index 097e759f7..ec8f3b3a2 100644 --- a/src/completionmodel.h +++ b/src/completionmodel.h @@ -7,7 +7,7 @@ #include -#include "chatdocumenthandler.h" +#include "roomlistmodel.h" class CompletionProxyModel; class UserListModel; @@ -19,10 +19,19 @@ class CompletionModel : public QAbstractListModel Q_OBJECT Q_PROPERTY(QString text READ text NOTIFY textChanged) Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) - Q_PROPERTY(ChatDocumentHandler::AutoCompletionType autoCompletionType READ autoCompletionType NOTIFY autoCompletionTypeChanged); + Q_PROPERTY(AutoCompletionType autoCompletionType READ autoCompletionType NOTIFY autoCompletionTypeChanged); Q_PROPERTY(RoomListModel *roomListModel READ roomListModel WRITE setRoomListModel NOTIFY roomListModelChanged); public: + enum AutoCompletionType { + User, + Room, + Emoji, + Command, + None, + }; + Q_ENUM(AutoCompletionType) + enum Roles { Text = Qt::DisplayRole, Subtitle, @@ -47,7 +56,7 @@ public: RoomListModel *roomListModel() const; void setRoomListModel(RoomListModel *roomListModel); - ChatDocumentHandler::AutoCompletionType autoCompletionType() const; + AutoCompletionType autoCompletionType() const; Q_SIGNALS: void textChanged(); @@ -60,11 +69,12 @@ private: QString m_fullText; CompletionProxyModel *m_filterModel; NeoChatRoom *m_room = nullptr; - ChatDocumentHandler::AutoCompletionType m_autoCompletionType = ChatDocumentHandler::None; + AutoCompletionType m_autoCompletionType = None; - void setAutoCompletionType(ChatDocumentHandler::AutoCompletionType autoCompletionType); + void setAutoCompletionType(AutoCompletionType autoCompletionType); UserListModel *m_userListModel; RoomListModel *m_roomListModel; KConcatenateRowsProxyModel *m_emojiModel; }; +Q_DECLARE_METATYPE(CompletionModel::AutoCompletionType); diff --git a/src/completionproxymodel.cpp b/src/completionproxymodel.cpp index 2681a7a87..35457f1b4 100644 --- a/src/completionproxymodel.cpp +++ b/src/completionproxymodel.cpp @@ -18,7 +18,11 @@ bool CompletionProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so && sourceModel() ->data(sourceModel()->index(sourceRow, 0), secondaryFilterRole()) .toString() +#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0) + .startsWith(QStringView(m_filterText).sliced(1), Qt::CaseInsensitive)); +#else .startsWith(m_filterText.midRef(1), Qt::CaseInsensitive)); +#endif } int CompletionProxyModel::secondaryFilterRole() const diff --git a/src/login.cpp b/src/login.cpp index a4d770c59..fe60f4aa4 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -158,8 +158,8 @@ void Login::login() // Some servers do not have a .well_known file. So we login via the username part from the mxid, // rather than with the full mxid, as that would lead to an invalid user. - QStringRef username(&m_matrixId, 1, m_matrixId.indexOf(":") - 1); - m_connection->loginWithPassword(username.toString(), m_password, m_deviceName, QString()); + auto username = m_matrixId.mid(1, m_matrixId.indexOf(":") - 1); + m_connection->loginWithPassword(username, m_password, m_deviceName, QString()); } bool Login::supportsPassword() const diff --git a/src/messagefiltermodel.cpp b/src/messagefiltermodel.cpp index 6a6f7f3e6..afb5e6902 100644 --- a/src/messagefiltermodel.cpp +++ b/src/messagefiltermodel.cpp @@ -51,7 +51,7 @@ bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour return false; } - const QString eventType = index.data(MessageEventModel::EventTypeRole).toString(); + const auto eventType = index.data(MessageEventModel::EventTypeRole).toInt(); if (eventType == MessageEventModel::Other) { return false;