diff --git a/ChatView/CMakeLists.txt b/ChatView/CMakeLists.txt
index 18e78ba..bb1976f 100644
--- a/ChatView/CMakeLists.txt
+++ b/ChatView/CMakeLists.txt
@@ -41,6 +41,7 @@ qt_add_qml_module(QodeAssistChatView
ChatUtils.h ChatUtils.cpp
ChatSerializer.hpp ChatSerializer.cpp
ChatView.hpp ChatView.cpp
+ ChatData.hpp
)
target_link_libraries(QodeAssistChatView
diff --git a/ChatView/ChatData.hpp b/ChatView/ChatData.hpp
new file mode 100644
index 0000000..fca7c36
--- /dev/null
+++ b/ChatView/ChatData.hpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2025 Petr Mironychev
+ *
+ * This file is part of QodeAssist.
+ *
+ * QodeAssist is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * QodeAssist is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with QodeAssist. If not, see .
+ */
+
+#pragma once
+
+#include
+#include
+
+namespace QodeAssist::Chat {
+Q_NAMESPACE
+QML_NAMED_ELEMENT(MessagePartType)
+
+enum class MessagePartType { Code, Text };
+Q_ENUM_NS(MessagePartType)
+
+} // namespace QodeAssist::Chat
diff --git a/ChatView/ChatModel.cpp b/ChatView/ChatModel.cpp
index d757694..e437ab2 100644
--- a/ChatView/ChatModel.cpp
+++ b/ChatView/ChatModel.cpp
@@ -132,10 +132,10 @@ QList ChatModel::processMessageContent(const QString &content) cons
QString textBetween
= content.mid(lastIndex, match.capturedStart() - lastIndex).trimmed();
if (!textBetween.isEmpty()) {
- parts.append({MessagePart::Text, textBetween, ""});
+ parts.append({MessagePartType::Text, textBetween, ""});
}
}
- parts.append({MessagePart::Code, match.captured(2).trimmed(), match.captured(1)});
+ parts.append({MessagePartType::Code, match.captured(2).trimmed(), match.captured(1)});
lastIndex = match.capturedEnd();
}
@@ -148,13 +148,15 @@ QList ChatModel::processMessageContent(const QString &content) cons
if (unclosedMatch.hasMatch()) {
QString beforeCodeBlock = remainingText.left(unclosedMatch.capturedStart()).trimmed();
if (!beforeCodeBlock.isEmpty()) {
- parts.append({MessagePart::Text, beforeCodeBlock, ""});
+ parts.append({MessagePartType::Text, beforeCodeBlock, ""});
}
parts.append(
- {MessagePart::Code, unclosedMatch.captured(2).trimmed(), unclosedMatch.captured(1)});
+ {MessagePartType::Code,
+ unclosedMatch.captured(2).trimmed(),
+ unclosedMatch.captured(1)});
} else if (!remainingText.isEmpty()) {
- parts.append({MessagePart::Text, remainingText, ""});
+ parts.append({MessagePartType::Text, remainingText, ""});
}
}
diff --git a/ChatView/MessagePart.hpp b/ChatView/MessagePart.hpp
index 5a42036..13a6616 100644
--- a/ChatView/MessagePart.hpp
+++ b/ChatView/MessagePart.hpp
@@ -19,33 +19,24 @@
#pragma once
-#include
-#include
+#include
+#include
+
+#include "ChatData.hpp"
namespace QodeAssist::Chat {
-Q_NAMESPACE
class MessagePart
{
Q_GADGET
- Q_PROPERTY(PartType type MEMBER type CONSTANT FINAL)
+ Q_PROPERTY(MessagePartType type MEMBER type CONSTANT FINAL)
Q_PROPERTY(QString text MEMBER text CONSTANT FINAL)
Q_PROPERTY(QString language MEMBER language CONSTANT FINAL)
QML_VALUE_TYPE(messagePart)
public:
- enum PartType { Code, Text };
- Q_ENUM(PartType)
-
- PartType type;
+ MessagePartType type;
QString text;
QString language;
};
-class MessagePartType : public MessagePart
-{
- Q_GADGET
-};
-
-QML_NAMED_ELEMENT(MessagePart)
-QML_FOREIGN_NAMESPACE(QodeAssist::Chat::MessagePartType)
} // namespace QodeAssist::Chat
diff --git a/ChatView/qml/ChatItem.qml b/ChatView/qml/ChatItem.qml
index 042752f..4c99a37 100644
--- a/ChatView/qml/ChatItem.qml
+++ b/ChatView/qml/ChatItem.qml
@@ -87,8 +87,8 @@ Rectangle {
}
switch(modelData.type) {
- case MessagePart.Text: return textComponent;
- case MessagePart.Code: return codeBlockComponent;
+ case MessagePartType.Text: return textComponent;
+ case MessagePartType.Code: return codeBlockComponent;
default: return textComponent;
}
}