Various Qt6 fixes

This commit is contained in:
Tobias Fella
2022-11-26 01:51:22 +01:00
parent 74b9f5fa4f
commit f207f57bd5
9 changed files with 50 additions and 43 deletions

View File

@@ -136,8 +136,8 @@
"sources": [ "sources": [
{ {
"type": "archive", "type": "archive",
"url": "https://github.com/danvratil/qcoro/archive/refs/tags/v0.4.0.tar.gz", "url": "https://github.com/danvratil/qcoro/archive/refs/tags/v0.7.0.tar.gz",
"sha256": "0e68b3f0ce7bf521ffbdd731464d2d60d8d7a39a749b551ed26855a1707d86d1", "sha256": "23ef0217926e67c8d2eb861cf91617da2f7d8d5a9ae6c62321b21448b1669210",
"x-checker-data": { "x-checker-data": {
"type": "anitya", "type": "anitya",
"project-id": 236236, "project-id": 236236,

View File

@@ -7,7 +7,8 @@
#include <events/roommessageevent.h> #include <events/roommessageevent.h>
class NeoChatRoom; #include "neochatroom.h"
class CustomEmojiModel; class CustomEmojiModel;
class NeoChatRoom; class NeoChatRoom;

View File

@@ -135,7 +135,11 @@ int ChatDocumentHandler::completionStartIndex() const
return 0; 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(); const auto &text = m_room->chatBoxText();
auto start = std::min(cursor, text.size()) - 1; auto start = std::min(cursor, text.size()) - 1;
while (start > -1) { while (start > -1) {
@@ -199,7 +203,7 @@ void ChatDocumentHandler::setRoom(NeoChatRoom *room)
void ChatDocumentHandler::complete(int index) 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 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 id = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::Subtitle).toString();
auto text = m_room->chatBoxText(); auto text = m_room->chatBoxText();
@@ -213,7 +217,7 @@ void ChatDocumentHandler::complete(int index)
cursor.setKeepPositionOnInsert(true); cursor.setKeepPositionOnInsert(true);
m_room->mentions()->push_back({cursor, name, 0, 0, id}); m_room->mentions()->push_back({cursor, name, 0, 0, id});
m_highlighter->rehighlight(); 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 command = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::ReplacedText).toString();
auto text = m_room->chatBoxText(); auto text = m_room->chatBoxText();
auto at = text.lastIndexOf(QLatin1Char('/')); auto at = text.lastIndexOf(QLatin1Char('/'));
@@ -221,7 +225,7 @@ void ChatDocumentHandler::complete(int index)
cursor.setPosition(at); cursor.setPosition(at);
cursor.setPosition(cursorPosition(), QTextCursor::KeepAnchor); cursor.setPosition(cursorPosition(), QTextCursor::KeepAnchor);
cursor.insertText(QStringLiteral("/%1 ").arg(command)); 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 alias = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::Subtitle).toString();
auto text = m_room->chatBoxText(); auto text = m_room->chatBoxText();
auto at = text.lastIndexOf(QLatin1Char('#'), cursorPosition() - 1); auto at = text.lastIndexOf(QLatin1Char('#'), cursorPosition() - 1);
@@ -234,7 +238,7 @@ void ChatDocumentHandler::complete(int index)
cursor.setKeepPositionOnInsert(true); cursor.setKeepPositionOnInsert(true);
m_room->mentions()->push_back({cursor, alias, 0, 0, alias}); m_room->mentions()->push_back({cursor, alias, 0, 0, alias});
m_highlighter->rehighlight(); 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 shortcode = m_completionModel->data(m_completionModel->index(index, 0), CompletionModel::ReplacedText).toString();
auto text = m_room->chatBoxText(); auto text = m_room->chatBoxText();
auto at = text.lastIndexOf(QLatin1Char(':')); auto at = text.lastIndexOf(QLatin1Char(':'));

View File

@@ -4,16 +4,15 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include <QQuickTextDocument>
#include <QTextCursor> #include <QTextCursor>
#include "completionmodel.h"
#include "userlistmodel.h" #include "userlistmodel.h"
class QTextDocument; class QTextDocument;
class QQuickTextDocument;
class NeoChatRoom; class NeoChatRoom;
class SyntaxHighlighter; class SyntaxHighlighter;
class CompletionModel;
class ChatDocumentHandler : public QObject class ChatDocumentHandler : public QObject
{ {
@@ -28,15 +27,6 @@ class ChatDocumentHandler : public QObject
Q_PROPERTY(NeoChatRoom *room READ room NOTIFY roomChanged) Q_PROPERTY(NeoChatRoom *room READ room NOTIFY roomChanged)
public: public:
enum AutoCompletionType {
User,
Room,
Emoji,
Command,
None,
};
Q_ENUM(AutoCompletionType)
explicit ChatDocumentHandler(QObject *parent = nullptr); explicit ChatDocumentHandler(QObject *parent = nullptr);
[[nodiscard]] QQuickTextDocument *document() const; [[nodiscard]] QQuickTextDocument *document() const;
@@ -80,9 +70,7 @@ private:
SyntaxHighlighter *m_highlighter = nullptr; SyntaxHighlighter *m_highlighter = nullptr;
AutoCompletionType m_completionType = None; CompletionModel::AutoCompletionType m_completionType = CompletionModel::None;
CompletionModel *m_completionModel = nullptr; CompletionModel *m_completionModel = nullptr;
}; };
Q_DECLARE_METATYPE(ChatDocumentHandler::AutoCompletionType);

View File

@@ -42,7 +42,7 @@ void CompletionModel::setText(const QString &text, const QString &fullText)
int CompletionModel::rowCount(const QModelIndex &parent) const int CompletionModel::rowCount(const QModelIndex &parent) const
{ {
Q_UNUSED(parent); Q_UNUSED(parent);
if (m_autoCompletionType == ChatDocumentHandler::None) { if (m_autoCompletionType == None) {
return 0; return 0;
} }
return m_filterModel->rowCount(); return m_filterModel->rowCount();
@@ -54,7 +54,7 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const
return {}; return {};
} }
auto filterIndex = m_filterModel->index(index.row(), 0); auto filterIndex = m_filterModel->index(index.row(), 0);
if (m_autoCompletionType == ChatDocumentHandler::User) { if (m_autoCompletionType == User) {
if (role == Text) { if (role == Text) {
return m_filterModel->data(filterIndex, UserListModel::NameRole); 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) { if (role == Text) {
return m_filterModel->data(filterIndex, ActionsModel::Prefix).toString() + QStringLiteral(" ") return m_filterModel->data(filterIndex, ActionsModel::Prefix).toString() + QStringLiteral(" ")
+ m_filterModel->data(filterIndex, ActionsModel::Parameters).toString(); + 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); return m_filterModel->data(filterIndex, ActionsModel::Prefix);
} }
} }
if (m_autoCompletionType == ChatDocumentHandler::Room) { if (m_autoCompletionType == Room) {
if (role == Text) { if (role == Text) {
return m_filterModel->data(filterIndex, RoomListModel::DisplayNameRole); 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); return m_filterModel->data(filterIndex, RoomListModel::AvatarRole);
} }
} }
if (m_autoCompletionType == ChatDocumentHandler::Emoji) { if (m_autoCompletionType == Emoji) {
if (role == Text) { if (role == Text) {
return m_filterModel->data(filterIndex, CustomEmojiModel::DisplayRole); return m_filterModel->data(filterIndex, CustomEmojiModel::DisplayRole);
} }
@@ -125,7 +125,7 @@ void CompletionModel::updateCompletion()
m_filterModel->setSecondaryFilterRole(UserListModel::NameRole); m_filterModel->setSecondaryFilterRole(UserListModel::NameRole);
m_filterModel->setFullText(m_fullText); m_filterModel->setFullText(m_fullText);
m_filterModel->setFilterText(m_text); m_filterModel->setFilterText(m_text);
m_autoCompletionType = ChatDocumentHandler::User; m_autoCompletionType = User;
m_filterModel->invalidate(); m_filterModel->invalidate();
} else if (text().startsWith(QLatin1Char('/'))) { } else if (text().startsWith(QLatin1Char('/'))) {
m_filterModel->setSourceModel(&ActionsModel::instance()); m_filterModel->setSourceModel(&ActionsModel::instance());
@@ -133,10 +133,10 @@ void CompletionModel::updateCompletion()
m_filterModel->setSecondaryFilterRole(-1); m_filterModel->setSecondaryFilterRole(-1);
m_filterModel->setFullText(m_fullText); m_filterModel->setFullText(m_fullText);
m_filterModel->setFilterText(m_text.mid(1)); m_filterModel->setFilterText(m_text.mid(1));
m_autoCompletionType = ChatDocumentHandler::Command; m_autoCompletionType = Command;
m_filterModel->invalidate(); m_filterModel->invalidate();
} else if (text().startsWith(QLatin1Char('#'))) { } else if (text().startsWith(QLatin1Char('#'))) {
m_autoCompletionType = ChatDocumentHandler::Room; m_autoCompletionType = Room;
m_filterModel->setSourceModel(m_roomListModel); m_filterModel->setSourceModel(m_roomListModel);
m_filterModel->setFilterRole(RoomListModel::CanonicalAliasRole); m_filterModel->setFilterRole(RoomListModel::CanonicalAliasRole);
m_filterModel->setSecondaryFilterRole(RoomListModel::DisplayNameRole); m_filterModel->setSecondaryFilterRole(RoomListModel::DisplayNameRole);
@@ -146,15 +146,15 @@ void CompletionModel::updateCompletion()
} else if (text().startsWith(QLatin1Char(':')) } else if (text().startsWith(QLatin1Char(':'))
&& (m_fullText.indexOf(QLatin1Char(':'), 1) == -1 && (m_fullText.indexOf(QLatin1Char(':'), 1) == -1
|| (m_fullText.indexOf(QLatin1Char(' ')) != -1 && m_fullText.indexOf(QLatin1Char(':'), 1) > m_fullText.indexOf(QLatin1Char(' '), 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_filterModel->setSourceModel(m_emojiModel);
m_autoCompletionType = Emoji;
m_filterModel->setFilterRole(CustomEmojiModel::Name); m_filterModel->setFilterRole(CustomEmojiModel::Name);
m_filterModel->setSecondaryFilterRole(-1); m_filterModel->setSecondaryFilterRole(-1);
m_filterModel->setFullText(m_fullText); m_filterModel->setFullText(m_fullText);
m_filterModel->setFilterText(m_text); m_filterModel->setFilterText(m_text);
m_filterModel->invalidate(); m_filterModel->invalidate();
} else { } else {
m_autoCompletionType = ChatDocumentHandler::None; m_autoCompletionType = None;
} }
beginResetModel(); beginResetModel();
endResetModel(); endResetModel();
@@ -171,12 +171,12 @@ void CompletionModel::setRoom(NeoChatRoom *room)
Q_EMIT roomChanged(); Q_EMIT roomChanged();
} }
ChatDocumentHandler::AutoCompletionType CompletionModel::autoCompletionType() const CompletionModel::AutoCompletionType CompletionModel::autoCompletionType() const
{ {
return m_autoCompletionType; return m_autoCompletionType;
} }
void CompletionModel::setAutoCompletionType(ChatDocumentHandler::AutoCompletionType autoCompletionType) void CompletionModel::setAutoCompletionType(AutoCompletionType autoCompletionType)
{ {
m_autoCompletionType = autoCompletionType; m_autoCompletionType = autoCompletionType;
Q_EMIT autoCompletionTypeChanged(); Q_EMIT autoCompletionTypeChanged();

View File

@@ -7,7 +7,7 @@
#include <KConcatenateRowsProxyModel> #include <KConcatenateRowsProxyModel>
#include "chatdocumenthandler.h" #include "roomlistmodel.h"
class CompletionProxyModel; class CompletionProxyModel;
class UserListModel; class UserListModel;
@@ -19,10 +19,19 @@ class CompletionModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString text READ text NOTIFY textChanged) Q_PROPERTY(QString text READ text NOTIFY textChanged)
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) 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); Q_PROPERTY(RoomListModel *roomListModel READ roomListModel WRITE setRoomListModel NOTIFY roomListModelChanged);
public: public:
enum AutoCompletionType {
User,
Room,
Emoji,
Command,
None,
};
Q_ENUM(AutoCompletionType)
enum Roles { enum Roles {
Text = Qt::DisplayRole, Text = Qt::DisplayRole,
Subtitle, Subtitle,
@@ -47,7 +56,7 @@ public:
RoomListModel *roomListModel() const; RoomListModel *roomListModel() const;
void setRoomListModel(RoomListModel *roomListModel); void setRoomListModel(RoomListModel *roomListModel);
ChatDocumentHandler::AutoCompletionType autoCompletionType() const; AutoCompletionType autoCompletionType() const;
Q_SIGNALS: Q_SIGNALS:
void textChanged(); void textChanged();
@@ -60,11 +69,12 @@ private:
QString m_fullText; QString m_fullText;
CompletionProxyModel *m_filterModel; CompletionProxyModel *m_filterModel;
NeoChatRoom *m_room = nullptr; 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; UserListModel *m_userListModel;
RoomListModel *m_roomListModel; RoomListModel *m_roomListModel;
KConcatenateRowsProxyModel *m_emojiModel; KConcatenateRowsProxyModel *m_emojiModel;
}; };
Q_DECLARE_METATYPE(CompletionModel::AutoCompletionType);

View File

@@ -18,7 +18,11 @@ bool CompletionProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &so
&& sourceModel() && sourceModel()
->data(sourceModel()->index(sourceRow, 0), secondaryFilterRole()) ->data(sourceModel()->index(sourceRow, 0), secondaryFilterRole())
.toString() .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)); .startsWith(m_filterText.midRef(1), Qt::CaseInsensitive));
#endif
} }
int CompletionProxyModel::secondaryFilterRole() const int CompletionProxyModel::secondaryFilterRole() const

View File

@@ -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, // 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. // rather than with the full mxid, as that would lead to an invalid user.
QStringRef username(&m_matrixId, 1, m_matrixId.indexOf(":") - 1); auto username = m_matrixId.mid(1, m_matrixId.indexOf(":") - 1);
m_connection->loginWithPassword(username.toString(), m_password, m_deviceName, QString()); m_connection->loginWithPassword(username, m_password, m_deviceName, QString());
} }
bool Login::supportsPassword() const bool Login::supportsPassword() const

View File

@@ -51,7 +51,7 @@ bool MessageFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sour
return false; return false;
} }
const QString eventType = index.data(MessageEventModel::EventTypeRole).toString(); const auto eventType = index.data(MessageEventModel::EventTypeRole).toInt();
if (eventType == MessageEventModel::Other) { if (eventType == MessageEventModel::Other) {
return false; return false;